diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-05-23 20:51:11 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-05-23 20:51:11 +0000 |
commit | 2e5c904f370d48a8e780ce64db2633d54ec0f5cd (patch) | |
tree | 9d18c3dd5cb067588c6a8e345f96230e323703c8 /plugins/Dropbox/src | |
parent | 8e146597bbd27b72a42a3a197c1db17153e2e0b3 (diff) |
Dropbox:
- fixed crash on file upload
- added upload icon (thx dracosha)
- resource fix
- version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@13797 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dropbox/src')
-rw-r--r-- | plugins/Dropbox/src/api/upload.h | 15 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox.h | 6 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_events.cpp | 4 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_icons.cpp | 9 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_menus.cpp | 4 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_transfers.cpp | 29 | ||||
-rw-r--r-- | plugins/Dropbox/src/http_request.h | 3 | ||||
-rw-r--r-- | plugins/Dropbox/src/resource.h | 3 | ||||
-rw-r--r-- | plugins/Dropbox/src/stdafx.h | 2 | ||||
-rw-r--r-- | plugins/Dropbox/src/version.h | 2 |
10 files changed, 37 insertions, 40 deletions
diff --git a/plugins/Dropbox/src/api/upload.h b/plugins/Dropbox/src/api/upload.h index a871940e20..4bc9da9043 100644 --- a/plugins/Dropbox/src/api/upload.h +++ b/plugins/Dropbox/src/api/upload.h @@ -4,34 +4,31 @@ class UploadFileRequest : public HttpRequest
{
public:
- UploadFileRequest(const char *token, const char *fileName, const char *data, int length, const char *root = "auto") :
+ UploadFileRequest(const char *token, const char *fileName, const char *data, size_t size, const char *root = "auto") :
HttpRequest(REQUEST_PUT, FORMAT, DROPBOX_APICONTENT_URL "/files_put/%s/%s", root, fileName)
{
AddBearerAuthHeader(token);
- pData = (char*)data;
- dataLength = length;
+ SetData(data, size);
}
};
class UploadFileChunkRequest : public HttpRequest
{
public:
- UploadFileChunkRequest(const char *token, const char *data, int length) :
+ UploadFileChunkRequest(const char *token, const char *data, size_t size) :
HttpRequest(REQUEST_PUT, DROPBOX_APICONTENT_URL "/chunked_upload")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/octet-stream");
- pData = (char*)data;
- dataLength = length;
+ SetData(data, size);
}
- UploadFileChunkRequest(const char *token, const char *uploadId, size_t offset, const char *data, int length) :
+ UploadFileChunkRequest(const char *token, const char *uploadId, size_t offset, const char *data, size_t size) :
HttpRequest(REQUEST_PUT, FORMAT, DROPBOX_APICONTENT_URL "/chunked_upload?upload_id=%s&offset=%i", uploadId, offset)
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/octet-stream");
- pData = (char*)data;
- dataLength = length;
+ SetData(data, size);
}
UploadFileChunkRequest(const char *token, const char *uploadId, const char *path, const char *root = "auto") :
diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h index 6889c0467a..74b156c864 100644 --- a/plugins/Dropbox/src/dropbox.h +++ b/plugins/Dropbox/src/dropbox.h @@ -82,9 +82,9 @@ private: void RequestAccountInfo();
// transfers
- void SendFile(const char *path, const char *data, int length);
- void SendFileChunkedFirst(const char *data, int length, char *uploadId, size_t &offset);
- void SendFileChunkedNext(const char *data, int length, const char *uploadId, size_t &offset);
+ void SendFile(const char *path, const char *data, size_t size);
+ void SendFileChunkedFirst(const char *data, size_t size, char *uploadId, size_t &offset);
+ void SendFileChunkedNext(const char *data, size_t size, const char *uploadId, size_t &offset);
void SendFileChunkedLast(const char *path, const char *uploadId);
void CreateFolder(const char *encodedPath);
diff --git a/plugins/Dropbox/src/dropbox_events.cpp b/plugins/Dropbox/src/dropbox_events.cpp index b2d83e23ea..9ab3242645 100644 --- a/plugins/Dropbox/src/dropbox_events.cpp +++ b/plugins/Dropbox/src/dropbox_events.cpp @@ -29,8 +29,8 @@ int CDropbox::OnModulesLoaded(WPARAM, LPARAM) bbd.pszModuleName = MODULE;
bbd.bbbFlags = BBBF_ISIMBUTTON | BBBF_ISRSIDEBUTTON;
- bbd.ptszTooltip = TranslateT("Send files to Dropbox");
- bbd.hIcon = GetIconHandle(IDI_DROPBOX);
+ bbd.ptszTooltip = TranslateT("Upload files to Dropbox");
+ bbd.hIcon = GetIconHandleByName("upload");
bbd.dwButtonID = BBB_ID_FILE_SEND;
bbd.dwDefPos = 100 + bbd.dwButtonID;
CallService(MS_BB_ADDBUTTON, 0, (LPARAM)&bbd);
diff --git a/plugins/Dropbox/src/dropbox_icons.cpp b/plugins/Dropbox/src/dropbox_icons.cpp index 881c41e7db..094c27bcb7 100644 --- a/plugins/Dropbox/src/dropbox_icons.cpp +++ b/plugins/Dropbox/src/dropbox_icons.cpp @@ -2,7 +2,8 @@ static IconItem iconList[] =
{
- { LPGEN("Protocol icon"), "main", IDI_DROPBOX }
+ { LPGEN("Protocol icon"), "main", IDI_DROPBOX },
+ { LPGEN("Upload file(s)"), "upload", IDI_UPLOAD }
};
void InitializeIcons()
@@ -10,10 +11,10 @@ void InitializeIcons() Icon_Register(g_hInstance, "Protocols/" MODULE, iconList, SIZEOF(iconList), MODULE);
}
-HANDLE GetIconHandle(int iconId)
+HANDLE GetIconHandleByName(const char *name)
{
- for (unsigned i = 0; i < SIZEOF(iconList); i++)
- if (iconList[i].defIconID == iconId)
+ for (size_t i = 0; i < SIZEOF(iconList); i++)
+ if (mir_strcmpi(iconList[i].szName, name) == 0)
return iconList[i].hIcolib;
return NULL;
diff --git a/plugins/Dropbox/src/dropbox_menus.cpp b/plugins/Dropbox/src/dropbox_menus.cpp index e14948e791..b03f25104a 100644 --- a/plugins/Dropbox/src/dropbox_menus.cpp +++ b/plugins/Dropbox/src/dropbox_menus.cpp @@ -18,9 +18,9 @@ void CDropbox::InitializeMenus() CLISTMENUITEM mi = { 0 };
mi.cbSize = sizeof(CLISTMENUITEM);
mi.pszService = MODULE"/SendFilesToDropbox";
- mi.pszName = LPGEN("Send files to Dropbox");
+ mi.pszName = LPGEN("Upload files to Dropbox");
mi.position = -2000020000 + CMI_SEND_FILES;
- mi.icolibItem = GetIconHandle(IDI_DROPBOX);
+ mi.icolibItem = GetIconHandleByName("upload");
contactMenuItems[CMI_SEND_FILES] = Menu_AddContactMenuItem(&mi);
CreateServiceFunctionObj(mi.pszService, SendFilesToDropboxCommand, this);
}
diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp index 9fce0e6b01..36990b3f74 100644 --- a/plugins/Dropbox/src/dropbox_transfers.cpp +++ b/plugins/Dropbox/src/dropbox_transfers.cpp @@ -1,18 +1,18 @@ #include "stdafx.h"
-void CDropbox::SendFile(const char *path, const char *data, int length)
+void CDropbox::SendFile(const char *path, const char *data, size_t size)
{
ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
ptrA encodedPath(mir_utf8encode(path));
- UploadFileRequest request(token, encodedPath, data, length);
+ UploadFileRequest request(token, encodedPath, data, size);
mir_ptr<NETLIBHTTPREQUEST> response(request.Send(hNetlibConnection));
HandleHttpResponseError(response);
}
-void CDropbox::SendFileChunkedFirst(const char *data, int length, char *uploadId, size_t &offset)
+void CDropbox::SendFileChunkedFirst(const char *data, size_t size, char *uploadId, size_t &offset)
{
ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- UploadFileChunkRequest request(token, data, length);
+ UploadFileChunkRequest request(token, data, size);
mir_ptr<NETLIBHTTPREQUEST> response(request.Send(hNetlibConnection));
HandleHttpResponseError(response);
JSONROOT root(response->pData);
@@ -26,10 +26,10 @@ void CDropbox::SendFileChunkedFirst(const char *data, int length, char *uploadId }
}
-void CDropbox::SendFileChunkedNext(const char *data, int length, const char *uploadId, size_t &offset)
+void CDropbox::SendFileChunkedNext(const char *data, size_t size, const char *uploadId, size_t &offset)
{
ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- UploadFileChunkRequest request(token, uploadId, offset, data, length);
+ UploadFileChunkRequest request(token, uploadId, offset, data, size);
mir_ptr<NETLIBHTTPREQUEST> response(request.Send(hNetlibConnection));
HandleHttpResponseError(response);
JSONROOT root(response->pData);
@@ -131,12 +131,8 @@ UINT CDropbox::SendFilesAsync(void *owner, void *arg) ftp->pfts.currentFileProgress = 0;
ftp->pfts.tszCurrentFile = _tcsrchr(ftp->pfts.ptszFiles[i], '\\') + 1;
- ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ftp->hProcess, (LPARAM)&ftp->pfts);
-
- //
size_t offset = 0;
char uploadId[32];
-
int chunkSize = DROPBOX_FILE_CHUNK_SIZE / 4;
if (fileSize < 1024 * 1024)
chunkSize = DROPBOX_FILE_CHUNK_SIZE / 20;
@@ -152,14 +148,14 @@ UINT CDropbox::SendFilesAsync(void *owner, void *arg) if (ftp->isTerminated)
throw TransferException("Transfer was terminated");
- int count = (int)fread(data, sizeof(char), chunkSize, hFile);
+ size_t size = fread(data, sizeof(char), chunkSize, hFile);
try
{
if (offset == 0)
- instance->SendFileChunkedFirst(data, count, uploadId, offset);
+ instance->SendFileChunkedFirst(data, size, uploadId, offset);
else
- instance->SendFileChunkedNext(data, count, uploadId, offset);
+ instance->SendFileChunkedNext(data, size, uploadId, offset);
}
catch (TransferException)
{
@@ -168,14 +164,17 @@ UINT CDropbox::SendFilesAsync(void *owner, void *arg) throw;
}
- ftp->pfts.currentFileProgress += count;
- ftp->pfts.totalProgress += count;
+ ftp->pfts.currentFileProgress += size;
+ ftp->pfts.totalProgress += size;
ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ftp->hProcess, (LPARAM)&ftp->pfts);
}
mir_free(data);
fclose(hFile);
+ if (ftp->pfts.currentFileProgress < ftp->pfts.currentFileSize)
+ throw TransferException("Transfer was terminated");
+
ptrA utf8_fileName(mir_utf8encodeW(fileName));
instance->SendFileChunkedLast(utf8_fileName, uploadId);
diff --git a/plugins/Dropbox/src/http_request.h b/plugins/Dropbox/src/http_request.h index 2d2b8d130d..9980945b66 100644 --- a/plugins/Dropbox/src/http_request.h +++ b/plugins/Dropbox/src/http_request.h @@ -121,9 +121,8 @@ protected: mir_free(pData);
dataLength = (int)size;
- pData = (char*)mir_alloc(size + 1);
+ pData = (char*)mir_alloc(size);
memcpy(pData, data, size);
- pData[size] = 0;
}
public:
diff --git a/plugins/Dropbox/src/resource.h b/plugins/Dropbox/src/resource.h index f52fb0a3a7..314d82c2b3 100644 --- a/plugins/Dropbox/src/resource.h +++ b/plugins/Dropbox/src/resource.h @@ -3,6 +3,7 @@ // Used by e:\Projects\C++\MirandaNG\plugins\Dropbox\res\resource.rc
//
#define IDI_DROPBOX 102
+#define IDI_UPLOAD 103
#define IDD_OPTIONS_MAIN 109
#define IDC_REQUEST_CODE 1001
#define IDC_AUTHORIZE 1002
@@ -22,7 +23,7 @@ //
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 103
+#define _APS_NEXT_RESOURCE_VALUE 104
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1011
#define _APS_NEXT_SYMED_VALUE 101
diff --git a/plugins/Dropbox/src/stdafx.h b/plugins/Dropbox/src/stdafx.h index c541f3ad4a..3df9e83ad8 100644 --- a/plugins/Dropbox/src/stdafx.h +++ b/plugins/Dropbox/src/stdafx.h @@ -64,7 +64,7 @@ extern HINSTANCE g_hInstance; // icons
void InitializeIcons();
-HANDLE GetIconHandle(int iconId);
+HANDLE GetIconHandleByName(const char *name);
HICON LoadIconEx(int iconId, bool big = false);
#endif //_COMMON_H_
\ No newline at end of file diff --git a/plugins/Dropbox/src/version.h b/plugins/Dropbox/src/version.h index a8bcc19833..65d96b82ca 100644 --- a/plugins/Dropbox/src/version.h +++ b/plugins/Dropbox/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 12
#define __RELEASE_NUM 0
-#define __BUILD_NUM 4
+#define __BUILD_NUM 5
#include <stdver.h>
|