Convert strings to wide when using wxString routines

WxString does not allocate space for wide strings needed during
conversion unless the string is explicitly wide.  This can cause buffer
over/underflow

Fixes https://gitlab.com/kicad/code/kicad/issues/10605
This commit is contained in:
Seth Hillbrand 2022-02-03 12:57:26 -08:00
parent ccf2a63f45
commit 7601a3385f
7 changed files with 85 additions and 83 deletions

View File

@ -460,7 +460,7 @@ bool PROJECT_FILE::MigrateFromLegacy( wxConfigBase* aCfg )
wxString entry; wxString entry;
nlohmann::json arr = nlohmann::json::array(); nlohmann::json arr = nlohmann::json::array();
wxLogTrace( traceSettings, "Migrating sheet names" ); wxLogTrace( traceSettings, wxT( "Migrating sheet names" ) );
aCfg->SetPath( wxT( "/sheetnames" ) ); aCfg->SetPath( wxT( "/sheetnames" ) );
@ -470,7 +470,8 @@ bool PROJECT_FILE::MigrateFromLegacy( wxConfigBase* aCfg )
if( tokens.size() == 2 ) if( tokens.size() == 2 )
{ {
wxLogTrace( traceSettings, "%d: %s = %s", sheet, tokens[0], tokens[1] ); wxLogTrace( traceSettings, wxT( "%d: %s = %s" ), sheet, tokens[0],
tokens[1] );
arr.push_back( nlohmann::json::array( { tokens[0], tokens[1] } ) ); arr.push_back( nlohmann::json::array( { tokens[0], tokens[1] } ) );
} }
} }
@ -490,7 +491,7 @@ bool PROJECT_FILE::MigrateFromLegacy( wxConfigBase* aCfg )
auto loadLegacyPairs = auto loadLegacyPairs =
[&]( const std::string& aGroup ) -> bool [&]( const std::string& aGroup ) -> bool
{ {
wxLogTrace( traceSettings, "Migrating group %s", aGroup ); wxLogTrace( traceSettings, wxT( "Migrating group %s" ), aGroup );
bool success = true; bool success = true;
wxString keyStr; wxString keyStr;
wxString val; wxString val;
@ -504,7 +505,7 @@ bool PROJECT_FILE::MigrateFromLegacy( wxConfigBase* aCfg )
std::string key( keyStr.ToUTF8() ); std::string key( keyStr.ToUTF8() );
wxLogTrace( traceSettings, " %s = %s", key, val ); wxLogTrace( traceSettings, wxT( " %s = %s" ), key, val );
try try
{ {

View File

@ -309,13 +309,13 @@ bool COLOR_SETTINGS::migrateSchema0to1()
if( !m_manager ) if( !m_manager )
{ {
wxLogTrace( traceSettings, "Error: COLOR_SETTINGS migration cannot run unmanaged!" ); wxLogTrace( traceSettings, wxT( "Error: COLOR_SETTINGS migration cannot run unmanaged!" ) );
return false; return false;
} }
if( !Contains( "fpedit" ) ) if( !Contains( "fpedit" ) )
{ {
wxLogTrace( traceSettings, "migrateSchema0to1: %s doesn't have fpedit settings; skipping.", wxLogTrace( traceSettings, wxT( "migrateSchema0to1: %s doesn't have fpedit settings; skipping." ),
m_filename ); m_filename );
return true; return true;
} }

View File

@ -346,7 +346,7 @@ bool COMMON_SETTINGS::migrateSchema0to1()
} }
catch( ... ) catch( ... )
{ {
wxLogTrace( traceSettings, "COMMON_SETTINGS::Migrate 0->1: mousewheel_pan not found" ); wxLogTrace( traceSettings, wxT( "COMMON_SETTINGS::Migrate 0->1: mousewheel_pan not found" ) );
} }
if( mwp ) if( mwp )
@ -383,7 +383,7 @@ bool COMMON_SETTINGS::migrateSchema1to2()
} }
catch( ... ) catch( ... )
{ {
wxLogTrace( traceSettings, "COMMON_SETTINGS::Migrate 1->2: prefer_select_to_drag not found" ); wxLogTrace( traceSettings, wxT( "COMMON_SETTINGS::Migrate 1->2: prefer_select_to_drag not found" ) );
} }
if( prefer_selection ) if( prefer_selection )
@ -418,7 +418,7 @@ bool COMMON_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
{ {
if( envVarBlacklist.count( key ) ) if( envVarBlacklist.count( key ) )
{ {
wxLogTrace( traceSettings, "Migrate Env: %s is blacklisted; skipping.", key ); wxLogTrace( traceSettings, wxT( "Migrate Env: %s is blacklisted; skipping." ), key );
continue; continue;
} }
@ -428,7 +428,7 @@ bool COMMON_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
{ {
ptr.push_back( key.ToStdString() ); ptr.push_back( key.ToStdString() );
wxLogTrace( traceSettings, "Migrate Env: %s=%s", ptr.to_string(), value ); wxLogTrace( traceSettings, wxT( "Migrate Env: %s=%s" ), ptr.to_string(), value );
( *m_internals )[ptr] = value.ToUTF8(); ( *m_internals )[ptr] = value.ToUTF8();
ptr.pop_back(); ptr.pop_back();

View File

@ -83,7 +83,7 @@ JSON_SETTINGS::JSON_SETTINGS( const wxString& aFilename, SETTINGS_LOC aLocation,
} }
catch( ... ) catch( ... )
{ {
wxLogTrace( traceSettings, "Error: Could not create filename field for %s", wxLogTrace( traceSettings, wxT( "Error: Could not create filename field for %s" ),
GetFullFilename() ); GetFullFilename() );
} }
@ -143,7 +143,7 @@ void JSON_SETTINGS::Load()
catch( ... ) catch( ... )
{ {
// Skip unreadable parameters in file // Skip unreadable parameters in file
wxLogTrace( traceSettings, "param '%s' load err", param->GetJsonPath().c_str() ); wxLogTrace( traceSettings, wxT( "param '%s' load err" ), param->GetJsonPath().c_str() );
} }
} }
} }
@ -172,7 +172,7 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory )
if( !wxCopyFile( aPath.GetFullPath(), temp.GetFullPath() ) ) if( !wxCopyFile( aPath.GetFullPath(), temp.GetFullPath() ) )
{ {
wxLogTrace( traceSettings, "%s: could not create temp file for migration", wxLogTrace( traceSettings, wxT( "%s: could not create temp file for migration" ),
GetFullFilename() ); GetFullFilename() );
} }
else else
@ -190,12 +190,12 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory )
if( !MigrateFromLegacy( cfg.get() ) ) if( !MigrateFromLegacy( cfg.get() ) )
{ {
wxLogTrace( traceSettings, wxLogTrace( traceSettings,
"%s: migrated; not all settings were found in legacy file", wxT( "%s: migrated; not all settings were found in legacy file" ),
GetFullFilename() ); GetFullFilename() );
} }
else else
{ {
wxLogTrace( traceSettings, "%s: migrated from legacy format", GetFullFilename() ); wxLogTrace( traceSettings, wxT( "%s: migrated from legacy format" ), GetFullFilename() );
} }
if( backed_up ) if( backed_up )
@ -205,14 +205,14 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory )
if( !wxCopyFile( temp.GetFullPath(), aPath.GetFullPath() ) ) if( !wxCopyFile( temp.GetFullPath(), aPath.GetFullPath() ) )
{ {
wxLogTrace( traceSettings, wxLogTrace( traceSettings,
"migrate; copy temp file %s to %s failed", wxT( "migrate; copy temp file %s to %s failed" ),
temp.GetFullPath(), aPath.GetFullPath() ); temp.GetFullPath(), aPath.GetFullPath() );
} }
if( !wxRemoveFile( temp.GetFullPath() ) ) if( !wxRemoveFile( temp.GetFullPath() ) )
{ {
wxLogTrace( traceSettings, wxLogTrace( traceSettings,
"migrate; failed to remove temp file %s", wxT( "migrate; failed to remove temp file %s" ),
temp.GetFullPath() ); temp.GetFullPath() );
} }
} }
@ -282,14 +282,14 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory )
} }
catch( ... ) catch( ... )
{ {
wxLogTrace( traceSettings, "%s: file version could not be read!", wxLogTrace( traceSettings, wxT( "%s: file version could not be read!" ),
GetFullFilename() ); GetFullFilename() );
success = false; success = false;
} }
if( filever >= 0 && filever < m_schemaVersion ) if( filever >= 0 && filever < m_schemaVersion )
{ {
wxLogTrace( traceSettings, "%s: attempting migration from version %d to %d", wxLogTrace( traceSettings, wxT( "%s: attempting migration from version %d to %d" ),
GetFullFilename(), filever, m_schemaVersion ); GetFullFilename(), filever, m_schemaVersion );
if( Migrate() ) if( Migrate() )
@ -298,27 +298,27 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory )
} }
else else
{ {
wxLogTrace( traceSettings, "%s: migration failed!", GetFullFilename() ); wxLogTrace( traceSettings, wxT( "%s: migration failed!" ), GetFullFilename() );
} }
} }
else if( filever > m_schemaVersion ) else if( filever > m_schemaVersion )
{ {
wxLogTrace( traceSettings, wxLogTrace( traceSettings,
"%s: warning: file version %d is newer than latest (%d)", wxT( "%s: warning: file version %d is newer than latest (%d)" ),
GetFullFilename(), filever, m_schemaVersion ); GetFullFilename(), filever, m_schemaVersion );
} }
} }
else else
{ {
wxLogTrace( traceSettings, "%s exists but can't be opened for read", wxLogTrace( traceSettings, wxT( "%s exists but can't be opened for read" ),
GetFullFilename() ); GetFullFilename() );
} }
} }
catch( nlohmann::json::parse_error& error ) catch( nlohmann::json::parse_error& error )
{ {
wxLogTrace( traceSettings, "Json parse error reading %s: %s", wxLogTrace( traceSettings, wxT( "Json parse error reading %s: %s" ),
path.GetFullPath(), error.what() ); path.GetFullPath(), error.what() );
wxLogTrace( traceSettings, "Attempting migration in case file is in legacy format" ); wxLogTrace( traceSettings, wxT( "Attempting migration in case file is in legacy format" ) );
migrateFromLegacy( path ); migrateFromLegacy( path );
} }
} }
@ -330,14 +330,14 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory )
for( auto settings : m_nested_settings ) for( auto settings : m_nested_settings )
settings->LoadFromFile(); settings->LoadFromFile();
wxLogTrace( traceSettings, "Loaded <%s> with schema %d", GetFullFilename(), m_schemaVersion ); wxLogTrace( traceSettings, wxT( "Loaded <%s> with schema %d" ), GetFullFilename(), m_schemaVersion );
// If we migrated, clean up the legacy file (with no extension) // If we migrated, clean up the legacy file (with no extension)
if( legacy_migrated || migrated ) if( legacy_migrated || migrated )
{ {
if( legacy_migrated && m_deleteLegacyAfterMigration && !wxRemoveFile( path.GetFullPath() ) ) if( legacy_migrated && m_deleteLegacyAfterMigration && !wxRemoveFile( path.GetFullPath() ) )
{ {
wxLogTrace( traceSettings, "Warning: could not remove legacy file %s", wxLogTrace( traceSettings, wxT( "Warning: could not remove legacy file %s" ),
path.GetFullPath() ); path.GetFullPath() );
} }
@ -396,7 +396,7 @@ bool JSON_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce )
if( !m_createIfMissing && !path.FileExists() ) if( !m_createIfMissing && !path.FileExists() )
{ {
wxLogTrace( traceSettings, wxLogTrace( traceSettings,
"File for %s doesn't exist and m_createIfMissing == false; not saving", wxT( "File for %s doesn't exist and m_createIfMissing == false; not saving" ),
GetFullFilename() ); GetFullFilename() );
return false; return false;
} }
@ -404,7 +404,7 @@ bool JSON_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce )
// Ensure the path exists, and create it if not. // Ensure the path exists, and create it if not.
if( !path.DirExists() && !path.Mkdir() ) if( !path.DirExists() && !path.Mkdir() )
{ {
wxLogTrace( traceSettings, "Warning: could not create path %s, can't save %s", wxLogTrace( traceSettings, wxT( "Warning: could not create path %s, can't save %s" ),
path.GetPath(), GetFullFilename() ); path.GetPath(), GetFullFilename() );
return false; return false;
} }
@ -412,7 +412,7 @@ bool JSON_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce )
if( ( path.FileExists() && !path.IsFileWritable() ) || if( ( path.FileExists() && !path.IsFileWritable() ) ||
( !path.FileExists() && !path.IsDirWritable() ) ) ( !path.FileExists() && !path.IsDirWritable() ) )
{ {
wxLogTrace( traceSettings, "File for %s is read-only; not saving", GetFullFilename() ); wxLogTrace( traceSettings, wxT( "File for %s is read-only; not saving" ), GetFullFilename() );
return false; return false;
} }
@ -425,18 +425,18 @@ bool JSON_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce )
if( !modified && !aForce && path.FileExists() ) if( !modified && !aForce && path.FileExists() )
{ {
wxLogTrace( traceSettings, "%s contents not modified, skipping save", GetFullFilename() ); wxLogTrace( traceSettings, wxT( "%s contents not modified, skipping save" ), GetFullFilename() );
return false; return false;
} }
else if( !modified && !aForce && !m_createIfDefault ) else if( !modified && !aForce && !m_createIfDefault )
{ {
wxLogTrace( traceSettings, wxLogTrace( traceSettings,
"%s contents still default and m_createIfDefault == false; not saving", wxT( "%s contents still default and m_createIfDefault == false; not saving" ),
GetFullFilename() ); GetFullFilename() );
return false; return false;
} }
wxLogTrace( traceSettings, "Saving %s", GetFullFilename() ); wxLogTrace( traceSettings, wxT( "Saving %s" ), GetFullFilename() );
LOCALE_IO dummy; LOCALE_IO dummy;
bool success = true; bool success = true;
@ -451,19 +451,19 @@ bool JSON_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce )
if( !fileStream.IsOk() if( !fileStream.IsOk()
|| !fileStream.WriteAll( buffer.str().c_str(), buffer.str().size() ) ) || !fileStream.WriteAll( buffer.str().c_str(), buffer.str().size() ) )
{ {
wxLogTrace( traceSettings, "Warning: could not save %s", GetFullFilename() ); wxLogTrace( traceSettings, wxT( "Warning: could not save %s" ), GetFullFilename() );
success = false; success = false;
} }
} }
catch( nlohmann::json::exception& error ) catch( nlohmann::json::exception& error )
{ {
wxLogTrace( traceSettings, "Catch error: could not save %s. Json error %s", wxLogTrace( traceSettings, wxT( "Catch error: could not save %s. Json error %s" ),
GetFullFilename(), error.what() ); GetFullFilename(), error.what() );
success = false; success = false;
} }
catch( ... ) catch( ... )
{ {
wxLogTrace( traceSettings, "Error: could not save %s." ); wxLogTrace( traceSettings, wxT( "Error: could not save %s." ) );
success = false; success = false;
} }
@ -557,7 +557,7 @@ bool JSON_SETTINGS::Migrate()
{ {
if( !m_migrators.count( filever ) ) if( !m_migrators.count( filever ) )
{ {
wxLogTrace( traceSettings, "Migrator missing for %s version %d!", wxLogTrace( traceSettings, wxT( "Migrator missing for %s version %d!" ),
typeid( *this ).name(), filever ); typeid( *this ).name(), filever );
return false; return false;
} }
@ -566,14 +566,14 @@ bool JSON_SETTINGS::Migrate()
if( pair.second() ) if( pair.second() )
{ {
wxLogTrace( traceSettings, "Migrated %s from %d to %d", typeid( *this ).name(), wxLogTrace( traceSettings, wxT( "Migrated %s from %d to %d" ), typeid( *this ).name(),
filever, pair.first ); filever, pair.first );
filever = pair.first; filever = pair.first;
m_internals->At( "meta.version" ) = filever; m_internals->At( "meta.version" ) = filever;
} }
else else
{ {
wxLogTrace( traceSettings, "Migration failed for %s from %d to %d", wxLogTrace( traceSettings, wxT( "Migration failed for %s from %d to %d" ),
typeid( *this ).name(), filever, pair.first ); typeid( *this ).name(), filever, pair.first );
return false; return false;
} }
@ -586,7 +586,7 @@ bool JSON_SETTINGS::Migrate()
bool JSON_SETTINGS::MigrateFromLegacy( wxConfigBase* aLegacyConfig ) bool JSON_SETTINGS::MigrateFromLegacy( wxConfigBase* aLegacyConfig )
{ {
wxLogTrace( traceSettings, wxLogTrace( traceSettings,
"MigrateFromLegacy() not implemented for %s", typeid( *this ).name() ); wxT( "MigrateFromLegacy() not implemented for %s" ), typeid( *this ).name() );
return false; return false;
} }
@ -742,7 +742,7 @@ bool JSON_SETTINGS::fromLegacyColor( wxConfigBase* aConfig, const std::string& a
void JSON_SETTINGS::AddNestedSettings( NESTED_SETTINGS* aSettings ) void JSON_SETTINGS::AddNestedSettings( NESTED_SETTINGS* aSettings )
{ {
wxLogTrace( traceSettings, "AddNestedSettings %s", aSettings->GetFilename() ); wxLogTrace( traceSettings, wxT( "AddNestedSettings %s" ), aSettings->GetFilename() );
m_nested_settings.push_back( aSettings ); m_nested_settings.push_back( aSettings );
} }
@ -759,7 +759,7 @@ void JSON_SETTINGS::ReleaseNestedSettings( NESTED_SETTINGS* aSettings )
if( it != m_nested_settings.end() ) if( it != m_nested_settings.end() )
{ {
wxLogTrace( traceSettings, "Flush and release %s", ( *it )->GetFilename() ); wxLogTrace( traceSettings, wxT( "Flush and release %s" ), ( *it )->GetFilename() );
( *it )->SaveToFile(); ( *it )->SaveToFile();
m_nested_settings.erase( it ); m_nested_settings.erase( it );
} }

View File

@ -54,13 +54,13 @@ bool NESTED_SETTINGS::LoadFromFile( const wxString& aDirectory )
{ {
m_internals->update( m_parent->m_internals->at( ptr ) ); m_internals->update( m_parent->m_internals->at( ptr ) );
wxLogTrace( traceSettings, "Loaded NESTED_SETTINGS %s", GetFilename() ); wxLogTrace( traceSettings, wxT( "Loaded NESTED_SETTINGS %s" ), GetFilename() );
success = true; success = true;
} }
catch( ... ) catch( ... )
{ {
wxLogTrace( traceSettings, "NESTED_SETTINGS %s: Could not load from %s at %s", wxLogTrace( traceSettings, wxT( "NESTED_SETTINGS %s: Could not load from %s at %s" ),
m_filename, m_parent->GetFilename(), m_path ); m_filename, m_parent->GetFilename(), m_path );
} }
} }
@ -76,31 +76,32 @@ bool NESTED_SETTINGS::LoadFromFile( const wxString& aDirectory )
} }
catch( ... ) catch( ... )
{ {
wxLogTrace( traceSettings, "%s: nested settings version could not be read!", wxLogTrace( traceSettings, wxT( "%s: nested settings version could not be read!" ),
m_filename ); m_filename );
success = false; success = false;
} }
if( filever >= 0 && filever < m_schemaVersion ) if( filever >= 0 && filever < m_schemaVersion )
{ {
wxLogTrace( traceSettings, "%s: attempting migration from version %d to %d", wxLogTrace( traceSettings, wxT( "%s: attempting migration from version %d to %d" ),
m_filename, filever, m_schemaVersion ); m_filename, filever, m_schemaVersion );
if( !Migrate() ) if( !Migrate() )
{ {
wxLogTrace( traceSettings, "%s: migration failed!", GetFullFilename() ); wxLogTrace( traceSettings, wxT( "%s: migration failed!" ), GetFullFilename() );
success = false; success = false;
} }
} }
else if( filever > m_schemaVersion ) else if( filever > m_schemaVersion )
{ {
wxLogTrace( traceSettings, wxLogTrace( traceSettings,
"%s: warning: nested settings version %d is newer than latest (%d)", wxT( "%s: warning: nested settings version %d is newer than latest (%d)" ),
m_filename, filever, m_schemaVersion ); m_filename, filever, m_schemaVersion );
} }
else if( filever >= 0 ) else if( filever >= 0 )
{ {
wxLogTrace( traceSettings, "%s: schema version %d is current", m_filename, filever ); wxLogTrace( traceSettings, wxT( "%s: schema version %d is current" ),
m_filename, filever );
} }
} }

