From 90c0b2be79a6068d08b12b5cab07f11c6744be4e Mon Sep 17 00:00:00 2001 From: Sude Date: Fri, 15 Mar 2013 23:33:53 +0200 Subject: [PATCH] Use static memory allocation for extras and installers in gameDetails --- include/api.h | 4 ++-- main.cpp | 2 +- src/api.cpp | 24 ++++++++++++------------ src/downloader.cpp | 38 +++++++++++++++++++------------------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/include/api.h b/include/api.h index 84914ef..893f29c 100644 --- a/include/api.h +++ b/include/api.h @@ -43,8 +43,8 @@ class gameFile { class gameDetails { public: - std::vector extras; - std::vector installers; + std::vector extras; + std::vector installers; std::string gamename; std::string title; std::string icon; diff --git a/main.cpp b/main.cpp index c124f08..d44ce19 100644 --- a/main.cpp +++ b/main.cpp @@ -27,7 +27,7 @@ namespace bpo = boost::program_options; int main(int argc, char *argv[]) { Config config; - config.sVersionString = "LGOGDownloader 2.2"; + config.sVersionString = "LGOGDownloader 2.2+git"; config.sHome = (std::string)getenv("HOME"); config.sCookiePath = config.sHome + "/.gogdownloader/cookies.txt"; config.sConfigFilePath = config.sHome + "/.gogdownloader/config.cfg"; diff --git a/src/api.cpp b/src/api.cpp index b3e1a67..36fb795 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -321,12 +321,12 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int Json::Value installer = installers[i][index]; game.installers.push_back( - new gameFile( installer["#updated"].isBool() ? installer["id"].asBool() : false, - installer["id"].isInt() ? std::to_string(installer["id"].asInt()) : installer["id"].asString(), - std::string(), // empty string because installer doesn't have "name" - installer["link"].asString(), - installer["size"].asString() - ) + gameFile( installer["#updated"].isBool() ? installer["id"].asBool() : false, + installer["id"].isInt() ? std::to_string(installer["id"].asInt()) : installer["id"].asString(), + std::string(), // empty string because installer doesn't have "name" + installer["link"].asString(), + installer["size"].asString() + ) ); } } @@ -338,12 +338,12 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int Json::Value extra = extras[index]; game.extras.push_back( - new gameFile( false, /* extras don't have "updated" flag */ - extra["id"].isInt() ? std::to_string(extra["id"].asInt()) : extra["id"].asString(), - extra["name"].asString(), - extra["link"].asString(), - extra["size_mb"].asString() - ) + gameFile( false, /* extras don't have "updated" flag */ + extra["id"].isInt() ? std::to_string(extra["id"].asInt()) : extra["id"].asString(), + extra["name"].asString(), + extra["link"].asString(), + extra["size_mb"].asString() + ) ); } diff --git a/src/downloader.cpp b/src/downloader.cpp index ae6d666..53c897d 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -234,9 +234,9 @@ void Downloader::listGames() std::cout << "installers: " << std::endl; for (unsigned int j = 0; j < games[i].installers.size(); ++j) { - std::cout << "\tid: " << games[i].installers[j]->id << std::endl - << "\tpath: " << games[i].installers[j]->path << std::endl - << "\tsize: " << games[i].installers[j]->size << std::endl + std::cout << "\tid: " << games[i].installers[j].id << std::endl + << "\tpath: " << games[i].installers[j].path << std::endl + << "\tsize: " << games[i].installers[j].size << std::endl << std::endl; } } @@ -246,10 +246,10 @@ void Downloader::listGames() std::cout << "extras: " << std::endl; for (unsigned int j = 0; j < games[i].extras.size(); ++j) { - std::cout << "\tid: " << games[i].extras[j]->id << std::endl - << "\tname: " << games[i].extras[j]->name << std::endl - << "\tpath: " << games[i].extras[j]->path << std::endl - << "\tsize: " << games[i].extras[j]->size << std::endl + std::cout << "\tid: " << games[i].extras[j].id << std::endl + << "\tname: " << games[i].extras[j].name << std::endl + << "\tpath: " << games[i].extras[j].path << std::endl + << "\tsize: " << games[i].extras[j].size << std::endl << std::endl; } } @@ -282,13 +282,13 @@ void Downloader::repair() { for (unsigned int j = 0; j < games[i].installers.size(); ++j) { - std::string filepath = Util::makeFilepath(config.sDirectory, games[i].installers[j]->path, games[i].gamename); + std::string filepath = Util::makeFilepath(config.sDirectory, games[i].installers[j].path, games[i].gamename); // Get XML data std::string XML = ""; if (!config.bNoRemoteXML) { - XML = gogAPI->getXML(games[i].gamename, games[i].installers[j]->id); + XML = gogAPI->getXML(games[i].gamename, games[i].installers[j].id); if (gogAPI->getError()) { std::cout << gogAPI->getErrorMessage() << std::endl; @@ -300,7 +300,7 @@ void Downloader::repair() // Repair if (!XML.empty() || config.bNoRemoteXML) { - std::string url = gogAPI->getInstallerLink(games[i].gamename, games[i].installers[j]->id); + std::string url = gogAPI->getInstallerLink(games[i].gamename, games[i].installers[j].id); if (gogAPI->getError()) { std::cout << gogAPI->getErrorMessage() << std::endl; @@ -319,9 +319,9 @@ void Downloader::repair() { for (unsigned int j = 0; j < games[i].extras.size(); ++j) { - std::string filepath = Util::makeFilepath(config.sDirectory, games[i].extras[j]->path, games[i].gamename); + std::string filepath = Util::makeFilepath(config.sDirectory, games[i].extras[j].path, games[i].gamename); - std::string url = gogAPI->getExtraLink(games[i].gamename, games[i].extras[j]->id); + std::string url = gogAPI->getExtraLink(games[i].gamename, games[i].extras[j].id); if (gogAPI->getError()) { std::cout << gogAPI->getErrorMessage() << std::endl; @@ -357,7 +357,7 @@ void Downloader::download() // std::string directory = config.sDirectory + games[i].gamename + "/"; // Take path from installer path because for some games the base directory for installer/extra path is not "gamename" - std::string filepath = Util::makeFilepath(config.sDirectory, games[i].installers[0]->path, games[i].gamename); + std::string filepath = Util::makeFilepath(config.sDirectory, games[i].installers[0].path, games[i].gamename); // Get base directory from filepath boost::match_results what; @@ -373,7 +373,7 @@ void Downloader::download() for (unsigned int j = 0; j < games[i].installers.size(); ++j) { // Get link - std::string url = gogAPI->getInstallerLink(games[i].gamename, games[i].installers[j]->id); + std::string url = gogAPI->getInstallerLink(games[i].gamename, games[i].installers[j].id); if (gogAPI->getError()) { std::cout << gogAPI->getErrorMessage() << std::endl; @@ -381,7 +381,7 @@ void Downloader::download() continue; } - std::string filepath = Util::makeFilepath(config.sDirectory, games[i].installers[j]->path, games[i].gamename); + std::string filepath = Util::makeFilepath(config.sDirectory, games[i].installers[j].path, games[i].gamename); // Download if (!url.empty()) @@ -398,7 +398,7 @@ void Downloader::download() for (unsigned int j = 0; j < games[i].extras.size(); ++j) { // Get link - std::string url = gogAPI->getExtraLink(games[i].gamename, games[i].extras[j]->id); + std::string url = gogAPI->getExtraLink(games[i].gamename, games[i].extras[j].id); if (gogAPI->getError()) { std::cout << gogAPI->getErrorMessage() << std::endl; @@ -406,13 +406,13 @@ void Downloader::download() continue; } - std::string filepath = Util::makeFilepath(config.sDirectory, games[i].extras[j]->path, games[i].gamename); + std::string filepath = Util::makeFilepath(config.sDirectory, games[i].extras[j].path, games[i].gamename); // Download if (!url.empty()) { - if (!games[i].extras[j]->name.empty()) - std::cout << "Dowloading: " << games[i].extras[j]->name << std::endl; + if (!games[i].extras[j].name.empty()) + std::cout << "Dowloading: " << games[i].extras[j].name << std::endl; std::cout << filepath << std::endl; CURLcode result = downloadFile(url, filepath); std::cout << std::endl;