Qt: Clean and remove empty game settings

This commit is contained in:
Stenzek
2024-05-04 23:33:35 +10:00
committed by Connor McLaughlin
parent 12af031193
commit 2ab6a3b873
21 changed files with 267 additions and 81 deletions

View File

@@ -1725,17 +1725,29 @@ bool FileSystem::CreateDirectoryPath(const char* Path, bool Recursive, Error* er
}
}
bool FileSystem::DeleteFilePath(const char* path)
bool FileSystem::DeleteFilePath(const char* path, Error* error)
{
if (path[0] == '\0')
{
Error::SetStringView(error, "Path is empty.");
return false;
}
const std::wstring wpath = GetWin32Path(path);
const DWORD fileAttributes = GetFileAttributesW(wpath.c_str());
if (fileAttributes == INVALID_FILE_ATTRIBUTES || fileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
Error::SetStringView(error, "File does not exist.");
return false;
}
return (DeleteFileW(wpath.c_str()) == TRUE);
if (!DeleteFileW(wpath.c_str()))
{
Error::SetWin32(error, "DeleteFileW() failed: ", GetLastError());
return false;
}
return true;
}
bool FileSystem::RenamePath(const char* old_path, const char* new_path, Error* error)
@@ -2213,16 +2225,28 @@ bool FileSystem::CreateDirectoryPath(const char* path, bool recursive, Error* er
}
}
bool FileSystem::DeleteFilePath(const char* path)
bool FileSystem::DeleteFilePath(const char* path, Error* error)
{
if (path[0] == '\0')
{
Error::SetStringView(error, "Path is empty.");
return false;
}
struct stat sysStatData;
if (stat(path, &sysStatData) != 0 || S_ISDIR(sysStatData.st_mode))
{
Error::SetStringView(error, "File does not exist.");
return false;
}
return (unlink(path) == 0);
if (unlink(path) != 0)
{
Error::SetErrno(error, "unlink() failed: ", errno);
return false;
}
return true;
}
bool FileSystem::RenamePath(const char* old_path, const char* new_path, Error* error)