Skip to content

Commit

Permalink
Support XDG Base Directory Specification
Browse files Browse the repository at this point in the history
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 d430af6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/config.h
Expand Up @@ -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;
Expand Down
37 changes: 32 additions & 5 deletions main.cpp
Expand Up @@ -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))
{
Expand All @@ -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;
Expand Down

0 comments on commit d430af6

Please sign in to comment.