diff options
| author | Alexander Lantsev <aunsane@gmail.com> | 2014-08-29 22:11:08 +0000 | 
|---|---|---|
| committer | Alexander Lantsev <aunsane@gmail.com> | 2014-08-29 22:11:08 +0000 | 
| commit | beaf93e92827b7bcc77c9f6b2a0c7097d355151c (patch) | |
| tree | 0cc6549ce3f4073a261cdd10e3eed761fc3c4648 /protocols/Tox/src/file_transfer.h | |
| parent | d8e0b2d36e1944ab747012ed7ba4612f0da48854 (diff) | |
Tox: added files receiving
git-svn-id: http://svn.miranda-ng.org/main/trunk@10339 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/file_transfer.h')
| -rw-r--r-- | protocols/Tox/src/file_transfer.h | 86 | 
1 files changed, 66 insertions, 20 deletions
diff --git a/protocols/Tox/src/file_transfer.h b/protocols/Tox/src/file_transfer.h index d131802973..6f30b90241 100644 --- a/protocols/Tox/src/file_transfer.h +++ b/protocols/Tox/src/file_transfer.h @@ -6,16 +6,16 @@ class CFileTransfer;  class CFile
  {
  private:
 -	HANDLE hProcess;
 -
 -	const CFileTransfer *transfer;
 -	
 +	int number;
  	char *name;
  	const TCHAR *path;
  	size_t size;
 +	const CFileTransfer *transfer;
 +
  public:
 -	CFile(const CFileTransfer *fileTransfer, const TCHAR *filePath, size_t fileSize)
 +	CFile(const CFileTransfer *fileTransfer, const TCHAR *filePath, size_t fileSize) :
 +		number(-1)
  	{
  		transfer = fileTransfer;
 @@ -24,14 +24,25 @@ public:  		size = fileSize;
  	}
 +	CFile(int number) : number(number), name(NULL) { }
 +
  	~CFile()
  	{
 -		mir_free(name);
 +		number = -1;
 +		if (name != NULL)
 +		{
 +			mir_free(name);
 +		}
 +	}
 +
 +	const CFileTransfer *GetTransfer() const
 +	{
 +		return this->transfer;
  	}
 -	void SetHandle(HANDLE hFileProcess)
 +	void SetNumber(int fileNumber)
  	{
 -		hProcess = hFileProcess;
 +		number = fileNumber;
  	}
  	const TCHAR* GetPath() const
 @@ -53,15 +64,19 @@ public:  class CFileTransfer
  {
  private:
 -	HANDLE hProcess;
 -	LIST<CFile> files;
 +	ULONG number;
 -public:
 +	HANDLE hWait;
 +	LIST<CFile> files;
  	PROTOFILETRANSFERSTATUS pfts;
 +	const PROTO_INTERFACE *proto;
 -	CFileTransfer(MCONTACT hContact, ULONG hProcess, DWORD flags) :
 -		files(1)
 +public:
 +	CFileTransfer(const PROTO_INTERFACE *proto, MCONTACT hContact, ULONG transferNumber, DWORD flags) :
 +		files(1, NumericKeySortT)
  	{
 +		this->proto = proto;
 +
  		pfts.cbSize = sizeof(pfts);
  		pfts.flags = PFTS_TCHAR | flags;
  		pfts.hContact = hContact;
 @@ -75,7 +90,7 @@ public:  		pfts.tszWorkingDir = NULL;
  		pfts.tszCurrentFile = NULL;
 -		this->hProcess = (HANDLE)hProcess;
 +		number = transferNumber;
  	}
  	~CFileTransfer()
 @@ -120,30 +135,61 @@ public:  				fclose(file);
  			}
 -			files.insert(new CFile(this, pfts.ptszFiles[i], fileSize));
 +			files.insert(new CFile(this, ppszFiles[i], fileSize));
  		}
  	}
 +	const PROTO_INTERFACE *GetProtoInstance() const
 +	{
 +		return proto;
 +	}
 +
 +	ULONG GetTransferNumber() const
 +	{
 +		return number;
 +	}
 +
 +	MCONTACT GetContactHandle() const
 +	{
 +		return pfts.hContact;
 +	}
 +
  	int GetFileCount() const
  	{
 -		return files.getCount();
 +		return pfts.totalFiles;
  	}
 -	CFile * const GetFileAt(int idx) const
 +	CFile *GetFileAt(int idx) const
  	{
  		return files[idx];
  	}
 -	HANDLE GetTransferHandler() const
 +	CFile *GetFileByNumber(int number) const
 +	{
 +		CFile *search = new CFile(number);
 +		CFile *file = files.find(search);
 +		delete search;
 +
 +		return file;
 +	}
 +
 +	bool HasFile(int number) const
 +	{
 +		const CFile *file = GetFileByNumber(number);
 +
 +		return file != NULL;
 +	}
 +
 +	void Wait()
  	{
 -		return hProcess;
 +		WaitForSingleObject(hWait, INFINITE);
  	}
  };
  class CFileSendTransfer : public CFileTransfer
  {
  public:
 -	CFileSendTransfer(MCONTACT hContact, ULONG hProcess) : CFileTransfer(hContact, hProcess, PFTS_SENDING)
 +	CFileSendTransfer(MCONTACT hContact, ULONG hProcess) : CFileTransfer(NULL, hContact, hProcess, PFTS_SENDING)
  	{
  	}
  };
  | 
