summaryrefslogtreecommitdiff
path: root/src/client/Client.cpp
diff options
context:
space:
mode:
authorSimon 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)
commitefddc12e5d2aadc5eee1927245ad38b9dee89aed (patch)
treecf7ad38119f0734609944158e33bbb944925c777 /src/client/Client.cpp
parent289556ac7078963b6af361f5812dd62e6712359f (diff)
downloadpowder-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/Client.cpp')
-rw-r--r--src/client/Client.cpp112
1 files changed, 112 insertions, 0 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 = "";