From ee445e9c96823f95a9a8fc47cb8a1bb40c706bec Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 24 Jun 2014 21:10:28 +0000 Subject: code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@9572 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/core/stdfile/commonheaders.h | 1 + src/core/stdfile/file.cpp | 11 +- src/core/stdfile/fileexistsdlg.cpp | 280 ++++++------ src/core/stdfile/fileopts.cpp | 240 +++++------ src/core/stdfile/filerecvdlg.cpp | 77 ++-- src/core/stdfile/filesenddlg.cpp | 4 +- src/core/stdfile/filexferdlg.cpp | 862 ++++++++++++++++++------------------- src/core/stdfile/ftmanager.cpp | 7 +- 8 files changed, 736 insertions(+), 746 deletions(-) diff --git a/src/core/stdfile/commonheaders.h b/src/core/stdfile/commonheaders.h index f3600efc5e..058ddb124d 100644 --- a/src/core/stdfile/commonheaders.h +++ b/src/core/stdfile/commonheaders.h @@ -75,6 +75,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include "version.h" diff --git a/src/core/stdfile/file.cpp b/src/core/stdfile/file.cpp index e7d92eb921..97b7d9549d 100644 --- a/src/core/stdfile/file.cpp +++ b/src/core/stdfile/file.cpp @@ -54,7 +54,7 @@ TCHAR* GetContactID(MCONTACT hContact) case CNFT_ASCIIZ: return (TCHAR *)ci.pszVal; case CNFT_DWORD: - return _itot(ci.dVal, (TCHAR *)mir_alloc(sizeof(TCHAR)* 32), 10); + return _itot(ci.dVal, (TCHAR *)mir_alloc(sizeof(TCHAR) * 32), 10); } } } @@ -179,7 +179,10 @@ void GetSensiblyFormattedSize(__int64 size, TCHAR *szOut, int cchOut, int unitsO else if (size < 1024 * 1024 * 1024) unitsOverride = UNITS_MBPOINT2; else unitsOverride = UNITS_GBPOINT3; } - if (unitsUsed) *unitsUsed = unitsOverride; + + if (unitsUsed) + *unitsUsed = unitsOverride; + switch (unitsOverride) { case UNITS_BYTES: mir_sntprintf(szOut, cchOut, _T("%u%s%s"), (int)size, appendUnits ? _T(" ") : _T(""), appendUnits ? TranslateT("bytes") : _T("")); break; case UNITS_KBPOINT1: mir_sntprintf(szOut, cchOut, _T("%.1lf%s"), size / 1024.0, appendUnits ? _T(" KB") : _T("")); break; @@ -305,8 +308,8 @@ static int SRFilePreBuildMenu(WPARAM wParam, LPARAM) bool bEnabled = false; char *szProto = GetContactProto(wParam); if (szProto != NULL) { - if ( CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_FILESEND) { - if ( CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_OFFLINEFILES) + if (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_FILESEND) { + if (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_OFFLINEFILES) bEnabled = true; else if (db_get_w(wParam, szProto, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) bEnabled = true; diff --git a/src/core/stdfile/fileexistsdlg.cpp b/src/core/stdfile/fileexistsdlg.cpp index 72930fe482..1e604c2947 100644 --- a/src/core/stdfile/fileexistsdlg.cpp +++ b/src/core/stdfile/fileexistsdlg.cpp @@ -60,10 +60,10 @@ static void DoAnnoyingShellCommand(HWND hwnd, const TCHAR *szFilename, int cmd, IShellFolder *pFileFolder; for (pidl = pCurrentIdl;;) { - pidlNext = (ITEMIDLIST*)((PBYTE)pidl+pidl->mkid.cb); + pidlNext = (ITEMIDLIST*)((PBYTE)pidl + pidl->mkid.cb); if (pidlNext->mkid.cb == 0) { - pidlFilename = (ITEMIDLIST*)CoTaskMemAlloc(pidl->mkid.cb+sizeof(pidl->mkid.cb)); - CopyMemory(pidlFilename, pidl, pidl->mkid.cb+sizeof(pidl->mkid.cb)); + pidlFilename = (ITEMIDLIST*)CoTaskMemAlloc(pidl->mkid.cb + sizeof(pidl->mkid.cb)); + CopyMemory(pidlFilename, pidl, pidl->mkid.cb + sizeof(pidl->mkid.cb)); pidl->mkid.cb = 0; break; } @@ -72,33 +72,33 @@ static void DoAnnoyingShellCommand(HWND hwnd, const TCHAR *szFilename, int cmd, if (pDesktopFolder->BindToObject(pCurrentIdl, NULL, IID_IShellFolder, (void**)&pFileFolder) == NOERROR) { IContextMenu *pContextMenu; if (pFileFolder->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST*)&pidlFilename, IID_IContextMenu, NULL, (void**)&pContextMenu) == NOERROR) { - switch(cmd) { - case C_PROPERTIES: - { CMINVOKECOMMANDINFO ici = {0}; + switch (cmd) { + case C_PROPERTIES: + { + CMINVOKECOMMANDINFO ici = { 0 }; ici.cbSize = sizeof(ici); ici.hwnd = hwnd; ici.lpVerb = "properties"; ici.nShow = SW_SHOW; pContextMenu->InvokeCommand(&ici); - break; } - case C_CONTEXTMENU: - { - HMENU hMenu = CreatePopupMenu(); - if (SUCCEEDED(pContextMenu->QueryContextMenu(hMenu, 0, 1000, 65535, (GetKeyState(VK_SHIFT)&0x8000?CMF_EXTENDEDVERBS:0)|CMF_NORMAL))) { - int cmd = TrackPopupMenu(hMenu, TPM_RETURNCMD, ptCursor->x, ptCursor->y, 0, hwnd, NULL); - if (cmd) { - CMINVOKECOMMANDINFO ici = {0}; - ici.cbSize = sizeof(ici); - ici.hwnd = hwnd; - ici.lpVerb = MAKEINTRESOURCEA(cmd-1000); - ici.nShow = SW_SHOW; - pContextMenu->InvokeCommand(&ici); - } + break; + + case C_CONTEXTMENU: + HMENU hMenu = CreatePopupMenu(); + if (SUCCEEDED(pContextMenu->QueryContextMenu(hMenu, 0, 1000, 65535, (GetKeyState(VK_SHIFT) & 0x8000 ? CMF_EXTENDEDVERBS : 0) | CMF_NORMAL))) { + int cmd = TrackPopupMenu(hMenu, TPM_RETURNCMD, ptCursor->x, ptCursor->y, 0, hwnd, NULL); + if (cmd) { + CMINVOKECOMMANDINFO ici = { 0 }; + ici.cbSize = sizeof(ici); + ici.hwnd = hwnd; + ici.lpVerb = MAKEINTRESOURCEA(cmd - 1000); + ici.nShow = SW_SHOW; + pContextMenu->InvokeCommand(&ici); } - DestroyMenu(hMenu); - break; } + DestroyMenu(hMenu); + break; } pContextMenu->Release(); } @@ -116,7 +116,7 @@ static LRESULT CALLBACK IconCtrlSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, { PROTOFILETRANSFERSTATUS* pft = (PROTOFILETRANSFERSTATUS*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); - switch(msg) { + switch (msg) { case WM_LBUTTONDBLCLK: ShellExecute(hwnd, NULL, pft->tszCurrentFile, NULL, NULL, SW_SHOW); break; @@ -140,7 +140,7 @@ void __cdecl LoadIconsAndTypesThread(void* param) loadiconsstartinfo *info = (loadiconsstartinfo*)param; SHFILEINFO fileInfo; - if (SHGetFileInfo(info->szFilename, 0, &fileInfo, sizeof(fileInfo), SHGFI_TYPENAME|SHGFI_ICON|SHGFI_LARGEICON)) { + if (SHGetFileInfo(info->szFilename, 0, &fileInfo, sizeof(fileInfo), SHGFI_TYPENAME | SHGFI_ICON | SHGFI_LARGEICON)) { TCHAR szExtension[64], szIconFile[MAX_PATH]; TCHAR *pszFilename = _tcsrchr(info->szFilename, '\\'); @@ -149,7 +149,7 @@ void __cdecl LoadIconsAndTypesThread(void* param) TCHAR *pszExtension = _tcsrchr(pszFilename, '.'); if (pszExtension) - lstrcpyn(szExtension, pszExtension+1, SIZEOF(szExtension)); + lstrcpyn(szExtension, pszExtension + 1, SIZEOF(szExtension)); else { pszExtension = _T("."); szExtension[0] = '\0'; @@ -161,7 +161,7 @@ void __cdecl LoadIconsAndTypesThread(void* param) SetDlgItemText(info->hwndDlg, IDC_NEWTYPE, fileInfo.szTypeName); SendDlgItemMessage(info->hwndDlg, IDC_EXISTINGICON, STM_SETICON, (WPARAM)fileInfo.hIcon, 0); szIconFile[0] = '\0'; - if ( !lstrcmp(szExtension, _T("EXE"))) + if (!lstrcmp(szExtension, _T("EXE"))) SRFile_GetRegValue(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Icons"), _T("2"), szIconFile, SIZEOF(szIconFile)); else { TCHAR szTypeName[MAX_PATH]; @@ -171,11 +171,13 @@ void __cdecl LoadIconsAndTypesThread(void* param) if (_tcsstr(szIconFile, _T("%1"))) SRFile_GetRegValue(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Icons"), _T("0"), szIconFile, SIZEOF(szIconFile)); else szIconFile[0] = '\0'; - } } } + } + } + } if (szIconFile[0]) { TCHAR *pszComma = _tcsrchr(szIconFile, ','); - int iconIndex = (pszComma == NULL) ? 0 :_ttoi(pszComma+1); *pszComma = '\0'; + int iconIndex = (pszComma == NULL) ? 0 : _ttoi(pszComma + 1); *pszComma = '\0'; HICON hIcon = ExtractIcon(hInst, szIconFile, iconIndex); if (hIcon) fileInfo.hIcon = hIcon; @@ -189,128 +191,132 @@ void __cdecl LoadIconsAndTypesThread(void* param) INT_PTR CALLBACK DlgProcFileExists(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { PROTOFILETRANSFERSTATUS *fts = (PROTOFILETRANSFERSTATUS*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch(msg) { + switch (msg) { case WM_INITDIALOG: - { - TCHAR szSize[64]; - struct _stati64 statbuf; - struct TDlgProcFileExistsParam *dat = (struct TDlgProcFileExistsParam *)lParam; - - SetPropA(hwndDlg, "Miranda.Preshutdown", HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwndDlg, M_PRESHUTDOWN)); - SetPropA(hwndDlg, "Miranda.ParentWnd", dat->hwndParent); - TranslateDialogDefault(hwndDlg); - fts = (PROTOFILETRANSFERSTATUS*)mir_alloc(sizeof(PROTOFILETRANSFERSTATUS)); - CopyProtoFileTransferStatus(fts, dat->fts); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)fts); - SetDlgItemText(hwndDlg, IDC_FILENAME, fts->tszCurrentFile); - SetControlToUnixTime(hwndDlg, IDC_NEWDATE, fts->currentFileTime); - GetSensiblyFormattedSize(fts->currentFileSize, szSize, SIZEOF(szSize), 0, 1, NULL); - SetDlgItemText(hwndDlg, IDC_NEWSIZE, szSize); - - mir_subclassWindow( GetDlgItem(hwndDlg, IDC_EXISTINGICON), IconCtrlSubclassProc); - - HWND hwndFocus = GetDlgItem(hwndDlg, IDC_RESUME); - if (_tstati64(fts->tszCurrentFile, &statbuf) == 0) { - SetControlToUnixTime(hwndDlg, IDC_EXISTINGDATE, statbuf.st_mtime); - GetSensiblyFormattedSize(statbuf.st_size, szSize, SIZEOF(szSize), 0, 1, NULL); - SetDlgItemText(hwndDlg, IDC_EXISTINGSIZE, szSize); - if (statbuf.st_size>(int)fts->currentFileSize) { - EnableWindow(GetDlgItem(hwndDlg, IDC_RESUME), FALSE); - hwndFocus = GetDlgItem(hwndDlg, IDC_OVERWRITE); - } } - - loadiconsstartinfo *lisi = (loadiconsstartinfo*)mir_alloc(sizeof(loadiconsstartinfo)); - lisi->hwndDlg = hwndDlg; - lisi->szFilename = mir_tstrdup(fts->tszCurrentFile); - //can be a little slow, so why not? - forkthread(LoadIconsAndTypesThread, 0, lisi); - SetFocus(hwndFocus); - SetWindowLongPtr(hwndFocus, GWL_STYLE, GetWindowLongPtr(hwndFocus, GWL_STYLE)|BS_DEFPUSHBUTTON); - return FALSE; - } - case WM_COMMAND: - { - PROTOFILERESUME pfr = {0}; - switch(LOWORD(wParam)) { - case IDC_OPENFILE: - ShellExecute(hwndDlg, NULL, fts->tszCurrentFile, NULL, NULL, SW_SHOW); - return FALSE; - - case IDC_OPENFOLDER: { - TCHAR szFile[MAX_PATH]; - lstrcpyn(szFile, fts->tszCurrentFile, SIZEOF(szFile)); - TCHAR *pszLastBackslash = _tcsrchr(szFile, '\\'); - if (pszLastBackslash) - *pszLastBackslash = '\0'; - ShellExecute(hwndDlg, NULL, szFile, NULL, NULL, SW_SHOW); - return FALSE; + TCHAR szSize[64]; + struct _stati64 statbuf; + struct TDlgProcFileExistsParam *dat = (struct TDlgProcFileExistsParam *)lParam; + + SetPropA(hwndDlg, "Miranda.Preshutdown", HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwndDlg, M_PRESHUTDOWN)); + SetPropA(hwndDlg, "Miranda.ParentWnd", dat->hwndParent); + + fts = (PROTOFILETRANSFERSTATUS*)mir_alloc(sizeof(PROTOFILETRANSFERSTATUS)); + CopyProtoFileTransferStatus(fts, dat->fts); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)fts); + SetDlgItemText(hwndDlg, IDC_FILENAME, fts->tszCurrentFile); + SetControlToUnixTime(hwndDlg, IDC_NEWDATE, fts->currentFileTime); + GetSensiblyFormattedSize(fts->currentFileSize, szSize, SIZEOF(szSize), 0, 1, NULL); + SetDlgItemText(hwndDlg, IDC_NEWSIZE, szSize); + + mir_subclassWindow(GetDlgItem(hwndDlg, IDC_EXISTINGICON), IconCtrlSubclassProc); + + HWND hwndFocus = GetDlgItem(hwndDlg, IDC_RESUME); + if (_tstati64(fts->tszCurrentFile, &statbuf) == 0) { + SetControlToUnixTime(hwndDlg, IDC_EXISTINGDATE, statbuf.st_mtime); + GetSensiblyFormattedSize(statbuf.st_size, szSize, SIZEOF(szSize), 0, 1, NULL); + SetDlgItemText(hwndDlg, IDC_EXISTINGSIZE, szSize); + if (statbuf.st_size > (int)fts->currentFileSize) { + EnableWindow(GetDlgItem(hwndDlg, IDC_RESUME), FALSE); + hwndFocus = GetDlgItem(hwndDlg, IDC_OVERWRITE); + } + } + + loadiconsstartinfo *lisi = (loadiconsstartinfo*)mir_alloc(sizeof(loadiconsstartinfo)); + lisi->hwndDlg = hwndDlg; + lisi->szFilename = mir_tstrdup(fts->tszCurrentFile); + //can be a little slow, so why not? + forkthread(LoadIconsAndTypesThread, 0, lisi); + SetFocus(hwndFocus); + SetWindowLongPtr(hwndFocus, GWL_STYLE, GetWindowLongPtr(hwndFocus, GWL_STYLE) | BS_DEFPUSHBUTTON); } - case IDC_PROPERTIES: - DoAnnoyingShellCommand(hwndDlg, fts->tszCurrentFile, C_PROPERTIES, NULL); - return FALSE; - case IDC_RESUME: - pfr.action = FILERESUME_RESUME; - break; - case IDC_RESUMEALL: - pfr.action = FILERESUME_RESUMEALL; - break; - case IDC_OVERWRITE: - pfr.action = FILERESUME_OVERWRITE; - break; - case IDC_OVERWRITEALL: - pfr.action = FILERESUME_OVERWRITEALL; - break; - - case IDC_AUTORENAME: - pfr.action = FILERESUME_RENAMEALL; - break; - - case IDC_SAVEAS: + return FALSE; + + case WM_COMMAND: { - OPENFILENAME ofn = {0}; - TCHAR filter[512], *pfilter; - TCHAR str[MAX_PATH]; - - lstrcpyn(str, fts->tszCurrentFile, SIZEOF(str)); - ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; - ofn.hwndOwner = hwndDlg; - ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; - _tcscpy(filter, TranslateT("All files")); - _tcscat(filter, _T(" (*)")); - pfilter = filter + _tcslen(filter) + 1; - _tcscpy(pfilter, _T("*")); - pfilter = pfilter + _tcslen(pfilter) + 1; - *pfilter = '\0'; - ofn.lpstrFilter = filter; - ofn.lpstrFile = str; - ofn.nMaxFile = SIZEOF(str); - ofn.nMaxFileTitle = MAX_PATH; - if ( !GetSaveFileName(&ofn)) + PROTOFILERESUME pfr = { 0 }; + switch (LOWORD(wParam)) { + case IDC_OPENFILE: + ShellExecute(hwndDlg, NULL, fts->tszCurrentFile, NULL, NULL, SW_SHOW); return FALSE; - pfr.szFilename = mir_tstrdup(str); - pfr.action = FILERESUME_RENAME; - break; - } - case IDC_SKIP: - pfr.action = FILERESUME_SKIP; - break; - case IDCANCEL: - pfr.action = FILERESUME_CANCEL; - break; - default: - return FALSE; - } - { + case IDC_OPENFOLDER: + { + TCHAR szFile[MAX_PATH]; + lstrcpyn(szFile, fts->tszCurrentFile, SIZEOF(szFile)); + TCHAR *pszLastBackslash = _tcsrchr(szFile, '\\'); + if (pszLastBackslash) + *pszLastBackslash = '\0'; + ShellExecute(hwndDlg, NULL, szFile, NULL, NULL, SW_SHOW); + } + return FALSE; + case IDC_PROPERTIES: + DoAnnoyingShellCommand(hwndDlg, fts->tszCurrentFile, C_PROPERTIES, NULL); + return FALSE; + case IDC_RESUME: + pfr.action = FILERESUME_RESUME; + break; + case IDC_RESUMEALL: + pfr.action = FILERESUME_RESUMEALL; + break; + case IDC_OVERWRITE: + pfr.action = FILERESUME_OVERWRITE; + break; + case IDC_OVERWRITEALL: + pfr.action = FILERESUME_OVERWRITEALL; + break; + + case IDC_AUTORENAME: + pfr.action = FILERESUME_RENAMEALL; + break; + + case IDC_SAVEAS: + { + OPENFILENAME ofn = { 0 }; + TCHAR filter[512], *pfilter; + TCHAR str[MAX_PATH]; + + lstrcpyn(str, fts->tszCurrentFile, SIZEOF(str)); + ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; + ofn.hwndOwner = hwndDlg; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; + _tcscpy(filter, TranslateT("All files")); + _tcscat(filter, _T(" (*)")); + pfilter = filter + _tcslen(filter) + 1; + _tcscpy(pfilter, _T("*")); + pfilter = pfilter + _tcslen(pfilter) + 1; + *pfilter = '\0'; + ofn.lpstrFilter = filter; + ofn.lpstrFile = str; + ofn.nMaxFile = SIZEOF(str); + ofn.nMaxFileTitle = MAX_PATH; + if (!GetSaveFileName(&ofn)) + return FALSE; + + pfr.szFilename = mir_tstrdup(str); + pfr.action = FILERESUME_RENAME; + } + break; + + case IDC_SKIP: + pfr.action = FILERESUME_SKIP; + break; + + case IDCANCEL: + pfr.action = FILERESUME_CANCEL; + break; + + default: + return FALSE; + } + PROTOFILERESUME *pfrCopy = (PROTOFILERESUME*)mir_alloc(sizeof(pfr)); CopyMemory(pfrCopy, &pfr, sizeof(pfr)); PostMessage((HWND)GetPropA(hwndDlg, "Miranda.ParentWnd"), M_FILEEXISTSDLGREPLY, (WPARAM)mir_tstrdup(fts->tszCurrentFile), (LPARAM)pfrCopy); DestroyWindow(hwndDlg); } break; - } case WM_CLOSE: PostMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, BN_CLICKED), (LPARAM)GetDlgItem(hwndDlg, IDCANCEL)); diff --git a/src/core/stdfile/fileopts.cpp b/src/core/stdfile/fileopts.cpp index 95a73b4455..cc36766a66 100644 --- a/src/core/stdfile/fileopts.cpp +++ b/src/core/stdfile/fileopts.cpp @@ -58,173 +58,173 @@ static const struct virusscannerinfo virusScanners[] = { static INT_PTR CALLBACK DlgProcFileOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) { - case WM_INITDIALOG: + switch (msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); { - TranslateDialogDefault(hwndDlg); - SHAutoComplete(GetDlgItem(hwndDlg, IDC_FILEDIR), SHACF_FILESYS_DIRS); - { - TCHAR str[MAX_PATH]; - GetContactReceivedFilesDir(NULL, str, SIZEOF(str), FALSE); - SetDlgItemText(hwndDlg, IDC_FILEDIR, str); - } + TCHAR str[MAX_PATH]; + GetContactReceivedFilesDir(NULL, str, SIZEOF(str), FALSE); + SetDlgItemText(hwndDlg, IDC_FILEDIR, str); CheckDlgButton(hwndDlg, IDC_AUTOACCEPT, db_get_b(NULL, "SRFile", "AutoAccept", 0) ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_AUTOMIN, db_get_b(NULL, "SRFile", "AutoMin", 0) ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_AUTOCLOSE, db_get_b(NULL, "SRFile", "AutoClose", 0) ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_AUTOCLEAR, db_get_b(NULL, "SRFile", "AutoClear", 1) ? BST_CHECKED : BST_UNCHECKED); - switch(db_get_b(NULL, "SRFile", "UseScanner", VIRUSSCAN_DISABLE)) { + switch (db_get_b(NULL, "SRFile", "UseScanner", VIRUSSCAN_DISABLE)) { case VIRUSSCAN_AFTERDL: CheckDlgButton(hwndDlg, IDC_SCANAFTERDL, BST_CHECKED); break; case VIRUSSCAN_DURINGDL: CheckDlgButton(hwndDlg, IDC_SCANDURINGDL, BST_CHECKED); break; default: CheckDlgButton(hwndDlg, IDC_NOSCANNER, BST_CHECKED); break; } CheckDlgButton(hwndDlg, IDC_WARNBEFOREOPENING, db_get_b(NULL, "SRFile", "WarnBeforeOpening", 1) ? BST_CHECKED : BST_UNCHECKED); - { TCHAR szScanExe[MAX_PATH]; - int i, iItem; - for (i=0; i < SIZEOF(virusScanners); i++) { - if (SRFile_GetRegValue(HKEY_LOCAL_MACHINE, virusScanners[i].szExeRegPath, virusScanners[i].szExeRegValue, szScanExe, SIZEOF(szScanExe))) { - iItem = SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_ADDSTRING, 0, (LPARAM)virusScanners[i].szProductName); - SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_SETITEMDATA, iItem, i); - } - } - if (SendDlgItemMessageA(hwndDlg, IDC_SCANCMDLINE, CB_GETCOUNT, 0, 0) == 0) - { - iItem = SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_ADDSTRING, 0, (LPARAM)_T("")); - SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_SETITEMDATA, iItem, (LPARAM)-1); + for (int i = 0; i < SIZEOF(virusScanners); i++) { + TCHAR szScanExe[MAX_PATH]; + if (SRFile_GetRegValue(HKEY_LOCAL_MACHINE, virusScanners[i].szExeRegPath, virusScanners[i].szExeRegValue, szScanExe, SIZEOF(szScanExe))) { + int iItem = SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_ADDSTRING, 0, (LPARAM)virusScanners[i].szProductName); + SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_SETITEMDATA, iItem, i); } } + if (SendDlgItemMessageA(hwndDlg, IDC_SCANCMDLINE, CB_GETCOUNT, 0, 0) == 0) { + int iItem = SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_ADDSTRING, 0, (LPARAM)_T("")); + SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_SETITEMDATA, iItem, (LPARAM)-1); + } DBVARIANT dbv; if (db_get_ts(NULL, "SRFile", "ScanCmdLine", &dbv) == 0) { SetDlgItemText(hwndDlg, IDC_SCANCMDLINE, dbv.ptszVal); db_free(&dbv); } - else { - if (SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_GETCOUNT, 0, 0)) { - SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_SETCURSEL, 0, 0); - PostMessage(hwndDlg, M_SCANCMDLINESELCHANGE, 0, 0); - } + else if (SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_GETCOUNT, 0, 0)) { + SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_SETCURSEL, 0, 0); + PostMessage(hwndDlg, M_SCANCMDLINESELCHANGE, 0, 0); } - switch(db_get_b(NULL, "SRFile", "IfExists", FILERESUME_ASK)) { + + switch (db_get_b(NULL, "SRFile", "IfExists", FILERESUME_ASK)) { case FILERESUME_RESUMEALL: CheckDlgButton(hwndDlg, IDC_RESUME, BST_CHECKED); break; case FILERESUME_OVERWRITEALL: CheckDlgButton(hwndDlg, IDC_OVERWRITE, BST_CHECKED); break; case FILERESUME_RENAMEALL: CheckDlgButton(hwndDlg, IDC_RENAME, BST_CHECKED); break; default: CheckDlgButton(hwndDlg, IDC_ASK, BST_CHECKED); break; } SendMessage(hwndDlg, M_UPDATEENABLING, 0, 0); - return TRUE; } - case M_UPDATEENABLING: - { int on = !IsDlgButtonChecked(hwndDlg, IDC_NOSCANNER); + return TRUE; + + case M_UPDATEENABLING: + { + int on = !IsDlgButtonChecked(hwndDlg, IDC_NOSCANNER); EnableWindow(GetDlgItem(hwndDlg, IDC_ST_CMDLINE), on); EnableWindow(GetDlgItem(hwndDlg, IDC_SCANCMDLINE), on); EnableWindow(GetDlgItem(hwndDlg, IDC_SCANCMDLINEBROWSE), on); EnableWindow(GetDlgItem(hwndDlg, IDC_ST_CMDLINEHELP), on); EnableWindow(GetDlgItem(hwndDlg, IDC_AUTOMIN), IsDlgButtonChecked(hwndDlg, IDC_AUTOACCEPT)); - break; } - case M_SCANCMDLINESELCHANGE: - { TCHAR str[512]; + break; + case M_SCANCMDLINESELCHANGE: + { + TCHAR str[512]; TCHAR szScanExe[MAX_PATH]; int iScanner = SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_GETCURSEL, 0, 0), 0); - if (iScanner >= SIZEOF(virusScanners) || iScanner<0) break; + if (iScanner >= SIZEOF(virusScanners) || iScanner < 0) break; str[0] = '\0'; if (SRFile_GetRegValue(HKEY_LOCAL_MACHINE, virusScanners[iScanner].szExeRegPath, virusScanners[iScanner].szExeRegValue, szScanExe, SIZEOF(szScanExe))) mir_sntprintf(str, SIZEOF(str), virusScanners[iScanner].szCommandLine, szScanExe); SetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str); - break; } - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_FILEDIR: - if ((HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) return 0; - break; - case IDC_FILEDIRBROWSE: - { TCHAR str[MAX_PATH]; - GetDlgItemText(hwndDlg, IDC_FILEDIR, str, SIZEOF(str)); - if (BrowseForFolder(hwndDlg, str)) - SetDlgItemText(hwndDlg, IDC_FILEDIR, str); - break; - } - case IDC_AUTOACCEPT: - case IDC_NOSCANNER: - case IDC_SCANAFTERDL: - case IDC_SCANDURINGDL: - SendMessage(hwndDlg, M_UPDATEENABLING, 0, 0); - break; - case IDC_SCANCMDLINE: - if (HIWORD(wParam) == CBN_SELCHANGE) PostMessage(hwndDlg, M_SCANCMDLINESELCHANGE, 0, 0); - else if (HIWORD(wParam) != CBN_EDITCHANGE) return 0; - break; - case IDC_SCANCMDLINEBROWSE: - { TCHAR str[MAX_PATH+2]; - OPENFILENAME ofn = {0}; - TCHAR filter[512], *pfilter; - - GetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str, SIZEOF(str)); - ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; - ofn.hwndOwner = hwndDlg; - ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_DONTADDTORECENT; - _tcscpy(filter, TranslateT("Executable files")); - _tcscat(filter, _T(" (*.exe)")); - pfilter = filter + _tcslen(filter) + 1; - _tcscpy(pfilter, _T("*.exe")); - pfilter = pfilter + _tcslen(pfilter)+1; - _tcscpy(pfilter, TranslateT("All files")); - _tcscat(pfilter, _T(" (*)")); - pfilter = pfilter + _tcslen(pfilter) + 1; - _tcscpy(pfilter, _T("*")); - pfilter = pfilter + _tcslen(pfilter) + 1; - *pfilter = 0; - ofn.lpstrFilter = filter; - ofn.lpstrFile = str; - ofn.nMaxFile = SIZEOF(str)-2; - if (str[0] == '"') { - TCHAR *pszQuote = _tcschr(str + 1, '"'); - if (pszQuote) *pszQuote = 0; - MoveMemory(str, str + 1, _tcslen(str) * sizeof(TCHAR)); - } - else { - TCHAR *pszSpace = _tcschr(str, ' '); - if (pszSpace) *pszSpace = 0; - } - ofn.nMaxFileTitle = MAX_PATH; - if ( !GetOpenFileName(&ofn)) break; - if (_tcschr(str, ' ') != NULL) { - MoveMemory(str+1, str, SIZEOF(str) - 2 * sizeof(TCHAR)); - str[0] = '"'; - _tcscat(str, _T("\"")); - } - SetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str); - break; - } - } - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_FILEDIR: + if ((HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) return 0; break; - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->code) + + case IDC_FILEDIRBROWSE: { - case PSN_APPLY: - { TCHAR str[512]; - GetDlgItemText(hwndDlg, IDC_FILEDIR, str, SIZEOF(str)); - RemoveInvalidPathChars(str); - db_set_ts(NULL, "SRFile", "RecvFilesDirAdv", str); - db_set_b(NULL, "SRFile", "AutoAccept", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOACCEPT)); - db_set_b(NULL, "SRFile", "AutoMin", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOMIN)); - db_set_b(NULL, "SRFile", "AutoClose", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOCLOSE)); - db_set_b(NULL, "SRFile", "AutoClear", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOCLEAR)); - db_set_b(NULL, "SRFile", "UseScanner", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_SCANAFTERDL)?VIRUSSCAN_AFTERDL:(IsDlgButtonChecked(hwndDlg, IDC_SCANDURINGDL)?VIRUSSCAN_DURINGDL:VIRUSSCAN_DISABLE))); - GetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str, SIZEOF(str)); - db_set_ts(NULL, "SRFile", "ScanCmdLine", str); - db_set_b(NULL, "SRFile", "WarnBeforeOpening", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_WARNBEFOREOPENING)); - db_set_b(NULL, "SRFile", "IfExists", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_ASK)?FILERESUME_ASK:(IsDlgButtonChecked(hwndDlg, IDC_RESUME)?FILERESUME_RESUMEALL:(IsDlgButtonChecked(hwndDlg, IDC_OVERWRITE)?FILERESUME_OVERWRITEALL:FILERESUME_RENAMEALL)))); - return TRUE; - } + TCHAR str[MAX_PATH]; + GetDlgItemText(hwndDlg, IDC_FILEDIR, str, SIZEOF(str)); + if (BrowseForFolder(hwndDlg, str)) + SetDlgItemText(hwndDlg, IDC_FILEDIR, str); + } + break; + + case IDC_AUTOACCEPT: + case IDC_NOSCANNER: + case IDC_SCANAFTERDL: + case IDC_SCANDURINGDL: + SendMessage(hwndDlg, M_UPDATEENABLING, 0, 0); + break; + + case IDC_SCANCMDLINE: + if (HIWORD(wParam) == CBN_SELCHANGE) PostMessage(hwndDlg, M_SCANCMDLINESELCHANGE, 0, 0); + else if (HIWORD(wParam) != CBN_EDITCHANGE) return 0; + break; + + case IDC_SCANCMDLINEBROWSE: + TCHAR str[MAX_PATH + 2]; + OPENFILENAME ofn = { 0 }; + TCHAR filter[512], *pfilter; + + GetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str, SIZEOF(str)); + ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; + ofn.hwndOwner = hwndDlg; + ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_DONTADDTORECENT; + _tcscpy(filter, TranslateT("Executable files")); + _tcscat(filter, _T(" (*.exe)")); + pfilter = filter + _tcslen(filter) + 1; + _tcscpy(pfilter, _T("*.exe")); + pfilter = pfilter + _tcslen(pfilter) + 1; + _tcscpy(pfilter, TranslateT("All files")); + _tcscat(pfilter, _T(" (*)")); + pfilter = pfilter + _tcslen(pfilter) + 1; + _tcscpy(pfilter, _T("*")); + pfilter = pfilter + _tcslen(pfilter) + 1; + *pfilter = 0; + ofn.lpstrFilter = filter; + ofn.lpstrFile = str; + ofn.nMaxFile = SIZEOF(str) - 2; + if (str[0] == '"') { + TCHAR *pszQuote = _tcschr(str + 1, '"'); + if (pszQuote) *pszQuote = 0; + MoveMemory(str, str + 1, _tcslen(str) * sizeof(TCHAR)); + } + else { + TCHAR *pszSpace = _tcschr(str, ' '); + if (pszSpace) *pszSpace = 0; + } + ofn.nMaxFileTitle = MAX_PATH; + if (!GetOpenFileName(&ofn)) break; + if (_tcschr(str, ' ') != NULL) { + MoveMemory(str + 1, str, SIZEOF(str) - 2 * sizeof(TCHAR)); + str[0] = '"'; + _tcscat(str, _T("\"")); } + SetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str); break; + } + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + + case WM_NOTIFY: + switch (((LPNMHDR)lParam)->code) { + case PSN_APPLY: + TCHAR str[512]; + GetDlgItemText(hwndDlg, IDC_FILEDIR, str, SIZEOF(str)); + RemoveInvalidPathChars(str); + db_set_ts(NULL, "SRFile", "RecvFilesDirAdv", str); + db_set_b(NULL, "SRFile", "AutoAccept", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOACCEPT)); + db_set_b(NULL, "SRFile", "AutoMin", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOMIN)); + db_set_b(NULL, "SRFile", "AutoClose", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOCLOSE)); + db_set_b(NULL, "SRFile", "AutoClear", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOCLEAR)); + db_set_b(NULL, "SRFile", "UseScanner", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_SCANAFTERDL) ? VIRUSSCAN_AFTERDL : (IsDlgButtonChecked(hwndDlg, IDC_SCANDURINGDL) ? VIRUSSCAN_DURINGDL : VIRUSSCAN_DISABLE))); + GetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str, SIZEOF(str)); + db_set_ts(NULL, "SRFile", "ScanCmdLine", str); + db_set_b(NULL, "SRFile", "WarnBeforeOpening", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_WARNBEFOREOPENING)); + db_set_b(NULL, "SRFile", "IfExists", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_ASK) ? FILERESUME_ASK : (IsDlgButtonChecked(hwndDlg, IDC_RESUME) ? FILERESUME_RESUMEALL : (IsDlgButtonChecked(hwndDlg, IDC_OVERWRITE) ? FILERESUME_OVERWRITEALL : FILERESUME_RENAMEALL)))); + return TRUE; + } + break; } return FALSE; } diff --git a/src/core/stdfile/filerecvdlg.cpp b/src/core/stdfile/filerecvdlg.cpp index c21d71795f..e952632e8c 100644 --- a/src/core/stdfile/filerecvdlg.cpp +++ b/src/core/stdfile/filerecvdlg.cpp @@ -41,10 +41,11 @@ static void GetLowestExistingDirName(const TCHAR *szTestDir, TCHAR *szExistingDi lstrcpyn(szExistingDir, szTestDir, cchExistingDir); while ((dwAttributes = GetFileAttributes(szExistingDir)) != INVALID_FILE_ATTRIBUTES && !(dwAttributes&FILE_ATTRIBUTE_DIRECTORY)) { pszLastBackslash = _tcsrchr(szExistingDir, '\\'); - if (pszLastBackslash == NULL) {*szExistingDir = '\0'; break;} + if (pszLastBackslash == NULL) { *szExistingDir = '\0'; break; } *pszLastBackslash = '\0'; } - if (szExistingDir[0] == '\0') GetCurrentDirectory(cchExistingDir, szExistingDir); + if (szExistingDir[0] == '\0') + GetCurrentDirectory(cchExistingDir, szExistingDir); } static const TCHAR InvalidFilenameChars[] = _T("\\/:*?\"<>|"); @@ -61,23 +62,21 @@ void RemoveInvalidFilenameChars(TCHAR *tszString) static const TCHAR InvalidPathChars[] = _T("*?\"<>|"); // "\/:" are excluded as they are allowed in file path void RemoveInvalidPathChars(TCHAR *tszString) { - size_t i; - if (tszString) { - for (i = _tcscspn(tszString, InvalidPathChars); tszString[i]; i+=_tcscspn(tszString+i+1, InvalidPathChars)+1) + if (tszString) + for (size_t i = _tcscspn(tszString, InvalidPathChars); tszString[i]; i += _tcscspn(tszString + i + 1, InvalidPathChars) + 1) if (tszString[i] >= 0) tszString[i] = _T('_'); - } } static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) { TCHAR szDir[MAX_PATH]; - switch(uMsg) { + switch (uMsg) { case BFFM_INITIALIZED: SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData); break; case BFFM_SELCHANGED: - if (SHGetPathFromIDList((LPITEMIDLIST) lp , szDir)) + if (SHGetPathFromIDList((LPITEMIDLIST)lp, szDir)) SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szDir); break; } @@ -86,9 +85,7 @@ static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM p int BrowseForFolder(HWND hwnd, TCHAR *szPath) { - BROWSEINFO bi = {0}; - LPITEMIDLIST pidlResult; - + BROWSEINFO bi = { 0 }; bi.hwndOwner = hwnd; bi.pszDisplayName = szPath; bi.lpszTitle = TranslateT("Select folder"); @@ -96,7 +93,7 @@ int BrowseForFolder(HWND hwnd, TCHAR *szPath) bi.lpfn = BrowseCallbackProc; bi.lParam = (LPARAM)szPath; - pidlResult = SHBrowseForFolder(&bi); + LPITEMIDLIST pidlResult = SHBrowseForFolder(&bi); if (pidlResult) { SHGetPathFromIDList(pidlResult, szPath); lstrcat(szPath, _T("\\")); @@ -127,8 +124,8 @@ static void patchDir(TCHAR *str, size_t strSize) } size_t len = lstrlen(str); - if (len+1 < strSize && str[len-1] != '\\') - lstrcpy(str+len, _T("\\")); + if (len + 1 < strSize && str[len - 1] != '\\') + lstrcpy(str + len, _T("\\")); } void GetContactReceivedFilesDir(MCONTACT hContact, TCHAR *szDir, int cchDir, BOOL patchVars) @@ -137,13 +134,13 @@ void GetContactReceivedFilesDir(MCONTACT hContact, TCHAR *szDir, int cchDir, BOO TCHAR szTemp[MAX_PATH]; szTemp[0] = 0; - if ( !db_get_ts(NULL, "SRFile", "RecvFilesDirAdv", &dbv)) { + if (!db_get_ts(NULL, "SRFile", "RecvFilesDirAdv", &dbv)) { if (lstrlen(dbv.ptszVal) > 0) lstrcpyn(szTemp, dbv.ptszVal, SIZEOF(szTemp)); db_free(&dbv); } - if ( !szTemp[0]) + if (!szTemp[0]) mir_sntprintf(szTemp, SIZEOF(szTemp), _T("%%mydocuments%%\\%s\\%%userid%%"), TranslateT("My received files")); @@ -159,7 +156,7 @@ void GetContactReceivedFilesDir(MCONTACT hContact, TCHAR *szDir, int cchDir, BOO rvaVarsToReplace[2].lptzValue = mir_a2t(GetContactProto(hContact)); rvaVarsToReplace[3].lptzKey = NULL; rvaVarsToReplace[3].lptzValue = NULL; - for (int i=0; i < (SIZEOF(rvaVarsToReplace)-1);i++) + for (int i = 0; i < (SIZEOF(rvaVarsToReplace) - 1); i++) RemoveInvalidFilenameChars(rvaVarsToReplace[i].lptzValue); dat.cbSize = sizeof(dat); @@ -170,9 +167,10 @@ void GetContactReceivedFilesDir(MCONTACT hContact, TCHAR *szDir, int cchDir, BOO if (result) { _tcsncpy(szTemp, result, SIZEOF(szTemp)); mir_free(result); - for (int i=0; i < (SIZEOF(rvaVarsToReplace)-1);i++) + for (int i = 0; i < (SIZEOF(rvaVarsToReplace) - 1); i++) mir_free(rvaVarsToReplace[i].lptzValue); - } } + } + } if (patchVars) patchDir(szTemp, SIZEOF(szTemp)); @@ -182,21 +180,18 @@ void GetContactReceivedFilesDir(MCONTACT hContact, TCHAR *szDir, int cchDir, BOO void GetReceivedFilesDir(TCHAR *szDir, int cchDir) { - DBVARIANT dbv; - TCHAR szTemp[MAX_PATH]; - szTemp[0] = 0; + TCHAR szTemp[MAX_PATH]; szTemp[0] = 0; - if ( !db_get_ts(NULL, "SRFile", "RecvFilesDirAdv", &dbv)) { + DBVARIANT dbv; + if (!db_get_ts(NULL, "SRFile", "RecvFilesDirAdv", &dbv)) { if (lstrlen(dbv.ptszVal) > 0) lstrcpyn(szTemp, dbv.ptszVal, SIZEOF(szTemp)); db_free(&dbv); } - if ( !szTemp[0]) - + if (!szTemp[0]) mir_sntprintf(szTemp, SIZEOF(szTemp), _T("%%mydocuments%%\\%s"), TranslateT("My received files")); - patchDir(szTemp, SIZEOF(szTemp)); RemoveInvalidPathChars(szTemp); lstrcpyn(szDir, szTemp, cchDir); @@ -204,9 +199,8 @@ void GetReceivedFilesDir(TCHAR *szDir, int cchDir) INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - FileDlgData *dat; - - dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); @@ -214,7 +208,6 @@ INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l TCHAR szPath[450]; CLISTEVENT* cle = (CLISTEVENT*)lParam; - dat = (FileDlgData*)mir_calloc(sizeof(FileDlgData)); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); dat->hContact = cle->hContact; @@ -236,7 +229,7 @@ INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l SetDlgItemText(hwndDlg, IDC_FILEDIR, szPath); SHAutoComplete(GetWindow(GetDlgItem(hwndDlg, IDC_FILEDIR), GW_CHILD), 1); - for (int i=0; i < MAX_MRU_DIRS; i++) { + for (int i = 0; i < MAX_MRU_DIRS; i++) { char idstr[32]; mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d", i); @@ -258,13 +251,13 @@ INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l dat->fs = cle->lParam ? (HANDLE)cle->lParam : (HANDLE)*(PDWORD)dbei.pBlob; char *str = (char*)dbei.pBlob + 4; - ptrT ptszFileName( DbGetEventStringT(&dbei, str)); + ptrT ptszFileName(DbGetEventStringT(&dbei, str)); SetDlgItemText(hwndDlg, IDC_FILENAMES, ptszFileName); unsigned len = (unsigned)strlen(str) + 1; if (len + 4 < dbei.cbBlob) { str += len; - ptrT ptszDescription( DbGetEventStringT(&dbei, str)); + ptrT ptszDescription(DbGetEventStringT(&dbei, str)); SetDlgItemText(hwndDlg, IDC_MSG, ptszDescription); } } @@ -284,8 +277,8 @@ INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l ci.hContact = dat->hContact; ci.szProto = szProto; ci.dwFlag = CNF_UNIQUEID; - if ( !CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) { - switch(ci.type) { + if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) { + switch (ci.type) { case CNFT_ASCIIZ: hasName = 1; mir_snprintf(buf, SIZEOF(buf), "%s", ci.pszVal); @@ -295,7 +288,8 @@ INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l hasName = 1; mir_snprintf(buf, SIZEOF(buf), "%u", ci.dVal); break; - } } + } + } if (hasName) SetDlgItemTextA(hwndDlg, IDC_NAME, buf); else @@ -307,13 +301,13 @@ INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l GetWindowRect(GetDlgItem(hwndDlg, IDC_ADD), &rcBtn1); GetWindowRect(GetDlgItem(hwndDlg, IDC_USERMENU), &rcBtn2); GetWindowRect(GetDlgItem(hwndDlg, IDC_DATE), &rcDateCtrl); - SetWindowPos(GetDlgItem(hwndDlg, IDC_DATE), 0, 0, 0, rcDateCtrl.right-rcDateCtrl.left-(rcBtn2.left-rcBtn1.left), rcDateCtrl.bottom-rcDateCtrl.top, SWP_NOZORDER|SWP_NOMOVE); + SetWindowPos(GetDlgItem(hwndDlg, IDC_DATE), 0, 0, 0, rcDateCtrl.right - rcDateCtrl.left - (rcBtn2.left - rcBtn1.left), rcDateCtrl.bottom - rcDateCtrl.top, SWP_NOZORDER | SWP_NOMOVE); } else if (db_get_b(NULL, "SRFile", "AutoAccept", 0)) { //don't check auto-min here to fix BUG#647620 PostMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDOK, BN_CLICKED), (LPARAM)GetDlgItem(hwndDlg, IDOK)); } - if ( !db_get_b(dat->hContact, "CList", "NotOnList", 0)) + if (!db_get_b(dat->hContact, "CList", "NotOnList", 0)) ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE); } return TRUE; @@ -396,18 +390,19 @@ INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l case IDC_ADD: { - ADDCONTACTSTRUCT acs = {0}; + ADDCONTACTSTRUCT acs = { 0 }; acs.hContact = dat->hContact; acs.handleType = HANDLE_CONTACT; acs.szProto = ""; CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)&acs); - if ( !db_get_b(dat->hContact, "CList", "NotOnList", 0)) + if (!db_get_b(dat->hContact, "CList", "NotOnList", 0)) ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE); } break; case IDC_USERMENU: - { RECT rc; + { + RECT rc; HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0); GetWindowRect((HWND)lParam, &rc); TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL); diff --git a/src/core/stdfile/filesenddlg.cpp b/src/core/stdfile/filesenddlg.cpp index 7f6067dbf7..7a9fc85a4c 100644 --- a/src/core/stdfile/filesenddlg.cpp +++ b/src/core/stdfile/filesenddlg.cpp @@ -69,13 +69,11 @@ static void SetFileListAndSizeControls(HWND hwndDlg, FileDlgData *dat) static void FilenameToFileList(HWND hwndDlg, FileDlgData* dat, const TCHAR *buf) { - DWORD dwFileAttributes; - // Make sure that the file matrix is empty (the user may select files several times) FreeFilesMatrix(&dat->files); // Get the file attributes of selection - dwFileAttributes = GetFileAttributes(buf); + DWORD dwFileAttributes = GetFileAttributes(buf); if (dwFileAttributes == INVALID_FILE_ATTRIBUTES) return; diff --git a/src/core/stdfile/filexferdlg.cpp b/src/core/stdfile/filexferdlg.cpp index 349301b1cb..c3efcc6e54 100644 --- a/src/core/stdfile/filexferdlg.cpp +++ b/src/core/stdfile/filexferdlg.cpp @@ -53,7 +53,7 @@ TCHAR* PFTS_StringToTchar(int flags, const PROTOCHAR* s) return mir_a2t((char*)s); } -int PFTS_CompareWithTchar(PROTOFILETRANSFERSTATUS* ft, const PROTOCHAR* s, TCHAR *r) +int PFTS_CompareWithTchar(PROTOFILETRANSFERSTATUS *ft, const PROTOCHAR *s, TCHAR *r) { if (ft->flags & PFTS_UTF) { TCHAR *ts = Utf8DecodeW((char*)s); @@ -63,7 +63,7 @@ int PFTS_CompareWithTchar(PROTOFILETRANSFERSTATUS* ft, const PROTOCHAR* s, TCHAR } if (ft->flags & PFTS_UNICODE) return _tcscmp(s, r); - + TCHAR *ts = mir_a2t((char*)s); int res = _tcscmp(ts, r); mir_free(ts); @@ -75,7 +75,7 @@ static void SetOpenFileButtonStyle(HWND hwndButton, int enabled) EnableWindow(hwndButton, enabled); } -void FillSendData(FileDlgData* dat, DBEVENTINFO& dbei) +void FillSendData(FileDlgData *dat, DBEVENTINFO& dbei) { dbei.cbSize = sizeof(dbei); dbei.szModule = GetContactProto(dat->hContact); @@ -85,39 +85,35 @@ void FillSendData(FileDlgData* dat, DBEVENTINFO& dbei) char *szFileNames = Utf8EncodeT(dat->szFilenames), *szMsg = Utf8EncodeT(dat->szMsg); dbei.flags |= DBEF_UTF; - dbei.cbBlob = sizeof(DWORD) + lstrlenA(szFileNames)+lstrlenA(szMsg)+2; + dbei.cbBlob = sizeof(DWORD) + lstrlenA(szFileNames) + lstrlenA(szMsg) + 2; dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob); *(PDWORD)dbei.pBlob = 0; - lstrcpyA((char*)dbei.pBlob+sizeof(DWORD), szFileNames); - lstrcpyA((char*)dbei.pBlob+sizeof(DWORD)+lstrlenA(szFileNames)+1, szMsg); + lstrcpyA((char*)dbei.pBlob + sizeof(DWORD), szFileNames); + lstrcpyA((char*)dbei.pBlob + sizeof(DWORD) + lstrlenA(szFileNames) + 1, szMsg); mir_free(szFileNames), mir_free(szMsg); - } static void __cdecl RunVirusScannerThread(struct virusscanthreadstartinfo *info) { - PROCESS_INFORMATION pi; DBVARIANT dbv; - - if ( !db_get_ts(NULL, "SRFile", "ScanCmdLine", &dbv)) - { - if (dbv.ptszVal[0]) - { - STARTUPINFO si = {0}; + if (!db_get_ts(NULL, "SRFile", "ScanCmdLine", &dbv)) { + if (dbv.ptszVal[0]) { + STARTUPINFO si = { 0 }; si.cb = sizeof(si); TCHAR *pszReplace = _tcsstr(dbv.ptszVal, _T("%f")); TCHAR szCmdLine[768]; - if (pszReplace) - { + if (pszReplace) { if (info->szFile[_tcslen(info->szFile) - 1] == '\\') info->szFile[_tcslen(info->szFile) - 1] = '\0'; *pszReplace = 0; - mir_sntprintf(szCmdLine, SIZEOF(szCmdLine), _T("%s\"%s\"%s"), dbv.ptszVal, info->szFile, pszReplace+2); + mir_sntprintf(szCmdLine, SIZEOF(szCmdLine), _T("%s\"%s\"%s"), dbv.ptszVal, info->szFile, pszReplace + 2); } else lstrcpyn(szCmdLine, dbv.ptszVal, SIZEOF(szCmdLine)); + + PROCESS_INFORMATION pi; if (CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { - if (WaitForSingleObject(pi.hProcess, 3600*1000) == WAIT_OBJECT_0) + if (WaitForSingleObject(pi.hProcess, 3600 * 1000) == WAIT_OBJECT_0) PostMessage(info->hwndReply, M_VIRUSSCANDONE, info->returnCode, 0); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); @@ -133,7 +129,7 @@ static void SetFilenameControls(HWND hwndDlg, FileDlgData *dat, PROTOFILETRANSFE { TCHAR msg[MAX_PATH]; TCHAR *fnbuf = NULL, *fn = NULL; - SHFILEINFO shfi = {0}; + SHFILEINFO shfi = { 0 }; if (fts->tszCurrentFile) { fnbuf = mir_tstrdup(fts->tszCurrentFile); @@ -147,15 +143,15 @@ static void SetFilenameControls(HWND hwndDlg, FileDlgData *dat, PROTOFILETRANSFE if (fn && (fts->totalFiles > 1)) { mir_sntprintf(msg, SIZEOF(msg), _T("%s: %s (%d %s %d)"), pcli->pfnGetContactDisplayName(fts->hContact, 0), - fn, fts->currentFileNumber+1, TranslateT("of"), fts->totalFiles); + fn, fts->currentFileNumber + 1, TranslateT("of"), fts->totalFiles); - SHGetFileInfo(fn, FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(shfi), SHGFI_USEFILEATTRIBUTES|SHGFI_ICON|SHGFI_SMALLICON); + SHGetFileInfo(fn, FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(shfi), SHGFI_USEFILEATTRIBUTES | SHGFI_ICON | SHGFI_SMALLICON); dat->hIcon = shfi.hIcon; } else if (fn) { mir_sntprintf(msg, SIZEOF(msg), _T("%s: %s"), pcli->pfnGetContactDisplayName(fts->hContact, 0), fn); - SHGetFileInfo(fn, FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(shfi), SHGFI_USEFILEATTRIBUTES|SHGFI_ICON|SHGFI_SMALLICON); + SHGetFileInfo(fn, FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(shfi), SHGFI_USEFILEATTRIBUTES | SHGFI_ICON | SHGFI_SMALLICON); dat->hIcon = shfi.hIcon; } else { @@ -177,10 +173,10 @@ static void SetFtStatus(HWND hwndDlg, TCHAR *text, int mode) SetDlgItemText(hwndDlg, IDC_STATUS, TranslateTS(text)); SetDlgItemText(hwndDlg, IDC_TRANSFERCOMPLETED, TranslateTS(text)); - ShowWindow(GetDlgItem(hwndDlg, IDC_STATUS), (mode == FTS_TEXT)?SW_SHOW:SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDC_ALLFILESPROGRESS), (mode == FTS_PROGRESS)?SW_SHOW:SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDC_TRANSFERCOMPLETED), (mode == FTS_OPEN)?SW_SHOW:SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDC_FILEICON), (mode == FTS_OPEN)?SW_SHOW:SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_STATUS), (mode == FTS_TEXT) ? SW_SHOW : SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_ALLFILESPROGRESS), (mode == FTS_PROGRESS) ? SW_SHOW : SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_TRANSFERCOMPLETED), (mode == FTS_OPEN) ? SW_SHOW : SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_FILEICON), (mode == FTS_OPEN) ? SW_SHOW : SW_HIDE); } static void HideProgressControls(HWND hwndDlg) @@ -190,7 +186,7 @@ static void HideProgressControls(HWND hwndDlg) GetWindowRect(GetDlgItem(hwndDlg, IDC_ALLPRECENTS), &rc); MapWindowPoints(NULL, hwndDlg, (LPPOINT)&rc, 2); - SetWindowPos(hwndDlg, NULL, 0, 0, 100, rc.bottom+3, SWP_NOMOVE|SWP_NOZORDER); + SetWindowPos(hwndDlg, NULL, 0, 0, 100, rc.bottom + 3, SWP_NOMOVE | SWP_NOZORDER); ShowWindow(GetDlgItem(hwndDlg, IDC_ALLTRANSFERRED), SW_HIDE); ShowWindow(GetDlgItem(hwndDlg, IDC_ALLSPEED), SW_HIDE); @@ -202,359 +198,348 @@ static void HideProgressControls(HWND hwndDlg) static int FileTransferDlgResizer(HWND, LPARAM, UTILRESIZECONTROL *urc) { - switch(urc->wId) { - case IDC_CONTACTNAME: - case IDC_STATUS: - case IDC_ALLFILESPROGRESS: - case IDC_TRANSFERCOMPLETED: - return RD_ANCHORX_WIDTH|RD_ANCHORY_TOP; - case IDC_FRAME: - return RD_ANCHORX_WIDTH|RD_ANCHORY_BOTTOM; - case IDC_ALLPRECENTS: - case IDCANCEL: - case IDC_OPENFILE: - case IDC_OPENFOLDER: - return RD_ANCHORX_RIGHT|RD_ANCHORY_TOP; - - case IDC_ALLTRANSFERRED: - urc->rcItem.right = urc->rcItem.left + (urc->rcItem.right - urc->rcItem.left - urc->dlgOriginalSize.cx + urc->dlgNewSize.cx) / 3; - return RD_ANCHORX_CUSTOM|RD_ANCHORY_CUSTOM; - - case IDC_ALLSPEED: - urc->rcItem.right = urc->rcItem.right - urc->dlgOriginalSize.cx + urc->dlgNewSize.cx; - urc->rcItem.left = urc->rcItem.left + (urc->rcItem.right - urc->rcItem.left) / 3; - return RD_ANCHORX_CUSTOM|RD_ANCHORY_CUSTOM; + switch (urc->wId) { + case IDC_CONTACTNAME: + case IDC_STATUS: + case IDC_ALLFILESPROGRESS: + case IDC_TRANSFERCOMPLETED: + return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP; + case IDC_FRAME: + return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM; + case IDC_ALLPRECENTS: + case IDCANCEL: + case IDC_OPENFILE: + case IDC_OPENFOLDER: + return RD_ANCHORX_RIGHT | RD_ANCHORY_TOP; + + case IDC_ALLTRANSFERRED: + urc->rcItem.right = urc->rcItem.left + (urc->rcItem.right - urc->rcItem.left - urc->dlgOriginalSize.cx + urc->dlgNewSize.cx) / 3; + return RD_ANCHORX_CUSTOM | RD_ANCHORY_CUSTOM; + + case IDC_ALLSPEED: + urc->rcItem.right = urc->rcItem.right - urc->dlgOriginalSize.cx + urc->dlgNewSize.cx; + urc->rcItem.left = urc->rcItem.left + (urc->rcItem.right - urc->rcItem.left) / 3; + return RD_ANCHORX_CUSTOM | RD_ANCHORY_CUSTOM; } - return RD_ANCHORX_LEFT|RD_ANCHORY_TOP; + return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; } INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch (msg) - { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - dat = (FileDlgData*)lParam; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); - dat->hNotifyEvent = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_RECVEVENT); - dat->transferStatus.currentFileNumber = -1; - if (dat->send) { - dat->fs = (HANDLE)CallContactService(dat->hContact, PSS_FILET, (WPARAM)dat->szMsg, (LPARAM)dat->files); - SetFtStatus(hwndDlg, LPGENT("Request sent, waiting for acceptance..."), FTS_TEXT); - SetOpenFileButtonStyle(GetDlgItem(hwndDlg, IDC_OPENFILE), 1); - dat->waitingForAcceptance = 1; - // hide "open" button since it may cause potential access violations... - ShowWindow(GetDlgItem(hwndDlg, IDC_OPENFILE), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDC_OPENFOLDER), SW_HIDE); - } - else { //recv - CreateDirectoryTreeT(dat->szSavePath); - dat->fs = (HANDLE)CallContactService(dat->hContact, PSS_FILEALLOWT, (WPARAM)dat->fs, (LPARAM)dat->szSavePath); - dat->transferStatus.tszWorkingDir = mir_tstrdup(dat->szSavePath); - if (db_get_b(dat->hContact, "CList", "NotOnList", 0)) dat->resumeBehaviour = FILERESUME_ASK; - else dat->resumeBehaviour = db_get_b(NULL, "SRFile", "IfExists", FILERESUME_ASK); - SetFtStatus(hwndDlg, LPGENT("Waiting for connection..."), FTS_TEXT); - } - { - /* check we actually got an fs handle back from the protocol */ - if ( !dat->fs) { - SetFtStatus(hwndDlg, LPGENT("Unable to initiate transfer."), FTS_TEXT); - dat->waitingForAcceptance = 0; - } - } - { - LOGFONT lf; - HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_CONTACTNAME, WM_GETFONT, 0, 0); - GetObject(hFont, sizeof(lf), &lf); - lf.lfWeight = FW_BOLD; - hFont = CreateFontIndirect(&lf); - SendDlgItemMessage(hwndDlg, IDC_CONTACTNAME, WM_SETFONT, (WPARAM)hFont, 0); - } + switch (msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + dat = (FileDlgData*)lParam; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); + dat->hNotifyEvent = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_RECVEVENT); + dat->transferStatus.currentFileNumber = -1; + if (dat->send) { + if (db_mc_isMeta(dat->hContact)) + dat->hContact = db_mc_getMostOnline(dat->hContact); + dat->fs = (HANDLE)CallContactService(dat->hContact, PSS_FILET, (WPARAM)dat->szMsg, (LPARAM)dat->files); + SetFtStatus(hwndDlg, LPGENT("Request sent, waiting for acceptance..."), FTS_TEXT); + SetOpenFileButtonStyle(GetDlgItem(hwndDlg, IDC_OPENFILE), 1); + dat->waitingForAcceptance = 1; + // hide "open" button since it may cause potential access violations... + ShowWindow(GetDlgItem(hwndDlg, IDC_OPENFILE), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_OPENFOLDER), SW_HIDE); + } + else { //recv + CreateDirectoryTreeT(dat->szSavePath); + dat->fs = (HANDLE)CallContactService(dat->hContact, PSS_FILEALLOWT, (WPARAM)dat->fs, (LPARAM)dat->szSavePath); + dat->transferStatus.tszWorkingDir = mir_tstrdup(dat->szSavePath); + if (db_get_b(dat->hContact, "CList", "NotOnList", 0)) dat->resumeBehaviour = FILERESUME_ASK; + else dat->resumeBehaviour = db_get_b(NULL, "SRFile", "IfExists", FILERESUME_ASK); + SetFtStatus(hwndDlg, LPGENT("Waiting for connection..."), FTS_TEXT); + } - { - SHFILEINFO shfi = {0}; - SHGetFileInfo(_T(""), FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(shfi), SHGFI_USEFILEATTRIBUTES|SHGFI_ICON|SHGFI_SMALLICON); - dat->hIconFolder = shfi.hIcon; - } + /* check we actually got an fs handle back from the protocol */ + if (!dat->fs) { + SetFtStatus(hwndDlg, LPGENT("Unable to initiate transfer."), FTS_TEXT); + dat->waitingForAcceptance = 0; + } + { + LOGFONT lf; + HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_CONTACTNAME, WM_GETFONT, 0, 0); + GetObject(hFont, sizeof(lf), &lf); + lf.lfWeight = FW_BOLD; + hFont = CreateFontIndirect(&lf); + SendDlgItemMessage(hwndDlg, IDC_CONTACTNAME, WM_SETFONT, (WPARAM)hFont, 0); + + SHFILEINFO shfi = { 0 }; + SHGetFileInfo(_T(""), FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(shfi), SHGFI_USEFILEATTRIBUTES | SHGFI_ICON | SHGFI_SMALLICON); + dat->hIconFolder = shfi.hIcon; + } + dat->hIcon = NULL; + { + char *szProto = GetContactProto(dat->hContact); + WORD status = db_get_w(dat->hContact, szProto, "Status", ID_STATUS_ONLINE); + SendDlgItemMessage(hwndDlg, IDC_CONTACT, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadSkinnedProtoIcon(szProto, status)); + } - dat->hIcon = NULL; - { - char *szProto=GetContactProto(dat->hContact); - WORD status = db_get_w(dat->hContact,szProto,"Status",ID_STATUS_ONLINE); - SendDlgItemMessage(hwndDlg, IDC_CONTACT, BM_SETIMAGE, IMAGE_ICON,(LPARAM)LoadSkinnedProtoIcon(szProto, status)); - } + SendDlgItemMessage(hwndDlg, IDC_CONTACT, BUTTONADDTOOLTIP, (WPARAM)LPGEN("Contact menu"), 0); + SendDlgItemMessage(hwndDlg, IDC_CONTACT, BUTTONSETASFLATBTN, TRUE, 0); - SendDlgItemMessage(hwndDlg, IDC_CONTACT, BUTTONADDTOOLTIP, (WPARAM)LPGEN("Contact menu"), 0); - SendDlgItemMessage(hwndDlg, IDC_CONTACT, BUTTONSETASFLATBTN, TRUE, 0); + Button_SetIcon_IcoLib(hwndDlg, IDC_OPENFILE, SKINICON_OTHER_DOWNARROW, LPGEN("Open...")); + SendDlgItemMessage(hwndDlg, IDC_OPENFILE, BUTTONSETASPUSHBTN, TRUE, 0); - Button_SetIcon_IcoLib(hwndDlg, IDC_OPENFILE, SKINICON_OTHER_DOWNARROW, LPGEN("Open...")); - SendDlgItemMessage(hwndDlg, IDC_OPENFILE, BUTTONSETASPUSHBTN, TRUE, 0); + SendDlgItemMessage(hwndDlg, IDC_OPENFOLDER, BM_SETIMAGE, IMAGE_ICON, (LPARAM)dat->hIconFolder); + SendDlgItemMessage(hwndDlg, IDC_OPENFOLDER, BUTTONADDTOOLTIP, (WPARAM)LPGEN("Open folder"), 0); + SendDlgItemMessage(hwndDlg, IDC_OPENFOLDER, BUTTONSETASFLATBTN, TRUE, 0); - SendDlgItemMessage(hwndDlg, IDC_OPENFOLDER, BM_SETIMAGE, IMAGE_ICON, (LPARAM)dat->hIconFolder); - SendDlgItemMessage(hwndDlg, IDC_OPENFOLDER, BUTTONADDTOOLTIP, (WPARAM)LPGEN("Open folder"), 0); - SendDlgItemMessage(hwndDlg, IDC_OPENFOLDER, BUTTONSETASFLATBTN, TRUE, 0); + Button_SetIcon_IcoLib(hwndDlg, IDCANCEL, SKINICON_OTHER_DELETE, LPGEN("Cancel")); - Button_SetIcon_IcoLib(hwndDlg, IDCANCEL, SKINICON_OTHER_DELETE, LPGEN("Cancel")); + SetDlgItemText(hwndDlg, IDC_CONTACTNAME, pcli->pfnGetContactDisplayName(dat->hContact, 0)); - SetDlgItemText(hwndDlg, IDC_CONTACTNAME, pcli->pfnGetContactDisplayName(dat->hContact, 0)); + if (!dat->waitingForAcceptance) SetTimer(hwndDlg, 1, 1000, NULL); + return TRUE; - if ( !dat->waitingForAcceptance) SetTimer(hwndDlg, 1, 1000, NULL); - return TRUE; - case WM_TIMER: - MoveMemory(dat->bytesRecvedHistory+1, dat->bytesRecvedHistory, sizeof(dat->bytesRecvedHistory)-sizeof(dat->bytesRecvedHistory[0])); - dat->bytesRecvedHistory[0] = dat->transferStatus.totalProgress; - if (dat->bytesRecvedHistorySize < SIZEOF(dat->bytesRecvedHistory)) - dat->bytesRecvedHistorySize++; + case WM_TIMER: + MoveMemory(dat->bytesRecvedHistory + 1, dat->bytesRecvedHistory, sizeof(dat->bytesRecvedHistory) - sizeof(dat->bytesRecvedHistory[0])); + dat->bytesRecvedHistory[0] = dat->transferStatus.totalProgress; + if (dat->bytesRecvedHistorySize < SIZEOF(dat->bytesRecvedHistory)) + dat->bytesRecvedHistorySize++; - { - TCHAR szSpeed[32], szTime[32], szDisplay[96]; - SYSTEMTIME st; - ULARGE_INTEGER li; - FILETIME ft; - - GetSensiblyFormattedSize((dat->bytesRecvedHistory[0]-dat->bytesRecvedHistory[dat->bytesRecvedHistorySize-1])/dat->bytesRecvedHistorySize, szSpeed, SIZEOF(szSpeed), 0, 1, NULL); - if (dat->bytesRecvedHistory[0] == dat->bytesRecvedHistory[dat->bytesRecvedHistorySize-1]) - lstrcpy(szTime, _T("??:??:??")); - else { - li.QuadPart = BIGI(10000000)*(dat->transferStatus.currentFileSize-dat->transferStatus.currentFileProgress)*dat->bytesRecvedHistorySize/(dat->bytesRecvedHistory[0]-dat->bytesRecvedHistory[dat->bytesRecvedHistorySize-1]); - ft.dwHighDateTime = li.HighPart; ft.dwLowDateTime = li.LowPart; - FileTimeToSystemTime(&ft, &st); - GetTimeFormat(LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT|TIME_NOTIMEMARKER, &st, NULL, szTime, SIZEOF(szTime)); - } - if (dat->bytesRecvedHistory[0] != dat->bytesRecvedHistory[dat->bytesRecvedHistorySize-1]) { - li.QuadPart = BIGI(10000000)*(dat->transferStatus.totalBytes-dat->transferStatus.totalProgress)*dat->bytesRecvedHistorySize/(dat->bytesRecvedHistory[0]-dat->bytesRecvedHistory[dat->bytesRecvedHistorySize-1]); - ft.dwHighDateTime = li.HighPart; ft.dwLowDateTime = li.LowPart; - FileTimeToSystemTime(&ft, &st); - GetTimeFormat(LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT|TIME_NOTIMEMARKER, &st, NULL, szTime, SIZEOF(szTime)); - } - - mir_sntprintf(szDisplay, SIZEOF(szDisplay), _T("%s/%s (%s %s)"), szSpeed, TranslateT("sec"), szTime, TranslateT("remaining")); - SetDlgItemText(hwndDlg, IDC_ALLSPEED, szDisplay); + { + TCHAR szSpeed[32], szTime[32], szDisplay[96]; + SYSTEMTIME st; + ULARGE_INTEGER li; + FILETIME ft; + + GetSensiblyFormattedSize((dat->bytesRecvedHistory[0] - dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]) / dat->bytesRecvedHistorySize, szSpeed, SIZEOF(szSpeed), 0, 1, NULL); + if (dat->bytesRecvedHistory[0] == dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]) + lstrcpy(szTime, _T("??:??:??")); + else { + li.QuadPart = BIGI(10000000)*(dat->transferStatus.currentFileSize - dat->transferStatus.currentFileProgress)*dat->bytesRecvedHistorySize / (dat->bytesRecvedHistory[0] - dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]); + ft.dwHighDateTime = li.HighPart; ft.dwLowDateTime = li.LowPart; + FileTimeToSystemTime(&ft, &st); + GetTimeFormat(LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER, &st, NULL, szTime, SIZEOF(szTime)); + } + if (dat->bytesRecvedHistory[0] != dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]) { + li.QuadPart = BIGI(10000000)*(dat->transferStatus.totalBytes - dat->transferStatus.totalProgress)*dat->bytesRecvedHistorySize / (dat->bytesRecvedHistory[0] - dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]); + ft.dwHighDateTime = li.HighPart; ft.dwLowDateTime = li.LowPart; + FileTimeToSystemTime(&ft, &st); + GetTimeFormat(LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER, &st, NULL, szTime, SIZEOF(szTime)); } - break; - case WM_MEASUREITEM: - return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam); + mir_sntprintf(szDisplay, SIZEOF(szDisplay), _T("%s/%s (%s %s)"), szSpeed, TranslateT("sec"), szTime, TranslateT("remaining")); + SetDlgItemText(hwndDlg, IDC_ALLSPEED, szDisplay); + } + break; - case WM_DRAWITEM: - return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam); + case WM_MEASUREITEM: + return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam); - case WM_FT_CLEANUP: - if ( !dat->fs) - { - PostMessage(GetParent(hwndDlg), WM_FT_REMOVE, 0, (LPARAM)hwndDlg); - DestroyWindow(hwndDlg); - } + case WM_DRAWITEM: + return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam); + + case WM_FT_CLEANUP: + if (!dat->fs) { + PostMessage(GetParent(hwndDlg), WM_FT_REMOVE, 0, (LPARAM)hwndDlg); + DestroyWindow(hwndDlg); + } + break; + + case WM_COMMAND: + if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact)) break; - case WM_COMMAND: - if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact)) - break; + switch (LOWORD(wParam)) { + case IDOK: + case IDCANCEL: + PostMessage(GetParent(hwndDlg), WM_FT_REMOVE, 0, (LPARAM)hwndDlg); + DestroyWindow(hwndDlg); + break; - switch (LOWORD(wParam)) + case IDC_CONTACT: { - case IDOK: - case IDCANCEL: - PostMessage(GetParent(hwndDlg), WM_FT_REMOVE, 0, (LPARAM)hwndDlg); - DestroyWindow(hwndDlg); - break; - - case IDC_CONTACT: - { RECT rc; - HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0); - GetWindowRect((HWND)lParam, &rc); - TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL); - DestroyMenu(hMenu); - break; - } - - case IDC_TRANSFERCOMPLETED: - if (dat->transferStatus.currentFileNumber <= 1 && CheckVirusScanned(hwndDlg, dat, 0)) - { - ShellExecute(NULL, NULL, dat->files[0], NULL, NULL, SW_SHOW); - break; - } + RECT rc; + HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0); + GetWindowRect((HWND)lParam, &rc); + TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL); + DestroyMenu(hMenu); + } + break; - case IDC_OPENFOLDER: - if (dat) - { - TCHAR *path = dat->transferStatus.tszWorkingDir; - if ( !path || !path[0]) - { - path = NEWTSTR_ALLOCA(dat->transferStatus.tszCurrentFile); - TCHAR *p = _tcsrchr(path, '\\'); if (p) *p = 0; - } + case IDC_TRANSFERCOMPLETED: + if (dat->transferStatus.currentFileNumber <= 1 && CheckVirusScanned(hwndDlg, dat, 0)) { + ShellExecute(NULL, NULL, dat->files[0], NULL, NULL, SW_SHOW); + break; + } - if (path) ShellExecute(NULL, _T("open"), path, NULL, NULL, SW_SHOW); - } - break; + case IDC_OPENFOLDER: + if (dat) { + TCHAR *path = dat->transferStatus.tszWorkingDir; + if (!path || !path[0]) { + path = NEWTSTR_ALLOCA(dat->transferStatus.tszCurrentFile); + TCHAR *p = _tcsrchr(path, '\\'); if (p) *p = 0; + } - case IDC_OPENFILE: - { - TCHAR **files; - HMENU hMenu; - RECT rc; - int ret; + if (path) ShellExecute(NULL, _T("open"), path, NULL, NULL, SW_SHOW); + } + break; - if (dat->send) - if (dat->files == NULL) - files = dat->transferStatus.ptszFiles; - else - files = dat->files; + case IDC_OPENFILE: + TCHAR **files; + if (dat->send) { + if (dat->files == NULL) + files = dat->transferStatus.ptszFiles; + else + files = dat->files; + } + else files = dat->files; + + HMENU hMenu = CreatePopupMenu(); + AppendMenu(hMenu, MF_STRING, 1, TranslateT("Open folder")); + AppendMenu(hMenu, MF_SEPARATOR, 0, 0); + + if (files && *files) { + int limit; + TCHAR *pszFilename, *pszNewFileName; + + if (dat->send) + limit = dat->transferStatus.totalFiles; + else + limit = dat->transferStatus.currentFileNumber; + + // Loop over all transfered files and add them to the menu + for (int i = 0; i < limit; i++) { + pszFilename = _tcsrchr(files[i], '\\'); + if (pszFilename == NULL) + pszFilename = files[i]; else - files = dat->files; - - hMenu = CreatePopupMenu(); - AppendMenu(hMenu, MF_STRING, 1, TranslateT("Open folder")); - AppendMenu(hMenu, MF_SEPARATOR, 0, 0); - - if (files && *files) - { - int i, limit; - TCHAR *pszFilename, *pszNewFileName; - - if (dat->send) - limit = dat->transferStatus.totalFiles; - else - limit = dat->transferStatus.currentFileNumber; - - // Loop over all transfered files and add them to the menu - for (i=0; i < limit; i++) { - pszFilename = _tcsrchr(files[i], '\\'); - if (pszFilename == NULL) - pszFilename = files[i]; - else - pszFilename++; - { - if (pszFilename) { - size_t cbFileNameLen = _tcslen(pszFilename); - - pszNewFileName = (TCHAR*)mir_alloc(cbFileNameLen*2*sizeof(TCHAR)); - TCHAR *p = pszNewFileName; - for (size_t pszlen = 0; pszlen < cbFileNameLen; pszlen++) { - *p++=pszFilename[pszlen]; - if (pszFilename[pszlen] == '&') - *p++='&'; - } - *p = '\0'; - AppendMenu(hMenu, MF_STRING, i+10, pszNewFileName); - mir_free(pszNewFileName); - } - } - } - } + pszFilename++; - GetWindowRect((HWND)lParam, &rc); - CheckDlgButton(hwndDlg, IDC_OPENFILE, BST_CHECKED); - ret = TrackPopupMenu(hMenu, TPM_RETURNCMD|TPM_RIGHTALIGN, rc.right, rc.bottom, 0, hwndDlg, NULL); - CheckDlgButton(hwndDlg, IDC_OPENFILE, BST_UNCHECKED); - DestroyMenu(hMenu); - - if (ret == 1) - { - TCHAR *path = dat->transferStatus.tszWorkingDir; - if ( !path || !path[0]) - { - path = NEWTSTR_ALLOCA(dat->transferStatus.tszCurrentFile); - TCHAR *p = _tcsrchr(path, '\\'); if (p) *p = 0; - } + if (pszFilename) { + size_t cbFileNameLen = _tcslen(pszFilename); - if (path) ShellExecute(NULL, _T("open"), path, NULL, NULL, SW_SHOW); + pszNewFileName = (TCHAR*)mir_alloc(cbFileNameLen * 2 * sizeof(TCHAR)); + TCHAR *p = pszNewFileName; + for (size_t pszlen = 0; pszlen < cbFileNameLen; pszlen++) { + *p++ = pszFilename[pszlen]; + if (pszFilename[pszlen] == '&') + *p++ = '&'; + } + *p = '\0'; + AppendMenu(hMenu, MF_STRING, i + 10, pszNewFileName); + mir_free(pszNewFileName); } - else if (ret && CheckVirusScanned(hwndDlg, dat, ret)) - ShellExecute(NULL, NULL, files[ret-10], NULL, NULL, SW_SHOW); + } + } - break; + RECT rc; + GetWindowRect((HWND)lParam, &rc); + CheckDlgButton(hwndDlg, IDC_OPENFILE, BST_CHECKED); + int ret = TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_RIGHTALIGN, rc.right, rc.bottom, 0, hwndDlg, NULL); + CheckDlgButton(hwndDlg, IDC_OPENFILE, BST_UNCHECKED); + DestroyMenu(hMenu); + + if (ret == 1) { + TCHAR *path = dat->transferStatus.tszWorkingDir; + if (!path || !path[0]) { + path = NEWTSTR_ALLOCA(dat->transferStatus.tszCurrentFile); + TCHAR *p = _tcsrchr(path, '\\'); + if (p) + *p = 0; } + + if (path) ShellExecute(NULL, _T("open"), path, NULL, NULL, SW_SHOW); } - break; - case M_FILEEXISTSDLGREPLY: - { PROTOFILERESUME *pfr = (PROTOFILERESUME*)lParam; + else if (ret && CheckVirusScanned(hwndDlg, dat, ret)) + ShellExecute(NULL, NULL, files[ret - 10], NULL, NULL, SW_SHOW); + } + break; + + case M_FILEEXISTSDLGREPLY: + EnableWindow(hwndDlg, TRUE); + { + PROTOFILERESUME *pfr = (PROTOFILERESUME*)lParam; TCHAR *szOriginalFilename = (TCHAR*)wParam; char *szProto = GetContactProto(dat->hContact); - EnableWindow(hwndDlg, TRUE); - switch(pfr->action) { - case FILERESUME_CANCEL: - if (dat->fs) CallContactService(dat->hContact, PSS_FILECANCEL, (WPARAM)dat->fs, 0); - dat->fs = NULL; - mir_free(szOriginalFilename); - if (pfr->szFilename) mir_free((char*)pfr->szFilename); - mir_free(pfr); - return 0; - case FILERESUME_RESUMEALL: - case FILERESUME_OVERWRITEALL: - dat->resumeBehaviour = pfr->action; - pfr->action&=~FILERESUMEF_ALL; - break; - case FILERESUME_RENAMEALL: - pfr->action = FILERESUME_RENAME; - { TCHAR *pszExtension, *pszFilename; - int i; - if ((pszFilename = _tcsrchr(szOriginalFilename, '\\')) == NULL) pszFilename = szOriginalFilename; - if ((pszExtension = _tcsrchr(pszFilename+1, '.')) == NULL) pszExtension = pszFilename+lstrlen(pszFilename); - if (pfr->szFilename) mir_free((TCHAR*)pfr->szFilename); - size_t size = (pszExtension-szOriginalFilename)+21+lstrlen(pszExtension); - pfr->szFilename = (TCHAR*)mir_alloc(sizeof(TCHAR)*size); - for (i = 1;;i++) { - mir_sntprintf((TCHAR*)pfr->szFilename, size, _T("%.*s (%u)%s"), pszExtension-szOriginalFilename, szOriginalFilename, i, pszExtension); - if (_taccess(pfr->szFilename, 0) != 0) - break; - } + switch (pfr->action) { + case FILERESUME_CANCEL: + if (dat->fs) CallContactService(dat->hContact, PSS_FILECANCEL, (WPARAM)dat->fs, 0); + dat->fs = NULL; + mir_free(szOriginalFilename); + if (pfr->szFilename) mir_free((char*)pfr->szFilename); + mir_free(pfr); + return 0; + case FILERESUME_RESUMEALL: + case FILERESUME_OVERWRITEALL: + dat->resumeBehaviour = pfr->action; + pfr->action &= ~FILERESUMEF_ALL; + break; + case FILERESUME_RENAMEALL: + pfr->action = FILERESUME_RENAME; + { + TCHAR *pszExtension, *pszFilename; + if ((pszFilename = _tcsrchr(szOriginalFilename, '\\')) == NULL) pszFilename = szOriginalFilename; + if ((pszExtension = _tcsrchr(pszFilename + 1, '.')) == NULL) pszExtension = pszFilename + lstrlen(pszFilename); + if (pfr->szFilename) mir_free((TCHAR*)pfr->szFilename); + size_t size = (pszExtension - szOriginalFilename) + 21 + lstrlen(pszExtension); + pfr->szFilename = (TCHAR*)mir_alloc(sizeof(TCHAR)*size); + for (int i = 1;; i++) { + mir_sntprintf((TCHAR*)pfr->szFilename, size, _T("%.*s (%u)%s"), pszExtension - szOriginalFilename, szOriginalFilename, i, pszExtension); + if (_taccess(pfr->szFilename, 0) != 0) + break; } - break; + } + break; } mir_free(szOriginalFilename); CallProtoService(szProto, PS_FILERESUMET, (WPARAM)dat->fs, (LPARAM)pfr); if (pfr->szFilename) mir_free((char*)pfr->szFilename); mir_free(pfr); - break; } - case HM_RECVEVENT: - { ACKDATA *ack = (ACKDATA*)lParam; - if (ack->hProcess != dat->fs) break; /* icq abuses this sometimes */ - if (ack->hContact != dat->hContact) break; + break; + + case HM_RECVEVENT: + { + ACKDATA *ack = (ACKDATA*)lParam; + if (ack->hProcess != dat->fs) break; if (ack->type != ACKTYPE_FILE) break; + if (ack->hContact != dat->hContact) break; if (dat->waitingForAcceptance) { SetTimer(hwndDlg, 1, 1000, NULL); dat->waitingForAcceptance = 0; } - switch(ack->result) { - case ACKRESULT_SENTREQUEST: SetFtStatus(hwndDlg, LPGENT("Decision sent"), FTS_TEXT); break; - case ACKRESULT_CONNECTING: SetFtStatus(hwndDlg, LPGENT("Connecting..."), FTS_TEXT); break; - case ACKRESULT_CONNECTPROXY: SetFtStatus(hwndDlg, LPGENT("Connecting to proxy..."), FTS_TEXT); break; - case ACKRESULT_CONNECTED: SetFtStatus(hwndDlg, LPGENT("Connected"), FTS_TEXT); break; - case ACKRESULT_LISTENING: SetFtStatus(hwndDlg, LPGENT("Waiting for connection..."), FTS_TEXT); break; - case ACKRESULT_INITIALISING: SetFtStatus(hwndDlg, LPGENT("Initializing..."), FTS_TEXT); break; - case ACKRESULT_NEXTFILE: - SetFtStatus(hwndDlg, LPGENT("Moving to next file..."), FTS_TEXT); - SetDlgItemTextA(hwndDlg, IDC_FILENAME, ""); - if (dat->transferStatus.currentFileNumber == 1 && dat->transferStatus.totalFiles>1 && !dat->send) - SetOpenFileButtonStyle(GetDlgItem(hwndDlg, IDC_OPENFILE), 1); - if (dat->transferStatus.currentFileNumber != -1 && dat->files && !dat->send && db_get_b(NULL, "SRFile", "UseScanner", VIRUSSCAN_DISABLE) == VIRUSSCAN_DURINGDL) { - if (GetFileAttributes(dat->files[dat->transferStatus.currentFileNumber])&FILE_ATTRIBUTE_DIRECTORY) - PostMessage(hwndDlg, M_VIRUSSCANDONE, dat->transferStatus.currentFileNumber, 0); - else { - virusscanthreadstartinfo *vstsi; - vstsi = (struct virusscanthreadstartinfo*)mir_alloc(sizeof(struct virusscanthreadstartinfo)); - vstsi->hwndReply = hwndDlg; - vstsi->szFile = mir_tstrdup(dat->files[dat->transferStatus.currentFileNumber]); - vstsi->returnCode = dat->transferStatus.currentFileNumber; - forkthread((void (*)(void*))RunVirusScannerThread, 0, vstsi); - } + + switch (ack->result) { + case ACKRESULT_SENTREQUEST: SetFtStatus(hwndDlg, LPGENT("Decision sent"), FTS_TEXT); break; + case ACKRESULT_CONNECTING: SetFtStatus(hwndDlg, LPGENT("Connecting..."), FTS_TEXT); break; + case ACKRESULT_CONNECTPROXY: SetFtStatus(hwndDlg, LPGENT("Connecting to proxy..."), FTS_TEXT); break; + case ACKRESULT_CONNECTED: SetFtStatus(hwndDlg, LPGENT("Connected"), FTS_TEXT); break; + case ACKRESULT_LISTENING: SetFtStatus(hwndDlg, LPGENT("Waiting for connection..."), FTS_TEXT); break; + case ACKRESULT_INITIALISING: SetFtStatus(hwndDlg, LPGENT("Initializing..."), FTS_TEXT); break; + case ACKRESULT_NEXTFILE: + SetFtStatus(hwndDlg, LPGENT("Moving to next file..."), FTS_TEXT); + SetDlgItemTextA(hwndDlg, IDC_FILENAME, ""); + if (dat->transferStatus.currentFileNumber == 1 && dat->transferStatus.totalFiles > 1 && !dat->send) + SetOpenFileButtonStyle(GetDlgItem(hwndDlg, IDC_OPENFILE), 1); + if (dat->transferStatus.currentFileNumber != -1 && dat->files && !dat->send && db_get_b(NULL, "SRFile", "UseScanner", VIRUSSCAN_DISABLE) == VIRUSSCAN_DURINGDL) { + if (GetFileAttributes(dat->files[dat->transferStatus.currentFileNumber])&FILE_ATTRIBUTE_DIRECTORY) + PostMessage(hwndDlg, M_VIRUSSCANDONE, dat->transferStatus.currentFileNumber, 0); + else { + virusscanthreadstartinfo *vstsi; + vstsi = (struct virusscanthreadstartinfo*)mir_alloc(sizeof(struct virusscanthreadstartinfo)); + vstsi->hwndReply = hwndDlg; + vstsi->szFile = mir_tstrdup(dat->files[dat->transferStatus.currentFileNumber]); + vstsi->returnCode = dat->transferStatus.currentFileNumber; + forkthread((void(*)(void*))RunVirusScannerThread, 0, vstsi); } - break; - case ACKRESULT_FILERESUME: + } + break; + + case ACKRESULT_FILERESUME: + UpdateProtoFileTransferStatus(&dat->transferStatus, (PROTOFILETRANSFERSTATUS*)ack->lParam); { - UpdateProtoFileTransferStatus(&dat->transferStatus, (PROTOFILETRANSFERSTATUS*)ack->lParam); PROTOFILETRANSFERSTATUS *fts = &dat->transferStatus; - SetFilenameControls(hwndDlg, dat, fts); - int res = _taccess(fts->tszCurrentFile, 0); - if (res) + if (_taccess(fts->tszCurrentFile, 0)) break; SetFtStatus(hwndDlg, LPGENT("File already exists"), FTS_TEXT); @@ -565,26 +550,25 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR EnableWindow(hwndDlg, FALSE); } else { - PROTOFILERESUME *pfr; - pfr = (PROTOFILERESUME*)mir_alloc(sizeof(PROTOFILERESUME)); + PROTOFILERESUME *pfr = (PROTOFILERESUME*)mir_alloc(sizeof(PROTOFILERESUME)); pfr->action = dat->resumeBehaviour; pfr->szFilename = NULL; PostMessage(hwndDlg, M_FILEEXISTSDLGREPLY, (WPARAM)mir_tstrdup(fts->tszCurrentFile), (LPARAM)pfr); } - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, 1); - return TRUE; } - case ACKRESULT_DATA: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, 1); + return TRUE; + + case ACKRESULT_DATA: { PROTOFILETRANSFERSTATUS *fts = (PROTOFILETRANSFERSTATUS*)ack->lParam; TCHAR str[64], str2[64], szSizeDone[32], szSizeTotal[32];//, *contactName; - int units; if (dat->fileVirusScanned == NULL) dat->fileVirusScanned = (int*)mir_calloc(sizeof(int) * fts->totalFiles); // This needs to be here - otherwise we get holes in the files array - if ( !dat->send) { + if (!dat->send) { if (dat->files == NULL) dat->files = (TCHAR**)mir_calloc((fts->totalFiles + 1) * sizeof(TCHAR*)); if (fts->currentFileNumber < fts->totalFiles && dat->files[fts->currentFileNumber] == NULL) @@ -592,7 +576,8 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR } /* HACK: for 0.3.3, limit updates to around 1.1 ack per second */ - if (fts->totalProgress != fts->totalBytes && GetTickCount() < (dat->dwTicks + 650)) break; // the last update was less than a second ago! + if (fts->totalProgress != fts->totalBytes && GetTickCount() < (dat->dwTicks + 650)) + break; // the last update was less than a second ago! dat->dwTicks = GetTickCount(); // Update local transfer status with data from protocol @@ -600,8 +585,7 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR fts = &dat->transferStatus; bool firstTime = false; - if ((GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_ALLFILESPROGRESS), GWL_STYLE) & WS_VISIBLE) == 0) - { + if ((GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_ALLFILESPROGRESS), GWL_STYLE) & WS_VISIBLE) == 0) { SetFtStatus(hwndDlg, (fts->flags & PFTS_SENDING) ? LPGENT("Sending...") : LPGENT("Receiving..."), FTS_PROGRESS); SetFilenameControls(hwndDlg, dat, fts); firstTime = true; @@ -609,146 +593,150 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR const unsigned long lastPos = SendDlgItemMessage(hwndDlg, IDC_ALLFILESPROGRESS, PBM_GETPOS, 0, 0); const unsigned long nextPos = fts->totalBytes ? (BIGI(100) * fts->totalProgress / fts->totalBytes) : 0; - if (lastPos != nextPos || firstTime) - { + if (lastPos != nextPos || firstTime) { SendDlgItemMessage(hwndDlg, IDC_ALLFILESPROGRESS, PBM_SETPOS, nextPos, 0); mir_sntprintf(str, SIZEOF(str), _T("%u%%"), nextPos); SetDlgItemText(hwndDlg, IDC_ALLPRECENTS, str); } + int units; GetSensiblyFormattedSize(fts->totalBytes, szSizeTotal, SIZEOF(szSizeTotal), 0, 1, &units); GetSensiblyFormattedSize(fts->totalProgress, szSizeDone, SIZEOF(szSizeDone), units, 0, NULL); mir_sntprintf(str, SIZEOF(str), _T("%s/%s"), szSizeDone, szSizeTotal); str2[0] = 0; GetDlgItemText(hwndDlg, IDC_ALLTRANSFERRED, str2, SIZEOF(str2)); - if (_tcscmp(str, str2)) SetDlgItemText(hwndDlg, IDC_ALLTRANSFERRED, str); - break; + if (_tcscmp(str, str2)) + SetDlgItemText(hwndDlg, IDC_ALLTRANSFERRED, str); } + break; - case ACKRESULT_SUCCESS: - case ACKRESULT_FAILED: - case ACKRESULT_DENIED: - { - - HideProgressControls(hwndDlg); - KillTimer(hwndDlg, 1); - if ( !dat->send) - SetOpenFileButtonStyle(GetDlgItem(hwndDlg, IDC_OPENFILE), 1); - SetDlgItemText(hwndDlg, IDCANCEL, TranslateT("Close")); - if (dat->hNotifyEvent) - UnhookEvent(dat->hNotifyEvent); - dat->hNotifyEvent = NULL; - - if (ack->result == ACKRESULT_DENIED) - { - dat->fs = NULL; /* protocol will free structure */ - SkinPlaySound("FileDenied"); - SetFtStatus(hwndDlg, LPGENT("File transfer denied"), FTS_TEXT); - } else if (ack->result == ACKRESULT_FAILED) - { + case ACKRESULT_SUCCESS: + case ACKRESULT_FAILED: + case ACKRESULT_DENIED: + HideProgressControls(hwndDlg); + KillTimer(hwndDlg, 1); + if (!dat->send) + SetOpenFileButtonStyle(GetDlgItem(hwndDlg, IDC_OPENFILE), 1); + SetDlgItemText(hwndDlg, IDCANCEL, TranslateT("Close")); + if (dat->hNotifyEvent) + UnhookEvent(dat->hNotifyEvent); + dat->hNotifyEvent = NULL; + + if (ack->result == ACKRESULT_DENIED) { + dat->fs = NULL; /* protocol will free structure */ + SkinPlaySound("FileDenied"); + SetFtStatus(hwndDlg, LPGENT("File transfer denied"), FTS_TEXT); + } + else if (ack->result == ACKRESULT_FAILED) { + dat->fs = NULL; /* protocol will free structure */ + SkinPlaySound("FileFailed"); + SetFtStatus(hwndDlg, LPGENT("File transfer failed"), FTS_TEXT); + } + else { + SkinPlaySound("FileDone"); + if (dat->send) { dat->fs = NULL; /* protocol will free structure */ - SkinPlaySound("FileFailed"); - SetFtStatus(hwndDlg, LPGENT("File transfer failed"), FTS_TEXT); - } else { - SkinPlaySound("FileDone"); - if (dat->send) - { - dat->fs = NULL; /* protocol will free structure */ - SetFtStatus(hwndDlg, LPGENT("Transfer completed."), FTS_TEXT); - - DBEVENTINFO dbei = {0}; - FillSendData(dat, dbei); - db_event_add(dat->hContact, &dbei); - if (dbei.pBlob) - mir_free(dbei.pBlob); - dat->files = NULL; //protocol library frees this - - } else { - SetFtStatus(hwndDlg, - (dat->transferStatus.totalFiles == 1) ? - LPGENT("Transfer completed, open file.") : - LPGENT("Transfer completed, open folder."), - FTS_OPEN); - - int useScanner = db_get_b(NULL, "SRFile", "UseScanner", VIRUSSCAN_DISABLE); - if (useScanner != VIRUSSCAN_DISABLE) { - struct virusscanthreadstartinfo *vstsi; - vstsi = (struct virusscanthreadstartinfo*)mir_alloc(sizeof(struct virusscanthreadstartinfo)); - vstsi->hwndReply = hwndDlg; - if (useScanner == VIRUSSCAN_DURINGDL) { - vstsi->returnCode = dat->transferStatus.currentFileNumber; - if (GetFileAttributes(dat->files[dat->transferStatus.currentFileNumber])&FILE_ATTRIBUTE_DIRECTORY) { - PostMessage(hwndDlg, M_VIRUSSCANDONE, vstsi->returnCode, 0); - mir_free(vstsi); - vstsi = NULL; - } - else vstsi->szFile = mir_tstrdup(dat->files[dat->transferStatus.currentFileNumber]); - } - else { - vstsi->szFile = mir_tstrdup(dat->transferStatus.tszWorkingDir); - vstsi->returnCode = -1; + SetFtStatus(hwndDlg, LPGENT("Transfer completed."), FTS_TEXT); + + DBEVENTINFO dbei = { 0 }; + FillSendData(dat, dbei); + db_event_add(dat->hContact, &dbei); + if (dbei.pBlob) + mir_free(dbei.pBlob); + dat->files = NULL; //protocol library frees this + } + else { + SetFtStatus(hwndDlg, + (dat->transferStatus.totalFiles == 1) ? + LPGENT("Transfer completed, open file.") : + LPGENT("Transfer completed, open folder."), + FTS_OPEN); + + int useScanner = db_get_b(NULL, "SRFile", "UseScanner", VIRUSSCAN_DISABLE); + if (useScanner != VIRUSSCAN_DISABLE) { + struct virusscanthreadstartinfo *vstsi; + vstsi = (struct virusscanthreadstartinfo*)mir_alloc(sizeof(struct virusscanthreadstartinfo)); + vstsi->hwndReply = hwndDlg; + if (useScanner == VIRUSSCAN_DURINGDL) { + vstsi->returnCode = dat->transferStatus.currentFileNumber; + if (GetFileAttributes(dat->files[dat->transferStatus.currentFileNumber])&FILE_ATTRIBUTE_DIRECTORY) { + PostMessage(hwndDlg, M_VIRUSSCANDONE, vstsi->returnCode, 0); + mir_free(vstsi); + vstsi = NULL; } - SetFtStatus(hwndDlg, LPGENT("Scanning for viruses..."), FTS_TEXT); - if (vstsi) - forkthread((void (*)(void*))RunVirusScannerThread, 0, vstsi); + else vstsi->szFile = mir_tstrdup(dat->files[dat->transferStatus.currentFileNumber]); } - else dat->fs = NULL; /* protocol will free structure */ + else { + vstsi->szFile = mir_tstrdup(dat->transferStatus.tszWorkingDir); + vstsi->returnCode = -1; + } + SetFtStatus(hwndDlg, LPGENT("Scanning for viruses..."), FTS_TEXT); + if (vstsi) + forkthread((void(*)(void*))RunVirusScannerThread, 0, vstsi); + } + else dat->fs = NULL; /* protocol will free structure */ - dat->transferStatus.currentFileNumber = dat->transferStatus.totalFiles; - } // else dat->send + dat->transferStatus.currentFileNumber = dat->transferStatus.totalFiles; + } // else dat->send - } // else ack->result + } // else ack->result - PostMessage(GetParent(hwndDlg), WM_FT_COMPLETED, ack->result, (LPARAM)hwndDlg); - break; - } - break; - } // switch ack->result - } break; // case HM_RECVEVENT - case M_VIRUSSCANDONE: - { int done = 1, i; + PostMessage(GetParent(hwndDlg), WM_FT_COMPLETED, ack->result, (LPARAM)hwndDlg); + break; + } // switch ack->result + } // case HM_RECVEVENT + break; + + case M_VIRUSSCANDONE: + { + int done = 1; if ((int)wParam == -1) { - for (i=0;itransferStatus.totalFiles;i++) dat->fileVirusScanned[i] = 1; + for (int i = 0; i < dat->transferStatus.totalFiles; i++) + dat->fileVirusScanned[i] = 1; } else { dat->fileVirusScanned[wParam] = 1; - for (i=0;itransferStatus.totalFiles;i++) if ( !dat->fileVirusScanned[i]) {done = 0; break;} + for (int i = 0; i < dat->transferStatus.totalFiles; i++) + if (!dat->fileVirusScanned[i]) { + done = 0; + break; + } } - if (done) - { + if (done) { dat->fs = NULL; /* protocol will free structure */ SetFtStatus(hwndDlg, LPGENT("Transfer and virus scan complete"), FTS_TEXT); } - break; } - case WM_SIZE: + break; + + case WM_SIZE: { - UTILRESIZEDIALOG urd = {0}; + UTILRESIZEDIALOG urd = { 0 }; urd.cbSize = sizeof(urd); urd.hwndDlg = hwndDlg; urd.hInstance = hInst; urd.lpTemplate = MAKEINTRESOURCEA(IDD_FILETRANSFERINFO); urd.pfnResizer = FileTransferDlgResizer; CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); - - RedrawWindow(GetDlgItem(hwndDlg, IDC_ALLTRANSFERRED), NULL, NULL, RDW_INVALIDATE|RDW_NOERASE); - RedrawWindow(GetDlgItem(hwndDlg, IDC_ALLSPEED), NULL, NULL, RDW_INVALIDATE|RDW_NOERASE); - RedrawWindow(GetDlgItem(hwndDlg, IDC_CONTACTNAME), NULL, NULL, RDW_INVALIDATE|RDW_NOERASE); - RedrawWindow(GetDlgItem(hwndDlg, IDC_STATUS), NULL, NULL, RDW_INVALIDATE|RDW_NOERASE); - break; } - case WM_DESTROY: - KillTimer(hwndDlg, 1); + RedrawWindow(GetDlgItem(hwndDlg, IDC_ALLTRANSFERRED), NULL, NULL, RDW_INVALIDATE | RDW_NOERASE); + RedrawWindow(GetDlgItem(hwndDlg, IDC_ALLSPEED), NULL, NULL, RDW_INVALIDATE | RDW_NOERASE); + RedrawWindow(GetDlgItem(hwndDlg, IDC_CONTACTNAME), NULL, NULL, RDW_INVALIDATE | RDW_NOERASE); + RedrawWindow(GetDlgItem(hwndDlg, IDC_STATUS), NULL, NULL, RDW_INVALIDATE | RDW_NOERASE); + break; - HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_CONTACTNAME, WM_GETFONT, 0, 0); - DeleteObject(hFont); + case WM_DESTROY: + KillTimer(hwndDlg, 1); - Button_FreeIcon_IcoLib(hwndDlg, IDC_CONTACT); - Button_FreeIcon_IcoLib(hwndDlg, IDC_OPENFILE); - Button_FreeIcon_IcoLib(hwndDlg, IDCANCEL); + HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_CONTACTNAME, WM_GETFONT, 0, 0); + DeleteObject(hFont); - FreeFileDlgData(dat); - break; + Button_FreeIcon_IcoLib(hwndDlg, IDC_CONTACT); + Button_FreeIcon_IcoLib(hwndDlg, IDC_OPENFILE); + Button_FreeIcon_IcoLib(hwndDlg, IDCANCEL); + + FreeFileDlgData(dat); + break; } return FALSE; } diff --git a/src/core/stdfile/ftmanager.cpp b/src/core/stdfile/ftmanager.cpp index 835cf80922..abd07d2b91 100644 --- a/src/core/stdfile/ftmanager.cpp +++ b/src/core/stdfile/ftmanager.cpp @@ -76,8 +76,7 @@ static void LayoutTransfers(HWND hwnd, struct TFtPageData *dat) if (dat->wnds->realCount) { HDWP hdwp = BeginDeferWindowPos(dat->wnds->realCount); top -= dat->scrollPos; - for (int i=0; i < dat->wnds->realCount; ++i) - { + for (int i = 0; i < dat->wnds->realCount; ++i) { int height = dat->wnds->items[i]->rc.bottom - dat->wnds->items[i]->rc.top; hdwp = DeferWindowPos(hdwp, dat->wnds->items[i]->hwnd, NULL, 0, top, rc.right, height, SWP_NOZORDER); top += height; @@ -88,9 +87,9 @@ static void LayoutTransfers(HWND hwnd, struct TFtPageData *dat) dat->dataHeight = top; - SCROLLINFO si = {0}; + SCROLLINFO si = { 0 }; si.cbSize = sizeof(si); - si.fMask = SIF_DISABLENOSCROLL|SIF_PAGE|SIF_RANGE; + si.fMask = SIF_DISABLENOSCROLL | SIF_PAGE | SIF_RANGE; si.nPage = dat->height; si.nMin = 0; si.nMax = dat->dataHeight; -- cgit v1.2.3