FileSystem: Add RenamePath()
This commit is contained in:
parent
762ab3ff43
commit
53cabbb134
|
@ -1571,6 +1571,20 @@ bool FileSystem::DeleteFile(const char* Path)
|
||||||
return false;
|
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)
|
static bool RecursiveDeleteDirectory(const std::wstring& wpath, bool Recursive)
|
||||||
{
|
{
|
||||||
// ensure it exists
|
// ensure it exists
|
||||||
|
@ -2046,6 +2060,20 @@ bool DeleteFile(const char* Path)
|
||||||
return (unlink(Path) == 0);
|
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)
|
bool DeleteDirectory(const char* Path, bool Recursive)
|
||||||
{
|
{
|
||||||
Log_ErrorPrintf("FileSystem::DeleteDirectory(%s) not implemented", Path);
|
Log_ErrorPrintf("FileSystem::DeleteDirectory(%s) not implemented", Path);
|
||||||
|
|
|
@ -182,6 +182,9 @@ bool DirectoryExists(const char* Path);
|
||||||
// delete file
|
// delete file
|
||||||
bool DeleteFile(const char* Path);
|
bool DeleteFile(const char* Path);
|
||||||
|
|
||||||
|
// rename file
|
||||||
|
bool RenamePath(const char* OldPath, const char* NewPath);
|
||||||
|
|
||||||
// open files
|
// open files
|
||||||
std::unique_ptr<ByteStream> OpenFile(const char* FileName, u32 Flags);
|
std::unique_ptr<ByteStream> OpenFile(const char* FileName, u32 Flags);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue