Skip to content
Permalink
Browse files

Support XDG Base Directory Specification

Configuration files and cookies are now stored in "$XDG_CONFIG_HOME/lgogdownloader"
if $XDG_CONFIG_HOME is not set it will use "$HOME/.config/lgogdownloader"

XML files are now stored in "$XDG_CACHE_HOME/lgogdownloader/xml"
if $XDG_CACHE_HOME is not set it will use "$HOME/.cache/lgogdownloader/xml"
  • Loading branch information...
Sude- committed Dec 11, 2013
1 parent 65f407d commit d430af63d0006714b708d826941b57e6fbb434dd
Showing with 33 additions and 6 deletions.
  1. +1 −1 include/config.h
  2. +32 −5 main.cpp
@@ -41,7 +41,7 @@ class Config
std::string sToken;
std::string sSecret;
std::string sVersionString;
std::string sHome;
std::string sConfigDirectory;
std::string sCookiePath;
std::string sConfigFilePath;
unsigned int iInstallerType;
@@ -33,12 +33,29 @@ int main(int argc, char *argv[])
{
Config config;
config.sVersionString = VERSION_STRING;
config.sHome = (std::string)getenv("HOME");
config.sCookiePath = config.sHome + "/.gogdownloader/cookies.txt";
config.sConfigFilePath = config.sHome + "/.gogdownloader/config.cfg";
config.sXMLDirectory = config.sHome + "/.gogdownloader/xml";
char *xdgconfig = getenv("XDG_CONFIG_HOME");
char *xdgcache = getenv("XDG_CACHE_HOME");
std::string home = (std::string)getenv("HOME");

// Create gogdownloader directories
if (xdgconfig)
{
config.sConfigDirectory = (std::string)xdgconfig + "/lgogdownloader";
config.sCookiePath = config.sConfigDirectory + "/cookies.txt";
config.sConfigFilePath = config.sConfigDirectory + "/config.cfg";
}
else
{
config.sConfigDirectory = home + "/.config/lgogdownloader";
config.sCookiePath = config.sConfigDirectory + "/cookies.txt";
config.sConfigFilePath = config.sConfigDirectory + "/config.cfg";
}

if (xdgcache)
config.sXMLDirectory = (std::string)xdgcache + "/lgogdownloader/xml";
else
config.sXMLDirectory = home + "/.cache/lgogdownloader/xml";

// Create lgogdownloader directories
boost::filesystem::path path = config.sXMLDirectory;
if (!boost::filesystem::exists(path))
{
@@ -49,6 +66,16 @@ int main(int argc, char *argv[])
}
}

path = config.sConfigDirectory;
if (!boost::filesystem::exists(path))
{
if (!boost::filesystem::create_directories(path))
{
std::cout << "Failed to create directory: " << path << std::endl;
return 1;
}
}

// Create help text for --platform option
std::string platform_text = "Select which installers are downloaded\n";
unsigned int platform_sum = 0;

0 comments on commit d430af6

Please sign in to comment.
You can’t perform that action at this time.