forked from tenacityteam/tenacity-legacy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFileNames.h
260 lines (212 loc) · 8.98 KB
/
FileNames.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/**********************************************************************
Audacity: A Digital Audio Editor
FileNames.h
James Crook
**********************************************************************/
#ifndef __AUDACITY_FILE_NAMES__
#define __AUDACITY_FILE_NAMES__
#include <wx/dir.h> // for wxDIR_FILES
#include <wx/string.h> // function return value
#include "Identifier.h"
#include "Prefs.h"
#include <memory>
// Please try to support unlimited path length instead of using PLATFORM_MAX_PATH!
// Define one constant for maximum path value, so we don't have to do
// platform-specific conditionals everywhere we want to check it.
#define PLATFORM_MAX_PATH 260 // Play it safe for default, with same value as Windows' MAX_PATH.
#ifdef __WXMAC__
#undef PLATFORM_MAX_PATH
#define PLATFORM_MAX_PATH PATH_MAX
#endif
#ifdef __WXGTK__
// Some systems do not restrict the path length and therefore PATH_MAX is undefined
#ifdef PATH_MAX
#undef PLATFORM_MAX_PATH
#define PLATFORM_MAX_PATH PATH_MAX
#endif
#endif
#ifdef __WXX11__
// wxX11 should also get the platform-specific definition of PLATFORM_MAX_PATH, so do not declare here.
#endif
#ifdef __WXMSW__
#undef PLATFORM_MAX_PATH
#define PLATFORM_MAX_PATH MAX_PATH
#endif
class wxFileName;
class wxFileNameWrapper;
namespace FileNames
{
// A description of a type of file
struct FileType {
FileType() = default;
FileType( TranslatableString d, FileExtensions e, bool a = false )
: description{ std::move( d ) }
, extensions( std::move( e ) )
, appendExtensions{ a }
{}
TranslatableString description;
FileExtensions extensions;
// Whether to extend the displayed description with mention of the
// extensions:
bool appendExtensions = false;
};
// Frequently used types
extern AUDACITY_DLL_API const FileType
AllFiles // *
, AudacityProjects // *.aup3
, DynamicLibraries // depends on the operating system
, TextFiles // *.txt
, XMLFiles; // *.xml, *.XML
using FileTypes = std::vector< FileType >;
// Convert fileTypes into a single string as expected by wxWidgets file
// selection dialog
AUDACITY_DLL_API wxString FormatWildcard( const FileTypes &fileTypes );
// This exists to compensate for bugs in wxCopyFile:
AUDACITY_DLL_API bool DoCopyFile(
const FilePath& file1, const FilePath& file2, bool overwrite = true);
// wxWidgets doesn't have a function to do this: make a hard file-system
// link if possible. It might not be, as when the paths are on different
// storage devices.
AUDACITY_DLL_API
bool HardLinkFile( const FilePath& file1, const FilePath& file2);
AUDACITY_DLL_API wxString MkDir(const wxString &Str);
AUDACITY_DLL_API bool IsMidi(const FilePath &fName);
/** \brief A list of directories that should be searched for Audacity files
* (plug-ins, help files, etc.).
*
* On Unix this will include the directory Audacity was installed into,
* plus the current user's .audacity-data/Plug-Ins directory. Additional
* directories can be specified using the AUDACITY_PATH environment
* variable. On Windows or Mac OS, this will include the directory
* which contains the Audacity program. */
AUDACITY_DLL_API const FilePaths &AudacityPathList();
AUDACITY_DLL_API void SetAudacityPathList( FilePaths list );
// originally an ExportMultipleDialog method. Append suffix if newName appears in otherNames.
AUDACITY_DLL_API void MakeNameUnique(
FilePaths &otherNames, wxFileName &newName);
AUDACITY_DLL_API wxString LowerCaseAppNameInPath( const wxString & dirIn);
/** \brief Audacity user data directory
*
* Where audacity keeps its settings and other user data squirreled away,
* by default ~/.audacity-data/ on Unix, Application Data/Audacity on
* windows system */
AUDACITY_DLL_API FilePath DataDir();
AUDACITY_DLL_API FilePath ResourcesDir();
AUDACITY_DLL_API FilePath HtmlHelpDir();
AUDACITY_DLL_API FilePath HtmlHelpIndexFile(bool quick);
AUDACITY_DLL_API FilePath LegacyChainDir();
AUDACITY_DLL_API FilePath MacroDir();
AUDACITY_DLL_API FilePath NRPDir();
AUDACITY_DLL_API FilePath NRPFile();
AUDACITY_DLL_API FilePath PluginRegistry();
AUDACITY_DLL_API FilePath PluginSettings();
AUDACITY_DLL_API FilePath BaseDir();
AUDACITY_DLL_API FilePath ModulesDir();
/** \brief The user plug-in directory (not a system one)
*
* This returns the string path to where the user may have put plug-ins
* if they don't have system admin rights. Under default settings, it's
* <DataDir>/Plug-Ins/ */
AUDACITY_DLL_API FilePath PlugInDir();
AUDACITY_DLL_API FilePath ThemeDir();
AUDACITY_DLL_API FilePath ThemeComponentsDir();
AUDACITY_DLL_API FilePath ThemeCachePng();
AUDACITY_DLL_API FilePath ThemeCacheAsCee();
AUDACITY_DLL_API FilePath ThemeComponent(const wxString &Str);
AUDACITY_DLL_API FilePath ThemeCacheHtm();
AUDACITY_DLL_API FilePath ThemeImageDefsAsCee();
// Obtain name of loaded module that contains address
AUDACITY_DLL_API FilePath PathFromAddr(void *addr);
AUDACITY_DLL_API bool IsPathAvailable( const FilePath & Path);
AUDACITY_DLL_API wxFileNameWrapper DefaultToDocumentsFolder
(const wxString &preference);
// If not None, determines a preference key (for the default path string) to
// be read and updated
enum class Operation {
// _ on None to defeat some macro that is expanding this.
_None,
// These do not have a specific pathtype
Temp,
Presets,
// These have default/lastused pathtypes
Open,
Save,
Import,
Export,
MacrosOut
};
enum class PathType {
// _ on None to defeat some macro that is expanding this.
_None,
User,
LastUsed
};
AUDACITY_DLL_API wxString PreferenceKey(FileNames::Operation op, FileNames::PathType type);
AUDACITY_DLL_API FilePath FindDefaultPath(Operation op);
AUDACITY_DLL_API void UpdateDefaultPath(Operation op, const FilePath &path);
// F is a function taking a wxString, returning wxString
template<typename F>
FilePath WithDefaultPath
(Operation op, const FilePath &defaultPath, F function)
{
auto path = gPrefs->Read(PreferenceKey(op, PathType::User), defaultPath);
if (path.empty())
path = FileNames::FindDefaultPath(op);
auto result = function(path);
FileNames::UpdateDefaultPath(op, ::wxPathOnly(result));
return result;
}
AUDACITY_DLL_API FilePath
SelectFile(Operation op, // op matters only when default_path is empty
const TranslatableString& message,
const FilePath& default_path,
const FilePath& default_filename,
const FileExtension& default_extension,
const FileTypes& fileTypes,
int flags,
wxWindow *parent);
// Useful functions for working with search paths
AUDACITY_DLL_API void AddUniquePathToPathList(const FilePath &path,
FilePaths &pathList);
AUDACITY_DLL_API void AddMultiPathsToPathList(const wxString &multiPathString,
FilePaths &pathList);
AUDACITY_DLL_API void FindFilesInPathList(const wxString & pattern,
const FilePaths & pathList,
FilePaths &results,
int flags = wxDIR_FILES);
/** \brief Protect against Unicode to multi-byte conversion failures
* on Windows */
#if defined(__WXMSW__)
AUDACITY_DLL_API char *VerifyFilename(const wxString &s, bool input = true);
#endif
// wxString compare function for sorting case, which is needed to load correctly.
AUDACITY_DLL_API int CompareNoCase(const wxString& first, const wxString& second);
// Create a unique filename using the passed prefix and suffix
AUDACITY_DLL_API wxString CreateUniqueName(const wxString &prefix,
const wxString &suffix = wxEmptyString);
// File extension used for unsaved/temporary project files
AUDACITY_DLL_API wxString UnsavedProjectExtension();
AUDACITY_DLL_API
bool IsOnFATFileSystem(const FilePath &path);
AUDACITY_DLL_API
//! Give enough of the path to identify the device. (On Windows, drive letter plus ':')
wxString AbbreviatePath(const wxFileName &fileName);
};
// Use this macro to wrap all filenames and pathnames that get
// passed directly to a system call, like opening a file, creating
// a directory, checking to see that a file exists, etc...
#if defined(__WXMSW__)
// Note, on Windows we don't define an OSFILENAME() to prevent accidental use.
// See VerifyFilename() for an explanation.
#define OSINPUT(X) FileNames::VerifyFilename(X, true)
#define OSOUTPUT(X) FileNames::VerifyFilename(X, false)
#elif defined(__WXMAC__)
#define OSFILENAME(X) ((char *) (const char *)(X).fn_str())
#define OSINPUT(X) OSFILENAME(X)
#define OSOUTPUT(X) OSFILENAME(X)
#else
#define OSFILENAME(X) ((char *) (const char *)(X).mb_str())
#define OSINPUT(X) OSFILENAME(X)
#define OSOUTPUT(X) OSFILENAME(X)
#endif
#endif