diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index 8efe8e93a..2602fef97 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -1571,6 +1571,20 @@ bool FileSystem::DeleteFile(const char* Path) return false; } +bool FileSystem::RenamePath(const char* OldPath, const char* NewPath) +{ + const std::wstring old_wpath(StringUtil::UTF8StringToWideString(OldPath)); + const std::wstring new_wpath(StringUtil::UTF8StringToWideString(NewPath)); + + if (!MoveFileExW(old_wpath.c_str(), new_wpath.c_str(), MOVEFILE_REPLACE_EXISTING)) + { + Log_ErrorPrintf("MoveFileEx('%s', '%s') failed: %08X", OldPath, NewPath, GetLastError()); + return false; + } + + return true; +} + static bool RecursiveDeleteDirectory(const std::wstring& wpath, bool Recursive) { // ensure it exists @@ -2046,6 +2060,20 @@ bool DeleteFile(const char* Path) return (unlink(Path) == 0); } +bool RenamePath(const char* OldPath, const char* NewPath) +{ + if (OldPath[0] == '\0' || NewPath[0] == '\0') + return false; + + if (rename(OldPath, NewPath) != 0) + { + Log_ErrorPrintf("rename('%s', '%s') failed: %d", OldPath, NewPath, errno); + return false; + } + + return true; +} + bool DeleteDirectory(const char* Path, bool Recursive) { Log_ErrorPrintf("FileSystem::DeleteDirectory(%s) not implemented", Path); diff --git a/src/common/file_system.h b/src/common/file_system.h index 9547a74f5..3fa33ab82 100644 --- a/src/common/file_system.h +++ b/src/common/file_system.h @@ -182,6 +182,9 @@ bool DirectoryExists(const char* Path); // delete file bool DeleteFile(const char* Path); +// rename file +bool RenamePath(const char* OldPath, const char* NewPath); + // open files std::unique_ptr OpenFile(const char* FileName, u32 Flags);