diff options
author | aunsane <aunsane@gmail.com> | 2017-12-09 23:39:16 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2017-12-09 23:39:16 +0300 |
commit | 6d27acd0a57bc6a228f1b6dd2ce451c02cc7419c (patch) | |
tree | a82b4c833eb6cec7ec81942d611ae708c0da0702 /plugins | |
parent | 15d04b366b37563254f914a41db97646730514b9 (diff) |
CloudFile: realized MS_DROPBOX_UPLOAD
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/CloudFile/src/Services/dropbox_service.cpp | 42 | ||||
-rw-r--r-- | plugins/CloudFile/src/Services/dropbox_service.h | 2 | ||||
-rw-r--r-- | plugins/CloudFile/src/file_transfer.h | 27 | ||||
-rw-r--r-- | plugins/CloudFile/src/version.h | 2 | ||||
-rw-r--r-- | plugins/ExternalAPI/m_dropbox.h | 6 |
5 files changed, 70 insertions, 9 deletions
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 diff --git a/plugins/CloudFile/src/file_transfer.h b/plugins/CloudFile/src/file_transfer.h index cdf4475aeb..cbe928eda9 100644 --- a/plugins/CloudFile/src/file_transfer.h +++ b/plugins/CloudFile/src/file_transfer.h @@ -12,6 +12,8 @@ private: bool isTerminated; + CMStringW serverFolder; + const wchar_t* folderName; int relativePathStart; @@ -85,6 +87,19 @@ public: isTerminated = true; } + void SetServerFolder(const wchar_t *path) + { + if (path) + serverFolder = path; + } + + const wchar_t* GetServerFolder() const + { + if (serverFolder.IsEmpty()) + return NULL; + return serverFolder; + } + void SetWorkingDirectory(const wchar_t *path) { relativePathStart = wcsrchr(path, '\\') - path + 1; @@ -193,7 +208,8 @@ public: { pfts.currentFileProgress += count; pfts.totalProgress += count; - ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)id, (LPARAM)&pfts); + if (pfts.hContact) + ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)id, (LPARAM)&pfts); } void FirstFile() @@ -203,7 +219,8 @@ public: pfts.currentFileNumber = 0; pfts.currentFileProgress = 0; pfts.tszCurrentFile = wcsrchr(pfts.ptszFiles[pfts.currentFileNumber], '\\') + 1; - ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)id, (LPARAM)&pfts); + if (pfts.hContact) + ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)id, (LPARAM)&pfts); OpenCurrentFile(); CheckCurrentFile(); @@ -218,7 +235,8 @@ public: pfts.currentFileProgress = 0; pfts.tszCurrentFile = wcsrchr(pfts.ptszFiles[pfts.currentFileNumber], '\\') + 1; - ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, (HANDLE)id, 0); + if (pfts.hContact) + ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, (HANDLE)id, 0); OpenCurrentFile(); CheckCurrentFile(); @@ -228,7 +246,8 @@ public: void SetStatus(int status, LPARAM param = 0) { - ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, status, (HANDLE)id, param); + if (pfts.hContact) + ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, status, (HANDLE)id, param); } }; diff --git a/plugins/CloudFile/src/version.h b/plugins/CloudFile/src/version.h index 7a5ce87b09..23b1f2094f 100644 --- a/plugins/CloudFile/src/version.h +++ b/plugins/CloudFile/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 11 #define __RELEASE_NUM 0 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include <stdver.h> diff --git a/plugins/ExternalAPI/m_dropbox.h b/plugins/ExternalAPI/m_dropbox.h index 656c95d010..e0061a74f0 100644 --- a/plugins/ExternalAPI/m_dropbox.h +++ b/plugins/ExternalAPI/m_dropbox.h @@ -5,8 +5,8 @@ struct DropboxUploadInfo
{
- const TCHAR *localPath; // local path
- const TCHAR *serverFolder; // server folder in witch file will be placed (can be NULL)
+ const wchar_t *localPath; // local path
+ const wchar_t *serverFolder; // server folder in witch file will be placed (can be NULL)
};
// upload file on Dropbox
@@ -19,7 +19,7 @@ struct DropboxUploadInfo // upload file on Dropbox
// wParam = 0
// lParam = (LPARAM)(const DropboxUploadInfo*)
-// returns file htansfer handle or NULL on failure
+// returns file transfer handle or NULL on failure
// returns immediately, without waiting for the send
// note, that you can track progress by using ME_PROTO_ACK
#define MS_DROPBOX_UPLOADASYNC "Dropbox/UploadAsync"
|