Move executable path to PATHS to avoid a circular dependency
This commit is contained in:
parent
3c18e216b1
commit
e3285c234a
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
#include <kiplatform/environment.h>
|
#include <kiplatform/environment.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <pgm_base.h>
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <build_version.h>
|
#include <build_version.h>
|
||||||
#include <macros.h>
|
#include <macros.h>
|
||||||
|
@ -166,7 +165,7 @@ wxString PATHS::GetStockDataPath( bool aRespectRunFromBuildDir )
|
||||||
#elif defined( __WXMSW__ )
|
#elif defined( __WXMSW__ )
|
||||||
path = getWindowsKiCadRoot();
|
path = getWindowsKiCadRoot();
|
||||||
#else
|
#else
|
||||||
path = Pgm().GetExecutablePath() + wxT( ".." );
|
path = GetExecutablePath() + wxT( ".." );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -265,7 +264,7 @@ wxString PATHS::GetStockPluginsPath()
|
||||||
wxFileName fn;
|
wxFileName fn;
|
||||||
|
|
||||||
#if defined( __WXMSW__ )
|
#if defined( __WXMSW__ )
|
||||||
fn.AssignDir( Pgm().GetExecutablePath() );
|
fn.AssignDir( GetExecutablePath() );
|
||||||
fn.AppendDir( wxT( "scripting" ) );
|
fn.AppendDir( wxT( "scripting" ) );
|
||||||
#else
|
#else
|
||||||
fn.AssignDir( PATHS::GetStockDataPath( false ) );
|
fn.AssignDir( PATHS::GetStockDataPath( false ) );
|
||||||
|
@ -296,7 +295,7 @@ wxString PATHS::GetStockPlugins3DPath()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fn.AssignDir( Pgm().GetExecutablePath() );
|
fn.AssignDir( GetExecutablePath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
fn.AppendDir( wxT( "plugins" ) );
|
fn.AppendDir( wxT( "plugins" ) );
|
||||||
|
@ -457,7 +456,7 @@ wxString PATHS::GetWindowsFontConfigDir()
|
||||||
|
|
||||||
wxString PATHS::getWindowsKiCadRoot()
|
wxString PATHS::getWindowsKiCadRoot()
|
||||||
{
|
{
|
||||||
wxFileName root( Pgm().GetExecutablePath() + wxT( "/../" ) );
|
wxFileName root( GetExecutablePath() + wxT( "/../" ) );
|
||||||
root.MakeAbsolute();
|
root.MakeAbsolute();
|
||||||
|
|
||||||
return root.GetPathWithSep();
|
return root.GetPathWithSep();
|
||||||
|
@ -499,4 +498,52 @@ wxString PATHS::CalculateUserSettingsPath( bool aIncludeVer, bool aUseEnv )
|
||||||
cfgpath.AppendDir( GetMajorMinorVersion().ToStdString() );
|
cfgpath.AppendDir( GetMajorMinorVersion().ToStdString() );
|
||||||
|
|
||||||
return cfgpath.GetPath();
|
return cfgpath.GetPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const wxString& PATHS::GetExecutablePath()
|
||||||
|
{
|
||||||
|
static wxString exe_path;
|
||||||
|
|
||||||
|
if( exe_path.empty() )
|
||||||
|
{
|
||||||
|
wxString bin_dir = wxStandardPaths::Get().GetExecutablePath();
|
||||||
|
|
||||||
|
#ifdef __WXMAC__
|
||||||
|
// On OSX GetExecutablePath() will always point to main
|
||||||
|
// bundle directory, e.g., /Applications/kicad.app/
|
||||||
|
|
||||||
|
wxFileName fn( bin_dir );
|
||||||
|
|
||||||
|
if( fn.GetName() == wxT( "kicad" ) || fn.GetName() == wxT( "kicad-cli" ) )
|
||||||
|
{
|
||||||
|
// kicad launcher, so just remove the Contents/MacOS part
|
||||||
|
fn.RemoveLastDir();
|
||||||
|
fn.RemoveLastDir();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// standalone binaries live in Contents/Applications/<standalone>.app/Contents/MacOS
|
||||||
|
fn.RemoveLastDir();
|
||||||
|
fn.RemoveLastDir();
|
||||||
|
fn.RemoveLastDir();
|
||||||
|
fn.RemoveLastDir();
|
||||||
|
fn.RemoveLastDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
bin_dir = fn.GetPath() + wxT( "/" );
|
||||||
|
#else
|
||||||
|
// Use unix notation for paths. I am not sure this is a good idea,
|
||||||
|
// but it simplifies compatibility between Windows and Unices.
|
||||||
|
// However it is a potential problem in path handling under Windows.
|
||||||
|
bin_dir.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
||||||
|
|
||||||
|
// Remove file name form command line:
|
||||||
|
while( bin_dir.Last() != '/' && !bin_dir.IsEmpty() )
|
||||||
|
bin_dir.RemoveLast();
|
||||||
|
#endif
|
||||||
|
exe_path = bin_dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
return exe_path;
|
||||||
}
|
}
|
|
@ -514,7 +514,6 @@ bool PGM_BASE::InitPgm( bool aHeadless, bool aSkipPyInit, bool aIsUnitTest )
|
||||||
|
|
||||||
// Analyze the command line & initialize the binary path
|
// Analyze the command line & initialize the binary path
|
||||||
wxString tmp;
|
wxString tmp;
|
||||||
setExecutablePath();
|
|
||||||
SetLanguagePath();
|
SetLanguagePath();
|
||||||
SetDefaultLanguage( tmp );
|
SetDefaultLanguage( tmp );
|
||||||
|
|
||||||
|
@ -594,48 +593,6 @@ bool PGM_BASE::InitPgm( bool aHeadless, bool aSkipPyInit, bool aIsUnitTest )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PGM_BASE::setExecutablePath()
|
|
||||||
{
|
|
||||||
m_bin_dir = wxStandardPaths::Get().GetExecutablePath();
|
|
||||||
|
|
||||||
#ifdef __WXMAC__
|
|
||||||
// On OSX Pgm().GetExecutablePath() will always point to main
|
|
||||||
// bundle directory, e.g., /Applications/kicad.app/
|
|
||||||
|
|
||||||
wxFileName fn( m_bin_dir );
|
|
||||||
|
|
||||||
if( fn.GetName() == wxT( "kicad" ) || fn.GetName() == wxT( "kicad-cli" ) )
|
|
||||||
{
|
|
||||||
// kicad launcher, so just remove the Contents/MacOS part
|
|
||||||
fn.RemoveLastDir();
|
|
||||||
fn.RemoveLastDir();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// standalone binaries live in Contents/Applications/<standalone>.app/Contents/MacOS
|
|
||||||
fn.RemoveLastDir();
|
|
||||||
fn.RemoveLastDir();
|
|
||||||
fn.RemoveLastDir();
|
|
||||||
fn.RemoveLastDir();
|
|
||||||
fn.RemoveLastDir();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_bin_dir = fn.GetPath() + wxT( "/" );
|
|
||||||
#else
|
|
||||||
// Use unix notation for paths. I am not sure this is a good idea,
|
|
||||||
// but it simplifies compatibility between Windows and Unices.
|
|
||||||
// However it is a potential problem in path handling under Windows.
|
|
||||||
m_bin_dir.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
|
||||||
|
|
||||||
// Remove file name form command line:
|
|
||||||
while( m_bin_dir.Last() != '/' && !m_bin_dir.IsEmpty() )
|
|
||||||
m_bin_dir.RemoveLast();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PGM_BASE::loadCommonSettings()
|
void PGM_BASE::loadCommonSettings()
|
||||||
{
|
{
|
||||||
m_text_editor = GetCommonSettings()->m_System.text_editor;
|
m_text_editor = GetCommonSettings()->m_System.text_editor;
|
||||||
|
@ -991,3 +948,9 @@ void PGM_BASE::HandleAssert( const wxString& aFile, int aLine, const wxString& a
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const wxString& PGM_BASE::GetExecutablePath() const
|
||||||
|
{
|
||||||
|
return PATHS::GetExecutablePath();
|
||||||
|
}
|
|
@ -23,6 +23,12 @@
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @note Do we really need these defined?
|
||||||
|
*/
|
||||||
|
#define UNIX_STRING_DIR_SEP wxT( "/" )
|
||||||
|
#define WIN_STRING_DIR_SEP wxT( "\\" )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to centralize the paths used throughout kicad
|
* Helper class to centralize the paths used throughout kicad
|
||||||
*/
|
*/
|
||||||
|
@ -204,6 +210,7 @@ public:
|
||||||
*/
|
*/
|
||||||
static wxString CalculateUserSettingsPath( bool aIncludeVer = true, bool aUseEnv = true );
|
static wxString CalculateUserSettingsPath( bool aIncludeVer = true, bool aUseEnv = true );
|
||||||
|
|
||||||
|
static const wxString& GetExecutablePath();
|
||||||
private:
|
private:
|
||||||
// we are a static helper
|
// we are a static helper
|
||||||
PATHS() {}
|
PATHS() {}
|
||||||
|
|
|
@ -171,7 +171,7 @@ public:
|
||||||
|
|
||||||
virtual const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
|
virtual const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
|
||||||
|
|
||||||
virtual const wxString& GetExecutablePath() const { return m_bin_dir; }
|
virtual const wxString& GetExecutablePath() const;
|
||||||
|
|
||||||
virtual wxLocale* GetLocale() { return m_locale; }
|
virtual wxLocale* GetLocale() { return m_locale; }
|
||||||
|
|
||||||
|
@ -387,13 +387,6 @@ protected:
|
||||||
/// Trap all changes in here, simplifies debugging
|
/// Trap all changes in here, simplifies debugging
|
||||||
void setLanguageId( int aId ) { m_language_id = aId; }
|
void setLanguageId( int aId ) { m_language_id = aId; }
|
||||||
|
|
||||||
/**
|
|
||||||
* Find the path to the executable and stores it in PGM_BASE::m_bin_dir.
|
|
||||||
*
|
|
||||||
* @return true if success, else false.
|
|
||||||
*/
|
|
||||||
bool setExecutablePath();
|
|
||||||
|
|
||||||
#ifdef KICAD_USE_SENTRY
|
#ifdef KICAD_USE_SENTRY
|
||||||
void sentryInit();
|
void sentryInit();
|
||||||
void sentryPrompt();
|
void sentryPrompt();
|
||||||
|
@ -411,7 +404,6 @@ protected:
|
||||||
std::unique_ptr<wxSingleInstanceChecker> m_pgm_checker;
|
std::unique_ptr<wxSingleInstanceChecker> m_pgm_checker;
|
||||||
|
|
||||||
|
|
||||||
wxString m_bin_dir; /// full path to this program
|
|
||||||
wxString m_kicad_env; /// The KICAD system environment variable.
|
wxString m_kicad_env; /// The KICAD system environment variable.
|
||||||
|
|
||||||
wxLocale* m_locale;
|
wxLocale* m_locale;
|
||||||
|
|
Loading…
Reference in New Issue