mirror of
https://github.com/cookiengineer/audacity
synced 2026-03-31 19:44:54 +02:00
Use XDG dirs by default on Linux
Signed-off-by: Campbell Jones <git@serebit.com>
This commit is contained in:
committed by
Sol Fisher Romanoff
parent
74f5f2ef98
commit
c0c275ffaf
@@ -47,6 +47,11 @@ used throughout Audacity into this one place.
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(__WXGTK__)
|
||||
static wxString gOldUnixDataDir;
|
||||
#endif
|
||||
|
||||
static wxString gConfigDir;
|
||||
static wxString gDataDir;
|
||||
|
||||
const FileNames::FileType
|
||||
@@ -176,7 +181,7 @@ bool FileNames::HardLinkFile( const FilePath& file1, const FilePath& file2 )
|
||||
#ifdef __WXMSW__
|
||||
|
||||
// Fix forced ASCII conversions and wrong argument order - MJB - 29/01/2019
|
||||
//return ::CreateHardLinkA( file1.c_str(), file2.c_str(), NULL );
|
||||
//return ::CreateHardLinkA( file1.c_str(), file2.c_str(), NULL );
|
||||
return ( 0 != ::CreateHardLink( file2, file1, NULL ) );
|
||||
|
||||
#else
|
||||
@@ -226,8 +231,49 @@ wxString FileNames::LowerCaseAppNameInPath( const wxString & dirIn){
|
||||
return dir;
|
||||
}
|
||||
|
||||
FilePath FileNames::ConfigDir()
|
||||
{
|
||||
#if defined(__WXGTK__)
|
||||
if (gOldUnixDataDir.empty())
|
||||
gOldUnixDataDir = wxFileName::GetHomeDir() + wxT("/.audacity-data");
|
||||
#endif
|
||||
|
||||
if (gConfigDir.empty())
|
||||
{
|
||||
wxFileName exePath(PlatformCompatibility::GetExecutablePath());
|
||||
#if defined(__WXMAC__)
|
||||
// Path ends for example in "Audacity.app/Contents/MacOSX"
|
||||
// just remove the MacOSX part.
|
||||
exePath.RemoveLastDir();
|
||||
#endif
|
||||
wxFileName portablePrefsPath(exePath.GetPath(), wxT("Portable Settings"));
|
||||
if (::wxDirExists(portablePrefsPath.GetFullPath()))
|
||||
{
|
||||
// Use "Portable Settings" folder
|
||||
gConfigDir = portablePrefsPath.GetFullPath();
|
||||
#if defined(__WXGTK__)
|
||||
} else if (::wxDirExists(gOldUnixDataDir))
|
||||
{
|
||||
// Use old user data dir folder
|
||||
gConfigDir = gOldUnixDataDir;
|
||||
#endif
|
||||
} else {
|
||||
// Use OS-provided user data dir folder
|
||||
wxString configDir(wxStandardPaths::Get().GetUserConfigDir() + wxT("/audacity"));
|
||||
gConfigDir = FileNames::MkDir(configDir);
|
||||
}
|
||||
}
|
||||
|
||||
return gConfigDir;
|
||||
}
|
||||
|
||||
|
||||
FilePath FileNames::DataDir()
|
||||
{
|
||||
#if defined(__WXGTK__)
|
||||
if (gOldUnixDataDir.empty())
|
||||
gOldUnixDataDir = wxFileName::GetHomeDir() + wxT("/.audacity-data");
|
||||
#endif
|
||||
// LLL: Wouldn't you know that as of WX 2.6.2, there is a conflict
|
||||
// between wxStandardPaths and wxConfig under Linux. The latter
|
||||
// creates a normal file as "$HOME/.audacity", while the former
|
||||
@@ -251,12 +297,25 @@ FilePath FileNames::DataDir()
|
||||
{
|
||||
// Use "Portable Settings" folder
|
||||
gDataDir = portablePrefsPath.GetFullPath();
|
||||
#if defined(__WXGTK__)
|
||||
} else if (::wxDirExists(gOldUnixDataDir))
|
||||
{
|
||||
// Use old user data dir folder
|
||||
gDataDir = gOldUnixDataDir;
|
||||
} else
|
||||
{
|
||||
wxString dataDir;
|
||||
// see if XDG_DATA_HOME is defined. if it is, use its value. if it isn't, use the default
|
||||
// XDG-specified value
|
||||
if ( !wxGetEnv(wxS("XDG_DATA_HOME"), &dataDir) || dataDir.empty() )
|
||||
dataDir = wxFileName::GetHomeDir() + wxT("/.local/share");
|
||||
|
||||
dataDir = dataDir + wxT("/audacity");
|
||||
#else
|
||||
} else
|
||||
{
|
||||
// Use OS-provided user data dir folder
|
||||
wxString dataDir( LowerCaseAppNameInPath( wxStandardPaths::Get().GetUserDataDir() ));
|
||||
#if defined( __WXGTK__ )
|
||||
dataDir = dataDir + wxT("-data");
|
||||
#endif
|
||||
gDataDir = FileNames::MkDir(dataDir);
|
||||
}
|
||||
@@ -317,12 +376,12 @@ FilePath FileNames::PlugInDir()
|
||||
|
||||
FilePath FileNames::PluginRegistry()
|
||||
{
|
||||
return wxFileName( DataDir(), wxT("pluginregistry.cfg") ).GetFullPath();
|
||||
return wxFileName( ConfigDir(), wxT("pluginregistry.cfg") ).GetFullPath();
|
||||
}
|
||||
|
||||
FilePath FileNames::PluginSettings()
|
||||
{
|
||||
return wxFileName( DataDir(), wxT("pluginsettings.cfg") ).GetFullPath();
|
||||
return wxFileName( ConfigDir(), wxT("pluginsettings.cfg") ).GetFullPath();
|
||||
}
|
||||
|
||||
FilePath FileNames::BaseDir()
|
||||
@@ -472,7 +531,7 @@ wxFileNameWrapper FileNames::DefaultToDocumentsFolder(const wxString &preference
|
||||
|
||||
// MJB: Bug 1899 & Bug 2007. Only create directory if the result is the default path
|
||||
bool bIsDefaultPath = result == defaultPath;
|
||||
if( !bIsDefaultPath )
|
||||
if( !bIsDefaultPath )
|
||||
{
|
||||
// IF the prefs directory doesn't exist - (Deleted by our user perhaps?)
|
||||
// or exists as a file
|
||||
|
||||
Reference in New Issue
Block a user