diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-04-02 16:01:28 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-04-02 16:01:28 (GMT) |
| commit | efddc12e5d2aadc5eee1927245ad38b9dee89aed (patch) | |
| tree | cf7ad38119f0734609944158e33bbb944925c777 /src/client | |
| parent | 289556ac7078963b6af361f5812dd62e6712359f (diff) | |
| download | powder-efddc12e5d2aadc5eee1927245ad38b9dee89aed.zip powder-efddc12e5d2aadc5eee1927245ad38b9dee89aed.tar.gz | |
Stamps browser, placement + clipboard sampling and placement - No clipboard or stamp thumbnail generation, needs thumbnail generator from SaveLoader
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/Client.cpp | 112 | ||||
| -rw-r--r-- | src/client/Client.h | 12 |
2 files changed, 123 insertions, 1 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp index e85d3e6..b472518 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -3,8 +3,16 @@ #include <sstream> #include <string> #include <vector> +#include <iomanip> #include <time.h> +#ifdef WIN32 +#include <direct.h> +#else +#include <sys/stat.h> +#include <unistd.h> +#endif + #include "Config.h" #include "Client.h" #include "MD5.h" @@ -76,6 +84,21 @@ Client::Client(): { http_init(NULL); } + + //Read stamps library + std::ifstream stampsLib; + stampsLib.open(STAMPS_DIR PATH_SEP "stamps.def", ios::binary); + while(true) + { + char data[11]; + memset(data, 0, 11); + if(stampsLib.readsome(data, 10)!=10) + break; + if(!data[0]) + break; + stampIDs.push_back(data); + } + stampsLib.close(); } Client::~Client() @@ -169,6 +192,95 @@ RequestStatus Client::UploadSave(Save * save) return RequestFailure; } +Save * Client::GetStamp(string stampID) +{ + std::ifstream stampFile; + stampFile.open(string(STAMPS_DIR PATH_SEP + stampID + ".stm").c_str(), ios::binary); + if(stampFile.is_open()) + { + stampFile.seekg(0, ios::end); + size_t fileSize = stampFile.tellg(); + stampFile.seekg(0); + + unsigned char * tempData = (unsigned char *)malloc(fileSize); + stampFile.read((char *)tempData, fileSize); + stampFile.close(); + + + Save * tempSave = new Save(0, 0, 0, 0, "", ""); + tempSave->SetData(tempData, fileSize); + return tempSave; + } + else + { + return NULL; + } +} + +void Client::DeleteStamp(string stampID) +{ + return; +} + +string Client::AddStamp(Save * saveData) +{ + unsigned t=(unsigned)time(NULL); + if (lastStampTime!=t) + { + lastStampTime=t; + lastStampName=0; + } + else + lastStampName++; + std::stringstream saveID; + //sprintf(saveID, "%08x%02x", lastStampTime, lastStampName); + saveID + << std::setw(8) << std::setfill('0') << std::hex << lastStampTime + << std::setw(2) << std::setfill('0') << std::hex << lastStampName; + +#ifdef WIN32 + _mkdir(STAMPS_DIR); +#else + mkdir(STAMPS_DIR, 0755); +#endif + + std::ofstream stampStream; + stampStream.open(string(STAMPS_DIR PATH_SEP + saveID.str()+".stm").c_str(), ios::binary); + stampStream.write((const char *)saveData->data, saveData->dataLength); + stampStream.close(); + + stampIDs.push_back(saveID.str()); + + updateStamps(); + + return saveID.str(); +} + +void Client::updateStamps() +{ + +#ifdef WIN32 + _mkdir(STAMPS_DIR); +#else + mkdir(STAMPS_DIR, 0755); +#endif + + std::ofstream stampsStream; + stampsStream.open(string(STAMPS_DIR PATH_SEP "stamps.def").c_str(), ios::binary); + for(int i = 0; i < stampIDs.size(); i++) + { + stampsStream.write(stampIDs[i].c_str(), 10); + } + stampsStream.write("\0", 1); + stampsStream.close(); + return; +} + +vector<string> Client::GetStamps() +{ + return stampIDs; +} + RequestStatus Client::ExecVote(int saveID, int direction) { lastError = ""; diff --git a/src/client/Client.h b/src/client/Client.h index 55d813f..c8f5764 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -29,6 +29,10 @@ class Client: public Singleton<Client> { private: std::string lastError; + vector<string> stampIDs; + int lastStampTime; + int lastStampName; + //Auth session User authUser; @@ -39,6 +43,7 @@ private: int activeThumbRequestTimes[IMGCONNS]; int activeThumbRequestCompleteTimes[IMGCONNS]; std::string activeThumbRequestIDs[IMGCONNS]; + void updateStamps(); public: //Config file handle json::Object configDocument; @@ -49,6 +54,11 @@ public: RequestStatus ExecVote(int saveID, int direction); RequestStatus UploadSave(Save * save); + Save * GetStamp(string stampID); + void DeleteStamp(string stampID); + string AddStamp(Save * saveData); + vector<string> GetStamps(); + unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength); LoginStatus Login(string username, string password, User & user); void ClearThumbnailRequests(); @@ -59,7 +69,7 @@ public: Save * GetSave(int saveID, int saveDate); void SetAuthUser(User user); User GetAuthUser(); - std::vector<string> * RemoveTag(int saveID, string tag); + std::vector<string> * RemoveTag(int saveID, string tag); //TODO RequestStatus std::vector<string> * AddTag(int saveID, string tag); std::string GetLastError() { return lastError; |
