Rudimentary support for showing location of local saves for cloud saves

This commit is contained in:
loki-47-6F-64 2022-07-28 21:11:44 +02:00
parent 6560688d8a
commit 8e046e977d
5 changed files with 112 additions and 1 deletions

View File

@ -114,6 +114,7 @@ class Downloader
void galaxyInstallGameById(const std::string& product_id, int build_index = -1, const unsigned int& iGalaxyArch = GlobalConstants::ARCH_X64);
void galaxyShowBuilds(const std::string& product_id, int build_index = -1);
void galaxyShowBuildsById(const std::string& product_id, int build_index = -1);
void galaxyShowCloudSavesById(const std::string& product_id, int build_index = -1);
protected:
private:
CURLcode downloadFile(const std::string& url, const std::string& filepath, const std::string& xml_data = std::string(), const std::string& gamename = std::string());

View File

@ -52,6 +52,7 @@ class galaxyAPI
Json::Value getManifestV1(const std::string& product_id, const std::string& build_id, const std::string& manifest_id = "repository", const std::string& platform = "windows");
Json::Value getManifestV1(const std::string& manifest_url);
Json::Value getManifestV2(std::string manifest_hash, const bool& is_dependency = false);
Json::Value getCloudPathAsJson(const std::string &clientId);
Json::Value getSecureLink(const std::string& product_id, const std::string& path);
Json::Value getDependencyLink(const std::string& path);
std::string getResponse(const std::string& url);

View File

@ -151,6 +151,7 @@ int main(int argc, char *argv[])
std::string galaxy_product_id_install;
std::string galaxy_product_id_show_builds;
std::string galaxy_product_id_show_cloud_paths;
std::string tags;
std::vector<std::string> vFileIdStrings;
@ -271,6 +272,7 @@ int main(int argc, char *argv[])
options_cli_experimental.add_options()
("galaxy-install", bpo::value<std::string>(&galaxy_product_id_install)->default_value(""), "Install game using product id [product_id/build_index] or gamename regex [gamename/build_id]\nBuild index is used to select a build and defaults to 0 if not specified.\n\nExample: 12345/2 selects build 2 for product 12345")
("galaxy-show-builds", bpo::value<std::string>(&galaxy_product_id_show_builds)->default_value(""), "Show game builds using product id [product_id/build_index] or gamename regex [gamename/build_id]\nBuild index is used to select a build and defaults to 0 if not specified.\n\nExample: 12345/2 selects build 2 for product 12345")
("galaxy-show-cloud-save-paths", bpo::value<std::string>(&galaxy_product_id_show_cloud_paths)->default_value(""), "Show game cloud-save paths using product id [product_id/build_index] or gamename regex [gamename/build_id]\nBuild index is used to select a build and defaults to 0 if not specified.\n\nExample: 12345/2 selects build 2 for product 12345")
("galaxy-platform", bpo::value<std::string>(&sGalaxyPlatform)->default_value("w"), galaxy_platform_text.c_str())
("galaxy-language", bpo::value<std::string>(&sGalaxyLanguage)->default_value("en"), galaxy_language_text.c_str())
("galaxy-arch", bpo::value<std::string>(&sGalaxyArch)->default_value("x64"), galaxy_arch_text.c_str())
@ -777,6 +779,17 @@ int main(int argc, char *argv[])
}
downloader.galaxyShowBuilds(product_id, build_index);
}
else if (!galaxy_product_id_show_cloud_paths.empty())
{
int build_index = -1;
std::vector<std::string> tokens = Util::tokenize(galaxy_product_id_show_cloud_paths, "/");
std::string product_id = tokens[0];
if (tokens.size() == 2)
{
build_index = std::stoi(tokens[1]);
}
downloader.galaxyShowCloudSavesById(product_id, build_index);
}
else if (!galaxy_product_id_install.empty())
{
int build_index = -1;

View File

@ -4091,7 +4091,97 @@ void Downloader::galaxyShowBuildsById(const std::string& product_id, int build_i
return;
}
std::cout << json << std::endl;
Json::StyledStreamWriter().write(std::cout, json);
return;
}
void Downloader::galaxyShowCloudSavesById(const std::string& product_id, int build_index)
{
std::string sPlatform;
unsigned int iPlatform = Globals::globalConfig.dlConf.iGalaxyPlatform;
if (iPlatform == GlobalConstants::PLATFORM_LINUX)
// Linux is not yet supported for cloud saves
return;
else if (iPlatform == GlobalConstants::PLATFORM_MAC)
sPlatform = "osx";
else
sPlatform = "windows";
Json::Value json = gogGalaxy->getProductBuilds(product_id, sPlatform);
// JSON is empty and platform is Linux. Most likely cause is that Galaxy API doesn't have Linux support
if (json.empty() && iPlatform == GlobalConstants::PLATFORM_LINUX)
{
std::cout << "Galaxy API doesn't have Linux support" << std::endl;
std::cout << "Checking for installers that can be used as repository" << std::endl;
DownloadConfig dlConf = Globals::globalConfig.dlConf;
dlConf.bInstallers = true;
dlConf.bExtras = false;
dlConf.bLanguagePacks = false;
dlConf.bPatches = false;
dlConf.bDLC = true;
dlConf.iInstallerPlatform = dlConf.iGalaxyPlatform;
dlConf.iInstallerLanguage = dlConf.iGalaxyLanguage;
Json::Value product_info = gogGalaxy->getProductInfo(product_id);
gameDetails game = gogGalaxy->productInfoJsonToGameDetails(product_info, dlConf);
std::vector<gameFile> vInstallers;
if (!game.installers.empty())
{
vInstallers.push_back(game.installers[0]);
for (unsigned int i = 0; i < game.dlcs.size(); ++i)
{
if (!game.dlcs[i].installers.empty())
vInstallers.push_back(game.dlcs[i].installers[0]);
}
}
if (vInstallers.empty())
{
std::cout << "No installers found" << std::endl;
}
else
{
std::cout << "Using these installers" << std::endl;
for (unsigned int i = 0; i < vInstallers.size(); ++i)
std::cout << "\t" << vInstallers[i].gamename << "/" << vInstallers[i].id << std::endl;
}
return;
}
build_index = std::max(0, build_index);
std::string link = json["items"][build_index]["link"].asString();
if (json["items"][build_index]["generation"].asInt() == 2)
{
std::string buildHash;
buildHash.assign(link.begin()+link.find_last_of("/")+1, link.end());
json = gogGalaxy->getManifestV2(buildHash);
}
else
{
std::cout << "Only generation 2 builds are supported currently" << std::endl;
return;
}
json = gogGalaxy->getCloudPathAsJson(json["clientId"].asString());
std::string platform;
switch(iPlatform) {
case GlobalConstants::PLATFORM_MAC:
platform = "MacOS";
break;
default:
platform = "Windows";
}
json = json["content"][platform]["cloudStorage"]["locations"];
Json::StyledStreamWriter().write(std::cout, json);
return;
}

View File

@ -190,6 +190,12 @@ Json::Value galaxyAPI::getManifestV2(std::string manifest_hash, const bool& is_d
return this->getResponseJson(url);
}
Json::Value galaxyAPI::getCloudPathAsJson(const std::string &clientId) {
std::string url = "https://remote-config.gog.com/components/galaxy_client/clients/" + clientId + "?component_version=2.0.51";
return this->getResponseJson(url);
}
Json::Value galaxyAPI::getSecureLink(const std::string& product_id, const std::string& path)
{
std::string url = "https://content-system.gog.com/products/" + product_id + "/secure_link?generation=2&path=" + path + "&_version=2";