diff --git a/Source/DialogTemplate.cpp b/Source/DialogTemplate.cpp index 8523864d..910f9385 100644 --- a/Source/DialogTemplate.cpp +++ b/Source/DialogTemplate.cpp @@ -281,17 +281,12 @@ int CDialogTemplate::RemoveItem(WORD wId) { // Sets the font of the dialog void CDialogTemplate::SetFont(TCHAR* szFaceName, WORD wFontSize) { - if (_tcscmp(szFaceName, _T("MS Shell Dlg"))) { - // not MS Shell Dlg - m_dwStyle &= ~DS_SHELLFONT; - } - else { - // MS Shell Dlg + m_dwStyle &= ~DS_SHELLFONT; + if (!_tcscmp(szFaceName, _T("MS Shell Dlg"))) // TODO: "MS Shell Dlg 2"? m_dwStyle |= DS_SHELLFONT; - } - m_bCharset = DEFAULT_CHARSET; m_dwStyle |= DS_SETFONT; - if (m_szFont) free(m_szFont); + m_bCharset = DEFAULT_CHARSET; + free(m_szFont); m_szFont = WinWStrDupFromTChar(szFaceName, m_uCodePage); m_sFontSize = wFontSize; } @@ -334,7 +329,7 @@ HWND CDialogTemplate::CreateDummyDialog() { DWORD dwTemp; BYTE* pbDlg = Save(dwTemp); HWND hDlg = CreateDialogIndirect(GetModuleHandle(0), (DLGTEMPLATE*)pbDlg, 0, 0); - delete [] pbDlg; + FreeSavedTemplate(pbDlg); if (!hDlg) throw runtime_error("Can't create dialog from template!"); diff --git a/Source/DialogTemplate.h b/Source/DialogTemplate.h index 496a808a..ab59236b 100644 --- a/Source/DialogTemplate.h +++ b/Source/DialogTemplate.h @@ -134,6 +134,7 @@ public: #endif void ConvertToRTL(); BYTE* Save(DWORD& dwSize); + static void FreeSavedTemplate(BYTE*pDT) { delete [] pDT; } DWORD GetSize(); private: diff --git a/Source/ResourceEditor.cpp b/Source/ResourceEditor.cpp index b9c81cdf..dbde2f7b 100644 --- a/Source/ResourceEditor.cpp +++ b/Source/ResourceEditor.cpp @@ -271,9 +271,7 @@ BYTE* CResourceEditor::GetResourceW(const WINWCHAR* szType, WINWCHAR* szName, LA i = nameDir->Find(szName); if (i > -1) { langDir = nameDir->GetEntry(i)->GetSubDirectory(); - i = 0; - if (wLanguage) - i = langDir->Find(wLanguage); + i = wLanguage ? langDir->Find(wLanguage) : 0; if (i > -1) { data = langDir->GetEntry(i)->GetDataEntry(); } @@ -313,9 +311,7 @@ int CResourceEditor::GetResourceSizeW(const WINWCHAR* szType, WINWCHAR* szName, i = nameDir->Find(szName); if (i > -1) { langDir = nameDir->GetEntry(i)->GetSubDirectory(); - i = 0; - if (wLanguage) - i = langDir->Find(wLanguage); + i = wLanguage ? langDir->Find(wLanguage) : 0; if (i > -1) { data = langDir->GetEntry(i)->GetDataEntry(); } @@ -352,9 +348,7 @@ DWORD CResourceEditor::GetResourceOffsetW(const WINWCHAR* szType, WINWCHAR* szNa i = nameDir->Find(szName); if (i > -1) { langDir = nameDir->GetEntry(i)->GetSubDirectory(); - i = 0; - if (wLanguage) - i = langDir->Find(wLanguage); + i = wLanguage ? langDir->Find(wLanguage) : 0; if (i > -1) { data = langDir->GetEntry(i)->GetDataEntry(); } @@ -565,7 +559,7 @@ bool CResourceEditor::SetPESectionVirtualSize(const char* pszSectionName, DWORD // Private Methods ////////////////////////////////////////////////////////////////////// -// This function scans a give resource directory and return a CResourceDirectory object +// This function scans a given resource directory and returns a CResourceDirectory object // rdRoot must point to the root directory of the resource section CResourceDirectory* CResourceEditor::ScanDirectory(PRESOURCE_DIRECTORY rdRoot, PRESOURCE_DIRECTORY rdToScan) { // Create CResourceDirectory from rdToScan diff --git a/Source/Tests/DialogTemplate.cpp b/Source/Tests/DialogTemplate.cpp index 9d16c5e4..556117e2 100644 --- a/Source/Tests/DialogTemplate.cpp +++ b/Source/Tests/DialogTemplate.cpp @@ -40,7 +40,7 @@ public: CPPUNIT_ASSERT_EQUAL( (DWORD) sizeof(original_dialog), dwSize ); CPPUNIT_ASSERT_EQUAL( 0, memcmp(saved_dialog, original_dialog, dwSize) ); - delete [] saved_dialog; + dt.FreeSavedTemplate(saved_dialog); } }; diff --git a/Source/build.cpp b/Source/build.cpp index 55113413..59c0da4e 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -2199,7 +2199,7 @@ again: DWORD dwSize; \ dlg = dt.Save(dwSize); \ res_editor->UpdateResource(RT_DIALOG, id, NSIS_DEFAULT_LANG, dlg, dwSize); \ - delete [] dlg; \ + dt.FreeSavedTemplate(dlg); \ } \ } \ } diff --git a/Source/lang.cpp b/Source/lang.cpp index c75d95bc..b01efe60 100644 --- a/Source/lang.cpp +++ b/Source/lang.cpp @@ -718,7 +718,7 @@ int CEXEBuild::GenerateLangTables() { DWORD dwSize; \ dlg = td.Save(dwSize); \ res_editor->UpdateResource(RT_DIALOG, id, NSIS_DEFAULT_LANG, dlg, dwSize); \ - res_editor->FreeResource(dlg); \ + td.FreeSavedTemplate(dlg); \ } \ } @@ -788,7 +788,7 @@ int CEXEBuild::GenerateLangTables() { DWORD dwSize; \ dlg = td.Save(dwSize); \ res_editor->UpdateResource(RT_DIALOG, id+cur_offset, NSIS_DEFAULT_LANG, dlg, dwSize); \ - res_editor->FreeResource(dlg); \ + td.FreeSavedTemplate(dlg); \ } \ } diff --git a/Source/script.cpp b/Source/script.cpp index f46155b0..ef6879e1 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -2320,7 +2320,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) DWORD dwSize; dlg = dt.Save(dwSize); res_editor->UpdateResource(RT_DIALOG, IDD_INSTFILES, NSIS_DEFAULT_LANG, dlg, dwSize); - delete [] dlg; + dt.FreeSavedTemplate(dlg); } catch (exception& err) { ERROR_MSG(_T("Error setting smooth progress bar: %") NPRIs _T("\n"), CtoTStrParam(err.what())); @@ -2589,9 +2589,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) init_res_editor(); // Search for required items - #define GET(x) dlg = uire->GetResource(RT_DIALOG, x, 0); if (!dlg) return PS_ERROR; CDialogTemplate UIDlg(dlg, build_unicode, uDefCodePage); - #define SEARCH(x) if (!UIDlg.GetItem(x)) {ERROR_MSG(_T("Error: Can't find %") NPRIs _T(" (%u) in the custom UI!\n"), _T(#x), x);uire->FreeResource(dlg);delete uire;return PS_ERROR;} - #define SAVE(x) uire->FreeResource(dlg); dlg = UIDlg.Save(dwSize); res_editor->UpdateResource(RT_DIALOG, x, NSIS_DEFAULT_LANG, dlg, dwSize); uire->FreeResource(dlg); + #define CUISEARCHERR(n,v) ERROR_MSG(_T("Error: Can't find %") NPRIs _T(" (%u) in the custom UI!\n"), n, v); + #define GET(x) if (!(dlg = uire->GetResource(RT_DIALOG, x, 0))) { CUISEARCHERR(_T(#x), x); return PS_ERROR; } CDialogTemplate UIDlg(dlg, build_unicode, uDefCodePage); + #define SEARCH(x) if (!UIDlg.GetItem(x)) { CUISEARCHERR(_T(#x), x); uire->FreeResource(dlg); delete uire; return PS_ERROR; } + #define SAVE(x) uire->FreeResource(dlg); dlg = UIDlg.Save(dwSize); res_editor->UpdateResource(RT_DIALOG, x, NSIS_DEFAULT_LANG, dlg, dwSize); UIDlg.FreeSavedTemplate(dlg); LPBYTE dlg = NULL; @@ -2749,7 +2750,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) DWORD dwDlgSize; dlg = dt.Save(dwDlgSize); res_editor->UpdateResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, dlg, dwDlgSize); - res_editor->FreeResource(dlg); + dt.FreeSavedTemplate(dlg); dt.DlgUnitsToPixels(brandingCtl.sWidth, brandingCtl.sHeight); SCRIPT_MSG(_T("AddBrandingImage: %") NPRIs _T(" %ux%u\n"), line.gettoken_str(1), brandingCtl.sWidth, brandingCtl.sHeight); @@ -3825,7 +3826,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) DWORD dwSize; dlg = td.Save(dwSize); res_editor->UpdateResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, dlg, dwSize); - res_editor->FreeResource(dlg); + td.FreeSavedTemplate(dlg); } catch (exception& err) { ERROR_MSG(_T("Error while triming branding text control: %") NPRIs _T("\n"), CtoTStrParam(err.what()));