View File

@ -84,7 +84,7 @@ JSON_SETTINGS* SETTINGS_MANAGER::registerSettings( JSON_SETTINGS* aSettings, boo
ptr->SetManager( this ); ptr->SetManager( this );
wxLogTrace( traceSettings, "Registered new settings object <%s>", ptr->GetFullFilename() ); wxLogTrace( traceSettings, wxT( "Registered new settings object <%s>" ), ptr->GetFullFilename() );
if( aLoadNow ) if( aLoadNow )
ptr->LoadFromFile( GetPathForSettingsFile( ptr.get() ) ); ptr->LoadFromFile( GetPathForSettingsFile( ptr.get() ) );
@ -140,7 +140,7 @@ void SETTINGS_MANAGER::Save( JSON_SETTINGS* aSettings )
if( it != m_settings.end() ) if( it != m_settings.end() )
{ {
wxLogTrace( traceSettings, "Saving %s", ( *it )->GetFullFilename() ); wxLogTrace( traceSettings, wxT( "Saving %s" ), ( *it )->GetFullFilename() );
( *it )->SaveToFile( GetPathForSettingsFile( it->get() ) ); ( *it )->SaveToFile( GetPathForSettingsFile( it->get() ) );
} }
} }
@ -156,7 +156,7 @@ void SETTINGS_MANAGER::FlushAndRelease( JSON_SETTINGS* aSettings, bool aSave )
if( it != m_settings.end() ) if( it != m_settings.end() )
{ {
wxLogTrace( traceSettings, "Flush and release %s", ( *it )->GetFullFilename() ); wxLogTrace( traceSettings, wxT( "Flush and release %s" ), ( *it )->GetFullFilename() );
if( aSave ) if( aSave )
( *it )->SaveToFile( GetPathForSettingsFile( it->get() ) ); ( *it )->SaveToFile( GetPathForSettingsFile( it->get() ) );
@ -198,13 +198,13 @@ COLOR_SETTINGS* SETTINGS_MANAGER::GetColorSettings( const wxString& aName )
COLOR_SETTINGS* SETTINGS_MANAGER::loadColorSettingsByName( const wxString& aName ) COLOR_SETTINGS* SETTINGS_MANAGER::loadColorSettingsByName( const wxString& aName )
{ {
wxLogTrace( traceSettings, "Attempting to load color theme %s", aName ); wxLogTrace( traceSettings, wxT( "Attempting to load color theme %s" ), aName );
wxFileName fn( GetColorSettingsPath(), aName, "json" ); wxFileName fn( GetColorSettingsPath(), aName, "json" );
if( !fn.IsOk() || !fn.Exists() ) if( !fn.IsOk() || !fn.Exists() )
{ {
wxLogTrace( traceSettings, "Theme file %s.json not found, falling back to user", aName ); wxLogTrace( traceSettings, wxT( "Theme file %s.json not found, falling back to user" ), aName );
return nullptr; return nullptr;
} }
@ -212,7 +212,7 @@ COLOR_SETTINGS* SETTINGS_MANAGER::loadColorSettingsByName( const wxString& aName
if( settings->GetFilename() != aName.ToStdString() ) if( settings->GetFilename() != aName.ToStdString() )
{ {
wxLogTrace( traceSettings, "Warning: stored filename is actually %s, ", wxLogTrace( traceSettings, wxT( "Warning: stored filename is actually %s, " ),
settings->GetFilename() ); settings->GetFilename() );
} }
@ -352,14 +352,14 @@ void SETTINGS_MANAGER::SaveColorSettings( COLOR_SETTINGS* aSettings, const std::
if( !aSettings->Store() ) if( !aSettings->Store() )
{ {
wxLogTrace( traceSettings, "Color scheme %s not modified; skipping save", wxLogTrace( traceSettings, wxT( "Color scheme %s not modified; skipping save" ),
aNamespace ); aNamespace );
return; return;
} }
wxASSERT( aSettings->Contains( aNamespace ) ); wxASSERT( aSettings->Contains( aNamespace ) );
wxLogTrace( traceSettings, "Saving color scheme %s, preserving %s", wxLogTrace( traceSettings, wxT( "Saving color scheme %s, preserving %s" ),
aSettings->GetFilename(), aSettings->GetFilename(),
aNamespace ); aNamespace );
@ -396,7 +396,7 @@ wxString SETTINGS_MANAGER::GetPathForSettingsFile( JSON_SETTINGS* aSettings )
return ""; return "";
default: default:
wxASSERT_MSG( false, "Unknown settings location!" ); wxASSERT_MSG( false, wxT( "Unknown settings location!" ) );
} }
return ""; return "";
@ -445,7 +445,7 @@ public:
path.Replace( m_src, m_dest, false ); path.Replace( m_src, m_dest, false );
file.SetPath( path ); file.SetPath( path );
wxLogTrace( traceSettings, "Copying %s to %s", aSrcFilePath, file.GetFullPath() ); wxLogTrace( traceSettings, wxT( "Copying %s to %s" ), aSrcFilePath, file.GetFullPath() );
// For now, just copy everything // For now, just copy everything
KiCopyFile( aSrcFilePath, file.GetFullPath(), m_errors ); KiCopyFile( aSrcFilePath, file.GetFullPath(), m_errors );
@ -483,12 +483,12 @@ bool SETTINGS_MANAGER::MigrateIfNeeded()
{ {
if( m_headless ) if( m_headless )
{ {
wxLogTrace( traceSettings, "Settings migration not checked; running headless" ); wxLogTrace( traceSettings, wxT( "Settings migration not checked; running headless" ) );
return false; return false;
} }
wxFileName path( GetUserSettingsPath(), "" ); wxFileName path( GetUserSettingsPath(), "" );
wxLogTrace( traceSettings, "Using settings path %s", path.GetFullPath() ); wxLogTrace( traceSettings, wxT( "Using settings path %s" ), path.GetFullPath() );
if( path.DirExists() ) if( path.DirExists() )
{ {
@ -498,7 +498,7 @@ bool SETTINGS_MANAGER::MigrateIfNeeded()
if( common.Exists() ) if( common.Exists() )
{ {
wxLogTrace( traceSettings, "Path exists and has a kicad_common, continuing!" ); wxLogTrace( traceSettings, wxT( "Path exists and has a kicad_common, continuing!" ) );
return true; return true;
} }
} }
@ -508,23 +508,23 @@ bool SETTINGS_MANAGER::MigrateIfNeeded()
if( dlg.ShowModal() != wxID_OK ) if( dlg.ShowModal() != wxID_OK )
{ {
wxLogTrace( traceSettings, "Migration dialog canceled; exiting" ); wxLogTrace( traceSettings, wxT( "Migration dialog canceled; exiting" ) );
return false; return false;
} }
if( !path.DirExists() ) if( !path.DirExists() )
{ {
wxLogTrace( traceSettings, "Path didn't exist; creating it" ); wxLogTrace( traceSettings, wxT( "Path didn't exist; creating it" ) );
path.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ); path.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
} }
if( m_migration_source.IsEmpty() ) if( m_migration_source.IsEmpty() )
{ {
wxLogTrace( traceSettings, "No migration source given; starting with defaults" ); wxLogTrace( traceSettings, wxT( "No migration source given; starting with defaults" ) );
return true; return true;
} }
wxLogTrace( traceSettings, "Migrating from path %s", m_migration_source ); wxLogTrace( traceSettings, wxT( "Migrating from path %s" ), m_migration_source );
MIGRATION_TRAVERSER traverser( m_migration_source, path.GetFullPath(), m_migrateLibraryTables ); MIGRATION_TRAVERSER traverser( m_migration_source, path.GetFullPath(), m_migrateLibraryTables );
wxDir source_dir( m_migration_source ); wxDir source_dir( m_migration_source );
@ -611,7 +611,7 @@ bool SETTINGS_MANAGER::GetPreviousVersionPaths( std::vector<wxString>* aPaths )
if( IsSettingsPathValid( sub_path ) ) if( IsSettingsPathValid( sub_path ) )
{ {
aPaths->push_back( sub_path ); aPaths->push_back( sub_path );
wxLogTrace( traceSettings, "GetPreviousVersionName: %s is valid", sub_path ); wxLogTrace( traceSettings, wxT( "GetPreviousVersionName: %s is valid" ), sub_path );
} }
} }
}; };
@ -627,12 +627,12 @@ bool SETTINGS_MANAGER::GetPreviousVersionPaths( std::vector<wxString>* aPaths )
if( !dir.Open( base_path.GetFullPath() ) ) if( !dir.Open( base_path.GetFullPath() ) )
{ {
wxLogTrace( traceSettings, "GetPreviousVersionName: could not open base path %s", wxLogTrace( traceSettings, wxT( "GetPreviousVersionName: could not open base path %s" ),
base_path.GetFullPath() ); base_path.GetFullPath() );
continue; continue;
} }
wxLogTrace( traceSettings, "GetPreviousVersionName: checking base path %s", wxLogTrace( traceSettings, wxT( "GetPreviousVersionName: checking base path %s" ),
base_path.GetFullPath() ); base_path.GetFullPath() );
if( dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS ) ) if( dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS ) )
@ -651,7 +651,7 @@ bool SETTINGS_MANAGER::GetPreviousVersionPaths( std::vector<wxString>* aPaths )
if( IsSettingsPathValid( dir.GetNameWithSep() ) ) if( IsSettingsPathValid( dir.GetNameWithSep() ) )
{ {
wxLogTrace( traceSettings, wxLogTrace( traceSettings,
"GetPreviousVersionName: root path %s is valid", dir.GetName() ); wxT( "GetPreviousVersionName: root path %s is valid" ), dir.GetName() );
aPaths->push_back( dir.GetName() ); aPaths->push_back( dir.GetName() );
} }
} }
@ -685,7 +685,7 @@ wxString SETTINGS_MANAGER::GetColorSettingsPath()
if( !wxMkdir( path.GetPath() ) ) if( !wxMkdir( path.GetPath() ) )
{ {
wxLogTrace( traceSettings, wxLogTrace( traceSettings,
"GetColorSettingsPath(): Path %s missing and could not be created!", wxT( "GetColorSettingsPath(): Path %s missing and could not be created!" ),
path.GetPath() ); path.GetPath() );
} }
} }
@ -747,7 +747,7 @@ int SETTINGS_MANAGER::compareVersions( const std::string& aFirst, const std::str
if( !extractVersion( aFirst, &a_maj, &a_min ) || !extractVersion( aSecond, &b_maj, &b_min ) ) if( !extractVersion( aFirst, &a_maj, &a_min ) || !extractVersion( aSecond, &b_maj, &b_min ) )
{ {
wxLogTrace( traceSettings, "compareSettingsVersions: bad input (%s, %s)", aFirst, aSecond ); wxLogTrace( traceSettings, wxT( "compareSettingsVersions: bad input (%s, %s)" ), aFirst, aSecond );
return -1; return -1;
} }
@ -822,7 +822,7 @@ bool SETTINGS_MANAGER::LoadProject( const wxString& aFullPath, bool aSetActive )
if( !lockFile ) if( !lockFile )
{ {
wxLogTrace( traceSettings, "Project %s is locked; opening read-only", fullPath ); wxLogTrace( traceSettings, wxT( "Project %s is locked; opening read-only" ), fullPath );
readOnly = true; readOnly = true;
} }
@ -843,7 +843,7 @@ bool SETTINGS_MANAGER::LoadProject( const wxString& aFullPath, bool aSetActive )
m_projects_list.erase( it ); m_projects_list.erase( it );
} }
wxLogTrace( traceSettings, "Load project %s", fullPath ); wxLogTrace( traceSettings, wxT( "Load project %s" ), fullPath );
std::unique_ptr<PROJECT> project = std::make_unique<PROJECT>(); std::unique_ptr<PROJECT> project = std::make_unique<PROJECT>();
project->setProjectFullName( fullPath ); project->setProjectFullName( fullPath );
@ -888,7 +888,7 @@ bool SETTINGS_MANAGER::UnloadProject( PROJECT* aProject, bool aSave )
return false; return false;
wxString projectPath = aProject->GetProjectFullName(); wxString projectPath = aProject->GetProjectFullName();
wxLogTrace( traceSettings, "Unload project %s", projectPath ); wxLogTrace( traceSettings, wxT( "Unload project %s" ), projectPath );
PROJECT* toRemove = m_projects.at( projectPath ); PROJECT* toRemove = m_projects.at( projectPath );
auto it = std::find_if( m_projects_list.begin(), m_projects_list.end(), auto it = std::find_if( m_projects_list.begin(), m_projects_list.end(),
@ -923,7 +923,7 @@ bool SETTINGS_MANAGER::UnloadProject( PROJECT* aProject, bool aSave )
PROJECT& SETTINGS_MANAGER::Prj() const PROJECT& SETTINGS_MANAGER::Prj() const
{ {
// No MDI yet: First project in the list is the active project // No MDI yet: First project in the list is the active project
wxASSERT_MSG( m_projects_list.size(), "no project in list" ); wxASSERT_MSG( m_projects_list.size(), wxT( "no project in list" ) );
return *m_projects_list.begin()->get(); return *m_projects_list.begin()->get();
} }
@ -1114,17 +1114,17 @@ bool SETTINGS_MANAGER::BackupProject( REPORTER& aReporter ) const
if( !target.DirExists() && !wxMkdir( target.GetPath() ) ) if( !target.DirExists() && !wxMkdir( target.GetPath() ) )
{ {
wxLogTrace( traceSettings, "Could not create project backup path %s", target.GetPath() ); wxLogTrace( traceSettings, wxT( "Could not create project backup path %s" ), target.GetPath() );
return false; return false;
} }
if( !target.IsDirWritable() ) if( !target.IsDirWritable() )
{ {
wxLogTrace( traceSettings, "Backup directory %s is not writable", target.GetPath() ); wxLogTrace( traceSettings, wxT( "Backup directory %s is not writable" ), target.GetPath() );
return false; return false;
} }
wxLogTrace( traceSettings, "Backing up project to %s", target.GetPath() ); wxLogTrace( traceSettings, wxT( "Backing up project to %s" ), target.GetPath() );
PROJECT_ARCHIVER archiver; PROJECT_ARCHIVER archiver;
@ -1191,11 +1191,11 @@ bool SETTINGS_MANAGER::TriggerBackupIfNeeded( REPORTER& aReporter ) const
if( !wxDirExists( backupPath ) ) if( !wxDirExists( backupPath ) )
{ {
wxLogTrace( traceSettings, "Backup path %s doesn't exist, creating it", backupPath ); wxLogTrace( traceSettings, wxT( "Backup path %s doesn't exist, creating it" ), backupPath );
if( !wxMkdir( backupPath ) ) if( !wxMkdir( backupPath ) )
{ {
wxLogTrace( traceSettings, "Could not create backups path! Skipping backup" ); wxLogTrace( traceSettings, wxT( "Could not create backups path! Skipping backup" ) );
return false; return false;
} }
} }
@ -1204,7 +1204,7 @@ bool SETTINGS_MANAGER::TriggerBackupIfNeeded( REPORTER& aReporter ) const
if( !dir.IsOpened() ) if( !dir.IsOpened() )
{ {
wxLogTrace( traceSettings, "Could not open project backups path %s", dir.GetName() ); wxLogTrace( traceSettings, wxT( "Could not open project backups path %s" ), dir.GetName() );
return false; return false;
} }

View File

@ -418,7 +418,7 @@ bool FOOTPRINT_EDITOR_SETTINGS::migrateSchema0to1()
if( !m_manager ) if( !m_manager )
{ {
wxLogTrace( traceSettings, wxLogTrace( traceSettings,
"Error: FOOTPRINT_EDITOR_SETTINGS migration cannot run unmanaged!" ); wxT( "Error: FOOTPRINT_EDITOR_SETTINGS migration cannot run unmanaged!" ) );
return false; return false;
} }
@ -434,7 +434,7 @@ bool FOOTPRINT_EDITOR_SETTINGS::migrateSchema0to1()
{ {
if( settings->GetFilename() == search ) if( settings->GetFilename() == search )
{ {
wxLogTrace( traceSettings, "Updating footprint editor theme from %s to %s", wxLogTrace( traceSettings, wxT( "Updating footprint editor theme from %s to %s" ),
selected, search ); selected, search );
Set( theme_ptr, search ); Set( theme_ptr, search );
return true; return true;