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
16static wxString &TempDirPath()
17{
18 static wxString path;
19 return path;
20}
21
27{
28 auto &path = TempDirPath();
29 if (gPrefs && path.empty())
30 path =
31 gPrefs->Read(PreferenceKey(FileNames::Operation::Temp,
32 FileNames::PathType::_None), wxT(""));
33
35 {
37 XO("Unsuitable"),
38 XO("The temporary files directory is on a FAT formatted drive.\n"
39 "Resetting to default location."),
40 "Error:_Unsuitable_drive"
41 );
42
43 path = DefaultTempDir();
44 UpdateDefaultPath(FileNames::Operation::Temp, path);
45 }
46
47 return FileNames::MkDir(path);
48}
49
51{
52 TempDirPath().clear();
53}
54
57
59{
60 return sDefaultTempDir;
61}
62
64{
65 sDefaultTempDir = tempDir;
66}
67
68// We now disallow temp directory name that puts it where cleaner apps will
69// try to clean out the files.
71{
72 if( Name.empty() )
73 return false;
74
75 wxFileName tmpFile;
76 tmpFile.AssignTempFileName(wxT("nn"));
77 // use Long Path to expand out any abbreviated long substrings.
78 wxString BadPath = tmpFile.GetLongPath();
79 ::wxRemoveFile(tmpFile.GetFullPath());
80
81#ifdef __WXMAC__
82 // This test is to fix bug 1220 on a 1.x to 2.x to 2.1.3 upgrade.
83 // It is less permissive than we could be as it stops a path
84 // with this string ANYWHERE within it rather than excluding just
85 // the paths that the earlier Audacities used to create.
86 if( Name.Contains( "/tmp/") )
87 return false;
88 BadPath = BadPath.BeforeLast( '/' ) + "/";
89 wxFileName cmpFile( Name );
90 wxString NameCanonical = cmpFile.GetLongPath( ) + "/";
91#else
92 BadPath = BadPath.BeforeLast( '\\' ) + "\\";
93 wxFileName cmpFile( Name );
94 wxString NameCanonical = cmpFile.GetLongPath( ) + "\\";
95#endif
96
97 if (FATFilesystemDenied(NameCanonical,
98 XO("The temporary files directory is on a FAT formatted drive.\n"
99 "Resetting to default location.")))
100 {
101 return false;
102 }
103
104 return !(NameCanonical.StartsWith( BadPath ));
105}
106
108{
109 wxFileName fn(TempDir(),
111
112 return fn.GetFullPath();
113}
114
116 const TranslatableString &msg, const BasicUI::WindowPlacement &placement )
117{
119 {
120 BasicUI::ShowErrorDialog( placement,
121 XO("Unsuitable"),
122 XO("%s\n\nFor tips on suitable drives, click the help button.").Format(msg),
123 "Error:_Unsuitable_drive"
124 );
125
126 return true;
127 }
128
129 return false;
130}
Toolkit-neutral facade for basic user interface services.
#define XO(s)
Definition: Internat.h:31
FileConfig * gPrefs
Definition: Prefs.cpp:71
wxString FilePath
Definition: Project.h:20
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:29
Abstract base class used in importing a file.
Holds a msgid for the translation catalog; may also bind format arguments.
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:241
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()
void BadPath(const TranslatableString &format, const wxString &key, const Identifier &name)
Definition: Registry.cpp:166