summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/FileAsMessage/src/dialog.cpp1062
1 files changed, 527 insertions, 535 deletions
diff --git a/plugins/FileAsMessage/src/dialog.cpp b/plugins/FileAsMessage/src/dialog.cpp
index 2b144d6048..6f6ed39a23 100644
--- a/plugins/FileAsMessage/src/dialog.cpp
+++ b/plugins/FileAsMessage/src/dialog.cpp
@@ -8,21 +8,21 @@ char *szFEMode[] =
char* ltoax(char* s, DWORD value)
{
- if(value == 0)
+ if (value == 0)
{
*s++ = '0';
}
uchar data;
int indx = 8;
- while(indx && !(data = (uchar)(value >> 28) & 0x0F))
+ while (indx && !(data = (uchar)(value >> 28) & 0x0F))
{
value <<= 4;
indx--;
}
- while(indx)
+ while (indx)
{
data = (uchar)(value >> 28) & 0x0F;
- if(data > 9) data += 'A' - 10;
+ if (data > 9) data += 'A' - 10;
else data += '0';
*s++ = data;
value <<= 4;
@@ -35,17 +35,17 @@ uint atolx(char* &value)
uint result = 0;
uchar ch;
- while( *value && (ch = *value - '0') >= 0 )
+ while (*value && (ch = *value - '0') >= 0)
{
- if(ch > 9)
+ if (ch > 9)
{
ch -= 'A' - '0';
- if(ch > 5) break;
+ if (ch > 5) break;
ch += 10;
}
result = result * 16 + ch;
value++;
- }
+ }
return result;
}
@@ -54,7 +54,7 @@ char cCmdList[CMD_COUNT] =
'?',
'+',
'-',
-
+
'*',
'>',
@@ -66,46 +66,46 @@ static int CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
{
MCONTACT hContact = PUGetContact(hWnd);
HWND hDlg = (HWND)PUGetPluginData(hWnd);
-/*
- if(hContact)
- {
+ /*
+ if(hContact)
+ {
CLISTEVENT *lpcle;
int indx = 0;
for(;;)
{
- if((lpcle = (CLISTEVENT*)CallService(MS_CLIST_GETEVENT, hContact, indx)) == NULL)
- break;
- if(mir_tstrcmp(lpcle->pszService, SERVICE_NAME "/FERecvFile") == 0)
- {
- lpcle->lParam = (LPARAM)hWnd;
- break;
- }
- indx++;
- }
- }
-*/
- switch(message) {
- case WM_COMMAND:
+ if((lpcle = (CLISTEVENT*)CallService(MS_CLIST_GETEVENT, hContact, indx)) == NULL)
+ break;
+ if(mir_tstrcmp(lpcle->pszService, SERVICE_NAME "/FERecvFile") == 0)
{
- PUDeletePopup(hWnd);
- CallService(MS_CLIST_REMOVEEVENT, hContact, 0);
-
- if(IsWindow(hDlg))
- {
- ShowWindow(hDlg, SW_SHOWNORMAL);
- SetForegroundWindow(hDlg);
- SetFocus(hDlg);
- }
+ lpcle->lParam = (LPARAM)hWnd;
+ break;
+ }
+ indx++;
+ }
+ }
+ */
+ switch (message) {
+ case WM_COMMAND:
+ {
+ PUDeletePopup(hWnd);
+ CallService(MS_CLIST_REMOVEEVENT, hContact, 0);
- break;
+ if (IsWindow(hDlg))
+ {
+ ShowWindow(hDlg, SW_SHOWNORMAL);
+ SetForegroundWindow(hDlg);
+ SetFocus(hDlg);
}
- case WM_CONTEXTMENU:
- PUDeletePopup(hWnd);
- break;
- case UM_FREEPLUGINDATA:
- return TRUE; //TRUE or FALSE is the same, it gets ignored.
- default:
- break;
+
+ break;
+ }
+ case WM_CONTEXTMENU:
+ PUDeletePopup(hWnd);
+ break;
+ case UM_FREEPLUGINDATA:
+ return TRUE; //TRUE or FALSE is the same, it gets ignored.
+ default:
+ break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
@@ -115,7 +115,7 @@ static int CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
void MakePopupMsg(HWND hDlg, MCONTACT hContact, char *msg)
{
HWND hFocused = GetForegroundWindow();
- if(hDlg == hFocused || hDlg == GetParent(hFocused)) return;
+ if (hDlg == hFocused || hDlg == GetParent(hFocused)) return;
//
//The text for the second line. You could even make something like: char lpzText[128]; mir_tstrcpy(lpzText, "Hello world!"); It's your choice.
@@ -137,17 +137,17 @@ void MakePopupMsg(HWND hDlg, MCONTACT hContact, char *msg)
//
int getMsgId(char *msg)
{
- for(int indx = 0; indx < CMD_COUNT; indx++)
+ for (int indx = 0; indx < CMD_COUNT; indx++)
{
- if(*msg == cCmdList[indx]) return indx;
+ if (*msg == cCmdList[indx]) return indx;
}
return -1;
};
int RetrieveFileSize(char *filename)
{
- int handle = open(filename, O_RDONLY|O_BINARY,0);
- if(handle != -1)
+ int handle = open(filename, O_RDONLY | O_BINARY, 0);
+ if (handle != -1)
{
int size = filelength(handle);
close(handle);
@@ -166,35 +166,35 @@ FILEECHO::FILEECHO(MCONTACT Contact)
chunkCount = 0;
filename = NULL;
- rgbRecv = db_get_dw(NULL, SERVICE_NAME, "colorRecv", RGB(64,255,64));
- rgbSent = db_get_dw(NULL, SERVICE_NAME, "colorSent", RGB(255,255,64));
- rgbUnSent = db_get_dw(NULL, SERVICE_NAME, "colorUnsent", RGB(128,128,128));
- rgbToSend = db_get_dw(NULL, SERVICE_NAME, "colorTosend", RGB(192,192,192));
+ rgbRecv = db_get_dw(NULL, SERVICE_NAME, "colorRecv", RGB(64, 255, 64));
+ rgbSent = db_get_dw(NULL, SERVICE_NAME, "colorSent", RGB(255, 255, 64));
+ rgbUnSent = db_get_dw(NULL, SERVICE_NAME, "colorUnsent", RGB(128, 128, 128));
+ rgbToSend = db_get_dw(NULL, SERVICE_NAME, "colorTosend", RGB(192, 192, 192));
asBinary = db_get_dw(NULL, SERVICE_NAME, "base64", 1) == 0;
}
uint controlEnabled[][2] =
{
- IDC_PLAY,
- STATE_OPERATE|STATE_PAUSED|STATE_PRERECV|STATE_ACKREQ|STATE_IDLE,
+ IDC_PLAY,
+ STATE_OPERATE | STATE_PAUSED | STATE_PRERECV | STATE_ACKREQ | STATE_IDLE,
IDC_STOP,
- STATE_OPERATE|STATE_PAUSED|STATE_PRERECV|STATE_REQSENT|STATE_ACKREQ,
-// IDC_FILENAME,
-// STATE_IDLE|STATE_PRERECV|STATE_FINISHED|STATE_CANCELLED,
-// IDC_BROWSE,
-// STATE_IDLE|STATE_PRERECV|STATE_FINISHED|STATE_CANCELLED,
+ STATE_OPERATE | STATE_PAUSED | STATE_PRERECV | STATE_REQSENT | STATE_ACKREQ,
+ // IDC_FILENAME,
+ // STATE_IDLE|STATE_PRERECV|STATE_FINISHED|STATE_CANCELLED,
+ // IDC_BROWSE,
+ // STATE_IDLE|STATE_PRERECV|STATE_FINISHED|STATE_CANCELLED,
};
/*
char *stateMsg[][2] =
{
- (char*)STATE_IDLE,"Idle",
- (char*)STATE_REQSENT,"ReqSent",
- (char*)STATE_PRERECV,"PreRecv",
- (char*)STATE_OPERATE,"Operate",
- (char*)STATE_ACKREQ,"AckReq",
- (char*)STATE_CANCELLED,"Cancelled",
- (char*)STATE_FINISHED,"Finished",
- (char*)STATE_PAUSED,"Paused"
+(char*)STATE_IDLE,"Idle",
+(char*)STATE_REQSENT,"ReqSent",
+(char*)STATE_PRERECV,"PreRecv",
+(char*)STATE_OPERATE,"Operate",
+(char*)STATE_ACKREQ,"AckReq",
+(char*)STATE_CANCELLED,"Cancelled",
+(char*)STATE_FINISHED,"Finished",
+(char*)STATE_PAUSED,"Paused"
};
*/
@@ -210,45 +210,45 @@ void FILEECHO::setState(DWORD state)
iState = state;
int indx;
- for(indx = 0; indx < SIZEOF(controlEnabled); indx++)
+ for (indx = 0; indx < SIZEOF(controlEnabled); indx++)
{
EnableWindow(GetDlgItem(hDlg, controlEnabled[indx][0]), (iState & controlEnabled[indx][1]) != 0);
}
- if(!inSend) // recv
+ if (!inSend) // recv
{
int kind;
SendDlgItemMessage(hDlg, IDC_FILENAME, EM_SETREADONLY, (state != STATE_PRERECV), 0);
- EnableWindow(GetDlgItem(hDlg, IDC_BROWSE), (iState & (STATE_PRERECV|STATE_FINISHED)));
+ EnableWindow(GetDlgItem(hDlg, IDC_BROWSE), (iState & (STATE_PRERECV | STATE_FINISHED)));
//SendDlgItemMessage(hDlg, IDC_FILENAME, EM_SETREADONLY, (iState & STATE_PRERECV) == 0, 0);
//EnableWindow(GetDlgItem(hDlg, IDC_FILENAME), (iState == STATE_PRERECV));
//EnableWindow(GetDlgItem(hDlg, IDC_FILENAME), (iState & STATE_IDLE|STATE_PRERECV|STATE_FINISHED|STATE_CANCELLED) != 0);
- if(state & (STATE_IDLE|STATE_FINISHED|STATE_CANCELLED|STATE_PRERECV))
+ if (state & (STATE_IDLE | STATE_FINISHED | STATE_CANCELLED | STATE_PRERECV))
kind = ICON_PLAY;
else
kind = ICON_REFRESH;
- SendDlgItemMessage(hDlg, IDC_PLAY,BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcons[kind]);
- SendDlgItemMessage(hDlg, IDC_PLAY, BUTTONADDTOOLTIP,(WPARAM)Translate(hint_controls[kind]),0);
+ SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcons[kind]);
+ SendDlgItemMessage(hDlg, IDC_PLAY, BUTTONADDTOOLTIP, (WPARAM)Translate(hint_controls[kind]), 0);
}
else
{
- SendDlgItemMessage(hDlg, IDC_FILENAME, EM_SETREADONLY, (iState & (STATE_IDLE|STATE_FINISHED|STATE_CANCELLED)) == 0, 0);
- EnableWindow(GetDlgItem(hDlg, IDC_BROWSE), (iState & (STATE_IDLE|STATE_FINISHED|STATE_CANCELLED)) != 0);
+ SendDlgItemMessage(hDlg, IDC_FILENAME, EM_SETREADONLY, (iState & (STATE_IDLE | STATE_FINISHED | STATE_CANCELLED)) == 0, 0);
+ EnableWindow(GetDlgItem(hDlg, IDC_BROWSE), (iState & (STATE_IDLE | STATE_FINISHED | STATE_CANCELLED)) != 0);
//EnableWindow(GetDlgItem(hDlg, IDC_FILENAME), (iState & STATE_IDLE|STATE_PRERECV|STATE_FINISHED|STATE_CANCELLED) != 0);
- switch(state)
+ switch (state)
{
- case STATE_FINISHED:
- case STATE_CANCELLED:
- case STATE_IDLE:
- case STATE_PAUSED:
- EnableWindow(GetDlgItem(hDlg, IDC_PLAY), TRUE);
- SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcons[ICON_PLAY]);
- SendDlgItemMessage(hDlg, IDC_PLAY, BUTTONADDTOOLTIP,(WPARAM)Translate(hint_controls[ICON_PLAY]),0);
- break;
- case STATE_OPERATE:
- SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcons[ICON_PAUSE]);
- SendDlgItemMessage(hDlg, IDC_PLAY, BUTTONADDTOOLTIP,(WPARAM)Translate(hint_controls[ICON_PAUSE]),0);
- break;
+ case STATE_FINISHED:
+ case STATE_CANCELLED:
+ case STATE_IDLE:
+ case STATE_PAUSED:
+ EnableWindow(GetDlgItem(hDlg, IDC_PLAY), TRUE);
+ SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcons[ICON_PLAY]);
+ SendDlgItemMessage(hDlg, IDC_PLAY, BUTTONADDTOOLTIP, (WPARAM)Translate(hint_controls[ICON_PLAY]), 0);
+ break;
+ case STATE_OPERATE:
+ SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcons[ICON_PAUSE]);
+ SendDlgItemMessage(hDlg, IDC_PLAY, BUTTONADDTOOLTIP, (WPARAM)Translate(hint_controls[ICON_PAUSE]), 0);
+ break;
}
}
updateProgress();
@@ -258,8 +258,8 @@ void FILEECHO::updateTitle()
{
char newtitle[256], *contactName;
- contactName=(char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME,hContact,0);
- if(iState == STATE_OPERATE && chunkCount != 0)
+ contactName = (char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, 0);
+ if (iState == STATE_OPERATE && chunkCount != 0)
mir_snprintf(newtitle, SIZEOF(newtitle), "%d%% - %s: %s", chunkSent * 100 / chunkCount, Translate(szFEMode[inSend]), contactName);
else
mir_snprintf(newtitle, SIZEOF(newtitle), "%s: %s", Translate(szFEMode[inSend]), contactName);
@@ -269,7 +269,7 @@ void FILEECHO::updateTitle()
void BuildFreqTable(uchar *data, uint len, uint *freqTable)
{
memset(freqTable, 0, (256 * sizeof(uint)));
- for(uint indx = 0; indx < len; indx++)
+ for (uint indx = 0; indx < len; indx++)
freqTable[data[indx]]++;
}
@@ -285,38 +285,38 @@ int FILEECHO::createTransfer()
BYTE bAuto = db_get_b(NULL, "SRFile", "AutoAccept", 0);
hFile = CreateFile(filename, inSend ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE), inSend ? FILE_SHARE_READ : 0, NULL, inSend ? OPEN_EXISTING : (bAuto ? CREATE_ALWAYS : CREATE_NEW), FILE_ATTRIBUTE_NORMAL, NULL);
- if(hFile == INVALID_HANDLE_VALUE && !inSend && GetLastError() == ERROR_FILE_EXISTS)
+ if (hFile == INVALID_HANDLE_VALUE && !inSend && GetLastError() == ERROR_FILE_EXISTS)
{
- if(MessageBox(hDlg, Translate("File already exists. Overwrite?"),
+ if (MessageBox(hDlg, Translate("File already exists. Overwrite?"),
Translate(SERVICE_TITLE),
MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) != IDYES) return 0;
- hFile = CreateFile(filename, GENERIC_READ|GENERIC_WRITE, 0,
+ hFile = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
}
- if(hFile == INVALID_HANDLE_VALUE) goto createTransfer_FAILED;
- if(!inSend)
+ if (hFile == INVALID_HANDLE_VALUE) goto createTransfer_FAILED;
+ if (!inSend)
{
SetFilePointer(hFile, fileSize, NULL, FILE_BEGIN);
SetEndOfFile(hFile);
}
else
fileSize = GetFileSize(hFile, NULL);
- hMapping = CreateFileMapping(hFile, NULL, inSend?PAGE_READONLY:PAGE_READWRITE,
+ hMapping = CreateFileMapping(hFile, NULL, inSend ? PAGE_READONLY : PAGE_READWRITE,
0, fileSize, NULL);
LastError = GetLastError();
- if(hMapping == NULL) goto createTransfer_FAILED;
- lpData = (uchar*)MapViewOfFile(hMapping, inSend?FILE_MAP_READ:FILE_MAP_WRITE, 0,0,0);
+ if (hMapping == NULL) goto createTransfer_FAILED;
+ lpData = (uchar*)MapViewOfFile(hMapping, inSend ? FILE_MAP_READ : FILE_MAP_WRITE, 0, 0, 0);
LastError = GetLastError();
- if(lpData == NULL) goto createTransfer_FAILED;
+ if (lpData == NULL) goto createTransfer_FAILED;
if (inSend)
- //
- // frequency analysis of source file
- // and building the table of offsets
- //
+ //
+ // frequency analysis of source file
+ // and building the table of offsets
+ //
{
- if(asBinary)
+ if (asBinary)
{
uint freq_table[256] = { 0 };
codeSymb = 1;
@@ -327,7 +327,7 @@ int FILEECHO::createTransfer()
for (uint i = codeSymb + 1; i < 256; ++i)
{
if (freq_table[codeSymb] > freq_table[i])
- codeSymb = i;
+ codeSymb = i;
}
//DEBUG
//codeSymb = ':';
@@ -353,7 +353,7 @@ int FILEECHO::createTransfer()
++out_size;
data++; chunk_size++;
- if (out_size >= chunkMaxLen-1)
+ if (out_size >= chunkMaxLen - 1)
{
chunkPos[indx] = chunk_offset;
chunk_offset += chunk_size;
@@ -362,7 +362,7 @@ int FILEECHO::createTransfer()
}
}
chunkPos[indx++] = chunk_offset; chunkCount = indx;
- chunkPos = (uint*)realloc(chunkPos, sizeof(uint)*(chunkCount+1));
+ chunkPos = (uint*)realloc(chunkPos, sizeof(uint)*(chunkCount + 1));
chunkPos[indx] = chunk_offset + chunk_size;
}
else
@@ -391,23 +391,23 @@ int FILEECHO::createTransfer()
return 1;
createTransfer_FAILED:
- if(lpData != NULL) UnmapViewOfFile(lpData);
- if(hMapping != NULL) CloseHandle(hMapping);
- if(hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile);
+ if (lpData != NULL) UnmapViewOfFile(lpData);
+ if (hMapping != NULL) CloseHandle(hMapping);
+ if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile);
return 0;
}
void FILEECHO::destroyTransfer()
{
- if(chunkCount)
+ if (chunkCount)
{
chunkCount = 0;
- if(inSend)
+ if (inSend)
free(chunkPos);
free(chunkAck);
- if(lpData != NULL) UnmapViewOfFile(lpData);
- if(hMapping != NULL) CloseHandle(hMapping);
- if(hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile);
+ if (lpData != NULL) UnmapViewOfFile(lpData);
+ if (hMapping != NULL) CloseHandle(hMapping);
+ if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile);
}
//setState(STATE_IDLE);
return;
@@ -417,21 +417,21 @@ void FILEECHO::sendReq()
{
char sendbuf[MAX_PATH];
- if(!createTransfer())
+ if (!createTransfer())
{
SetDlgItemText(hDlg, IDC_FILESIZE, Translate("Couldn't open a file"));
return;
}
///!!!!!!!
char *p = filename + strlen(filename);
- while(p != filename && *p != '\\')
+ while (p != filename && *p != '\\')
p--;
- if(*p == '\\')
- strcpy(filename,p+1);
+ if (*p == '\\')
+ strcpy(filename, p + 1);
mir_snprintf(sendbuf, SIZEOF(sendbuf), Translate("Size: %d bytes"), fileSize);
SetDlgItemText(hDlg, IDC_FILESIZE, sendbuf);
- mir_snprintf(sendbuf, SIZEOF(sendbuf), "?%c%c%d:%d \n" NOPLUGIN_MESSAGE, asBinary+'0', codeSymb, chunkCount, fileSize);
+ mir_snprintf(sendbuf, SIZEOF(sendbuf), "?%c%c%d:%d \n" NOPLUGIN_MESSAGE, asBinary + '0', codeSymb, chunkCount, fileSize);
sendCmd(0, CMD_REQ, sendbuf, filename);
SetDlgItemText(hDlg, IDC_STATUS, Translate("Request sent. Awaiting of acceptance.."));
@@ -444,19 +444,19 @@ void FILEECHO::incomeRequest(char *param)
char buf[MAX_PATH];
// param == &filename
char *p = strchr(param, '?');
- if(p == NULL) return; *p++ = 0;
+ if (p == NULL) return; *p++ = 0;
CallService(MS_FILE_GETRECEIVEDFILESFOLDER, hContact, (LPARAM)buf);
strncat(buf, param, sizeof(buf));
free(filename);
filename = strdup(buf);
// p == &c
- if(*p == 0) return; asBinary = (*p++) != '0';
- if(*p == 0) return; codeSymb = *p++;
+ if (*p == 0) return; asBinary = (*p++) != '0';
+ if (*p == 0) return; codeSymb = *p++;
// p == &COUNT
- if(*p == 0) return; param = strchr(p, ':');
+ if (*p == 0) return; param = strchr(p, ':');
// param == &SIZE
- if(param == NULL) return; *param++ = 0;
- if(*param == 0) return;
+ if (param == NULL) return; *param++ = 0;
+ if (*param == 0) return;
chunkCountx = atoi(p);
fileSize = atoi(param);
@@ -468,17 +468,17 @@ void FILEECHO::incomeRequest(char *param)
inSend = FALSE;
SkinPlaySound("RecvFile");
- int AutoMin = db_get_b(NULL,"SRFile","AutoMin",0);
- if(db_get_b(NULL,"SRFile","AutoAccept",0) && !db_get_b(hContact,"CList","NotOnList",0))
+ int AutoMin = db_get_b(NULL, "SRFile", "AutoMin", 0);
+ if (db_get_b(NULL, "SRFile", "AutoAccept", 0) && !db_get_b(hContact, "CList", "NotOnList", 0))
{
PostMessage(hDlg, WM_COMMAND, IDC_PLAY, 0);
- if(AutoMin)
+ if (AutoMin)
ShowWindow(hDlg, SW_SHOWMINIMIZED);
-// ShowWindow(hDlg, SW_MINIMIZE);
-// UpdateWindow(hDlg);
+ // ShowWindow(hDlg, SW_MINIMIZE);
+ // UpdateWindow(hDlg);
}
-// else
- if(!IsWindowVisible(hDlg) && !AutoMin)
+ // else
+ if (!IsWindowVisible(hDlg) && !AutoMin)
{
CLISTEVENT cle;
memset(&cle, 0, sizeof(cle));
@@ -496,7 +496,7 @@ void FILEECHO::incomeRequest(char *param)
void FILEECHO::cmdACCEPT()
{
- if(chunkCount == 0) return;
+ if (chunkCount == 0) return;
setState(STATE_OPERATE);
SetDlgItemText(hDlg, IDC_STATUS, Translate("Sending..."));
lastTimestamp = GetTickCount();
@@ -516,28 +516,28 @@ void FILEECHO::updateProgress()
//
void FILEECHO::onRecvTimer()
{
- if(chunkCount == 0) return;
+ if (chunkCount == 0) return;
char *buffer = (char*)malloc(1024);
char *p = buffer;
uchar prev_value;
uint indx, jndx;
-
+
KillTimer(hDlg, TIMER_SEND);
//
// Build response about successfully received chunks
//
indx = jndx = 0; prev_value = chunkAck[jndx];
- while(jndx < chunkCount)
+ while (jndx < chunkCount)
{
- if(chunkAck[jndx] != prev_value)
+ if (chunkAck[jndx] != prev_value)
{
- if(prev_value != CHUNK_ACK)
+ if (prev_value != CHUNK_ACK)
{
p = ltoax(p, indx);
- if(indx != jndx-1)
+ if (indx != jndx - 1)
{
*p++ = '-';
- p = ltoax(p, jndx-1);
+ p = ltoax(p, jndx - 1);
}
*p++ = ',';
}
@@ -546,25 +546,25 @@ void FILEECHO::onRecvTimer()
}
jndx++;
}
- if(prev_value != CHUNK_ACK)
+ if (prev_value != CHUNK_ACK)
{
p = ltoax(p, indx);
- if(indx != jndx-1)
+ if (indx != jndx - 1)
{
*p++ = '-';
- p = ltoax(p, jndx-1);
+ p = ltoax(p, jndx - 1);
}
}
*p = 0;
- if(*buffer == 0)
+ if (*buffer == 0)
{
char *msg = Translate("Received successfully");
SetDlgItemText(hDlg, IDC_STATUS, msg);
MakePopupMsg(hDlg, hContact, msg);
setState(STATE_FINISHED);
- if(db_get_b(NULL,"SRFile","AutoClose",0))
+ if (db_get_b(NULL, "SRFile", "AutoClose", 0))
{
- PostMessage(hDlg, WM_CLOSE, 0,0);
+ PostMessage(hDlg, WM_CLOSE, 0, 0);
CallService(MS_CLIST_REMOVEEVENT, hContact, 0);
}
SkinPlaySound("FileDone");
@@ -582,7 +582,7 @@ void FILEECHO::onRecvTimer()
//
void FILEECHO::onSendTimer()
{
- if(chunkCount == 0) return;
+ if (chunkCount == 0) return;
//
// perform request of acknowledge, if scheduled
//
@@ -590,32 +590,32 @@ void FILEECHO::onSendTimer()
//
// Search for next unsent chunk
//
- while(chunkIndx < chunkCount && chunkAck[chunkIndx] != CHUNK_UNSENT) chunkIndx++;
- if(iState == STATE_ACKREQ || chunkIndx == chunkCount)
+ while (chunkIndx < chunkCount && chunkAck[chunkIndx] != CHUNK_UNSENT) chunkIndx++;
+ if (iState == STATE_ACKREQ || chunkIndx == chunkCount)
{
SetDlgItemText(hDlg, IDC_STATUS, Translate("Requesting of missing chunks"));
setState(STATE_OPERATE);
sendCmd(0, CMD_END, "", NULL);
- chunkIndx = chunkCount+1;
+ chunkIndx = chunkCount + 1;
return;
}
- if(chunkIndx > chunkCount) return;
+ if (chunkIndx > chunkCount) return;
- uchar *buffer = (uchar*)malloc(chunkMaxLen*2);
+ uchar *buffer = (uchar*)malloc(chunkMaxLen * 2);
uchar *p = buffer;
uchar *data = lpData + chunkPos[chunkIndx];
- uchar *data_end = lpData + chunkPos[chunkIndx+1];
+ uchar *data_end = lpData + chunkPos[chunkIndx + 1];
ulong chksum = memcrc32(data, data_end - data, INITCRC);
- if(asBinary)
+ if (asBinary)
{
//
// Encoding data to transfer with symb. filtering
//
- while(data < data_end)
+ while (data < data_end)
{
uchar ch = *data++;
- if(ch == 0)
+ if (ch == 0)
{
*p++ = codeSymb; *p++ = '0';
}
@@ -630,12 +630,12 @@ void FILEECHO::onSendTimer()
}
else
{
- ptrA enc( mir_base64_encode(data, data_end - data));
- strncpy((char*)buffer, enc, chunkMaxLen*2);
+ ptrA enc(mir_base64_encode(data, data_end - data));
+ strncpy((char*)buffer, enc, chunkMaxLen * 2);
}
char prefix[128];
- mir_snprintf(prefix, SIZEOF(prefix), "%X,%X,%X>", chunkIndx+1, chunkPos[chunkIndx], chksum);
+ mir_snprintf(prefix, SIZEOF(prefix), "%X,%X,%X>", chunkIndx + 1, chunkPos[chunkIndx], chksum);
#ifdef DEBUG
overhead += mir_tstrlen((char*)buffer);
#endif
@@ -646,7 +646,7 @@ void FILEECHO::onSendTimer()
chunkIndx++; chunkSent++;
- if(chunkIndx == chunkCount)
+ if (chunkIndx == chunkCount)
setState(STATE_ACKREQ);
else
{
@@ -657,11 +657,11 @@ void FILEECHO::onSendTimer()
}
void FILEECHO::cmdDATA(char *param)
{
- if(chunkCount == 0) return;
+ if (chunkCount == 0) return;
chunkIndx = atolx(param); param++;
- if(chunkIndx-- == 0) return;
+ if (chunkIndx-- == 0) return;
uint filepos = atolx(param); param++;
- if(filepos >= fileSize) return;
+ if (filepos >= fileSize) return;
ulong chksum_local;
ulong chksum_remote = atolx(param); param++;
@@ -673,27 +673,27 @@ void FILEECHO::cmdDATA(char *param)
//
uchar *data = lpData + filepos;
uchar *data_end = lpData + fileSize;
- if(asBinary)
+ if (asBinary)
{
uchar ch;
- while(ch = *param++)
+ while (ch = *param++)
{
- if(ch == codeSymb)
+ if (ch == codeSymb)
{
- if((ch = *param++) == 0) goto cmdDATA_corrupted;
- switch(ch)
+ if ((ch = *param++) == 0) goto cmdDATA_corrupted;
+ switch (ch)
{
- case '+':
- ch = codeSymb;
- break;
- case '0':
- ch = 0;
- break;
- default:
- goto cmdDATA_corrupted;
+ case '+':
+ ch = codeSymb;
+ break;
+ case '0':
+ ch = 0;
+ break;
+ default:
+ goto cmdDATA_corrupted;
}
}
- if(data > data_end) goto cmdDATA_corrupted;
+ if (data > data_end) goto cmdDATA_corrupted;
*data++ = ch;
}
}
@@ -702,15 +702,15 @@ void FILEECHO::cmdDATA(char *param)
unsigned bufLen;
mir_ptr<BYTE> buf((BYTE*)mir_base64_decode(param, &bufLen));
memcpy(data, buf, min(bufLen, unsigned(data_end - data)));
- data += bufLen;
+ data += bufLen;
}
//
// let's check it up
//
chksum_local = memcrc32(lpData + filepos, data - (lpData + filepos), INITCRC);
- if(chksum_local == chksum_remote)
+ if (chksum_local == chksum_remote)
{
- if(chunkAck[chunkIndx] != CHUNK_ACK) chunkSent++;
+ if (chunkAck[chunkIndx] != CHUNK_ACK) chunkSent++;
chunkAck[chunkIndx] = CHUNK_ACK;
//chunkPos[chunkIndx++] = filepos;
}
@@ -728,12 +728,12 @@ void FILEECHO::cmdDACK(char *param)
{
uint indx, jndx;
- if(chunkCount == 0) return;
+ if (chunkCount == 0) return;
memset(chunkAck, CHUNK_ACK, sizeof(uchar)*chunkCount);
- if(*param == 'x')
- //
- // All chunks has been received successfully
- //
+ if (*param == 'x')
+ //
+ // All chunks has been received successfully
+ //
{
char *msg = Translate("Sent successfully");
SetDlgItemText(hDlg, IDC_STATUS, msg);
@@ -751,26 +751,26 @@ void FILEECHO::cmdDACK(char *param)
//
// format: chunk1, chunk3-chunk10, etc..
//
- while(*param)
+ while (*param)
{
indx = atolx(param);
- if(*param == '-')
+ if (*param == '-')
{
param++; jndx = atolx(param);
}
else
jndx = indx;
- if(*param == 0 || *param == ',')
+ if (*param == 0 || *param == ',')
{
- for(uint p = indx; p <= jndx; p++)
+ for (uint p = indx; p <= jndx; p++)
{
- if(p < chunkCount)
+ if (p < chunkCount)
{
chunkAck[p] = CHUNK_UNSENT;
chunkSent--;
}
}
- if(*param == ',')
+ if (*param == ',')
param++;
}
}
@@ -786,79 +786,79 @@ void FILEECHO::cmdDACK(char *param)
void FILEECHO::perform(char *str)
{
int msgId = getMsgId(str);
- if(msgId == -1)
+ if (msgId == -1)
{
MakePopupMsg(hDlg, hContact, Translate("Unknown command for \"File As Message\" was received"));
return;
}
- if(inSend)
- switch(msgId)
- {
- case CMD_REQ:
- if(MessageBox(hDlg, Translate("Incoming file request. Do you want to proceed?"),
- Translate(SERVICE_TITLE), MB_YESNO | MB_ICONWARNING) == IDYES)
- {
- SetDlgItemText(hDlg, IDC_STATUS, "");
- SendMessage(hDlg, WM_COMMAND, IDC_STOP, 0);
+ if (inSend)
+ switch (msgId)
+ {
+ case CMD_REQ:
+ if (MessageBox(hDlg, Translate("Incoming file request. Do you want to proceed?"),
+ Translate(SERVICE_TITLE), MB_YESNO | MB_ICONWARNING) == IDYES)
+ {
+ SetDlgItemText(hDlg, IDC_STATUS, "");
+ SendMessage(hDlg, WM_COMMAND, IDC_STOP, 0);
- incomeRequest(str+1);
- updateTitle();
- break;
- }
- break;
- case CMD_ACCEPT:
- cmdACCEPT();
+ incomeRequest(str + 1);
+ updateTitle();
break;
- case CMD_CANCEL:
+ }
+ break;
+ case CMD_ACCEPT:
+ cmdACCEPT();
+ break;
+ case CMD_CANCEL:
+ {
+ if (iState & (STATE_PRERECV | STATE_REQSENT | STATE_OPERATE | STATE_ACKREQ | STATE_PAUSED))
{
- if(iState & (STATE_PRERECV|STATE_REQSENT|STATE_OPERATE|STATE_ACKREQ|STATE_PAUSED))
- {
- char *msg = Translate("Canceled by remote user");
- SetDlgItemText(hDlg, IDC_STATUS, msg);
- MakePopupMsg(hDlg, hContact, msg);
- destroyTransfer();
- setState(STATE_CANCELLED);
- }
- break;
+ char *msg = Translate("Canceled by remote user");
+ SetDlgItemText(hDlg, IDC_STATUS, msg);
+ MakePopupMsg(hDlg, hContact, msg);
+ destroyTransfer();
+ setState(STATE_CANCELLED);
}
- case CMD_DACK:
- cmdDACK(str+1);
- break;
+ break;
}
+ case CMD_DACK:
+ cmdDACK(str + 1);
+ break;
+ }
else
- switch(msgId)
+ switch (msgId)
+ {
+ case CMD_CANCEL:
{
- case CMD_CANCEL:
+ if (iState & (STATE_PRERECV | STATE_REQSENT | STATE_OPERATE | STATE_ACKREQ | STATE_PAUSED))
{
- if(iState & (STATE_PRERECV|STATE_REQSENT|STATE_OPERATE|STATE_ACKREQ|STATE_PAUSED))
- {
- char *msg = Translate("Canceled by remote user");
- SetDlgItemText(hDlg, IDC_STATUS, msg);
- MakePopupMsg(hDlg, hContact, msg);
- destroyTransfer();
- setState(STATE_CANCELLED);
- }
- break;
+ char *msg = Translate("Canceled by remote user");
+ SetDlgItemText(hDlg, IDC_STATUS, msg);
+ MakePopupMsg(hDlg, hContact, msg);
+ destroyTransfer();
+ setState(STATE_CANCELLED);
}
- case CMD_REQ:
- if(chunkCount)
- {
- if(MessageBox(hDlg, Translate("New incoming file request. Do you want to proceed?"),
- Translate(SERVICE_TITLE), MB_YESNO | MB_ICONWARNING) != IDYES)
- break;
- //sendCmd(0, CMD_CANCEL, "", NULL);
- destroyTransfer();
- }
- SetDlgItemText(hDlg, IDC_STATUS, "");
- incomeRequest(str+1);
- break;
- case CMD_DATA:
- cmdDATA(str+1);
- break;
- case CMD_END:
- cmdEND();
- break;
- };
+ break;
+ }
+ case CMD_REQ:
+ if (chunkCount)
+ {
+ if (MessageBox(hDlg, Translate("New incoming file request. Do you want to proceed?"),
+ Translate(SERVICE_TITLE), MB_YESNO | MB_ICONWARNING) != IDYES)
+ break;
+ //sendCmd(0, CMD_CANCEL, "", NULL);
+ destroyTransfer();
+ }
+ SetDlgItemText(hDlg, IDC_STATUS, "");
+ incomeRequest(str + 1);
+ break;
+ case CMD_DATA:
+ cmdDATA(str + 1);
+ break;
+ case CMD_END:
+ cmdEND();
+ break;
+ };
};
int FILEECHO::sendCmd(int id, int cmd, char *szParam, char *szPrefix)
@@ -866,18 +866,18 @@ int FILEECHO::sendCmd(int id, int cmd, char *szParam, char *szPrefix)
char *buf;
int retval;
int buflen = (int)_tcslen(szServicePrefix) + (int)_tcslen(szParam) + 2;
- if(szPrefix != NULL)
+ if (szPrefix != NULL)
buflen += (int)_tcslen(szPrefix);
-
+
buf = (char*)malloc(buflen);
- if(szPrefix == NULL)
+ if (szPrefix == NULL)
mir_snprintf(buf, buflen, "%s%c%s", szServicePrefix, cCmdList[cmd], szParam);
else
mir_snprintf(buf, buflen, "%s%c%s%s", szServicePrefix, cCmdList[cmd], szPrefix, szParam);
retval = CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)buf);
free(buf);
updateProgress();
- return retval;
+ return retval;
}
@@ -887,7 +887,7 @@ void CreateDirectoryTree(char *szDir)
char *pszLastBackslash, szTestDir[MAX_PATH];
strncpy_s(szTestDir, szDir, _TRUNCATE);
- if((dwAttributes = GetFileAttributes(szTestDir)) != 0xffffffff && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
+ if ((dwAttributes = GetFileAttributes(szTestDir)) != 0xffffffff && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
return;
pszLastBackslash = strrchr(szTestDir, '\\');
if (pszLastBackslash == NULL) {
@@ -901,332 +901,324 @@ void CreateDirectoryTree(char *szDir)
LRESULT CALLBACK ProgressWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- switch(uMsg)
+ switch (uMsg)
{
- case WM_NCPAINT:
- return 0;
- case WM_PAINT:
+ case WM_NCPAINT:
+ return 0;
+ case WM_PAINT:
+ {
+ HDC hdc;
+ PAINTSTRUCT ps;
+ RECT rc;
+ HRGN hrgn;
+ HBRUSH frameBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
+ struct FILEECHO *dat;
+
+ dat = (struct FILEECHO*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA);
+ //if(dat == NULL)
+ // return CallSubclassed(hwnd, uMsg, wParam, lParam);
+ GetClientRect(hwnd, &rc);
+ if (dat == NULL || dat->chunkCount == 0)
{
- HDC hdc;
- PAINTSTRUCT ps;
- RECT rc;
- HRGN hrgn;
- HBRUSH frameBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
- struct FILEECHO *dat;
-
- dat = (struct FILEECHO*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA);
- //if(dat == NULL)
- // return CallSubclassed(hwnd, uMsg, wParam, lParam);
- GetClientRect(hwnd, &rc);
- if(dat == NULL || dat->chunkCount == 0)
- {
- COLORREF colour;
- HBRUSH hbr;
+ COLORREF colour;
+ HBRUSH hbr;
- if(dat == NULL || dat->iState != STATE_FINISHED)
- {
- hbr = (HBRUSH)(COLOR_3DFACE+1);
- }
- else
- {
- colour = dat->rgbRecv;
- hbr = CreateSolidBrush(colour);
- }
- hdc=BeginPaint(hwnd,&ps);
- FillRect(hdc, &rc, hbr);
- FrameRect(hdc, &rc, frameBrush);
- if(hbr != (HBRUSH)(COLOR_3DFACE+1))
- DeleteObject(hbr);
- EndPaint(hwnd,&ps);
- return 0;
+ if (dat == NULL || dat->iState != STATE_FINISHED)
+ {
+ hbr = (HBRUSH)(COLOR_3DFACE + 1);
+ }
+ else
+ {
+ colour = dat->rgbRecv;
+ hbr = CreateSolidBrush(colour);
}
+ hdc = BeginPaint(hwnd, &ps);
+ FillRect(hdc, &rc, hbr);
+ FrameRect(hdc, &rc, frameBrush);
+ if (hbr != (HBRUSH)(COLOR_3DFACE + 1))
+ DeleteObject(hbr);
+ EndPaint(hwnd, &ps);
+ return 0;
+ }
- hrgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
-
- hdc=BeginPaint(hwnd,&ps);
- SelectClipRgn(hdc, hrgn);
-
- RECT rc2 = rc;
- //uint sliceWidth = (rc.right - rc.left) / dat->chunkCount;
- float sliceWidth = (float)((float)(rc.right - rc.left) / (float)dat->chunkCount);
- float dx = (float)rc2.left;
- for(uint indx = 0; indx < dat->chunkCount; indx++)
- {
- HBRUSH hbr;
- COLORREF colour;
- if(dat->inSend && indx == dat->chunkIndx)
- colour = dat->rgbToSend;
- else
- switch(dat->chunkAck[indx])
- {
- case CHUNK_UNSENT:
- colour = dat->rgbUnSent;
- break;
- case CHUNK_SENT:
- colour = dat->rgbSent;
- break;
- case CHUNK_ACK:
- colour = dat->rgbRecv;
- break;
- }
- /*
- if(indx == 5) colour = RGB(255,64,64);
- else if(indx < 2) colour = RGB(64,255,64);
- else if(indx < 4) colour = RGB(255,255,64);
- else colour = RGB(128,128,128);
- //*/
- if(indx == dat->chunkCount-1)
- rc2.right = rc.right;
- hbr = CreateSolidBrush(colour);
- rc2.left = (int)dx;
- rc2.right = (int)(dx + sliceWidth);
- FillRect(hdc, &rc2, hbr);
- FrameRect(hdc, &rc2, frameBrush);
- DeleteObject(hbr);
- dx += sliceWidth-1;
- }
- if(rc2.right < rc.right)
- {
- rc2.left = rc2.right;
- rc2.right = rc.right;
- FillRect(hdc, &rc2, (HBRUSH)(COLOR_3DFACE+1));
- }
- //FrameRect(hdc, &rc, (HBRUSH)(COLOR_3DLIGHT+1));
- //OffsetRect(&rc, 1,1);
- //FrameRect(hdc, &rc, (HBRUSH)(COLOR_BTNTEXT+1));
- //FrameRect(hdc, &rc, (HBRUSH)(COLOR_BTNTEXT+1));
- EndPaint(hwnd,&ps);
+ hrgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
- DeleteObject(hrgn);
+ hdc = BeginPaint(hwnd, &ps);
+ SelectClipRgn(hdc, hrgn);
- return 0;
+ RECT rc2 = rc;
+ //uint sliceWidth = (rc.right - rc.left) / dat->chunkCount;
+ float sliceWidth = (float)((float)(rc.right - rc.left) / (float)dat->chunkCount);
+ float dx = (float)rc2.left;
+ for (uint indx = 0; indx < dat->chunkCount; indx++)
+ {
+ HBRUSH hbr;
+ COLORREF colour;
+ if (dat->inSend && indx == dat->chunkIndx)
+ colour = dat->rgbToSend;
+ else
+ switch (dat->chunkAck[indx])
+ {
+ case CHUNK_UNSENT:
+ colour = dat->rgbUnSent;
+ break;
+ case CHUNK_SENT:
+ colour = dat->rgbSent;
+ break;
+ case CHUNK_ACK:
+ colour = dat->rgbRecv;
+ break;
+ }
+ hbr = CreateSolidBrush(colour);
+ rc2.left = (int)dx;
+ rc2.right = (int)(dx + sliceWidth);
+ FillRect(hdc, &rc2, hbr);
+ FrameRect(hdc, &rc2, frameBrush);
+ DeleteObject(hbr);
+ dx += sliceWidth - 1;
+ }
+ if (rc2.right < rc.right)
+ {
+ rc2.left = rc2.right;
+ rc2.right = rc.right;
+ FillRect(hdc, &rc2, (HBRUSH)(COLOR_3DFACE + 1));
}
+ //FrameRect(hdc, &rc, (HBRUSH)(COLOR_3DLIGHT+1));
+ //OffsetRect(&rc, 1,1);
+ //FrameRect(hdc, &rc, (HBRUSH)(COLOR_BTNTEXT+1));
+ //FrameRect(hdc, &rc, (HBRUSH)(COLOR_BTNTEXT+1));
+ EndPaint(hwnd, &ps);
+
+ DeleteObject(hrgn);
+
+ return 0;
+ }
}
return mir_callNextSubclass(hwnd, ProgressWndProc, uMsg, wParam, lParam);
}
-INT_PTR CALLBACK DialogProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
+INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
struct FILEECHO *dat = (struct FILEECHO*)GetWindowLongPtr(hDlg, GWLP_USERDATA);
HWND hwndStatus = NULL;
- switch( uMsg )
+ switch (uMsg)
{
- case WM_INITDIALOG:
- {
- dat = (FILEECHO*)lParam;
- dat->hDlg = hDlg;
+ case WM_INITDIALOG:
+ {
+ dat = (FILEECHO*)lParam;
+ dat->hDlg = hDlg;
- dat->updateTitle();
+ dat->updateTitle();
- hwndStatus = CreateStatusWindow(WS_CHILD|WS_VISIBLE, "", hDlg, IDC_STATUS);
- SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)dat);
- WindowList_Add(hFileList, hDlg, dat->hContact);
- SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcons[ICON_MAIN]);
- SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcons[ICON_MAIN]);
- SendDlgItemMessage(hDlg, IDC_STOP, BUTTONADDTOOLTIP,(WPARAM)Translate(hint_controls[ICON_STOP]),0);
+ hwndStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE, "", hDlg, IDC_STATUS);
+ SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)dat);
+ WindowList_Add(hFileList, hDlg, dat->hContact);
+ SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcons[ICON_MAIN]);
+ SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcons[ICON_MAIN]);
+ SendDlgItemMessage(hDlg, IDC_STOP, BUTTONADDTOOLTIP, (WPARAM)Translate(hint_controls[ICON_STOP]), 0);
- //SetDlgItemText(hDlg, IDC_FILENAME, "C:\\!Developer\\!Miranda\\miranda\\bin\\release\\emo\\biggrin.gif");
+ //SetDlgItemText(hDlg, IDC_FILENAME, "C:\\!Developer\\!Miranda\\miranda\\bin\\release\\emo\\biggrin.gif");
- mir_subclassWindow(GetDlgItem(hDlg, IDC_PROGRESS), ProgressWndProc);
-
- SendDlgItemMessage(hDlg, IDC_PLAY, BUTTONSETASFLATBTN,0,0);
- SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcons[ICON_PLAY]);
- SendDlgItemMessage(hDlg, IDC_STOP, BUTTONSETASFLATBTN,0,0);
- SendDlgItemMessage(hDlg, IDC_STOP, BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcons[ICON_STOP]);
- dat->setState(STATE_IDLE);
+ mir_subclassWindow(GetDlgItem(hDlg, IDC_PROGRESS), ProgressWndProc);
- //ShowWindow(hDlg, SW_HIDE);
- //UpdateWindow(hDlg);
+ SendDlgItemMessage(hDlg, IDC_PLAY, BUTTONSETASFLATBTN, 0, 0);
+ SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcons[ICON_PLAY]);
+ SendDlgItemMessage(hDlg, IDC_STOP, BUTTONSETASFLATBTN, 0, 0);
+ SendDlgItemMessage(hDlg, IDC_STOP, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcons[ICON_STOP]);
+ dat->setState(STATE_IDLE);
- if(dat->inSend)
- PostMessage(hDlg, WM_COMMAND, IDC_BROWSE, NULL);
+ //ShowWindow(hDlg, SW_HIDE);
+ //UpdateWindow(hDlg);
- return FALSE;
- }
- case WM_FE_MESSAGE:
- {
- dat->perform((char *)lParam);
- delete (char *)lParam;
+ if (dat->inSend)
+ PostMessage(hDlg, WM_COMMAND, IDC_BROWSE, NULL);
- return TRUE;
- }
- case WM_FE_SKINCHANGE:
- SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcons[ICON_MAIN]);
- SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcons[ICON_MAIN]);
- dat->setState(dat->iState);
- SendDlgItemMessage(hDlg, IDC_STOP, BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcons[ICON_STOP]);
+ return FALSE;
+ }
+ case WM_FE_MESSAGE:
+ {
+ dat->perform((char *)lParam);
+ delete (char *)lParam;
- break;
- case WM_FE_STATUSCHANGE:
+ return TRUE;
+ }
+ case WM_FE_SKINCHANGE:
+ SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcons[ICON_MAIN]);
+ SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcons[ICON_MAIN]);
+ dat->setState(dat->iState);
+ SendDlgItemMessage(hDlg, IDC_STOP, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcons[ICON_STOP]);
+
+ break;
+ case WM_FE_STATUSCHANGE:
+ {
+ char *szProto = GetContactProto(dat->hContact);
+ if (szProto)
{
- char *szProto = GetContactProto(dat->hContact);
- if (szProto)
+ int dwStatus = db_get_w(dat->hContact, szProto, "Status", ID_STATUS_OFFLINE);
+ if (dat->inSend && dwStatus != dat->contactStatus)
{
- int dwStatus = db_get_w(dat->hContact,szProto,"Status",ID_STATUS_OFFLINE);
- if(dat->inSend && dwStatus != dat->contactStatus)
+ if (dat->contactStatus == ID_STATUS_OFFLINE)
{
- if(dat->contactStatus == ID_STATUS_OFFLINE)
+ dat->chunkIndx = dat->chunkCount;
+ }
+ else
+ if (dwStatus == ID_STATUS_OFFLINE)
{
- dat->chunkIndx = dat->chunkCount;
- }
- else
- if(dwStatus == ID_STATUS_OFFLINE)
+ if (dat->iState & (STATE_OPERATE | STATE_ACKREQ))
{
- if(dat->iState & (STATE_OPERATE|STATE_ACKREQ))
- {
- char *msg = Translate("File transfer is paused because of dropped connection");
- SetDlgItemText(hDlg, IDC_STATUS, msg);
- MakePopupMsg(dat->hDlg, dat->hContact, msg);
- dat->setState(STATE_PAUSED);
- KillTimer(hDlg, TIMER_SEND);
- }
+ char *msg = Translate("File transfer is paused because of dropped connection");
+ SetDlgItemText(hDlg, IDC_STATUS, msg);
+ MakePopupMsg(dat->hDlg, dat->hContact, msg);
+ dat->setState(STATE_PAUSED);
+ KillTimer(hDlg, TIMER_SEND);
}
- }
- dat->contactStatus = dwStatus;
+ }
}
- return TRUE;
+ dat->contactStatus = dwStatus;
}
- case WM_DESTROY:
- WindowList_Remove(hFileList, hDlg);
- DestroyWindow(hwndStatus);
- delete dat;
-
- return TRUE;
-
- case WM_TIMER:
- if(dat->inSend)
- dat->onSendTimer();
+ return TRUE;
+ }
+ case WM_DESTROY:
+ WindowList_Remove(hFileList, hDlg);
+ DestroyWindow(hwndStatus);
+ delete dat;
+
+ return TRUE;
+
+ case WM_TIMER:
+ if (dat->inSend)
+ dat->onSendTimer();
+ else
+ dat->onRecvTimer();
+ break;
+ case WM_COMMAND:
+ switch (wParam)
+ {
+ case IDC_PLAY:
+ {
+ if (dat->iState & (STATE_IDLE | STATE_FINISHED | STATE_CANCELLED | STATE_PRERECV))
+ {
+ int len = GetWindowTextLength(GetDlgItem(hDlg, IDC_FILENAME)) + 1;
+ free(dat->filename);
+ dat->filename = (char*)malloc(len);
+ GetDlgItemText(hDlg, IDC_FILENAME, dat->filename, len);
+ if (dat->inSend)
+ // Send offer to remote side
+ {
+ dat->sendReq();
+ }
+ else
+ // Send the accept and starting to receive
+ {
+ char buff[MAX_PATH];
+ char *bufname;
+
+ GetFullPathName(dat->filename, sizeof(buff), buff, &bufname);
+ *bufname = 0;
+ CreateDirectoryTree(buff);
+ if (!dat->createTransfer())
+ {
+ SetDlgItemText(hDlg, IDC_STATUS, Translate("Failed on file initialization"));
+ break;
+ }
+ dat->sendCmd(0, CMD_ACCEPT, "");
+ dat->lastTimestamp = GetTickCount();
+ SetDlgItemText(hDlg, IDC_STATUS, Translate("Receiving..."));
+ dat->setState(STATE_OPERATE);
+ }
+ }
else
- dat->onRecvTimer();
- break;
- case WM_COMMAND:
- switch(wParam)
{
- case IDC_PLAY:
+ if (dat->inSend)
{
- if(dat->iState & (STATE_IDLE|STATE_FINISHED|STATE_CANCELLED|STATE_PRERECV))
+ if (dat->iState == STATE_OPERATE)
{
- int len = GetWindowTextLength(GetDlgItem(hDlg, IDC_FILENAME))+1;
- free(dat->filename);
- dat->filename = (char*)malloc(len);
- GetDlgItemText(hDlg, IDC_FILENAME, dat->filename, len);
- if(dat->inSend)
- // Send offer to remote side
- {
- dat->sendReq();
- }
- else
- // Send the accept and starting to receive
- {
- char buff[MAX_PATH];
- char *bufname;
-
- GetFullPathName(dat->filename, sizeof(buff), buff, &bufname);
- *bufname = 0;
- CreateDirectoryTree(buff);
- if(!dat->createTransfer())
- {
- SetDlgItemText(hDlg, IDC_STATUS, Translate("Failed on file initialization"));
- break;
- }
- dat->sendCmd(0, CMD_ACCEPT, "");
- dat->lastTimestamp = GetTickCount();
- SetDlgItemText(hDlg, IDC_STATUS, Translate("Receiving..."));
- dat->setState(STATE_OPERATE);
- }
+ SetDlgItemText(hDlg, IDC_STATUS, Translate("Paused..."));
+ dat->setState(STATE_PAUSED);
+ KillTimer(hDlg, TIMER_SEND);
}
else
{
- if(dat->inSend)
- {
- if(dat->iState == STATE_OPERATE)
- {
- SetDlgItemText(hDlg, IDC_STATUS, Translate("Paused..."));
- dat->setState(STATE_PAUSED);
- KillTimer(hDlg, TIMER_SEND);
- }
- else
- {
- SetDlgItemText(hDlg, IDC_STATUS, Translate("Sending..."));
- if(dat->chunkIndx < dat->chunkCount)
- dat->setState(STATE_OPERATE);
- else
- dat->setState(STATE_ACKREQ);
- PostMessage(hDlg, WM_TIMER, 0,0);
- //dat->onRecvTimer();
- //SetTimer(hDlg, TIMER_SEND, dwSendInterval, NULL);
- }
- }
+ SetDlgItemText(hDlg, IDC_STATUS, Translate("Sending..."));
+ if (dat->chunkIndx < dat->chunkCount)
+ dat->setState(STATE_OPERATE);
else
- {
- SetDlgItemText(hDlg, IDC_STATUS, Translate("Synchronizing..."));
dat->setState(STATE_ACKREQ);
- PostMessage(hDlg, WM_TIMER, 0,0);
- //dat->onRecvTimer();
- //SetTimer(hDlg, TIMER_SEND, dwSendInterval, 0);
- }
- break;
+ PostMessage(hDlg, WM_TIMER, 0, 0);
+ //dat->onRecvTimer();
+ //SetTimer(hDlg, TIMER_SEND, dwSendInterval, NULL);
}
- break;
}
- case IDC_BROWSE:
+ else
{
- char str[MAX_PATH];
- OPENFILENAME ofn;
-
- memset(&ofn, 0, sizeof(ofn));
- *str = 0;
- GetDlgItemText(hDlg, IDC_FILENAME, str, SIZEOF(str));
- //ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
- ofn.lStructSize = sizeof(ofn);
- ofn.hwndOwner = hDlg;
- //ofn.lpstrFilter = "*.*";
- ofn.lpstrFile = str;
- ofn.Flags = dat->inSend?OFN_FILEMUSTEXIST:0;
- ofn.lpstrTitle = dat->inSend?Translate("Select a file"):Translate("Save as");
- ofn.nMaxFile = SIZEOF(str);
- ofn.nMaxFileTitle = MAX_PATH;
- if(!GetOpenFileName(&ofn)) break;
- if(!dat->inSend && dat->iState == STATE_FINISHED) break;
- SetDlgItemText(hDlg, IDC_FILENAME, str);
-
- int size = RetrieveFileSize(str);
- if(size != -1)
- mir_snprintf(str, SIZEOF(str), Translate("Size: %d bytes"), size);
- else
- strncpy_s(str, Translate("Can't get a file size"), _TRUNCATE);
- SetDlgItemText(hDlg, IDC_FILESIZE, str);
-
- break;
+ SetDlgItemText(hDlg, IDC_STATUS, Translate("Synchronizing..."));
+ dat->setState(STATE_ACKREQ);
+ PostMessage(hDlg, WM_TIMER, 0, 0);
+ //dat->onRecvTimer();
+ //SetTimer(hDlg, TIMER_SEND, dwSendInterval, 0);
}
-
- case IDC_STOP:
- case IDCANCEL:
- if(dat->iState == STATE_PRERECV)
- {
- SetDlgItemText(hDlg, IDC_STATUS, Translate("Canceled by user"));
- dat->sendCmd(0, CMD_CANCEL, "", NULL);
- dat->setState(STATE_CANCELLED);
- }
- if(dat->chunkCount)
- {
- if(MessageBox(hDlg, Translate("Transfer is in progress. Do you really want to close?"),
- Translate(SERVICE_TITLE), MB_ICONWARNING|MB_YESNO|MB_DEFBUTTON2) == IDYES)
- {
- SetDlgItemText(hDlg, IDC_STATUS, Translate("Canceled by user"));
- dat->setState(STATE_CANCELLED);
- dat->sendCmd(0, CMD_CANCEL, "", NULL);
- dat->destroyTransfer();
- if(wParam == IDCANCEL)
- DestroyWindow(hDlg);
- }
- }
- else
- if(wParam == IDCANCEL)
- DestroyWindow(hDlg);
- break;//return TRUE;
+ break;
}
break;
+ }
+ case IDC_BROWSE:
+ {
+ char str[MAX_PATH];
+ OPENFILENAME ofn;
+
+ memset(&ofn, 0, sizeof(ofn));
+ *str = 0;
+ GetDlgItemText(hDlg, IDC_FILENAME, str, SIZEOF(str));
+ //ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
+ ofn.lStructSize = sizeof(ofn);
+ ofn.hwndOwner = hDlg;
+ //ofn.lpstrFilter = "*.*";
+ ofn.lpstrFile = str;
+ ofn.Flags = dat->inSend ? OFN_FILEMUSTEXIST : 0;
+ ofn.lpstrTitle = dat->inSend ? Translate("Select a file") : Translate("Save as");
+ ofn.nMaxFile = SIZEOF(str);
+ ofn.nMaxFileTitle = MAX_PATH;
+ if (!GetOpenFileName(&ofn)) break;
+ if (!dat->inSend && dat->iState == STATE_FINISHED) break;
+ SetDlgItemText(hDlg, IDC_FILENAME, str);
+
+ int size = RetrieveFileSize(str);
+ if (size != -1)
+ mir_snprintf(str, SIZEOF(str), Translate("Size: %d bytes"), size);
+ else
+ strncpy_s(str, Translate("Can't get a file size"), _TRUNCATE);
+ SetDlgItemText(hDlg, IDC_FILESIZE, str);
+
+ break;
+ }
+
+ case IDC_STOP:
+ case IDCANCEL:
+ if (dat->iState == STATE_PRERECV)
+ {
+ SetDlgItemText(hDlg, IDC_STATUS, Translate("Canceled by user"));
+ dat->sendCmd(0, CMD_CANCEL, "", NULL);
+ dat->setState(STATE_CANCELLED);
+ }
+ if (dat->chunkCount)
+ {
+ if (MessageBox(hDlg, Translate("Transfer is in progress. Do you really want to close?"),
+ Translate(SERVICE_TITLE), MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2) == IDYES)
+ {
+ SetDlgItemText(hDlg, IDC_STATUS, Translate("Canceled by user"));
+ dat->setState(STATE_CANCELLED);
+ dat->sendCmd(0, CMD_CANCEL, "", NULL);
+ dat->destroyTransfer();
+ if (wParam == IDCANCEL)
+ DestroyWindow(hDlg);
+ }
+ }
+ else
+ if (wParam == IDCANCEL)
+ DestroyWindow(hDlg);
+ break;//return TRUE;
+ }
+ break;
}
return FALSE;