Audacity  3.0.3
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 
46 class wxFileName;
47 class wxFileNameWrapper;
48 
49 namespace FileNames
50 {
51  // A description of a type of file
52  struct FileType {
53  FileType() = default;
54 
55  FileType( TranslatableString d, FileExtensions e, bool a = false )
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
70  AllFiles // *
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();
118  FILES_API FilePath ResourcesDir();
119  FILES_API FilePath HtmlHelpDir();
120  FILES_API FilePath HtmlHelpIndexFile(bool quick);
122  FILES_API FilePath MacroDir();
123  FILES_API FilePath NRPDir();
124  FILES_API FilePath NRPFile();
127 
128  FILES_API FilePath BaseDir();
129  FILES_API FilePath ModulesDir();
130 
136  FILES_API FilePath PlugInDir();
137  FILES_API FilePath ThemeDir();
139  FILES_API FilePath ThemeCachePng();
141  FILES_API FilePath ThemeComponent(const wxString &Str);
142  FILES_API FilePath ThemeCacheHtm();
144 
145  // Obtain name of loaded module that contains address
146  FILES_API FilePath PathFromAddr(void *addr);
147 
148  FILES_API bool IsPathAvailable( const FilePath & Path);
150  (const wxString &preference);
151 
152  // If not None, determines a preference key (for the default path string) to
153  // be read and updated
154  enum class Operation {
155  // _ on None to defeat some macro that is expanding this.
156  _None,
157 
158  // These do not have a specific pathtype
159  Temp,
160  Presets,
161 
162  // These have default/lastused pathtypes
163  Open,
164  Save,
165  Import,
166  Export,
167  MacrosOut
168  };
169 
170  enum class PathType {
171  // _ on None to defeat some macro that is expanding this.
172  _None,
173  User,
174  LastUsed
175  };
176 
178 
180  FILES_API void UpdateDefaultPath(Operation op, const FilePath &path);
181 
182  // F is a function taking a wxString, returning wxString
183  template<typename F>
185  (Operation op, const FilePath &defaultPath, F function)
186  {
187  auto path = gPrefs->Read(PreferenceKey(op, PathType::User), defaultPath);
188  if (path.empty())
189  path = FileNames::FindDefaultPath(op);
190  auto result = function(path);
191  FileNames::UpdateDefaultPath(op, ::wxPathOnly(result));
192  return result;
193  }
194 
195  // Useful functions for working with search paths
196  FILES_API void AddUniquePathToPathList(const FilePath &path,
197  FilePaths &pathList);
198  FILES_API void AddMultiPathsToPathList(const wxString &multiPathString,
199  FilePaths &pathList);
200  FILES_API void FindFilesInPathList(const wxString & pattern,
201  const FilePaths & pathList,
202  FilePaths &results,
203  int flags = wxDIR_FILES);
204 
205 
207  // message is the explanation that is to be displayed to the user if the location is unwritable.
208  FILES_API bool WritableLocationCheck(const FilePath& path,
209  const TranslatableString & message);
210 
211  // wxString compare function for sorting case, which is needed to load correctly.
212  FILES_API int CompareNoCase(const wxString& first, const wxString& second);
213 
214  // Create a unique filename using the passed prefix and suffix
215  FILES_API wxString CreateUniqueName(const wxString &prefix,
216  const wxString &suffix = wxEmptyString);
217 
218  // File extension used for unsaved/temporary project files
219  FILES_API wxString UnsavedProjectExtension();
220 
221  FILES_API
222  bool IsOnFATFileSystem(const FilePath &path);
223 
224  FILES_API
226  wxString AbbreviatePath(const wxFileName &fileName);
227 };
228 
229 #endif
FileNames::ResourcesDir
FILES_API FilePath ResourcesDir()
FileNames::UnsavedProjectExtension
FILES_API wxString UnsavedProjectExtension()
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
FileNames::MakeNameUnique
FILES_API void MakeNameUnique(FilePaths &otherNames, wxFileName &newName)
FileNames::FileType::description
TranslatableString description
Definition: FileNames.h:61
FileNames::MkDir
FILES_API wxString MkDir(const wxString &Str)
wxFileNameWrapper
Definition: wxFileNameWrapper.h:21
FileNames::FindDefaultPath
FILES_API FilePath FindDefaultPath(Operation op)
FileNames::AbbreviatePath
FILES_API wxString AbbreviatePath(const wxFileName &fileName)
Give enough of the path to identify the device. (On Windows, drive letter plus ':')
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
FileNames::NRPDir
FILES_API FilePath NRPDir()
FileNames::UpdateDefaultPath
FILES_API void UpdateDefaultPath(Operation op, const FilePath &path)
FileNames::FileType::FileType
FileType()=default
FileNames::XMLFiles
FILES_API const FileType XMLFiles
Definition: FileNames.h:74
FileNames::PlugInDir
FILES_API FilePath PlugInDir()
The user plug-in directory (not a system one)
FileNames::ThemeImageDefsAsCee
FILES_API FilePath ThemeImageDefsAsCee()
FileNames::ThemeCachePng
FILES_API FilePath ThemeCachePng()
FileNames::DefaultToDocumentsFolder
FILES_API wxFileNameWrapper DefaultToDocumentsFolder(const wxString &preference)
FileNames::PluginSettings
FILES_API FilePath PluginSettings()
FileNames::HtmlHelpIndexFile
FILES_API FilePath HtmlHelpIndexFile(bool quick)
FileNames::AllFiles
FILES_API const FileType AllFiles
Definition: FileNames.h:71
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
FileNames::PreferenceKey
FILES_API wxString PreferenceKey(FileNames::Operation op, FileNames::PathType type)
FileNames::AudacityProjects
FILES_API const FileType AudacityProjects
Definition: FileNames.h:72
FileNames::AddUniquePathToPathList
FILES_API void AddUniquePathToPathList(const FilePath &path, FilePaths &pathList)
FileNames::LegacyChainDir
FILES_API FilePath LegacyChainDir()
FileNames::WithDefaultPath
FilePath WithDefaultPath(Operation op, const FilePath &defaultPath, F function)
Definition: FileNames.h:185
Export
Main class to control the export function.
FileNames::DataDir
FILES_API FilePath DataDir()
Audacity user data directory.
FileNames::PluginRegistry
FILES_API FilePath PluginRegistry()
FileNames::IsOnFATFileSystem
FILES_API bool IsOnFATFileSystem(const FilePath &path)
FileNames::IsMidi
FILES_API bool IsMidi(const FilePath &fName)
FileNames::PathFromAddr
FILES_API FilePath PathFromAddr(void *addr)
FilePath
wxString FilePath
Definition: Project.h:20
FileNames::SetAudacityPathList
FILES_API void SetAudacityPathList(FilePaths list)
FileNames::TextFiles
FILES_API const FileType TextFiles
Definition: FileNames.h:74
FileNames
Definition: SelectFile.h:19
FileNames::CreateUniqueName
FILES_API wxString CreateUniqueName(const wxString &prefix, const wxString &suffix=wxEmptyString)
Identifier.h
FileNames::FileType::appendExtensions
bool appendExtensions
Definition: FileNames.h:65
FileNames::ModulesDir
FILES_API FilePath ModulesDir()
FileNames::ThemeComponentsDir
FILES_API FilePath ThemeComponentsDir()
FileNames::FindFilesInPathList
FILES_API void FindFilesInPathList(const wxString &pattern, const FilePaths &pathList, FilePaths &results, int flags=wxDIR_FILES)
FileNames::IsPathAvailable
FILES_API bool IsPathAvailable(const FilePath &Path)
FileNames::ThemeCacheAsCee
FILES_API FilePath ThemeCacheAsCee()
FileNames::PathType
PathType
Definition: FileNames.h:170
FileNames::NRPFile
FILES_API FilePath NRPFile()
FileNames::AddMultiPathsToPathList
FILES_API void AddMultiPathsToPathList(const wxString &multiPathString, FilePaths &pathList)
FileNames::BaseDir
FILES_API FilePath BaseDir()
FileNames::LowerCaseAppNameInPath
FILES_API wxString LowerCaseAppNameInPath(const wxString &dirIn)
FileNames::WritableLocationCheck
FILES_API bool WritableLocationCheck(const FilePath &path, const TranslatableString &message)
Check location on writable access and return true if checked successfully.
FileNames::AudacityPathList
FILES_API const FilePaths & AudacityPathList()
A list of directories that should be searched for Audacity files (plug-ins, help files,...
FileNames::DynamicLibraries
FILES_API const FileType DynamicLibraries
Definition: FileNames.h:73
FileNames::ThemeDir
FILES_API FilePath ThemeDir()
FileNames::HtmlHelpDir
FILES_API FilePath HtmlHelpDir()
FileNames::MacroDir
FILES_API FilePath MacroDir()
FileNames::CompareNoCase
FILES_API int CompareNoCase(const wxString &first, const wxString &second)
FileNames::ThemeComponent
FILES_API FilePath ThemeComponent(const wxString &Str)
FileNames::DoCopyFile
FILES_API bool DoCopyFile(const FilePath &file1, const FilePath &file2, bool overwrite=true)
FileNames::FileTypes
std::vector< FileType > FileTypes
Definition: FileNames.h:76
Prefs.h
FileNames::FileType::extensions
FileExtensions extensions
Definition: FileNames.h:62
FileNames::FileType::FileType
FileType(TranslatableString d, FileExtensions e, bool a=false)
Definition: FileNames.h:55
FileNames::ThemeCacheHtm
FILES_API FilePath ThemeCacheHtm()
FileNames::FormatWildcard
FILES_API wxString FormatWildcard(const FileTypes &fileTypes)
FileNames::HardLinkFile
FILES_API bool HardLinkFile(const FilePath &file1, const FilePath &file2)
FileNames::FileType
Definition: FileNames.h:52
Journal::WindowPaths::Path
Identifier Path
Definition: JournalWindowPaths.h:24
FileNames::Operation
Operation
Definition: FileNames.h:154