This commit is contained in:
Sude 2014-09-12 16:27:21 +03:00
commit 1394888920

104
main.cpp
View File

@ -34,45 +34,6 @@ int main(int argc, char *argv[])
char *xdgcache = getenv("XDG_CACHE_HOME");
std::string home = (std::string)getenv("HOME");
if (xdgconfig)
{
config.sConfigDirectory = (std::string)xdgconfig + "/lgogdownloader";
}
else
{
config.sConfigDirectory = home + "/.config/lgogdownloader";
}
config.sCookiePath = config.sConfigDirectory + "/cookies.txt";
config.sConfigFilePath = config.sConfigDirectory + "/config.cfg";
config.sBlacklistFilePath = config.sConfigDirectory + "/blacklist.txt";
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))
{
if (!boost::filesystem::create_directories(path))
{
std::cout << "Failed to create directory: " << path << std::endl;
return 1;
}
}
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;
@ -180,6 +141,58 @@ int main(int argc, char *argv[])
bpo::store(bpo::parse_command_line(argc, argv, options_cli_all), vm);
bpo::notify(vm);
if (vm.count("help"))
{
std::cout << config.sVersionString << std::endl
<< options_cli_all << std::endl;
return 0;
}
if (vm.count("version"))
{
std::cout << VERSION_STRING << std::endl;
return 0;
}
if (xdgconfig)
{
config.sConfigDirectory = (std::string)xdgconfig + "/lgogdownloader";
}
else
{
config.sConfigDirectory = home + "/.config/lgogdownloader";
}
config.sCookiePath = config.sConfigDirectory + "/cookies.txt";
config.sConfigFilePath = config.sConfigDirectory + "/config.cfg";
config.sBlacklistFilePath = config.sConfigDirectory + "/blacklist.txt";
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))
{
if (!boost::filesystem::create_directories(path))
{
std::cout << "Failed to create directory: " << path << std::endl;
return 1;
}
}
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;
}
}
if (boost::filesystem::exists(config.sConfigFilePath))
{
std::ifstream ifs(config.sConfigFilePath.c_str());
@ -231,19 +244,6 @@ int main(int argc, char *argv[])
config.blacklist.initialize(lines);
}
if (vm.count("help"))
{
std::cout << config.sVersionString << std::endl
<< options_cli_all << std::endl;
return 0;
}
if (vm.count("version"))
{
std::cout << VERSION_STRING << std::endl;
return 0;
}
if (vm.count("chunk-size"))
config.iChunkSize <<= 20; // Convert chunk size from bytes to megabytes