summaryrefslogtreecommitdiff
path: root/plugins/Dropbox/src/file_transfer.h
blob: 7558b83ebab06e7cb7beb9ed5f9d108dcf5925d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef _FILE_TRANSFER_H_
#define _FILE_TRANSFER_H_

#include "common.h"

struct FileTransferParam
{
	HANDLE hProcess;
	MCONTACT hContact;
	PROTOFILETRANSFERSTATUS pfts;

	int totalFolders;
	wchar_t **pwszFolders;
	int relativePathStart;

	wchar_t **pwszUrls;

	FileTransferParam()
	{
		totalFolders = 0;
		pwszFolders = NULL;
		relativePathStart = 0;

		pfts.cbSize = sizeof(this->pfts);
		pfts.flags = PFTS_UNICODE;
		pfts.currentFileNumber = 0;
		pfts.currentFileProgress = 0;
		pfts.currentFileSize = 0;
		pfts.totalBytes = 0;
		pfts.totalFiles = 0;
		pfts.totalProgress = 0;
		pfts.pszFiles = NULL;
		pfts.tszWorkingDir = NULL;
		pfts.wszCurrentFile = NULL;

		pwszUrls = NULL;
	}

	~FileTransferParam()
	{
		if (pfts.wszWorkingDir)
			mir_free(pfts.wszWorkingDir);

		if (pfts.pszFiles)
		{
			for (int i = 0; pfts.pszFiles[i]; i++)
			{
				if (pfts.pszFiles[i]) mir_free(pfts.pszFiles[i]);
			}
			mir_free(pfts.pszFiles);
		}

		if (pwszFolders)
		{
			for (int i = 0; pwszFolders[i]; i++)
			{
				if (pwszFolders[i]) mir_free(pwszFolders[i]);
			}
			mir_free(pwszFolders);
		}

		if (pwszUrls)
		{
			for (int i = 0; pwszUrls[i]; i++)
			{
				if (pwszUrls[i]) mir_free(pwszUrls[i]);
			}
			mir_free(pwszUrls);
		}
	}

	void AddUrl(const wchar_t *url)
	{
		int count = 0;
		if (pwszUrls == NULL)
			pwszUrls = (wchar_t**)mir_alloc(sizeof(wchar_t*) * 2);
		else
		{
			for (; pwszUrls[count]; count++);
			pwszUrls = (wchar_t**)mir_realloc(pwszUrls, sizeof(wchar_t*) * (count + 2));
		}
		int length = wcslen(url);
		pwszUrls[count] = (wchar_t*)mir_alloc(sizeof(wchar_t) * (length + 1));
		wcscpy(pwszUrls[count], url);
		pwszUrls[count][length] = '\0';
		pwszUrls[count + 1] = NULL;
	}
};

#endif //_FILE_TRANSFER_H_