Audacity 3.2.0
FileNames.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 FileNames.h
6
7 James Crook
8
9**********************************************************************/
10
11#ifndef __AUDACITY_FILE_NAMES__
12#define __AUDACITY_FILE_NAMES__
13
14#include <wx/dir.h> // for wxDIR_FILES
15#include "Identifier.h"
16#include "Prefs.h"
17
18// Please try to support unlimited path length instead of using PLATFORM_MAX_PATH!
19// Define one constant for maximum path value, so we don't have to do
20// platform-specific conditionals everywhere we want to check it.
21#define PLATFORM_MAX_PATH 260 // Play it safe for default, with same value as Windows' MAX_PATH.
22
23#ifdef __WXMAC__
24#undef PLATFORM_MAX_PATH
25#define PLATFORM_MAX_PATH PATH_MAX
26#endif
27
28#ifdef __WXGTK__
29// Some systems do not restrict the path length and therefore PATH_MAX is undefined
30#ifdef PATH_MAX
31#undef PLATFORM_MAX_PATH
32#define PLATFORM_MAX_PATH PATH_MAX
33#endif
34#endif
35
36#ifdef __WXX11__
37// wxX11 should also get the platform-specific definition of PLATFORM_MAX_PATH, so do not declare here.
38#endif
39
40#ifdef __WXMSW__
41#undef PLATFORM_MAX_PATH
42#define PLATFORM_MAX_PATH MAX_PATH
43#endif
44
45class wxFileName;
47
48namespace FileNames
49{
50 // A description of a type of file
51 struct FileType {
52 FileType() = default;
53
55 : description{ std::move( d ) }
56 , extensions( std::move( e ) )
57 , appendExtensions{ a }
58 {}
59
62 // Whether to extend the displayed description with mention of the
63 // extensions:
64 bool appendExtensions = false;
65 };
66
67 // Frequently used types
68 extern FILES_API const FileType
70 , AudacityProjects // *.aup3
71 , DynamicLibraries // depends on the operating system
72 , TextFiles // *.txt
73 , XMLFiles; // *.xml, *.XML
74
75 using FileTypes = std::vector< FileType >;
76
77 // Convert fileTypes into a single string as expected by wxWidgets file
78 // selection dialog
79 FILES_API wxString FormatWildcard( const FileTypes &fileTypes );
80
81 // This exists to compensate for bugs in wxCopyFile:
82 FILES_API bool DoCopyFile(
83 const FilePath& file1, const FilePath& file2, bool overwrite = true);
84
85 // wxWidgets doesn't have a function to do this: make a hard file-system
86 // link if possible. It might not be, as when the paths are on different
87 // storage devices.
88 FILES_API
89 bool HardLinkFile( const FilePath& file1, const FilePath& file2);
90
91 FILES_API wxString MkDir(const wxString &Str);
92
101 FILES_API const FilePaths &AudacityPathList();
102 FILES_API void SetAudacityPathList( FilePaths list );
103
104 // originally an ExportMultipleDialog method. Append suffix if newName appears in otherNames.
105 FILES_API void MakeNameUnique(
106 FilePaths &otherNames, wxFileName &newName);
107
108 FILES_API wxString LowerCaseAppNameInPath( const wxString & dirIn);
109
114 FILES_API FilePath CacheDir();
119 FILES_API FilePath ConfigDir();
124 FILES_API FilePath DataDir();
129 FILES_API FilePath StateDir();
130
133 FILES_API FilePath HtmlHelpIndexFile(bool quick);
135 FILES_API FilePath MacroDir();
136 FILES_API FilePath NRPDir();
137 FILES_API FilePath NRPFile();
141
142 FILES_API FilePath BaseDir();
143 FILES_API FilePath ModulesDir();
144
150 FILES_API FilePath PlugInDir();
151
152 // Obtain name of loaded module that contains address
153 FILES_API FilePath PathFromAddr(void *addr);
154
155 FILES_API bool IsPathAvailable( const FilePath & Path);
157 (const wxString &preference);
158
159 // If not None, determines a preference key (for the default path string) to
160 // be read and updated
161 enum class Operation {
162 // _ on None to defeat some macro that is expanding this.
163 _None,
164
165 // These do not have a specific pathtype
166 Temp,
167 Presets,
168
169 // These have default/lastused pathtypes
170 Open,
171 Save,
172 Import,
173 Export,
174 MacrosOut
175 };
176
177 enum class PathType {
178 // _ on None to defeat some macro that is expanding this.
179 _None,
180 User,
181 LastUsed
182 };
183
185
187 FILES_API void UpdateDefaultPath(Operation op, const FilePath &path);
188
189 // F is a function taking a wxString, returning wxString
190 template<typename F>
192 (Operation op, const FilePath &defaultPath, F function)
193 {
194 auto path = gPrefs->Read(PreferenceKey(op, PathType::User), defaultPath);
195 if (path.empty())
197 auto result = function(path);
198 FileNames::UpdateDefaultPath(op, ::wxPathOnly(result));
199 return result;
200 }
201
202 // Useful functions for working with search paths
203 FILES_API void AddUniquePathToPathList(const FilePath &path,
204 FilePaths &pathList);
205 FILES_API void AddMultiPathsToPathList(const wxString &multiPathString,
206 FilePaths &pathList);
207 FILES_API void FindFilesInPathList(const wxString & pattern,
208 const FilePaths & pathList,
209 FilePaths &results,
210 int flags = wxDIR_FILES);
211
212
214 // message is the explanation that is to be displayed to the user if the location is unwritable.
215 FILES_API bool WritableLocationCheck(const FilePath& path,
216 const TranslatableString & message);
217
218 // wxString compare function for sorting case, which is needed to load correctly.
219 FILES_API int CompareNoCase(const wxString& first, const wxString& second);
220
221 // Create a unique filename using the passed prefix and suffix
222 FILES_API wxString CreateUniqueName(const wxString &prefix,
223 const wxString &suffix = wxEmptyString);
224
225 // File extension used for unsaved/temporary project files
226 FILES_API wxString UnsavedProjectExtension();
227
228 FILES_API
229 bool IsOnFATFileSystem(const FilePath &path);
230
231 FILES_API
233 wxString AbbreviatePath(const wxFileName &fileName);
234};
235
236#endif
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
wxString FilePath
Definition: Project.h:21
Main class to control the export function.
FILES_API const FileType XMLFiles
Definition: FileNames.h:73
std::vector< FileType > FileTypes
Definition: FileNames.h:75
FILES_API const FileType AllFiles
Definition: FileNames.h:70
FILES_API const FileType DynamicLibraries
Definition: FileNames.h:72
FILES_API const FileType TextFiles
Definition: FileNames.h:73
FILES_API const FileType AudacityProjects
Definition: FileNames.h:71
Holds a msgid for the translation catalog; may also bind format arguments.
virtual bool Read(const wxString &key, bool *value) const =0
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
FILES_API FilePath MacroDir()
FILES_API bool IsOnFATFileSystem(const FilePath &path)
FILES_API FilePath PlugInDir()
The user plug-in directory (not a system one)
FILES_API FilePath Configuration()
FILES_API bool HardLinkFile(const FilePath &file1, const FilePath &file2)
FILES_API FilePath HtmlHelpDir()
FILES_API FilePath NRPFile()
FILES_API bool IsPathAvailable(const FilePath &Path)
FILES_API wxString LowerCaseAppNameInPath(const wxString &dirIn)
FILES_API wxString CreateUniqueName(const wxString &prefix, const wxString &suffix=wxEmptyString)
FILES_API wxString MkDir(const wxString &Str)
FILES_API wxFileNameWrapper DefaultToDocumentsFolder(const wxString &preference)
FILES_API wxString UnsavedProjectExtension()
FILES_API void AddUniquePathToPathList(const FilePath &path, FilePaths &pathList)
FILES_API FilePath ResourcesDir()
FILES_API FilePath ConfigDir()
Audacity user config directory.
FILES_API FilePath HtmlHelpIndexFile(bool quick)
FILES_API wxString PreferenceKey(FileNames::Operation op, FileNames::PathType type)
FILES_API FilePath StateDir()
Audacity user state directory.
FILES_API void FindFilesInPathList(const wxString &pattern, const FilePaths &pathList, FilePaths &results, int flags=wxDIR_FILES)
FILES_API bool DoCopyFile(const FilePath &file1, const FilePath &file2, bool overwrite=true)
FILES_API FilePath CacheDir()
Audacity user cache directory.
FILES_API bool WritableLocationCheck(const FilePath &path, const TranslatableString &message)
Check location on writable access and return true if checked successfully.
FILES_API void AddMultiPathsToPathList(const wxString &multiPathString, FilePaths &pathList)
FILES_API FilePath PathFromAddr(void *addr)
FILES_API wxString AbbreviatePath(const wxFileName &fileName)
Give enough of the path to identify the device. (On Windows, drive letter plus ':')
FILES_API wxString FormatWildcard(const FileTypes &fileTypes)
FILES_API FilePath BaseDir()
FILES_API FilePath DataDir()
Audacity user data directory.
FILES_API void UpdateDefaultPath(Operation op, const FilePath &path)
FilePath WithDefaultPath(Operation op, const FilePath &defaultPath, F function)
Definition: FileNames.h:192
FILES_API FilePath ModulesDir()
FILES_API FilePath PluginRegistry()
FILES_API FilePath LegacyChainDir()
FILES_API FilePath NRPDir()
FILES_API void MakeNameUnique(FilePaths &otherNames, wxFileName &newName)
FILES_API int CompareNoCase(const wxString &first, const wxString &second)
FILES_API FilePath FindDefaultPath(Operation op)
FILES_API FilePath PluginSettings()
FILES_API const FilePaths & AudacityPathList()
A list of directories that should be searched for Audacity files (plug-ins, help files,...
FILES_API void SetAudacityPathList(FilePaths list)
STL namespace.
FileType(TranslatableString d, FileExtensions e, bool a=false)
Definition: FileNames.h:54
TranslatableString description
Definition: FileNames.h:60
FileExtensions extensions
Definition: FileNames.h:61