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 {
public:
std::vector<gameFile *> extras;
std::vector<gameFile *> installers;
std::vector<gameFile> extras;
std::vector<gameFile> installers;
std::string gamename;
std::string title;
std::string icon;

View File

@ -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";

View File

@ -321,7 +321,7 @@ 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,
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(),
@ -338,7 +338,7 @@ 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 */
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(),

View File

@ -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<std::string::const_iterator> 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;