mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
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")
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user