From 41fe019f3bf5edced73747c173103daead2cf7c8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 9 Mar 2017 18:00:29 +0100 Subject: [PATCH] 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. --- src/unix/stdpaths.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/unix/stdpaths.cpp b/src/unix/stdpaths.cpp index de0c1d9555..51722274ab 100644 --- a/src/unix/stdpaths.cpp +++ b/src/unix/stdpaths.cpp @@ -50,6 +50,16 @@ void wxStandardPaths::SetInstallPrefix(const wxString& 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 dir; @@ -61,8 +71,7 @@ wxString wxStandardPaths::GetUserConfigDir() const break; case FileLayout_XDG: - if ( !wxGetEnv(wxS("XDG_CONFIG_HOME"), &dir) || dir.empty() ) - dir = wxFileName::GetHomeDir() + wxS("/.config"); + dir = GetXDGConfigHome(); break; } @@ -268,12 +277,7 @@ wxString wxStandardPaths::GetUserDir(Dir userDir) const return homeDir + wxT("/.cache"); } - wxString configPath; - if (wxGetenv(wxT("XDG_CONFIG_HOME"))) - configPath = wxGetenv(wxT("XDG_CONFIG_HOME")); - else - configPath = homeDir + wxT("/.config"); - wxString dirsFile = configPath + wxT("/user-dirs.dirs"); + wxString dirsFile = GetXDGConfigHome() + wxT("/user-dirs.dirs"); if (wxFileExists(dirsFile)) { wxString userDirId;