From a7c24ca48995cf2bf436156302f96b91bf135409 Mon Sep 17 00:00:00 2001 From: Goraf <22941576+Goraf@users.noreply.github.com> Date: Mon, 13 Nov 2017 15:03:31 +0100 Subject: Code modernize ... * replace 0/NULL with nullptr [using clang-tidy] --- plugins/PackUpdater/Src/Events.cpp | 6 +-- plugins/PackUpdater/Src/Notifications.cpp | 54 +++++++++++++-------------- plugins/PackUpdater/Src/Options.cpp | 4 +- plugins/PackUpdater/Src/PackUpdater.cpp | 6 +-- plugins/PackUpdater/Src/Utils.cpp | 62 +++++++++++++++---------------- 5 files changed, 66 insertions(+), 66 deletions(-) (limited to 'plugins/PackUpdater') diff --git a/plugins/PackUpdater/Src/Events.cpp b/plugins/PackUpdater/Src/Events.cpp index be0be7c32d..71abc60030 100644 --- a/plugins/PackUpdater/Src/Events.cpp +++ b/plugins/PackUpdater/Src/Events.cpp @@ -38,7 +38,7 @@ int ModulesLoaded(WPARAM, LPARAM) if (AllowUpdateOnStartup()) DoCheck(UpdateOnStartup); - Timer = CreateWaitableTimer(NULL, FALSE, NULL); + Timer = CreateWaitableTimer(nullptr, FALSE, nullptr); InitTimer(); return 0; @@ -54,14 +54,14 @@ INT_PTR MenuCommand(WPARAM, LPARAM) INT_PTR EmptyFolder(WPARAM, LPARAM lParam) { SHFILEOPSTRUCT file_op = { - NULL, + nullptr, FO_DELETE, tszRoot, L"", FOF_NOERRORUI | FOF_SILENT, false, - 0, + nullptr, L"" }; if (lParam) file_op.fFlags |= FOF_NOCONFIRMATION; diff --git a/plugins/PackUpdater/Src/Notifications.cpp b/plugins/PackUpdater/Src/Notifications.cpp index ea1778f311..7ce39467bf 100644 --- a/plugins/PackUpdater/Src/Notifications.cpp +++ b/plugins/PackUpdater/Src/Notifications.cpp @@ -19,7 +19,7 @@ Boston, MA 02111-1307, USA. #include "stdafx.h" -HWND hDlgDld = NULL; +HWND hDlgDld = nullptr; INT UpdatesCount = 0; void PopupAction(HWND hWnd, BYTE action) @@ -139,7 +139,7 @@ void show_popup(HWND hDlg, LPCTSTR pszTitle, LPCTSTR pszText, int iNumber, int A pd.iSeconds = -1; else pd.iSeconds = MyOptions.Timeout; - pd.hNotification = NULL; + pd.hNotification = nullptr; pd.lpActions = pmpd->pa; pmpd->hDialog = hDlg; @@ -177,10 +177,10 @@ INT_PTR CALLBACK DlgDownloadPop(HWND hDlg, UINT uMsg, WPARAM, LPARAM) static void __stdcall CreateDownloadDialog(void*) { if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) && db_get_b(NULL, MODNAME, "Popups3", DEFAULT_POPUP_ENABLED)) - hDlgDld = CreateDialog(hInst, MAKEINTRESOURCE(IDD_POPUPDUMMI), NULL, DlgDownloadPop); + hDlgDld = CreateDialog(hInst, MAKEINTRESOURCE(IDD_POPUPDUMMI), nullptr, DlgDownloadPop); else if (db_get_b(NULL, MODNAME, "Popups3M", DEFAULT_MESSAGE_ENABLED)) { mir_wstrncpy(tszDialogMsg, Text, _countof(tszDialogMsg)); - hDlgDld = CreateDialog(hInst, MAKEINTRESOURCE(IDD_DOWNLOAD), NULL, DlgDownload); + hDlgDld = CreateDialog(hInst, MAKEINTRESOURCE(IDD_DOWNLOAD), nullptr, DlgDownload); } } @@ -191,18 +191,18 @@ static void __stdcall DestroyDownloadDialog(void*) void DlgDownloadProc() { - CallFunctionAsync(CreateDownloadDialog, 0); + CallFunctionAsync(CreateDownloadDialog, nullptr); if (!DownloadFile(pFileUrl->tszDownloadURL, pFileUrl->tszDiskPath)) { Title = TranslateT("Pack Updater"); Text = TranslateT("An error occurred while downloading the update."); if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) && db_get_b(NULL, MODNAME, "Popups1", DEFAULT_POPUP_ENABLED)) { Number = 1; - show_popup(0, Title, Text, Number, 0); + show_popup(nullptr, Title, Text, Number, 0); } else if (db_get_b(NULL, MODNAME, "Popups1M", DEFAULT_MESSAGE_ENABLED)) - MessageBox(NULL, Text, Title, MB_ICONSTOP); + MessageBox(nullptr, Text, Title, MB_ICONSTOP); } - CallFunctionAsync(DestroyDownloadDialog, 0); + CallFunctionAsync(DestroyDownloadDialog, nullptr); } INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) @@ -327,7 +327,7 @@ INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam vector &todo = *(vector *)GetWindowLongPtr(hDlg, GWLP_USERDATA); ShowWindow(hDlg, SW_HIDE); wchar_t tszBuff[2048] = { 0 }, tszFileDest[MAX_PATH] = { 0 }, tszFilePathDest[MAX_PATH] = { 0 }, tszFilePathBack[MAX_PATH] = { 0 }, tszFileName[MAX_PATH] = { 0 }; - wchar_t* tszExt = NULL; + wchar_t* tszExt = nullptr; char szKey[64] = { 0 }; vector arFileType; vector arFilePath; @@ -350,30 +350,30 @@ INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam switch (todo[i].FileType) { case 1: mir_snwprintf(tszFileDest, L"%s\\Pack", tszRoot); - CreateDirectory(tszFileDest, NULL); + CreateDirectory(tszFileDest, nullptr); break; case 2: mir_snwprintf(tszFileDest, L"%s\\Plugins", tszRoot); - CreateDirectory(tszFileDest, NULL); + CreateDirectory(tszFileDest, nullptr); break; case 3: mir_snwprintf(tszFileDest, L"%s\\Icons", tszRoot); - CreateDirectory(tszFileDest, NULL); + CreateDirectory(tszFileDest, nullptr); break; case 4: mir_snwprintf(tszFileDest, L"%s\\Others", tszRoot); - CreateDirectory(tszFileDest, NULL); + CreateDirectory(tszFileDest, nullptr); break; case 5: mir_snwprintf(tszFileDest, L"%s\\Others", tszRoot); - CreateDirectory(tszFileDest, NULL); + CreateDirectory(tszFileDest, nullptr); break; default: mir_wstrncpy(tszFileDest, tszRoot, _countof(tszFileDest)); break; } mir_snwprintf(tszBuff, L"%s\\Backups", tszRoot); - CreateDirectory(tszBuff, NULL); + CreateDirectory(tszBuff, nullptr); mir_wstrncpy(tszFileName, todo[i].File.tszDiskPath, _countof(tszFileName)); mir_snwprintf(todo[i].File.tszDiskPath, L"%s\\%s", tszFileDest, tszFileName); UpdatesCount++; @@ -421,14 +421,14 @@ INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam Title = TranslateT("Pack Updater"); Text = tszBuff; if (ServiceExists(MS_POPUP_ADDPOPUPT) && ServiceExists(MS_POPUP_REGISTERACTIONS) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) && db_get_b(NULL, MODNAME, "Popups0", DEFAULT_POPUP_ENABLED) && (db_get_dw(NULL, "Popup", "Actions", 0) & 1)) - rc = DialogBox(hInst, MAKEINTRESOURCE(IDD_POPUPDUMMI), NULL, DlgMsgPop); + rc = DialogBox(hInst, MAKEINTRESOURCE(IDD_POPUPDUMMI), nullptr, DlgMsgPop); else - rc = MessageBox(NULL, tszBuff, Title, MB_YESNO | MB_ICONQUESTION); + rc = MessageBox(nullptr, tszBuff, Title, MB_YESNO | MB_ICONQUESTION); if (rc == IDYES) { for (int i = 0; i < UpdatesCount; i++) { - wchar_t* tszUtilRootPlug = NULL; - wchar_t* tszUtilRootIco = NULL; - wchar_t* tszUtilRoot = NULL; + wchar_t* tszUtilRootPlug = nullptr; + wchar_t* tszUtilRootIco = nullptr; + wchar_t* tszUtilRoot = nullptr; wchar_t tszCurrentDir[MAX_PATH]; switch (arFileType[i]) { @@ -445,9 +445,9 @@ INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam wchar_t *p = wcsrchr(tszCurrentDir, '\\'); if (p) *p = 0; } - CreateProcess(arFilePath[i].c_str(), L"", NULL, NULL, FALSE, NULL, NULL, tszCurrentDir, &si, &pi); + CreateProcess(arFilePath[i].c_str(), L"", nullptr, nullptr, FALSE, NULL, nullptr, tszCurrentDir, &si, &pi); i = UpdatesCount; - CallFunctionAsync(ExitMe, 0); + CallFunctionAsync(ExitMe, nullptr); break; case 2: tszUtilRootPlug = Utils_ReplaceVarsW(L"%miranda_path%\\Plugins"); @@ -460,7 +460,7 @@ INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam MoveFile(arFilePath[i].c_str(), tszFilePathDest); mir_free(tszUtilRootPlug); if (i == UpdatesCount - 1) - CallFunctionAsync(RestartMe, 0); + CallFunctionAsync(RestartMe, nullptr); break; case 3: tszUtilRootIco = Utils_ReplaceVarsW(L"%miranda_path%\\Icons"); @@ -473,7 +473,7 @@ INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam MoveFile(arFilePath[i].c_str(), tszFilePathDest); mir_free(tszUtilRootIco); if (i == UpdatesCount - 1) - CallFunctionAsync(RestartMe, 0); + CallFunctionAsync(RestartMe, nullptr); break; case 4: tszUtilRoot = Utils_ReplaceVarsW(L"%miranda_path%"); @@ -486,7 +486,7 @@ INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam MoveFile(arFilePath[i].c_str(), tszFilePathDest); mir_free(tszUtilRoot); if (i == UpdatesCount - 1) - CallFunctionAsync(RestartMe, 0); + CallFunctionAsync(RestartMe, nullptr); break; case 5: tszUtilRoot = Utils_ReplaceVarsW(L"%miranda_path%"); @@ -510,10 +510,10 @@ INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam Text = tszBuff; if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) && db_get_b(NULL, MODNAME, "Popups2", DEFAULT_POPUP_ENABLED)) { Number = 2; - show_popup(0, Title, Text, Number, 0); + show_popup(nullptr, Title, Text, Number, 0); } else if (db_get_b(NULL, MODNAME, "Popups2M", DEFAULT_MESSAGE_ENABLED)) - MessageBox(NULL, Text, Title, MB_ICONINFORMATION); + MessageBox(nullptr, Text, Title, MB_ICONINFORMATION); } } } diff --git a/plugins/PackUpdater/Src/Options.cpp b/plugins/PackUpdater/Src/Options.cpp index 2fc1bb3868..421244f4af 100644 --- a/plugins/PackUpdater/Src/Options.cpp +++ b/plugins/PackUpdater/Src/Options.cpp @@ -290,7 +290,7 @@ INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) for (i = 0; i < POPUPS; i++) { if ((BST_UNCHECKED == IsDlgButtonChecked(hdlg, (i + 40071))) || (!IsWindowEnabled(GetDlgItem(hdlg, (i + 40071))))) continue; - show_popup(0, Title, Text, i, 0); + show_popup(nullptr, Title, Text, i, 0); } break; @@ -358,7 +358,7 @@ INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) //Colors db_set_b(NULL, MODNAME, "DefColors", MyOptions.DefColors); //Timeout - MyOptions.Timeout = GetDlgItemInt(hdlg, IDC_TIMEOUT_VALUE, 0, TRUE); + MyOptions.Timeout = GetDlgItemInt(hdlg, IDC_TIMEOUT_VALUE, nullptr, TRUE); db_set_dw(NULL, MODNAME, "Timeout", MyOptions.Timeout); //Left mouse click db_set_b(NULL, MODNAME, "LeftClickAction", MyOptions.LeftClickAction); diff --git a/plugins/PackUpdater/Src/PackUpdater.cpp b/plugins/PackUpdater/Src/PackUpdater.cpp index 860c37fb83..ca83b8ae11 100644 --- a/plugins/PackUpdater/Src/PackUpdater.cpp +++ b/plugins/PackUpdater/Src/PackUpdater.cpp @@ -19,9 +19,9 @@ Boston, MA 02111-1307, USA. #include "stdafx.h" -HINSTANCE hInst = NULL; +HINSTANCE hInst = nullptr; -HANDLE hPackUpdaterFolder = NULL; +HANDLE hPackUpdaterFolder = nullptr; wchar_t tszRoot[MAX_PATH] = { 0 }; int hLangpack; @@ -100,7 +100,7 @@ extern "C" __declspec(dllexport) int Load(void) extern "C" __declspec(dllexport) int Unload(void) { if (hCheckThread) - hCheckThread = NULL; + hCheckThread = nullptr; NetlibUnInit(); return 0; } \ No newline at end of file diff --git a/plugins/PackUpdater/Src/Utils.cpp b/plugins/PackUpdater/Src/Utils.cpp index 9a8ce67da2..036a782d3c 100644 --- a/plugins/PackUpdater/Src/Utils.cpp +++ b/plugins/PackUpdater/Src/Utils.cpp @@ -26,13 +26,13 @@ BYTE Reminder, AutoUpdate; BYTE UpdateOnStartup, UpdateOnPeriod, OnlyOnceADay, PeriodMeasure; INT Period; wchar_t tszDialogMsg[2048] = { 0 }; -FILEINFO* pFileInfo = NULL; -FILEURL* pFileUrl = NULL; -HANDLE hCheckThread = NULL; -HNETLIBUSER hNetlibUser = NULL; +FILEINFO* pFileInfo = nullptr; +FILEURL* pFileUrl = nullptr; +HANDLE hCheckThread = nullptr; +HNETLIBUSER hNetlibUser = nullptr; MYOPTIONS MyOptions = { 0 }; aPopups PopupsList[POPUPS]; -LPCTSTR Title = { 0 }, Text = { 0 }; +LPCTSTR Title = {}, Text = {}; IconItem iconList[] = { @@ -55,13 +55,13 @@ BOOL NetlibInit() nlu.szSettingsModule = MODNAME; hNetlibUser = Netlib_RegisterUser(&nlu); - return hNetlibUser != NULL; + return hNetlibUser != nullptr; } void NetlibUnInit() { Netlib_CloseHandle(hNetlibUser); - hNetlibUser = NULL; + hNetlibUser = nullptr; } void InitPopupList() @@ -130,9 +130,9 @@ BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal) if (pReply) { if (200 == pReply->resultCode && pReply->dataLength > 0) { - HANDLE hFile = CreateFile(tszLocal, GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE hFile = CreateFile(tszLocal, GENERIC_READ | GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); DWORD dwBytes; - WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, NULL); + WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, nullptr); ret = true; if (hFile) CloseHandle(hFile); @@ -184,7 +184,7 @@ static void CheckUpdates(void *) vector UpdateFiles; if (!Exists(tszRoot)) - CreateDirectory(tszRoot, NULL); + CreateDirectory(tszRoot, nullptr); Files.clear(); Reminder = db_get_b(NULL, MODNAME, "Reminder", DEFAULT_REMINDER); FileCount = db_get_dw(NULL, MODNAME, "FileCount", DEFAULT_FILECOUNT); @@ -196,11 +196,11 @@ static void CheckUpdates(void *) Text = TranslateT("URL for checking updates not found."); if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) && db_get_b(NULL, MODNAME, "Popups1", DEFAULT_POPUP_ENABLED)) { Number = 1; - show_popup(0, Title, Text, Number, 0); + show_popup(nullptr, Title, Text, Number, 0); } else if (db_get_b(NULL, MODNAME, "Popups1M", DEFAULT_MESSAGE_ENABLED)) - MessageBox(NULL, Text, Title, MB_ICONSTOP); - hCheckThread = NULL; + MessageBox(nullptr, Text, Title, MB_ICONSTOP); + hCheckThread = nullptr; return; } // Download version info @@ -214,7 +214,7 @@ static void CheckUpdates(void *) DlgDownloadProc(); mir_free(pFileUrl); if (!DlgDld) { - hCheckThread = NULL; + hCheckThread = nullptr; return; } @@ -251,10 +251,10 @@ static void CheckUpdates(void *) Text = TranslateT("Name of Update's file is not supported."); if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) && db_get_b(NULL, MODNAME, "Popups1", DEFAULT_POPUP_ENABLED)) { Number = 1; - show_popup(0, Title, Text, Number, 0); + show_popup(nullptr, Title, Text, Number, 0); } else if (db_get_b(NULL, MODNAME, "Popups1M", DEFAULT_MESSAGE_ENABLED)) - MessageBox(NULL, Text, Title, MB_ICONINFORMATION); + MessageBox(nullptr, Text, Title, MB_ICONINFORMATION); continue; } // end check update name mir_wstrncpy(Files[CurrentFile].File.tszDiskPath, tszBuff, _countof(Files[CurrentFile].File.tszDiskPath)); @@ -279,9 +279,9 @@ static void CheckUpdates(void *) VARSW tszProgFiles(L"%ProgramFiles%"); if (Files[CurrentFile].FileType != 1 && !IsUserAnAdmin() && (wcsstr(tszRoot, tszSysRoot) || wcsstr(tszRoot, tszProgFiles))) { - MessageBox(NULL, TranslateT("Update is not possible!\nYou have no Administrator's rights.\nPlease run Miranda NG with Administrator's rights."), Title, MB_ICONINFORMATION); + MessageBox(nullptr, TranslateT("Update is not possible!\nYou have no Administrator's rights.\nPlease run Miranda NG with Administrator's rights."), Title, MB_ICONINFORMATION); DeleteFile(tszTmpIni); - hCheckThread = NULL; + hCheckThread = nullptr; return; } // user have not admin's rights @@ -333,7 +333,7 @@ static void CheckUpdates(void *) upd_ret = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_UPDATE), GetDesktopWindow(), DlgUpdate, (LPARAM)&UpdateFiles); DeleteFile(tszTmpIni); if (upd_ret == IDCANCEL) { - hCheckThread = NULL; + hCheckThread = nullptr; return; } @@ -342,10 +342,10 @@ static void CheckUpdates(void *) Text = TranslateT("No updates found."); if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) && db_get_b(NULL, MODNAME, "Popups2", DEFAULT_POPUP_ENABLED)) { Number = 2; - show_popup(0, Title, Text, Number, 0); + show_popup(nullptr, Title, Text, Number, 0); } else if (db_get_b(NULL, MODNAME, "Popups2M", DEFAULT_MESSAGE_ENABLED)) - MessageBox(NULL, Text, Title, MB_ICONINFORMATION); + MessageBox(nullptr, Text, Title, MB_ICONINFORMATION); } if (!FileCount) { @@ -353,36 +353,36 @@ static void CheckUpdates(void *) Text = TranslateT("No files for update."); if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) && db_get_b(NULL, MODNAME, "Popups2", DEFAULT_POPUP_ENABLED)) { Number = 2; - show_popup(0, Title, Text, Number, 0); + show_popup(nullptr, Title, Text, Number, 0); } else if (db_get_b(NULL, MODNAME, "Popups2M", DEFAULT_MESSAGE_ENABLED)) - MessageBox(NULL, Text, Title, MB_ICONINFORMATION); + MessageBox(nullptr, Text, Title, MB_ICONINFORMATION); } - hCheckThread = NULL; + hCheckThread = nullptr; } void DoCheck(int iFlag) { - if (hCheckThread != NULL) { + if (hCheckThread != nullptr) { Title = TranslateT("Pack Updater"); Text = TranslateT("Update checking already started!"); if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) && db_get_b(NULL, MODNAME, "Popups2", DEFAULT_POPUP_ENABLED)) { Number = 2; - show_popup(0, Title, Text, Number, 0); + show_popup(nullptr, Title, Text, Number, 0); } else if (db_get_b(NULL, MODNAME, "Popups2M", DEFAULT_MESSAGE_ENABLED)) - MessageBox(NULL, Text, Title, MB_ICONINFORMATION); + MessageBox(nullptr, Text, Title, MB_ICONINFORMATION); } else if (iFlag) { - hCheckThread = mir_forkthread(CheckUpdates, 0); - db_set_dw(NULL, MODNAME, "LastUpdate", time(NULL)); + hCheckThread = mir_forkthread(CheckUpdates, nullptr); + db_set_dw(NULL, MODNAME, "LastUpdate", time(nullptr)); } } BOOL AllowUpdateOnStartup() { if (OnlyOnceADay) { - time_t now = time(NULL); + time_t now = time(nullptr); time_t was = db_get_dw(NULL, MODNAME, "LastUpdate", 0); if ((now - was) < 86400) @@ -427,6 +427,6 @@ void InitTimer() li.LowPart = (DWORD)(qwDueTime & 0xFFFFFFFF); li.HighPart = (LONG)(qwDueTime >> 32); - SetWaitableTimer(Timer, &li, interval, TimerAPCProc, NULL, 0); + SetWaitableTimer(Timer, &li, interval, TimerAPCProc, nullptr, 0); } } -- cgit v1.2.3