summaryrefslogtreecommitdiff
path: root/plugins/FileAsMessage/src/dialog.h
blob: 117ae006a32e576f55d4810ebd4d5dcc091af846 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#pragma once

extern HINSTANCE hInst;

int getMsgId(char *msg);

INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);

#ifdef _DEBUG
#define CHECKPOINT
#else
#define CHECKPOINT error
#endif

#define TIMER_SEND	100

typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long ulong;
enum
{
	CMD_REQ,
	CMD_ACCEPT,
	CMD_CANCEL,

	CMD_NEXT,

	CMD_DATA,
	CMD_DACK,
	CMD_END,

	CMD_COUNT
};

extern char cFECmd[CMD_COUNT];

#define STATE_IDLE		0x100 // idle, no operation
#define STATE_REQSENT	0x02 // request sent, awaiting of  response
#define STATE_PRERECV	0x04 // incoming request, awaiting of user
#define STATE_OPERATE	0x08 // operating mode
#define STATE_ACKREQ	0x10 // ACK-request scheduled
#define STATE_CANCELLED 0x20 // operation aborted
#define STATE_FINISHED	0x40 // ... finished successfully
#define STATE_PAUSED	0x80 // ... paused

#define CHUNK_UNSENT	0x00
#define CHUNK_SENT		0x01
#define CHUNK_ACK		0x02

#define ICON_PLAY		0
#define ICON_PAUSE		1
#define ICON_REFRESH	2
#define ICON_STOP		3
#define ICON_MAIN		4

struct FILEECHO
{
public:
	MCONTACT hContact;
	HWND hDlg;

	bool inSend;
	int iState;
	int contactStatus;

	HANDLE hFile, hMapping;
	uchar *lpData;

	char *filename;
	uint chunkIndx;			// next chunk to send
	uint chunkCount;		// count of chunks
	uint chunkSent;
	uint chunkCountx;
	uint *chunkPos;			// offsets of chunks in file
	uchar *chunkAck;		// acknowledge of incoming chunks

	uchar codeSymb;			// symb for replace NUL-symb.

	uint fileSize;
	uint chunkMaxLen;		// limit for outgoing chunk

	DWORD lastTimestamp;
	DWORD lastDelay;
	bool asBinary;

	// settings
	uint dwSendInterval;
	//uint dwChunkSize;

	COLORREF rgbSent, rgbRecv, rgbUnSent, rgbToSend;
#ifdef DEBUG
	uint overhead;
#endif

	FILEECHO(MCONTACT Contact);

	void setState(DWORD state);
	void updateProgress();
	void updateTitle();

	void perform(char *str);
	void cmdACCEPT();
	void cmdDACK(char *data);
	void sendReq();
	int  sendCmd(int id, int cmd, char *szParam, char *szPrefix = nullptr);

	void cmdDATA(char *data);
	void cmdEND();

	int  createTransfer();
	void destroyTransfer();

	void onSendTimer();
	void onRecvTimer();
	void incomeRequest(char *data);

};

void InitCRC32();