void PGM_BASE::SetLanguagePath() { SEARCH_STACK guesses; SystemDirsAppend( &guesses ); // Add our internat dir to the wxLocale catalog of paths for( unsigned i = 0; i < guesses.GetCount(); i++ ) { wxFileName fn( guesses[i], wxEmptyString ); // Append path for Windows and unix KiCad package install fn.AppendDir( wxT( "share" ) ); fn.AppendDir( wxT( "internat" ) ); if( fn.IsDirReadable() ) { wxLogDebug( wxT( "Adding locale lookup path: " ) + fn.GetPath() ); wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() ); } // Append path for unix standard install fn.RemoveLastDir(); fn.AppendDir( wxT( "kicad" ) ); fn.AppendDir( wxT( "internat" ) ); if( fn.IsDirReadable() ) { wxLogDebug( wxT( "Adding locale lookup path: " ) + fn.GetPath() ); wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() ); } } }
/** * Function FindFileInSearchPaths * looks in "this" for \a aFilename, but first modifies every search * path by appending a list of path fragments from aSubdirs. That modification * is not relative. */ wxString FindFileInSearchPaths( const SEARCH_STACK& aStack, const wxString& aFilename, const wxArrayString* aSubdirs ) { wxPathList paths; for( unsigned i = 0; i < aStack.GetCount(); ++i ) { wxFileName fn( aStack[i], wxEmptyString ); if( aSubdirs ) { for( unsigned j = 0; j < aSubdirs->GetCount(); j++ ) fn.AppendDir( (*aSubdirs)[j] ); } wxLogDebug( wxT( " %s" ), GetChars( fn.GetFullPath() ) ); if( fn.DirExists() ) { paths.Add( fn.GetPath() ); } } return paths.FindValidPath( aFilename ); }
wxString RETAINED_PATH::LastVisitedPath( const SEARCH_STACK& aSStack, const wxString& aSubPathToSearch ) { if( !!m_retained_path ) return m_retained_path; wxString path; // Initialize default path to the main default lib path // this is the second path in list (the first is the project path) unsigned pcount = aSStack.GetCount(); if( pcount ) { unsigned ipath = 0; if( aSStack[0] == wxGetCwd() ) ipath = 1; // First choice of path: if( ipath < pcount ) path = aSStack[ipath]; // Search a sub path matching aSubPathToSearch if( !aSubPathToSearch.IsEmpty() ) { for( ; ipath < pcount; ipath++ ) { if( aSStack[ipath].Contains( aSubPathToSearch ) ) { path = aSStack[ipath]; break; } } } } if( path.IsEmpty() ) path = wxGetCwd(); return path; }
bool PGM_KICAD::OnPgmInit( wxApp* aWxApp ) { m_wx_app = aWxApp; // first thing. wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath(); if( !wxIsAbsolutePath( absoluteArgv0 ) ) { wxLogError( wxT( "No meaningful argv[0]" ) ); return false; } // Set LIB_ENV_VAR *before* loading the KIFACE DSOs, in case they have hard // dependencies on subsidiary DSOs below it. set_lib_env_var( absoluteArgv0 ); if( !initPgm() ) return false; m_bm.Init(); // Add search paths to feed the PGM_KICAD::SysSearch() function, // currenly limited in support to only look for project templates { SEARCH_STACK bases; SystemDirsAppend( &bases ); // DBG( bases.Show( (std::string(__func__) + " bases").c_str() );) for( unsigned i = 0; i < bases.GetCount(); ++i ) { wxFileName fn( bases[i], wxEmptyString ); // Add KiCad template file path to search path list. fn.AppendDir( wxT( "template" ) ); m_bm.m_search.AddPaths( fn.GetPath() ); } //DBG( m_bm.m_search.Show( (std::string( __func__ ) + " SysSearch()").c_str() );) } // Must be called before creating the main frame in order to // display the real hotkeys in menus or tool tips extern struct EDA_HOTKEY_CONFIG kicad_Manager_Hokeys_Descr[]; ReadHotkeyConfig( KICAD_MANAGER_FRAME_NAME, kicad_Manager_Hokeys_Descr ); KICAD_MANAGER_FRAME* frame = new KICAD_MANAGER_FRAME( NULL, wxT( "KiCad" ), wxDefaultPosition, wxDefaultSize ); App().SetTopWindow( frame ); Kiway.SetTop( frame ); bool prjloaded = false; // true when the project is loaded if( App().argc > 1 ) frame->SetProjectFileName( App().argv[1] ); else if( GetFileHistory().GetCount() ) { wxString last_pro = GetFileHistory().GetHistoryFile( 0 ); if( !wxFileExists( last_pro ) ) { GetFileHistory().RemoveFileFromHistory( 0 ); wxFileName namelessProject( wxStandardPaths::Get().GetDocumentsDir(), NAMELESS_PROJECT, ProjectFileExtension ); frame->SetProjectFileName( namelessProject.GetFullPath() ); } else { // Try to open the last opened project, // if a project name is not given when starting Kicad frame->SetProjectFileName( last_pro ); wxCommandEvent cmd( 0, wxID_FILE1 ); frame->OnFileHistory( cmd ); prjloaded = true; // OnFileHistory() loads the project } } else // there is no history { wxFileName namelessProject( wxStandardPaths::Get().GetDocumentsDir(), NAMELESS_PROJECT, ProjectFileExtension ); frame->SetProjectFileName( namelessProject.GetFullPath() ); } if( !prjloaded ) { wxCommandEvent cmd( 0, wxID_ANY ); frame->OnLoadProject( cmd ); } frame->Show( true ); frame->Raise(); return true; }
// non-member so it can be moved easily, and kept REALLY private. // Do NOT Clear() in here. static void add_search_paths( SEARCH_STACK* aDst, const SEARCH_STACK& aSrc, int aIndex ) { for( unsigned i=0; i<aSrc.GetCount(); ++i ) aDst->AddPaths( aSrc[i], aIndex ); }
void SystemDirsAppend( SEARCH_STACK* aSearchStack ) { // No clearing is done here, the most general approach is NOT to assume that // our appends will be the only thing in the stack. This function has no // knowledge of caller's intentions. // wxPathList::AddEnvList() is broken, use SEARCH_STACK::AddPaths(). // SEARCH_STACK::AddPaths() will verify readability and existence of // each directory before adding. SEARCH_STACK maybe; // User environment variable path is the first search path. Chances are // if the user is savvy enough to set an environment variable they know // what they are doing. It should take precedence over anything else. // Otherwise don't set it. maybe.AddPaths( wxGetenv( wxT( "KICAD" ) ) ); #ifdef __WXMAC__ // Add the directory for the user-dependent, program specific data files. maybe.AddPaths( GetOSXKicadUserDataDir() ); // Global machine specific application data maybe.AddPaths( GetOSXKicadMachineDataDir() ); // Global application specific data files inside bundle maybe.AddPaths( GetOSXKicadDataDir() ); #else // This is from CMAKE_INSTALL_PREFIX. // Useful when KiCad is installed by `make install`. // Use as second ranked place. maybe.AddPaths( wxT( DEFAULT_INSTALL_PATH ) ); // Add the directory for the user-dependent, program specific data files. // According to wxWidgets documentation: // Unix: ~/.appname // Windows: C:\Documents and Settings\username\Application Data\appname maybe.AddPaths( wxStandardPaths::Get().GetUserDataDir() ); { // Should be full path to this program executable. wxString bin_dir = Pgm().GetExecutablePath(); #if defined(__MINGW32__) // bin_dir uses unix path separator. So to parse with wxFileName // use windows separator, especially important for server inclusion: // like: \\myserver\local_path . bin_dir.Replace( wxFileName::GetPathSeparator( wxPATH_UNIX ), wxFileName::GetPathSeparator( wxPATH_WIN ) ); #endif wxFileName bin_fn( bin_dir, wxEmptyString ); // Dir of the global (not user-specific), application specific, data files. // From wx docs: // Unix: prefix/share/appname // Windows: the directory where the executable file is located // Mac: appname.app/Contents/SharedSupport bundle subdirectory wxString data_dir = wxStandardPaths::Get().GetDataDir(); if( bin_fn.GetPath() != data_dir ) { // add data_dir if it is different from the bin_dir maybe.AddPaths( data_dir ); } // Up one level relative to binary path with "share" appended below. bin_fn.RemoveLastDir(); maybe.AddPaths( bin_fn.GetPath() ); } /* The normal OS program file install paths allow for a binary to be * installed in a different path from the library files. This is * useful for development purposes so the library and documentation * files do not need to be installed separately. If someone can * figure out a way to implement this without #ifdef, please do. */ #if defined(__MINGW32__) maybe.AddPaths( wxGetenv( wxT( "PROGRAMFILES" ) ) ); #else maybe.AddPaths( wxGetenv( wxT( "PATH" ) ) ); #endif #endif #if defined(DEBUG) && 0 maybe.Show( "maybe wish list" ); #endif // Append 1) kicad, 2) kicad/share, 3) share, and 4) share/kicad to each // possible base path in 'maybe'. Since SEARCH_STACK::AddPaths() will verify // readability and existence of each directory, not all of these will be // actually appended. for( unsigned i = 0; i < maybe.GetCount(); ++i ) { wxFileName fn( maybe[i], wxEmptyString ); #ifndef __WXMAC__ if( fn.GetPath().AfterLast( fn.GetPathSeparator() ) == wxT( "bin" ) ) { fn.RemoveLastDir(); if( !fn.GetDirCount() ) continue; // at least on linux } #endif aSearchStack->AddPaths( fn.GetPath() ); #ifndef __WXMAC__ fn.AppendDir( wxT( "kicad" ) ); aSearchStack->AddPaths( fn.GetPath() ); // add maybe[i]/kicad fn.AppendDir( wxT( "share" ) ); aSearchStack->AddPaths( fn.GetPath() ); // add maybe[i]/kicad/share fn.RemoveLastDir(); // ../ clear share fn.RemoveLastDir(); // ../ clear kicad fn.AppendDir( wxT( "share" ) ); aSearchStack->AddPaths( fn.GetPath() ); // add maybe[i]/share fn.AppendDir( wxT( "kicad" ) ); aSearchStack->AddPaths( fn.GetPath() ); // add maybe[i]/share/kicad #endif } #if defined(DEBUG) && 0 // final results: aSearchStack->Show( __func__ ); #endif }