From 650fc5a2103cedfe149500ade9c684ecf381d348 Mon Sep 17 00:00:00 2001 From: Mataes Date: Wed, 16 May 2018 21:48:52 +0300 Subject: FavContacts, FileAsMessage, Fingerprint, FloatingContacts, Folders, FTPFile: cmplugin adaptation --- plugins/FileAsMessage/src/dialog.cpp | 394 +++++++++++++++++------------------ plugins/FileAsMessage/src/dialog.h | 2 - plugins/FileAsMessage/src/main.cpp | 19 +- plugins/FileAsMessage/src/stdafx.h | 10 +- 4 files changed, 209 insertions(+), 216 deletions(-) (limited to 'plugins/FileAsMessage') diff --git a/plugins/FileAsMessage/src/dialog.cpp b/plugins/FileAsMessage/src/dialog.cpp index 4ca7a5f496..ea5b0f7aed 100644 --- a/plugins/FileAsMessage/src/dialog.cpp +++ b/plugins/FileAsMessage/src/dialog.cpp @@ -65,18 +65,18 @@ static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPA switch (message) { case WM_COMMAND: - { - PUDeletePopup(hWnd); - pcli->pfnRemoveEvent(hContact, 0); - - if (IsWindow(hDlg)) { - ShowWindow(hDlg, SW_SHOWNORMAL); - SetForegroundWindow(hDlg); - SetFocus(hDlg); - } + { + PUDeletePopup(hWnd); + pcli->pfnRemoveEvent(hContact, 0); - break; + if (IsWindow(hDlg)) { + ShowWindow(hDlg, SW_SHOWNORMAL); + SetForegroundWindow(hDlg); + SetFocus(hDlg); } + + break; + } case WM_CONTEXTMENU: PUDeletePopup(hWnd); break; @@ -98,7 +98,7 @@ void MakePopupMsg(HWND hDlg, MCONTACT hContact, wchar_t *msg) POPUPDATAW ppd = { 0 }; ppd.lchContact = hContact; - ppd.lchIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_SMALLICON)); + ppd.lchIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_SMALLICON)); mir_wstrcpy(ppd.lpwzContactName, Clist_GetContactDisplayName(hContact)); mir_wstrcpy(ppd.lpwzText, msg); ppd.colorBack = GetSysColor(COLOR_INFOBK); @@ -117,7 +117,7 @@ int getMsgId(char *msg) for (int indx = 0; indx < CMD_COUNT; indx++) if (*msg == cCmdList[indx]) return indx; - + return -1; }; @@ -248,7 +248,7 @@ int FILEECHO::createTransfer() } if (hFile == INVALID_HANDLE_VALUE) goto createTransfer_FAILED; - + if (!inSend) { SetFilePointer(hFile, fileSize, nullptr, FILE_BEGIN); SetEndOfFile(hFile); @@ -259,7 +259,7 @@ int FILEECHO::createTransfer() LastError = GetLastError(); if (hMapping == nullptr) goto createTransfer_FAILED; - + lpData = (uchar*)MapViewOfFile(hMapping, inSend ? FILE_MAP_READ : FILE_MAP_WRITE, 0, 0, 0); LastError = GetLastError(); if (lpData == nullptr) @@ -270,7 +270,7 @@ int FILEECHO::createTransfer() if (asBinary) { uint freq_table[256] = { 0 }; codeSymb = 1; - + // searching for symbol with lowest frequency: "codeSymb" BuildFreqTable(lpData, fileSize, freq_table); for (uint i = codeSymb + 1; i < 256; ++i) { @@ -416,7 +416,7 @@ void FILEECHO::incomeRequest(char *param) if (!IsWindowVisible(hDlg) && !AutoMin) { CLISTEVENT cle = {}; cle.hContact = hContact; - cle.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_SMALLICON)); + cle.hIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_SMALLICON)); cle.flags = CLEF_URGENT; cle.hDbEvent = 0; cle.pszService = SERVICE_NAME "/FERecvFile"; @@ -703,16 +703,16 @@ void FILEECHO::perform(char *str) cmdACCEPT(); break; case CMD_CANCEL: - { - if (iState & (STATE_PRERECV | STATE_REQSENT | STATE_OPERATE | STATE_ACKREQ | STATE_PAUSED)) { - wchar_t *msg = TranslateT("Canceled by remote user"); - SetDlgItemText(hDlg, IDC_STATUS, msg); - MakePopupMsg(hDlg, hContact, msg); - destroyTransfer(); - setState(STATE_CANCELLED); - } - break; + { + if (iState & (STATE_PRERECV | STATE_REQSENT | STATE_OPERATE | STATE_ACKREQ | STATE_PAUSED)) { + wchar_t *msg = TranslateT("Canceled by remote user"); + SetDlgItemText(hDlg, IDC_STATUS, msg); + MakePopupMsg(hDlg, hContact, msg); + destroyTransfer(); + setState(STATE_CANCELLED); } + break; + } case CMD_DACK: cmdDACK(str + 1); break; @@ -720,17 +720,17 @@ void FILEECHO::perform(char *str) else switch (msgId) { case CMD_CANCEL: - { - if (iState & (STATE_PRERECV | STATE_REQSENT | STATE_OPERATE | STATE_ACKREQ | STATE_PAUSED)) { - wchar_t *msg = TranslateT("Canceled by remote user"); - SetDlgItemText(hDlg, IDC_STATUS, msg); - MakePopupMsg(hDlg, hContact, msg); - destroyTransfer(); - setState(STATE_CANCELLED); - } - break; + { + if (iState & (STATE_PRERECV | STATE_REQSENT | STATE_OPERATE | STATE_ACKREQ | STATE_PAUSED)) { + wchar_t *msg = TranslateT("Canceled by remote user"); + SetDlgItemText(hDlg, IDC_STATUS, msg); + MakePopupMsg(hDlg, hContact, msg); + destroyTransfer(); + setState(STATE_CANCELLED); } - + break; + } + case CMD_REQ: if (chunkCount) { if (MessageBox(hDlg, TranslateT("New incoming file request. Do you want to proceed?"), @@ -742,11 +742,11 @@ void FILEECHO::perform(char *str) SetDlgItemText(hDlg, IDC_STATUS, L""); incomeRequest(str + 1); break; - + case CMD_DATA: cmdDATA(str + 1); break; - + case CMD_END: cmdEND(); break; @@ -777,80 +777,80 @@ LRESULT CALLBACK ProgressWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa switch (uMsg) { case WM_NCPAINT: return 0; - + case WM_PAINT: - { - HDC hdc; - PAINTSTRUCT ps; - RECT rc; - HRGN hrgn; - HBRUSH frameBrush = (HBRUSH)GetStockObject(BLACK_BRUSH); - FILEECHO *dat = (FILEECHO*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); - - GetClientRect(hwnd, &rc); - if (dat == nullptr || dat->chunkCount == 0) { - COLORREF colour; - HBRUSH hbr; - - if (dat == nullptr || dat->iState != STATE_FINISHED) { - hbr = (HBRUSH)(COLOR_3DFACE + 1); - } - else { - colour = dat->rgbRecv; - hbr = CreateSolidBrush(colour); - } - hdc = BeginPaint(hwnd, &ps); - FillRect(hdc, &rc, hbr); - FrameRect(hdc, &rc, frameBrush); - if (hbr != (HBRUSH)(COLOR_3DFACE + 1)) - DeleteObject(hbr); - EndPaint(hwnd, &ps); - return 0; + { + HDC hdc; + PAINTSTRUCT ps; + RECT rc; + HRGN hrgn; + HBRUSH frameBrush = (HBRUSH)GetStockObject(BLACK_BRUSH); + FILEECHO *dat = (FILEECHO*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); + + GetClientRect(hwnd, &rc); + if (dat == nullptr || dat->chunkCount == 0) { + COLORREF colour; + HBRUSH hbr; + + if (dat == nullptr || dat->iState != STATE_FINISHED) { + hbr = (HBRUSH)(COLOR_3DFACE + 1); } - - hrgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom); - - hdc = BeginPaint(hwnd, &ps); - SelectClipRgn(hdc, hrgn); - - RECT rc2 = rc; - float sliceWidth = (float)((float)(rc.right - rc.left) / (float)dat->chunkCount); - float dx = (float)rc2.left; - for (uint indx = 0; indx < dat->chunkCount; indx++) { - HBRUSH hbr; - COLORREF colour = 0; - if (dat->inSend && indx == dat->chunkIndx) - colour = dat->rgbToSend; - else - switch (dat->chunkAck[indx]) { - case CHUNK_UNSENT: - colour = dat->rgbUnSent; - break; - case CHUNK_SENT: - colour = dat->rgbSent; - break; - case CHUNK_ACK: - colour = dat->rgbRecv; - break; - } + else { + colour = dat->rgbRecv; hbr = CreateSolidBrush(colour); - rc2.left = (int)dx; - rc2.right = (int)(dx + sliceWidth); - FillRect(hdc, &rc2, hbr); - FrameRect(hdc, &rc2, frameBrush); - DeleteObject(hbr); - dx += sliceWidth - 1; - } - if (rc2.right < rc.right) { - rc2.left = rc2.right; - rc2.right = rc.right; - FillRect(hdc, &rc2, (HBRUSH)(COLOR_3DFACE + 1)); } + hdc = BeginPaint(hwnd, &ps); + FillRect(hdc, &rc, hbr); + FrameRect(hdc, &rc, frameBrush); + if (hbr != (HBRUSH)(COLOR_3DFACE + 1)) + DeleteObject(hbr); EndPaint(hwnd, &ps); - - DeleteObject(hrgn); return 0; } + + hrgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom); + + hdc = BeginPaint(hwnd, &ps); + SelectClipRgn(hdc, hrgn); + + RECT rc2 = rc; + float sliceWidth = (float)((float)(rc.right - rc.left) / (float)dat->chunkCount); + float dx = (float)rc2.left; + for (uint indx = 0; indx < dat->chunkCount; indx++) { + HBRUSH hbr; + COLORREF colour = 0; + if (dat->inSend && indx == dat->chunkIndx) + colour = dat->rgbToSend; + else + switch (dat->chunkAck[indx]) { + case CHUNK_UNSENT: + colour = dat->rgbUnSent; + break; + case CHUNK_SENT: + colour = dat->rgbSent; + break; + case CHUNK_ACK: + colour = dat->rgbRecv; + break; + } + hbr = CreateSolidBrush(colour); + rc2.left = (int)dx; + rc2.right = (int)(dx + sliceWidth); + FillRect(hdc, &rc2, hbr); + FrameRect(hdc, &rc2, frameBrush); + DeleteObject(hbr); + dx += sliceWidth - 1; + } + if (rc2.right < rc.right) { + rc2.left = rc2.right; + rc2.right = rc.right; + FillRect(hdc, &rc2, (HBRUSH)(COLOR_3DFACE + 1)); + } + EndPaint(hwnd, &ps); + + DeleteObject(hrgn); + return 0; + } } return mir_callNextSubclass(hwnd, ProgressWndProc, uMsg, wParam, lParam); } @@ -898,29 +898,29 @@ INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) break; case WM_FE_STATUSCHANGE: - { - char *szProto = GetContactProto(dat->hContact); - if (szProto) { - int dwStatus = db_get_w(dat->hContact, szProto, "Status", ID_STATUS_OFFLINE); - if (dat->inSend && dwStatus != dat->contactStatus) { - if (dat->contactStatus == ID_STATUS_OFFLINE) { - dat->chunkIndx = dat->chunkCount; - } - else - if (dwStatus == ID_STATUS_OFFLINE) { - if (dat->iState & (STATE_OPERATE | STATE_ACKREQ)) { - wchar_t *msg = TranslateT("File transfer is paused because of dropped connection"); - SetDlgItemText(hDlg, IDC_STATUS, msg); - MakePopupMsg(dat->hDlg, dat->hContact, msg); - dat->setState(STATE_PAUSED); - KillTimer(hDlg, TIMER_SEND); - } - } + { + char *szProto = GetContactProto(dat->hContact); + if (szProto) { + int dwStatus = db_get_w(dat->hContact, szProto, "Status", ID_STATUS_OFFLINE); + if (dat->inSend && dwStatus != dat->contactStatus) { + if (dat->contactStatus == ID_STATUS_OFFLINE) { + dat->chunkIndx = dat->chunkCount; } - dat->contactStatus = dwStatus; + else + if (dwStatus == ID_STATUS_OFFLINE) { + if (dat->iState & (STATE_OPERATE | STATE_ACKREQ)) { + wchar_t *msg = TranslateT("File transfer is paused because of dropped connection"); + SetDlgItemText(hDlg, IDC_STATUS, msg); + MakePopupMsg(dat->hDlg, dat->hContact, msg); + dat->setState(STATE_PAUSED); + KillTimer(hDlg, TIMER_SEND); + } + } } + dat->contactStatus = dwStatus; } - return TRUE; + } + return TRUE; case WM_DESTROY: WindowList_Remove(hFileList, hDlg); @@ -938,90 +938,90 @@ INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_COMMAND: switch (wParam) { case IDC_PLAY: - { - if (dat->iState & (STATE_IDLE | STATE_FINISHED | STATE_CANCELLED | STATE_PRERECV)) { - int len = GetWindowTextLength(GetDlgItem(hDlg, IDC_FILENAME)) + 1; - free(dat->filename); - dat->filename = (char*)malloc(len); - GetDlgItemTextA(hDlg, IDC_FILENAME, dat->filename, len); - if (dat->inSend) - // Send offer to remote side - { - dat->sendReq(); - } - else - // Send the accept and starting to receive - { - char buff[MAX_PATH]; - char *bufname; - - GetFullPathNameA(dat->filename, sizeof(buff), buff, &bufname); - *bufname = 0; - CreateDirectoryTree(buff); - if (!dat->createTransfer()) { - SetDlgItemText(hDlg, IDC_STATUS, TranslateT("Failed on file initialization")); - break; - } - dat->sendCmd(0, CMD_ACCEPT, ""); - dat->lastTimestamp = GetTickCount(); - SetDlgItemText(hDlg, IDC_STATUS, TranslateT("Receiving...")); - dat->setState(STATE_OPERATE); + { + if (dat->iState & (STATE_IDLE | STATE_FINISHED | STATE_CANCELLED | STATE_PRERECV)) { + int len = GetWindowTextLength(GetDlgItem(hDlg, IDC_FILENAME)) + 1; + free(dat->filename); + dat->filename = (char*)malloc(len); + GetDlgItemTextA(hDlg, IDC_FILENAME, dat->filename, len); + if (dat->inSend) + // Send offer to remote side + { + dat->sendReq(); + } + else + // Send the accept and starting to receive + { + char buff[MAX_PATH]; + char *bufname; + + GetFullPathNameA(dat->filename, sizeof(buff), buff, &bufname); + *bufname = 0; + CreateDirectoryTree(buff); + if (!dat->createTransfer()) { + SetDlgItemText(hDlg, IDC_STATUS, TranslateT("Failed on file initialization")); + break; } + dat->sendCmd(0, CMD_ACCEPT, ""); + dat->lastTimestamp = GetTickCount(); + SetDlgItemText(hDlg, IDC_STATUS, TranslateT("Receiving...")); + dat->setState(STATE_OPERATE); } - else { - if (dat->inSend) { - if (dat->iState == STATE_OPERATE) { - SetDlgItemText(hDlg, IDC_STATUS, TranslateT("Paused...")); - dat->setState(STATE_PAUSED); - KillTimer(hDlg, TIMER_SEND); - } - else { - SetDlgItemText(hDlg, IDC_STATUS, TranslateT("Sending...")); - if (dat->chunkIndx < dat->chunkCount) - dat->setState(STATE_OPERATE); - else - dat->setState(STATE_ACKREQ); - PostMessage(hDlg, WM_TIMER, 0, 0); - } + } + else { + if (dat->inSend) { + if (dat->iState == STATE_OPERATE) { + SetDlgItemText(hDlg, IDC_STATUS, TranslateT("Paused...")); + dat->setState(STATE_PAUSED); + KillTimer(hDlg, TIMER_SEND); } else { - SetDlgItemText(hDlg, IDC_STATUS, TranslateT("Synchronizing...")); - dat->setState(STATE_ACKREQ); + SetDlgItemText(hDlg, IDC_STATUS, TranslateT("Sending...")); + if (dat->chunkIndx < dat->chunkCount) + dat->setState(STATE_OPERATE); + else + dat->setState(STATE_ACKREQ); PostMessage(hDlg, WM_TIMER, 0, 0); } - break; } + else { + SetDlgItemText(hDlg, IDC_STATUS, TranslateT("Synchronizing...")); + dat->setState(STATE_ACKREQ); + PostMessage(hDlg, WM_TIMER, 0, 0); + } + break; } - break; + } + break; case IDC_BROWSE: - { - wchar_t str[MAX_PATH]; *str = 0; - GetDlgItemText(hDlg, IDC_FILENAME, str, _countof(str)); - - OPENFILENAME ofn = {}; - ofn.lStructSize = sizeof(ofn); - ofn.hwndOwner = hDlg; - ofn.lpstrFile = str; - ofn.Flags = dat->inSend ? OFN_FILEMUSTEXIST : 0; - ofn.lpstrTitle = dat->inSend ? TranslateT("Select a file") : TranslateT("Save as"); - ofn.nMaxFile = _countof(str); - ofn.nMaxFileTitle = MAX_PATH; - if (!GetOpenFileName(&ofn)) - break; - if (!dat->inSend && dat->iState == STATE_FINISHED) - break; - - SetDlgItemText(hDlg, IDC_FILENAME, str); + { + wchar_t str[MAX_PATH]; *str = 0; + GetDlgItemText(hDlg, IDC_FILENAME, str, _countof(str)); + + OPENFILENAME ofn = {}; + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = hDlg; + ofn.lpstrFile = str; + ofn.Flags = dat->inSend ? OFN_FILEMUSTEXIST : 0; + ofn.lpstrTitle = dat->inSend ? TranslateT("Select a file") : TranslateT("Save as"); + ofn.nMaxFile = _countof(str); + ofn.nMaxFileTitle = MAX_PATH; + if (!GetOpenFileName(&ofn)) + break; + if (!dat->inSend && dat->iState == STATE_FINISHED) + break; - int size = RetrieveFileSize(str); - if (size != -1) - mir_snwprintf(str, TranslateT("Size: %d bytes"), size); - else - mir_wstrncpy(str, TranslateT("Can't get a file size"), _countof(str)); - SetDlgItemText(hDlg, IDC_FILESIZE, str); - } - break; + SetDlgItemText(hDlg, IDC_FILENAME, str); + + int size = RetrieveFileSize(str); + if (size != -1) + mir_snwprintf(str, TranslateT("Size: %d bytes"), size); + else + mir_wstrncpy(str, TranslateT("Can't get a file size"), _countof(str)); + SetDlgItemText(hDlg, IDC_FILESIZE, str); + } + break; case IDC_STOP: case IDCANCEL: diff --git a/plugins/FileAsMessage/src/dialog.h b/plugins/FileAsMessage/src/dialog.h index 117ae006a3..ace7c198a3 100644 --- a/plugins/FileAsMessage/src/dialog.h +++ b/plugins/FileAsMessage/src/dialog.h @@ -1,7 +1,5 @@ #pragma once -extern HINSTANCE hInst; - int getMsgId(char *msg); INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); diff --git a/plugins/FileAsMessage/src/main.cpp b/plugins/FileAsMessage/src/main.cpp index abb3068398..3e96b927fa 100644 --- a/plugins/FileAsMessage/src/main.cpp +++ b/plugins/FileAsMessage/src/main.cpp @@ -16,7 +16,7 @@ PLUGININFOEX pluginInfo = CLIST_INTERFACE *pcli; MWindowList hFileList; -HINSTANCE hInst; +CMPlugin g_plugin; int hLangpack; char *szServiceTitle = SERVICE_TITLE; @@ -104,7 +104,7 @@ INT_PTR OnSendFile(WPARAM wParam, LPARAM) if (hwnd != nullptr) WindowList_Remove(hFileList, hwnd); FILEECHO *fe = new FILEECHO(wParam); fe->inSend = TRUE; - hwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN), nullptr, DialogProc, (LPARAM)fe); + hwnd = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_MAIN), nullptr, DialogProc, (LPARAM)fe); if (hwnd == nullptr) { delete fe; @@ -130,7 +130,7 @@ INT_PTR OnRecvMessage(WPARAM wParam, LPARAM lParam) if (hwnd != nullptr) WindowList_Remove(hFileList, hwnd); FILEECHO *fe = new FILEECHO(ccs->hContact); fe->inSend = FALSE; - hwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN), nullptr, DialogProc, (LPARAM)fe); + hwnd = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_MAIN), nullptr, DialogProc, (LPARAM)fe); if (hwnd == nullptr) { delete fe; @@ -146,7 +146,7 @@ INT_PTR OnRecvMessage(WPARAM wParam, LPARAM lParam) int OnOptInitialise(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = {}; - odp.hInstance = hInst; + odp.hInstance = g_plugin.getInst(); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS); odp.szTitle.a = SERVICE_TITLE; odp.szGroup.a = LPGEN("Events"); @@ -194,7 +194,7 @@ extern "C" __declspec(dllexport) int Load(void) InitCRC32(); - Icon_Register(hInst, "fileAsMessage", iconList, _countof(iconList)); + Icon_Register(g_plugin.getInst(), "fileAsMessage", iconList, _countof(iconList)); hFileList = WindowList_Create(); @@ -226,12 +226,3 @@ extern "C" __declspec(dllexport) int Unload(void) return 0; } - -// -// DllMain() -// -int WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID) -{ - hInst = hInstance; - return TRUE; -} diff --git a/plugins/FileAsMessage/src/stdafx.h b/plugins/FileAsMessage/src/stdafx.h index 3ac7b52e8d..519c80745d 100644 --- a/plugins/FileAsMessage/src/stdafx.h +++ b/plugins/FileAsMessage/src/stdafx.h @@ -7,8 +7,6 @@ #include #include -#define __NO_CMPLUGIN_NEEDED - #include #include #include @@ -35,6 +33,13 @@ #define NOPLUGIN_MESSAGE "If you see this \"garbage\", probably you have no \"fileAsMessage\" plugin installed, see https://miranda-ng.org/p/FileAsMessage/ for more information and download." +struct CMPlugin : public PLUGIN +{ + CMPlugin() : + PLUGIN(SERVICE_NAME) + {} +}; + extern char *szServiceTitle; extern char *szServicePrefix; extern const ulong INITCRC; @@ -43,7 +48,6 @@ extern const ulong INITCRC; #define WM_FE_STATUSCHANGE WM_USER+101 #define WM_FE_SKINCHANGE WM_USER+102 -extern HINSTANCE hInst; extern MWindowList hFileList; extern HANDLE hEventNewFile; -- cgit v1.2.3