FileSystem: Add RenamePath()

This commit is contained in:
Connor McLaughlin 2021-07-03 16:48:22 +10:00
parent 762ab3ff43
commit 53cabbb134
2 changed files with 31 additions and 0 deletions

View File

@ -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);

View File

@ -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<ByteStream> OpenFile(const char* FileName, u32 Flags);