2012-01-19 07:44:59 -06:00
|
|
|
#ifndef CLIENT_H
|
|
|
|
#define CLIENT_H
|
|
|
|
|
|
|
|
#include <queue>
|
2012-01-19 14:10:05 -06:00
|
|
|
#include <vector>
|
2012-06-10 13:52:24 -05:00
|
|
|
#include <list>
|
2012-01-31 12:49:14 -06:00
|
|
|
#include <fstream>
|
2012-01-19 14:10:05 -06:00
|
|
|
|
2012-01-19 11:59:00 -06:00
|
|
|
#include "Config.h"
|
2012-01-19 07:44:59 -06:00
|
|
|
#include "HTTP.h"
|
2012-02-11 10:08:59 -06:00
|
|
|
#include "preview/Comment.h"
|
2012-01-19 07:44:59 -06:00
|
|
|
#include "search/Thumbnail.h"
|
2012-06-07 08:23:26 -05:00
|
|
|
#include "client/SaveInfo.h"
|
|
|
|
#include "client/SaveFile.h"
|
2012-01-19 07:44:59 -06:00
|
|
|
#include "Singleton.h"
|
2012-01-25 11:21:55 -06:00
|
|
|
#include "User.h"
|
2012-01-19 07:44:59 -06:00
|
|
|
|
2012-01-31 12:49:14 -06:00
|
|
|
#include "cajun/reader.h"
|
|
|
|
#include "cajun/writer.h"
|
|
|
|
#include "cajun/elements.h"
|
|
|
|
|
2012-01-28 13:56:13 -06:00
|
|
|
enum LoginStatus {
|
2012-01-24 18:57:39 -06:00
|
|
|
LoginOkay, LoginError
|
2012-01-24 14:19:19 -06:00
|
|
|
};
|
|
|
|
|
2012-01-28 13:56:13 -06:00
|
|
|
enum RequestStatus {
|
|
|
|
RequestOkay, RequestFailure
|
|
|
|
};
|
|
|
|
|
2012-06-22 13:04:38 -05:00
|
|
|
class UpdateInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum BuildType { Stable, Beta, Snapshot };
|
|
|
|
std::string File;
|
|
|
|
int Major;
|
|
|
|
int Minor;
|
|
|
|
int Build;
|
2012-07-22 12:51:05 -05:00
|
|
|
int Time;
|
2012-06-22 13:04:38 -05:00
|
|
|
BuildType Type;
|
2012-07-22 12:51:05 -05:00
|
|
|
UpdateInfo() : Major(0), Minor(0), Build(0), Time(0), File(""), Type(Stable) {}
|
|
|
|
UpdateInfo(int major, int minor, int build, std::string file, BuildType type) : Major(major), Minor(minor), Build(build), Time(0), File(file), Type(type) {}
|
|
|
|
UpdateInfo(int time, std::string file, BuildType type) : Major(0), Minor(0), Build(0), Time(time), File(file), Type(type) {}
|
2012-06-22 13:04:38 -05:00
|
|
|
};
|
|
|
|
|
2012-07-31 13:49:08 -05:00
|
|
|
class ThumbnailListener;
|
2012-06-20 07:40:18 -05:00
|
|
|
class ClientListener;
|
2012-01-28 13:56:13 -06:00
|
|
|
class Client: public Singleton<Client> {
|
2012-01-19 07:44:59 -06:00
|
|
|
private:
|
2012-06-20 07:40:18 -05:00
|
|
|
void * versionCheckRequest;
|
|
|
|
bool updateAvailable;
|
2012-06-22 13:04:38 -05:00
|
|
|
UpdateInfo updateInfo;
|
2012-06-20 07:40:18 -05:00
|
|
|
|
|
|
|
|
2012-01-19 14:10:05 -06:00
|
|
|
std::string lastError;
|
2012-01-28 13:56:13 -06:00
|
|
|
|
2012-06-10 13:52:24 -05:00
|
|
|
list<string> stampIDs;
|
2012-04-02 11:01:28 -05:00
|
|
|
int lastStampTime;
|
|
|
|
int lastStampName;
|
|
|
|
|
2012-01-28 13:56:13 -06:00
|
|
|
//Auth session
|
|
|
|
User authUser;
|
|
|
|
|
|
|
|
//Thumbnail retreival
|
2012-01-19 07:44:59 -06:00
|
|
|
int thumbnailCacheNextID;
|
2012-01-19 11:59:00 -06:00
|
|
|
Thumbnail * thumbnailCache[THUMB_CACHE_SIZE];
|
|
|
|
void * activeThumbRequests[IMGCONNS];
|
|
|
|
int activeThumbRequestTimes[IMGCONNS];
|
|
|
|
int activeThumbRequestCompleteTimes[IMGCONNS];
|
|
|
|
std::string activeThumbRequestIDs[IMGCONNS];
|
2012-04-02 11:01:28 -05:00
|
|
|
void updateStamps();
|
2012-06-21 19:04:55 -05:00
|
|
|
static vector<std::string> explodePropertyString(std::string property);
|
2012-06-20 07:40:18 -05:00
|
|
|
void notifyUpdateAvailable();
|
2012-07-17 13:14:05 -05:00
|
|
|
void notifyAuthUserChanged();
|
2012-06-20 07:40:18 -05:00
|
|
|
|
2012-01-31 12:49:14 -06:00
|
|
|
//Config file handle
|
|
|
|
json::Object configDocument;
|
2012-06-21 19:04:55 -05:00
|
|
|
public:
|
2012-07-31 13:49:08 -05:00
|
|
|
|
2012-06-21 19:04:55 -05:00
|
|
|
vector<ClientListener*> listeners;
|
2012-01-31 12:49:14 -06:00
|
|
|
|
2012-06-22 13:04:38 -05:00
|
|
|
UpdateInfo GetUpdateInfo();
|
|
|
|
|
2012-01-19 07:44:59 -06:00
|
|
|
Client();
|
|
|
|
~Client();
|
2012-01-28 13:56:13 -06:00
|
|
|
|
2012-07-27 14:06:17 -05:00
|
|
|
std::vector<std::string> DirectorySearch(std::string directory, std::string search, std::vector<std::string> extensions);
|
|
|
|
std::vector<std::string> DirectorySearch(std::string directory, std::string search, std::string extension);
|
|
|
|
|
|
|
|
std::vector<unsigned char> ReadFile(std::string filename);
|
|
|
|
|
2012-08-08 12:34:37 -05:00
|
|
|
void Initialise(std::string proxyString);
|
|
|
|
void SetProxy(std::string proxy);
|
|
|
|
|
2012-08-01 16:29:22 -05:00
|
|
|
void WriteFile(std::vector<unsigned char> fileData, std::string filename);
|
|
|
|
void WriteFile(std::vector<char> fileData, std::string filename);
|
|
|
|
bool FileExists(std::string filename);
|
|
|
|
|
2012-06-20 07:40:18 -05:00
|
|
|
void AddListener(ClientListener * listener);
|
2012-07-17 13:14:05 -05:00
|
|
|
void RemoveListener(ClientListener * listener);
|
2012-06-20 07:40:18 -05:00
|
|
|
|
2012-01-28 13:56:13 -06:00
|
|
|
RequestStatus ExecVote(int saveID, int direction);
|
2012-08-01 16:29:22 -05:00
|
|
|
RequestStatus UploadSave(SaveInfo & save);
|
2012-01-28 13:56:13 -06:00
|
|
|
|
2012-06-07 08:23:26 -05:00
|
|
|
SaveFile * GetStamp(string stampID);
|
2012-04-02 11:01:28 -05:00
|
|
|
void DeleteStamp(string stampID);
|
2012-06-07 08:23:26 -05:00
|
|
|
string AddStamp(GameSave * saveData);
|
2012-06-10 13:52:24 -05:00
|
|
|
vector<string> GetStamps(int start, int count);
|
|
|
|
int GetStampsCount();
|
|
|
|
SaveFile * GetFirstStamp();
|
2012-04-02 11:01:28 -05:00
|
|
|
|
2012-07-18 07:07:33 -05:00
|
|
|
RequestStatus AddComment(int saveID, std::string comment);
|
|
|
|
|
2012-01-25 19:13:33 -06:00
|
|
|
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
2012-08-08 15:32:10 -05:00
|
|
|
std::vector<unsigned char> GetSaveData(int saveID, int saveDate);
|
2012-01-25 11:21:55 -06:00
|
|
|
LoginStatus Login(string username, string password, User & user);
|
2012-01-19 07:44:59 -06:00
|
|
|
void ClearThumbnailRequests();
|
2012-06-07 08:23:26 -05:00
|
|
|
std::vector<SaveInfo*> * SearchSaves(int start, int count, string query, string sort, string category, int & resultCount);
|
2012-08-04 14:55:59 -05:00
|
|
|
std::vector<std::pair<std::string, int> > * GetTags(int start, int count, string query, int & resultCount);
|
2012-05-31 04:24:44 -05:00
|
|
|
std::vector<SaveComment*> * GetComments(int saveID, int start, int count);
|
2012-01-23 16:53:57 -06:00
|
|
|
Thumbnail * GetPreview(int saveID, int saveDate);
|
2012-01-19 07:44:59 -06:00
|
|
|
Thumbnail * GetThumbnail(int saveID, int saveDate);
|
2012-06-07 08:23:26 -05:00
|
|
|
SaveInfo * GetSave(int saveID, int saveDate);
|
2012-04-06 18:45:24 -05:00
|
|
|
RequestStatus DeleteSave(int saveID);
|
2012-04-14 13:00:24 -05:00
|
|
|
RequestStatus ReportSave(int saveID, std::string message);
|
|
|
|
RequestStatus UnpublishSave(int saveID);
|
|
|
|
RequestStatus FavouriteSave(int saveID, bool favourite);
|
2012-01-28 13:56:13 -06:00
|
|
|
void SetAuthUser(User user);
|
|
|
|
User GetAuthUser();
|
2012-04-02 11:01:28 -05:00
|
|
|
std::vector<string> * RemoveTag(int saveID, string tag); //TODO RequestStatus
|
2012-03-22 17:12:16 -05:00
|
|
|
std::vector<string> * AddTag(int saveID, string tag);
|
2012-01-28 13:56:13 -06:00
|
|
|
std::string GetLastError() {
|
|
|
|
return lastError;
|
|
|
|
}
|
2012-06-20 07:40:18 -05:00
|
|
|
void Tick();
|
2012-06-21 19:04:55 -05:00
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
std::string GetPrefString(std::string property, std::string defaultValue);
|
|
|
|
double GetPrefNumber(std::string property, double defaultValue);
|
2012-07-24 07:03:28 -05:00
|
|
|
int GetPrefInteger(std::string property, int defaultValue);
|
2012-08-05 12:35:12 -05:00
|
|
|
unsigned int GetPrefUInteger(std::string property, unsigned int defaultValue);
|
2012-06-21 19:04:55 -05:00
|
|
|
vector<string> GetPrefStringArray(std::string property);
|
|
|
|
vector<double> GetPrefNumberArray(std::string property);
|
2012-07-24 07:03:28 -05:00
|
|
|
vector<int> GetPrefIntegerArray(std::string property);
|
2012-08-05 12:35:12 -05:00
|
|
|
vector<unsigned int> GetPrefUIntegerArray(std::string property);
|
2012-06-21 19:04:55 -05:00
|
|
|
vector<bool> GetPrefBoolArray(std::string property);
|
|
|
|
bool GetPrefBool(std::string property, bool defaultValue);
|
|
|
|
|
|
|
|
void SetPref(std::string property, std::string value);
|
|
|
|
void SetPref(std::string property, double value);
|
2012-07-24 07:03:28 -05:00
|
|
|
void SetPref(std::string property, int value);
|
2012-08-05 12:35:12 -05:00
|
|
|
void SetPref(std::string property, unsigned int value);
|
2012-06-21 19:04:55 -05:00
|
|
|
void SetPref(std::string property, vector<string> value);
|
|
|
|
void SetPref(std::string property, vector<double> value);
|
2012-07-24 07:03:28 -05:00
|
|
|
void SetPref(std::string property, vector<int> value);
|
2012-08-05 12:35:12 -05:00
|
|
|
void SetPref(std::string property, vector<unsigned int> value);
|
2012-06-21 19:04:55 -05:00
|
|
|
void SetPref(std::string property, vector<bool> value);
|
|
|
|
void SetPref(std::string property, bool value);
|
|
|
|
|
|
|
|
json::UnknownElement GetPref(std::string property);
|
|
|
|
void setPrefR(std::deque<string> tokens, json::UnknownElement & element, json::UnknownElement & value);
|
|
|
|
void SetPref(std::string property, json::UnknownElement & value);
|
2012-01-19 07:44:59 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CLIENT_H
|