From b609c7dcd6da8ad9363406b46bdb3830d4781358 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Tue, 16 Feb 2021 23:26:46 -0500 Subject: [PATCH] Kick the osx specific path helpers into PATHS --- 3d-viewer/3d_cache/3d_plugin_manager.cpp | 4 +- common/common.cpp | 48 ------------------------ common/paths.cpp | 48 ++++++++++++++++++++++++ common/searchhelpfilefullpath.cpp | 3 +- common/systemdirsappend.cpp | 8 ++-- eeschema/dialogs/dialog_bom.cpp | 5 ++- eeschema/dialogs/dialog_netlist.cpp | 3 +- eeschema/sim/ngspice.cpp | 6 ++- include/common.h | 20 ---------- include/paths.h | 19 ++++++++++ pcbnew/pcbnew.cpp | 3 +- 11 files changed, 86 insertions(+), 81 deletions(-) diff --git a/3d-viewer/3d_cache/3d_plugin_manager.cpp b/3d-viewer/3d_cache/3d_plugin_manager.cpp index 244fc625fa..e51d8a5261 100644 --- a/3d-viewer/3d_cache/3d_plugin_manager.cpp +++ b/3d-viewer/3d_cache/3d_plugin_manager.cpp @@ -163,10 +163,10 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void ) // Search path on OS X is // (1) User ~/Library/Application Support/kicad/PlugIns/3d - checkPluginPath( GetOSXKicadUserDataDir() + wxT( "/PlugIns/3d" ), searchpaths ); + checkPluginPath( PATHS::GetOSXKicadUserDataDir() + wxT( "/PlugIns/3d" ), searchpaths ); // (2) Machine /Library/Application Support/kicad/PlugIns/3d - checkPluginPath( GetOSXKicadMachineDataDir() + wxT( "/PlugIns/3d" ), searchpaths ); + checkPluginPath( PATHS::GetOSXKicadMachineDataDir() + wxT( "/PlugIns/3d" ), searchpaths ); // (3) Bundle kicad.app/Contents/PlugIns/3d fn.AssignDir( PATHS::GetStockPlugins3DPath() ); diff --git a/common/common.cpp b/common/common.cpp index ec74204a2a..7bd226f52d 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -347,54 +347,6 @@ bool EnsureFileDirectoryExists( wxFileName* aTargetFullFileName, } -#ifdef __WXMAC__ -wxString GetOSXKicadUserDataDir() -{ - // According to wxWidgets documentation for GetUserDataDir: - // Mac: ~/Library/Application Support/appname - wxFileName udir( wxStandardPaths::Get().GetUserDataDir(), wxEmptyString ); - - // Since appname is different if started via launcher or standalone binary - // map all to "kicad" here - udir.RemoveLastDir(); - udir.AppendDir( "kicad" ); - - return udir.GetPath(); -} - - -wxString GetOSXKicadMachineDataDir() -{ - return wxT( "/Library/Application Support/kicad" ); -} - - -wxString GetOSXKicadDataDir() -{ - // According to wxWidgets documentation for GetDataDir: - // Mac: appname.app/Contents/SharedSupport bundle subdirectory - wxFileName ddir( wxStandardPaths::Get().GetDataDir(), wxEmptyString ); - - // This must be mapped to main bundle for everything but kicad.app - const wxArrayString dirs = ddir.GetDirs(); - if( dirs[dirs.GetCount() - 3] != wxT( "kicad.app" ) ) - { - // Bundle structure resp. current path is - // kicad.app/Contents/Applications/.app/Contents/SharedSupport - // and will be mapped to - // kicad.app/Contents/SharedSupprt - ddir.RemoveLastDir(); - ddir.RemoveLastDir(); - ddir.RemoveLastDir(); - ddir.RemoveLastDir(); - ddir.AppendDir( wxT( "SharedSupport" ) ); - } - - return ddir.GetPath(); -} -#endif - - // add this only if it is not in wxWidgets (for instance before 3.1.0) #ifdef USE_KICAD_WXSTRING_HASH size_t std::hash::operator()( const wxString& s ) const diff --git a/common/paths.cpp b/common/paths.cpp index 5e844d1dfa..e467d7c7f3 100644 --- a/common/paths.cpp +++ b/common/paths.cpp @@ -239,3 +239,51 @@ void PATHS::EnsureUserPathsExist() EnsurePathExists( GetDefaultUserFootprintsPath() ); EnsurePathExists( GetDefaultUser3DModelsPath() ); } + + +#ifdef __WXMAC__ +wxString PATHS::GetOSXKicadUserDataDir() +{ + // According to wxWidgets documentation for GetUserDataDir: + // Mac: ~/Library/Application Support/appname + wxFileName udir( wxStandardPaths::Get().GetUserDataDir(), wxEmptyString ); + + // Since appname is different if started via launcher or standalone binary + // map all to "kicad" here + udir.RemoveLastDir(); + udir.AppendDir( "kicad" ); + + return udir.GetPath(); +} + + +wxString PATHS::GetOSXKicadMachineDataDir() +{ + return wxT( "/Library/Application Support/kicad" ); +} + + +wxString PATHS::GetOSXKicadDataDir() +{ + // According to wxWidgets documentation for GetDataDir: + // Mac: appname.app/Contents/SharedSupport bundle subdirectory + wxFileName ddir( wxStandardPaths::Get().GetDataDir(), wxEmptyString ); + + // This must be mapped to main bundle for everything but kicad.app + const wxArrayString dirs = ddir.GetDirs(); + if( dirs[dirs.GetCount() - 3] != wxT( "kicad.app" ) ) + { + // Bundle structure resp. current path is + // kicad.app/Contents/Applications/.app/Contents/SharedSupport + // and will be mapped to + // kicad.app/Contents/SharedSupprt + ddir.RemoveLastDir(); + ddir.RemoveLastDir(); + ddir.RemoveLastDir(); + ddir.RemoveLastDir(); + ddir.AppendDir( wxT( "SharedSupport" ) ); + } + + return ddir.GetPath(); +} +#endif \ No newline at end of file diff --git a/common/searchhelpfilefullpath.cpp b/common/searchhelpfilefullpath.cpp index e59b382962..7021b9f2f4 100644 --- a/common/searchhelpfilefullpath.cpp +++ b/common/searchhelpfilefullpath.cpp @@ -29,6 +29,7 @@ #include #include #include +#include /** @@ -79,7 +80,7 @@ wxString SearchHelpFileFullPath( const SEARCH_STACK& aSStack, const wxString& aB ss.AddPaths( wxT( DEFAULT_INSTALL_PATH ), 0 ); #if defined(__WXMAC__) - ss.AddPaths( GetOSXKicadMachineDataDir() ); + ss.AddPaths( PATHS::GetOSXKicadMachineDataDir() ); ss.AddPaths( Pgm().GetExecutablePath(), 0 ); // OS X packages can have the help files in diff --git a/common/systemdirsappend.cpp b/common/systemdirsappend.cpp index 9e86932bd0..58f251dc8d 100644 --- a/common/systemdirsappend.cpp +++ b/common/systemdirsappend.cpp @@ -29,7 +29,7 @@ #include #include #include // to define DEFAULT_INSTALL_PATH - +#include // put your best guesses in here, send the computer on a wild goose chase, its // got nothing else to do. @@ -53,13 +53,13 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack ) #ifdef __WXMAC__ // Add the directory for the user-dependent, program specific data files. - maybe.AddPaths( GetOSXKicadUserDataDir() ); + maybe.AddPaths( PATHS::GetOSXKicadUserDataDir() ); // Global machine specific application data - maybe.AddPaths( GetOSXKicadMachineDataDir() ); + maybe.AddPaths( PATHS::GetOSXKicadMachineDataDir() ); // Global application specific data files inside bundle - maybe.AddPaths( GetOSXKicadDataDir() ); + maybe.AddPaths( PATHS::GetOSXKicadDataDir() ); #else // This is from CMAKE_INSTALL_PREFIX. // Useful when KiCad is installed by `make install`. diff --git a/eeschema/dialogs/dialog_bom.cpp b/eeschema/dialogs/dialog_bom.cpp index 9244f2e7c9..f5604b21d0 100644 --- a/eeschema/dialogs/dialog_bom.cpp +++ b/eeschema/dialogs/dialog_bom.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include @@ -352,7 +353,7 @@ void DIALOG_BOM::installGeneratorsList() #elif defined(__WXMSW__) wxString::Format( "%s\\scripting\\plugins", Pgm().GetExecutablePath() ), #elif defined(__WXMAC__) - wxString::Format( "%s/plugins", GetOSXKicadDataDir() ), + wxString::Format( "%s/plugins", PATHS::GetOSXKicadDataDir() ), #endif }; @@ -562,7 +563,7 @@ wxString DIALOG_BOM::chooseGenerator() #ifndef __WXMAC__ lastPath = Pgm().GetExecutablePath(); #else - lastPath = GetOSXKicadDataDir() + "/plugins"; + lastPath = PATHS::GetOSXKicadDataDir() + "/plugins"; #endif } diff --git a/eeschema/dialogs/dialog_netlist.cpp b/eeschema/dialogs/dialog_netlist.cpp index 22d35c045b..2c3be99a55 100644 --- a/eeschema/dialogs/dialog_netlist.cpp +++ b/eeschema/dialogs/dialog_netlist.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -748,7 +749,7 @@ void NETLIST_DIALOG_ADD_GENERATOR::OnBrowseGenerators( wxCommandEvent& event ) #ifndef __WXMAC__ Path = Pgm().GetExecutablePath(); #else - Path = GetOSXKicadDataDir() + wxT( "/plugins" ); + Path = PATHS::GetOSXKicadDataDir() + wxT( "/plugins" ); #endif FullFileName = EDA_FILE_SELECTOR( _( "Generator files:" ), Path, FullFileName, wxEmptyString, wxFileSelectorDefaultWildcardStr, diff --git a/eeschema/sim/ngspice.cpp b/eeschema/sim/ngspice.cpp index 3578ee00b9..4c9b8f6a75 100644 --- a/eeschema/sim/ngspice.cpp +++ b/eeschema/sim/ngspice.cpp @@ -34,6 +34,8 @@ #include #include +#include + #include #include @@ -344,8 +346,8 @@ void NGSPICE::init_dll() #endif #elif defined(__WXMAC__) const vector dllPaths = { - GetOSXKicadUserDataDir().ToStdString() + "/PlugIns/ngspice", - GetOSXKicadMachineDataDir().ToStdString() + "/PlugIns/ngspice", + PATHS::GetOSXKicadUserDataDir().ToStdString() + "/PlugIns/ngspice", + PATHS::GetOSXKicadMachineDataDir().ToStdString() + "/PlugIns/ngspice", // when running kicad.app stdPaths.GetPluginsDir().ToStdString() + "/sim", // when running eeschema.app diff --git a/include/common.h b/include/common.h index df74ff331e..53fb1bf75b 100644 --- a/include/common.h +++ b/include/common.h @@ -124,26 +124,6 @@ wxString ExpandTextVars( const wxString& aSource, const PROJECT* aProject ); */ const wxString ResolveUriByEnvVars( const wxString& aUri, PROJECT* aProject ); - -#ifdef __WXMAC__ -/** - * OSX specific function GetOSXKicadUserDataDir - * - * @return The macOS specific user data directory for KiCad. - */ -wxString GetOSXKicadUserDataDir(); - -/** - * @return The macOS specific machine data directory for KiCad - */ -wxString GetOSXKicadMachineDataDir(); - -/** - * @return The macOS specific bundle data directory for KiCad - */ -wxString GetOSXKicadDataDir(); -#endif - // Some wxWidgets versions (for instance before 3.1.0) do not include // this function, so add it if missing #if !wxCHECK_VERSION( 3, 1, 0 ) diff --git a/include/paths.h b/include/paths.h index edf27cebd9..ad6dcf8ae9 100644 --- a/include/paths.h +++ b/include/paths.h @@ -97,6 +97,25 @@ public: */ static void EnsureUserPathsExist(); +#ifdef __WXMAC__ + /** + * OSX specific function GetOSXKicadUserDataDir + * + * @return The macOS specific user data directory for KiCad. + */ + static wxString GetOSXKicadUserDataDir(); + + /** + * @return The macOS specific machine data directory for KiCad + */ + static wxString GetOSXKicadMachineDataDir(); + + /** + * @return The macOS specific bundle data directory for KiCad + */ + static wxString GetOSXKicadDataDir(); +#endif + private: // we are a static helper PATHS() {} diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 37918fb791..d8eca37b6a 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include "invoke_pcb_dialog.h" #include "dialog_global_fp_lib_table_config.h" @@ -246,7 +247,7 @@ static bool scriptingSetup() wxString pypath; // Bundle scripting folder (/Contents/SharedSupport/scripting) - pypath += GetOSXKicadDataDir() + wxT( "/scripting" ); + pypath += PATHS::GetOSXKicadDataDir() + wxT( "/scripting" ); // $(KICAD_PATH)/scripting/plugins is always added in kicadplugins.i if( wxGetenv("KICAD_PATH") != NULL )