mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
Add support for some game specific settings
This commit is contained in:
parent
5102f812a4
commit
705bde3f6f
@ -15,6 +15,13 @@
|
||||
#include <sstream>
|
||||
#include <rhash.h>
|
||||
|
||||
struct gameSpecificConfig
|
||||
{
|
||||
unsigned int iInstallerType;
|
||||
unsigned int iInstallerLanguage;
|
||||
bool bDLC;
|
||||
};
|
||||
|
||||
namespace Util
|
||||
{
|
||||
std::string makeFilepath(const std::string& directory, const std::string& path, const std::string& gamename, std::string subdirectory = "");
|
||||
@ -22,6 +29,7 @@ namespace Util
|
||||
std::string getFileHash(const std::string& filename, unsigned hash_id);
|
||||
std::string getChunkHash(unsigned char* chunk, size_t chunk_size, unsigned hash_id);
|
||||
int createXML(std::string filepath, size_t chunk_size, std::string xml_dir = std::string());
|
||||
int getGameSpecificConfig(std::string gamename, gameSpecificConfig* conf, std::string directory = std::string());
|
||||
}
|
||||
|
||||
#endif // UTIL_H
|
||||
|
@ -66,5 +66,22 @@ Allows user to specify individual files that should not be downloaded or mention
|
||||
.br
|
||||
It doesn't have to exist, but if it does exist, it must be readable to lgogdownloader.
|
||||
|
||||
.TP
|
||||
\fI$XDG_CONFIG_HOME/lgogdownloader/gamename.conf\fP
|
||||
JSON formatted file. Sets game specific settings for \fBgamename\fP.
|
||||
.br
|
||||
Allowed settings are \fBlanguage\fP, \fBplatform\fP and \fBdlc\fP.
|
||||
.br
|
||||
The \fBdlc\fP option is limited to disabling DLC for specific game. It can't enable DLC listing/downloading if \fB--no-dlc\fP option is used.
|
||||
.br
|
||||
Must be in the following format:
|
||||
.br
|
||||
{
|
||||
"language" : <int>,
|
||||
"platform" : <int>,
|
||||
"dlc" : <bool>
|
||||
.br
|
||||
}
|
||||
|
||||
[availability]
|
||||
The latest version of this distribution is available from \fIhttps://github.com/Sude-/lgogdownloader\fP
|
||||
|
@ -210,19 +210,27 @@ int Downloader::getGameDetails()
|
||||
{
|
||||
std::cout << "Getting game info " << i+1 << " / " << gameItems.size() << "\r" << std::flush;
|
||||
bool bHasDLC = !gameItems[i].dlcnames.empty();
|
||||
game = gogAPI->getGameDetails(gameItems[i].name, config.iInstallerType, config.iInstallerLanguage, config.bDuplicateHandler);
|
||||
|
||||
gameSpecificConfig conf;
|
||||
conf.bDLC = config.bDLC;
|
||||
conf.iInstallerLanguage = config.iInstallerLanguage;
|
||||
conf.iInstallerType = config.iInstallerType;
|
||||
if (Util::getGameSpecificConfig(gameItems[i].name, &conf) > 0)
|
||||
std::cout << std::endl << gameItems[i].name << " - Language: " << conf.iInstallerLanguage << ", Platform: " << conf.iInstallerType << ", DLC: " << (conf.bDLC ? "true" : "false") << std::endl;
|
||||
|
||||
game = gogAPI->getGameDetails(gameItems[i].name, conf.iInstallerType, conf.iInstallerLanguage, config.bDuplicateHandler);
|
||||
if (!gogAPI->getError())
|
||||
{
|
||||
if (game.extras.empty() && config.bExtras) // Try to get extras from account page if API didn't return any extras
|
||||
{
|
||||
game.extras = this->getExtras(gameItems[i].name, gameItems[i].id);
|
||||
}
|
||||
if (game.dlcs.empty() && bHasDLC && config.bDLC)
|
||||
if (game.dlcs.empty() && bHasDLC && conf.bDLC)
|
||||
{
|
||||
for (unsigned int j = 0; j < gameItems[i].dlcnames.size(); ++j)
|
||||
{
|
||||
gameDetails dlc;
|
||||
dlc = gogAPI->getGameDetails(gameItems[i].dlcnames[j], config.iInstallerType, config.iInstallerLanguage, config.bDuplicateHandler);
|
||||
dlc = gogAPI->getGameDetails(gameItems[i].dlcnames[j], conf.iInstallerType, conf.iInstallerLanguage, config.bDuplicateHandler);
|
||||
if (dlc.extras.empty() && config.bExtras) // Try to get extras from account page if API didn't return any extras
|
||||
{
|
||||
dlc.extras = this->getExtras(gameItems[i].dlcnames[j], gameItems[i].id);
|
||||
|
64
src/util.cpp
64
src/util.cpp
@ -8,6 +8,8 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <tinyxml.h>
|
||||
#include <jsoncpp/json/json.h>
|
||||
#include <fstream>
|
||||
|
||||
/*
|
||||
Create filepath from specified directory and path
|
||||
@ -192,3 +194,65 @@ int Util::createXML(std::string filepath, size_t chunk_size, std::string xml_dir
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
Overrides global settings with game specific settings
|
||||
returns 0 if fails
|
||||
returns number of changed settings if succesful
|
||||
*/
|
||||
int Util::getGameSpecificConfig(std::string gamename, gameSpecificConfig* conf, std::string directory)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
if (directory.empty())
|
||||
{
|
||||
char *xdghome = getenv("XDG_CONFIG_HOME");
|
||||
if (xdghome)
|
||||
directory = (std::string)xdghome + "/lgogdownloader";
|
||||
else
|
||||
{
|
||||
std::string home = (std::string)getenv("HOME");
|
||||
directory = home + "/.config/lgogdownloader";
|
||||
}
|
||||
}
|
||||
|
||||
std::string filepath = directory + "/" + gamename + ".conf";
|
||||
|
||||
// Make sure file exists
|
||||
boost::filesystem::path path = filepath;
|
||||
if (!boost::filesystem::exists(path)) {
|
||||
return res;
|
||||
}
|
||||
|
||||
std::ifstream json(filepath, std::ifstream::binary);
|
||||
Json::Value root;
|
||||
Json::Reader *jsonparser = new Json::Reader;
|
||||
if (jsonparser->parse(json, root))
|
||||
{
|
||||
if (root.isMember("language"))
|
||||
{
|
||||
conf->iInstallerLanguage = root["language"].asUInt();
|
||||
res++;
|
||||
}
|
||||
if (root.isMember("platform"))
|
||||
{
|
||||
conf->iInstallerType = root["platform"].asUInt();
|
||||
res++;
|
||||
}
|
||||
if (root.isMember("dlc"))
|
||||
{
|
||||
conf->bDLC = root["dlc"].asBool();
|
||||
res++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Failed to parse game specific config" << std::endl;
|
||||
std::cout << jsonparser->getFormatedErrorMessages() << std::endl;
|
||||
}
|
||||
delete jsonparser;
|
||||
if (json)
|
||||
json.close();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user