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/AssocMgr/src/assoclist.cpp | 154 +++++++++++++------------- plugins/AssocMgr/src/dde.cpp | 40 +++---- plugins/AssocMgr/src/reg.cpp | 218 ++++++++++++++++++------------------- plugins/AssocMgr/src/utils.cpp | 38 +++---- 4 files changed, 225 insertions(+), 225 deletions(-) (limited to 'plugins/AssocMgr') diff --git a/plugins/AssocMgr/src/assoclist.cpp b/plugins/AssocMgr/src/assoclist.cpp index 873283fea4..1a153b144e 100644 --- a/plugins/AssocMgr/src/assoclist.cpp +++ b/plugins/AssocMgr/src/assoclist.cpp @@ -60,7 +60,7 @@ static void SetAssocEnabled(const ASSOCDATA *assoc, BOOL fEnabled) mir_snprintf(szSetting, "enabled_%s", assoc->pszClassName); db_set_b(NULL, "AssocMgr", szSetting, (BYTE)fEnabled); // dll name for uninstall - if (assoc->hInstance != NULL && assoc->hInstance != hInst && assoc->hInstance != GetModuleHandle(NULL)) + if (assoc->hInstance != nullptr && assoc->hInstance != hInst && assoc->hInstance != GetModuleHandle(nullptr)) if (GetModuleFileName(assoc->hInstance, szBuf, _countof(szBuf))) if (PathToRelativeW(szBuf, szDLL)) { mir_snprintf(szSetting, "module_%s", assoc->pszClassName); @@ -97,7 +97,7 @@ void CleanupAssocEnabledSettings(void) if (!db_get_ws(NULL, "AssocMgr", szSetting, &dbv)) { if (PathToAbsoluteW(dbv.ptszVal, szDLL)) { // file still exists? - hFile = CreateFile(szDLL, 0, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + hFile = CreateFile(szDLL, 0, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr); if (hFile == INVALID_HANDLE_VALUE) { db_unset(NULL, "AssocMgr", ppszSettings[i]); db_unset(NULL, "AssocMgr", szSetting); @@ -174,7 +174,7 @@ static void CALLBACK NotifyTimerProc(HWND hwnd, UINT, UINT_PTR nTimerID, DWORD) mir_cslock lck(csNotifyTimer); KillTimer(hwnd, nTimerID); if (nNotifyTimerID == nTimerID) // might be stopped previously - SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, NULL, NULL); + SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, nullptr, nullptr); nNotifyTimerID = 0; } @@ -183,9 +183,9 @@ static void NotifyAssocChange(BOOL fNow) mir_cslock lck(csNotifyTimer); if (fNow) { nNotifyTimerID = 0; // stop previous timer - SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSH, NULL, NULL); + SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSH, nullptr, nullptr); } - else nNotifyTimerID = SetTimer(NULL, nNotifyTimerID, SHELLNOTIFY_DELAY, NotifyTimerProc); + else nNotifyTimerID = SetTimer(nullptr, nNotifyTimerID, SHELLNOTIFY_DELAY, NotifyTimerProc); } /************************* Assoc List Utils ***********************/ @@ -214,7 +214,7 @@ static ASSOCDATA* CopyAssocItem(const ASSOCDATA *assoc) { ASSOCDATA *assoc2; assoc2 = (ASSOCDATA*)mir_alloc(sizeof(ASSOCDATA)); - if (assoc2 == NULL) return NULL; + if (assoc2 == nullptr) return nullptr; assoc2->pszClassName = mir_strdup(assoc->pszClassName); assoc2->pszDescription = mir_wstrdup(assoc->pszDescription); assoc2->hInstance = assoc->hInstance; @@ -224,8 +224,8 @@ static ASSOCDATA* CopyAssocItem(const ASSOCDATA *assoc) assoc2->pszFileExt = mir_strdup(assoc->pszFileExt); assoc2->pszMimeType = mir_strdup(assoc->pszMimeType); assoc2->pszVerbDesc = mir_wstrdup(assoc->pszVerbDesc); - if (assoc2->pszClassName == NULL || assoc2->pszDescription == NULL || - (assoc2->pszFileExt == NULL && assoc->pszFileExt != NULL)) { + if (assoc2->pszClassName == nullptr || assoc2->pszDescription == nullptr || + (assoc2->pszFileExt == nullptr && assoc->pszFileExt != nullptr)) { mir_free(assoc2->pszClassName); // does NULL check mir_free(assoc2->pszDescription); // does NULL check mir_free(assoc2->pszService); // does NULL check @@ -233,7 +233,7 @@ static ASSOCDATA* CopyAssocItem(const ASSOCDATA *assoc) mir_free(assoc2->pszMimeType); // does NULL check mir_free(assoc2->pszVerbDesc); // does NULL check mir_free(assoc2); - return NULL; + return nullptr; } return assoc2; } @@ -242,19 +242,19 @@ static ASSOCDATA* CopyAssocItem(const ASSOCDATA *assoc) // this function assumes CoInitialize() has been called before static int ReplaceImageListAssocIcon(HIMAGELIST himl, const ASSOCDATA *assoc, int iPrevIndex) { - HICON hIcon = NULL; + HICON hIcon = nullptr; int index; - if (himl == NULL) return -1; + if (himl == nullptr) return -1; // load icon hIcon = LoadRegClassSmallIcon(assoc->pszClassName); - if (hIcon == NULL) { + if (hIcon == nullptr) { SHFILEINFOA sfi; - if (SHGetFileInfoA((assoc->pszFileExt != NULL) ? assoc->pszFileExt : "", FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES)) + if (SHGetFileInfoA((assoc->pszFileExt != nullptr) ? assoc->pszFileExt : "", FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES)) hIcon = sfi.hIcon; // WinXP: this icon is not updated until the process exits } // add icon - if (hIcon == NULL) return -1; + if (hIcon == nullptr) return -1; index = ImageList_ReplaceIcon(himl, iPrevIndex, hIcon); DestroyIcon(hIcon); return index; @@ -265,7 +265,7 @@ static int ReplaceImageListAssocIcon(HIMAGELIST himl, const ASSOCDATA *assoc, in static wchar_t* GetAssocTypeDesc(const ASSOCDATA *assoc) { static wchar_t szDesc[32]; - if (assoc->pszFileExt == NULL) + if (assoc->pszFileExt == nullptr) mir_snwprintf(szDesc, L"%hs:", assoc->pszClassName); else mir_snwprintf(szDesc, TranslateT("%hs files"), assoc->pszFileExt); @@ -277,12 +277,12 @@ static BOOL IsAssocRegistered(const ASSOCDATA *assoc) { BOOL fSuccess = FALSE, fIsUrl, fUseMainCmdLine; - fIsUrl = (assoc->pszFileExt == NULL); - fUseMainCmdLine = (assoc->pszService == NULL); + fIsUrl = (assoc->pszFileExt == nullptr); + fUseMainCmdLine = (assoc->pszService == nullptr); // class wchar_t *pszRunCmd = MakeRunCommand(fUseMainCmdLine, !fUseMainCmdLine); - if (pszRunCmd != NULL) + if (pszRunCmd != nullptr) fSuccess = IsRegClass(assoc->pszClassName, pszRunCmd); mir_free(pszRunCmd); // does NULL check // file ext @@ -299,34 +299,34 @@ static BOOL EnsureAssocRegistered(const ASSOCDATA *assoc) BOOL fSuccess = FALSE, fIsUrl, fUseMainCmdLine; wchar_t *pszIconLoc, *pszRunCmd, *pszDdeCmd, *pszAppFileName; - fIsUrl = (assoc->pszFileExt == NULL); - fUseMainCmdLine = (assoc->pszService == NULL); + fIsUrl = (assoc->pszFileExt == nullptr); + fUseMainCmdLine = (assoc->pszService == nullptr); pszRunCmd = MakeRunCommand(fUseMainCmdLine, !fUseMainCmdLine); - if (pszRunCmd != NULL) { + if (pszRunCmd != nullptr) { fSuccess = TRUE; // tentatively // do not overwrite user customized settings if (!IsRegClass(assoc->pszClassName, pszRunCmd)) { // class icon - if (!assoc->nIconResID && fIsUrl) pszIconLoc = MakeIconLocation(NULL, 0); // miranda logo + if (!assoc->nIconResID && fIsUrl) pszIconLoc = MakeIconLocation(nullptr, 0); // miranda logo else if (!assoc->nIconResID) pszIconLoc = MakeIconLocation(hInst, IDI_MIRANDAFILE); // generic file else pszIconLoc = MakeIconLocation(assoc->hInstance, assoc->nIconResID); // register class - if (fUseMainCmdLine) pszDdeCmd = NULL; + if (fUseMainCmdLine) pszDdeCmd = nullptr; else pszDdeCmd = fIsUrl ? DDEURLCMD : DDEFILECMD; fSuccess = AddRegClass(assoc->pszClassName, assoc->pszDescription, pszIconLoc, _A2W(MIRANDANAME), pszRunCmd, pszDdeCmd, DDEAPP, DDETOPIC, assoc->pszVerbDesc, assoc->flags&FTDF_BROWSERAUTOOPEN, fIsUrl, assoc->flags&FTDF_ISSHORTCUT); mir_free(pszIconLoc); // does NULL check // file type if (fSuccess && !fIsUrl) { // register mime type - if (assoc->pszMimeType != NULL) + if (assoc->pszMimeType != nullptr) if (AddRegMimeType(assoc->pszMimeType, assoc->pszFileExt)) RememberMimeTypeAdded(assoc->pszMimeType, assoc->pszFileExt, TRUE); // register file ext fSuccess = AddRegFileExt(assoc->pszFileExt, assoc->pszClassName, assoc->pszMimeType, assoc->flags&FTDF_ISTEXT); // register open-with pszAppFileName = MakeAppFileName(fUseMainCmdLine); - if (pszAppFileName != NULL) + if (pszAppFileName != nullptr) AddRegOpenWithExtEntry(pszAppFileName, assoc->pszFileExt, assoc->pszDescription); mir_free(pszAppFileName); // does NULL check } @@ -344,12 +344,12 @@ static BOOL UnregisterAssoc(const ASSOCDATA *assoc) BOOL fIsUrl, fUseMainCmdLine; wchar_t *pszAppFileName; - fIsUrl = (assoc->pszFileExt == NULL); - fUseMainCmdLine = (assoc->pszService == NULL); + fIsUrl = (assoc->pszFileExt == nullptr); + fUseMainCmdLine = (assoc->pszService == nullptr); // class might have been registered by another instance wchar_t *pszRunCmd = MakeRunCommand(fUseMainCmdLine, !fUseMainCmdLine); - if (pszRunCmd != NULL && !IsRegClass(assoc->pszClassName, pszRunCmd)) { + if (pszRunCmd != nullptr && !IsRegClass(assoc->pszClassName, pszRunCmd)) { mir_free(pszRunCmd); return TRUE; // succeed anyway } @@ -360,14 +360,14 @@ static BOOL UnregisterAssoc(const ASSOCDATA *assoc) // file extension RemoveRegFileExt(assoc->pszFileExt, assoc->pszClassName); // mime type - if (assoc->pszMimeType != NULL) + if (assoc->pszMimeType != nullptr) if (WasMimeTypeAdded(assoc->pszMimeType)) { RemoveRegMimeType(assoc->pszMimeType, assoc->pszFileExt); RememberMimeTypeAdded(assoc->pszMimeType, assoc->pszFileExt, FALSE); } // open-with entry pszAppFileName = MakeAppFileName(fUseMainCmdLine); - if (pszAppFileName != NULL) + if (pszAppFileName != nullptr) RemoveRegOpenWithExtEntry(pszAppFileName, assoc->pszFileExt); mir_free(pszAppFileName); // does NULL check } @@ -402,7 +402,7 @@ static BOOL AddNewAssocItem_Worker(char *pszClassName, const TYPEDESCHEAD *tdh, // resize storage array pAssocListBuf = (ASSOCDATA*)mir_realloc(pAssocList, (nAssocListCount + 1)*sizeof(ASSOCDATA)); - if (pAssocListBuf == NULL) + if (pAssocListBuf == nullptr) return FALSE; pAssocList = pAssocListBuf; @@ -419,7 +419,7 @@ static BOOL AddNewAssocItem_Worker(char *pszClassName, const TYPEDESCHEAD *tdh, assoc->pszVerbDesc = pszVerbDesc; // error check - if (assoc->pszDescription == NULL || (assoc->pszService == NULL && tdh->pszService != NULL)) { + if (assoc->pszDescription == nullptr || (assoc->pszService == nullptr && tdh->pszService != nullptr)) { mir_free(assoc->pszService); // does NULL check mir_free(assoc->pszDescription); // does NULL check return FALSE; @@ -448,7 +448,7 @@ static BOOL RemoveAssocItem_Worker(const char *pszClassName) // delete registry keys and db setting UnregisterAssoc(assoc); - if (assoc->pszMimeType != NULL) + if (assoc->pszMimeType != nullptr) RememberMimeTypeAdded(assoc->pszMimeType, assoc->pszFileExt, FALSE); DeleteAssocEnabledSetting(assoc); @@ -464,7 +464,7 @@ static BOOL RemoveAssocItem_Worker(const char *pszClassName) if ((index + 1) < nAssocListCount) memmove(assoc, &pAssocList[index + 1], ((nAssocListCount - index - 1)*sizeof(ASSOCDATA))); pAssocListBuf = (ASSOCDATA*)mir_realloc(pAssocList, (nAssocListCount - 1)*sizeof(ASSOCDATA)); - if (pAssocListBuf != NULL) pAssocList = pAssocListBuf; + if (pAssocListBuf != nullptr) pAssocList = pAssocListBuf; --nAssocListCount; NotifyAssocChange(FALSE); @@ -478,12 +478,12 @@ static INT_PTR ServiceAddNewFileType(WPARAM, LPARAM lParam) const FILETYPEDESC *ftd = (FILETYPEDESC*)lParam; if (ftd->cbSize < sizeof(FILETYPEDESC)) return 1; - if (ftd->pszFileExt == NULL || ftd->pszFileExt[0] != '.') + if (ftd->pszFileExt == nullptr || ftd->pszFileExt[0] != '.') return 2; char *pszFileExt = mir_strdup(ftd->pszFileExt); char *pszClassName = MakeFileClassName(ftd->pszFileExt); - if (pszFileExt != NULL && pszClassName != NULL) { + if (pszFileExt != nullptr && pszClassName != nullptr) { wchar_t *pszVerbDesc = s2t(ftd->ptszVerbDesc, ftd->flags&FTDF_UNICODE, TRUE); // does NULL check char *pszMimeType = mir_strdup(ftd->pszMimeType); // does NULL check if (AddNewAssocItem_Worker(pszClassName, (TYPEDESCHEAD*)ftd, pszFileExt, pszVerbDesc, pszMimeType)) @@ -498,9 +498,9 @@ static INT_PTR ServiceAddNewFileType(WPARAM, LPARAM lParam) static INT_PTR ServiceRemoveFileType(WPARAM, LPARAM lParam) { - if ((char*)lParam == NULL) return 2; + if ((char*)lParam == nullptr) return 2; char *pszClassName = MakeFileClassName((char*)lParam); - if (pszClassName != NULL) + if (pszClassName != nullptr) if (RemoveAssocItem_Worker(pszClassName)) { mir_free(pszClassName); return 0; @@ -515,14 +515,14 @@ static INT_PTR ServiceAddNewUrlType(WPARAM, LPARAM lParam) if (utd->cbSize < sizeof(URLTYPEDESC)) return 1; - if (utd->pszService == NULL) + if (utd->pszService == nullptr) return 2; - if (utd->pszProtoPrefix == NULL || utd->pszProtoPrefix[mir_strlen(utd->pszProtoPrefix) - 1] != ':') + if (utd->pszProtoPrefix == nullptr || utd->pszProtoPrefix[mir_strlen(utd->pszProtoPrefix) - 1] != ':') return 2; char *pszClassName = MakeUrlClassName(utd->pszProtoPrefix); - if (pszClassName != NULL) - if (AddNewAssocItem_Worker(pszClassName, (TYPEDESCHEAD*)utd, NULL, NULL, NULL)) + if (pszClassName != nullptr) + if (AddNewAssocItem_Worker(pszClassName, (TYPEDESCHEAD*)utd, nullptr, nullptr, nullptr)) // no need to free pszClassName, as its ownership got transferred to storage list return 0; mir_free(pszClassName); // does NULL check @@ -531,9 +531,9 @@ static INT_PTR ServiceAddNewUrlType(WPARAM, LPARAM lParam) static INT_PTR ServiceRemoveUrlType(WPARAM, LPARAM lParam) { - if ((char*)lParam == NULL) return 2; + if ((char*)lParam == nullptr) return 2; char *pszClassName = MakeUrlClassName((char*)lParam); - if (pszClassName != NULL) + if (pszClassName != nullptr) if (RemoveAssocItem_Worker(pszClassName)) { mir_free(pszClassName); return 0; @@ -556,11 +556,11 @@ static BOOL InvokeHandler_Worker(const char *pszClassName, const wchar_t *pszPar return FALSE; ASSOCDATA *assoc = &pAssocList[index]; // no service specified? correct registry to use main commandline - if (assoc->pszService == NULL) { + if (assoc->pszService == nullptr) { EnsureAssocRegistered(assoc); NotifyAssocChange(FALSE); // try main command line - if ((INT_PTR)ShellExecute(NULL, NULL, pszParam, NULL, NULL, SW_SHOWNORMAL) >= 32) + if ((INT_PTR)ShellExecute(nullptr, nullptr, pszParam, nullptr, nullptr, SW_SHOWNORMAL) >= 32) *res = 0; // success return TRUE; } @@ -569,7 +569,7 @@ static BOOL InvokeHandler_Worker(const char *pszClassName, const wchar_t *pszPar pvParam = t2s(pszParam, assoc->flags&FTDF_UNICODE, FALSE); // call service - if (pszService != NULL && pvParam != NULL) + if (pszService != nullptr && pvParam != nullptr) *res = CallService(pszService, 0, (LPARAM)pvParam); mir_free(pszService); // does NULL check mir_free(pvParam); // does NULL check @@ -583,12 +583,12 @@ INT_PTR InvokeFileHandler(const wchar_t *pszFileName) // find extension wchar_t *p = (wchar_t*)wcsrchr(pszFileName, '.'); - if (p != NULL) { + if (p != nullptr) { pszFileExt = t2a(p); - if (pszFileExt != NULL) { + if (pszFileExt != nullptr) { // class name pszClassName = MakeFileClassName(pszFileExt); - if (pszClassName != NULL) + if (pszClassName != nullptr) if (!InvokeHandler_Worker(pszClassName, pszFileName, &res)) { // correct registry on error (no longer in list) RemoveRegFileExt(pszFileExt, pszClassName); @@ -608,13 +608,13 @@ INT_PTR InvokeUrlHandler(const wchar_t *pszUrl) // find prefix pszProtoPrefix = t2a(pszUrl); - if (pszProtoPrefix != NULL) { + if (pszProtoPrefix != nullptr) { p = strchr(pszProtoPrefix, ':'); - if (p != NULL) { + if (p != nullptr) { *(++p) = 0; // remove trailing : // class name pszClassName = MakeUrlClassName(pszProtoPrefix); - if (pszClassName != NULL) + if (pszClassName != nullptr) if (!InvokeHandler_Worker(pszClassName, pszUrl, &res)) // correct registry on error (no longer in list) RemoveRegClass(pszClassName); @@ -630,12 +630,12 @@ INT_PTR InvokeUrlHandler(const wchar_t *pszUrl) static int CALLBACK ListViewSortDesc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { int cmp; - if (((ASSOCDATA*)lParam1)->pszFileExt != NULL && ((ASSOCDATA*)lParam2)->pszFileExt != NULL) + if (((ASSOCDATA*)lParam1)->pszFileExt != nullptr && ((ASSOCDATA*)lParam2)->pszFileExt != nullptr) cmp = CompareStringA((LCID)lParamSort, 0, ((ASSOCDATA*)lParam1)->pszFileExt, -1, ((ASSOCDATA*)lParam2)->pszFileExt, -1); else if (((ASSOCDATA*)lParam1)->pszFileExt == ((ASSOCDATA*)lParam2)->pszFileExt) // both NULL cmp = CompareStringA((LCID)lParamSort, 0, ((ASSOCDATA*)lParam1)->pszClassName, -1, ((ASSOCDATA*)lParam2)->pszClassName, -1); else // different types, incomparable - cmp = (((ASSOCDATA*)lParam1)->pszFileExt == NULL) ? CSTR_LESS_THAN : CSTR_GREATER_THAN; + cmp = (((ASSOCDATA*)lParam1)->pszFileExt == nullptr) ? CSTR_LESS_THAN : CSTR_GREATER_THAN; if (cmp == CSTR_EQUAL) cmp = CompareString((LCID)lParamSort, 0, ((ASSOCDATA*)lParam1)->pszDescription, -1, ((ASSOCDATA*)lParam2)->pszDescription, -1); if (cmp != 0) cmp -= 2; // maintain CRT conventions @@ -652,7 +652,7 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara case WM_INITDIALOG: { TranslateDialogDefault(hwndDlg); - CoInitialize(NULL); + CoInitialize(nullptr); HWND hwndList = GetDlgItem(hwndDlg, IDC_ASSOCLIST); ListView_SetUnicodeFormat(hwndList, TRUE); @@ -675,11 +675,11 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara mir_cslock lck(csAssocList); { HDC hdc = GetDC(hwndList); - if (hdc != NULL) { // BITSPIXEL is compatible with ILC_COLOR flags + if (hdc != nullptr) { // BITSPIXEL is compatible with ILC_COLOR flags himl = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), GetDeviceCaps(hdc, BITSPIXEL) | ILC_MASK, nAssocListCount, 0); ReleaseDC(hwndList, hdc); } - else himl = NULL; + else himl = nullptr; } ListView_SetImageList(hwndList, himl, LVSIL_SMALL); // autodestroyed // enum assoc list @@ -729,8 +729,8 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara lvi.mask = LVIF_PARAM | LVIF_GROUPID; for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) { assoc = (ASSOCDATA*)lvi.lParam; - if (assoc == NULL) continue; // groups - lvi.iGroupId = (assoc->pszFileExt == NULL) + 1; + if (assoc == nullptr) continue; // groups + lvi.iGroupId = (assoc->pszFileExt == nullptr) + 1; ListView_SetItem(hwndList, &lvi); } } @@ -742,7 +742,7 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara // autostart wchar_t *pszRunCmd = MakeRunCommand(TRUE, TRUE); - if (pszRunCmd != NULL) { + if (pszRunCmd != nullptr) { CheckDlgButton(hwndDlg, IDC_AUTOSTART, IsRegRunEntry(L"MirandaNG", pszRunCmd) ? BST_CHECKED : BST_UNCHECKED); mir_free(pszRunCmd); } @@ -759,7 +759,7 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara lvi.mask = LVIF_PARAM | LVIF_IMAGE; for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) { assoc = (ASSOCDATA*)lvi.lParam; - if (assoc == NULL) continue; // groups + if (assoc == nullptr) continue; // groups lvi.iImage = ReplaceImageListAssocIcon(himl, assoc, lvi.iImage); ListView_SetItem(hwndList, &lvi); } @@ -777,7 +777,7 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara HBRUSH hBrush = (HBRUSH)SendMessage(hwndDlg, msg, wParam, lParam); COLORREF clr; HTHEME hTheme = GetWindowTheme((HWND)lParam); - if (hTheme != NULL && !GetThemeColor(hTheme, BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, &clr)) { + if (hTheme != nullptr && !GetThemeColor(hTheme, BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, &clr)) { SetBkMode((HDC)wParam, TRANSPARENT); SetTextColor((HDC)wParam, clr); } @@ -831,7 +831,7 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara lvi.iItem = ListView_GetNextItem(nmhdr->hwndFrom, lvi.iItem, LVNI_ABOVE); if (lvi.iItem != -1) if (ListView_GetItem(nmhdr->hwndFrom, &lvi)) - if ((ASSOCDATA*)lvi.lParam == NULL) // groups + if ((ASSOCDATA*)lvi.lParam == nullptr) // groups lvi.iItem = -1; if (lvi.iItem == -1) { SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); // eat it @@ -846,7 +846,7 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara lvi.iItem -= ListView_GetCountPerPage(nmhdr->hwndFrom); if (lvi.iItem >= 0) if (ListView_GetItem(nmhdr->hwndFrom, &lvi)) - if ((ASSOCDATA*)lvi.lParam == NULL) // groups + if ((ASSOCDATA*)lvi.lParam == nullptr) // groups lvi.iItem = -1; if (lvi.iItem < 0) { ListView_SetItemState(nmhdr->hwndFrom, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); @@ -874,14 +874,14 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara mir_cslock lck(csAssocList); for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) { assoc = (ASSOCDATA*)lvi.lParam; - if (assoc == NULL) continue; // groups + if (assoc == nullptr) continue; // groups fEnabled = ListView_GetCheckState(hwndList, lvi.iItem); SetAssocEnabled(assoc, fEnabled); // re-register registery keys if (fEnabled ? !EnsureAssocRegistered(assoc) : !UnregisterAssoc(assoc)) { char *pszErr = GetWinErrorDescription(GetLastError()); - ShowInfoMessage(NIIF_ERROR, Translate("File association error"), Translate("There was an error writing to the registry to modify the file/url associations.\nReason: %s"), (pszErr != NULL) ? pszErr : Translate("Unknown")); + ShowInfoMessage(NIIF_ERROR, Translate("File association error"), Translate("There was an error writing to the registry to modify the file/url associations.\nReason: %s"), (pszErr != nullptr) ? pszErr : Translate("Unknown")); mir_free(pszErr); // does NULL check fRegFailed = TRUE; // just show one time } @@ -892,12 +892,12 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara // autostart wchar_t *pszRunCmd = MakeRunCommand(TRUE, TRUE); fRegFailed = FALSE; - if (pszRunCmd != NULL) { + if (pszRunCmd != nullptr) { fEnabled = IsDlgButtonChecked(hwndDlg, IDC_AUTOSTART); if (fEnabled ? !AddRegRunEntry(L"MirandaNG", pszRunCmd) : !RemoveRegRunEntry(L"MirandaNG", pszRunCmd)) { char *pszErr; pszErr = GetWinErrorDescription(GetLastError()); - ShowInfoMessage(NIIF_ERROR, Translate("Autostart error"), Translate("There was an error writing to the registry to modify the autostart list.\n\nReason: %s"), (pszErr != NULL) ? pszErr : Translate("Unknown")); + ShowInfoMessage(NIIF_ERROR, Translate("Autostart error"), Translate("There was an error writing to the registry to modify the autostart list.\n\nReason: %s"), (pszErr != nullptr) ? pszErr : Translate("Unknown")); mir_free(pszErr); // does NULL check fRegFailed = TRUE; // just show one time } @@ -937,7 +937,7 @@ void InitAssocList(void) hHookOptInit = HookEvent(ME_OPT_INITIALISE, AssocListOptInit); // Assoc List - pAssocList = NULL; + pAssocList = nullptr; nAssocListCount = 0; // Services @@ -952,19 +952,19 @@ void InitAssocList(void) // register open-with app { wchar_t *pszAppFileName, *pszIconLoc, *pszRunCmd; - pszIconLoc = MakeIconLocation(NULL, 0); + pszIconLoc = MakeIconLocation(nullptr, 0); // miranda32.exe pszAppFileName = MakeAppFileName(TRUE); pszRunCmd = MakeRunCommand(TRUE, FALSE); - if (pszAppFileName != NULL && pszRunCmd != NULL) - AddRegOpenWith(pszAppFileName, FALSE, _A2W(MIRANDANAME), pszIconLoc, pszRunCmd, NULL, NULL, NULL); + if (pszAppFileName != nullptr && pszRunCmd != nullptr) + AddRegOpenWith(pszAppFileName, FALSE, _A2W(MIRANDANAME), pszIconLoc, pszRunCmd, nullptr, nullptr, nullptr); mir_free(pszRunCmd); // does NULL check mir_free(pszAppFileName); // does NULL check // assocmgr.dll pszAppFileName = MakeAppFileName(FALSE); pszRunCmd = MakeRunCommand(FALSE, TRUE); - if (pszAppFileName != NULL && pszRunCmd != NULL) + if (pszAppFileName != nullptr && pszRunCmd != nullptr) AddRegOpenWith(pszAppFileName, TRUE, _A2W(MIRANDANAME), pszIconLoc, pszRunCmd, DDEFILECMD, DDEAPP, DDETOPIC); mir_free(pszRunCmd); // does NULL check mir_free(pszAppFileName); // does NULL check @@ -977,12 +977,12 @@ void InitAssocList(void) FILETYPEDESC ftd; ftd.cbSize = sizeof(FILETYPEDESC); ftd.pszFileExt = ".dat"; - ftd.pszMimeType = NULL; + ftd.pszMimeType = nullptr; ftd.pwszDescription = TranslateT("Miranda NG database"); ftd.hInstance = hInst; ftd.nIconResID = IDI_MIRANDAFILE; - ftd.ptszVerbDesc = NULL; - ftd.pszService = NULL; + ftd.ptszVerbDesc = nullptr; + ftd.pszService = nullptr; ftd.flags = FTDF_DEFAULTDISABLED | FTDF_TCHAR; ServiceAddNewFileType(0, (LPARAM)&ftd); } diff --git a/plugins/AssocMgr/src/dde.cpp b/plugins/AssocMgr/src/dde.cpp index 13da3b00eb..0e9d29fb0e 100644 --- a/plugins/AssocMgr/src/dde.cpp +++ b/plugins/AssocMgr/src/dde.cpp @@ -75,7 +75,7 @@ static wchar_t* GetExecuteParam(wchar_t **ppszString) if (fQuoted) pszParam++; wchar_t *p = wcschr(pszParam, (wchar_t)(fQuoted ? '"' : ',')); - if (p != NULL) { + if (p != nullptr) { *(p++) = 0; if (fQuoted && *p == ',') p++; } @@ -105,14 +105,14 @@ static LRESULT CALLBACK DdeMessageWindow(HWND hwnd, UINT msg, WPARAM wParam, LPA case WM_DDE_EXECUTE: /* posted message */ HGLOBAL hCommand; - if (UnpackDDElParam(msg, lParam, NULL, (PUINT_PTR)&hCommand)) { + if (UnpackDDElParam(msg, lParam, nullptr, (PUINT_PTR)&hCommand)) { /* ANSI execute command can't happen for shell */ if (IsWindowUnicode((HWND)wParam)) { wchar_t *pszCommand = (wchar_t*)GlobalLock(hCommand); - if (pszCommand != NULL) { + if (pszCommand != nullptr) { wchar_t *pszAction = GetExecuteParam(&pszCommand); wchar_t *pszArg = GetExecuteParam(&pszCommand); - if (pszArg != NULL) { + if (pszArg != nullptr) { /* we are inside miranda here, we make it async so the shell does * not timeout regardless what the plugins try to do. */ if (!mir_wstrcmpi(pszAction, L"file")) @@ -147,7 +147,7 @@ static LRESULT CALLBACK DdeMessageWindow(HWND hwnd, UINT msg, WPARAM wParam, LPA ATOM hSzItem; DDEACK ack; memset(&ack, 0, sizeof(ack)); - if (UnpackDDElParam(msg, lParam, NULL, (PUINT_PTR)&hSzItem)) { + if (UnpackDDElParam(msg, lParam, nullptr, (PUINT_PTR)&hSzItem)) { lParam = ReuseDDElParam(lParam, msg, WM_DDE_ACK, *(PUINT)&ack, (UINT)hSzItem); if (!PostMessage((HWND)wParam, WM_DDE_ACK, (WPARAM)hwnd, lParam)) { if (hSzItem) GlobalDeleteAtom(hSzItem); @@ -166,18 +166,18 @@ static HANDLE StartupMainProcess(wchar_t *pszDatabasePath) wchar_t *p, szPath[MAX_PATH]; /* we are inside RunDll32 here */ - if (!GetModuleFileName(hInst, szPath, _countof(szPath))) return NULL; + if (!GetModuleFileName(hInst, szPath, _countof(szPath))) return nullptr; p = wcsrchr(szPath, '\\'); - if (p != NULL) { *p = 0; p = wcsrchr(szPath, '\\'); } - if (p == NULL) return NULL; + if (p != nullptr) { *p = 0; p = wcsrchr(szPath, '\\'); } + if (p == nullptr) return nullptr; mir_wstrcpy(++p, L"miranda32.exe"); /* inherit startup data from RunDll32 process */ STARTUPINFO si; GetStartupInfo(&si); PROCESS_INFORMATION pi; - if (!CreateProcess(szPath, pszDatabasePath, NULL, NULL, TRUE, GetPriorityClass(GetCurrentProcess()), NULL, NULL, &si, &pi)) - return NULL; + if (!CreateProcess(szPath, pszDatabasePath, nullptr, nullptr, TRUE, GetPriorityClass(GetCurrentProcess()), nullptr, nullptr, &si, &pi)) + return nullptr; CloseHandle(pi.hThread); return pi.hProcess; } @@ -189,10 +189,10 @@ EXTERN_C __declspec(dllexport) void CALLBACK WaitForDDE(HWND, HINSTANCE, wchar_t DWORD dwTick; /* wait for dde window to be available (avoiding race condition) */ - pHandles[0] = CreateEvent(NULL, TRUE, FALSE, WNDCLASS_DDEMSGWINDOW); - if (pHandles[0] != NULL) { + pHandles[0] = CreateEvent(nullptr, TRUE, FALSE, WNDCLASS_DDEMSGWINDOW); + if (pHandles[0] != nullptr) { pHandles[1] = StartupMainProcess(pszCmdLine); /* obeys nCmdShow using GetStartupInfo() */ - if (pHandles[1] != NULL) { + if (pHandles[1] != nullptr) { dwTick = GetTickCount(); /* either process terminated or dde window created */ if (WaitForMultipleObjects(_countof(pHandles), pHandles, FALSE, DDEMESSAGETIMEOUT) == WAIT_OBJECT_0) { @@ -213,7 +213,7 @@ EXTERN_C __declspec(dllexport) void CALLBACK WaitForDDE(HWND, HINSTANCE, wchar_t static int DdePreShutdown(WPARAM, LPARAM) { /* dde needs to be stopped before any plugins are unloaded */ - if (hwndDdeMsg != NULL) DestroyWindow(hwndDdeMsg); + if (hwndDdeMsg != nullptr) DestroyWindow(hwndDdeMsg); UnregisterClass(WNDCLASS_DDEMSGWINDOW, hInst); return 0; } @@ -226,19 +226,19 @@ static int DdeModulesLoaded2(WPARAM, LPARAM) wcl.cbClsExtra = 0; wcl.cbWndExtra = 0; wcl.hInstance = hInst; - wcl.hCursor = NULL; + wcl.hCursor = nullptr; wcl.lpszClassName = WNDCLASS_DDEMSGWINDOW; - wcl.hbrBackground = NULL; - wcl.hIcon = NULL; - wcl.lpszMenuName = NULL; + wcl.hbrBackground = nullptr; + wcl.hIcon = nullptr; + wcl.lpszMenuName = nullptr; wcl.style = 0; RegisterClass(&wcl); /* Note: use of HWND_MESSAGE does not fit for DDE as the window must be a top-level one */ - hwndDdeMsg = CreateWindow(WNDCLASS_DDEMSGWINDOW, NULL, 0, 0, 0, 0, 0, NULL, NULL, hInst, NULL); + hwndDdeMsg = CreateWindow(WNDCLASS_DDEMSGWINDOW, nullptr, 0, 0, 0, 0, 0, nullptr, nullptr, hInst, nullptr); /* make known dde startup code is passed */ HANDLE hEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, WNDCLASS_DDEMSGWINDOW); - if (hEvent != NULL) { + if (hEvent != nullptr) { SetEvent(hEvent); CloseHandle(hEvent); } diff --git a/plugins/AssocMgr/src/reg.cpp b/plugins/AssocMgr/src/reg.cpp index 7a717a0766..43976f1217 100644 --- a/plugins/AssocMgr/src/reg.cpp +++ b/plugins/AssocMgr/src/reg.cpp @@ -34,8 +34,8 @@ static __inline LONG regchk(LONG res, const char *pszFunc, const void *pszInfo, pszErr = GetWinErrorDescription(res); pszInfo2 = s2t(pszInfo, fInfoUnicode, FALSE); // does NULL check mir_snwprintf(szMsg, TranslateT("Access failed:\n%.64hs(%.128s)\n%.250hs(%u)\n%.256hs (%u)"), pszFunc, pszInfo2, pszFile, nLine, pszErr, res); - MessageBox(NULL, szMsg, TranslateT("Registry warning"), MB_OK | MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST | MB_TASKMODAL); - if (pszErr != NULL) LocalFree(pszErr); + MessageBox(nullptr, szMsg, TranslateT("Registry warning"), MB_OK | MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST | MB_TASKMODAL); + if (pszErr != nullptr) LocalFree(pszErr); mir_free(pszInfo2); // does NULL check } return res; @@ -100,7 +100,7 @@ char* MakeFileClassName(const char *pszFileExt) { size_t cbLen = mir_strlen(pszFileExt) + 12; char *pszClass = (char*)mir_alloc(cbLen); - if (pszClass != NULL) + if (pszClass != nullptr) // using correctly formated PROGID mir_snprintf(pszClass, cbLen, "miranda%sfile", pszFileExt); // includes dot, buffer safe return pszClass; @@ -110,7 +110,7 @@ char* MakeFileClassName(const char *pszFileExt) char* MakeUrlClassName(const char *pszUrl) { char *pszClass = mir_strdup(pszUrl); - if (pszClass != NULL) + if (pszClass != nullptr) // remove trailing : pszClass[mir_strlen(pszClass) - 1] = 0; return pszClass; @@ -119,7 +119,7 @@ char* MakeUrlClassName(const char *pszUrl) static BOOL IsFileClassName(char *pszClassName, char **ppszFileExt) { *ppszFileExt = strchr(pszClassName, '.'); - return *ppszFileExt != NULL; + return *ppszFileExt != nullptr; } // mir_free() the return value @@ -128,15 +128,15 @@ wchar_t* MakeRunCommand(BOOL fMirExe, BOOL fFixedDbProfile) wchar_t szDbFile[MAX_PATH], szExe[MAX_PATH], *pszFmt; if (fFixedDbProfile) { if (Profile_GetNameW(_countof(szDbFile), szDbFile)) - return NULL; + return nullptr; wchar_t *p = wcsrchr(szDbFile, '.'); if (p) *p = 0; } else mir_wstrcpy(szDbFile, L"%1"); // buffer safe - if (!GetModuleFileName(fMirExe ? NULL : hInst, szExe, _countof(szExe))) - return NULL; + if (!GetModuleFileName(fMirExe ? nullptr : hInst, szExe, _countof(szExe))) + return nullptr; if (fMirExe) // run command for miranda32.exe @@ -148,7 +148,7 @@ wchar_t* MakeRunCommand(BOOL fMirExe, BOOL fFixedDbProfile) GetShortPathName(szExe, szExe, _countof(szExe)); // surround by quotes if failed size_t len = mir_wstrlen(szExe); - if (wcschr(szExe, ' ') != NULL && (len + 2) < _countof(szExe)) { + if (wcschr(szExe, ' ') != nullptr && (len + 2) < _countof(szExe)) { memmove(szExe, szExe + 1, (len + 1) * sizeof(wchar_t)); szExe[len + 2] = szExe[0] = '\"'; szExe[len + 3] = 0; @@ -168,29 +168,29 @@ static BOOL IsValidRunCommand(const wchar_t *pszRunCmd) // split into executable path and arguments if (buf[0] == '\"') { pargs = wcschr(&buf[1], '\"'); - if (pargs != NULL) *(pargs++) = 0; + if (pargs != nullptr) *(pargs++) = 0; pexe = &buf[1]; if (*pargs == ' ') ++pargs; } else { pargs = wcschr(buf, ' '); - if (pargs != NULL) *pargs = 0; + if (pargs != nullptr) *pargs = 0; pexe = buf; } - if (SearchPath(NULL, pexe, L".exe", _countof(szFullExe), szFullExe, &pszFilePart)) { - if (pszFilePart != NULL) + if (SearchPath(nullptr, pexe, L".exe", _countof(szFullExe), szFullExe, &pszFilePart)) { + if (pszFilePart != nullptr) if (!mir_wstrcmpi(pszFilePart, L"rundll32.exe") || !mir_wstrcmpi(pszFilePart, L"rundll.exe")) { // split into dll path and arguments if (pargs[0] == '\"') { ++pargs; pexe = wcschr(&pargs[1], '\"'); - if (pexe != NULL) *pexe = 0; + if (pexe != nullptr) *pexe = 0; } else { pexe = wcschr(pargs, ','); - if (pexe != NULL) *pexe = 0; + if (pexe != nullptr) *pexe = 0; } - return SearchPath(NULL, pargs, L".dll", 0, NULL, NULL) != 0; + return SearchPath(nullptr, pargs, L".dll", 0, nullptr, nullptr) != 0; } return TRUE; } @@ -200,11 +200,11 @@ static BOOL IsValidRunCommand(const wchar_t *pszRunCmd) // mir_free() the return value wchar_t* MakeIconLocation(HMODULE hModule, WORD nIconResID) { - wchar_t szModule[MAX_PATH], *pszIconLoc = NULL; + wchar_t szModule[MAX_PATH], *pszIconLoc = nullptr; int cch; if ((cch = GetModuleFileName(hModule, szModule, _countof(szModule))) != 0) { pszIconLoc = (wchar_t*)mir_alloc((cch += 8) * sizeof(wchar_t)); - if (pszIconLoc != NULL) + if (pszIconLoc != nullptr) mir_snwprintf(pszIconLoc, cch, L"%s,%i", szModule, -(int)nIconResID); // id may be 0, buffer safe } return pszIconLoc; @@ -214,13 +214,13 @@ wchar_t* MakeIconLocation(HMODULE hModule, WORD nIconResID) wchar_t* MakeAppFileName(BOOL fMirExe) { wchar_t szExe[MAX_PATH], *psz; - if (GetModuleFileName(fMirExe ? NULL : hInst, szExe, _countof(szExe))) { + if (GetModuleFileName(fMirExe ? nullptr : hInst, szExe, _countof(szExe))) { psz = wcsrchr(szExe, '\\'); - if (psz != NULL) ++psz; + if (psz != nullptr) ++psz; else psz = szExe; return mir_wstrdup(psz); } - return NULL; + return nullptr; } /************************* Helpers ********************************/ @@ -232,12 +232,12 @@ static LONG DeleteRegSubTree(HKEY hKey, const wchar_t *pszSubKey) wchar_t *pszSubKeyBuf; HKEY hSubKey; if ((res = RegOpenKeyEx(hKey, pszSubKey, 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | DELETE, &hSubKey)) == ERROR_SUCCESS) { - if ((res = RegQueryInfoKey(hSubKey, NULL, NULL, NULL, NULL, &nMaxSubKeyLen, NULL, NULL, NULL, NULL, NULL, NULL)) == ERROR_SUCCESS) { + if ((res = RegQueryInfoKey(hSubKey, nullptr, nullptr, nullptr, nullptr, &nMaxSubKeyLen, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr)) == ERROR_SUCCESS) { pszSubKeyBuf = (wchar_t*)mir_alloc((nMaxSubKeyLen + 1) * sizeof(wchar_t)); - if (pszSubKeyBuf == NULL) res = ERROR_NOT_ENOUGH_MEMORY; + if (pszSubKeyBuf == nullptr) res = ERROR_NOT_ENOUGH_MEMORY; while (!res) { cchSubKey = nMaxSubKeyLen + 1; - if ((res = RegEnumKeyEx(hSubKey, 0, pszSubKeyBuf, &cchSubKey, NULL, NULL, NULL, NULL)) == ERROR_SUCCESS) + if ((res = RegEnumKeyEx(hSubKey, 0, pszSubKeyBuf, &cchSubKey, nullptr, nullptr, nullptr, nullptr)) == ERROR_SUCCESS) res = DeleteRegSubTree(hSubKey, pszSubKeyBuf); // recursion } mir_free(pszSubKeyBuf); // does NULL check @@ -253,9 +253,9 @@ static LONG DeleteRegSubTree(HKEY hKey, const wchar_t *pszSubKey) static LONG SetRegSubKeyStrDefValue(HKEY hMainKey, const wchar_t *pszSubKey, const wchar_t *pszVal) { HKEY hSubKey; - LONG res = RegCreateKeyEx(hMainKey, pszSubKey, 0, NULL, 0, KEY_SET_VALUE | KEY_QUERY_VALUE, NULL, &hSubKey, NULL); + LONG res = RegCreateKeyEx(hMainKey, pszSubKey, 0, nullptr, 0, KEY_SET_VALUE | KEY_QUERY_VALUE, nullptr, &hSubKey, nullptr); if (!res) { - res = RegSetValueEx(hSubKey, NULL, 0, REG_SZ, (BYTE*)pszVal, (int)(mir_wstrlen(pszVal) + 1) * sizeof(wchar_t)); + res = RegSetValueEx(hSubKey, nullptr, 0, REG_SZ, (BYTE*)pszVal, (int)(mir_wstrlen(pszVal) + 1) * sizeof(wchar_t)); RegCloseKey(hSubKey); } return res; @@ -267,7 +267,7 @@ static void SetRegStrPrefixValue(HKEY hKey, const wchar_t *pszValPrefix, const w size_t dwSize = (mir_wstrlen(pszVal) + mir_wstrlen(pszValPrefix) + 1) * sizeof(wchar_t); wchar_t *pszStr = (wchar_t*)_alloca(dwSize); mir_wstrcat(mir_wstrcpy(pszStr, pszValPrefix), pszVal); // buffer safe - RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)pszStr, (int)dwSize); + RegSetValueEx(hKey, nullptr, 0, REG_SZ, (BYTE*)pszStr, (int)dwSize); } // hKey must have been opened with KEY_QUERY_VALUE access right @@ -276,11 +276,11 @@ static wchar_t* GetRegStrValue(HKEY hKey, const wchar_t *pszValName) { // get size DWORD dwSize, dwType; - if (!RegQueryValueEx(hKey, pszValName, NULL, NULL, NULL, &dwSize) && dwSize > sizeof(wchar_t)) { + if (!RegQueryValueEx(hKey, pszValName, nullptr, nullptr, nullptr, &dwSize) && dwSize > sizeof(wchar_t)) { wchar_t *pszVal = (wchar_t*)mir_alloc(dwSize + sizeof(wchar_t)); - if (pszVal != NULL) { + if (pszVal != nullptr) { // get value - if (!RegQueryValueEx(hKey, pszValName, NULL, &dwType, (BYTE*)pszVal, &dwSize)) { + if (!RegQueryValueEx(hKey, pszValName, nullptr, &dwType, (BYTE*)pszVal, &dwSize)) { pszVal[dwSize / sizeof(wchar_t)] = 0; if (dwType == REG_EXPAND_SZ) { dwSize = MAX_PATH; @@ -297,7 +297,7 @@ static wchar_t* GetRegStrValue(HKEY hKey, const wchar_t *pszValName) mir_free(pszVal); } } - return NULL; + return nullptr; } // hKey must have been opened with KEY_QUERY_VALUE access right @@ -305,7 +305,7 @@ static BOOL IsRegStrValue(HKEY hKey, const wchar_t *pszValName, const wchar_t *p { BOOL fSame = FALSE; wchar_t *pszVal = GetRegStrValue(hKey, pszValName); - if (pszVal != NULL) { + if (pszVal != nullptr) { fSame = !mir_wstrcmp(pszVal, pszCmpVal); mir_free(pszVal); } @@ -318,9 +318,9 @@ static BOOL IsRegStrValueA(HKEY hKey, const wchar_t *pszValName, const char *psz BOOL fSame = FALSE; char *pszValA; wchar_t *pszVal = GetRegStrValue(hKey, pszValName); - if (pszVal != NULL) { + if (pszVal != nullptr) { pszValA = t2a(pszVal); - if (pszValA != NULL) + if (pszValA != nullptr) fSame = !mir_strcmp(pszValA, pszCmpVal); mir_free(pszValA); // does NULL check mir_free(pszVal); @@ -377,14 +377,14 @@ static void BackupRegTree_Worker(HKEY hKey, const char *pszSubKey, struct Backup char *pszName; DWORD nDbPrefixLen; if ((res = RegOpenKeyExA(hKey, pszSubKey, 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &hKey)) == ERROR_SUCCESS) { - if ((res = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, &nMaxSubKeyLen, NULL, NULL, &nMaxValNameLen, &nMaxValSize, NULL, NULL)) == ERROR_SUCCESS) { + if ((res = RegQueryInfoKey(hKey, nullptr, nullptr, nullptr, nullptr, &nMaxSubKeyLen, nullptr, nullptr, &nMaxValNameLen, &nMaxValSize, nullptr, nullptr)) == ERROR_SUCCESS) { if (nMaxSubKeyLen > nMaxValNameLen) nMaxValNameLen = nMaxSubKeyLen; // prepare buffer nDbPrefixLen = (DWORD)(mir_strlen(*param->ppszDbPrefix) + mir_strlen(pszSubKey) + 1); cchName = nDbPrefixLen + nMaxValNameLen + 3; if (cchName > *param->pdwDbPrefixSize) { pszName = (char*)mir_realloc(*param->ppszDbPrefix, cchName); - if (pszName == NULL) return; + if (pszName == nullptr) return; *param->ppszDbPrefix = pszName; *param->pdwDbPrefixSize = cchName; } @@ -393,17 +393,17 @@ static void BackupRegTree_Worker(HKEY hKey, const char *pszSubKey, struct Backup pszName = (char*)mir_alloc(nMaxValNameLen + 1); if (nMaxValSize == 0) nMaxValSize = 1; BYTE *pData = (BYTE*)mir_alloc(nMaxValSize); - if (pszName != NULL && pData != NULL) { + if (pszName != nullptr && pData != nullptr) { DWORD index = 0; while (!res) { cchName = nMaxValNameLen + 1; cbData = nMaxValSize; - if ((res = RegEnumValueA(hKey, index++, pszName, &cchName, NULL, NULL, NULL, NULL)) == ERROR_SUCCESS) { + if ((res = RegEnumValueA(hKey, index++, pszName, &cchName, nullptr, nullptr, nullptr, nullptr)) == ERROR_SUCCESS) { (*param->ppszDbPrefix)[nDbPrefixLen] = 0; mir_strcat(*param->ppszDbPrefix, pszName); // buffer safe ptrW ptszName(a2t(pszName)); if (ptszName != NULL) - if (!RegQueryValueEx(hKey, ptszName, NULL, &dwType, pData, &cbData)) + if (!RegQueryValueEx(hKey, ptszName, nullptr, &dwType, pData, &cbData)) WriteDbBackupData(*param->ppszDbPrefix, dwType, pData, cbData); } } @@ -412,12 +412,12 @@ static void BackupRegTree_Worker(HKEY hKey, const char *pszSubKey, struct Backup } mir_free(pData); // does NULL check // enum subkeys - if (param->level < 32 && pszName != NULL) { + if (param->level < 32 && pszName != nullptr) { ++param->level; // can be max 32 levels deep (after prefix), restriction of RegCreateKeyEx() DWORD index = 0; while (!res) { cchName = nMaxSubKeyLen + 1; - if ((res = RegEnumKeyExA(hKey, index++, pszName, &cchName, NULL, NULL, NULL, NULL)) == ERROR_SUCCESS) { + if ((res = RegEnumKeyExA(hKey, index++, pszName, &cchName, nullptr, nullptr, nullptr, nullptr)) == ERROR_SUCCESS) { (*param->ppszDbPrefix)[nDbPrefixLen] = 0; BackupRegTree_Worker(hKey, pszName, param); // recursion } @@ -448,12 +448,12 @@ static LONG RestoreRegTree(HKEY hKey, const char *pszSubKey, const char *pszDbPr int nDbPrefixLen = (int)mir_strlen(pszDbPrefix); int nPrefixWithSubKeyLen = nDbPrefixLen + (int)mir_strlen(pszSubKey) + 1; char *pszPrefixWithSubKey = (char*)mir_alloc(nPrefixWithSubKeyLen + 1); - if (pszPrefixWithSubKey == NULL) + if (pszPrefixWithSubKey == nullptr) return ERROR_OUTOFMEMORY; mir_strcat(mir_strcat(mir_strcpy(pszPrefixWithSubKey, pszDbPrefix), pszSubKey), "\\"); // buffer safe LONG res = ERROR_NO_MORE_ITEMS; - if (pszPrefixWithSubKey != NULL) { + if (pszPrefixWithSubKey != nullptr) { int nSettingsCount; char **ppszSettings; if (EnumDbPrefixSettings("AssocMgr", pszPrefixWithSubKey, &ppszSettings, &nSettingsCount)) { @@ -461,15 +461,15 @@ static LONG RestoreRegTree(HKEY hKey, const char *pszSubKey, const char *pszDbPr char *pszSuffix = &ppszSettings[i][nDbPrefixLen]; // key hierachy char *pkeys = mir_strcpy((char*)_alloca(mir_strlen(pszSuffix) + 1), pszSuffix); - char *pnext = pkeys, *pslash = NULL; - while ((pnext = strchr(pnext + 1, '\\')) != NULL) + char *pnext = pkeys, *pslash = nullptr; + while ((pnext = strchr(pnext + 1, '\\')) != nullptr) pslash = pnext; - if (pslash != NULL) { + if (pslash != nullptr) { // create subkey *(pslash++) = 0; HKEY hSubKey = hKey; if (pslash != pkeys + 1) - if ((res = RegCreateKeyExA(hKey, pkeys, 0, NULL, 0, KEY_SET_VALUE, NULL, &hSubKey, NULL)) != ERROR_SUCCESS) + if ((res = RegCreateKeyExA(hKey, pkeys, 0, nullptr, 0, KEY_SET_VALUE, nullptr, &hSubKey, nullptr)) != ERROR_SUCCESS) break; char *pszValName = pslash; // read data @@ -479,7 +479,7 @@ static LONG RestoreRegTree(HKEY hKey, const char *pszSubKey, const char *pszDbPr // set value if (!(dwType & REGF_ANSI)) { WCHAR *pwszValName = a2u(pszValName, FALSE); - if (pwszValName != NULL) res = RegSetValueExW(hSubKey, pwszValName, 0, dwType, pData, cbData); + if (pwszValName != nullptr) res = RegSetValueExW(hSubKey, pwszValName, 0, dwType, pData, cbData); else res = ERROR_NOT_ENOUGH_MEMORY; mir_free(pwszValName); // does NULL check } @@ -506,9 +506,9 @@ static void DeleteRegTreeBackup(const char *pszSubKey, const char *pszDbPrefix) int nSettingsCount, i; char *pszPrefixWithSubKey = (char*)mir_alloc(mir_strlen(pszDbPrefix) + mir_strlen(pszSubKey) + 2); - if (pszPrefixWithSubKey == NULL) return; + if (pszPrefixWithSubKey == nullptr) return; mir_strcat(mir_strcat(mir_strcpy(pszPrefixWithSubKey, pszDbPrefix), pszSubKey), "\\"); // buffer safe - if (pszPrefixWithSubKey != NULL) { + if (pszPrefixWithSubKey != nullptr) { if (EnumDbPrefixSettings("AssocMgr", pszPrefixWithSubKey, &ppszSettings, &nSettingsCount)) { for (i = 0; i < nSettingsCount; ++i) { db_unset(NULL, "AssocMgr", ppszSettings[i]); @@ -531,16 +531,16 @@ void CleanupRegTreeBackupSettings(void) for (int i = 0; i < nSettingsCount; ++i) { char *pszClassName = &ppszSettings[i][4]; char *pszBuf = strchr(pszClassName, '\\'); - if (pszBuf != NULL) { + if (pszBuf != nullptr) { *pszBuf = '\0'; // remove others in list with same class name if (i < nSettingsCount - 1) { for (int j = i + 1; j < nSettingsCount; ++j) { pszBuf = strchr(&ppszSettings[j][4], '\\'); - if (pszBuf != NULL) *pszBuf = '\0'; + if (pszBuf != nullptr) *pszBuf = '\0'; if (mir_strcmp(pszClassName, &ppszSettings[j][4])) { - if (pszBuf != NULL) *pszBuf = '\\'; + if (pszBuf != nullptr) *pszBuf = '\\'; continue; } @@ -582,7 +582,7 @@ BOOL AddRegClass(const char *pszClassName, const wchar_t *pszTypeDescription, co HKEY hRootKey, hClassKey, hShellKey, hVerbKey, hDdeKey; // some error checking for disallowed values (to avoid errors in registry) - if (strchr(pszClassName, '\\') != NULL || strchr(pszClassName, ' ') != NULL) { + if (strchr(pszClassName, '\\') != nullptr || strchr(pszClassName, ' ') != nullptr) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } @@ -591,50 +591,50 @@ BOOL AddRegClass(const char *pszClassName, const wchar_t *pszTypeDescription, co hRootKey = HKEY_CLASSES_ROOT; // might be write protected by security settings // class - if ((res = RegCreateKeyExA(hRootKey, pszClassName, 0, NULL, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY | DELETE | KEY_QUERY_VALUE, NULL, &hClassKey, NULL)) == ERROR_SUCCESS) { + if ((res = RegCreateKeyExA(hRootKey, pszClassName, 0, nullptr, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY | DELETE | KEY_QUERY_VALUE, nullptr, &hClassKey, nullptr)) == ERROR_SUCCESS) { // backup class if shared if (fUrlProto) BackupRegTree(hRootKey, pszClassName, "bak_"); // type description if (fUrlProto) SetRegStrPrefixValue(hClassKey, L"URL:", pszTypeDescription); - else RegSetValueEx(hClassKey, NULL, 0, REG_SZ, (BYTE*)pszTypeDescription, (int)(mir_wstrlen(pszTypeDescription) + 1) * sizeof(wchar_t)); + else RegSetValueEx(hClassKey, nullptr, 0, REG_SZ, (BYTE*)pszTypeDescription, (int)(mir_wstrlen(pszTypeDescription) + 1) * sizeof(wchar_t)); // default icon - if (pszIconLoc != NULL) SetRegSubKeyStrDefValue(hClassKey, L"DefaultIcon", pszIconLoc); + if (pszIconLoc != nullptr) SetRegSubKeyStrDefValue(hClassKey, L"DefaultIcon", pszIconLoc); // url protocol if (!fUrlProto) RegDeleteValue(hClassKey, L"URL Protocol"); - else RegSetValueEx(hClassKey, L"URL Protocol", 0, REG_SZ, NULL, 0); + else RegSetValueEx(hClassKey, L"URL Protocol", 0, REG_SZ, nullptr, 0); // moniker clsid RegDeleteKey(hClassKey, L"CLSID"); // edit flags { DWORD dwFlags = 0, dwSize = sizeof(dwFlags); - RegQueryValueEx(hClassKey, L"EditFlags", NULL, NULL, (BYTE*)&dwFlags, &dwSize); + RegQueryValueEx(hClassKey, L"EditFlags", nullptr, nullptr, (BYTE*)&dwFlags, &dwSize); if (fBrowserAutoOpen) dwFlags = (dwFlags&~FTA_AlwaysUnsafe) | FTA_OpenIsSafe; if (!fUrlProto) dwFlags |= FTA_HasExtension; else dwFlags = (dwFlags&~FTA_HasExtension) | FTA_Show; // show classes without extension RegSetValueEx(hClassKey, L"EditFlags", 0, REG_DWORD, (BYTE*)&dwFlags, sizeof(dwFlags)); } if (fIsShortcut) { - RegSetValueExA(hClassKey, "IsShortcut", 0, REG_SZ, NULL, 0); - RegSetValueExA(hClassKey, "NeverShowExt", 0, REG_SZ, NULL, 0); + RegSetValueExA(hClassKey, "IsShortcut", 0, REG_SZ, nullptr, 0); + RegSetValueExA(hClassKey, "NeverShowExt", 0, REG_SZ, nullptr, 0); } // shell - if ((res = RegCreateKeyEx(hClassKey, L"shell", 0, NULL, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY, NULL, &hShellKey, NULL)) == ERROR_SUCCESS) { + if ((res = RegCreateKeyEx(hClassKey, L"shell", 0, nullptr, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY, nullptr, &hShellKey, nullptr)) == ERROR_SUCCESS) { // default verb (when empty "open" is used) - RegSetValueEx(hShellKey, NULL, 0, REG_SZ, (BYTE*)L"open", 5 * sizeof(wchar_t)); + RegSetValueEx(hShellKey, nullptr, 0, REG_SZ, (BYTE*)L"open", 5 * sizeof(wchar_t)); // verb - if ((res = RegCreateKeyEx(hShellKey, L"open", 0, NULL, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY | DELETE, NULL, &hVerbKey, NULL)) == ERROR_SUCCESS) { + if ((res = RegCreateKeyEx(hShellKey, L"open", 0, nullptr, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY | DELETE, nullptr, &hVerbKey, nullptr)) == ERROR_SUCCESS) { // verb description - if (pszVerbDesc == NULL) RegDeleteValue(hVerbKey, NULL); - else RegSetValueEx(hVerbKey, NULL, 0, REG_SZ, (BYTE*)pszVerbDesc, (int)(mir_wstrlen(pszVerbDesc) + 1) * sizeof(wchar_t)); + if (pszVerbDesc == nullptr) RegDeleteValue(hVerbKey, nullptr); + else RegSetValueEx(hVerbKey, nullptr, 0, REG_SZ, (BYTE*)pszVerbDesc, (int)(mir_wstrlen(pszVerbDesc) + 1) * sizeof(wchar_t)); // friendly appname (mui string) RegSetValueEx(hVerbKey, L"FriendlyAppName", 0, REG_SZ, (BYTE*)pszAppName, (int)(mir_wstrlen(pszAppName) + 1) * sizeof(wchar_t)); // command SetRegSubKeyStrDefValue(hVerbKey, L"command", pszRunCmd); // ddeexec - if (pszDdeCmd != NULL) { - if (!RegCreateKeyEx(hVerbKey, L"ddeexec", 0, NULL, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY | DELETE, NULL, &hDdeKey, NULL)) { + if (pszDdeCmd != nullptr) { + if (!RegCreateKeyEx(hVerbKey, L"ddeexec", 0, nullptr, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY | DELETE, nullptr, &hDdeKey, nullptr)) { // command - RegSetValueEx(hDdeKey, NULL, 0, REG_SZ, (BYTE*)pszDdeCmd, (int)(mir_wstrlen(pszDdeCmd) + 1) * sizeof(wchar_t)); + RegSetValueEx(hDdeKey, nullptr, 0, REG_SZ, (BYTE*)pszDdeCmd, (int)(mir_wstrlen(pszDdeCmd) + 1) * sizeof(wchar_t)); // application SetRegSubKeyStrDefValue(hDdeKey, L"application", pszDdeApp); // topic @@ -684,7 +684,7 @@ BOOL RemoveRegClass(const char *pszClassName) // class name ptszClassName = a2t(pszClassName); - if (ptszClassName != NULL) + if (ptszClassName != nullptr) res = DeleteRegSubTree(hRootKey, ptszClassName); else res = ERROR_OUTOFMEMORY; mir_free(ptszClassName); // does NULL check @@ -700,7 +700,7 @@ BOOL RemoveRegClass(const char *pszClassName) if (!RegOpenKeyEx(hShellKey, L"open", 0, KEY_QUERY_VALUE, &hVerbKey)) { // command ptszPrevRunCmd = GetRegStrValue(hVerbKey, L"command"); - if (ptszPrevRunCmd != NULL && !IsValidRunCommand(ptszPrevRunCmd)) + if (ptszPrevRunCmd != nullptr && !IsValidRunCommand(ptszPrevRunCmd)) res = DeleteRegSubTree(hRootKey, ptszClassName); // backup outdated, remove all mir_free(ptszPrevRunCmd); // does NULL check RegCloseKey(hVerbKey); @@ -742,7 +742,7 @@ BOOL IsRegClass(const char *pszClassName, const wchar_t *pszRunCmd) // command if (!RegOpenKeyEx(hVerbKey, L"command", 0, KEY_QUERY_VALUE, &hCmdKey)) { // it is enough to check if the command is right - fSuccess = IsRegStrValue(hCmdKey, NULL, pszRunCmd); + fSuccess = IsRegStrValue(hCmdKey, nullptr, pszRunCmd); RegCloseKey(hCmdKey); } RegCloseKey(hVerbKey); @@ -762,7 +762,7 @@ BOOL IsRegClass(const char *pszClassName, const wchar_t *pszRunCmd) // DestroyIcon() the return value HICON LoadRegClassSmallIcon(const char *pszClassName) { - HICON hIcon = NULL; + HICON hIcon = nullptr; HKEY hClassKey, hIconKey; wchar_t *pszIconLoc, *p; @@ -772,12 +772,12 @@ HICON LoadRegClassSmallIcon(const char *pszClassName) // default icon if (!RegOpenKeyEx(hClassKey, L"DefaultIcon", 0, KEY_QUERY_VALUE, &hIconKey)) { // extract icon - pszIconLoc = GetRegStrValue(hIconKey, NULL); - if (pszIconLoc != NULL) { + pszIconLoc = GetRegStrValue(hIconKey, nullptr); + if (pszIconLoc != nullptr) { p = wcsrchr(pszIconLoc, ','); - if (p != NULL) { + if (p != nullptr) { *(p++) = 0; - ExtractIconEx(pszIconLoc, _wtoi(p), NULL, &hIcon, 1); + ExtractIconEx(pszIconLoc, _wtoi(p), nullptr, &hIcon, 1); } mir_free(pszIconLoc); } @@ -806,7 +806,7 @@ BOOL AddRegFileExt(const char *pszFileExt, const char *pszClassName, const char HKEY hRootKey, hExtKey, hOpenWithKey; // some error checking for disallowed values (to avoid errors in registry) - if (strchr(pszFileExt, '\\') != NULL || strchr(pszFileExt, ' ') != NULL) + if (strchr(pszFileExt, '\\') != nullptr || strchr(pszFileExt, ' ') != nullptr) return FALSE; // try to open interactive user's classes key @@ -814,24 +814,24 @@ BOOL AddRegFileExt(const char *pszFileExt, const char *pszClassName, const char hRootKey = HKEY_CLASSES_ROOT; // file ext - if (!RegCreateKeyExA(hRootKey, pszFileExt, 0, NULL, 0, KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_CREATE_SUB_KEY, NULL, &hExtKey, NULL)) { + if (!RegCreateKeyExA(hRootKey, pszFileExt, 0, nullptr, 0, KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_CREATE_SUB_KEY, nullptr, &hExtKey, nullptr)) { // backup previous app BackupRegTree(hRootKey, pszFileExt, "bak_"); // remove any no-open flag RegDeleteValue(hExtKey, L"NoOpen"); // open with progids - wchar_t *pszPrevClass = GetRegStrValue(hExtKey, NULL); - if (pszPrevClass != NULL && !IsRegStrValueA(hExtKey, NULL, pszClassName)) - if (!RegCreateKeyEx(hExtKey, L"OpenWithProgids", 0, NULL, 0, KEY_SET_VALUE, NULL, &hOpenWithKey, NULL)) { + wchar_t *pszPrevClass = GetRegStrValue(hExtKey, nullptr); + if (pszPrevClass != nullptr && !IsRegStrValueA(hExtKey, nullptr, pszClassName)) + if (!RegCreateKeyEx(hExtKey, L"OpenWithProgids", 0, nullptr, 0, KEY_SET_VALUE, nullptr, &hOpenWithKey, nullptr)) { // previous class (backup) - RegSetValueEx(hOpenWithKey, pszPrevClass, 0, REG_NONE, NULL, 0); + RegSetValueEx(hOpenWithKey, pszPrevClass, 0, REG_NONE, nullptr, 0); RegCloseKey(hOpenWithKey); } mir_free(pszPrevClass); // does NULL check // class name - fSuccess = !RegSetValueExA(hExtKey, NULL, 0, REG_SZ, (BYTE*)pszClassName, (int)mir_strlen(pszClassName) + 1); + fSuccess = !RegSetValueExA(hExtKey, nullptr, 0, REG_SZ, (BYTE*)pszClassName, (int)mir_strlen(pszClassName) + 1); // mime type e.g. "application/x-icq" - if (pszMimeType != NULL) RegSetValueExA(hExtKey, "Content Type", 0, REG_SZ, (BYTE*)pszMimeType, (int)mir_strlen(pszMimeType) + 1); + if (pszMimeType != nullptr) RegSetValueExA(hExtKey, "Content Type", 0, REG_SZ, (BYTE*)pszMimeType, (int)mir_strlen(pszMimeType) + 1); // perceived type e.g. text (WinXP+) if (fIsText) RegSetValueEx(hExtKey, L"PerceivedType", 0, REG_SZ, (BYTE*)L"text", 5 * sizeof(wchar_t)); RegCloseKey(hExtKey); @@ -846,7 +846,7 @@ void RemoveRegFileExt(const char *pszFileExt, const char *pszClassName) { HKEY hRootKey, hExtKey, hSubKey; DWORD nOpenWithCount; - wchar_t *pszPrevClassName = NULL; + wchar_t *pszPrevClassName = nullptr; BOOL fRestored = FALSE; // try to open interactive user's classes key @@ -857,25 +857,25 @@ void RemoveRegFileExt(const char *pszFileExt, const char *pszClassName) if (!RegOpenKeyExA(hRootKey, pszFileExt, 0, KEY_QUERY_VALUE | KEY_SET_VALUE | DELETE, &hExtKey)) { // class name (the important part) if (!RestoreRegTree(hRootKey, pszFileExt, "bak_")) { - pszPrevClassName = GetRegStrValue(hExtKey, NULL); - if (pszPrevClassName != NULL) { + pszPrevClassName = GetRegStrValue(hExtKey, nullptr); + if (pszPrevClassName != nullptr) { // previous class name still exists? // using the merged view classes key for reading if (!RegOpenKeyEx(HKEY_CLASSES_ROOT, pszPrevClassName, 0, KEY_QUERY_VALUE, &hSubKey)) { fRestored = TRUE; RegCloseKey(hSubKey); } - else RegDeleteValue(hExtKey, NULL); + else RegDeleteValue(hExtKey, nullptr); mir_free(pszPrevClassName); } } - if (pszPrevClassName == NULL) RegDeleteValue(hExtKey, NULL); + if (pszPrevClassName == nullptr) RegDeleteValue(hExtKey, nullptr); // open with progids (remove if empty) nOpenWithCount = 0; if (!RegOpenKeyEx(hExtKey, L"OpenWithProgids", 0, KEY_SET_VALUE | KEY_QUERY_VALUE, &hSubKey)) { // remove current class (if set by another app) RegDeleteValueA(hSubKey, pszClassName); - RegQueryInfoKey(hSubKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &nOpenWithCount, NULL, NULL, NULL); + RegQueryInfoKey(hSubKey, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, &nOpenWithCount, nullptr, nullptr, nullptr); RegCloseKey(hSubKey); } if (!nOpenWithCount) RegDeleteKey(hExtKey, L"OpenWithProgids"); // delete if no values @@ -904,7 +904,7 @@ BOOL IsRegFileExt(const char *pszFileExt, const char *pszClassName) if (!RegOpenKeyExA(HKEY_CLASSES_ROOT, pszFileExt, 0, KEY_QUERY_VALUE, &hExtKey)) { // class name // it is enough to check if the class is right - fSuccess = IsRegStrValueA(hExtKey, NULL, pszClassName); + fSuccess = IsRegStrValueA(hExtKey, nullptr, pszClassName); RegCloseKey(hExtKey); } return fSuccess; @@ -924,7 +924,7 @@ BOOL AddRegMimeType(const char *pszMimeType, const char *pszFileExt) HKEY hRootKey, hDbKey, hTypeKey; // some error checking for disallowed values (to avoid errors in registry) - if (strchr(pszMimeType, '\\') != NULL || strchr(pszMimeType, ' ') != NULL) + if (strchr(pszMimeType, '\\') != nullptr || strchr(pszMimeType, ' ') != nullptr) return FALSE; // try to open interactive user's classes key @@ -934,9 +934,9 @@ BOOL AddRegMimeType(const char *pszMimeType, const char *pszFileExt) // database if (!RegOpenKeyEx(hRootKey, L"MIME\\Database\\Content Type", 0, KEY_CREATE_SUB_KEY, &hDbKey)) { // mime type - if (!RegCreateKeyExA(hDbKey, pszMimeType, 0, NULL, 0, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &hTypeKey, NULL)) { + if (!RegCreateKeyExA(hDbKey, pszMimeType, 0, nullptr, 0, KEY_QUERY_VALUE | KEY_SET_VALUE, nullptr, &hTypeKey, nullptr)) { // file ext - if (RegQueryValueExA(hTypeKey, "Extension", NULL, NULL, NULL, NULL)) // only set if not present + if (RegQueryValueExA(hTypeKey, "Extension", nullptr, nullptr, nullptr, nullptr)) // only set if not present fSuccess = !RegSetValueExA(hTypeKey, "Extension", 0, REG_SZ, (BYTE*)pszFileExt, (int)mir_strlen(pszFileExt) + 1); RegCloseKey(hTypeKey); } @@ -989,31 +989,31 @@ void AddRegOpenWith(const wchar_t *pszAppFileName, BOOL fAllowOpenWith, const wc hRootKey = HKEY_CLASSES_ROOT; // database - if (!RegCreateKeyEx(hRootKey, L"Applications", 0, NULL, 0, KEY_CREATE_SUB_KEY, NULL, &hAppsKey, NULL)) { + if (!RegCreateKeyEx(hRootKey, L"Applications", 0, nullptr, 0, KEY_CREATE_SUB_KEY, nullptr, &hAppsKey, nullptr)) { // filename - if (!RegCreateKeyEx(hAppsKey, pszAppFileName, 0, NULL, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY, NULL, &hExeKey, NULL)) { + if (!RegCreateKeyEx(hAppsKey, pszAppFileName, 0, nullptr, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY, nullptr, &hExeKey, nullptr)) { // appname - RegSetValueEx(hExeKey, NULL, 0, REG_SZ, (BYTE*)pszAppName, (int)(mir_wstrlen(pszAppName) + 1) * sizeof(wchar_t)); + RegSetValueEx(hExeKey, nullptr, 0, REG_SZ, (BYTE*)pszAppName, (int)(mir_wstrlen(pszAppName) + 1) * sizeof(wchar_t)); // no open-with flag if (fAllowOpenWith) RegDeleteValue(hExeKey, L"NoOpenWith"); - else RegSetValueEx(hExeKey, L"NoOpenWith", 0, REG_SZ, NULL, 0); + else RegSetValueEx(hExeKey, L"NoOpenWith", 0, REG_SZ, nullptr, 0); // default icon - if (pszIconLoc != NULL) SetRegSubKeyStrDefValue(hExeKey, L"DefaultIcon", pszIconLoc); + if (pszIconLoc != nullptr) SetRegSubKeyStrDefValue(hExeKey, L"DefaultIcon", pszIconLoc); // shell - if (!RegCreateKeyEx(hExeKey, L"shell", 0, NULL, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY, NULL, &hShellKey, NULL)) { + if (!RegCreateKeyEx(hExeKey, L"shell", 0, nullptr, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY, nullptr, &hShellKey, nullptr)) { // default verb (when empty "open" is used) - RegSetValueEx(hShellKey, NULL, 0, REG_SZ, (BYTE*)L"open", 5 * sizeof(wchar_t)); + RegSetValueEx(hShellKey, nullptr, 0, REG_SZ, (BYTE*)L"open", 5 * sizeof(wchar_t)); // verb - if (!RegCreateKeyEx(hShellKey, L"open", 0, NULL, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY, NULL, &hVerbKey, NULL)) { + if (!RegCreateKeyEx(hShellKey, L"open", 0, nullptr, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY, nullptr, &hVerbKey, nullptr)) { // friendly appname (mui string) RegSetValueEx(hVerbKey, L"FriendlyAppName", 0, REG_SZ, (BYTE*)pszAppName, (int)(mir_wstrlen(pszAppName) + 1) * sizeof(wchar_t)); // command SetRegSubKeyStrDefValue(hVerbKey, L"command", pszRunCmd); // ddeexec - if (pszDdeCmd != NULL) - if (!RegCreateKeyEx(hVerbKey, L"ddeexec", 0, NULL, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY, NULL, &hDdeKey, NULL)) { + if (pszDdeCmd != nullptr) + if (!RegCreateKeyEx(hVerbKey, L"ddeexec", 0, nullptr, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY, nullptr, &hDdeKey, nullptr)) { // command - RegSetValueEx(hDdeKey, NULL, 0, REG_SZ, (BYTE*)pszDdeCmd, (int)(mir_wstrlen(pszDdeCmd) + 1) * sizeof(wchar_t)); + RegSetValueEx(hDdeKey, nullptr, 0, REG_SZ, (BYTE*)pszDdeCmd, (int)(mir_wstrlen(pszDdeCmd) + 1) * sizeof(wchar_t)); // application SetRegSubKeyStrDefValue(hDdeKey, L"application", pszDdeApp); // topic @@ -1097,10 +1097,10 @@ void AddRegOpenWithExtEntry(const wchar_t *pszAppFileName, const char *pszFileEx // filename if (!RegOpenKeyEx(hAppsKey, pszAppFileName, 0, KEY_CREATE_SUB_KEY, &hExeKey)) { // supported types - if (!RegCreateKeyEx(hExeKey, L"SupportedTypes", 0, NULL, 0, KEY_SET_VALUE, NULL, &hTypesKey, NULL)) { + if (!RegCreateKeyEx(hExeKey, L"SupportedTypes", 0, nullptr, 0, KEY_SET_VALUE, nullptr, &hTypesKey, nullptr)) { wchar_t *ptszFileExt; ptszFileExt = a2t(pszFileExt); - if (ptszFileExt != NULL) + if (ptszFileExt != nullptr) RegSetValueEx(hTypesKey, ptszFileExt, 0, REG_SZ, (BYTE*)pszFileDesc, (int)(mir_wstrlen(pszFileDesc) + 1) * sizeof(wchar_t)); mir_free(ptszFileExt); // does NULL check RegCloseKey(hTypesKey); @@ -1152,7 +1152,7 @@ BOOL AddRegRunEntry(const wchar_t *pszAppName, const wchar_t *pszRunCmd) HKEY hRunKey; // run - if (!RegCreateKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, 0, KEY_SET_VALUE, NULL, &hRunKey, NULL)) { + if (!RegCreateKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, nullptr, 0, KEY_SET_VALUE, nullptr, &hRunKey, nullptr)) { // appname fSuccess = !RegSetValueEx(hRunKey, pszAppName, 0, REG_SZ, (BYTE*)pszRunCmd, (int)(mir_wstrlen(pszRunCmd) + 1) * sizeof(wchar_t)); RegCloseKey(hRunKey); diff --git a/plugins/AssocMgr/src/utils.cpp b/plugins/AssocMgr/src/utils.cpp index 6f2a90b8d1..21cd8de4f6 100644 --- a/plugins/AssocMgr/src/utils.cpp +++ b/plugins/AssocMgr/src/utils.cpp @@ -29,15 +29,15 @@ WCHAR* a2u(const char *pszAnsi,BOOL fMirCp) UINT codepage,cch; WCHAR *psz; - if(pszAnsi==NULL) return NULL; + if(pszAnsi==nullptr) return nullptr; codepage = fMirCp ? Langpack_GetDefaultCodePage() : CP_ACP; - cch=MultiByteToWideChar(codepage,0,pszAnsi,-1,NULL,0); - if (!cch) return NULL; + cch=MultiByteToWideChar(codepage,0,pszAnsi,-1,nullptr,0); + if (!cch) return nullptr; psz=(WCHAR*)mir_alloc(cch*sizeof(WCHAR)); - if(psz!=NULL && !MultiByteToWideChar(codepage,0,pszAnsi,-1,psz,cch)) { + if(psz!=nullptr && !MultiByteToWideChar(codepage,0,pszAnsi,-1,psz,cch)) { mir_free(psz); - return NULL; + return nullptr; } return psz; } @@ -49,17 +49,17 @@ char* u2a(const WCHAR *pszUnicode,BOOL fMirCp) char *psz; DWORD flags; - if(pszUnicode==NULL) return NULL; + if(pszUnicode==nullptr) return nullptr; codepage = fMirCp ? Langpack_GetDefaultCodePage() : CP_ACP; /* without WC_COMPOSITECHECK some characters might get out strange (see MS blog) */ - cch=WideCharToMultiByte(codepage,flags=WC_COMPOSITECHECK,pszUnicode,-1,NULL,0,NULL,NULL); - if (!cch) cch=WideCharToMultiByte(codepage,flags=0,pszUnicode,-1,NULL,0,NULL,NULL); - if (!cch) return NULL; + cch=WideCharToMultiByte(codepage,flags=WC_COMPOSITECHECK,pszUnicode,-1,nullptr,0,nullptr,nullptr); + if (!cch) cch=WideCharToMultiByte(codepage,flags=0,pszUnicode,-1,nullptr,0,nullptr,nullptr); + if (!cch) return nullptr; psz=(char*)mir_alloc(cch); - if(psz!=NULL && !WideCharToMultiByte(codepage,flags,pszUnicode,-1,psz,cch,NULL,NULL)) { + if(psz!=nullptr && !WideCharToMultiByte(codepage,flags,pszUnicode,-1,psz,cch,nullptr,nullptr)) { mir_free(psz); - return NULL; + return nullptr; } return psz; } @@ -98,10 +98,10 @@ static int EnumPrefixSettingsProc(const char *pszSetting,LPARAM lParam) char **buf; /* resize storage array */ buf = (char**)mir_realloc(param->settings,(param->nSettingsCount+1)*sizeof(char*)); - if(buf!=NULL) { + if(buf!=nullptr) { param->settings=buf; buf[param->nSettingsCount]=mir_strdup(pszSetting); - if(buf[param->nSettingsCount]!=NULL) ++param->nSettingsCount; + if(buf[param->nSettingsCount]!=nullptr) ++param->nSettingsCount; } } return 0; @@ -111,7 +111,7 @@ static int EnumPrefixSettingsProc(const char *pszSetting,LPARAM lParam) BOOL EnumDbPrefixSettings(const char *pszModule,const char *pszSettingPrefix,char ***pSettings,int *pnSettingsCount) { struct EnumPrefixSettingsParams param; - param.settings = NULL; + param.settings = nullptr; param.nSettingsCount = 0; param.pszPrefix = pszSettingPrefix; param.nPrefixLen = (int)mir_strlen(pszSettingPrefix); @@ -141,11 +141,11 @@ void ShowInfoMessage(BYTE flags,const char *pszTitle,const char *pszTextFmt,...) mir_vsnprintf(szText,_countof(szText),pszTextFmt,va); va_end(va); - if (!Clist_TrayNotifyA(NULL, pszTitle, szText, flags, 30000)) // success + if (!Clist_TrayNotifyA(nullptr, pszTitle, szText, flags, 30000)) // success return; MSGBOXPARAMSA *mbp = (MSGBOXPARAMSA*)mir_calloc(sizeof(*mbp)); - if(mbp == NULL) + if(mbp == nullptr) return; mbp->cbSize = sizeof(*mbp); @@ -164,10 +164,10 @@ void ShowInfoMessage(BYTE flags,const char *pszTitle,const char *pszTextFmt,...) // LocalFree() the return value char* GetWinErrorDescription(DWORD dwLastError) { - char *buf=NULL; + char *buf=nullptr; DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM; - if (!FormatMessageA(flags,NULL,dwLastError, LANGIDFROMLCID(Langpack_GetDefaultLocale()),(char*)&buf,0,NULL)) + if (!FormatMessageA(flags,nullptr,dwLastError, LANGIDFROMLCID(Langpack_GetDefaultLocale()),(char*)&buf,0,nullptr)) if(GetLastError()==ERROR_RESOURCE_LANG_NOT_FOUND) - FormatMessageA(flags,NULL,dwLastError,0,(char*)&buf,0,NULL); + FormatMessageA(flags,nullptr,dwLastError,0,(char*)&buf,0,nullptr); return buf; } -- cgit v1.2.3