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 <wx/string.h> // function return value
16#include "Identifier.h"
17#include "Prefs.h"
18
19// Please try to support unlimited path length instead of using PLATFORM_MAX_PATH!
20// Define one constant for maximum path value, so we don't have to do
21// platform-specific conditionals everywhere we want to check it.
22#define PLATFORM_MAX_PATH 260 // Play it safe for default, with same value as Windows' MAX_PATH.
23
24#ifdef __WXMAC__
25#undef PLATFORM_MAX_PATH
26#define PLATFORM_MAX_PATH PATH_MAX
27#endif
28
29#ifdef __WXGTK__
30// Some systems do not restrict the path length and therefore PATH_MAX is undefined
31#ifdef PATH_MAX
32#undef PLATFORM_MAX_PATH
33#define PLATFORM_MAX_PATH PATH_MAX
34#endif
35#endif
36
37#ifdef __WXX11__
38// wxX11 should also get the platform-specific definition of PLATFORM_MAX_PATH, so do not declare here.
39#endif
40
41#ifdef __WXMSW__
42#undef PLATFORM_MAX_PATH
43#define PLATFORM_MAX_PATH MAX_PATH
44#endif
45
46class wxFileName;
48
49namespace FileNames
50{
51 // A description of a type of file
52 struct FileType {
53 FileType() = default;
54
56 : description{ std::move( d ) }
57 , extensions( std::move( e ) )
58 , appendExtensions{ a }
59 {}
60
63 // Whether to extend the displayed description with mention of the
64 // extensions:
65 bool appendExtensions = false;
66 };
67
68 // Frequently used types
69 extern FILES_API const FileType
71 , AudacityProjects // *.aup3
72 , DynamicLibraries // depends on the operating system
73 , TextFiles // *.txt
74 , XMLFiles; // *.xml, *.XML
75
76 using FileTypes = std::vector< FileType >;
77
78 // Convert fileTypes into a single string as expected by wxWidgets file
79 // selection dialog
80 FILES_API wxString FormatWildcard( const FileTypes &fileTypes );
81
82 // This exists to compensate for bugs in wxCopyFile:
83 FILES_API bool DoCopyFile(
84 const FilePath& file1, const FilePath& file2, bool overwrite = true);
85
86 // wxWidgets doesn't have a function to do this: make a hard file-system
87 // link if possible. It might not be, as when the paths are on different
88 // storage devices.
89 FILES_API
90 bool HardLinkFile( const FilePath& file1, const FilePath& file2);
91
92 FILES_API wxString MkDir(const wxString &Str);
93
94 FILES_API bool IsMidi(const FilePath &fName);
95
104 FILES_API const FilePaths &AudacityPathList();
105 FILES_API void SetAudacityPathList( FilePaths list );
106
107 // originally an ExportMultipleDialog method. Append suffix if newName appears in otherNames.
108 FILES_API void MakeNameUnique(
109 FilePaths &otherNames, wxFileName &newName);
110
111 FILES_API wxString LowerCaseAppNameInPath( const wxString & dirIn);
112
117 FILES_API FilePath CacheDir();
122 FILES_API FilePath ConfigDir();
127 FILES_API FilePath DataDir();
132 FILES_API FilePath StateDir();
133
136 FILES_API FilePath HtmlHelpIndexFile(bool quick);
138 FILES_API FilePath MacroDir();
139 FILES_API FilePath NRPDir();
140 FILES_API FilePath NRPFile();
144
145 FILES_API FilePath BaseDir();
146 FILES_API FilePath ModulesDir();
147
153 FILES_API FilePath PlugInDir();
154
155 // Obtain name of loaded module that contains address
156 FILES_API FilePath PathFromAddr(void *addr);
157
158 FILES_API bool IsPathAvailable( const FilePath & Path);
160 (const wxString &preference);
161
162 // If not None, determines a preference key (for the default path string) to
163 // be read and updated
164 enum class Operation {
165 // _ on None to defeat some macro that is expanding this.
166 _None,
167
168 // These do not have a specific pathtype
169 Temp,
170 Presets,
171
172 // These have default/lastused pathtypes
173 Open,
174 Save,
175 Import,
176 Export,
177 MacrosOut
178 };
179
180 enum class PathType {
181 // _ on None to defeat some macro that is expanding this.
182 _None,
183 User,
184 LastUsed
185 };
186
188
190 FILES_API void UpdateDefaultPath(Operation op, const FilePath &path);
191
192 // F is a function taking a wxString, returning wxString
193 template<typename F>
195 (Operation op, const FilePath &defaultPath, F function)
196 {
197 auto path = gPrefs->Read(PreferenceKey(op, PathType::User), defaultPath);
198 if (path.empty())
200 auto result = function(path);
201 FileNames::UpdateDefaultPath(op, ::wxPathOnly(result));
202 return result;
203 }
204
205 // Useful functions for working with search paths
206 FILES_API void AddUniquePathToPathList(const FilePath &path,
207 FilePaths &pathList);
208 FILES_API void AddMultiPathsToPathList(const wxString &multiPathString,
209 FilePaths &pathList);
210 FILES_API void FindFilesInPathList(const wxString & pattern,
211 const FilePaths & pathList,
212 FilePaths &results,
213 int flags = wxDIR_FILES);
214
215
217 // message is the explanation that is to be displayed to the user if the location is unwritable.
218 FILES_API bool WritableLocationCheck(const FilePath& path,
219 const TranslatableString & message);
220
221 // wxString compare function for sorting case, which is needed to load correctly.
222 FILES_API int CompareNoCase(const wxString& first, const wxString& second);
223
224 // Create a unique filename using the passed prefix and suffix
225 FILES_API wxString CreateUniqueName(const wxString &prefix,
226 const wxString &suffix = wxEmptyString);
227
228 // File extension used for unsaved/temporary project files
229 FILES_API wxString UnsavedProjectExtension();
230
231 FILES_API
232 bool IsOnFATFileSystem(const FilePath &path);
233
234 FILES_API
236 wxString AbbreviatePath(const wxFileName &fileName);
237};
238
239#endif
FileConfig * gPrefs
Definition: Prefs.cpp:71
wxString FilePath
Definition: Project.h:20
Main class to control the export function.
FILES_API const FileType XMLFiles
Definition: FileNames.h:74
std::vector< FileType > FileTypes
Definition: FileNames.h:76
FILES_API const FileType AllFiles
Definition: FileNames.h:71
FILES_API const FileType DynamicLibraries
Definition: FileNames.h:73
FILES_API const FileType TextFiles
Definition: FileNames.h:74
FILES_API const FileType AudacityProjects
Definition: FileNames.h:72
Holds a msgid for the translation catalog; may also bind format arguments.
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:195
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)
filesystem::path Path
STL namespace.
FileType(TranslatableString d, FileExtensions e, bool a=false)
Definition: FileNames.h:55
TranslatableString description
Definition: FileNames.h:61
FileExtensions extensions
Definition: FileNames.h:62