Fix some UTF8 issues with project settings

Fixes https://gitlab.com/kicad/code/kicad/-/issues/4808
This commit is contained in:
Jon Evans 2020-07-05 12:25:04 -04:00
parent e76d302197
commit 6eca886292
4 changed files with 19 additions and 7 deletions

View File

@ -153,7 +153,8 @@ bool JSON_SETTINGS::LoadFromFile( const std::string& aDirectory )
} }
else else
{ {
path.Assign( aDirectory, m_filename, getFileExt() ); wxString dir( aDirectory.c_str(), wxConvUTF8 );
path.Assign( dir, m_filename, getFileExt() );
} }
if( !path.Exists() ) if( !path.Exists() )
@ -182,7 +183,7 @@ bool JSON_SETTINGS::LoadFromFile( const std::string& aDirectory )
{ {
try try
{ {
std::ifstream in( path.GetFullPath().ToStdString() ); std::ifstream in( path.GetFullPath().ToUTF8() );
in >> *this; in >> *this;
// If parse succeeds, check if schema migration is required // If parse succeeds, check if schema migration is required
@ -294,7 +295,8 @@ bool JSON_SETTINGS::SaveToFile( const std::string& aDirectory, bool aForce )
} }
else else
{ {
path.Assign( aDirectory, m_filename, getFileExt() ); wxString dir( aDirectory.c_str(), wxConvUTF8 );
path.Assign( dir, m_filename, getFileExt() );
} }
if( !m_createIfMissing && !path.FileExists() ) if( !m_createIfMissing && !path.FileExists() )
@ -338,7 +340,7 @@ bool JSON_SETTINGS::SaveToFile( const std::string& aDirectory, bool aForce )
try try
{ {
std::ofstream file( path.GetFullPath().ToStdString() ); std::ofstream file( path.GetFullPath().ToUTF8() );
file << std::setw( 2 ) << *this << std::endl; file << std::setw( 2 ) << *this << std::endl;
} }
catch( const std::exception& e ) catch( const std::exception& e )
@ -551,4 +553,4 @@ void to_json( nlohmann::json& aJson, const wxString& aString )
void from_json( const nlohmann::json& aJson, wxString& aString ) void from_json( const nlohmann::json& aJson, wxString& aString )
{ {
aString = wxString( aJson.get<std::string>().c_str(), wxConvUTF8 ); aString = wxString( aJson.get<std::string>().c_str(), wxConvUTF8 );
} }

View File

@ -706,7 +706,7 @@ bool SETTINGS_MANAGER::LoadProject( const wxString& aFullPath, bool aSetActive )
m_projects[fullPath].reset( project.release() ); m_projects[fullPath].reset( project.release() );
std::string fn( path.GetName() ); std::string fn( path.GetName().ToUTF8() );
PROJECT_LOCAL_SETTINGS* settings = static_cast<PROJECT_LOCAL_SETTINGS*>( PROJECT_LOCAL_SETTINGS* settings = static_cast<PROJECT_LOCAL_SETTINGS*>(
RegisterSettings( new PROJECT_LOCAL_SETTINGS( fn ) ) ); RegisterSettings( new PROJECT_LOCAL_SETTINGS( fn ) ) );
@ -783,7 +783,9 @@ bool SETTINGS_MANAGER::loadProjectFile( PROJECT& aProject )
aProject.setProjectFile( file ); aProject.setProjectFile( file );
file->SetProject( &aProject ); file->SetProject( &aProject );
return file->LoadFromFile( std::string( fullFn.GetPath().ToUTF8() ) ); std::string path( fullFn.GetPath().ToUTF8() );
return file->LoadFromFile( path );
} }

View File

@ -62,6 +62,11 @@ protected:
return ProjectLocalSettingsFileExtension; return ProjectLocalSettingsFileExtension;
} }
wxString getLegacyFileExt() const override
{
return wxT( "NO_SUCH_FILE_EXTENSION" );
}
private: private:
/// A link to the owning project /// A link to the owning project

View File

@ -94,6 +94,9 @@ int TREEPROJECTFILES::OnCompareItems( const wxTreeItemId& item1, const wxTreeIte
TREEPROJECT_ITEM* myitem1 = (TREEPROJECT_ITEM*) GetItemData( item1 ); TREEPROJECT_ITEM* myitem1 = (TREEPROJECT_ITEM*) GetItemData( item1 );
TREEPROJECT_ITEM* myitem2 = (TREEPROJECT_ITEM*) GetItemData( item2 ); TREEPROJECT_ITEM* myitem2 = (TREEPROJECT_ITEM*) GetItemData( item2 );
if( !myitem1 || !myitem2 )
return 0;
if( myitem1->GetType() == TREE_DIRECTORY && myitem2->GetType() != TREE_DIRECTORY ) if( myitem1->GetType() == TREE_DIRECTORY && myitem2->GetType() != TREE_DIRECTORY )
return -1; return -1;