Kick the osx specific path helpers into PATHS

This commit is contained in:
Marek Roszko 2021-02-16 23:26:46 -05:00
parent ba6aa3e034
commit b609c7dcd6
11 changed files with 86 additions and 81 deletions

View File

@ -163,10 +163,10 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void )
// Search path on OS X is // Search path on OS X is
// (1) User ~/Library/Application Support/kicad/PlugIns/3d // (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 // (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 // (3) Bundle kicad.app/Contents/PlugIns/3d
fn.AssignDir( PATHS::GetStockPlugins3DPath() ); fn.AssignDir( PATHS::GetStockPlugins3DPath() );

View File

@ -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/<standalone>.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) // add this only if it is not in wxWidgets (for instance before 3.1.0)
#ifdef USE_KICAD_WXSTRING_HASH #ifdef USE_KICAD_WXSTRING_HASH
size_t std::hash<wxString>::operator()( const wxString& s ) const size_t std::hash<wxString>::operator()( const wxString& s ) const

View File

@ -239,3 +239,51 @@ void PATHS::EnsureUserPathsExist()
EnsurePathExists( GetDefaultUserFootprintsPath() ); EnsurePathExists( GetDefaultUserFootprintsPath() );
EnsurePathExists( GetDefaultUser3DModelsPath() ); 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/<standalone>.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

View File

