diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-01 21:29:22 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-01 21:29:22 (GMT) |
| commit | cbefea85d717bd599fa0559f091b051e904d9e2f (patch) | |
| tree | e11849927aa88b270470c55d8b0fc052d34851e4 /src/client/Client.cpp | |
| parent | 29ac6380ba649e30dc29771b2833a86f20c9dbfe (diff) | |
| download | powder-cbefea85d717bd599fa0559f091b051e904d9e2f.zip powder-cbefea85d717bd599fa0559f091b051e904d9e2f.tar.gz | |
Local Saving, Server Saving rewrite
Diffstat (limited to 'src/client/Client.cpp')
| -rw-r--r-- | src/client/Client.cpp | 71 |
1 files changed, 65 insertions, 6 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 7f26a4c..29f6a94 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -198,6 +198,64 @@ std::vector<std::string> Client::DirectorySearch(std::string directory, std::str return searchResults; } +void Client::WriteFile(std::vector<unsigned char> fileData, std::string filename) +{ + try + { + std::ofstream fileStream; + fileStream.open(string(filename).c_str(), ios::binary); + if(fileStream.is_open()) + { + fileStream.write((char*)&fileData[0], fileData.size()); + fileStream.close(); + } + } + catch (std::exception & e) + { + std::cerr << "WriteFile:" << e.what() << std::endl; + throw; + } +} + +bool Client::FileExists(std::string filename) +{ + bool exists = false; + try + { + std::ofstream fileStream; + fileStream.open(string(filename).c_str(), ios::binary); + if(fileStream.is_open()) + { + exists = true; + fileStream.close(); + } + } + catch (std::exception & e) + { + exists = false; + } + return exists; +} + +void Client::WriteFile(std::vector<char> fileData, std::string filename) +{ + try + { + std::ofstream fileStream; + fileStream.open(string(filename).c_str(), ios::binary); + if(fileStream.is_open()) + { + fileStream.write(&fileData[0], fileData.size()); + fileStream.close(); + } + } + catch (std::exception & e) + { + std::cerr << "WriteFile:" << e.what() << std::endl; + throw; + } +} + std::vector<unsigned char> Client::ReadFile(std::string filename) { try @@ -400,7 +458,7 @@ User Client::GetAuthUser() return authUser; } -RequestStatus Client::UploadSave(SaveInfo * save) +RequestStatus Client::UploadSave(SaveInfo & save) { lastError = ""; int gameDataLength; @@ -412,13 +470,14 @@ RequestStatus Client::UploadSave(SaveInfo * save) userIDStream << authUser.ID; if(authUser.ID) { - if(!save->GetGameSave()) + if(!save.GetGameSave()) { lastError = "Empty game save"; return RequestFailure; } + save.SetID(0); - gameData = save->GetGameSave()->Serialise(gameDataLength); + gameData = save.GetGameSave()->Serialise(gameDataLength); if(!gameData) { @@ -427,8 +486,8 @@ RequestStatus Client::UploadSave(SaveInfo * save) } char * postNames[] = { "Name", "Description", "Data:save.bin", "Publish", NULL }; - char * postDatas[] = { (char *)(save->name.c_str()), (char *)(save->Description.c_str()), gameData, (char *)(save->Published?"Public":"Private") }; - int postLengths[] = { save->name.length(), save->Description.length(), gameDataLength, save->Published?6:7 }; + char * postDatas[] = { (char *)(save.GetName().c_str()), (char *)(save.GetDescription().c_str()), gameData, (char *)(save.GetPublished()?"Public":"Private") }; + int postLengths[] = { save.GetName().length(), save.GetDescription().length(), gameDataLength, save.GetPublished()?6:7 }; //std::cout << postNames[0] << " " << postDatas[0] << " " << postLengths[0] << std::endl; data = http_multipart_post("http://" SERVER "/Save.api", postNames, postDatas, postLengths, (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength); } @@ -458,7 +517,7 @@ RequestStatus Client::UploadSave(SaveInfo * save) } else { - save->id = tempID; + save.SetID(tempID); } } free(data); |
