summaryrefslogtreecommitdiff
path: root/plugins/Dropbox/src
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2016-02-25 16:30:28 +0000
committerAlexander Lantsev <aunsane@gmail.com>2016-02-25 16:30:28 +0000
commitc600be64cf8246cf9054bbb775fec21cf1ecdba9 (patch)
tree5e9106e44bf6115673d3e3fd21c669c343a7190a /plugins/Dropbox/src
parentb7ed1f2179ca045c16a007f1fabb1a44587d9426 (diff)
Dropbox: transfer refactiring
git-svn-id: http://svn.miranda-ng.org/main/trunk@16339 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dropbox/src')
-rw-r--r--plugins/Dropbox/src/dropbox_services.cpp47
-rw-r--r--plugins/Dropbox/src/dropbox_transfers.cpp28
-rw-r--r--plugins/Dropbox/src/file_transfer.h63
-rw-r--r--plugins/Dropbox/src/stdafx.h3
4 files changed, 47 insertions, 94 deletions
diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp
index 81f77683ba..d679059c43 100644
--- a/plugins/Dropbox/src/dropbox_services.cpp
+++ b/plugins/Dropbox/src/dropbox_services.cpp
@@ -58,52 +58,11 @@ INT_PTR CDropbox::ProtoSendFile(WPARAM, LPARAM lParam)
hTransferContact = 0;
TCHAR **paths = (TCHAR**)pccsd->lParam;
-
+ ftp->SetWorkingDirectory(paths[0]);
for (int i = 0; paths[i]; i++) {
if (PathIsDirectory(paths[i]))
- ftp->totalFolders++;
- else
- ftp->pfts.totalFiles++;
- }
-
- ftp->ptszFolders = (TCHAR**)mir_alloc(sizeof(TCHAR*) * (ftp->totalFolders + 1));
- ftp->ptszFolders[ftp->totalFolders] = NULL;
-
- ftp->pfts.ptszFiles = (TCHAR**)mir_alloc(sizeof(TCHAR*) * (ftp->pfts.totalFiles + 1));
- ftp->pfts.ptszFiles[ftp->pfts.totalFiles] = NULL;
-
- for (int i = 0, j = 0, k = 0; paths[i]; i++) {
- if (PathIsDirectory(paths[i])) {
- if (!ftp->relativePathStart) {
- TCHAR *rootFolder = paths[j];
- TCHAR *relativePath = _tcsrchr(rootFolder, '\\') + 1;
- ftp->relativePathStart = relativePath - rootFolder;
- }
-
- ftp->ptszFolders[j] = mir_tstrdup(&paths[i][ftp->relativePathStart]);
-
- j++;
- }
- else {
- if (!ftp->pfts.tszWorkingDir) {
- TCHAR *path = paths[j];
- int length = _tcsrchr(path, '\\') - path;
- ftp->pfts.tszWorkingDir = (TCHAR*)mir_alloc(sizeof(TCHAR) * (length + 1));
- mir_tstrncpy(ftp->pfts.tszWorkingDir, paths[j], length + 1);
- ftp->pfts.tszWorkingDir[length] = '\0';
-
- }
-
- ftp->pfts.ptszFiles[k] = mir_wstrdup(paths[i]);
-
- FILE *hFile = _wfopen(paths[i], L"rb");
- if (hFile != NULL) {
- _fseeki64(hFile, 0, SEEK_END);
- ftp->pfts.totalBytes += _ftelli64(hFile);
- fclose(hFile);
- }
- k++;
- }
+ continue;
+ ftp->AddFile(paths[i]);
}
ULONG fileId = InterlockedIncrement(&hFileProcess);
diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp
index f97f6d2f01..ae4c50896b 100644
--- a/plugins/Dropbox/src/dropbox_transfers.cpp
+++ b/plugins/Dropbox/src/dropbox_transfers.cpp
@@ -96,26 +96,10 @@ UINT CDropbox::SendFilesAsync(void *owner, void *arg)
FileTransferParam *ftp = (FileTransferParam*)arg;
try {
- if (ftp->ptszFolders) {
- for (int i = 0; ftp->ptszFolders[i]; i++) {
- if (ftp->isTerminated)
- throw DropboxException("Transfer was terminated");
-
- char path[MAX_PATH];
- PreparePath(ftp->ptszFolders[i], path);
- instance->CreateFolder(path);
- if (!strchr(path, '\\')) {
- char url[MAX_PATH];
- instance->CreateDownloadUrl(path, url);
- ftp->AddUrl(url);
- }
- }
- }
-
- ftp->First();
+ ftp->FirstFile();
do
{
- const TCHAR *fileName = &ftp->GetCurrentFileName()[ftp->relativePathStart];
+ const TCHAR *fileName = &ftp->GetCurrentFilePath()[ftp->relativePathStart];
uint64_t fileSize = ftp->GetCurrentFileSize();
int chunkSize = ftp->GetCurrentFileChunkSize();
@@ -154,7 +138,7 @@ UINT CDropbox::SendFilesAsync(void *owner, void *arg)
instance->CreateDownloadUrl(path, url);
ftp->AddUrl(url);
}
- } while (ftp->Next());
+ } while (ftp->NextFile());
}
catch (DropboxException &ex) {
Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, ex.what());
@@ -175,8 +159,8 @@ UINT CDropbox::SendFilesAndReportAsync(void *owner, void *arg)
if (res == ACKRESULT_SUCCESS)
{
CMStringA urls;
- for (int i = 0; i < ftp->urlList.getCount(); i++)
- urls.AppendFormat("%s\r\n", ftp->urlList[i]);
+ for (int i = 0; i < ftp->urls.getCount(); i++)
+ urls.AppendFormat("%s\r\n", ftp->urls[i]);
instance->Report(ftp->hContact, urls.GetBuffer());
}
@@ -197,7 +181,7 @@ UINT CDropbox::SendFilesAndEventAsync(void *owner, void *arg)
TRANSFERINFO ti = { 0 };
ti.hProcess = ftp->hProcess;
ti.status = res;
- ti.data = ftp->urlList.getArray();
+ ti.data = ftp->urls.getArray();
NotifyEventHooks(instance->hFileSentEventHook, ftp->hContact, (LPARAM)&ti);
diff --git a/plugins/Dropbox/src/file_transfer.h b/plugins/Dropbox/src/file_transfer.h
index 442f821f44..f63483d46f 100644
--- a/plugins/Dropbox/src/file_transfer.h
+++ b/plugins/Dropbox/src/file_transfer.h
@@ -10,25 +10,20 @@ struct FileTransferParam
bool isTerminated;
- int totalFolders;
- TCHAR **ptszFolders;
int relativePathStart;
- LIST<char> urlList;
+ LIST<char> urls;
- FileTransferParam() : urlList(1)
+ FileTransferParam() : urls(1)
{
hFile = NULL;
-
- totalFolders = 0;
- ptszFolders = NULL;
- relativePathStart = 0;
-
hProcess = NULL;
hContact = NULL;
isTerminated = false;
+ relativePathStart = 0;
+
pfts.cbSize = sizeof(this->pfts);
pfts.flags = PFTS_TCHAR | PFTS_SENDING;
pfts.hContact = NULL;
@@ -39,7 +34,8 @@ struct FileTransferParam
pfts.totalBytes = 0;
pfts.totalFiles = 0;
pfts.totalProgress = 0;
- pfts.pszFiles = NULL;
+ pfts.ptszFiles = (TCHAR**)mir_alloc(sizeof(TCHAR*) * (pfts.totalFiles + 1));
+ pfts.ptszFiles[pfts.totalFiles] = NULL;
pfts.tszWorkingDir = NULL;
pfts.tszCurrentFile = NULL;
@@ -62,18 +58,36 @@ struct FileTransferParam
mir_free(pfts.pszFiles);
}
- if (ptszFolders)
- {
- for (int i = 0; ptszFolders[i]; i++)
- {
- if (ptszFolders[i]) mir_free(ptszFolders[i]);
- }
- mir_free(ptszFolders);
+ for (int i = 0; i < urls.getCount(); i++)
+ mir_free(urls[i]);
+ urls.destroy();
+ }
+
+ void SetWorkingDirectory(const TCHAR *path)
+ {
+ relativePathStart = _tcsrchr(path, '\\') - path + 1;
+ pfts.tszWorkingDir = (TCHAR*)mir_alloc(sizeof(TCHAR) * relativePathStart);
+ mir_tstrncpy(pfts.tszWorkingDir, path, relativePathStart);
+ pfts.tszWorkingDir[relativePathStart - 1] = '\0';
+ }
+
+ void AddFile(const TCHAR *path)
+ {
+ pfts.ptszFiles = (TCHAR**)mir_realloc(pfts.ptszFiles, sizeof(TCHAR*) * (pfts.totalFiles + 2));
+ pfts.ptszFiles[pfts.totalFiles++] = mir_tstrdup(path);
+ pfts.ptszFiles[pfts.totalFiles] = NULL;
+
+ FILE *hFile = _tfopen(path, L"rb");
+ if (hFile != NULL) {
+ _fseeki64(hFile, 0, SEEK_END);
+ pfts.totalBytes += _ftelli64(hFile);
+ fclose(hFile);
}
+ }
- for (int i = 0; i < urlList.getCount(); i++)
- mir_free(urlList[i]);
- urlList.destroy();
+ void AddUrl(const char *url)
+ {
+ urls.insert(mir_strdup(url));
}
const TCHAR* GetCurrentFilePath() const
@@ -141,7 +155,7 @@ struct FileTransferParam
ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, hProcess, (LPARAM)&pfts);
}
- void First()
+ void FirstFile()
{
CloseCurrentFile();
@@ -154,7 +168,7 @@ struct FileTransferParam
CheckCurrentFile();
}
- bool Next()
+ bool NextFile()
{
CloseCurrentFile();
@@ -175,11 +189,6 @@ struct FileTransferParam
{
ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, status, hProcess, param);
}
-
- void AddUrl(const char *url)
- {
- urlList.insert(mir_strdup(url));
- }
};
#endif //_FILE_TRANSFER_H_ \ No newline at end of file
diff --git a/plugins/Dropbox/src/stdafx.h b/plugins/Dropbox/src/stdafx.h
index b83d80895b..75155fd5cd 100644
--- a/plugins/Dropbox/src/stdafx.h
+++ b/plugins/Dropbox/src/stdafx.h
@@ -43,7 +43,8 @@ class CDropbox;
#define DROPBOX_API_CU "https://content.dropboxapi.com/" DROPBOX_API_VER
#define DROPBOX_APP_KEY "fa8du7gkf2q8xzg"
-#include "..\..\..\miranda-private-keys\Dropbox\secret_key.h"
+#define DROPBOX_API_SECRET "bb8zirh7nnk8fow"
+//#include "..\..\..\miranda-private-keys\Dropbox\secret_key.h"
class DropboxException
{