Browse Source

SETTINGS_MANAGER: Fix bug: ensure the destination folder exists.

Better fix than a0df876d
For new users, if this folder does not exist, saving colors does not work,
because if this folder does not exist, it is not created.
pull/16/head
jean-pierre charras 5 years ago
parent
commit
276d77a1d7
  1. 23
      common/settings/json_settings.cpp
  2. 4
      common/settings/settings_manager.cpp

23
common/settings/json_settings.cpp

@ -326,6 +326,14 @@ bool JSON_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce )
return false;
}
// Ensure the path exists, and create it if not.
if( !path.DirExists() && !path.Mkdir() )
{
wxLogTrace( traceSettings, "Warning: could not create path %s, can't save %s",
path.GetPath(), GetFullFilename() );
return false;
}
if( ( path.FileExists() && !path.IsFileWritable() ) ||
( !path.FileExists() && !path.IsDirWritable() ) )
{
@ -353,13 +361,6 @@ bool JSON_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce )
return false;
}
if( !path.DirExists() && !path.Mkdir() )
{
wxLogTrace( traceSettings, "Warning: could not create path %s, can't save %s",
path.GetPath(), GetFullFilename() );
return false;
}
wxLogTrace( traceSettings, "Saving %s", GetFullFilename() );
LOCALE_IO dummy;
@ -448,7 +449,7 @@ nlohmann::json::json_pointer JSON_SETTINGS::PointerFromString( std::string aPath
}
bool JSON_SETTINGS::SetIfPresent( const nlohmann::json& aObj, const std::string& aPath,
bool JSON_SETTINGS::SetIfPresent( const nlohmann::json& aObj, const std::string& aPath,
wxString& aTarget )
{
nlohmann::json::json_pointer ptr = PointerFromString( aPath );
@ -463,7 +464,7 @@ bool JSON_SETTINGS::SetIfPresent( const nlohmann::json& aObj, const std::string&
}
bool JSON_SETTINGS::SetIfPresent( const nlohmann::json& aObj, const std::string& aPath,
bool JSON_SETTINGS::SetIfPresent( const nlohmann::json& aObj, const std::string& aPath,
bool& aTarget )
{
nlohmann::json::json_pointer ptr = PointerFromString( aPath );
@ -478,7 +479,7 @@ bool JSON_SETTINGS::SetIfPresent( const nlohmann::json& aObj, const std::string&
}
bool JSON_SETTINGS::SetIfPresent( const nlohmann::json& aObj, const std::string& aPath,
bool JSON_SETTINGS::SetIfPresent( const nlohmann::json& aObj, const std::string& aPath,
int& aTarget )
{
nlohmann::json::json_pointer ptr = PointerFromString( aPath );
@ -493,7 +494,7 @@ bool JSON_SETTINGS::SetIfPresent( const nlohmann::json& aObj, const std::string&
}
bool JSON_SETTINGS::SetIfPresent( const nlohmann::json& aObj, const std::string& aPath,
bool JSON_SETTINGS::SetIfPresent( const nlohmann::json& aObj, const std::string& aPath,
unsigned int& aTarget )
{
nlohmann::json::json_pointer ptr = PointerFromString( aPath );

4
common/settings/settings_manager.cpp

@ -326,10 +326,6 @@ void SETTINGS_MANAGER::SaveColorSettings( COLOR_SETTINGS* aSettings, const std::
( *aSettings )[ptr].update( backup );
aSettings->Load();
// Ensure the folder to store the config exists:
if( !wxDir::Exists( SETTINGS_MANAGER::GetColorSettingsPath() ) )
wxDir::Make( SETTINGS_MANAGER::GetColorSettingsPath() );
aSettings->SaveToFile( path, true );
}

Loading…
Cancel
Save