KiCad PCB EDA Suite
Loading...
Searching...
No Matches
systemdirsappend.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2014 CERN
5 * Copyright (C) 2014 KiCad Developers, see AUTHORS.TXT for contributors.
6 * @author Maciej Suminski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <wx/stdpaths.h>
27
28#include <systemdirsappend.h>
29#include <common.h>
31#include <search_stack.h>
32#include <pgm_base.h>
33#include <config.h> // to define DEFAULT_INSTALL_PATH
34#include <paths.h>
35
36// put your best guesses in here, send the computer on a wild goose chase, its
37// got nothing else to do.
38
39void SystemDirsAppend( SEARCH_STACK* aSearchStack )
40{
41 // No clearing is done here, the most general approach is NOT to assume that
42 // our appends will be the only thing in the stack. This function has no
43 // knowledge of caller's intentions.
44
45 // wxPathList::AddEnvList() is broken, use SEARCH_STACK::AddPaths().
46 // SEARCH_STACK::AddPaths() will verify readability and existence of
47 // each directory before adding.
48 SEARCH_STACK maybe;
49
50 // User environment variable path is the first search path. Chances are
51 // if the user is savvy enough to set an environment variable they know
52 // what they are doing. It should take precedence over anything else.
53 // Otherwise don't set it.
54 maybe.AddPaths( wxGetenv( wxT( "KICAD" ) ) );
55
56#ifdef __WXMAC__
57 // Add the directory for the user-dependent, program specific data files.
58 maybe.AddPaths( PATHS::GetOSXKicadUserDataDir() );
59
60 // Global machine specific application data
61 maybe.AddPaths( PATHS::GetOSXKicadMachineDataDir() );
62
63 // Global application specific data files inside bundle
64 maybe.AddPaths( PATHS::GetOSXKicadDataDir() );
65#else
66 // This is from CMAKE_INSTALL_PREFIX.
67 // Useful when KiCad is installed by `make install`.
68 // Use as second ranked place.
69 maybe.AddPaths( wxT( DEFAULT_INSTALL_PATH ) );
70
71#ifdef __WXGTK__
72 // On Linux, the stock EDA library data install path can be redefined via
73 // KICAD_LIBRARY_DATA, otherwise KICAD_DATA will be used.
74 // Useful when multiple versions of KiCad are installed in parallel.
76#endif
77
78 // Add the directory for the user-dependent, program specific data files.
79 // According to wxWidgets documentation:
80 // Unix: ~/.appname
81 // Windows: C:\Documents and Settings\username\Application Data\appname
83
84 {
85 // Should be full path to this program executable.
86 wxString bin_dir = Pgm().GetExecutablePath();
87
88#if defined(_WIN32)
89 // bin_dir uses unix path separator. So to parse with wxFileName
90 // use windows separator, especially important for server inclusion:
91 // like: \\myserver\local_path .
92 bin_dir.Replace( wxFileName::GetPathSeparator( wxPATH_UNIX ),
93 wxFileName::GetPathSeparator( wxPATH_WIN ) );
94#endif
95
96 wxFileName bin_fn( bin_dir, wxEmptyString );
97
98 // Dir of the global (not user-specific), application specific, data files.
99 // From wx docs:
100 // Unix: prefix/share/appname
101 // Windows: the directory where the executable file is located
102 // Mac: appname.app/Contents/SharedSupport bundle subdirectory
103 wxString data_dir = wxStandardPaths::Get().GetDataDir();
104
105 if( bin_fn.GetPath() != data_dir )
106 {
107 // add data_dir if it is different from the bin_dir
108 maybe.AddPaths( data_dir );
109 }
110
111 // Up one level relative to binary path with "share" appended below.
112 bin_fn.RemoveLastDir();
113 maybe.AddPaths( bin_fn.GetPath() );
114 }
115
116 /* The normal OS program file install paths allow for a binary to be
117 * installed in a different path from the library files. This is
118 * useful for development purposes so the library and documentation
119 * files do not need to be installed separately. If someone can
120 * figure out a way to implement this without #ifdef, please do.
121 */
122#if defined(_WIN32)
123 maybe.AddPaths( wxGetenv( wxT( "PROGRAMFILES" ) ) );
124#else
125 maybe.AddPaths( wxGetenv( wxT( "PATH" ) ) );
126#endif
127#endif
128
129#if defined(DEBUG) && 0
130 maybe.Show( "maybe wish list" );
131#endif
132
133 // Append 1) kicad, 2) kicad/share, 3) share, and 4) share/kicad to each
134 // possible base path in 'maybe'. Since SEARCH_STACK::AddPaths() will verify
135 // readability and existence of each directory, not all of these will be
136 // actually appended.
137 for( unsigned i = 0; i < maybe.GetCount(); ++i )
138 {
139 wxFileName fn( maybe[i], wxEmptyString );
140
141#ifndef __WXMAC__
142 if( fn.GetPath().AfterLast( fn.GetPathSeparator() ) == wxT( "bin" ) )
143 {
144 fn.RemoveLastDir();
145
146 if( !fn.GetDirCount() )
147 continue; // at least on linux
148 }
149#endif
150
151 aSearchStack->AddPaths( fn.GetPath() );
152
153#ifndef __WXMAC__
154 fn.AppendDir( wxT( "kicad" ) );
155 aSearchStack->AddPaths( fn.GetPath() ); // add maybe[i]/kicad
156
157 fn.AppendDir( wxT( "share" ) );
158 aSearchStack->AddPaths( fn.GetPath() ); // add maybe[i]/kicad/share
159
160 fn.RemoveLastDir(); // ../ clear share
161 fn.RemoveLastDir(); // ../ clear kicad
162
163 fn.AppendDir( wxT( "share" ) );
164 aSearchStack->AddPaths( fn.GetPath() ); // add maybe[i]/share
165
166 fn.AppendDir( wxT( "kicad" ) );
167 aSearchStack->AddPaths( fn.GetPath() ); // add maybe[i]/share/kicad
168#endif
169 }
170
171#if defined(DEBUG) && 0
172 // final results:
173 aSearchStack->Show( __func__ );
174#endif
175}
176
177
179{
180 SEARCH_STACK bases;
181
182 SystemDirsAppend( &bases );
183 aDst->Clear();
184
185 for( unsigned i = 0; i < bases.GetCount(); ++i )
186 {
187 wxFileName fn( bases[i], wxEmptyString );
188
189 // Add schematic library file path to search path list.
190 // we must add <kicad path>/library and <kicad path>/library/doc
191 if( aId == KIWAY::FACE_SCH )
192 {
193 // Add schematic doc file path (library/doc) to search path list.
194
195 fn.AppendDir( wxT( "library" ) );
196 aDst->AddPaths( fn.GetPath() );
197
198 fn.AppendDir( wxT( "doc" ) );
199 aDst->AddPaths( fn.GetPath() );
200
201 fn.RemoveLastDir();
202 fn.RemoveLastDir(); // "../../" up twice, removing library/doc/
203
204 fn.AppendDir( wxT( "symbols" ) );
205 aDst->AddPaths( fn.GetPath() );
206
207 fn.AppendDir( wxT( "doc" ) );
208 aDst->AddPaths( fn.GetPath() );
209
210 fn.RemoveLastDir();
211 fn.RemoveLastDir(); // "../../" up twice, removing symbols/doc/
212 }
213
214 // Add PCB library file path to search path list.
215 if( aId == KIWAY::FACE_PCB || aId == KIWAY::FACE_CVPCB )
216 {
217 fn.AppendDir( wxT( "modules" ) );
218 aDst->AddPaths( fn.GetPath() );
219 fn.RemoveLastDir();
220
221 fn.AppendDir( wxT( "footprints" ) );
222 aDst->AddPaths( fn.GetPath() );
223 fn.RemoveLastDir();
224
225 // Add 3D module library file path to search path list.
226 fn.AppendDir( wxT( "3dmodels" ) );
227 aDst->AddPaths( fn.GetPath() );
228 fn.RemoveLastDir();
229 }
230
231 // Add KiCad template file path to search path list.
232 fn.AppendDir( wxT( "template" ) );
233 aDst->AddPaths( fn.GetPath() );
234 }
235
236#ifndef __WXMAC__
237 aDst->AddPaths( wxT( "/usr/local/share" ) );
238#endif
239}
FACE_T
Known KIFACE implementations.
Definition: kiway.h:285
@ FACE_SCH
eeschema DSO
Definition: kiway.h:286
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:287
@ FACE_CVPCB
Definition: kiway.h:288
static wxString GetStockEDALibraryPath()
Gets the stock (install) EDA library data path, which is the base path for templates,...
Definition: paths.cpp:191
virtual const wxString & GetExecutablePath() const
Definition: pgm_base.cpp:1038
Look for files in a number of paths.
Definition: search_stack.h:43
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
The common library.
wxString GetDocumentsPath()
Retrieves the operating system specific path for a user's documents.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
void GlobalPathsAppend(SEARCH_STACK *aDst, KIWAY::FACE_T aId)
Initialize aDst SEARCH_STACK with KIFACE (DSO) specific settings.
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
System directories search utilities.