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
93 FILES_API bool IsMidi(const FilePath &fName);
94
103 FILES_API const FilePaths &AudacityPathList();
104 FILES_API void SetAudacityPathList( FilePaths list );
105
106 // originally an ExportMultipleDialog method. Append suffix if newName appears in otherNames.
107 FILES_API void MakeNameUnique(
108 FilePaths &otherNames, wxFileName &newName);
109
110 FILES_API wxString LowerCaseAppNameInPath( const wxString & dirIn);
111
116 FILES_API FilePath CacheDir();
121 FILES_API FilePath ConfigDir();
126 FILES_API FilePath DataDir();
131 FILES_API FilePath StateDir();
132
135 FILES_API FilePath HtmlHelpIndexFile(bool quick);
137 FILES_API FilePath MacroDir();
138 FILES_API FilePath NRPDir();
139 FILES_API FilePath NRPFile();
143
144 FILES_API FilePath BaseDir();
145 FILES_API FilePath ModulesDir();
146
152 FILES_API FilePath PlugInDir();
153
154 // Obtain name of loaded module that contains address
155 FILES_API FilePath PathFromAddr(void *addr);
156
157 FILES_API bool IsPathAvailable( const FilePath & Path);
159 (const wxString &preference);
160
161 // If not None, determines a preference key (for the default path string) to
162 // be read and updated
163 enum class Operation {
164 // _ on None to defeat some macro that is expanding this.
165 _None,
166
167 // These do not have a specific pathtype
168 Temp,
169 Presets,
170
171 // These have default/lastused pathtypes
172 Open,
173 Save,
174 Import,
175 Export,
176 MacrosOut
177 };
178
179 enum class PathType {
180 // _ on None to defeat some macro that is expanding this.
181 _None,
182 User,
183 LastUsed
184 };
185
187
189 FILES_API void UpdateDefaultPath(Operation op, const FilePath &path);
190
191 // F is a function taking a wxString, returning wxString
192 template<typename F>
194 (Operation op, const FilePath &defaultPath, F function)
195 {
196 auto path = gPrefs->Read(PreferenceKey(op, PathType::User), defaultPath);
197 if (path.empty())
199 auto result = function(path);
200 FileNames::UpdateDefaultPath(op, ::wxPathOnly(result));
201 return result;
202 }
203
204 // Useful functions for working with search paths
205 FILES_API void AddUniquePathToPathList(const FilePath &path,
206 FilePaths &pathList);
207 FILES_API void AddMultiPathsToPathList(const wxString &multiPathString,
208 FilePaths &pathList);
209 FILES_API void FindFilesInPathList(const wxString & pattern,
210 const FilePaths & pathList,
211 FilePaths &results,
212 int flags = wxDIR_FILES);
213
214
216 // message is the explanation that is to be displayed to the user if the location is unwritable.
217 FILES_API bool WritableLocationCheck(const FilePath& path,
218 const TranslatableString & message);
219
220 // wxString compare function for sorting case, which is needed to load correctly.
221 FILES_API int CompareNoCase(const wxString& first, const wxString& second);
222
223 // Create a unique filename using the passed prefix and suffix
224 FILES_API wxString CreateUniqueName(const wxString &prefix,
225 const wxString &suffix = wxEmptyString);
226
227 // File extension used for unsaved/temporary project files
228 FILES_API wxString UnsavedProjectExtension();
229
230 FILES_API
231 bool IsOnFATFileSystem(const FilePath &path);
232
233 FILES_API
235 wxString AbbreviatePath(const wxFileName &fileName);
236};
237
238#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 IsMidi(const FilePath &fName)
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:194
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