2013-03-15 21:46:16 +01:00
|
|
|
/* This program is free software. It comes without any warranty, to
|
|
|
|
* the extent permitted by applicable law. You can redistribute it
|
|
|
|
* and/or modify it under the terms of the Do What The Fuck You Want
|
|
|
|
* To Public License, Version 2, as published by Sam Hocevar. See
|
2013-03-24 22:56:57 +01:00
|
|
|
* http://www.wtfpl.net/ for more details. */
|
2013-03-15 21:46:16 +01:00
|
|
|
|
|
|
|
#ifndef DOWNLOADER_H
|
|
|
|
#define DOWNLOADER_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "api.h"
|
|
|
|
#include "progressbar.h"
|
|
|
|
#include <curl/curl.h>
|
|
|
|
#include <ctime>
|
2014-02-13 10:16:31 +01:00
|
|
|
#include <fstream>
|
2013-03-15 21:46:16 +01:00
|
|
|
|
|
|
|
class Timer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Timer() { this->reset(); };
|
|
|
|
void reset() { gettimeofday(&(this->last_update), NULL); };
|
|
|
|
double getTimeBetweenUpdates()
|
|
|
|
{ // Returns time elapsed between updates in milliseconds
|
|
|
|
struct timeval time_now;
|
|
|
|
gettimeofday(&time_now, NULL);
|
|
|
|
double time_between = ( (time_now.tv_sec+(time_now.tv_usec/1000000.0))*1000.0 - (this->last_update.tv_sec+(this->last_update.tv_usec/1000000.0))*1000.0 );
|
|
|
|
return time_between;
|
|
|
|
};
|
|
|
|
~Timer() {};
|
|
|
|
private:
|
|
|
|
struct timeval last_update;
|
|
|
|
};
|
|
|
|
|
2014-03-29 00:51:39 +01:00
|
|
|
class gameItem {
|
|
|
|
public:
|
|
|
|
std::string name;
|
|
|
|
std::string id;
|
|
|
|
std::vector<std::string> dlcnames;
|
|
|
|
};
|
|
|
|
|
2013-03-15 21:46:16 +01:00
|
|
|
class Downloader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Downloader(Config &conf);
|
|
|
|
virtual ~Downloader();
|
|
|
|
int init();
|
2014-07-07 14:57:07 +02:00
|
|
|
int login();
|
2013-03-15 21:46:16 +01:00
|
|
|
void listGames();
|
|
|
|
void updateCheck();
|
|
|
|
void repair();
|
|
|
|
void download();
|
2013-10-14 21:31:12 +02:00
|
|
|
void checkOrphans();
|
2013-11-14 14:40:59 +01:00
|
|
|
void checkStatus();
|
2013-03-15 21:46:16 +01:00
|
|
|
CURL* curlhandle;
|
|
|
|
Timer timer;
|
|
|
|
Config config;
|
|
|
|
ProgressBar* progressbar;
|
|
|
|
protected:
|
|
|
|
private:
|
2014-02-26 14:04:16 +01:00
|
|
|
CURLcode downloadFile(const std::string& url, const std::string& filepath, const std::string& xml_data = std::string(), const std::string& gamename = std::string());
|
|
|
|
int repairFile(const std::string& url, const std::string& filepath, const std::string& xml_data = std::string(), const std::string& gamename = std::string());
|
2013-04-08 12:43:11 +02:00
|
|
|
int downloadCovers(const std::string& gamename, const std::string& directory, const std::string& cover_xml_data);
|
2013-03-15 21:46:16 +01:00
|
|
|
int getGameDetails();
|
|
|
|
void getGameList();
|
|
|
|
size_t getResumePosition();
|
|
|
|
CURLcode beginDownload();
|
|
|
|
std::string getResponse(const std::string& url);
|
2014-02-26 14:04:16 +01:00
|
|
|
std::string getLocalFileHash(const std::string& filepath, const std::string& gamename = std::string());
|
2013-11-14 14:40:59 +01:00
|
|
|
std::string getRemoteFileHash(const std::string& gamename, const std::string& id);
|
2013-03-15 21:46:16 +01:00
|
|
|
|
|
|
|
int HTTP_Login(const std::string& email, const std::string& password);
|
2014-03-29 00:51:39 +01:00
|
|
|
std::vector<gameItem> getGames();
|
|
|
|
std::vector<gameItem> getFreeGames();
|
2013-10-13 10:54:35 +02:00
|
|
|
std::vector<gameFile> getExtras(const std::string& gamename, const std::string& gameid);
|
2013-03-15 21:46:16 +01:00
|
|
|
|
|
|
|
static int progressCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
|
|
|
|
static size_t writeMemoryCallback(char *ptr, size_t size, size_t nmemb, void *userp);
|
|
|
|
static size_t writeData(void *ptr, size_t size, size_t nmemb, FILE *stream);
|
|
|
|
static size_t readData(void *ptr, size_t size, size_t nmemb, FILE *stream);
|
|
|
|
|
|
|
|
|
|
|
|
API *gogAPI;
|
2014-03-29 00:51:39 +01:00
|
|
|
std::vector<gameItem> gameItems;
|
2013-03-15 21:46:16 +01:00
|
|
|
std::vector<gameDetails> games;
|
|
|
|
std::string coverXML;
|
|
|
|
|
|
|
|
size_t resume_position;
|
2014-02-26 13:59:23 +01:00
|
|
|
int retries;
|
2014-02-13 10:16:31 +01:00
|
|
|
std::ofstream report_ofs;
|
2013-03-15 21:46:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DOWNLOADER_H
|