From 038bdcc30724bf98d1ebb8a4238680e8a09e1424 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 31 Aug 2020 20:00:56 +0300 Subject: Plugin Updater: unused services removed --- plugins/PluginUpdater/PluginUpdater.vcxproj | 1 - .../PluginUpdater/PluginUpdater.vcxproj.filters | 3 - plugins/PluginUpdater/src/DlgListNew.cpp | 5 + plugins/PluginUpdater/src/Events.cpp | 2 +- plugins/PluginUpdater/src/Notifications.cpp | 2 - plugins/PluginUpdater/src/PluginUpdater.cpp | 2 - plugins/PluginUpdater/src/Services.cpp | 66 ----------- plugins/PluginUpdater/src/Utils.cpp | 126 ++++++++++----------- plugins/PluginUpdater/src/stdafx.h | 6 +- 9 files changed, 70 insertions(+), 143 deletions(-) delete mode 100644 plugins/PluginUpdater/src/Services.cpp (limited to 'plugins/PluginUpdater') diff --git a/plugins/PluginUpdater/PluginUpdater.vcxproj b/plugins/PluginUpdater/PluginUpdater.vcxproj index 7c83aa1f5b..7617829081 100644 --- a/plugins/PluginUpdater/PluginUpdater.vcxproj +++ b/plugins/PluginUpdater/PluginUpdater.vcxproj @@ -33,7 +33,6 @@ - Create diff --git a/plugins/PluginUpdater/PluginUpdater.vcxproj.filters b/plugins/PluginUpdater/PluginUpdater.vcxproj.filters index fa518e6a97..bbce06fcdb 100644 --- a/plugins/PluginUpdater/PluginUpdater.vcxproj.filters +++ b/plugins/PluginUpdater/PluginUpdater.vcxproj.filters @@ -23,9 +23,6 @@ Source Files - - Source Files - Source Files diff --git a/plugins/PluginUpdater/src/DlgListNew.cpp b/plugins/PluginUpdater/src/DlgListNew.cpp index 8ea1056727..8703fafc7a 100644 --- a/plugins/PluginUpdater/src/DlgListNew.cpp +++ b/plugins/PluginUpdater/src/DlgListNew.cpp @@ -37,6 +37,11 @@ bool FILEINFO::IsFiltered(const CMStringW &wszFilter) ///////////////////////////////////////////////////////////////////////////////////////// +static void __stdcall OpenPluginOptions(void *) +{ + g_plugin.openOptions(nullptr, L"Plugins"); +} + static LRESULT CALLBACK PluginListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (msg == WM_LBUTTONDOWN) { diff --git a/plugins/PluginUpdater/src/Events.cpp b/plugins/PluginUpdater/src/Events.cpp index 3e734f0a0c..20080cc6d8 100644 --- a/plugins/PluginUpdater/src/Events.cpp +++ b/plugins/PluginUpdater/src/Events.cpp @@ -79,4 +79,4 @@ void InitEvents() { HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); HookEvent(ME_SYSTEM_PRESHUTDOWN, OnPreShutdown); -} \ No newline at end of file +} diff --git a/plugins/PluginUpdater/src/Notifications.cpp b/plugins/PluginUpdater/src/Notifications.cpp index 1c6cbe293c..1c1bc7e5e4 100644 --- a/plugins/PluginUpdater/src/Notifications.cpp +++ b/plugins/PluginUpdater/src/Notifications.cpp @@ -87,7 +87,6 @@ static LRESULT CALLBACK PopupDlgProcRestart(HWND hPopup, UINT uMsg, WPARAM wPara case WM_COMMAND: PUDeletePopup(hPopup); CallFunctionAsync(RestartPrompt, nullptr); - break; } @@ -138,4 +137,3 @@ void ShowPopup(LPCTSTR ptszTitle, LPCTSTR ptszText, int Number) if (Number == POPUP_TYPE_ERROR) MessageBox(nullptr, ptszText, ptszTitle, MB_ICONINFORMATION); } - diff --git a/plugins/PluginUpdater/src/PluginUpdater.cpp b/plugins/PluginUpdater/src/PluginUpdater.cpp index 7a5daa18ab..f46768a0a5 100644 --- a/plugins/PluginUpdater/src/PluginUpdater.cpp +++ b/plugins/PluginUpdater/src/PluginUpdater.cpp @@ -67,8 +67,6 @@ CMPlugin::CMPlugin() : int CMPlugin::Load() { - InitServices(); - g_plugin.setByte(DB_SETTING_NEED_RESTART, 0); DWORD dwLen = GetTempPath(_countof(g_tszTempPath), g_tszTempPath); diff --git a/plugins/PluginUpdater/src/Services.cpp b/plugins/PluginUpdater/src/Services.cpp deleted file mode 100644 index 2182c08817..0000000000 --- a/plugins/PluginUpdater/src/Services.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* -Copyright (C) 2010 Mataes - -This is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public -License as published by the Free Software Foundation; either -version 2 of the License, or (at your option) any later version. - -This is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with this file; see the file license.txt. If -not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. -*/ - -#include "stdafx.h" - -static INT_PTR srvParseHashes(WPARAM wParam, LPARAM lParam) -{ - LPCTSTR ptszUrl = (LPCTSTR)wParam; - LPTSTR ptszBaseUrl = (LPTSTR)lParam; - if (ptszUrl == nullptr || ptszBaseUrl == nullptr) - return NULL; - - SERVLIST *pList = new SERVLIST(50, CompareHashes); - ptrW baseUrl; - if (ParseHashes(ptszUrl, baseUrl, *pList)) { - wcsncpy(ptszBaseUrl, baseUrl, MAX_PATH); - return (INT_PTR)pList; - } - - delete pList; - *ptszBaseUrl = 0; - return NULL; -} - -static INT_PTR srvFreeHashes(WPARAM, LPARAM lParam) -{ - SERVLIST *pList = (SERVLIST*)lParam; - delete pList; - return 0; -} - -static INT_PTR srvGetHashCount(WPARAM, LPARAM lParam) -{ - SERVLIST *pList = (SERVLIST*)lParam; - return (pList == nullptr) ? 0 : pList->getCount(); -} - -static INT_PTR srvGetNthHash(WPARAM wParam, LPARAM lParam) -{ - SERVLIST *pList = (SERVLIST*)lParam; - return (pList == nullptr) ? 0 : INT_PTR(&(*pList)[wParam]); -} - -void InitServices() -{ - CreateServiceFunction(MS_PU_PARSEHASHES, srvParseHashes); - CreateServiceFunction(MS_PU_FREEHASHES, srvFreeHashes); - CreateServiceFunction(MS_PU_GETHASHCOUNT, srvGetHashCount); - CreateServiceFunction(MS_PU_GETNTHHASH, srvGetNthHash); -} \ No newline at end of file diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp index dcb7fcb2c0..b2482e9b0c 100644 --- a/plugins/PluginUpdater/src/Utils.cpp +++ b/plugins/PluginUpdater/src/Utils.cpp @@ -232,38 +232,34 @@ bool DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc) return false; } -void __stdcall OpenPluginOptions(void*) -{ - g_plugin.openOptions(nullptr, L"Plugins"); -} - -// FUNCTION: IsRunAsAdmin() -// -// PURPOSE: The function checks whether the current process is run as -// administrator. In other words, it dictates whether the primary access -// token of the process belongs to user account that is a member of the -// local Administrators group and it is elevated. +///////////////////////////////////////////////////////////////////////////////////// +// FUNCTION: IsRunAsAdmin() // -// RETURN VALUE: Returns TRUE if the primary access token of the process -// belongs to user account that is a member of the local Administrators -// group and it is elevated. Returns FALSE if the token does not. +// PURPOSE: The function checks whether the current process is run as +// administrator. In other words, it dictates whether the primary access +// token of the process belongs to user account that is a member of the +// local Administrators group and it is elevated. // -// EXCEPTION: If this function fails, it throws a C++ DWORD exception which -// contains the Win32 error code of the failure. +// RETURN VALUE: Returns TRUE if the primary access token of the process +// belongs to user account that is a member of the local Administrators +// group and it is elevated. Returns FALSE if the token does not. // -// EXAMPLE CALL: -// try -// { -// if (IsRunAsAdmin()) -// wprintf (L"Process is run as administrator\n"); -// else -// wprintf (L"Process is not run as administrator\n"); -// } -// catch (DWORD dwError) -// { -// wprintf(L"IsRunAsAdmin failed w/err %lu\n", dwError); -// } +// EXCEPTION: If this function fails, it throws a C++ DWORD exception which +// contains the Win32 error code of the failure. // +// EXAMPLE CALL: +// try +// { +// if (IsRunAsAdmin()) +// wprintf (L"Process is run as administrator\n"); +// else +// wprintf (L"Process is not run as administrator\n"); +// } +// catch (DWORD dwError) +// { +// wprintf(L"IsRunAsAdmin failed w/err %lu\n", dwError); +// } + BOOL IsRunAsAdmin() { BOOL fIsRunAsAdmin = FALSE; @@ -299,46 +295,46 @@ Cleanup: return fIsRunAsAdmin; } +///////////////////////////////////////////////////////////////////////////////////// +// FUNCTION: IsProcessElevated() // -// FUNCTION: IsProcessElevated() -// -// PURPOSE: The function gets the elevation information of the current -// process. It dictates whether the process is elevated or not. Token -// elevation is only available on Windows Vista and newer operating -// systems, thus IsProcessElevated throws a C++ exception if it is called -// on systems prior to Windows Vista. It is not appropriate to use this -// function to determine whether a process is run as administartor. -// -// RETURN VALUE: Returns TRUE if the process is elevated. Returns FALSE if -// it is not. +// PURPOSE: The function gets the elevation information of the current +// process. It dictates whether the process is elevated or not. Token +// elevation is only available on Windows Vista and newer operating +// systems, thus IsProcessElevated throws a C++ exception if it is called +// on systems prior to Windows Vista. It is not appropriate to use this +// function to determine whether a process is run as administartor. // -// EXCEPTION: If this function fails, it throws a C++ DWORD exception -// which contains the Win32 error code of the failure. For example, if -// IsProcessElevated is called on systems prior to Windows Vista, the error -// code will be ERROR_INVALID_PARAMETER. +// RETURN VALUE: Returns TRUE if the process is elevated. Returns FALSE if +// it is not. // -// NOTE: TOKEN_INFORMATION_CLASS provides TokenElevationType to check the -// elevation type (TokenElevationTypeDefault / TokenElevationTypeLimited / -// TokenElevationTypeFull) of the process. It is different from -// TokenElevation in that, when UAC is turned off, elevation type always -// returns TokenElevationTypeDefault even though the process is elevated -// (Integrity Level == High). In other words, it is not safe to say if the -// process is elevated based on elevation type. Instead, we should use -// TokenElevation. +// EXCEPTION: If this function fails, it throws a C++ DWORD exception +// which contains the Win32 error code of the failure. For example, if +// IsProcessElevated is called on systems prior to Windows Vista, the error +// code will be ERROR_INVALID_PARAMETER. // -// EXAMPLE CALL: -// try -// { -// if (IsProcessElevated()) -// wprintf (L"Process is elevated\n"); -// else -// wprintf (L"Process is not elevated\n"); -// } -// catch (DWORD dwError) -// { -// wprintf(L"IsProcessElevated failed w/err %lu\n", dwError); -// } +// NOTE: TOKEN_INFORMATION_CLASS provides TokenElevationType to check the +// elevation type (TokenElevationTypeDefault / TokenElevationTypeLimited / +// TokenElevationTypeFull) of the process. It is different from +// TokenElevation in that, when UAC is turned off, elevation type always +// returns TokenElevationTypeDefault even though the process is elevated +// (Integrity Level == High). In other words, it is not safe to say if the +// process is elevated based on elevation type. Instead, we should use +// TokenElevation. // +// EXAMPLE CALL: +// try +// { +// if (IsProcessElevated()) +// wprintf (L"Process is elevated\n"); +// else +// wprintf (L"Process is not elevated\n"); +// } +// catch (DWORD dwError) +// { +// wprintf(L"IsProcessElevated failed w/err %lu\n", dwError); +// } + BOOL IsProcessElevated() { BOOL fIsElevated = FALSE; @@ -545,7 +541,7 @@ int SafeCreateFilePath(const wchar_t *pFolder) int BackupFile(wchar_t *ptszSrcFileName, wchar_t *ptszBackFileName) { SafeCreateFilePath(ptszBackFileName); - + if (int iErrorCode = SafeMoveFile(ptszSrcFileName, ptszBackFileName)) return iErrorCode; return 0; @@ -553,7 +549,7 @@ int BackupFile(wchar_t *ptszSrcFileName, wchar_t *ptszBackFileName) ///////////////////////////////////////////////////////////////////////////////////////// -char *StrToLower(char *str) +char* StrToLower(char *str) { for (int i = 0; str[i]; i++) str[i] = tolower(str[i]); diff --git a/plugins/PluginUpdater/src/stdafx.h b/plugins/PluginUpdater/src/stdafx.h index 1bc95e97d5..62b5086088 100644 --- a/plugins/PluginUpdater/src/stdafx.h +++ b/plugins/PluginUpdater/src/stdafx.h @@ -41,7 +41,6 @@ Boston, MA 02111-1307, USA. #include #include #include -#include #include @@ -57,6 +56,9 @@ extern "C" #include +#define MS_PU_SHOWLIST "PluginUpdater/ShowList" +#define MS_PU_CHECKUPDATES "PluginUpdater/CheckUpdates" + #include "Notifications.h" // Enable Visual Style @@ -238,7 +240,6 @@ typedef OBJLIST SERVLIST; void InitPopupList(); void InitNetlib(); void InitIcoLib(); -void InitServices(); void InitEvents(); void InitListNew(); void InitCheck(); @@ -258,7 +259,6 @@ wchar_t* GetDefaultUrl(); bool DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc); void ShowPopup(LPCTSTR Title, LPCTSTR Text, int Number); -void __stdcall OpenPluginOptions(void*); void CheckUpdateOnStartup(); void __stdcall InitTimer(void *type); -- cgit v1.2.3