Fix #868 (move wxWidgets Unix config files to XDG basedir location), based on patch from leper.
Fix handling of set but empty XDG environment variables. This was SVN commit r11374.
This commit is contained in:
parent
700e28480d
commit
0e1b5522d6
@ -111,7 +111,8 @@ Paths::Paths(const CmdLineArgs& args)
|
||||
/*static*/ OsPath Paths::XDG_Path(const char* envname, const OsPath& home, const OsPath& defaultPath)
|
||||
{
|
||||
const char* path = getenv(envname);
|
||||
if(path)
|
||||
// Use if set and non-empty
|
||||
if(path && path[0] != '\0')
|
||||
{
|
||||
if(path[0] != '/') // relative to $HOME
|
||||
return home / path/"";
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -112,6 +112,13 @@ ATLASDLLIMPEXP void Atlas_SetDataDirectory(const wchar_t* path)
|
||||
g_HasSetDataDirectory = true;
|
||||
}
|
||||
|
||||
wxString g_ConfigDir;
|
||||
ATLASDLLIMPEXP void Atlas_SetConfigDirectory(const wchar_t* path)
|
||||
{
|
||||
wxFileName config (path);
|
||||
g_ConfigDir = config.GetPath(wxPATH_GET_SEPARATOR);
|
||||
}
|
||||
|
||||
ATLASDLLIMPEXP void Atlas_StartWindow(const wchar_t* type)
|
||||
{
|
||||
// Initialise libxml2
|
||||
@ -188,8 +195,31 @@ public:
|
||||
wxHandleFatalExceptions();
|
||||
#endif
|
||||
|
||||
#ifndef __WXMSW__ // On Windows we use the registry so don't attempt to set the path.
|
||||
// When launching a standalone executable g_ConfigDir may not be
|
||||
// set. In this case we default to the XDG base dir spec and use
|
||||
// 0ad/config/ as the config directory.
|
||||
wxString configPath;
|
||||
if (!g_ConfigDir.IsEmpty())
|
||||
{
|
||||
configPath = g_ConfigDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxString xdgConfigHome;
|
||||
if (wxGetEnv(_T("XDG_CONFIG_HOME"), &xdgConfigHome) && !xdgConfigHome.IsEmpty())
|
||||
configPath = xdgConfigHome + _T("/0ad/config/");
|
||||
else
|
||||
configPath = wxFileName::GetHomeDir() + _T("/.config/0ad/config/");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Initialise the global config file
|
||||
wxConfigBase::Set(new wxConfig(_T("Atlas Editor"), _T("Wildfire Games")));
|
||||
wxConfigBase::Set(new wxConfig(_T("Atlas Editor"), _T("Wildfire Games")
|
||||
#ifndef __WXMSW__ // On Windows we use wxRegConfig and setting this changes the Registry key
|
||||
, configPath + _T("atlas.ini")
|
||||
#endif
|
||||
));
|
||||
|
||||
if (! g_HasSetDataDirectory)
|
||||
{
|
||||
|
@ -52,6 +52,7 @@ namespace AtlasMessage
|
||||
// Loaded from DLL:
|
||||
void (*Atlas_StartWindow)(const wchar_t* type);
|
||||
void (*Atlas_SetDataDirectory)(const wchar_t* path);
|
||||
void (*Atlas_SetConfigDirectory)(const wchar_t* path);
|
||||
void (*Atlas_SetMessagePasser)(MessagePasser*);
|
||||
void (*Atlas_GLSetCurrent)(void* cavas);
|
||||
void (*Atlas_GLSwapBuffers)(void* canvas);
|
||||
@ -277,6 +278,7 @@ bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll)
|
||||
dll.LoadSymbol("Atlas_StartWindow", Atlas_StartWindow);
|
||||
dll.LoadSymbol("Atlas_SetMessagePasser", Atlas_SetMessagePasser);
|
||||
dll.LoadSymbol("Atlas_SetDataDirectory", Atlas_SetDataDirectory);
|
||||
dll.LoadSymbol("Atlas_SetConfigDirectory", Atlas_SetConfigDirectory);
|
||||
dll.LoadSymbol("Atlas_GLSetCurrent", Atlas_GLSetCurrent);
|
||||
dll.LoadSymbol("Atlas_GLSwapBuffers", Atlas_GLSwapBuffers);
|
||||
dll.LoadSymbol("Atlas_NotifyEndOfFrame", Atlas_NotifyEndOfFrame);
|
||||
@ -303,6 +305,9 @@ bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll)
|
||||
const Paths paths(args);
|
||||
Atlas_SetDataDirectory(paths.RData().string().c_str());
|
||||
|
||||
// Tell Atlas the location of the user config directory
|
||||
Atlas_SetConfigDirectory(paths.Config().string().c_str());
|
||||
|
||||
// Run the engine loop in a new thread
|
||||
pthread_t engineThread;
|
||||
pthread_create(&engineThread, NULL, RunEngine, reinterpret_cast<void*>(const_cast<CmdLineArgs*>(&args)));
|
||||
|
Loading…
Reference in New Issue
Block a user