Audacity 3.2.0
PathList.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file PathList.cpp
6
7 Paul Licameli split from AudacityApp.cpp
8
9**********************************************************************/
10
11#include "PathList.h"
12
13#include "FileNames.h"
14#include "TempDirectory.h"
15#include <wx/stdpaths.h>
16#include <wx/utils.h>
17
18#if HAVE_DLFCN_H && !defined(DISABLE_DLADDR)
19# if __linux__ && !defined(_GNU_SOURCE)
20# define _GNU_SOURCE
21# endif
22# include <dlfcn.h>
23# define HAVE_GET_LIBRARY_PATH 1
24namespace
25{
26wxString GetLibraryPath()
27{
28 Dl_info info;
29 // This is a GNU extension, but it's also supported on FreeBSD, OpenBSD, macOS and Solaris.
30 if (dladdr(reinterpret_cast<const void*>(GetLibraryPath), &info))
31 return info.dli_fname;
32 return {};
33}
34}
35#endif
36
38{
39 auto &standardPaths = wxStandardPaths::Get();
40 const auto programPath = standardPaths.GetExecutablePath();
41
42 //
43 // Paths: set search path and temp dir path
44 //
45 FilePaths audacityPathList;
46
47#ifdef __WXGTK__
48 const auto portablePrefix = wxPathOnly(wxPathOnly(programPath));
49
50 // Make sure install prefix is set so wxStandardPath resolves paths properly
51 if (wxDirExists(portablePrefix + L"/share/audacity")) {
52 // use prefix relative to executable location to make Audacity portable
53 standardPaths.SetInstallPrefix(portablePrefix);
54 } else {
55 // fallback to hard-coded prefix set during configuration
56 standardPaths.SetInstallPrefix(wxT(INSTALL_PREFIX));
57 }
58 wxString installPrefix = standardPaths.GetInstallPrefix();
59
60 /* Search path (for plug-ins, translations etc) is (in this order):
61 * The AUDACITY_PATH environment variable
62 * The current directory
63 * The user's "~/.audacity-data" or "Portable Settings" directory
64 * The user's "~/.audacity-files" directory
65 * The "share" and "share/doc" directories in their install path */
66 wxString home = wxGetHomeDir();
67
68 wxString envTempDir = wxGetenv(wxT("TMPDIR"));
69 if (!envTempDir.empty()) {
70 /* On Unix systems, the environment variable TMPDIR may point to
71 an unusual path when /tmp and /var/tmp are not desirable. */
72 TempDirectory::SetDefaultTempDir( wxString::Format(
73 wxT("%s/audacity-%s"), envTempDir, wxGetUserId() ) );
74 } else {
75 /* On Unix systems, the default temp dir is in /var/tmp. */
76 TempDirectory::SetDefaultTempDir( wxString::Format(
77 wxT("/var/tmp/audacity-%s"), wxGetUserId() ) );
78 }
79
80 wxString pathVar = wxGetenv(wxT("AUDACITY_PATH"));
81
82 if (!pathVar.empty())
83 FileNames::AddMultiPathsToPathList(pathVar, audacityPathList);
84 FileNames::AddUniquePathToPathList(::wxGetCwd(), audacityPathList);
85
86 const auto progPath = wxPathOnly(programPath);
87
88 FileNames::AddUniquePathToPathList(progPath, audacityPathList);
89 // Add the path to modules:
90 FileNames::AddUniquePathToPathList(progPath + L"/lib/audacity", audacityPathList);
91
92#if !defined(__WXMSW__)
93 // On Unix systems, the common directory structure is
94 // .../bin
95 // .../lib
96 const wxString progParentPath = wxPathOnly(progPath);
97
98 if (!progParentPath.IsEmpty())
99 {
100 FileNames::AddUniquePathToPathList(progParentPath + L"/lib/audacity", audacityPathList);
101 FileNames::AddUniquePathToPathList(progParentPath + L"/lib", audacityPathList);
102 }
103
104#if HAVE_GET_LIBRARY_PATH
105 const wxString thisLibPath = GetLibraryPath();
106 if (!thisLibPath.IsEmpty())
107 FileNames::AddUniquePathToPathList(wxPathOnly(thisLibPath), audacityPathList);
108#endif
109#endif
110
112
113#ifdef AUDACITY_NAME
114 FileNames::AddUniquePathToPathList(wxString::Format(wxT("%s/.%s-files"),
115 home, wxT(AUDACITY_NAME)),
116 audacityPathList);
118 audacityPathList);
119 FileNames::AddUniquePathToPathList(wxString::Format(installPrefix + L"/share/%s", wxT(AUDACITY_NAME)),
120 audacityPathList);
121 FileNames::AddUniquePathToPathList(wxString::Format(installPrefix + L"/share/doc/%s", wxT(AUDACITY_NAME)),
122 audacityPathList);
123#else //AUDACITY_NAME
124 FileNames::AddUniquePathToPathList(wxString::Format(wxT("%s/.audacity-files"),
125 home),
126 audacityPathList);
128 audacityPathList);
129 FileNames::AddUniquePathToPathList(installPrefix + L"/share/audacity",
130 audacityPathList);
131 FileNames::AddUniquePathToPathList(installPrefix + L"/share/doc/audacity",
132 audacityPathList);
133#endif //AUDACITY_NAME
134
135 FileNames::AddUniquePathToPathList(installPrefix + L"/share/locale",
136 audacityPathList);
137
138 FileNames::AddUniquePathToPathList(wxString::Format(wxT("./locale")),
139 audacityPathList);
140
141#endif //__WXGTK__
142
143// JKC Bug 1220: Use path based on home directory on WXMAC
144#ifdef __WXMAC__
145 wxFileName tmpFile;
146 tmpFile.AssignHomeDir();
147 wxString tmpDirLoc = tmpFile.GetPath(wxPATH_GET_VOLUME);
148#else
149 wxFileName tmpFile;
150 tmpFile.AssignTempFileName(wxT("nn"));
151 wxString tmpDirLoc = tmpFile.GetPath(wxPATH_GET_VOLUME);
152 ::wxRemoveFile(tmpFile.GetFullPath());
153#endif
154
155
156
157 // On Mac and Windows systems, use the directory which contains Audacity.
158#ifdef __WXMSW__
159 // On Windows, the path to the Audacity program is programPath
160 const auto progPath = wxPathOnly(programPath);
161 FileNames::AddUniquePathToPathList(progPath, audacityPathList);
162 FileNames::AddUniquePathToPathList(progPath + wxT("\\Languages"), audacityPathList);
163
164 // See bug #1271 for explanation of location
165 tmpDirLoc = FileNames::MkDir(wxStandardPaths::Get().GetUserLocalDataDir());
166 TempDirectory::SetDefaultTempDir( wxString::Format(
167 wxT("%s\\SessionData"), tmpDirLoc ) );
168#endif //__WXWSW__
169
170#ifdef __WXMAC__
171 // On Mac OS X, the path to the Audacity program is programPath
172 const auto progPath = wxPathOnly(programPath);
173
174 FileNames::AddUniquePathToPathList(progPath, audacityPathList);
175 // If Audacity is a "bundle" package, then the root directory is
176 // the great-great-grandparent of the directory containing the executable.
177 //FileNames::AddUniquePathToPathList(progPath + wxT("/../../../"), audacityPathList);
178
179 // These allow for searching the "bundle"
181 progPath + wxT("/../"), audacityPathList);
183 progPath + wxT("/../Resources"), audacityPathList);
184
185 // JKC Bug 1220: Using an actual temp directory for session data on Mac was
186 // wrong because it would get cleared out on a reboot.
187 TempDirectory::SetDefaultTempDir( wxString::Format(
188 wxT("%s/Library/Application Support/audacity/SessionData"), tmpDirLoc) );
189
190 //TempDirectory::SetDefaultTempDir( wxString::Format(
191 // wxT("%s/audacity-%s"),
192 // tmpDirLoc,
193 // wxGetUserId() ) );
194#endif //__WXMAC__
195
196 FileNames::SetAudacityPathList( std::move( audacityPathList ) );
197}
wxT("CloseDown"))
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196
FILES_API wxString MkDir(const wxString &Str)
FILES_API void AddUniquePathToPathList(const FilePath &path, FilePaths &pathList)
FILES_API void InitializePathList()
FILES_API void AddMultiPathsToPathList(const wxString &multiPathString, FilePaths &pathList)
FILES_API FilePath DataDir()
Audacity user data directory.
FILES_API FilePath ModulesDir()
FILES_API void SetAudacityPathList(FilePaths list)
FILES_API void SetDefaultTempDir(const FilePath &tempDir)