mirror of https://github.com/PCSX2/pcsx2.git
SettingsInterface: Add Error to Save()
This commit is contained in:
parent
81502e6c7d
commit
332be6c771
|
@ -1,15 +1,17 @@
|
||||||
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
||||||
// SPDX-License-Identifier: LGPL-3.0+
|
// SPDX-License-Identifier: LGPL-3.0+
|
||||||
|
|
||||||
#include "common/MemorySettingsInterface.h"
|
#include "MemorySettingsInterface.h"
|
||||||
#include "common/StringUtil.h"
|
#include "Error.h"
|
||||||
|
#include "StringUtil.h"
|
||||||
|
|
||||||
MemorySettingsInterface::MemorySettingsInterface() = default;
|
MemorySettingsInterface::MemorySettingsInterface() = default;
|
||||||
|
|
||||||
MemorySettingsInterface::~MemorySettingsInterface() = default;
|
MemorySettingsInterface::~MemorySettingsInterface() = default;
|
||||||
|
|
||||||
bool MemorySettingsInterface::Save()
|
bool MemorySettingsInterface::Save(Error* error)
|
||||||
{
|
{
|
||||||
|
Error::SetStringView(error, "Memory settings cannot be saved.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
||||||
// SPDX-License-Identifier: LGPL-3.0+
|
// SPDX-License-Identifier: LGPL-3.0+
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@ -12,7 +12,7 @@ public:
|
||||||
MemorySettingsInterface();
|
MemorySettingsInterface();
|
||||||
~MemorySettingsInterface();
|
~MemorySettingsInterface();
|
||||||
|
|
||||||
bool Save() override;
|
bool Save(Error* error = nullptr) override;
|
||||||
|
|
||||||
void Clear() override;
|
void Clear() override;
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
||||||
// SPDX-License-Identifier: LGPL-3.0+
|
// SPDX-License-Identifier: LGPL-3.0+
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Pcsx2Defs.h"
|
#include "Pcsx2Defs.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class Error;
|
||||||
|
|
||||||
class SettingsInterface
|
class SettingsInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~SettingsInterface() = default;
|
virtual ~SettingsInterface() = default;
|
||||||
|
|
||||||
virtual bool Save() = 0;
|
virtual bool Save(Error* error = nullptr) = 0;
|
||||||
virtual void Clear() = 0;
|
virtual void Clear() = 0;
|
||||||
|
|
||||||
virtual bool GetIntValue(const char* section, const char* key, int* value) const = 0;
|
virtual bool GetIntValue(const char* section, const char* key, int* value) const = 0;
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
||||||
// SPDX-License-Identifier: LGPL-3.0+
|
// SPDX-License-Identifier: LGPL-3.0+
|
||||||
|
|
||||||
#include "INISettingsInterface.h"
|
#include "INISettingsInterface.h"
|
||||||
|
|
||||||
|
#include "common/Error.h"
|
||||||
#include "common/FileSystem.h"
|
#include "common/FileSystem.h"
|
||||||
#include "common/Console.h"
|
#include "common/Console.h"
|
||||||
#include "common/StringUtil.h"
|
#include "common/StringUtil.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
@ -66,15 +69,18 @@ bool INISettingsInterface::Load()
|
||||||
return (err == SI_OK);
|
return (err == SI_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool INISettingsInterface::Save()
|
bool INISettingsInterface::Save(Error* error)
|
||||||
{
|
{
|
||||||
if (m_filename.empty())
|
if (m_filename.empty())
|
||||||
|
{
|
||||||
|
Error::SetStringView(error, "Filename is not set.");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_lock lock(s_ini_load_save_mutex);
|
std::unique_lock lock(s_ini_load_save_mutex);
|
||||||
std::string temp_filename(GetTemporaryFileName(m_filename));
|
std::string temp_filename(GetTemporaryFileName(m_filename));
|
||||||
SI_Error err = SI_FAIL;
|
SI_Error err = SI_FAIL;
|
||||||
std::FILE* fp = FileSystem::OpenCFile(temp_filename.c_str(), "wb");
|
std::FILE* fp = FileSystem::OpenCFile(temp_filename.c_str(), "wb", error);
|
||||||
if (fp)
|
if (fp)
|
||||||
{
|
{
|
||||||
err = m_ini.SaveFile(fp, false);
|
err = m_ini.SaveFile(fp, false);
|
||||||
|
@ -82,10 +88,12 @@ bool INISettingsInterface::Save()
|
||||||
|
|
||||||
if (err != SI_OK)
|
if (err != SI_OK)
|
||||||
{
|
{
|
||||||
|
Error::SetStringFmt(error, "INI SaveFile() failed: {}", static_cast<int>(err));
|
||||||
|
|
||||||
// remove temporary file
|
// remove temporary file
|
||||||
FileSystem::DeleteFilePath(temp_filename.c_str());
|
FileSystem::DeleteFilePath(temp_filename.c_str());
|
||||||
}
|
}
|
||||||
else if (!FileSystem::RenamePath(temp_filename.c_str(), m_filename.c_str()))
|
else if (!FileSystem::RenamePath(temp_filename.c_str(), m_filename.c_str(), error))
|
||||||
{
|
{
|
||||||
Console.Error("Failed to rename '%s' to '%s'", temp_filename.c_str(), m_filename.c_str());
|
Console.Error("Failed to rename '%s' to '%s'", temp_filename.c_str(), m_filename.c_str());
|
||||||
FileSystem::DeleteFilePath(temp_filename.c_str());
|
FileSystem::DeleteFilePath(temp_filename.c_str());
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
||||||
// SPDX-License-Identifier: LGPL-3.0+
|
// SPDX-License-Identifier: LGPL-3.0+
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@ -20,7 +20,7 @@ public:
|
||||||
bool IsDirty() const { return m_dirty; }
|
bool IsDirty() const { return m_dirty; }
|
||||||
|
|
||||||
bool Load();
|
bool Load();
|
||||||
bool Save() override;
|
bool Save(Error* error = nullptr) override;
|
||||||
|
|
||||||
void Clear() override;
|
void Clear() override;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
||||||
// SPDX-License-Identifier: LGPL-3.0+
|
// SPDX-License-Identifier: LGPL-3.0+
|
||||||
|
|
||||||
#include "LayeredSettingsInterface.h"
|
#include "LayeredSettingsInterface.h"
|
||||||
|
|
||||||
#include "common/Assertions.h"
|
#include "common/Assertions.h"
|
||||||
|
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
@ -10,7 +11,7 @@ LayeredSettingsInterface::LayeredSettingsInterface() = default;
|
||||||
|
|
||||||
LayeredSettingsInterface::~LayeredSettingsInterface() = default;
|
LayeredSettingsInterface::~LayeredSettingsInterface() = default;
|
||||||
|
|
||||||
bool LayeredSettingsInterface::Save()
|
bool LayeredSettingsInterface::Save(Error* error)
|
||||||
{
|
{
|
||||||
pxFailRel("Attempting to save layered settings interface");
|
pxFailRel("Attempting to save layered settings interface");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
||||||
// SPDX-License-Identifier: LGPL-3.0+
|
// SPDX-License-Identifier: LGPL-3.0+
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common/SettingsInterface.h"
|
#include "common/SettingsInterface.h"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
class LayeredSettingsInterface final : public SettingsInterface
|
class LayeredSettingsInterface final : public SettingsInterface
|
||||||
|
@ -23,7 +25,7 @@ public:
|
||||||
SettingsInterface* GetLayer(Layer layer) const { return m_layers[layer]; }
|
SettingsInterface* GetLayer(Layer layer) const { return m_layers[layer]; }
|
||||||
void SetLayer(Layer layer, SettingsInterface* sif) { m_layers[layer] = sif; }
|
void SetLayer(Layer layer, SettingsInterface* sif) { m_layers[layer] = sif; }
|
||||||
|
|
||||||
bool Save() override;
|
bool Save(Error* error = nullptr) override;
|
||||||
|
|
||||||
void Clear() override;
|
void Clear() override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue