mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2025-03-09 21:01:53 +01:00
Changed gameFile format and gamedetails cache format
gameFile now contains gamename and file type info Game details cache format has been changed to match gameFile changes Cache also has a new "gamedetails-cache-version" field that can be used to detect cache format changes
This commit is contained in:
parent
2538825fb2
commit
5bfb00bb31
@ -13,18 +13,25 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
|
|
||||||
|
// Game file types
|
||||||
|
const unsigned int GFTYPE_INSTALLER = 1 << 0;
|
||||||
|
const unsigned int GFTYPE_EXTRA = 1 << 1;
|
||||||
|
const unsigned int GFTYPE_PATCH = 1 << 2;
|
||||||
|
const unsigned int GFTYPE_LANGPACK = 1 << 3;
|
||||||
|
|
||||||
class gameFile
|
class gameFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
gameFile();
|
gameFile();
|
||||||
gameFile(const int& t_updated, const std::string& t_id, const std::string& t_name, const std::string& t_path, const std::string& t_size, const unsigned int& t_language = GlobalConstants::LANGUAGE_EN, const unsigned int& t_platform = GlobalConstants::PLATFORM_WINDOWS, const int& t_silent = 0);
|
|
||||||
int updated;
|
int updated;
|
||||||
|
std::string gamename;
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string path;
|
std::string path;
|
||||||
std::string size;
|
std::string size;
|
||||||
unsigned int platform;
|
unsigned int platform;
|
||||||
unsigned int language;
|
unsigned int language;
|
||||||
|
unsigned int type;
|
||||||
int score;
|
int score;
|
||||||
int silent;
|
int silent;
|
||||||
void setFilepath(const std::string& path);
|
void setFilepath(const std::string& path);
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
namespace GlobalConstants
|
namespace GlobalConstants
|
||||||
{
|
{
|
||||||
|
const int GAMEDETAILS_CACHE_VERSION = 1;
|
||||||
|
|
||||||
struct optionsStruct {const unsigned int id; const std::string code; const std::string str; const std::string regexp;};
|
struct optionsStruct {const unsigned int id; const std::string code; const std::string str; const std::string regexp;};
|
||||||
const std::string PROTOCOL_PREFIX = "gogdownloader://";
|
const std::string PROTOCOL_PREFIX = "gogdownloader://";
|
||||||
|
|
||||||
|
107
src/api.cpp
107
src/api.cpp
@ -349,17 +349,19 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
game.installers.push_back(
|
gameFile gf;
|
||||||
gameFile( installer["notificated"].isInt() ? installer["notificated"].asInt() : std::stoi(installer["notificated"].asString()),
|
gf.type = GFTYPE_INSTALLER;
|
||||||
installer["id"].isInt() ? std::to_string(installer["id"].asInt()) : installer["id"].asString(),
|
gf.gamename = game.gamename;
|
||||||
installer["name"].asString(),
|
gf.updated = installer["notificated"].isInt() ? installer["notificated"].asInt() : std::stoi(installer["notificated"].asString());
|
||||||
installer["link"].asString(),
|
gf.id = installer["id"].isInt() ? std::to_string(installer["id"].asInt()) : installer["id"].asString();
|
||||||
installer["size"].asString(),
|
gf.name = installer["name"].asString();
|
||||||
language,
|
gf.path = installer["link"].asString();
|
||||||
installers[i].platform,
|
gf.size = installer["size"].asString();
|
||||||
installer["silent"].isInt() ? installer["silent"].asInt() : std::stoi(installer["silent"].asString())
|
gf.language = language;
|
||||||
)
|
gf.platform = installers[i].platform;
|
||||||
);
|
gf.silent = installer["silent"].isInt() ? installer["silent"].asInt() : std::stoi(installer["silent"].asString());
|
||||||
|
|
||||||
|
game.installers.push_back(gf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,14 +371,16 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
|
|||||||
{
|
{
|
||||||
Json::Value extra = extras[index];
|
Json::Value extra = extras[index];
|
||||||
|
|
||||||
game.extras.push_back(
|
gameFile gf;
|
||||||
gameFile( false, /* extras don't have "updated" flag */
|
gf.type = GFTYPE_EXTRA;
|
||||||
extra["id"].isInt() ? std::to_string(extra["id"].asInt()) : extra["id"].asString(),
|
gf.gamename = game.gamename;
|
||||||
extra["name"].asString(),
|
gf.updated = false; // extras don't have "updated" flag
|
||||||
extra["link"].asString(),
|
gf.id = extra["id"].isInt() ? std::to_string(extra["id"].asInt()) : extra["id"].asString();
|
||||||
extra["size_mb"].asString()
|
gf.name = extra["name"].asString();
|
||||||
)
|
gf.path = extra["link"].asString();
|
||||||
);
|
gf.size = extra["size_mb"].asString();
|
||||||
|
|
||||||
|
game.extras.push_back(gf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Patch details
|
// Patch details
|
||||||
@ -434,16 +438,18 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
game.patches.push_back(
|
gameFile gf;
|
||||||
gameFile( patch["notificated"].isInt() ? patch["notificated"].asInt() : std::stoi(patch["notificated"].asString()),
|
gf.type = GFTYPE_PATCH;
|
||||||
patch["id"].isInt() ? std::to_string(patch["id"].asInt()) : patch["id"].asString(),
|
gf.gamename = game.gamename;
|
||||||
patch["name"].asString(),
|
gf.updated = patch["notificated"].isInt() ? patch["notificated"].asInt() : std::stoi(patch["notificated"].asString());
|
||||||
patch["link"].asString(),
|
gf.id = patch["id"].isInt() ? std::to_string(patch["id"].asInt()) : patch["id"].asString();
|
||||||
patch["size"].asString(),
|
gf.name = patch["name"].asString();
|
||||||
GlobalConstants::LANGUAGES[i].id,
|
gf.path = patch["link"].asString();
|
||||||
patches[j].platform
|
gf.size = patch["size"].asString();
|
||||||
)
|
gf.language = GlobalConstants::LANGUAGES[i].id;
|
||||||
);
|
gf.platform = patches[j].platform;
|
||||||
|
|
||||||
|
game.patches.push_back(gf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // Patch is a single file
|
else // Patch is a single file
|
||||||
@ -465,16 +471,18 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
game.patches.push_back(
|
gameFile gf;
|
||||||
gameFile( patchnode["notificated"].isInt() ? patchnode["notificated"].asInt() : std::stoi(patchnode["notificated"].asString()),
|
gf.type = GFTYPE_PATCH;
|
||||||
patchnode["id"].isInt() ? std::to_string(patchnode["id"].asInt()) : patchnode["id"].asString(),
|
gf.gamename = game.gamename;
|
||||||
patchnode["name"].asString(),
|
gf.updated = patchnode["notificated"].isInt() ? patchnode["notificated"].asInt() : std::stoi(patchnode["notificated"].asString());
|
||||||
patchnode["link"].asString(),
|
gf.id = patchnode["id"].isInt() ? std::to_string(patchnode["id"].asInt()) : patchnode["id"].asString();
|
||||||
patchnode["size"].asString(),
|
gf.name = patchnode["name"].asString();
|
||||||
GlobalConstants::LANGUAGES[i].id,
|
gf.path = patchnode["link"].asString();
|
||||||
patches[j].platform
|
gf.size = patchnode["size"].asString();
|
||||||
)
|
gf.language = GlobalConstants::LANGUAGES[i].id;
|
||||||
);
|
gf.platform = patches[j].platform;
|
||||||
|
|
||||||
|
game.patches.push_back(gf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -500,15 +508,18 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
|
|||||||
for (unsigned int j = 0; j < langpacknames.size(); ++j)
|
for (unsigned int j = 0; j < langpacknames.size(); ++j)
|
||||||
{
|
{
|
||||||
Json::Value langpack = root["game"][langpacknames[j]];
|
Json::Value langpack = root["game"][langpacknames[j]];
|
||||||
game.languagepacks.push_back(
|
|
||||||
gameFile( false, /* language packs don't have "updated" flag */
|
gameFile gf;
|
||||||
langpack["id"].isInt() ? std::to_string(langpack["id"].asInt()) : langpack["id"].asString(),
|
gf.type = GFTYPE_LANGPACK;
|
||||||
langpack["name"].asString(),
|
gf.gamename = game.gamename;
|
||||||
langpack["link"].asString(),
|
gf.updated = false; // language packs don't have "updated" flag
|
||||||
langpack["size"].asString(),
|
gf.id = langpack["id"].isInt() ? std::to_string(langpack["id"].asInt()) : langpack["id"].asString();
|
||||||
GlobalConstants::LANGUAGES[i].id
|
gf.name = langpack["name"].asString();
|
||||||
)
|
gf.path = langpack["link"].asString();
|
||||||
);
|
gf.size = langpack["size"].asString();
|
||||||
|
gf.language = GlobalConstants::LANGUAGES[i].id;
|
||||||
|
|
||||||
|
game.languagepacks.push_back(gf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,6 +256,11 @@ int Downloader::getGameDetails()
|
|||||||
std::cerr << "Cache is too old." << std::endl;
|
std::cerr << "Cache is too old." << std::endl;
|
||||||
std::cerr << "Update cache with --update-cache or use bigger --cache-valid" << std::endl;
|
std::cerr << "Update cache with --update-cache or use bigger --cache-valid" << std::endl;
|
||||||
}
|
}
|
||||||
|
else if (result == 5)
|
||||||
|
{
|
||||||
|
std::cerr << "Cache version doesn't match current version." << std::endl;
|
||||||
|
std::cerr << "Update cache with --update-cache" << std::endl;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2056,14 +2061,15 @@ std::vector<gameFile> Downloader::getExtrasFromJSON(const Json::Value& json, con
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
extras.push_back(
|
gameFile gf;
|
||||||
gameFile ( false,
|
gf.type = GFTYPE_EXTRA;
|
||||||
id,
|
gf.gamename = gamename;
|
||||||
name,
|
gf.updated = false;
|
||||||
path,
|
gf.id = id;
|
||||||
std::string()
|
gf.name = name;
|
||||||
)
|
gf.path = path;
|
||||||
);
|
|
||||||
|
extras.push_back(gf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return extras;
|
return extras;
|
||||||
@ -2609,6 +2615,7 @@ std::string Downloader::getRemoteFileHash(const std::string& gamename, const std
|
|||||||
returns 2 if JSON parsing failed
|
returns 2 if JSON parsing failed
|
||||||
returns 3 if cache is too old
|
returns 3 if cache is too old
|
||||||
returns 4 if JSON doesn't contain "games" node
|
returns 4 if JSON doesn't contain "games" node
|
||||||
|
returns 5 if cache version doesn't match
|
||||||
*/
|
*/
|
||||||
int Downloader::loadGameDetailsCache()
|
int Downloader::loadGameDetailsCache()
|
||||||
{
|
{
|
||||||
@ -2641,14 +2648,25 @@ int Downloader::loadGameDetailsCache()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root.isMember("games"))
|
int iCacheVersion = 0;
|
||||||
|
if (root.isMember("gamedetails-cache-version"))
|
||||||
|
iCacheVersion = root["gamedetails-cache-version"].asInt();
|
||||||
|
|
||||||
|
if (iCacheVersion != GlobalConstants::GAMEDETAILS_CACHE_VERSION)
|
||||||
{
|
{
|
||||||
this->games = getGameDetailsFromJsonNode(root["games"]);
|
res = 5;
|
||||||
res = 0;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res = 4;
|
if (root.isMember("games"))
|
||||||
|
{
|
||||||
|
this->games = getGameDetailsFromJsonNode(root["games"]);
|
||||||
|
res = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res = 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2681,6 +2699,7 @@ int Downloader::saveGameDetailsCache()
|
|||||||
|
|
||||||
Json::Value json;
|
Json::Value json;
|
||||||
|
|
||||||
|
json["gamedetails-cache-version"] = GlobalConstants::GAMEDETAILS_CACHE_VERSION;
|
||||||
json["version-string"] = config.sVersionString;
|
json["version-string"] = config.sVersionString;
|
||||||
json["version-number"] = config.sVersionNumber;
|
json["version-number"] = config.sVersionNumber;
|
||||||
json["date"] = bptime::to_iso_string(bptime::second_clock::local_time());
|
json["date"] = bptime::to_iso_string(bptime::second_clock::local_time());
|
||||||
@ -2764,6 +2783,8 @@ std::vector<gameDetails> Downloader::getGameDetailsFromJsonNode(Json::Value root
|
|||||||
fileDetails.platform = fileDetailsNode["platform"].asUInt();
|
fileDetails.platform = fileDetailsNode["platform"].asUInt();
|
||||||
fileDetails.language = fileDetailsNode["language"].asUInt();
|
fileDetails.language = fileDetailsNode["language"].asUInt();
|
||||||
fileDetails.silent = fileDetailsNode["silent"].asInt();
|
fileDetails.silent = fileDetailsNode["silent"].asInt();
|
||||||
|
fileDetails.gamename = fileDetailsNode["gamename"].asString();
|
||||||
|
fileDetails.type = fileDetailsNode["type"].asUInt();
|
||||||
|
|
||||||
if (nodeName != "extras" && !(fileDetails.platform & conf.iInstallerPlatform))
|
if (nodeName != "extras" && !(fileDetails.platform & conf.iInstallerPlatform))
|
||||||
continue;
|
continue;
|
||||||
|
@ -6,21 +6,12 @@
|
|||||||
|
|
||||||
#include "gamefile.h"
|
#include "gamefile.h"
|
||||||
|
|
||||||
gameFile::gameFile(const int& t_updated, const std::string& t_id, const std::string& t_name, const std::string& t_path, const std::string& t_size, const unsigned int& t_language, const unsigned int& t_platform, const int& t_silent)
|
|
||||||
{
|
|
||||||
this->updated = t_updated;
|
|
||||||
this->id = t_id;
|
|
||||||
this->name = t_name;
|
|
||||||
this->path = t_path;
|
|
||||||
this->size = t_size;
|
|
||||||
this->platform = t_platform;
|
|
||||||
this->language = t_language;
|
|
||||||
this->silent = t_silent;
|
|
||||||
}
|
|
||||||
|
|
||||||
gameFile::gameFile()
|
gameFile::gameFile()
|
||||||
{
|
{
|
||||||
//ctor
|
this->platform = GlobalConstants::PLATFORM_WINDOWS;
|
||||||
|
this->language = GlobalConstants::LANGUAGE_EN;
|
||||||
|
this->silent = 0;
|
||||||
|
this->type = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gameFile::~gameFile()
|
gameFile::~gameFile()
|
||||||
@ -50,6 +41,8 @@ Json::Value gameFile::getAsJson()
|
|||||||
json["platform"] = this->platform;
|
json["platform"] = this->platform;
|
||||||
json["language"] = this->language;
|
json["language"] = this->language;
|
||||||
json["silent"] = this->silent;
|
json["silent"] = this->silent;
|
||||||
|
json["gamename"] = this->gamename;
|
||||||
|
json["type"] = this->type;
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user