Use static memory allocation for extras and installers in gameDetails

This commit is contained in:
Sude 2013-03-15 23:33:53 +02:00
parent 2d045c4052
commit 90c0b2be79
4 changed files with 34 additions and 34 deletions

View File

@ -43,8 +43,8 @@ class gameFile {
class gameDetails { class gameDetails {
public: public:
std::vector<gameFile *> extras; std::vector<gameFile> extras;
std::vector<gameFile *> installers; std::vector<gameFile> installers;
std::string gamename; std::string gamename;
std::string title; std::string title;
std::string icon; std::string icon;

View File

@ -27,7 +27,7 @@ namespace bpo = boost::program_options;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
Config config; Config config;
config.sVersionString = "LGOGDownloader 2.2"; config.sVersionString = "LGOGDownloader 2.2+git";
config.sHome = (std::string)getenv("HOME"); config.sHome = (std::string)getenv("HOME");
config.sCookiePath = config.sHome + "/.gogdownloader/cookies.txt"; config.sCookiePath = config.sHome + "/.gogdownloader/cookies.txt";
config.sConfigFilePath = config.sHome + "/.gogdownloader/config.cfg"; config.sConfigFilePath = config.sHome + "/.gogdownloader/config.cfg";

View File

@ -321,12 +321,12 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
Json::Value installer = installers[i][index]; Json::Value installer = installers[i][index];
game.installers.push_back( game.installers.push_back(
new gameFile( installer["#updated"].isBool() ? installer["id"].asBool() : false, gameFile( installer["#updated"].isBool() ? installer["id"].asBool() : false,
installer["id"].isInt() ? std::to_string(installer["id"].asInt()) : installer["id"].asString(), installer["id"].isInt() ? std::to_string(installer["id"].asInt()) : installer["id"].asString(),
std::string(), // empty string because installer doesn't have "name" std::string(), // empty string because installer doesn't have "name"
installer["link"].asString(), installer["link"].asString(),
installer["size"].asString() installer["size"].asString()
) )
); );
} }
} }
@ -338,12 +338,12 @@ 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( game.extras.push_back(
new gameFile( false, /* extras don't have "updated" flag */ gameFile( false, /* extras don't have "updated" flag */
extra["id"].isInt() ? std::to_string(extra["id"].asInt()) : extra["id"].asString(), extra["id"].isInt() ? std::to_string(extra["id"].asInt()) : extra["id"].asString(),
extra["name"].asString(), extra["name"].asString(),
extra["link"].asString(), extra["link"].asString(),
extra["size_mb"].asString() extra["size_mb"].asString()
) )
); );
} }

View File

@ -234,9 +234,9 @@ void Downloader::listGames()
std::cout << "installers: " << std::endl; std::cout << "installers: " << std::endl;
for (unsigned int j = 0; j < games[i].installers.size(); ++j) for (unsigned int j = 0; j < games[i].installers.size(); ++j)
{ {
std::cout << "\tid: " << games[i].installers[j]->id << std::endl std::cout << "\tid: " << games[i].installers[j].id << std::endl
<< "\tpath: " << games[i].installers[j]->path << std::endl << "\tpath: " << games[i].installers[j].path << std::endl
<< "\tsize: " << games[i].installers[j]->size << std::endl << "\tsize: " << games[i].installers[j].size << std::endl
<< std::endl; << std::endl;
} }
} }
@ -246,10 +246,10 @@ void Downloader::listGames()
std::cout << "extras: " << std::endl; std::cout << "extras: " << std::endl;
for (unsigned int j = 0; j < games[i].extras.size(); ++j) for (unsigned int j = 0; j < games[i].extras.size(); ++j)
{ {
std::cout << "\tid: " << games[i].extras[j]->id << std::endl std::cout << "\tid: " << games[i].extras[j].id << std::endl
<< "\tname: " << games[i].extras[j]->name << std::endl << "\tname: " << games[i].extras[j].name << std::endl
<< "\tpath: " << games[i].extras[j]->path << std::endl << "\tpath: " << games[i].extras[j].path << std::endl
<< "\tsize: " << games[i].extras[j]->size << std::endl << "\tsize: " << games[i].extras[j].size << std::endl
<< std::endl; << std::endl;
} }
} }
@ -282,13 +282,13 @@ void Downloader::repair()
{ {
for (unsigned int j = 0; j < games[i].installers.size(); ++j) 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 // Get XML data
std::string XML = ""; std::string XML = "";
if (!config.bNoRemoteXML) 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()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cout << gogAPI->getErrorMessage() << std::endl;
@ -300,7 +300,7 @@ void Downloader::repair()
// Repair // Repair
if (!XML.empty() || config.bNoRemoteXML) 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()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cout << gogAPI->getErrorMessage() << std::endl;
@ -319,9 +319,9 @@ void Downloader::repair()
{ {
for (unsigned int j = 0; j < games[i].extras.size(); ++j) 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()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cout << gogAPI->getErrorMessage() << std::endl;
@ -357,7 +357,7 @@ void Downloader::download()
// std::string directory = config.sDirectory + games[i].gamename + "/"; // 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" // 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 // Get base directory from filepath
boost::match_results<std::string::const_iterator> what; boost::match_results<std::string::const_iterator> what;
@ -373,7 +373,7 @@ void Downloader::download()
for (unsigned int j = 0; j < games[i].installers.size(); ++j) for (unsigned int j = 0; j < games[i].installers.size(); ++j)
{ {
// Get link // 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()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cout << gogAPI->getErrorMessage() << std::endl;
@ -381,7 +381,7 @@ void Downloader::download()
continue; 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 // Download
if (!url.empty()) if (!url.empty())
@ -398,7 +398,7 @@ void Downloader::download()
for (unsigned int j = 0; j < games[i].extras.size(); ++j) for (unsigned int j = 0; j < games[i].extras.size(); ++j)
{ {
// Get link // 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()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cout << gogAPI->getErrorMessage() << std::endl;
@ -406,13 +406,13 @@ void Downloader::download()
continue; 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 // Download
if (!url.empty()) if (!url.empty())
{ {
if (!games[i].extras[j]->name.empty()) if (!games[i].extras[j].name.empty())
std::cout << "Dowloading: " << games[i].extras[j]->name << std::endl; std::cout << "Dowloading: " << games[i].extras[j].name << std::endl;
std::cout << filepath << std::endl; std::cout << filepath << std::endl;
CURLcode result = downloadFile(url, filepath); CURLcode result = downloadFile(url, filepath);
std::cout << std::endl; std::cout << std::endl;