From 6d27acd0a57bc6a228f1b6dd2ce451c02cc7419c Mon Sep 17 00:00:00 2001 From: aunsane <aunsane@gmail.com> Date: Sat, 9 Dec 2017 23:39:16 +0300 Subject: CloudFile: realized MS_DROPBOX_UPLOAD --- plugins/CloudFile/src/Services/dropbox_service.cpp | 42 +++++++++++++++++++++- plugins/CloudFile/src/Services/dropbox_service.h | 2 ++ 2 files changed, 43 insertions(+), 1 deletion(-) (limited to 'plugins/CloudFile/src/Services') diff --git a/plugins/CloudFile/src/Services/dropbox_service.cpp b/plugins/CloudFile/src/Services/dropbox_service.cpp index f1157a52b2..51e3c9a3c9 100644 --- a/plugins/CloudFile/src/Services/dropbox_service.cpp +++ b/plugins/CloudFile/src/Services/dropbox_service.cpp @@ -4,6 +4,7 @@ CDropboxService::CDropboxService(HNETLIBUSER hConnection) : CCloudService(hConnection) { + CreateServiceFunctionObj(MS_DROPBOX_UPLOAD, &CDropboxService::UploadToDropbox, this); } const char* CDropboxService::GetModule() const @@ -234,7 +235,14 @@ UINT CDropboxService::Upload(FileTransferParam *ftp) mir_ptr<char>chunk((char*)mir_calloc(chunkSize)); char path[MAX_PATH]; - PreparePath(fileName, path); + const wchar_t *serverFolder = ftp->GetServerFolder(); + if (serverFolder) { + char serverPath[MAX_PATH] = { 0 }; + mir_snprintf(serverPath, "%s\\%s", T2Utf(serverFolder), fileName); + PreparePath(serverPath, path); + } + else + PreparePath(fileName, path); if (chunkSize == fileSize) { @@ -293,3 +301,35 @@ UINT CDropboxService::Upload(FileTransferParam *ftp) ftp->SetStatus(ACKRESULT_SUCCESS); return ACKRESULT_SUCCESS; } + +INT_PTR CDropboxService::UploadToDropbox(void *obj, WPARAM wParam, LPARAM lParam) +{ + CDropboxService *self = (CDropboxService*)obj; + DropboxUploadInfo *uploadInfo = (DropboxUploadInfo*)lParam; + + FileTransferParam *ftp = new FileTransferParam(0); + ftp->SetWorkingDirectory(uploadInfo->localPath); + ftp->SetServerFolder(uploadInfo->serverFolder); + + if (PathIsDirectory(uploadInfo->localPath)) + { + // temporary unsupported + Transfers.remove(ftp); + delete ftp; + + return ACKRESULT_FAILED; + } + else + ftp->AddFile(uploadInfo->localPath); + + int res = self->Upload(ftp); + if (res == ACKRESULT_SUCCESS && wParam) { + char **data = (char**)wParam; + *data = mir_utf8encodeW(ftp->GetData()); + } + + Transfers.remove(ftp); + delete ftp; + + return res; +} diff --git a/plugins/CloudFile/src/Services/dropbox_service.h b/plugins/CloudFile/src/Services/dropbox_service.h index 90dc11d259..1f123d2d5c 100644 --- a/plugins/CloudFile/src/Services/dropbox_service.h +++ b/plugins/CloudFile/src/Services/dropbox_service.h @@ -28,6 +28,8 @@ public: void Logout(); UINT Upload(FileTransferParam *ftp); + + static INT_PTR UploadToDropbox(void*, WPARAM wParam, LPARAM lParam); }; #endif //_CLOUDSERVICE_DROPBOX_H_ \ No newline at end of file -- cgit v1.2.3