@ -29,6 +29,7 @@
#include <macros.h> #include <macros.h>
#include <wx/log.h> #include <wx/log.h>
#include <trace_helpers.h> #include <trace_helpers.h>
#include <paths.h>
/** /**
@ -79,7 +80,7 @@ wxString SearchHelpFileFullPath( const SEARCH_STACK& aSStack, const wxString& aB
ss.AddPaths( wxT( DEFAULT_INSTALL_PATH ), 0 ); ss.AddPaths( wxT( DEFAULT_INSTALL_PATH ), 0 );
#if defined(__WXMAC__) #if defined(__WXMAC__)
ss.AddPaths( GetOSXKicadMachineDataDir() ); ss.AddPaths( PATHS::GetOSXKicadMachineDataDir() );
ss.AddPaths( Pgm().GetExecutablePath(), 0 ); ss.AddPaths( Pgm().GetExecutablePath(), 0 );
// OS X packages can have the help files in // OS X packages can have the help files in

View File

@ -29,7 +29,7 @@
#include <search_stack.h> #include <search_stack.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <config.h> // to define DEFAULT_INSTALL_PATH #include <config.h> // to define DEFAULT_INSTALL_PATH
#include <paths.h>
// put your best guesses in here, send the computer on a wild goose chase, its // put your best guesses in here, send the computer on a wild goose chase, its
// got nothing else to do. // got nothing else to do.
@ -53,13 +53,13 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack )
#ifdef __WXMAC__ #ifdef __WXMAC__
// Add the directory for the user-dependent, program specific data files. // Add the directory for the user-dependent, program specific data files.
maybe.AddPaths( GetOSXKicadUserDataDir() ); maybe.AddPaths( PATHS::GetOSXKicadUserDataDir() );
// Global machine specific application data // Global machine specific application data
maybe.AddPaths( GetOSXKicadMachineDataDir() ); maybe.AddPaths( PATHS::GetOSXKicadMachineDataDir() );
// Global application specific data files inside bundle // Global application specific data files inside bundle
maybe.AddPaths( GetOSXKicadDataDir() ); maybe.AddPaths( PATHS::GetOSXKicadDataDir() );
#else #else
// This is from CMAKE_INSTALL_PREFIX. // This is from CMAKE_INSTALL_PREFIX.
// Useful when KiCad is installed by `make install`. // Useful when KiCad is installed by `make install`.

View File

@ -44,6 +44,7 @@
#include <reporter.h> #include <reporter.h>
#include <sch_edit_frame.h> #include <sch_edit_frame.h>
#include <schematic.h> #include <schematic.h>
#include <paths.h>
#include <dialogs/dialog_bom_cfg_lexer.h> #include <dialogs/dialog_bom_cfg_lexer.h>
@ -352,7 +353,7 @@ void DIALOG_BOM::installGeneratorsList()
#elif defined(__WXMSW__) #elif defined(__WXMSW__)
wxString::Format( "%s\\scripting\\plugins", Pgm().GetExecutablePath() ), wxString::Format( "%s\\scripting\\plugins", Pgm().GetExecutablePath() ),
#elif defined(__WXMAC__) #elif defined(__WXMAC__)
wxString::Format( "%s/plugins", GetOSXKicadDataDir() ), wxString::Format( "%s/plugins", PATHS::GetOSXKicadDataDir() ),
#endif #endif
}; };
@ -562,7 +563,7 @@ wxString DIALOG_BOM::chooseGenerator()
#ifndef __WXMAC__ #ifndef __WXMAC__
lastPath = Pgm().GetExecutablePath(); lastPath = Pgm().GetExecutablePath();
#else #else
lastPath = GetOSXKicadDataDir() + "/plugins"; lastPath = PATHS::GetOSXKicadDataDir() + "/plugins";
#endif #endif
} }

View File

@ -45,6 +45,7 @@
#include <netlist_exporters/netlist_exporter_pspice.h> #include <netlist_exporters/netlist_exporter_pspice.h>
#include <eeschema_settings.h> #include <eeschema_settings.h>
#include <schematic.h> #include <schematic.h>
#include <paths.h>
#include <eeschema_id.h> #include <eeschema_id.h>
#include <wx/regex.h> #include <wx/regex.h>
@ -748,7 +749,7 @@ void NETLIST_DIALOG_ADD_GENERATOR::OnBrowseGenerators( wxCommandEvent& event )
#ifndef __WXMAC__ #ifndef __WXMAC__
Path = Pgm().GetExecutablePath(); Path = Pgm().GetExecutablePath();
#else #else
Path = GetOSXKicadDataDir() + wxT( "/plugins" ); Path = PATHS::GetOSXKicadDataDir() + wxT( "/plugins" );
#endif #endif
FullFileName = EDA_FILE_SELECTOR( _( "Generator files:" ), Path, FullFileName, FullFileName = EDA_FILE_SELECTOR( _( "Generator files:" ), Path, FullFileName,
wxEmptyString, wxFileSelectorDefaultWildcardStr, wxEmptyString, wxFileSelectorDefaultWildcardStr,

View File

@ -34,6 +34,8 @@
#include <common.h> #include <common.h>
#include <locale_io.h> #include <locale_io.h>
#include <paths.h>
#include <wx/stdpaths.h> #include <wx/stdpaths.h>
#include <wx/dir.h> #include <wx/dir.h>
@ -344,8 +346,8 @@ void NGSPICE::init_dll()
#endif #endif
#elif defined(__WXMAC__) #elif defined(__WXMAC__)
const vector<string> dllPaths = { const vector<string> dllPaths = {
GetOSXKicadUserDataDir().ToStdString() + "/PlugIns/ngspice", PATHS::GetOSXKicadUserDataDir().ToStdString() + "/PlugIns/ngspice",
GetOSXKicadMachineDataDir().ToStdString() + "/PlugIns/ngspice", PATHS::GetOSXKicadMachineDataDir().ToStdString() + "/PlugIns/ngspice",
// when running kicad.app // when running kicad.app
stdPaths.GetPluginsDir().ToStdString() + "/sim", stdPaths.GetPluginsDir().ToStdString() + "/sim",
// when running eeschema.app // when running eeschema.app

View File

@ -124,26 +124,6 @@ wxString ExpandTextVars( const wxString& aSource, const PROJECT* aProject );
*/ */
const wxString ResolveUriByEnvVars( const wxString& aUri, 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 // Some wxWidgets versions (for instance before 3.1.0) do not include
// this function, so add it if missing // this function, so add it if missing
#if !wxCHECK_VERSION( 3, 1, 0 ) #if !wxCHECK_VERSION( 3, 1, 0 )

View File

@ -97,6 +97,25 @@ public:
*/ */
static void EnsureUserPathsExist(); 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: private:
// we are a static helper // we are a static helper
PATHS() {} PATHS() {}

View File

@ -54,6 +54,7 @@
#include <footprint_preview_panel.h> #include <footprint_preview_panel.h>
#include <footprint_info_impl.h> #include <footprint_info_impl.h>
#include <dialogs/dialog_configure_paths.h> #include <dialogs/dialog_configure_paths.h>
#include <paths.h>
#include "invoke_pcb_dialog.h" #include "invoke_pcb_dialog.h"
#include "dialog_global_fp_lib_table_config.h" #include "dialog_global_fp_lib_table_config.h"
@ -246,7 +247,7 @@ static bool scriptingSetup()
wxString pypath; wxString pypath;
// Bundle scripting folder (<kicad.app>/Contents/SharedSupport/scripting) // Bundle scripting folder (<kicad.app>/Contents/SharedSupport/scripting)
pypath += GetOSXKicadDataDir() + wxT( "/scripting" ); pypath += PATHS::GetOSXKicadDataDir() + wxT( "/scripting" );
// $(KICAD_PATH)/scripting/plugins is always added in kicadplugins.i // $(KICAD_PATH)/scripting/plugins is always added in kicadplugins.i
if( wxGetenv("KICAD_PATH") != NULL ) if( wxGetenv("KICAD_PATH") != NULL )