KiCad PCB EDA Suite
systemdirsappend.h File Reference

System directories search utilities. More...

Go to the source code of this file.

Functions

void SystemDirsAppend (SEARCH_STACK *aSearchStack)
 Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs. More...
 

Detailed Description

System directories search utilities.

Definition in file systemdirsappend.h.

Function Documentation

◆ SystemDirsAppend()

void SystemDirsAppend ( SEARCH_STACK aSearchStack)

Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.

Definition at line 38 of file systemdirsappend.cpp.

39 {
40  // No clearing is done here, the most general approach is NOT to assume that
41  // our appends will be the only thing in the stack. This function has no
42  // knowledge of caller's intentions.
43 
44  // wxPathList::AddEnvList() is broken, use SEARCH_STACK::AddPaths().
45  // SEARCH_STACK::AddPaths() will verify readability and existence of
46  // each directory before adding.
47  SEARCH_STACK maybe;
48 
49  // User environment variable path is the first search path. Chances are
50  // if the user is savvy enough to set an environment variable they know
51  // what they are doing. It should take precedence over anything else.
52  // Otherwise don't set it.
53  maybe.AddPaths( wxGetenv( wxT( "KICAD" ) ) );
54 
55 #ifdef __WXMAC__
56  // Add the directory for the user-dependent, program specific data files.
57  maybe.AddPaths( PATHS::GetOSXKicadUserDataDir() );
58 
59  // Global machine specific application data
60  maybe.AddPaths( PATHS::GetOSXKicadMachineDataDir() );
61 
62  // Global application specific data files inside bundle
63  maybe.AddPaths( PATHS::GetOSXKicadDataDir() );
64 #else
65  // This is from CMAKE_INSTALL_PREFIX.
66  // Useful when KiCad is installed by `make install`.
67  // Use as second ranked place.
68  maybe.AddPaths( wxT( DEFAULT_INSTALL_PATH ) );
69 
70 #ifdef __WXGTK__
71  // On Linux, the stock EDA library data install path can be redefined via
72  // KICAD_LIBRARY_DATA, otherwise KICAD_DATA will be used.
73  // Useful when multiple versions of KiCad are installed in parallel.
75 #endif
76 
77  // Add the directory for the user-dependent, program specific data files.
78  // According to wxWidgets documentation:
79  // Unix: ~/.appname
80  // Windows: C:\Documents and Settings\username\Application Data\appname
82 
83  {
84  // Should be full path to this program executable.
85  wxString bin_dir = Pgm().GetExecutablePath();
86 
87 #if defined(_WIN32)
88  // bin_dir uses unix path separator. So to parse with wxFileName
89  // use windows separator, especially important for server inclusion:
90  // like: \\myserver\local_path .
91  bin_dir.Replace( wxFileName::GetPathSeparator( wxPATH_UNIX ),
92  wxFileName::GetPathSeparator( wxPATH_WIN ) );
93 #endif
94 
95  wxFileName bin_fn( bin_dir, wxEmptyString );
96 
97  // Dir of the global (not user-specific), application specific, data files.
98  // From wx docs:
99  // Unix: prefix/share/appname
100  // Windows: the directory where the executable file is located
101  // Mac: appname.app/Contents/SharedSupport bundle subdirectory
102  wxString data_dir = wxStandardPaths::Get().GetDataDir();
103 
104  if( bin_fn.GetPath() != data_dir )
105  {
106  // add data_dir if it is different from the bin_dir
107  maybe.AddPaths( data_dir );
108  }
109 
110  // Up one level relative to binary path with "share" appended below.
111  bin_fn.RemoveLastDir();
112  maybe.AddPaths( bin_fn.GetPath() );
113  }
114 
115  /* The normal OS program file install paths allow for a binary to be
116  * installed in a different path from the library files. This is
117  * useful for development purposes so the library and documentation
118  * files do not need to be installed separately. If someone can
119  * figure out a way to implement this without #ifdef, please do.
120  */
121 #if defined(_WIN32)
122  maybe.AddPaths( wxGetenv( wxT( "PROGRAMFILES" ) ) );
123 #else
124  maybe.AddPaths( wxGetenv( wxT( "PATH" ) ) );
125 #endif
126 #endif
127 
128 #if defined(DEBUG) && 0
129  maybe.Show( "maybe wish list" );
130 #endif
131 
132  // Append 1) kicad, 2) kicad/share, 3) share, and 4) share/kicad to each
133  // possible base path in 'maybe'. Since SEARCH_STACK::AddPaths() will verify
134  // readability and existence of each directory, not all of these will be
135  // actually appended.
136  for( unsigned i = 0; i < maybe.GetCount(); ++i )
137  {
138  wxFileName fn( maybe[i], wxEmptyString );
139 
140 #ifndef __WXMAC__
141  if( fn.GetPath().AfterLast( fn.GetPathSeparator() ) == wxT( "bin" ) )
142  {
143  fn.RemoveLastDir();
144 
145  if( !fn.GetDirCount() )
146  continue; // at least on linux
147  }
148 #endif
149 
150  aSearchStack->AddPaths( fn.GetPath() );
151 
152 #ifndef __WXMAC__
153  fn.AppendDir( wxT( "kicad" ) );
154  aSearchStack->AddPaths( fn.GetPath() ); // add maybe[i]/kicad
155 
156  fn.AppendDir( wxT( "share" ) );
157  aSearchStack->AddPaths( fn.GetPath() ); // add maybe[i]/kicad/share
158 
159  fn.RemoveLastDir(); // ../ clear share
160  fn.RemoveLastDir(); // ../ clear kicad
161 
162  fn.AppendDir( wxT( "share" ) );
163  aSearchStack->AddPaths( fn.GetPath() ); // add maybe[i]/share
164 
165  fn.AppendDir( wxT( "kicad" ) );
166  aSearchStack->AddPaths( fn.GetPath() ); // add maybe[i]/share/kicad
167 #endif
168  }
169 
170 #if defined(DEBUG) && 0
171  // final results:
172  aSearchStack->Show( __func__ );
173 #endif
174 }
wxString GetDocumentsPath()
Retrieves the operating system specific path for a user's documents.
Look for files in a number of paths.
Definition: search_stack.h:41
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
static wxString GetStockEDALibraryPath()
Gets the stock (install) EDA library data path, which is the base path for templates,...
Definition: paths.cpp:165
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).

References SEARCH_STACK::AddPaths(), KIPLATFORM::ENV::GetDocumentsPath(), PATHS::GetStockEDALibraryPath(), and Pgm().

Referenced by PGM_BASE::InitPgm(), SYMBOL_LIB_TABLE::LoadGlobalTable(), FP_LIB_TABLE::LoadGlobalTable(), PGM_KICAD::OnPgmInit(), PGM_BASE::SetLanguagePath(), setSearchPaths(), and DIALOG_GLOBAL_LIB_TABLE_CONFIG::TransferDataToWindow().