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 --- include/delphi/m_api.pas | 1 - include/delphi/m_pluginupdater.inc | 73 ------------ include/m_pluginupdater.h | 70 ------------ 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 +- 12 files changed, 70 insertions(+), 287 deletions(-) delete mode 100644 include/delphi/m_pluginupdater.inc delete mode 100644 include/m_pluginupdater.h delete mode 100644 plugins/PluginUpdater/src/Services.cpp diff --git a/include/delphi/m_api.pas b/include/delphi/m_api.pas index 4194a23e96..3b0c5a90f8 100644 --- a/include/delphi/m_api.pas +++ b/include/delphi/m_api.pas @@ -231,7 +231,6 @@ var {$include m_metacontacts.inc} {$include m_netlib.inc} {$include m_options.inc} - {$include m_pluginupdater.inc} {$include m_popup.inc} {$include m_protomod.inc} {$include m_skin.inc} diff --git a/include/delphi/m_pluginupdater.inc b/include/delphi/m_pluginupdater.inc deleted file mode 100644 index 25cf3648cd..0000000000 --- a/include/delphi/m_pluginupdater.inc +++ /dev/null @@ -1,73 +0,0 @@ -{ -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright 2012 Miranda NG team, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -} - - -{$IFNDEF M_PLUGINUPDATER} -{$DEFINE M_PLUGINUPDATER} - -type - PPUHashItem = ^TPUHashItem; - TPUHashItem = record - fileName :PWideChar; // file name - fileCrc :dword; // zip's crc - hash :array [0..32] of char; // file's md5 hash - selected :byte; - end; - -const -{ - Parses hashes.zip file at the specified URL and fills the base url buffer. - later a plugin can use it to address files. %platform% macro is allowed, - it expands to 32 or 64 depending on a Miranda's platform. For example, - https://miranda-ng.org/distr/stable/x%platform% - - wParam = (PWideChar)ptszUrl = url of hashes.zip - lParam = (array [1..260] of PWideChar)ptszBaseUrl = decoded base url - return = (THANDLE)array of hash items or NULL on error -} - MS_PU_PARSEHASHES = 'PluginUpdater/ParseHashes'; - -{ - Frees the hashes handle - wParam = 0 (unused) - lParam = (THANDLE) handle, returned from MS_PU_PARSEHASHES - return = always returs 0 -} - MS_PU_FREEHASHES = 'PluginUpdater/FreeHashes'; - -{ - Gets number of hashes - wParam = 0 (unused) - lParam = (THANDLE) handle, returned from MS_PU_PARSEHASHES - return = (int)number of hashes in an object -} - MS_PU_GETHASHCOUNT = 'PluginUpdater/GetHashCount'; - -{ - Gets concrete hash by index - wParam = (int)zero-based index (0..MS_PU_GETHASHCOUNT-1) - lParam = (THANDLE) handle, returned from MS_PU_PARSEHASHES - return = (PU_HASH_ITEM*)pointer to a hash structure -} - MS_PU_GETNTHHASH = 'PluginUpdater/GetNthCount'; - -{$ENDIF} diff --git a/include/m_pluginupdater.h b/include/m_pluginupdater.h deleted file mode 100644 index f4e2e47f4a..0000000000 --- a/include/m_pluginupdater.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (C) 2012-20 Miranda NG team (https://miranda-ng.org) -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - - -#ifndef M_PLUGINUPDATER_H__ -#define M_PLUGINUPDATER_H__ 1 - -typedef struct { - wchar_t *m_fileName; - DWORD m_zipCrc; - char m_hash[32+1]; -} - PU_HASH_ITEM; - -//Parses hashes.zip file at the specified URL and fills the base url buffer. -//later a plugin can use it to address files. %platform% macro is allowed, -//it expands to 32 or 64 depending on a Miranda's platform. For example, -// https://miranda-ng.org/distr/stable/x%platform% -// -//wParam = (wchar_t*)ptszUrl = url of hashes.zip -//lParam = (wchar_t[260])ptszBaseUrl = decoded base url -//return = (HANDLE)array of hash items or NULL on error - -#define MS_PU_PARSEHASHES "PluginUpdater/ParseHashes" - -//Frees the hashes handle -//wParam = 0 (unused) -//lParam = (HANDLE) handle, returned from MS_PU_PARSEHASHES -//return = always returs 0 - -#define MS_PU_FREEHASHES "PluginUpdater/FreeHashes" - -//Gets number of hashes -//wParam = 0 (unused) -//lParam = (HANDLE) handle, returned from MS_PU_PARSEHASHES -//return = (int)number of hashes in an object - -#define MS_PU_GETHASHCOUNT "PluginUpdater/GetHashCount" - -//Gets concrete hash by index -//wParam = (int)zero-based index (0..MS_PU_GETHASHCOUNT-1) -//lParam = (HANDLE) handle, returned from MS_PU_PARSEHASHES -//return = (PU_HASH_ITEM*)pointer to a hash structure - -#define MS_PU_GETNTHHASH "PluginUpdater/GetNthCount" - - -#define MS_PU_SHOWLIST "PluginUpdater/ShowList" -#define MS_PU_CHECKUPDATES "PluginUpdater/CheckUpdates" -#endif // M_PLUGINUPDATER_H__ 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