mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Merge pull request #55 from davidfoerster/xdg-config-paths
Use XDG_CONFIG_HOME to determine the path of the configuration
This commit is contained in:
0
src/Core/Unix/MacOSX/CoreMacOSX.cpp
Executable file → Normal file
0
src/Core/Unix/MacOSX/CoreMacOSX.cpp
Executable file → Normal file
0
src/Crypto/Whirlpool.c
Executable file → Normal file
0
src/Crypto/Whirlpool.c
Executable file → Normal file
0
src/Crypto/config.h
Executable file → Normal file
0
src/Crypto/config.h
Executable file → Normal file
0
src/Crypto/cpu.c
Executable file → Normal file
0
src/Crypto/cpu.c
Executable file → Normal file
0
src/Crypto/cpu.h
Executable file → Normal file
0
src/Crypto/cpu.h
Executable file → Normal file
0
src/Crypto/misc.h
Executable file → Normal file
0
src/Crypto/misc.h
Executable file → Normal file
@@ -22,6 +22,54 @@
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void EnsureEndsWithPathSeparator( wxString &s )
|
||||
{
|
||||
const wxUniChar pathSeparator = wxFileName::GetPathSeparator();
|
||||
if (s[s.size() - 1] != pathSeparator)
|
||||
s.append(pathSeparator);
|
||||
}
|
||||
|
||||
wxString *GetXdgConfigPath ()
|
||||
{
|
||||
const wxChar *xdgConfig = wxGetenv(wxT("XDG_CONFIG_HOME"));
|
||||
wxString *configDir;
|
||||
|
||||
if (!wxIsEmpty(xdgConfig))
|
||||
{
|
||||
configDir = new wxString (xdgConfig);
|
||||
//wcerr << L"XDG_CONFIG_HOME=" << *configDir << endl;
|
||||
EnsureEndsWithPathSeparator(*configDir);
|
||||
configDir->append(Application::GetName());
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !defined(TC_UNIX) || defined(TC_MACOSX) // Windows, OS X:
|
||||
configDir =
|
||||
new wxString (wxStandardPaths::Get().GetUserDataDir());
|
||||
#else // Linux, FreeBSD, Solaris:
|
||||
configDir = new wxString (wxFileName::GetHomeDir());
|
||||
configDir->append(wxT("/.config/"));
|
||||
configDir->append(Application::GetName());
|
||||
|
||||
if (!wxDirExists(*configDir))
|
||||
{
|
||||
wxString legacyConfigDir = wxStandardPaths::Get().GetUserDataDir();
|
||||
//wcerr << L"Legacy config dir: " << legacyConfigDir << endl;
|
||||
if (wxDirExists(legacyConfigDir))
|
||||
{
|
||||
configDir->swap(legacyConfigDir);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//wcerr << L"Config dir: " << *configDir << endl;
|
||||
return configDir;
|
||||
}
|
||||
}
|
||||
|
||||
wxApp* Application::CreateConsoleApp ()
|
||||
{
|
||||
mUserInterface = new TextUserInterface;
|
||||
@@ -40,27 +88,44 @@ namespace VeraCrypt
|
||||
|
||||
FilePath Application::GetConfigFilePath (const wxString &configFileName, bool createConfigDir)
|
||||
{
|
||||
DirectoryPath configDir;
|
||||
static wxScopedPtr<const wxString> configDirC;
|
||||
static bool configDirExists = false;
|
||||
|
||||
if (!Core->IsInPortableMode())
|
||||
if (!configDirExists)
|
||||
{
|
||||
#ifdef TC_MACOSX
|
||||
wxFileName configPath (L"~/Library/Application Support/VeraCrypt");
|
||||
configPath.Normalize();
|
||||
configDir = wstring (configPath.GetFullPath());
|
||||
#else
|
||||
wxStandardPaths& stdPaths = wxStandardPaths::Get();
|
||||
configDir = wstring (stdPaths.GetUserDataDir());
|
||||
#endif
|
||||
if (!configDirC)
|
||||
{
|
||||
wxString *configDir;
|
||||
|
||||
if (Core->IsInPortableMode())
|
||||
{
|
||||
configDir = new wxString (
|
||||
wxPathOnly(wxStandardPaths::Get().GetExecutablePath()));
|
||||
}
|
||||
else
|
||||
{
|
||||
configDir = GetXdgConfigPath();
|
||||
}
|
||||
|
||||
EnsureEndsWithPathSeparator(*configDir);
|
||||
configDirC.reset(configDir);
|
||||
}
|
||||
|
||||
if (createConfigDir)
|
||||
{
|
||||
if (!wxDirExists(*configDirC))
|
||||
{
|
||||
//wcerr << L"Creating config dir »" << *configDirC << L"« ..." << endl;
|
||||
throw_sys_sub_if(
|
||||
!wxMkdir(*configDirC, wxS_IRUSR | wxS_IWUSR | wxS_IXUSR),
|
||||
configDirC->ToStdWstring());
|
||||
}
|
||||
configDirExists = true;
|
||||
//wcerr << L"Config directory »" << *configDirC << L"« exists now" << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
configDir = GetExecutableDirectory();
|
||||
|
||||
if (createConfigDir && !configDir.IsDirectory())
|
||||
Directory::Create (configDir);
|
||||
|
||||
FilePath filePath = wstring (wxFileName (wstring (configDir), configFileName).GetFullPath());
|
||||
return filePath;
|
||||
return FilePath((*configDirC + configFileName).ToStdWstring());
|
||||
}
|
||||
|
||||
DirectoryPath Application::GetExecutableDirectory ()
|
||||
|
||||
0
src/Main/Forms/ChangePasswordDialog.cpp
Executable file → Normal file
0
src/Main/Forms/ChangePasswordDialog.cpp
Executable file → Normal file
0
src/Main/Forms/MountOptionsDialog.cpp
Executable file → Normal file
0
src/Main/Forms/MountOptionsDialog.cpp
Executable file → Normal file
0
src/Main/Forms/VolumeCreationWizard.cpp
Executable file → Normal file
0
src/Main/Forms/VolumeCreationWizard.cpp
Executable file → Normal file
0
src/Main/Forms/VolumePasswordPanel.cpp
Executable file → Normal file
0
src/Main/Forms/VolumePasswordPanel.cpp
Executable file → Normal file
0
src/Main/Forms/VolumePimWizardPage.cpp
Executable file → Normal file
0
src/Main/Forms/VolumePimWizardPage.cpp
Executable file → Normal file
0
src/Resources/Icons/VeraCrypt-128x128.xpm
Executable file → Normal file
0
src/Resources/Icons/VeraCrypt-128x128.xpm
Executable file → Normal file
0
src/Resources/Icons/VeraCrypt-256x256.xpm
Executable file → Normal file
0
src/Resources/Icons/VeraCrypt-256x256.xpm
Executable file → Normal file
Reference in New Issue
Block a user