Refactor: extract GetXDGConfigHome() into a separate function
No real changes, just avoid doing the same thing in 2 different places and do it in a single helper function instead.
This commit is contained in:
@@ -50,6 +50,16 @@ void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
|
|||||||
m_prefix = prefix;
|
m_prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function returning the value of XDG_CONFIG_HOME environment variable
|
||||||
|
// or its default value if it is not defined.
|
||||||
|
static wxString GetXDGConfigHome()
|
||||||
|
{
|
||||||
|
wxString dir;
|
||||||
|
if ( !wxGetEnv(wxS("XDG_CONFIG_HOME"), &dir) || dir.empty() )
|
||||||
|
dir = wxFileName::GetHomeDir() + wxS("/.config");
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
wxString wxStandardPaths::GetUserConfigDir() const
|
wxString wxStandardPaths::GetUserConfigDir() const
|
||||||
{
|
{
|
||||||
wxString dir;
|
wxString dir;
|
||||||
@@ -61,8 +71,7 @@ wxString wxStandardPaths::GetUserConfigDir() const
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case FileLayout_XDG:
|
case FileLayout_XDG:
|
||||||
if ( !wxGetEnv(wxS("XDG_CONFIG_HOME"), &dir) || dir.empty() )
|
dir = GetXDGConfigHome();
|
||||||
dir = wxFileName::GetHomeDir() + wxS("/.config");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,12 +277,7 @@ wxString wxStandardPaths::GetUserDir(Dir userDir) const
|
|||||||
return homeDir + wxT("/.cache");
|
return homeDir + wxT("/.cache");
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString configPath;
|
wxString dirsFile = GetXDGConfigHome() + wxT("/user-dirs.dirs");
|
||||||
if (wxGetenv(wxT("XDG_CONFIG_HOME")))
|
|
||||||
configPath = wxGetenv(wxT("XDG_CONFIG_HOME"));
|
|
||||||
else
|
|
||||||
configPath = homeDir + wxT("/.config");
|
|
||||||
wxString dirsFile = configPath + wxT("/user-dirs.dirs");
|
|
||||||
if (wxFileExists(dirsFile))
|
if (wxFileExists(dirsFile))
|
||||||
{
|
{
|
||||||
wxString userDirId;
|
wxString userDirId;
|
||||||
|
Reference in New Issue
Block a user