From 04234ccac258c85555438973180a12f2cdcecc4d Mon Sep 17 00:00:00 2001 From: kichik Date: Sat, 6 Sep 2003 09:59:02 +0000 Subject: [PATCH] - Fixed and improved SetFont - Fixed WindowIcon git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@2852 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/DialogTemplate.cpp | 11 ++-- Source/DialogTemplate.h | 2 +- Source/build.cpp | 43 +++++++++++++-- Source/build.h | 6 ++- Source/lang.cpp | 92 +++++++++++++++++++++++--------- Source/script.cpp | 108 +++++++------------------------------- Source/tokens.cpp | 2 +- 7 files changed, 140 insertions(+), 124 deletions(-) diff --git a/Source/DialogTemplate.cpp b/Source/DialogTemplate.cpp index 76adfaa0..f8c8ab65 100644 --- a/Source/DialogTemplate.cpp +++ b/Source/DialogTemplate.cpp @@ -251,10 +251,15 @@ DialogItemTemplate* CDialogTemplate::GetItemByIdx(DWORD i) { } // Removes an item -void CDialogTemplate::RemoveItem(WORD wId) { - for (unsigned int i = 0; i < m_vItems.size(); i++) - if (m_vItems[i]->wId == wId) +// Returns 1 if removed, 0 otherwise +int CDialogTemplate::RemoveItem(WORD wId) { + for (unsigned int i = 0; i < m_vItems.size(); i++) { + if (m_vItems[i]->wId == wId) { m_vItems.erase(m_vItems.begin() + i); + return 1; + } + } + return 0; } #ifndef DS_SHELLFONT diff --git a/Source/DialogTemplate.h b/Source/DialogTemplate.h index 65370062..004d77fe 100644 --- a/Source/DialogTemplate.h +++ b/Source/DialogTemplate.h @@ -96,7 +96,7 @@ public: short GetHeight(); DialogItemTemplate* GetItem(WORD wId); DialogItemTemplate* GetItemByIdx(DWORD i); - void RemoveItem(WORD wId); + int RemoveItem(WORD wId); void SetFont(char* szFaceName, WORD wFontSize); void AddItem(DialogItemTemplate item); HWND CreateDummyDialog(); diff --git a/Source/build.cpp b/Source/build.cpp index f8655c8c..b3d8d576 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -8,8 +8,9 @@ #include "build.h" #include "util.h" -#include "ResourceEditor.h" #include "exehead/resource.h" +#include "ResourceEditor.h" +#include "DialogTemplate.h" #include "ResourceVersionInfo.h" bool isSimpleChar(char ch) @@ -337,6 +338,9 @@ CEXEBuild::CEXEBuild() build_langstring_num=0; ubuild_langstring_num=0; + build_font[0]=NULL; + build_font_size=0; + m_unicon_data=(unsigned char *)malloc(unicondata_size+3*sizeof(DWORD)); memcpy(m_unicon_data+2*sizeof(DWORD),unicon_data+22,unicondata_size); *(DWORD*)(m_unicon_data) = unicondata_size; @@ -344,9 +348,6 @@ CEXEBuild::CEXEBuild() *(DWORD*)(m_unicon_data + 2*sizeof(DWORD) + unicondata_size) = 0; unicondata_size += 3*sizeof(DWORD); - m_inst_fileused=0; - m_uninst_fileused=0; - branding_image_found=false; no_space_texts=false; @@ -364,6 +365,8 @@ CEXEBuild::CEXEBuild() license_res_id=IDD_LICENSE; + disable_window_icon=0; + notify_hwnd=0; defcodepage_set=false; @@ -1828,6 +1831,31 @@ again: SCRIPT_MSG("Done!\n"); +#define REMOVE_ICON(id) if (disable_window_icon) { \ + BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); \ + if (dlg) { \ + CDialogTemplate dt(dlg,uDefCodePage); \ + free(dlg); \ + if (dt.RemoveItem(IDC_ULICON)) { \ + DialogItemTemplate* text = dt.GetItem(IDC_INTROTEXT); \ + DialogItemTemplate* prog = dt.GetItem(IDC_PROGRESS); \ + if (text) { \ + text->sWidth += text->sX; \ + text->sX = 0; \ + } \ + if (prog) { \ + prog->sWidth += prog->sX; \ + prog->sX = 0; \ + } \ + \ + DWORD dwSize; \ + dlg = dt.Save(dwSize); \ + res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), dlg, dwSize); \ + } \ + free(dlg); \ + } \ + } + try { SCRIPT_MSG("Removing unused resources... "); init_res_editor(); @@ -1835,30 +1863,37 @@ again: if (!license_normal) { res_editor->UpdateResource(RT_DIALOG, IDD_LICENSE, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); } + else REMOVE_ICON(IDD_LICENSE); if (!license_fsrb) { res_editor->UpdateResource(RT_DIALOG, IDD_LICENSE_FSRB, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); } + else REMOVE_ICON(IDD_LICENSE_FSRB); if (!license_fscb) { res_editor->UpdateResource(RT_DIALOG, IDD_LICENSE_FSCB, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); } + else REMOVE_ICON(IDD_LICENSE_FSCB); #endif // NSIS_CONFIG_LICENSEPAGE #ifdef NSIS_CONFIG_COMPONENTPAGE if (!selcom) { res_editor->UpdateResource(RT_DIALOG, IDD_SELCOM, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); res_editor->UpdateResource(RT_BITMAP, IDB_BITMAP1, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); } + else REMOVE_ICON(IDD_SELCOM); #endif // NSIS_CONFIG_COMPONENTPAGE if (!dir) { res_editor->UpdateResource(RT_DIALOG, IDD_DIR, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); } + else REMOVE_ICON(IDD_DIR); #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT if (!uninstconfirm) { res_editor->UpdateResource(RT_DIALOG, IDD_UNINST, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); } + else REMOVE_ICON(IDD_UNINST); #endif // NSIS_CONFIG_UNINSTALL_SUPPORT if (!instlog) { res_editor->UpdateResource(RT_DIALOG, IDD_INSTFILES, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); } + else REMOVE_ICON(IDD_INSTFILES); if (!main) { res_editor->UpdateResource(RT_DIALOG, IDD_INST, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 0, 0); if (!build_compress_whole && !build_crcchk) diff --git a/Source/build.h b/Source/build.h index ab5825dd..6b076be1 100644 --- a/Source/build.h +++ b/Source/build.h @@ -234,6 +234,8 @@ class CEXEBuild { LANGID last_used_lang; LangStringList build_langstrings; int build_langstring_num, ubuild_langstring_num; + char build_font[1024]; + int build_font_size; unsigned int uDefCodePage; @@ -243,6 +245,8 @@ class CEXEBuild { int cur_page_type; int enable_last_page_cancel, uenable_last_page_cancel; + int disable_window_icon; + // User variables stuff int GetUserVarIndex(LineParser &line, int token); // Added by ramon 3 jun 2003 @@ -320,8 +324,6 @@ class CEXEBuild { unsigned char *header_data_new; int exeheader_size_new; int icon_offset; - int m_inst_fileused; - int m_uninst_fileused; bool branding_image_found; // Added by Amir Szekely 29nd July 2002 WORD branding_image_id; // Added by Amir Szekely 29nd July 2002 unsigned char *m_unicon_data; diff --git a/Source/lang.cpp b/Source/lang.cpp index d1365c3d..285cb82c 100644 --- a/Source/lang.cpp +++ b/Source/lang.cpp @@ -292,6 +292,50 @@ int CEXEBuild::GenerateLangTables() { lt = (LanguageTable*)lang_tables.get(); } + // Apply default font + if (*build_font) + { + try { + init_res_editor(); + +#define ADD_FONT(id) { \ + BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); \ + if (dlg) { \ + CDialogTemplate td(dlg); \ + free(dlg); \ + td.SetFont(build_font, build_font_size); \ + DWORD dwSize; \ + dlg = td.Save(dwSize); \ + res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), dlg, dwSize); \ + free(dlg); \ + } \ + } + +#ifdef NSIS_CONFIG_LICENSEPAGE + ADD_FONT(IDD_LICENSE); + ADD_FONT(IDD_LICENSE_FSRB); + ADD_FONT(IDD_LICENSE_FSCB); +#endif + ADD_FONT(IDD_DIR); +#ifdef NSIS_CONFIG_COMPONENTPAGE + ADD_FONT(IDD_SELCOM); +#endif + ADD_FONT(IDD_INST); + ADD_FONT(IDD_INSTFILES); +#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT + ADD_FONT(IDD_UNINST); +#endif +#ifdef NSIS_CONFIG_CRC_SUPPORT + ADD_FONT(IDD_VERIFY); +#endif +#undef ADD_FONT + } + catch (exception& err) { + ERROR_MSG("Error while applying font: %s\n", err.what()); + return PS_ERROR; + } + } + // Fill tables with defaults (if needed) and with instruction strings // Create language specific resources (currently only dialogs with different fonts) int num_lang_tables = lang_tables.getlen() / sizeof(LanguageTable); @@ -299,11 +343,14 @@ int CEXEBuild::GenerateLangTables() { int cur_offset = num_lang_tables == 1 ? 0 : 100; for (i = 0; i < num_lang_tables; i++) { - if (lt[i].nlf.m_bLoaded && (lt[i].nlf.m_szFont || lt[i].nlf.m_bRTL)) + if ((lt[i].nlf.m_szFont && !*build_font) || lt[i].nlf.m_bRTL) { lt[i].dlg_offset = cur_offset; char *font = lt[i].nlf.m_szFont; + if (*build_font) font = 0; + + SCRIPT_MSG("setting %d to %s\n", lt[i].lang_id, font); try { init_res_editor(); @@ -342,7 +389,7 @@ int CEXEBuild::GenerateLangTables() { #undef ADD_FONT } catch (exception& err) { - ERROR_MSG("Error while applying NLF font/RTL for %s: %s\n", err.what()); + ERROR_MSG("Error while applying NLF font/RTL: %s\n", err.what()); return PS_ERROR; } @@ -627,59 +674,56 @@ LanguageTable * CEXEBuild::LoadLangFile(char *filename) { char *p, *p2, t; p = strrchr(filename, '.'); - if (p) - { + if (p) { t = *p; *p = 0; } p2 = strrchr(filename, '\\'); - if (p2) - { + if (p2) { p2++; nlf->m_szName = (char*)malloc(strlen(p2)+1); strcpy(nlf->m_szName, p2); } - else - { + else { nlf->m_szName = (char*)malloc(strlen(filename)+1); strcpy(nlf->m_szName, filename); } if (p) *p = t; - if (nlf_version != NLF_VERSION) - { + if (nlf_version != NLF_VERSION) { warning_fl("%s language file version doesn't match. Using default English texts for missing strings.", nlf->m_szName); } int temp; // Get font - nlf->m_szFont = NULL; - nlf->m_iFontSize = 0; - buf[0] = SkipComments(f); fgets(buf+1, NSIS_MAX_STRLEN, f); - temp=strlen(buf); - while (buf[temp-1] == '\n' || buf[temp-1] == '\r') { - buf[temp-1] = 0; - temp--; - } - if (buf[0] != '-' && buf [1] != 0) { - nlf->m_szFont = (char*)malloc(strlen(buf)+1);; - strcpy(nlf->m_szFont, buf); + if (!nlf->m_szFont) { + temp=strlen(buf); + while (buf[temp-1] == '\n' || buf[temp-1] == '\r') { + buf[temp-1] = 0; + temp--; + } + if (buf[0] != '-' || buf[1] != 0) { + nlf->m_szFont = (char*)malloc(strlen(buf)+1); + strcpy(nlf->m_szFont, buf); + } } buf[0] = SkipComments(f); fgets(buf+1, NSIS_MAX_STRLEN, f); - if (buf[0] != '-' && buf [1] != 0) { - nlf->m_iFontSize = atoi(buf); + if (!nlf->m_iFontSize) { + if (buf[0] != '-' || buf[1] != 0) { + nlf->m_iFontSize = atoi(buf); + } } // Get code page nlf->m_uCodePage = CP_ACP; buf[0] = SkipComments(f); fgets(buf+1, NSIS_MAX_STRLEN, f); - if (buf[0] != '-' && buf [1] != 0) { + if (buf[0] != '-' || buf[1] != 0) { nlf->m_uCodePage = atoi(buf); if (!IsValidCodePage(nlf->m_uCodePage)) nlf->m_uCodePage = CP_ACP; diff --git a/Source/script.cpp b/Source/script.cpp index 4c23d371..aa101379 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -1778,58 +1778,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return make_sure_not_in_secorfunc(line.gettoken_str(0)); case TOK_WINDOWICON: #ifdef NSIS_CONFIG_VISIBLE_SUPPORT - // Changed by Amir Szekely 30th July 2002 - try { - int k=line.gettoken_enum(1,"on\0off\0"); - if (k == -1) PRINTHELP(); - SCRIPT_MSG("WindowIcon: %s\n",line.gettoken_str(1)); - - if (!k) return make_sure_not_in_secorfunc(line.gettoken_str(0)); - - init_res_editor(); - -#define REMOVE_ICON(id) { \ - BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); \ - if (!dlg) throw runtime_error(#id " doesn't exist!"); \ - CDialogTemplate dt(dlg,uDefCodePage); \ - free(dlg); \ - dt.RemoveItem(IDC_ULICON); \ - DialogItemTemplate* text = dt.GetItem(IDC_INTROTEXT); \ - DialogItemTemplate* prog = dt.GetItem(IDC_PROGRESS); \ - if (text) { \ - text->sWidth += text->sX; \ - text->sX = 0; \ - } \ - if (prog) { \ - prog->sWidth += prog->sX; \ - prog->sX = 0; \ - } \ - \ - DWORD dwSize; \ - dlg = dt.Save(dwSize); \ - res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), dlg, dwSize); \ - free(dlg); \ - } - -#ifdef NSIS_CONFIG_LICENSEPAGE - REMOVE_ICON(IDD_LICENSE); -#endif - REMOVE_ICON(IDD_DIR); -#ifdef NSIS_CONFIG_COMPONENTPAGE - REMOVE_ICON(IDD_SELCOM); -#endif - REMOVE_ICON(IDD_INSTFILES); -#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT - REMOVE_ICON(IDD_UNINST); -#endif -#ifdef NSIS_CONFIG_CRC_SUPPORT - REMOVE_ICON(IDD_VERIFY); -#endif - } - catch (exception& err) { - ERROR_MSG("Error removing window icon: %s\n", err.what()); - return PS_ERROR; - } + disable_window_icon=line.gettoken_enum(1,"on\0off\0"); + if (disable_window_icon == -1) PRINTHELP(); + SCRIPT_MSG("WindowIcon: %s\n",line.gettoken_str(1)); return make_sure_not_in_secorfunc(line.gettoken_str(0)); #else ERROR_MSG("Error: %s specified, NSIS_CONFIG_VISIBLE_SUPPORT not defined.\n",line.gettoken_str(0)); @@ -2186,43 +2137,25 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } return make_sure_not_in_secorfunc(line.gettoken_str(0)); case TOK_SETFONT: - SCRIPT_MSG("SetFont: \"%s\" %s\n", line.gettoken_str(1), line.gettoken_str(2)); - try { - init_res_editor(); + { + if (!strnicmp(line.gettoken_str(1), "/LANG=", 6)) + { + LANGID lang_id = atoi(line.gettoken_str(1) + 6); + LanguageTable *table = GetLangTable(lang_id); + table->nlf.m_szFont = (char*)malloc(strlen(line.gettoken_str(2))+1); + strcpy(table->nlf.m_szFont, line.gettoken_str(2)); + table->nlf.m_iFontSize = line.gettoken_int(3); -#define SET_FONT(id) { \ - BYTE* dlg = res_editor->GetResource(RT_DIALOG, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); \ - if (!dlg) throw runtime_error(#id " doesn't exist!"); \ - CDialogTemplate td(dlg,uDefCodePage); \ - free(dlg); \ - td.SetFont(line.gettoken_str(1), line.gettoken_int(2)); \ - DWORD dwSize; \ - dlg = td.Save(dwSize); \ - res_editor->UpdateResource(RT_DIALOG, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), dlg, dwSize); \ - free(dlg); \ - } + SCRIPT_MSG("SetFont: lang=%d \"%s\" %s\n", lang_id, line.gettoken_str(2), line.gettoken_str(3)); + } + else + { + strncpy(build_font, line.gettoken_str(1), sizeof(build_font)); + build_font_size = line.gettoken_int(2); -#ifdef NSIS_CONFIG_LICENSEPAGE - SET_FONT(IDD_LICENSE); -#endif - SET_FONT(IDD_DIR); -#ifdef NSIS_CONFIG_COMPONENTPAGE - SET_FONT(IDD_SELCOM); -#endif - SET_FONT(IDD_INST); - SET_FONT(IDD_INSTFILES); -#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT - SET_FONT(IDD_UNINST); -#endif -#ifdef NSIS_CONFIG_CRC_SUPPORT - SET_FONT(IDD_VERIFY); -#endif -#undef SET_FONT - } - catch (exception& err) { - ERROR_MSG("Error while changing font: %s\n", err.what()); - return PS_ERROR; + SCRIPT_MSG("SetFont: \"%s\" %s\n", line.gettoken_str(1), line.gettoken_str(2)); } + } return make_sure_not_in_secorfunc(line.gettoken_str(0)); #else case TOK_INSTCOLORS: @@ -5204,9 +5137,6 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn // overwrite flag can be 0, 1, 2 or 3. in all cases, 2 bits ent.offsets[0] |= ((build_allowskipfiles ? MB_ABORTRETRYIGNORE : MB_RETRYCANCEL) | MB_ICONSTOP) << 2; ent.offsets[5] = DefineInnerLangString(build_allowskipfiles ? NLF_FILE_ERROR : NLF_FILE_ERROR_NOIGNORE); - - if (uninstall_mode) m_uninst_fileused++; - else m_inst_fileused++; } CloseHandle(hFile); diff --git a/Source/tokens.cpp b/Source/tokens.cpp index efb42bf1..4a79c348 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -161,7 +161,7 @@ static tokenType tokenlist[TOK__LAST] = {TOK_SETDETAILSPRINT,"SetDetailsPrint",1,0,"(none|listonly|textonly|both)"}, {TOK_SETERRORS,"SetErrors",0,0,""}, {TOK_SETFILEATTRIBUTES,"SetFileAttributes",2,0,"file attribute[|attribute[...]]\n attribute=(NORMAL|ARCHIVE|HIDDEN|OFFLINE|READONLY|SYSTEM|TEMPORARY|0)"}, -{TOK_SETFONT,"SetFont",2,0,"font_face_name font_size"}, +{TOK_SETFONT,"SetFont",2,1,"[/LANG=lang_id] font_face_name font_size"}, {TOK_SETOUTPATH,"SetOutPath",1,0,"output_path"}, {TOK_SETOVERWRITE,"SetOverwrite",1,0,"(on|off|try|ifnewer)"}, {TOK_SETPLUGINUNLOAD,"SetPluginUnload",1,0,"(manual|alwaysoff)"},