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
19{
20 auto &standardPaths = wxStandardPaths::Get();
21 const auto programPath = standardPaths.GetExecutablePath();
22
23 //
24 // Paths: set search path and temp dir path
25 //
26 FilePaths audacityPathList;
27
28#ifdef __WXGTK__
29 const auto portablePrefix = wxPathOnly(wxPathOnly(programPath));
30
31 // Make sure install prefix is set so wxStandardPath resolves paths properly
32 if (wxDirExists(portablePrefix + L"/share/audacity")) {
33 // use prefix relative to executable location to make Audacity portable
34 standardPaths.SetInstallPrefix(portablePrefix);
35 } else {
36 // fallback to hard-coded prefix set during configuration
37 standardPaths.SetInstallPrefix(wxT(INSTALL_PREFIX));
38 }
39 wxString installPrefix = standardPaths.GetInstallPrefix();
40
41 /* Search path (for plug-ins, translations etc) is (in this order):
42 * The AUDACITY_PATH environment variable
43 * The current directory
44 * The user's "~/.audacity-data" or "Portable Settings" directory
45 * The user's "~/.audacity-files" directory
46 * The "share" and "share/doc" directories in their install path */
47 wxString home = wxGetHomeDir();
48
49 wxString envTempDir = wxGetenv(wxT("TMPDIR"));
50 if (!envTempDir.empty()) {
51 /* On Unix systems, the environment variable TMPDIR may point to
52 an unusual path when /tmp and /var/tmp are not desirable. */
53 TempDirectory::SetDefaultTempDir( wxString::Format(
54 wxT("%s/audacity-%s"), envTempDir, wxGetUserId() ) );
55 } else {
56 /* On Unix systems, the default temp dir is in /var/tmp. */
57 TempDirectory::SetDefaultTempDir( wxString::Format(
58 wxT("/var/tmp/audacity-%s"), wxGetUserId() ) );
59 }
60
61// DA: Path env variable.
62#ifndef EXPERIMENTAL_DA
63 wxString pathVar = wxGetenv(wxT("AUDACITY_PATH"));
64#else
65 wxString pathVar = wxGetenv(wxT("DARKAUDACITY_PATH"));
66#endif
67 if (!pathVar.empty())
68 FileNames::AddMultiPathsToPathList(pathVar, audacityPathList);
69 FileNames::AddUniquePathToPathList(::wxGetCwd(), audacityPathList);
70
71 const auto progPath = wxPathOnly(programPath);
72
73 FileNames::AddUniquePathToPathList(progPath, audacityPathList);
74 // Add the path to modules:
75 FileNames::AddUniquePathToPathList(progPath + L"/lib/audacity", audacityPathList);
76
77#if !defined(__WXMSW__)
78 // On Unix systems, the common directory structure is
79 // .../bin
80 // .../lib
81 const wxString progParentPath = wxPathOnly(progPath);
82
83 if (!progParentPath.IsEmpty())
84 {
85 FileNames::AddUniquePathToPathList(progParentPath + L"/lib/audacity", audacityPathList);
86 FileNames::AddUniquePathToPathList(progParentPath + L"/lib", audacityPathList);
87 }
88#endif
89
91
92#ifdef AUDACITY_NAME
93 FileNames::AddUniquePathToPathList(wxString::Format(wxT("%s/.%s-files"),
94 home, wxT(AUDACITY_NAME)),
95 audacityPathList);
97 audacityPathList);
98 FileNames::AddUniquePathToPathList(wxString::Format(installPrefix + L"/share/%s", wxT(AUDACITY_NAME)),
99 audacityPathList);
100 FileNames::AddUniquePathToPathList(wxString::Format(installPrefix + L"/share/doc/%s", wxT(AUDACITY_NAME)),
101 audacityPathList);
102#else //AUDACITY_NAME
103 FileNames::AddUniquePathToPathList(wxString::Format(wxT("%s/.audacity-files"),
104 home),
105 audacityPathList);
107 audacityPathList);
108 FileNames::AddUniquePathToPathList(installPrefix + L"/share/audacity",
109 audacityPathList);
110 FileNames::AddUniquePathToPathList(installPrefix + L"/share/doc/audacity",
111 audacityPathList);
112#endif //AUDACITY_NAME
113
114 FileNames::AddUniquePathToPathList(installPrefix + L"/share/locale",
115 audacityPathList);
116
117 FileNames::AddUniquePathToPathList(wxString::Format(wxT("./locale")),
118 audacityPathList);
119
120#endif //__WXGTK__
121
122// JKC Bug 1220: Use path based on home directory on WXMAC
123#ifdef __WXMAC__
124 wxFileName tmpFile;
125 tmpFile.AssignHomeDir();
126 wxString tmpDirLoc = tmpFile.GetPath(wxPATH_GET_VOLUME);
127#else
128 wxFileName tmpFile;
129 tmpFile.AssignTempFileName(wxT("nn"));
130 wxString tmpDirLoc = tmpFile.GetPath(wxPATH_GET_VOLUME);
131 ::wxRemoveFile(tmpFile.GetFullPath());
132#endif
133
134
135
136 // On Mac and Windows systems, use the directory which contains Audacity.
137#ifdef __WXMSW__
138 // On Windows, the path to the Audacity program is programPath
139 const auto progPath = wxPathOnly(programPath);
140 FileNames::AddUniquePathToPathList(progPath, audacityPathList);
141 FileNames::AddUniquePathToPathList(progPath + wxT("\\Languages"), audacityPathList);
142
143 // See bug #1271 for explanation of location
144 tmpDirLoc = FileNames::MkDir(wxStandardPaths::Get().GetUserLocalDataDir());
145 TempDirectory::SetDefaultTempDir( wxString::Format(
146 wxT("%s\\SessionData"), tmpDirLoc ) );
147#endif //__WXWSW__
148
149#ifdef __WXMAC__
150 // On Mac OS X, the path to the Audacity program is programPath
151 const auto progPath = wxPathOnly(programPath);
152
153 FileNames::AddUniquePathToPathList(progPath, audacityPathList);
154 // If Audacity is a "bundle" package, then the root directory is
155 // the great-great-grandparent of the directory containing the executable.
156 //FileNames::AddUniquePathToPathList(progPath + wxT("/../../../"), audacityPathList);
157
158 // These allow for searching the "bundle"
160 progPath + wxT("/../"), audacityPathList);
162 progPath + wxT("/../Resources"), audacityPathList);
163
164 // JKC Bug 1220: Using an actual temp directory for session data on Mac was
165 // wrong because it would get cleared out on a reboot.
166 TempDirectory::SetDefaultTempDir( wxString::Format(
167 wxT("%s/Library/Application Support/audacity/SessionData"), tmpDirLoc) );
168
169 //TempDirectory::SetDefaultTempDir( wxString::Format(
170 // wxT("%s/audacity-%s"),
171 // tmpDirLoc,
172 // wxGetUserId() ) );
173#endif //__WXMAC__
174
175 FileNames::SetAudacityPathList( std::move( audacityPathList ) );
176}
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:194
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)