From 03d54436363ad920f45c9f990150f566f04788d5 Mon Sep 17 00:00:00 2001 From: "fires.gc" Date: Thu, 6 Nov 2008 22:01:09 +0000 Subject: [PATCH] it seems that "rename" overwrites files... git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1086 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/FileUtil.cpp | 5 +++++ Source/Core/Common/Src/FileUtil.h | 1 + .../Core/Src/IPC_HLE/WII_IPC_HLE_Device_fs.cpp | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index 7660aeb824..0cb66dcdeb 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -163,6 +163,11 @@ bool DeleteDir(const char *filename) #endif } +bool Rename(const char *srcFilename, const char *destFilename) +{ + return (rename(srcFilename, destFilename) == 0); +} + std::string GetUserDirectory() { #ifdef _WIN32 diff --git a/Source/Core/Common/Src/FileUtil.h b/Source/Core/Common/Src/FileUtil.h index 778846d4a6..74f1ed5592 100644 --- a/Source/Core/Common/Src/FileUtil.h +++ b/Source/Core/Common/Src/FileUtil.h @@ -43,6 +43,7 @@ bool IsDirectory(const char *filename); bool CreateDir(const char *filename); bool Delete(const char *filename); bool DeleteDir(const char *filename); +bool Rename(const char *srcFilename, const char *destFilename); u64 GetSize(const char *filename); std::string GetUserDirectory(); bool CreateEmptyFile(const char *filename); diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_fs.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_fs.cpp index 9457d9b1e1..bf7c20f5d4 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_fs.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_fs.cpp @@ -328,9 +328,17 @@ s32 CWII_IPC_HLE_Device_fs::ExecuteCommand(u32 _Parameter, u32 _BufferIn, u32 _B std::string FilenameRename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn+Offset), 64); Offset += 64; - // F|RES: i think that we dont need this - CreateDirectoryStruct(Filename); + // try to make the basis directory + CreateDirectoryStruct(Filename); - if (rename(Filename.c_str(), FilenameRename.c_str()) == 0) + // if there is already a filedelete it + if (File::Exists(FilenameRename.c_str())) + { + File::Delete(FilenameRename.c_str()); + } + + // finally try to rename the file + if (File::Rename(Filename.c_str(), FilenameRename.c_str())) { LOG(WII_IPC_FILEIO, "FS: Rename %s to %s", Filename.c_str(), FilenameRename.c_str()); } @@ -354,9 +362,9 @@ s32 CWII_IPC_HLE_Device_fs::ExecuteCommand(u32 _Parameter, u32 _BufferIn, u32 _B std::string Filename(HLE_IPC_BuildFilename((const char*)Memory::GetPointer(Addr), 64)); Addr += 64; - u8 OwnerPerm = Memory::Read_U8(Addr); Addr++; - u8 GroupPerm = Memory::Read_U8(Addr); Addr++; - u8 OtherPerm = Memory::Read_U8(Addr); Addr++; + u8 OwnerPerm = Memory::Read_U8(Addr); Addr++; + u8 GroupPerm = Memory::Read_U8(Addr); Addr++; + u8 OtherPerm = Memory::Read_U8(Addr); Addr++; u8 Attributes = Memory::Read_U8(Addr); Addr++; LOG(WII_IPC_FILEIO, "FS: CreateFile %s", Filename.c_str());