Audacity  3.0.3
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 static 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 }
FileNames::UnsavedProjectExtension
FILES_API wxString UnsavedProjectExtension()
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
TempDirectory::DefaultTempDir
FILES_API const FilePath & DefaultTempDir()
Definition: TempDirectory.cpp:58
FileNames::MkDir
FILES_API wxString MkDir(const wxString &Str)
fn
static const auto fn
Definition: WaveformView.cpp:1113
sDefaultTempDir
static FilePath sDefaultTempDir
Default temp directory.
Definition: TempDirectory.cpp:56
TempDirectory::ResetTempDir
FILES_API void ResetTempDir()
Definition: TempDirectory.cpp:50
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
BasicUI::ShowErrorDialog
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:233
FileNames::UpdateDefaultPath
FILES_API void UpdateDefaultPath(Operation op, const FilePath &path)
Format
Abstract base class used in importing a file.
XO
#define XO(s)
Definition: Internat.h:31
FileNames::PreferenceKey
FILES_API wxString PreferenceKey(FileNames::Operation op, FileNames::PathType type)
FileNames::IsOnFATFileSystem
FILES_API bool IsOnFATFileSystem(const FilePath &path)
FilePath
wxString FilePath
Definition: Project.h:20
BasicUI::WindowPlacement
Subclasses may hold information such as a parent window pointer for a dialog.
Definition: BasicUI.h:29
FileNames::CreateUniqueName
FILES_API wxString CreateUniqueName(const wxString &prefix, const wxString &suffix=wxEmptyString)
TempDirectory.h
TempDirectory::IsTempDirectoryNameOK
FILES_API bool IsTempDirectoryNameOK(const FilePath &Name)
Definition: TempDirectory.cpp:70
BasicUI.h
Toolkit-neutral facade for basic user interface services.
TempDirectory::SetDefaultTempDir
FILES_API void SetDefaultTempDir(const FilePath &tempDir)
Definition: TempDirectory.cpp:63
TempDirectory::UnsavedProjectFileName
FILES_API wxString UnsavedProjectFileName()
Definition: TempDirectory.cpp:107
FileNames.h
TempDirectory::FATFilesystemDenied
FILES_API bool FATFilesystemDenied(const FilePath &path, const TranslatableString &msg, const BasicUI::WindowPlacement &placement={})
Definition: TempDirectory.cpp:115
TempDirPath
static wxString & TempDirPath()
Definition: TempDirectory.cpp:16
anonymous_namespace{Registry.cpp}::BadPath
void BadPath(const TranslatableString &format, const wxString &key, const Identifier &name)
Definition: Registry.cpp:166
TempDirectory::TempDir
FILES_API wxString TempDir()
Definition: TempDirectory.cpp:26