Audacity 3.2.0
TempDirectory.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 TempDirectory.cpp
6
7 Paul Licameli split from FileNames.cpp
8
9 **********************************************************************/
10
11#include "TempDirectory.h"
12
13#include "FileNames.h"
14#include "BasicUI.h"
15
16
17namespace
18{
20{
21 void UpdateTempPath(const FilePath& path)
22 {
23 if (prevPath != path)
24 {
25 Publish(path);
26 prevPath = path;
27 }
28 }
29
31};
32
34{
35 static TempDirChangedPublisher publisher;
36 return publisher;
37}
38}
39
40static wxString &TempDirPath()
41{
42 static wxString path;
43 return path;
44}
45
51{
52 auto &path = TempDirPath();
53 if (gPrefs && path.empty())
54 path =
55 gPrefs->Read(PreferenceKey(FileNames::Operation::Temp,
56 FileNames::PathType::_None), wxT(""));
57
59 {
61 XO("Unsuitable"),
62 XO("The temporary files directory is on a FAT formatted drive.\n"
63 "Resetting to default location."),
64 "Error:_Unsuitable_drive"
65 );
66
67 path = DefaultTempDir();
68 UpdateDefaultPath(FileNames::Operation::Temp, path);
69 }
70
71 return FileNames::MkDir(path);
72}
73
75{
76 TempDirPath().clear();
77}
78
81
83{
84 return sDefaultTempDir;
85}
86
88{
89 sDefaultTempDir = tempDir;
91}
92
93// We now disallow temp directory name that puts it where cleaner apps will
94// try to clean out the files.
96{
97 if( Name.empty() )
98 return false;
99
100 wxFileName tmpFile;
101 tmpFile.AssignTempFileName(wxT("nn"));
102 // use Long Path to expand out any abbreviated long substrings.
103 wxString BadPath = tmpFile.GetLongPath();
104 ::wxRemoveFile(tmpFile.GetFullPath());
105
106#ifdef __WXMAC__
107 // This test is to fix bug 1220 on a 1.x to 2.x to 2.1.3 upgrade.
108 // It is less permissive than we could be as it stops a path
109 // with this string ANYWHERE within it rather than excluding just
110 // the paths that the earlier Audacities used to create.
111 if( Name.Contains( "/tmp/") )
112 return false;
113 BadPath = BadPath.BeforeLast( '/' ) + "/";
114 wxFileName cmpFile( Name );
115 wxString NameCanonical = cmpFile.GetLongPath( ) + "/";
116#else
117 BadPath = BadPath.BeforeLast( '\\' ) + "\\";
118 wxFileName cmpFile( Name );
119 wxString NameCanonical = cmpFile.GetLongPath( ) + "\\";
120#endif
121
122 if (FATFilesystemDenied(NameCanonical,
123 XO("The temporary files directory is on a FAT formatted drive.\n"
124 "Resetting to default location.")))
125 {
126 return false;
127 }
128
129 return !(NameCanonical.StartsWith( BadPath ));
130}
131
133{
134 wxFileName fn(TempDir(),
136
137 return fn.GetFullPath();
138}
139
141 const TranslatableString &msg, const BasicUI::WindowPlacement &placement )
142{
144 {
145 BasicUI::ShowErrorDialog( placement,
146 XO("Unsuitable"),
147 XO("%s\n\nFor tips on suitable drives, click the help button.").Format(msg),
148 "Error:_Unsuitable_drive"
149 );
150
151 return true;
152 }
153
154 return false;
155}
156
158{
160}
wxT("CloseDown"))
Toolkit-neutral facade for basic user interface services.
XO("Cut/Copy/Paste")
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
wxString FilePath
Definition: Project.h:21
static wxString & TempDirPath()
static FilePath sDefaultTempDir
Default temp directory.
static const auto fn
Subclasses may hold information such as a parent window pointer for a dialog.
Definition: BasicUI.h:30
Abstract base class used in importing a file.
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
Holds a msgid for the translation catalog; may also bind format arguments.
virtual bool Read(const wxString &key, bool *value) const =0
void ShowErrorDialog(const WindowPlacement &placement, const TranslatableString &dlogTitle, const TranslatableString &message, const ManualPageID &helpPage, const ErrorDialogOptions &options={})
Show an error dialog with a link to the manual for further help.
Definition: BasicUI.h:272
FILES_API bool IsOnFATFileSystem(const FilePath &path)
FILES_API wxString CreateUniqueName(const wxString &prefix, const wxString &suffix=wxEmptyString)
FILES_API wxString MkDir(const wxString &Str)
FILES_API wxString UnsavedProjectExtension()
FILES_API wxString PreferenceKey(FileNames::Operation op, FileNames::PathType type)
FILES_API void UpdateDefaultPath(Operation op, const FilePath &path)
FILES_API bool FATFilesystemDenied(const FilePath &path, const TranslatableString &msg, const BasicUI::WindowPlacement &placement={})
FILES_API wxString UnsavedProjectFileName()
FILES_API bool IsTempDirectoryNameOK(const FilePath &Name)
FILES_API wxString TempDir()
FILES_API void ResetTempDir()
FILES_API void SetDefaultTempDir(const FilePath &tempDir)
FILES_API const FilePath & DefaultTempDir()
FILES_API Observer::Publisher< FilePath > & GetTempPathObserver()
void BadPath(const TranslatableString &format, const wxString &key, const Identifier &name)
Definition: Registry.cpp:175
TempDirChangedPublisher & GetTempDirChangedPublisher()