diff options
author | aunsane <aunsane@gmail.com> | 2017-05-07 02:25:29 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2017-05-07 02:25:29 +0300 |
commit | ff6a107e5f566da2644fbfe36455467beafaeb1e (patch) | |
tree | 3d5b96794ee835c8686a74da6c418c440c91c403 /plugins/CloudFile/src/Services/dropbox_service.cpp | |
parent | 453b3de91c372ee7b2661771aead6675e12fe98f (diff) |
CloudFile:
- reworked options to dupport default service
- added options to select conflict behavior
- multiple fix and refactoring
- version bump
Diffstat (limited to 'plugins/CloudFile/src/Services/dropbox_service.cpp')
-rw-r--r-- | plugins/CloudFile/src/Services/dropbox_service.cpp | 59 |
1 files changed, 27 insertions, 32 deletions
diff --git a/plugins/CloudFile/src/Services/dropbox_service.cpp b/plugins/CloudFile/src/Services/dropbox_service.cpp index 409494e9d3..fdd904e5e3 100644 --- a/plugins/CloudFile/src/Services/dropbox_service.cpp +++ b/plugins/CloudFile/src/Services/dropbox_service.cpp @@ -119,10 +119,10 @@ char* CDropboxService::UploadFile(const char *data, size_t size, char *path) return path; } -void CDropboxService::StartUploadSession(const char *data, size_t size, char *sessionId) +void CDropboxService::CreateUploadSession(const char *chunk, size_t chunkSize, char *sessionId) { ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret")); - DropboxAPI::StartUploadSessionRequest request(token, data, size); + DropboxAPI::CreateUploadSessionRequest request(token, chunk, chunkSize); NLHR_PTR response(request.Send(hConnection)); JSONNode root = GetJsonResponse(response); @@ -130,19 +130,19 @@ void CDropboxService::StartUploadSession(const char *data, size_t size, char *se mir_strcpy(sessionId, node.as_string().c_str()); } -void CDropboxService::AppendToUploadSession(const char *data, size_t size, const char *sessionId, size_t offset) +void CDropboxService::UploadFileChunk(const char *chunk, size_t chunkSize, const char *sessionId, size_t offset) { ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret")); - DropboxAPI::AppendToUploadSessionRequest request(token, sessionId, offset, data, size); + DropboxAPI::UploadFileChunkRequest request(token, sessionId, offset, chunk, chunkSize); NLHR_PTR response(request.Send(hConnection)); GetJsonResponse(response); } -char* CDropboxService::FinishUploadSession(const char *data, size_t size, const char *sessionId, size_t offset, char *path) +char* CDropboxService::CommitUploadSession(const char *data, size_t size, const char *sessionId, size_t offset, char *path) { ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret")); - DropboxAPI::FinishUploadSessionRequest request(token, sessionId, offset, path, data, size); + DropboxAPI::CommitUploadSessionRequest request(token, sessionId, offset, path, data, size); NLHR_PTR response(request.Send(hConnection)); JSONNode root = GetJsonResponse(response); @@ -214,62 +214,57 @@ UINT CDropboxService::Upload(FileTransferParam *ftp) Login(); try { - const wchar_t *folderName = ftp->GetFolderName(); - if (folderName) { - char path[MAX_PATH], url[MAX_PATH]; + if (ftp->IsFolder()) { + T2Utf folderName(ftp->GetFolderName()); + + char path[MAX_PATH]; PreparePath(folderName, path); CreateFolder(path); - CreateSharedLink(path, url); - ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(url))); + + char link[MAX_PATH]; + CreateSharedLink(path, link); + ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link))); } ftp->FirstFile(); do { - const wchar_t *fileName = ftp->GetCurrentRelativeFilePath(); + T2Utf fileName(ftp->GetCurrentRelativeFilePath()); uint64_t fileSize = ftp->GetCurrentFileSize(); int chunkSize = ftp->GetCurrentFileChunkSize(); mir_ptr<char>data((char*)mir_calloc(chunkSize)); - size_t size = ftp->ReadCurrentFile(data, chunkSize); - size_t offset = 0; char sessionId[64]; - StartUploadSession(data, size, sessionId); + size_t size = ftp->ReadCurrentFile(data, chunkSize); + CreateUploadSession(data, size, sessionId); - offset += size; ftp->Progress(size); - for (size_t chunk = 0; chunk < (fileSize / chunkSize) - 1; chunk++) + size_t offset = size; + size_t chunkCount = ceil(fileSize / chunkSize) - 2; + while (chunkCount--) { ftp->CheckCurrentFile(); size = ftp->ReadCurrentFile(data, chunkSize); - AppendToUploadSession(data, size, sessionId, offset); + UploadFileChunk(data, size, sessionId, offset); offset += size; ftp->Progress(size); } - if (offset < fileSize) - size = ftp->ReadCurrentFile(data, fileSize - offset); - else - size = 0; + size = offset < fileSize + ? ftp->ReadCurrentFile(data, fileSize - offset) + : 0; char path[MAX_PATH]; - const wchar_t *serverFolder = ftp->GetServerFolder(); - if (serverFolder) { - wchar_t serverPath[MAX_PATH] = { 0 }; - mir_snwprintf(serverPath, L"%s\\%s", serverFolder, fileName); - PreparePath(serverPath, path); - } - else - PreparePath(fileName, path); - FinishUploadSession(data, size, sessionId, offset, path); + PreparePath(fileName, path); + CommitUploadSession(data, size, sessionId, offset, path); ftp->Progress(size); - if (!wcschr(fileName, L'\\')) { + if (!ftp->IsFolder()) { char url[MAX_PATH]; CreateSharedLink(path, url); ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(url))); |