From d07899c7630040511591755c86371a9fbd58da34 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 18 Mar 2021 12:33:23 +0300 Subject: fixes #2783 (HTTPServer: remove menu-related options) --- plugins/HTTPServer/src/FileShareNode.h | 30 ++----------------- plugins/HTTPServer/src/GuiElements.cpp | 54 ++++++++-------------------------- plugins/HTTPServer/src/HttpUser.cpp | 8 ++--- plugins/HTTPServer/src/main.cpp | 37 +++++++++++------------ plugins/HTTPServer/src/resource.h | 8 ++--- 5 files changed, 40 insertions(+), 97 deletions(-) (limited to 'plugins/HTTPServer/src') diff --git a/plugins/HTTPServer/src/FileShareNode.h b/plugins/HTTPServer/src/FileShareNode.h index 032bc34510..c47117291f 100644 --- a/plugins/HTTPServer/src/FileShareNode.h +++ b/plugins/HTTPServer/src/FileShareNode.h @@ -58,8 +58,8 @@ public://, DWORD dwAllowedIP, DWORD dwAllowedMask, int nMaxDownloads ); CLFileShareNode * pclNext; //CLHttpUser * pclAddHttpUser( HANDLE hConnection, in_addr stAddr ); //bool bRemoveHttpUser( CLHttpUser * pclUser ); - bool bAddUser(CLShareUser * pclUser); - bool bRemoveUser(CLShareUser * pclUser); + bool bAddUser(CLShareUser *pclUser); + bool bRemoveUser(CLShareUser *pclUser); bool bAnyUsers() { return pclCurrentUsers != nullptr; } @@ -72,31 +72,7 @@ private: }; -extern CLFileShareNode * pclFirstNode; +extern CLFileShareNode *pclFirstNode; extern mir_cs csFileShareListAccess; -class CLFileShareListAccess { - bool bLocked; -public: - CLFileShareListAccess() { - bLocked = false; - Lock(); - } - ~CLFileShareListAccess() { - Unlock(); - } - void Lock() { - if (bLocked) - return; - mir_cslock lck(csFileShareListAccess); - bLocked = true; - } - void Unlock() { - if (!bLocked) - return; - bLocked = false; - } - -}; - #endif \ No newline at end of file diff --git a/plugins/HTTPServer/src/GuiElements.cpp b/plugins/HTTPServer/src/GuiElements.cpp index ebb4f0587f..ab8219230f 100644 --- a/plugins/HTTPServer/src/GuiElements.cpp +++ b/plugins/HTTPServer/src/GuiElements.cpp @@ -530,7 +530,7 @@ void UpdateStatisticView(HWND hwndDlg, bool bRefressUsersOnly = false) ListView_DeleteAllItems(hShareList); ListView_DeleteAllItems(hUserList); - CLFileShareListAccess scCrit; + mir_cslock lck(csFileShareListAccess); char szTmp[50]; in_addr stAddr; @@ -681,8 +681,7 @@ static INT_PTR CALLBACK DlgProcStatsticView(HWND hwndDlg, UINT msg, WPARAM wPara switch (msg) { case WM_INITDIALOG: { - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, - (LPARAM)LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_SHARE_NEW_FILE))); + SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)g_plugin.getIcon(IDI_SHARE_NEW_FILE)); TranslateDialogDefault(hwndDlg); @@ -1073,15 +1072,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP string sDefExt = DBGetString(0, MODULENAME, "ExternalSrvName", szDefaultExternalSrvName); SetDlgItemText(hwndDlg, IDC_EXTERNAL_SRV_NAME, sDefExt.c_str()); - bool b = g_plugin.getByte("AddStatisticsMenuItem", 1) != 0; - CheckDlgButton(hwndDlg, IDC_ADD_STATISTICS_MENU_ITEM, b ? BST_CHECKED : BST_UNCHECKED); - - b = g_plugin.getByte("AddAcceptConMenuItem", 1) != 0; - CheckDlgButton(hwndDlg, IDC_ACCEPT_COM_MENU_ITEM, b ? BST_CHECKED : BST_UNCHECKED); - - b = g_plugin.getByte("WriteLogFile", 0) != 0; - CheckDlgButton(hwndDlg, IDC_WRITE_LOG_FILE, b ? BST_CHECKED : BST_UNCHECKED); - + CheckDlgButton(hwndDlg, IDC_WRITE_LOG_FILE, g_plugin.getByte("WriteLogFile", 0) != 0 ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_SHOW_POPUPS, bShowPopups ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_LIMIT_ONLY_WHEN_ONLINE, bLimitOnlyWhenOnline ? BST_CHECKED : BST_UNCHECKED); @@ -1159,8 +1150,6 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP case IDC_LIMIT_ONLY_WHEN_ONLINE: case IDC_SHOW_POPUPS: case IDC_WRITE_LOG_FILE: - case IDC_ADD_STATISTICS_MENU_ITEM: - case IDC_ACCEPT_COM_MENU_ITEM: if (HIWORD(wParam) == BN_CLICKED) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); return TRUE; @@ -1201,22 +1190,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP if (GetDlgItemText(hwndDlg, IDC_EXTERNAL_SRV_NAME, szTemp, _countof(szTemp))) g_plugin.setString("ExternalSrvName", szTemp); - bool b = g_plugin.getByte("AddStatisticsMenuItem", 1) != 0; - bool bNew = IsDlgButtonChecked(hwndDlg, IDC_ADD_STATISTICS_MENU_ITEM) == BST_CHECKED; - if (b != bNew) { - g_plugin.setByte("AddStatisticsMenuItem", bNew); - MessageBoxW(hwndDlg, TranslateT("You need to restart Miranda to change the main menu"), TranslateW(_A2W(MSG_BOX_TITLE)), MB_OK); - } - - b = g_plugin.getByte("AddAcceptConMenuItem", 1) != 0; - bNew = IsDlgButtonChecked(hwndDlg, IDC_ACCEPT_COM_MENU_ITEM) == BST_CHECKED; - if (b != bNew) { - g_plugin.setByte("AddAcceptConMenuItem", bNew); - MessageBoxW(hwndDlg, TranslateT("You need to restart Miranda to change the main menu"), TranslateW(_A2W(MSG_BOX_TITLE)), MB_OK); - } - - bNew = IsDlgButtonChecked(hwndDlg, IDC_WRITE_LOG_FILE) == BST_CHECKED; - g_plugin.setByte("WriteLogFile", bNew); + g_plugin.setByte("WriteLogFile", IsDlgButtonChecked(hwndDlg, IDC_WRITE_LOG_FILE) == BST_CHECKED); bShowPopups = IsDlgButtonChecked(hwndDlg, IDC_SHOW_POPUPS) == BST_CHECKED; g_plugin.setByte("ShowPopups", bShowPopups); @@ -1398,7 +1372,7 @@ void ShowPopupWindow(const char * pszName, const char * pszText, COLORREF ColorB POPUPDATA *pclData = new POPUPDATA; memset(pclData, 0, sizeof(POPUPDATA)); - pclData->lchIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_SHARE_NEW_FILE)); + pclData->lchIcon = g_plugin.getIcon(IDI_SHARE_NEW_FILE); strncpy(pclData->lpzContactName, pszName, sizeof(pclData->lpzContactName) - 1); // -1 so that there aways will be a null termination !! strncpy(pclData->lpzText, pszText, sizeof(pclData->lpzText) - 1); pclData->colorBack = ColorBack; @@ -1433,21 +1407,19 @@ void InitGuiElements() hShowStatisticsViewService = CreateServiceFunction(MS_SHOW_STATISTICS_VIEW, nShowStatisticsView); CMenuItem mi(&g_plugin); - mi.flags = CMIF_UNICODE; + mi.hIcolibItem = g_plugin.getIconHandle(IDI_SHARE_NEW_FILE); + SET_UID(mi, 0xb30a6ab5, 0x17a8, 0x4e2e, 0x84, 0x52, 0x5f, 0xbc, 0x83, 0x35, 0xf2, 0x6); - mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_SHARE_NEW_FILE)); mi.position = -2000019955; - mi.name.w = LPGENW("HTTP Share new file"); + mi.name.a = LPGEN("HTTP Share new file"); mi.pszService = MS_SHARE_NEW_FILE; hShareNewFileMenuItem = Menu_AddContactMenuItem(&mi); - if (g_plugin.getByte("AddStatisticsMenuItem", 1) != 0) { - SET_UID(mi, 0x68db84c9, 0xe6b4, 0x4b4f, 0x93, 0x4b, 0xfd, 0x34, 0x2d, 0x83, 0x11, 0xe7); - mi.position = 1000085005; - mi.name.w = LPGENW("Show HTTP server statistics"); - mi.pszService = MS_SHOW_STATISTICS_VIEW; - hShowStatisticsViewMenuItem = Menu_AddMainMenuItem(&mi); - } + SET_UID(mi, 0x68db84c9, 0xe6b4, 0x4b4f, 0x93, 0x4b, 0xfd, 0x34, 0x2d, 0x83, 0x11, 0xe7); + mi.position = 1000085005; + mi.name.a = LPGEN("Show HTTP server statistics"); + mi.pszService = MS_SHOW_STATISTICS_VIEW; + hShowStatisticsViewMenuItem = Menu_AddMainMenuItem(&mi); bShowPopups = g_plugin.getByte("ShowPopups", bShowPopups) != 0; } diff --git a/plugins/HTTPServer/src/HttpUser.cpp b/plugins/HTTPServer/src/HttpUser.cpp index 1f28cdac5d..5b738240b0 100644 --- a/plugins/HTTPServer/src/HttpUser.cpp +++ b/plugins/HTTPServer/src/HttpUser.cpp @@ -377,11 +377,11 @@ bool CLHttpUser::bProcessGetRequest(char * pszRequest, bool bIsGetCommand) if (nUriLength <= 0) return false; - CLFileShareListAccess clCritSection; - if (bShutdownInProgress) return false; + mir_cslockfull lck(csFileShareListAccess); + static char szTempfile[MAX_PATH + 1]; szTempfile[0] = '\0'; @@ -561,7 +561,7 @@ bool CLHttpUser::bProcessGetRequest(char * pszRequest, bool bIsGetCommand) ShowPopupWindow(inet_ntoa(stAddr), pszSrvPath); } - clCritSection.Unlock(); + lck.unlock(); DWORD dwFileStart = 0; DWORD dwDataToSend = nDataSize; @@ -740,7 +740,7 @@ bool CLHttpUser::bProcessGetRequest(char * pszRequest, bool bIsGetCommand) DeleteFile(szTempfile); } - clCritSection.Lock(); + lck.lock(); nThreadCount--; bool bNeedToWriteConfig = false; diff --git a/plugins/HTTPServer/src/main.cpp b/plugins/HTTPServer/src/main.cpp index d6a4a78566..16c328fbf9 100644 --- a/plugins/HTTPServer/src/main.cpp +++ b/plugins/HTTPServer/src/main.cpp @@ -229,7 +229,7 @@ DWORD dwReadIPAddress(char * pszStr, bool &bError) bool bReadConfigurationFile() { - CLFileShareListAccess clCritSection; + mir_cslock lck(csFileShareListAccess); CLFileShareNode * pclLastNode = nullptr; @@ -334,7 +334,7 @@ bool bReadConfigurationFile() bool bWriteConfigurationFile() { - CLFileShareListAccess clCritSection; + mir_cslock lck(csFileShareListAccess); char szBuf[1000]; mir_strcpy(szBuf, szPluginPath); mir_strcat(szBuf, szConfigFile); @@ -396,7 +396,7 @@ static INT_PTR nAddChangeRemoveShare(WPARAM wParam, LPARAM lParam) if (pclNew->lStructSize != sizeof(STFileShareInfo)) return 1002; - CLFileShareListAccess clCritSection; + mir_cslockfull lck(csFileShareListAccess); bool bIsDirectory = (pclNew->pszSrvPath[mir_strlen(pclNew->pszSrvPath) - 1] == '/'); CLFileShareNode **pclPrev = &pclFirstNode; @@ -421,9 +421,9 @@ static INT_PTR nAddChangeRemoveShare(WPARAM wParam, LPARAM lParam) nTryCount++; if (nTryCount >= 100) return 1004; - clCritSection.Unlock(); + lck.unlock(); Sleep(50); - clCritSection.Lock(); + lck.lock(); } while (pclCur->bAnyUsers()); } @@ -474,7 +474,7 @@ static INT_PTR nGetShare(WPARAM /*wParam*/, LPARAM lParam) if (!lParam) return 1001; - CLFileShareListAccess clCritSection; + mir_cslock lck(csFileShareListAccess); STFileShareInfo * pclShare = (STFileShareInfo*)lParam; CLFileShareNode * pclCur = pclFirstNode; @@ -731,13 +731,12 @@ int MainInit(WPARAM /*wparam*/, LPARAM /*lparam*/) int PreShutdown(WPARAM /*wparam*/, LPARAM /*lparam*/) { + bShutdownInProgress = true; { - CLFileShareListAccess clCrit; - bShutdownInProgress = true; + mir_cslock lck(csFileShareListAccess); - for (CLFileShareNode * pclCur = pclFirstNode; pclCur; pclCur = pclCur->pclNext) { + for (CLFileShareNode * pclCur = pclFirstNode; pclCur; pclCur = pclCur->pclNext) pclCur->CloseAllTransfers(); - } } if (hDirectBoundPort) @@ -823,16 +822,14 @@ int CMPlugin::Load() bLimitOnlyWhenOnline = g_plugin.getByte("LimitOnlyWhenOnline", bLimitOnlyWhenOnline) != 0; indexCreationMode = (eIndexCreationMode)g_plugin.getByte("IndexCreationMode", 2); - if (g_plugin.getByte("AddAcceptConMenuItem", 1)) { - CMenuItem mi(&g_plugin); - SET_UID(mi, 0xf0a68784, 0xc30e, 0x4245, 0xb6, 0x2b, 0xb8, 0x71, 0x7e, 0xe6, 0xe1, 0x73); - mi.flags = CMIF_UNICODE; - mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_SHARE_NEW_FILE)); - mi.position = 1000085000; - mi.name.a = LPGEN("Enable HTTP server"); - mi.pszService = MS_HTTP_ACCEPT_CONNECTIONS; - hAcceptConnectionsMenuItem = Menu_AddMainMenuItem(&mi); - } + CMenuItem mi(&g_plugin); + SET_UID(mi, 0xf0a68784, 0xc30e, 0x4245, 0xb6, 0x2b, 0xb8, 0x71, 0x7e, 0xe6, 0xe1, 0x73); + mi.flags = CMIF_UNICODE; + mi.hIcolibItem = g_plugin.getIconHandle(IDI_SHARE_NEW_FILE); + mi.position = 1000085000; + mi.name.a = LPGEN("Enable HTTP server"); + mi.pszService = MS_HTTP_ACCEPT_CONNECTIONS; + hAcceptConnectionsMenuItem = Menu_AddMainMenuItem(&mi); if (indexCreationMode == INDEX_CREATION_HTML || indexCreationMode == INDEX_CREATION_DETECT) if (!LoadIndexHTMLTemplate()) { diff --git a/plugins/HTTPServer/src/resource.h b/plugins/HTTPServer/src/resource.h index 3f2a2df98d..5e911d2ce1 100644 --- a/plugins/HTTPServer/src/resource.h +++ b/plugins/HTTPServer/src/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}} -// Включаемый файл, созданный в Microsoft Visual C++. -// Используется D:\MNG_orig\plugins\HTTPServer\res\resource.rc +// Microsoft Visual C++ generated include file. +// Used by w:\miranda-ng\plugins\HTTPServer\res\resource.rc // #define IDD_NEW_SHARE_PROPERTIES 101 #define IDI_DISABLE_SERVER 101 @@ -16,10 +16,8 @@ #define IDC_CURRENT_SHARES 1071 #define IDC_CURRENT_USERS 1072 #define IDC_EXTERNAL_SRV_NAME 1073 -#define IDC_ADD_STATISTICS_MENU_ITEM 1074 #define IDC_EXTERNAL_SRV_DEFAULT 1075 #define IDC_WRITE_LOG_FILE 1076 -#define IDC_ACCEPT_COM_MENU_ITEM 1078 #define IDC_TOGGLE_MASK 1080 #define IDC_OPEN_LOG 1081 #define IDC_SHOW_POPUPS 1082 @@ -48,7 +46,7 @@ // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 126 +#define _APS_NEXT_RESOURCE_VALUE 127 #define _APS_NEXT_COMMAND_VALUE 40009 #define _APS_NEXT_CONTROL_VALUE 1095 #define _APS_NEXT_SYMED_VALUE 101 -- cgit v1.2.3