Qt: Clean and remove empty game settings
This commit is contained in:
@ -1736,17 +1736,29 @@ bool FileSystem::CreateDirectory(const char* Path, bool Recursive, Error* error)
|
||||
}
|
||||
}
|
||||
|
||||
bool FileSystem::DeleteFile(const char* path)
|
||||
bool FileSystem::DeleteFile(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)
|
||||
@ -2241,16 +2253,28 @@ bool FileSystem::CreateDirectory(const char* path, bool recursive, Error* error)
|
||||
}
|
||||
}
|
||||
|
||||
bool FileSystem::DeleteFile(const char* path)
|
||||
bool FileSystem::DeleteFile(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)
|
||||
|
||||
@ -86,7 +86,7 @@ bool DirectoryExists(const char* path);
|
||||
bool DirectoryIsEmpty(const char* path);
|
||||
|
||||
/// Delete file
|
||||
bool DeleteFile(const char* path);
|
||||
bool DeleteFile(const char* path, Error* error = nullptr);
|
||||
|
||||
/// Rename file
|
||||
bool RenamePath(const char* OldPath, const char* NewPath, Error* error = nullptr);
|
||||
|
||||
@ -19,6 +19,11 @@ void LayeredSettingsInterface::Clear()
|
||||
Panic("Attempting to clear layered settings interface");
|
||||
}
|
||||
|
||||
bool LayeredSettingsInterface::IsEmpty()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LayeredSettingsInterface::GetIntValue(const char* section, const char* key, s32* value) const
|
||||
{
|
||||
for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++)
|
||||
@ -170,6 +175,16 @@ void LayeredSettingsInterface::ClearSection(const char* section)
|
||||
Panic("Attempt to call ClearSection() on layered settings interface");
|
||||
}
|
||||
|
||||
void LayeredSettingsInterface::RemoveSection(const char* section)
|
||||
{
|
||||
Panic("Attempt to call RemoveSection() on layered settings interface");
|
||||
}
|
||||
|
||||
void LayeredSettingsInterface::RemoveEmptySections()
|
||||
{
|
||||
Panic("Attempt to call RemoveEmptySections() on layered settings interface");
|
||||
}
|
||||
|
||||
std::vector<std::string> LayeredSettingsInterface::GetStringList(const char* section, const char* key) const
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
|
||||
@ -27,6 +27,8 @@ public:
|
||||
|
||||
void Clear() override;
|
||||
|
||||
bool IsEmpty() override;
|
||||
|
||||
bool GetIntValue(const char* section, const char* key, s32* value) const override;
|
||||
bool GetUIntValue(const char* section, const char* key, u32* value) const override;
|
||||
bool GetFloatValue(const char* section, const char* key, float* value) const override;
|
||||
@ -44,6 +46,8 @@ public:
|
||||
bool ContainsValue(const char* section, const char* key) const override;
|
||||
void DeleteValue(const char* section, const char* key) override;
|
||||
void ClearSection(const char* section) override;
|
||||
void RemoveSection(const char* section) override;
|
||||
void RemoveEmptySections() override;
|
||||
|
||||
std::vector<std::string> GetStringList(const char* section, const char* key) const override;
|
||||
void SetStringList(const char* section, const char* key, const std::vector<std::string>& items) override;
|
||||
|
||||
@ -22,6 +22,11 @@ void MemorySettingsInterface::Clear()
|
||||
m_sections.clear();
|
||||
}
|
||||
|
||||
bool MemorySettingsInterface::IsEmpty()
|
||||
{
|
||||
return m_sections.empty();
|
||||
}
|
||||
|
||||
bool MemorySettingsInterface::GetIntValue(const char* section, const char* key, s32* value) const
|
||||
{
|
||||
const auto sit = m_sections.find(section);
|
||||
@ -315,3 +320,26 @@ void MemorySettingsInterface::ClearSection(const char* section)
|
||||
|
||||
m_sections.erase(sit);
|
||||
}
|
||||
|
||||
void MemorySettingsInterface::RemoveSection(const char* section)
|
||||
{
|
||||
auto sit = m_sections.find(section);
|
||||
if (sit == m_sections.end())
|
||||
return;
|
||||
|
||||
m_sections.erase(sit);
|
||||
}
|
||||
|
||||
void MemorySettingsInterface::RemoveEmptySections()
|
||||
{
|
||||
for (auto sit = m_sections.begin(); sit != m_sections.end();)
|
||||
{
|
||||
if (sit->second.size() > 0)
|
||||
{
|
||||
++sit;
|
||||
continue;
|
||||
}
|
||||
|
||||
sit = m_sections.erase(sit);
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,8 @@ public:
|
||||
|
||||
void Clear() override;
|
||||
|
||||
bool IsEmpty() override;
|
||||
|
||||
bool GetIntValue(const char* section, const char* key, s32* value) const override;
|
||||
bool GetUIntValue(const char* section, const char* key, u32* value) const override;
|
||||
bool GetFloatValue(const char* section, const char* key, float* value) const override;
|
||||
@ -37,6 +39,8 @@ public:
|
||||
bool ContainsValue(const char* section, const char* key) const override;
|
||||
void DeleteValue(const char* section, const char* key) override;
|
||||
void ClearSection(const char* section) override;
|
||||
void RemoveSection(const char* section) override;
|
||||
void RemoveEmptySections();
|
||||
|
||||
std::vector<std::string> GetStringList(const char* section, const char* key) const override;
|
||||
void SetStringList(const char* section, const char* key, const std::vector<std::string>& items) override;
|
||||
|
||||
@ -19,6 +19,7 @@ public:
|
||||
|
||||
virtual bool Save(Error* error = nullptr) = 0;
|
||||
virtual void Clear() = 0;
|
||||
virtual bool IsEmpty() = 0;
|
||||
|
||||
virtual bool GetIntValue(const char* section, const char* key, s32* value) const = 0;
|
||||
virtual bool GetUIntValue(const char* section, const char* key, u32* value) const = 0;
|
||||
@ -46,6 +47,8 @@ public:
|
||||
virtual bool ContainsValue(const char* section, const char* key) const = 0;
|
||||
virtual void DeleteValue(const char* section, const char* key) = 0;
|
||||
virtual void ClearSection(const char* section) = 0;
|
||||
virtual void RemoveSection(const char* section) = 0;
|
||||
virtual void RemoveEmptySections() = 0;
|
||||
|
||||
ALWAYS_INLINE s32 GetIntValue(const char* section, const char* key, s32 default_value = 0) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user