Audacity 3.2.0
Classes | Enumerations | Functions | Variables
anonymous_namespace{FileNames.cpp} Namespace Reference

Classes

struct  XDGDirConfig
 

Enumerations

enum class  DirTarget {
  Cache , Config , Data , State ,
  _targetCount
}
 

Functions

FilePath GetXDGTargetDir (DirTarget target)
 
FilePath GetUserTargetDir (DirTarget target, bool allowRoaming)
 

Variables

static FilePath gTargetDirs [size_t(DirTarget::_targetCount)] = {}
 
const XDGDirConfig gXDGUnixDirs []
 

Enumeration Type Documentation

◆ DirTarget

enum class anonymous_namespace{FileNames.cpp}::DirTarget
strong

Function Documentation

◆ GetUserTargetDir()

FilePath anonymous_namespace{FileNames.cpp}::GetUserTargetDir ( DirTarget  target,
bool  allowRoaming 
)

Definition at line 282 of file FileNames.cpp.

283{
284 auto& dir = gTargetDirs[size_t(target)];
285 if (dir.empty())
286 {
287 // If there is a directory "Portable Settings" relative to the
288 // executable's EXE file, the prefs are stored in there, otherwise
289 // the prefs are stored in the user data dir provided by the OS.
290 wxFileName exePath(PlatformCompatibility::GetExecutablePath());
291#if defined(__WXMAC__)
292 // Path ends for example in "Audacity.app/Contents/MacOSX"
293 //exePath.RemoveLastDir();
294 //exePath.RemoveLastDir();
295 // just remove the MacOSX part.
296 exePath.RemoveLastDir();
297#endif
298 wxFileName portablePrefsPath(exePath.GetPath(), wxT("Portable Settings"));
299
300 if (::wxDirExists(portablePrefsPath.GetFullPath()))
301 {
302 // Use "Portable Settings" folder
303 dir = portablePrefsPath.GetFullPath();
304 } else
305 {
306#if defined(__WXGTK__)
307 // Use XDG Base Directory compliant folders
308 wxString newDir(GetXDGTargetDir(target));
309#else
310 // Use OS-provided user data dir folder
311 wxString newDir(FileNames::LowerCaseAppNameInPath(
314#endif
315 dir = FileNames::MkDir(newDir);
316 }
317 }
318 return dir;
319}
wxT("CloseDown"))
FILES_API wxString LowerCaseAppNameInPath(const wxString &dirIn)
FILES_API wxString MkDir(const wxString &Str)
std::string FILES_API GetUserDataDir()
std::string FILES_API GetExecutablePath()
std::string FILES_API GetUserLocalDataDir()
static FilePath gTargetDirs[size_t(DirTarget::_targetCount)]
Definition: FileNames.cpp:236
FilePath GetXDGTargetDir(DirTarget target)
Definition: FileNames.cpp:257

References PlatformCompatibility::GetExecutablePath(), PlatformCompatibility::GetUserDataDir(), PlatformCompatibility::GetUserLocalDataDir(), GetXDGTargetDir(), gTargetDirs, FileNames::LowerCaseAppNameInPath(), FileNames::MkDir(), and wxT().

Here is the call graph for this function:

◆ GetXDGTargetDir()

FilePath anonymous_namespace{FileNames.cpp}::GetXDGTargetDir ( DirTarget  target)

Definition at line 257 of file FileNames.cpp.

258{
259 static const auto oldUnixDataDir = wxFileName::GetHomeDir() + wxT("/.audacity-data");
260 static const auto oldUnixDataDirExists = wxDirExists(oldUnixDataDir);
261 // Compatibility: Use old user data dir folder, if it already exists
262 if (oldUnixDataDirExists)
263 return oldUnixDataDir;
264
265 // see if the XDG_*_HOME env var is defined. if it is, use its value.
266 // if it isn't, use the default XDG-specified value.
267 wxString newDir;
268 const auto [dirEnvVar, dirDefault] = gXDGUnixDirs[size_t(target)];
269 if (!wxGetEnv(dirEnvVar, &newDir) || newDir.empty())
270 newDir = wxFileName::GetHomeDir() + dirDefault;
271
272#ifdef AUDACITY_NAME
273 newDir = newDir + wxT("/" AUDACITY_NAME);
274#else
275 newDir = newDir + wxT("/audacity");
276#endif
277
278 return newDir;
279}
std::string FILES_API GetHomeDir()
const XDGDirConfig gXDGUnixDirs[]
Definition: FileNames.cpp:245

References PlatformCompatibility::GetHomeDir(), gXDGUnixDirs, and wxT().

Referenced by GetUserTargetDir().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ gTargetDirs

FilePath anonymous_namespace{FileNames.cpp}::gTargetDirs[size_t(DirTarget::_targetCount)] = {}
static

Definition at line 236 of file FileNames.cpp.

Referenced by GetUserTargetDir().

◆ gXDGUnixDirs

const XDGDirConfig anonymous_namespace{FileNames.cpp}::gXDGUnixDirs[]
Initial value:
= {
{wxT("XDG_CACHE_HOME"), wxT("/.cache") },
{wxT("XDG_CONFIG_HOME"), wxT("/.config") },
{wxT("XDG_DATA_HOME"), wxT("/.local/share")},
{wxT("XDG_STATE_HOME"), wxT("/.local/state")}
}

Definition at line 245 of file FileNames.cpp.

Referenced by GetXDGTargetDir().