ByteStream: Fix atomic updates on external storage with UWP

This commit is contained in:
Connor McLaughlin
2021-07-11 19:05:30 +10:00
parent e8c16056b6
commit 3be6270b2d
2 changed files with 52 additions and 6 deletions

View File

@ -1794,7 +1794,17 @@ bool FileSystem::RenamePath(const char* OldPath, const char* NewPath)
return false;
}
#else
if (!ReplaceFileFromAppW(old_wpath.c_str(), new_wpath.c_str(), nullptr, 0, nullptr, nullptr))
// try moving if it doesn't exist, since ReplaceFile fails on non-existing destinations
if (WrapGetFileAttributes(new_wpath.c_str()) != INVALID_FILE_ATTRIBUTES)
{
if (!DeleteFileFromAppW(new_wpath.c_str()))
{
Log_ErrorPrintf("DeleteFileFromAppW('%s') failed: %08X", new_wpath.c_str(), GetLastError());
return false;
}
}
if (!MoveFileFromAppW(old_wpath.c_str(), new_wpath.c_str()))
{
Log_ErrorPrintf("MoveFileFromAppW('%s', '%s') failed: %08X", OldPath, NewPath, GetLastError());
return false;