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);
117 FILES_API FilePath DataDir();
120 FILES_API FilePath HtmlHelpIndexFile(bool quick);
122 FILES_API FilePath MacroDir();
123 FILES_API FilePath NRPDir();
124 FILES_API FilePath NRPFile();
128
129 FILES_API FilePath BaseDir();
130 FILES_API FilePath ModulesDir();
131
137 FILES_API FilePath PlugInDir();
138
139 // Obtain name of loaded module that contains address
140 FILES_API FilePath PathFromAddr(void *addr);
141
142 FILES_API bool IsPathAvailable( const FilePath & Path);
144 (const wxString &preference);
145
146 // If not None, determines a preference key (for the default path string) to
147 // be read and updated
148 enum class Operation {
149 // _ on None to defeat some macro that is expanding this.
150 _None,
151
152 // These do not have a specific pathtype
153 Temp,
154 Presets,
155
156 // These have default/lastused pathtypes
157 Open,
158 Save,
159 Import,
160 Export,
161 MacrosOut
162 };
163
164 enum class PathType {
165 // _ on None to defeat some macro that is expanding this.
166 _None,
167 User,
168 LastUsed
169 };
170
172
174 FILES_API void UpdateDefaultPath(Operation op, const FilePath &path);
175
176 // F is a function taking a wxString, returning wxString
177 template<typename F>
179 (Operation op, const FilePath &defaultPath, F function)
180 {
181 auto path = gPrefs->Read(PreferenceKey(op, PathType::User), defaultPath);
182 if (path.empty())
184 auto result = function(path);
185 FileNames::UpdateDefaultPath(op, ::wxPathOnly(result));
186 return result;
187 }
188
189 // Useful functions for working with search paths
190 FILES_API void AddUniquePathToPathList(const FilePath &path,
191 FilePaths &pathList);
192 FILES_API void AddMultiPathsToPathList(const wxString &multiPathString,
193 FilePaths &pathList);
194 FILES_API void FindFilesInPathList(const wxString & pattern,
195 const FilePaths & pathList,
196 FilePaths &results,
197 int flags = wxDIR_FILES);
198
199
201 // message is the explanation that is to be displayed to the user if the location is unwritable.
202 FILES_API bool WritableLocationCheck(const FilePath& path,
203 const TranslatableString & message);
204
205 // wxString compare function for sorting case, which is needed to load correctly.
206 FILES_API int CompareNoCase(const wxString& first, const wxString& second);
207
208 // Create a unique filename using the passed prefix and suffix
209 FILES_API wxString CreateUniqueName(const wxString &prefix,
210 const wxString &suffix = wxEmptyString);
211
212 // File extension used for unsaved/temporary project files
213 FILES_API wxString UnsavedProjectExtension();
214
215 FILES_API
216 bool IsOnFATFileSystem(const FilePath &path);
217
218 FILES_API
220 wxString AbbreviatePath(const wxFileName &fileName);
221};
222
223#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 HtmlHelpIndexFile(bool quick)
FILES_API wxString PreferenceKey(FileNames::Operation op, FileNames::PathType type)
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 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:179
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