aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2022-05-16 14:37:00 -0400
committerRyan Ofsky <ryan@ofsky.org>2022-05-19 11:32:56 -0400
commitf9fdcec7e932843a91ddf7f377e00bd2a6efb82a (patch)
tree445d6149d3336842aa63ee000d64854e834b54a4 /src/util
parent77fabffef4ea840ee15c97061048fe8443d74658 (diff)
downloadbitcoin-f9fdcec7e932843a91ddf7f377e00bd2a6efb82a.tar.xz
settings: Add resetSettings() method
Allows the GUI to clear settings.json file and save settings.json.bak file when GUI "Reset Options" button is pressed or -resetguisettings command line option is used. (GUI code already backs up and resets the "guisettings.ini" file this way, so this just makes the same behavior possible for "settings.json")
Diffstat (limited to 'src/util')
-rw-r--r--src/util/system.cpp9
-rw-r--r--src/util/system.h7
2 files changed, 10 insertions, 6 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp
index 87d3be9d23..fa2e564791 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -526,12 +526,15 @@ bool ArgsManager::InitSettings(std::string& error)
return true;
}
-bool ArgsManager::GetSettingsPath(fs::path* filepath, bool temp) const
+bool ArgsManager::GetSettingsPath(fs::path* filepath, bool temp, bool backup) const
{
fs::path settings = GetPathArg("-settings", fs::path{BITCOIN_SETTINGS_FILENAME});
if (settings.empty()) {
return false;
}
+ if (backup) {
+ settings += ".bak";
+ }
if (filepath) {
*filepath = fsbridge::AbsPathJoin(GetDataDirNet(), temp ? settings + ".tmp" : settings);
}
@@ -572,10 +575,10 @@ bool ArgsManager::ReadSettingsFile(std::vector<std::string>* errors)
return true;
}
-bool ArgsManager::WriteSettingsFile(std::vector<std::string>* errors) const
+bool ArgsManager::WriteSettingsFile(std::vector<std::string>* errors, bool backup) const
{
fs::path path, path_tmp;
- if (!GetSettingsPath(&path, /* temp= */ false) || !GetSettingsPath(&path_tmp, /* temp= */ true)) {
+ if (!GetSettingsPath(&path, /*temp=*/false, backup) || !GetSettingsPath(&path_tmp, /*temp=*/true, backup)) {
throw std::logic_error("Attempt to write settings file when dynamic settings are disabled.");
}
diff --git a/src/util/system.h b/src/util/system.h
index bfc9698221..6af4f1dc18 100644
--- a/src/util/system.h
+++ b/src/util/system.h
@@ -440,7 +440,7 @@ protected:
* Get settings file path, or return false if read-write settings were
* disabled with -nosettings.
*/
- bool GetSettingsPath(fs::path* filepath = nullptr, bool temp = false) const;
+ bool GetSettingsPath(fs::path* filepath = nullptr, bool temp = false, bool backup = false) const;
/**
* Read settings file. Push errors to vector, or log them if null.
@@ -448,9 +448,10 @@ protected:
bool ReadSettingsFile(std::vector<std::string>* errors = nullptr);
/**
- * Write settings file. Push errors to vector, or log them if null.
+ * Write settings file or backup settings file. Push errors to vector, or
+ * log them if null.
*/
- bool WriteSettingsFile(std::vector<std::string>* errors = nullptr) const;
+ bool WriteSettingsFile(std::vector<std::string>* errors = nullptr, bool backup = false) const;
/**
* Get current setting from config file or read/write settings file,