From f1c873ba3659ce32342419b11fa84948a302b8e1 Mon Sep 17 00:00:00 2001 From: kichik Date: Sat, 14 Apr 2007 23:03:40 +0000 Subject: [PATCH] implemented RFE #1564986 - block unsupported language git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5080 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/LangDLL/LangDLL.c | 40 ++++++++++++++++++++++++++++-------- Contrib/Modern UI/System.nsh | 6 +++--- Source/script.cpp | 4 ++++ 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/Contrib/LangDLL/LangDLL.c b/Contrib/LangDLL/LangDLL.c index fe838720..afa4b3aa 100644 --- a/Contrib/LangDLL/LangDLL.c +++ b/Contrib/LangDLL/LangDLL.c @@ -20,12 +20,14 @@ HWND g_hwndParent; char temp[1024]; char g_wndtitle[1024], g_wndtext[1024]; int dofont; +int docp; int langs_num; struct lang { char *name; char *id; + UINT cp; } *langs; BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) @@ -37,7 +39,12 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_INITDIALOG: // add languages for (i = langs_num - 1; i >= 0; i--) { - int cbi = SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_ADDSTRING, 0, (LPARAM) langs[i].name); + int cbi; + + if (langs[i].cp != 0 && langs[i].cp != GetACP()) + continue; + + cbi = SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_ADDSTRING, 0, (LPARAM) langs[i].name); SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_SETITEMDATA, cbi, (LPARAM) langs[i].id); // remember selected language @@ -123,6 +130,18 @@ void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size, // get flags if (popstring(temp)) return; + + // parse flags + { + char *p=temp; + while (*p) + { + if (*p == 'F') dofont=1; // parse font flag + if (*p == 'C') docp=1; // parse codepage flag + p++; + } + } + if (*temp == 'A') { // automatic language count stack_t *th; @@ -133,19 +152,18 @@ void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size, th = th->next; } if (!th) return; - langs_num /= 2; + if (dofont) + langs_num -= 2; + if (docp) + langs_num /= 3; + else + langs_num /= 2; pop_empty_string = TRUE; } else { // use counts languages langs_num = myatoi(temp); } - { - // parse font flag - char *p=temp; - while (*p) if (*p++ == 'F') dofont=1; - } - // zero languages? if (!langs_num) return; @@ -164,6 +182,12 @@ void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size, langs[i].id = GlobalAlloc(GPTR, lstrlen(temp)+1); if (!langs[i].id) return; lstrcpy(langs[i].id, temp); + + if (docp) + { + if (popstring(temp)) return; + langs[i].cp = myatoi(temp); + } } // pop the empty string to keep the stack clean diff --git a/Contrib/Modern UI/System.nsh b/Contrib/Modern UI/System.nsh index 3e40cc58..140effa4 100644 --- a/Contrib/Modern UI/System.nsh +++ b/Contrib/Modern UI/System.nsh @@ -2051,7 +2051,7 @@ Var /GLOBAL MUI_TEMP2 !endif - LangDLL::LangDialog "${MUI_LANGDLL_WINDOWTITLE}" "${MUI_LANGDLL_INFO}" A ${MUI_LANGDLL_PUSHLIST} "" + LangDLL::LangDialog "${MUI_LANGDLL_WINDOWTITLE}" "${MUI_LANGDLL_INFO}" AC ${MUI_LANGDLL_PUSHLIST} "" Pop $LANGUAGE StrCmp $LANGUAGE "cancel" 0 +2 @@ -2230,14 +2230,14 @@ Var /GLOBAL MUI_TEMP2 !insertmacro MUI_LANGUAGEFILE_DEFINE "MUI_${LANGUAGE}_LANGNAME" "MUI_LANGNAME" !ifndef MUI_LANGDLL_PUSHLIST - !define MUI_LANGDLL_PUSHLIST "'${MUI_${LANGUAGE}_LANGNAME}' ${LANG_${LANGUAGE}} " + !define MUI_LANGDLL_PUSHLIST "'${MUI_${LANGUAGE}_LANGNAME}' '${LANG_${LANGUAGE}}' '${LANG_${LANGUAGE}_CP}' " !else !ifdef MUI_LANGDLL_PUSHLIST_TEMP !undef MUI_LANGDLL_PUSHLIST_TEMP !endif !define MUI_LANGDLL_PUSHLIST_TEMP "${MUI_LANGDLL_PUSHLIST}" !undef MUI_LANGDLL_PUSHLIST - !define MUI_LANGDLL_PUSHLIST "'${MUI_${LANGUAGE}_LANGNAME}' ${LANG_${LANGUAGE}} ${MUI_LANGDLL_PUSHLIST_TEMP}" + !define MUI_LANGDLL_PUSHLIST "'${MUI_${LANGUAGE}_LANGNAME}' '${LANG_${LANGUAGE}}' '${LANG_${LANGUAGE}_CP}' ${MUI_LANGDLL_PUSHLIST_TEMP}" !endif !insertmacro MUI_LANGUAGEFILE_LANGSTRING_PAGE WELCOME "MUI_TEXT_WELCOME_INFO_TITLE" diff --git a/Source/script.cpp b/Source/script.cpp index 8cf62405..d19af77a 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -2735,10 +2735,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) // define LANG_LangName as "####" (lang id) // for example ${LANG_ENGLISH} = 1033 char lang_id[16]; + char lang_cp[16]; char lang_name[1024]; wsprintf(lang_name, "LANG_%s", table->nlf.m_szName); wsprintf(lang_id, "%u", table->lang_id); + wsprintf(lang_cp, "%u", table->nlf.m_uCodePage); definedlist.add(lang_name, lang_id); + wsprintf(lang_name, "LANG_%s_CP", table->nlf.m_szName); + definedlist.add(lang_name, lang_cp); } return PS_OK;