diff options
author | George Hazan <ghazan@miranda.im> | 2022-02-08 14:36:23 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-02-08 14:36:36 +0300 |
commit | dd0c36ddb76469825c06f51a647dea64a85f7af5 (patch) | |
tree | 0f27847ad59acbfd6de098a14b63b3fa2e12433f /src/core/stdfile | |
parent | 1aa297e6db8159dc500848eb4b5b087ca5b16785 (diff) |
code cleaning
Diffstat (limited to 'src/core/stdfile')
-rw-r--r-- | src/core/stdfile/src/file.cpp | 2 | ||||
-rw-r--r-- | src/core/stdfile/src/file.h | 11 | ||||
-rw-r--r-- | src/core/stdfile/src/fileexistsdlg.cpp | 2 | ||||
-rw-r--r-- | src/core/stdfile/src/filerecvdlg.cpp | 6 | ||||
-rw-r--r-- | src/core/stdfile/src/filesenddlg.cpp | 28 | ||||
-rw-r--r-- | src/core/stdfile/src/filexferdlg.cpp | 101 | ||||
-rw-r--r-- | src/core/stdfile/src/ftmanager.cpp | 10 | ||||
-rw-r--r-- | src/core/stdfile/src/main.cpp | 5 |
8 files changed, 84 insertions, 81 deletions
diff --git a/src/core/stdfile/src/file.cpp b/src/core/stdfile/src/file.cpp index 5e6f82fd6d..e257013663 100644 --- a/src/core/stdfile/src/file.cpp +++ b/src/core/stdfile/src/file.cpp @@ -44,7 +44,7 @@ wchar_t* GetContactID(MCONTACT hContact) static INT_PTR SendFileCommand(WPARAM hContact, LPARAM)
{
- struct FileSendData fsd;
+ FileSendData fsd;
fsd.hContact = hContact;
fsd.ppFiles = nullptr;
return (INT_PTR)CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_FILESEND), NULL, DlgProcSendFile, (LPARAM)&fsd);
diff --git a/src/core/stdfile/src/file.h b/src/core/stdfile/src/file.h index a1f81b218d..b89671ab8a 100644 --- a/src/core/stdfile/src/file.h +++ b/src/core/stdfile/src/file.h @@ -46,13 +46,17 @@ struct FileSendData };
#define BYTESRECVEDHISTORYCOUNT 10 //the number of bytes recved is sampled once a second and the last 10 are used to get the transfer speed
-struct FileDlgData
+
+struct FileDlgData : public MZeroedObject
{
+ ~FileDlgData();
+
HWND hwndTransfer;
HANDLE fs;
MCONTACT hContact;
MEVENT hDbEvent;
HANDLE hNotifyEvent;
+ HICON hIcon, hIconFolder;
wchar_t **files;
int send;
int closeIfFileChooseCancelled;
@@ -67,7 +71,6 @@ struct FileDlgData wchar_t szSavePath[MAX_PATH];
wchar_t szMsg[450], szFilenames[1024];
- HICON hIcon, hIconFolder;
};
//file.c
@@ -115,9 +118,7 @@ int FileOptInitialise(WPARAM wParam, LPARAM lParam); HWND FtMgr_Show(bool bForceActivate, bool bFromMenu);
void FtMgr_Destroy();
-HWND FtMgr_AddTransfer(FileDlgData *dat);
-
-void FreeFileDlgData(FileDlgData* dat);
+void FtMgr_AddTransfer(FileDlgData *dat);
wchar_t *GetContactID(MCONTACT hContact);
diff --git a/src/core/stdfile/src/fileexistsdlg.cpp b/src/core/stdfile/src/fileexistsdlg.cpp index ec6028e468..bd715cfa24 100644 --- a/src/core/stdfile/src/fileexistsdlg.cpp +++ b/src/core/stdfile/src/fileexistsdlg.cpp @@ -204,7 +204,7 @@ INT_PTR CALLBACK DlgProcFileExists(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM {
wchar_t szSize[64];
struct _stati64 statbuf;
- struct TDlgProcFileExistsParam *dat = (struct TDlgProcFileExistsParam *)lParam;
+ auto *dat = (TDlgProcFileExistsParam *)lParam;
SetPropA(hwndDlg, "Miranda.Preshutdown", HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwndDlg, M_PRESHUTDOWN));
SetPropA(hwndDlg, "Miranda.ParentWnd", dat->hwndParent);
diff --git a/src/core/stdfile/src/filerecvdlg.cpp b/src/core/stdfile/src/filerecvdlg.cpp index e367cabf7d..651ae2746a 100644 --- a/src/core/stdfile/src/filerecvdlg.cpp +++ b/src/core/stdfile/src/filerecvdlg.cpp @@ -187,7 +187,7 @@ INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l wchar_t szPath[450];
CLISTEVENT* cle = (CLISTEVENT*)lParam;
- dat = (FileDlgData*)mir_calloc(sizeof(FileDlgData));
+ dat = new FileDlgData();
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
dat->hContact = cle->hContact;
dat->hDbEvent = cle->hDbEvent;
@@ -326,7 +326,7 @@ INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l GetDlgItemText(hwndDlg, IDC_FILEDIR, dat->szSavePath, _countof(dat->szSavePath));
GetDlgItemText(hwndDlg, IDC_FILE, dat->szFilenames, _countof(dat->szFilenames));
GetDlgItemText(hwndDlg, IDC_MSG, dat->szMsg, _countof(dat->szMsg));
- dat->hwndTransfer = FtMgr_AddTransfer(dat);
+ FtMgr_AddTransfer(dat);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
//check for auto-minimize here to fix BUG#647620
if (g_plugin.bAutoAccept && g_plugin.bAutoMin) {
@@ -397,7 +397,7 @@ INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY);
Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU);
- FreeFileDlgData(dat);
+ delete dat;
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
break;
}
diff --git a/src/core/stdfile/src/filesenddlg.cpp b/src/core/stdfile/src/filesenddlg.cpp index abacb8768a..30f6fa84b8 100644 --- a/src/core/stdfile/src/filesenddlg.cpp +++ b/src/core/stdfile/src/filesenddlg.cpp @@ -67,7 +67,7 @@ static void SetFileListAndSizeControls(HWND hwndDlg, FileDlgData *dat) EnableWindow(GetDlgItem(hwndDlg, IDOK), fileCount || dirCount);
}
-static void FilenameToFileList(HWND hwndDlg, FileDlgData* dat, const wchar_t *buf)
+static void FilenameToFileList(HWND hwndDlg, FileDlgData *dat, const wchar_t *buf)
{
// Make sure that the file matrix is empty (the user may select files several times)
FreeFilesMatrix(&dat->files);
@@ -109,7 +109,7 @@ static void FilenameToFileList(HWND hwndDlg, FileDlgData* dat, const wchar_t *bu dat->files[nTemp] = (wchar_t*)mir_alloc(sizeof(wchar_t)*(fileOffset + cbFileNameLen + 1));
// Add path to filename and copy into array
- memcpy(dat->files[nTemp], buf, (fileOffset - 1)*sizeof(wchar_t));
+ memcpy(dat->files[nTemp], buf, (fileOffset - 1) * sizeof(wchar_t));
dat->files[nTemp][fileOffset - 1] = '\\';
mir_wstrcpy(dat->files[nTemp] + fileOffset - (buf[fileOffset - 2] == '\\' ? 1 : 0), pBuf);
@@ -134,12 +134,12 @@ static void FilenameToFileList(HWND hwndDlg, FileDlgData* dat, const wchar_t *bu }
#define M_FILECHOOSEDONE (WM_USER+100)
-void __cdecl ChooseFilesThread(void* param)
+void __cdecl ChooseFilesThread(void *param)
{
HWND hwndDlg = (HWND)param;
- FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ FileDlgData *dat = (FileDlgData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- wchar_t *buf = (wchar_t*)mir_alloc(sizeof(wchar_t) * 32767);
+ wchar_t *buf = (wchar_t *)mir_alloc(sizeof(wchar_t) * 32767);
if (buf == nullptr) {
PostMessage(hwndDlg, M_FILECHOOSEDONE, 0, NULL);
return;
@@ -160,7 +160,7 @@ void __cdecl ChooseFilesThread(void* param) ofn.lpstrFile = buf; *buf = 0;
ofn.nMaxFile = 32767;
ofn.Flags = OFN_NOCHANGEDIR | OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_DONTADDTORECENT;
-
+
char *szProto = Proto_GetBaseAccountName(dat->hContact);
if (!(CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_SINGLEFILEONLY))
ofn.Flags |= OFN_ALLOWMULTISELECT;
@@ -200,14 +200,14 @@ static LRESULT CALLBACK SendEditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ FileDlgData *dat = (FileDlgData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
{
- struct FileSendData *fsd = (struct FileSendData*)lParam;
+ FileSendData *fsd = (FileSendData *)lParam;
- dat = (FileDlgData*)mir_calloc(sizeof(FileDlgData));
+ dat = new FileDlgData();
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
dat->hContact = fsd->hContact;
dat->send = 1;
@@ -228,7 +228,7 @@ INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l if (fsd->ppFiles != nullptr && fsd->ppFiles[0] != nullptr) {
int totalCount, i;
for (totalCount = 0; fsd->ppFiles[totalCount]; totalCount++);
- dat->files = (wchar_t**)mir_alloc(sizeof(wchar_t*)*(totalCount + 1)); // Leaks
+ dat->files = (wchar_t **)mir_alloc(sizeof(wchar_t *) * (totalCount + 1)); // Leaks
for (i = 0; i < totalCount; i++)
dat->files[i] = mir_wstrdup(fsd->ppFiles[i]);
dat->files[totalCount] = nullptr;
@@ -270,8 +270,8 @@ INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l case M_FILECHOOSEDONE:
if (lParam != 0) {
- FilenameToFileList(hwndDlg, dat, (wchar_t*)lParam);
- mir_free((wchar_t*)lParam);
+ FilenameToFileList(hwndDlg, dat, (wchar_t *)lParam);
+ mir_free((wchar_t *)lParam);
dat->closeIfFileChooseCancelled = 0;
}
else if (dat->closeIfFileChooseCancelled)
@@ -300,7 +300,7 @@ INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l GetDlgItemText(hwndDlg, IDC_FILEDIR, dat->szSavePath, _countof(dat->szSavePath));
GetDlgItemText(hwndDlg, IDC_FILE, dat->szFilenames, _countof(dat->szFilenames));
GetDlgItemText(hwndDlg, IDC_MSG, dat->szMsg, _countof(dat->szMsg));
- dat->hwndTransfer = FtMgr_AddTransfer(dat);
+ FtMgr_AddTransfer(dat);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
DestroyWindow(hwndDlg);
return TRUE;
@@ -336,7 +336,7 @@ INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY);
Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU);
- FreeFileDlgData(dat);
+ delete dat;
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
return TRUE;
}
diff --git a/src/core/stdfile/src/filexferdlg.cpp b/src/core/stdfile/src/filexferdlg.cpp index 7b4d230632..81f849acbb 100644 --- a/src/core/stdfile/src/filexferdlg.cpp +++ b/src/core/stdfile/src/filexferdlg.cpp @@ -32,17 +32,22 @@ static int CheckVirusScanned(HWND hwnd, FileDlgData *dat, int i) if (dat->fileVirusScanned == nullptr) return 0; if (dat->fileVirusScanned[i]) return 1; if (g_plugin.getByte("WarnBeforeOpening", 1) == 0) return 1; - return IDYES == MessageBox(hwnd, TranslateT("This file has not yet been scanned for viruses. Are you certain you want to open it?"), TranslateT("File received"), MB_YESNO|MB_DEFBUTTON2); + + return IDYES == MessageBox(hwnd, + TranslateT("This file has not yet been scanned for viruses. Are you certain you want to open it?"), + TranslateT("File received"), + MB_YESNO | MB_DEFBUTTON2); } #define M_VIRUSSCANDONE (WM_USER+100) -struct virusscanthreadstartinfo { +struct virusscanthreadstartinfo +{ wchar_t *szFile; int returnCode; HWND hwndReply; }; -wchar_t* PFTS_StringToTchar(int flags, const wchar_t* s) +wchar_t* PFTS_StringToTchar(int flags, const wchar_t *s) { if (flags & PFTS_UTF) return mir_utf8decodeW((char*)s); @@ -73,7 +78,7 @@ static void SetOpenFileButtonStyle(HWND hwndButton, int enabled) EnableWindow(hwndButton, enabled); } -void FillSendData(FileDlgData *dat, DBEVENTINFO& dbei) +void FillSendData(FileDlgData *dat, DBEVENTINFO &dbei) { dbei.szModule = Proto_GetBaseAccountName(dat->hContact); dbei.eventType = EVENTTYPE_FILE; @@ -91,7 +96,7 @@ void FillSendData(FileDlgData *dat, DBEVENTINFO& dbei) mir_free(szFileNames), mir_free(szMsg); } -static void __cdecl RunVirusScannerThread(struct virusscanthreadstartinfo *info) +static void __cdecl RunVirusScannerThread(virusscanthreadstartinfo *info) { DBVARIANT dbv; if (!g_plugin.getWString("ScanCmdLine", &dbv)) { @@ -105,7 +110,8 @@ static void __cdecl RunVirusScannerThread(struct virusscanthreadstartinfo *info) info->szFile[mir_wstrlen(info->szFile) - 1] = '\0'; *pszReplace = 0; mir_snwprintf(szCmdLine, L"%s\"%s\"%s", dbv.pwszVal, info->szFile, pszReplace + 2); - } else + } + else wcsncpy_s(szCmdLine, dbv.pwszVal, _TRUNCATE); PROCESS_INFORMATION pi; @@ -230,12 +236,12 @@ static int FileTransferDlgResizer(HWND, LPARAM param, UTILRESIZECONTROL *urc) INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + FileDlgData *dat = (FileDlgData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); - dat = (FileDlgData*)lParam; + dat = (FileDlgData *)lParam; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); dat->hNotifyEvent = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_RECVEVENT); dat->transferStatus.currentFileNumber = -1; @@ -318,13 +324,13 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR if (dat->bytesRecvedHistory[0] == dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]) mir_wstrcpy(szTime, L"??:??:??"); else { - li.QuadPart = 10000000ll*(dat->transferStatus.currentFileSize - dat->transferStatus.currentFileProgress)*dat->bytesRecvedHistorySize / (dat->bytesRecvedHistory[0] - dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]); + li.QuadPart = 10000000ll * (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, _countof(szTime)); } if (dat->bytesRecvedHistory[0] != dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]) { - li.QuadPart = 10000000ll*(dat->transferStatus.totalBytes - dat->transferStatus.totalProgress)*dat->bytesRecvedHistorySize / (dat->bytesRecvedHistory[0] - dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]); + li.QuadPart = 10000000ll * (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, _countof(szTime)); @@ -463,8 +469,8 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR case M_FILEEXISTSDLGREPLY: EnableWindow(hwndDlg, TRUE); { - PROTOFILERESUME *pfr = (PROTOFILERESUME*)lParam; - wchar_t *szOriginalFilename = (wchar_t*)wParam; + PROTOFILERESUME *pfr = (PROTOFILERESUME *)lParam; + wchar_t *szOriginalFilename = (wchar_t *)wParam; char *szProto = Proto_GetBaseAccountName(dat->hContact); switch (pfr->action) { @@ -472,7 +478,7 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR if (dat->fs) ProtoChainSend(dat->hContact, PSS_FILECANCEL, (WPARAM)dat->fs, 0); dat->fs = nullptr; mir_free(szOriginalFilename); - if (pfr->szFilename) mir_free((char*)pfr->szFilename); + if (pfr->szFilename) mir_free((char *)pfr->szFilename); mir_free(pfr); return 0; case FILERESUME_RESUMEALL: @@ -486,11 +492,11 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR wchar_t *pszExtension, *pszFilename; if ((pszFilename = wcsrchr(szOriginalFilename, '\\')) == nullptr) pszFilename = szOriginalFilename; if ((pszExtension = wcsrchr(pszFilename + 1, '.')) == nullptr) pszExtension = pszFilename + mir_wstrlen(pszFilename); - if (pfr->szFilename) mir_free((wchar_t*)pfr->szFilename); + if (pfr->szFilename) mir_free((wchar_t *)pfr->szFilename); size_t size = (pszExtension - szOriginalFilename) + 21 + mir_wstrlen(pszExtension); - pfr->szFilename = (wchar_t*)mir_alloc(sizeof(wchar_t)*size); + pfr->szFilename = (wchar_t *)mir_alloc(sizeof(wchar_t) * size); for (int i = 1;; i++) { - mir_snwprintf((wchar_t*)pfr->szFilename, size, L"%.*s (%u)%s", pszExtension - szOriginalFilename, szOriginalFilename, i, pszExtension); + mir_snwprintf((wchar_t *)pfr->szFilename, size, L"%.*s (%u)%s", pszExtension - szOriginalFilename, szOriginalFilename, i, pszExtension); if (_waccess(pfr->szFilename, 0) != 0) break; } @@ -505,7 +511,7 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR case HM_RECVEVENT: { - ACKDATA *ack = (ACKDATA*)lParam; + ACKDATA *ack = (ACKDATA *)lParam; if (ack->hProcess != dat->fs) break; if (ack->type != ACKTYPE_FILE) break; if (ack->hContact != dat->hContact) break; @@ -528,10 +534,10 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR 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 && g_plugin.getByte("UseScanner", VIRUSSCAN_DISABLE) == VIRUSSCAN_DURINGDL) { - if (GetFileAttributes(dat->files[dat->transferStatus.currentFileNumber])&FILE_ATTRIBUTE_DIRECTORY) + if (GetFileAttributes(dat->files[dat->transferStatus.currentFileNumber]) & FILE_ATTRIBUTE_DIRECTORY) PostMessage(hwndDlg, M_VIRUSSCANDONE, dat->transferStatus.currentFileNumber, 0); else { - virusscanthreadstartinfo *vstsi = (virusscanthreadstartinfo*)mir_alloc(sizeof(virusscanthreadstartinfo)); + virusscanthreadstartinfo *vstsi = (virusscanthreadstartinfo *)mir_alloc(sizeof(virusscanthreadstartinfo)); vstsi->hwndReply = hwndDlg; vstsi->szFile = mir_wstrdup(dat->files[dat->transferStatus.currentFileNumber]); vstsi->returnCode = dat->transferStatus.currentFileNumber; @@ -541,7 +547,7 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR break; case ACKRESULT_FILERESUME: - UpdateProtoFileTransferStatus(&dat->transferStatus, (PROTOFILETRANSFERSTATUS*)ack->lParam); + UpdateProtoFileTransferStatus(&dat->transferStatus, (PROTOFILETRANSFERSTATUS *)ack->lParam); { PROTOFILETRANSFERSTATUS *fts = &dat->transferStatus; SetFilenameControls(hwndDlg, dat, fts); @@ -567,16 +573,16 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR case ACKRESULT_DATA: { - PROTOFILETRANSFERSTATUS *fts = (PROTOFILETRANSFERSTATUS*)ack->lParam; + PROTOFILETRANSFERSTATUS *fts = (PROTOFILETRANSFERSTATUS *)ack->lParam; wchar_t str[64], str2[64], szSizeDone[32], szSizeTotal[32];//, *contactName; if (dat->fileVirusScanned == nullptr) - dat->fileVirusScanned = (int*)mir_calloc(sizeof(int) * fts->totalFiles); + 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->files == nullptr) - dat->files = (wchar_t**)mir_calloc((fts->totalFiles + 1) * sizeof(wchar_t*)); + dat->files = (wchar_t **)mir_calloc((fts->totalFiles + 1) * sizeof(wchar_t *)); if (fts->currentFileNumber < fts->totalFiles && dat->files[fts->currentFileNumber] == nullptr) dat->files[fts->currentFileNumber] = PFTS_StringToTchar(fts->flags, fts->szCurrentFile.w); } @@ -660,12 +666,11 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR int useScanner = g_plugin.getByte("UseScanner", VIRUSSCAN_DISABLE); if (useScanner != VIRUSSCAN_DISABLE) { - struct virusscanthreadstartinfo *vstsi; - vstsi = (struct virusscanthreadstartinfo*)mir_alloc(sizeof(struct virusscanthreadstartinfo)); + auto *vstsi = (virusscanthreadstartinfo *)mir_alloc(sizeof(virusscanthreadstartinfo)); vstsi->hwndReply = hwndDlg; if (useScanner == VIRUSSCAN_DURINGDL) { vstsi->returnCode = dat->transferStatus.currentFileNumber; - if (GetFileAttributes(dat->files[dat->transferStatus.currentFileNumber])&FILE_ATTRIBUTE_DIRECTORY) { + if (GetFileAttributes(dat->files[dat->transferStatus.currentFileNumber]) & FILE_ATTRIBUTE_DIRECTORY) { PostMessage(hwndDlg, M_VIRUSSCANDONE, vstsi->returnCode, 0); mir_free(vstsi); vstsi = nullptr; @@ -683,14 +688,14 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR else dat->fs = nullptr; /* protocol will free structure */ dat->transferStatus.currentFileNumber = dat->transferStatus.totalFiles; - } + } } PostMessage(GetParent(hwndDlg), WM_FT_COMPLETED, ack->result, (LPARAM)hwndDlg); break; } } - break; + break; case M_VIRUSSCANDONE: { @@ -701,7 +706,7 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR } else { dat->fileVirusScanned[wParam] = 1; - for (int i = 0; i < dat->transferStatus.totalFiles; i++) + for (int i = 0; i < dat->transferStatus.totalFiles; i++) if (!dat->fileVirusScanned[i]) { done = 0; break; @@ -733,32 +738,28 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR Button_FreeIcon_IcoLib(hwndDlg, IDC_OPENFILE); Button_FreeIcon_IcoLib(hwndDlg, IDCANCEL); - FreeFileDlgData(dat); + delete dat; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); break; } return FALSE; } -void FreeFileDlgData(FileDlgData* dat) +FileDlgData::~FileDlgData() { - if (dat == nullptr) - return; - - if (dat->fs) - ProtoChainSend(dat->hContact, PSS_FILECANCEL, (WPARAM)dat->fs, 0); - if (dat->hPreshutdownEvent) - UnhookEvent(dat->hPreshutdownEvent); - if (dat->hNotifyEvent) - UnhookEvent(dat->hNotifyEvent); - - FreeProtoFileTransferStatus(&dat->transferStatus); - FreeFilesMatrix(&dat->files); - - mir_free(dat->fileVirusScanned); - if (dat->hIcon) - DestroyIcon(dat->hIcon); - if (dat->hIconFolder) - DestroyIcon(dat->hIconFolder); - mir_free(dat); + if (fs) + ProtoChainSend(hContact, PSS_FILECANCEL, (WPARAM)fs, 0); + if (hPreshutdownEvent) + UnhookEvent(hPreshutdownEvent); + if (hNotifyEvent) + UnhookEvent(hNotifyEvent); + + FreeProtoFileTransferStatus(&transferStatus); + FreeFilesMatrix(&files); + + mir_free(fileVirusScanned); + if (hIcon) + DestroyIcon(hIcon); + if (hIconFolder) + DestroyIcon(hIconFolder); } diff --git a/src/core/stdfile/src/ftmanager.cpp b/src/core/stdfile/src/ftmanager.cpp index fa3f5b921d..20206908be 100644 --- a/src/core/stdfile/src/ftmanager.cpp +++ b/src/core/stdfile/src/ftmanager.cpp @@ -257,7 +257,7 @@ static INT_PTR CALLBACK FtMgrPageDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPA static INT_PTR CALLBACK FtMgrDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- struct TFtMgrData *dat = (struct TFtMgrData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ auto *dat = (TFtMgrData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
HWND hwndTab = GetDlgItem(hwnd, IDC_TABS);
switch (msg) {
@@ -266,7 +266,7 @@ static INT_PTR CALLBACK FtMgrDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM TranslateDialogDefault(hwnd);
Window_SetSkinIcon_IcoLib(hwnd, SKINICON_EVENT_FILE);
- dat = (struct TFtMgrData *)mir_calloc(sizeof(struct TFtMgrData));
+ dat = (TFtMgrData *)mir_calloc(sizeof(struct TFtMgrData));
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)dat);
@@ -498,17 +498,17 @@ void FtMgr_ShowPage(int page) SendMessage(hwndFtMgr, WM_FT_SELECTPAGE, page, 0);
}
-HWND FtMgr_AddTransfer(FileDlgData *fdd)
+void FtMgr_AddTransfer(FileDlgData *fdd)
{
bool bForceActivate = fdd->send || !g_plugin.bAutoAccept;
TFtMgrData *dat = (TFtMgrData *)GetWindowLongPtr(FtMgr_Show(bForceActivate, false), GWLP_USERDATA);
if (dat == nullptr)
- return nullptr;
+ return;
HWND hwndBox = fdd->send ? dat->hwndOutgoing : dat->hwndIncoming;
HWND hwndFt = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_FILETRANSFERINFO), hwndBox, DlgProcFileTransfer, (LPARAM)fdd);
ShowWindow(hwndFt, SW_SHOWNA);
SendMessage(hwndBox, WM_FT_ADD, 0, (LPARAM)hwndFt);
FtMgr_ShowPage(fdd->send ? 1 : 0);
- return hwndFt;
+ fdd->hwndTransfer = hwndFt;
}
diff --git a/src/core/stdfile/src/main.cpp b/src/core/stdfile/src/main.cpp index 57e0a6f332..275c58cf44 100644 --- a/src/core/stdfile/src/main.cpp +++ b/src/core/stdfile/src/main.cpp @@ -60,8 +60,9 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_SRFILE int CMPlugin::Load()
{
- if ( IsWinVer7Plus())
- CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_ALL, IID_ITaskbarList3, (void**)&pTaskbarInterface);
+ if (IsWinVer7Plus())
+ if (FAILED(CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_ALL, IID_ITaskbarList3, (void**)&pTaskbarInterface)))
+ pTaskbarInterface = nullptr;
LoadSendRecvFileModule();
return 0;
|