Debian Codegraph @

Source/lang.cpp

raw
1 /*
2 * lang.cpp
3 *
4 * This file is a part of NSIS.
5 *
6 * Copyright (C) 1999-2026 Nullsoft and Contributors
7 *
8 * Licensed under the zlib/libpng license (the "License");
9 * you may not use this file except in compliance with the License.
10 *
11 * Licence details can be found in the file COPYING.
12 *
13 * This software is provided 'as-is', without any express or implied
14 * warranty.
15 *
16 * Unicode support and Doxygen comments by Jim Park -- 07/25/2007
17 */
18
19 #include "Platform.h"
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include "tchar.h"
23 #include "build.h"
24 #include "util.h"
25 #include "DialogTemplate.h"
26 #include "exehead/resource.h"
27 #include <nsis-version.h>
28 #include "tstring.h"
29 #include "utf.h"
30
31 using namespace std;
32
33 // Default English strings. Should match NSIS_DEFAULT_LANG
34 // Do not change the first string in every item, it's the LangString
35 // name for usage in scripts.
36
37 typedef enum {
38 NONE_STATIC = 0,
39 INSTALL_STATIC = 1,
40 UNINSTALL_STATIC = 2,
41 BOTH_STATIC = 3
42 } STATICID;
43
44 struct NLFString {
45 const TCHAR *szLangStringName;
46 const TCHAR *szDefault;
47 STATICID eStaticID;
48 };
49
50 NLFString NLFStrings[NLF_STRINGS] = {
51 {_T("^Branding"), _T("Nullsoft Install System %s"), BOTH_STATIC},
52 {_T("^SetupCaption"), _T("$(^Name) Setup"), INSTALL_STATIC},
53 {_T("^UninstallCaption"), _T("$(^Name) Uninstall"), UNINSTALL_STATIC},
54 {_T("^LicenseSubCaption"), _T(": License Agreement"), NONE_STATIC},
55 {_T("^ComponentsSubCaption"), _T(": Installation Options"), NONE_STATIC},
56 {_T("^DirSubCaption"), _T(": Installation Folder"), NONE_STATIC},
57 {_T("^InstallingSubCaption"), _T(": Installing"), NONE_STATIC},
58 {_T("^CompletedSubCaption"), _T(": Completed"), NONE_STATIC},
59 {_T("^UnComponentsSubCaption"), _T(": Uninstallation Options"), NONE_STATIC},
60 {_T("^UnDirSubCaption"), _T(": Uninstallation Folder"), NONE_STATIC},
61 {_T("^ConfirmSubCaption"), _T(": Confirmation"), NONE_STATIC},
62 {_T("^UninstallingSubCaption"), _T(": Uninstalling"), NONE_STATIC},
63 {_T("^UnCompletedSubCaption"), _T(": Completed"), NONE_STATIC},
64 {_T("^BackBtn"), _T("< &Back"), NONE_STATIC},
65 {_T("^NextBtn"), _T("&Next >"), NONE_STATIC},
66 {_T("^AgreeBtn"), _T("I &Agree"), NONE_STATIC},
67 {_T("^AcceptBtn"), _T("I &accept the terms of the License Agreement"), NONE_STATIC},
68 {_T("^DontAcceptBtn"), _T("I &do not accept the terms of the License Agreement"), NONE_STATIC},
69 {_T("^InstallBtn"), _T("&Install"), NONE_STATIC},
70 {_T("^UninstallBtn"), _T("&Uninstall"), NONE_STATIC},
71 {_T("^CancelBtn"), _T("Cancel"), NONE_STATIC},
72 {_T("^CloseBtn"), _T("&Close"), NONE_STATIC},
73 {_T("^BrowseBtn"), _T("B&rowse..."), NONE_STATIC},
74 {_T("^ShowDetailsBtn"), _T("Show &details"), NONE_STATIC},
75 {_T("^ClickNext"), _T("Click Next to continue."), NONE_STATIC},
76 {_T("^ClickInstall"), _T("Click Install to start the installation."), NONE_STATIC},
77 {_T("^ClickUninstall"), _T("Click Uninstall to start the uninstallation."), NONE_STATIC},
78 {_T("^Name"), _T("Name"), BOTH_STATIC},
79 {_T("^NameDA"), 0, NONE_STATIC}, // virtual
80 {_T("^Completed"), _T("Completed"), NONE_STATIC},
81 {_T("^LicenseText"), _T("Please review the license agreement before installing $(^NameDA). If you accept all terms of the agreement, click I Agree."), NONE_STATIC},
82 {_T("^LicenseTextCB"), _T("Please review the license agreement before installing $(^NameDA). If you accept all terms of the agreement, click the check box below. $_CLICK"), NONE_STATIC},
83 {_T("^LicenseTextRB"), _T("Please review the license agreement before installing $(^NameDA). If you accept all terms of the agreement, select the first option below. $_CLICK"), NONE_STATIC},
84 {_T("^UnLicenseText"), _T("Please review the license agreement before uninstalling $(^NameDA). If you accept all terms of the agreement, click I Agree."), NONE_STATIC},
85 {_T("^UnLicenseTextCB"), _T("Please review the license agreement before uninstalling $(^NameDA). If you accept all terms of the agreement, click the check box below. $_CLICK"), NONE_STATIC},
86 {_T("^UnLicenseTextRB"), _T("Please review the license agreement before uninstalling $(^NameDA). If you accept all terms of the agreement, select the first option below. $_CLICK"), NONE_STATIC},
87 {_T("^LicenseData"), 0, NONE_STATIC}, // virtual - not processed
88 {_T("^Custom"), _T("Custom"), NONE_STATIC},
89 {_T("^ComponentsText"), _T("Check the components you want to install and uncheck the components you don't want to install. $_CLICK"), NONE_STATIC},
90 {_T("^ComponentsSubText1"), _T("Select the type of install:"), NONE_STATIC},
91 {_T("^ComponentsSubText2_NoInstTypes"), _T("Select components to install:"), NONE_STATIC},
92 {_T("^ComponentsSubText2"), _T("Or, select the optional components you wish to install:"), NONE_STATIC},
93 {_T("^UnComponentsText"), _T("Check the components you want to uninstall and uncheck the components you don't want to uninstall. $_CLICK"), NONE_STATIC},
94 {_T("^UnComponentsSubText1"), _T("Select the type of uninstall:"), NONE_STATIC},
95 {_T("^UnComponentsSubText2_NoInstTypes"), _T("Select components to uninstall:"), NONE_STATIC},
96 {_T("^UnComponentsSubText2"), _T("Or, select the optional components you wish to uninstall:"), NONE_STATIC},
97 {_T("^DirText"), _T("Setup will install $(^NameDA) in the following folder. To install in a different folder, click Browse and select another folder. $_CLICK"), NONE_STATIC},
98 {_T("^DirSubText"), _T("Destination Folder"), NONE_STATIC},
99 {_T("^DirBrowseText"), _T("Select the folder to install $(^NameDA) in:"), NONE_STATIC},
100 {_T("^UnDirText"), _T("Setup will uninstall $(^NameDA) from the following folder. To uninstall from a different folder, click Browse and select another folder. $_CLICK"), NONE_STATIC},
101 {_T("^UnDirSubText"), _T(""), NONE_STATIC},
102 {_T("^UnDirBrowseText"), _T("Select the folder to uninstall $(^NameDA) from:"), NONE_STATIC},
103 {_T("^SpaceAvailable"), _T("Space available: "), BOTH_STATIC},
104 {_T("^SpaceRequired"), _T("Space required: "), BOTH_STATIC},
105 {_T("^UninstallingText"), _T("This wizard will uninstall $(^NameDA) from your computer. $_CLICK"), NONE_STATIC},
106 {_T("^UninstallingSubText"), _T("Uninstalling from:"), NONE_STATIC},
107 {_T("^FileError"), _T("Error opening file for writing: \r\n\r\n$0\r\n\r\nClick Abort to stop the installation,\r\nRetry to try again, or\r\nIgnore to skip this file."), NONE_STATIC},
108 {_T("^FileError_NoIgnore"), _T("Error opening file for writing: \r\n\r\n$0\r\n\r\nClick Retry to try again, or\r\nCancel to stop the installation."), NONE_STATIC},
109 {_T("^CantWrite"), _T("Can't write: "), BOTH_STATIC},
110 {_T("^CopyFailed"), _T("Copy failed"), BOTH_STATIC},
111 {_T("^CopyTo"), _T("Copy to "), BOTH_STATIC},
112 {_T("^Registering"), _T("Registering: "), NONE_STATIC},
113 {_T("^Unregistering"), _T("Unregistering: "), NONE_STATIC},
114 {_T("^SymbolNotFound"), _T("Could not find symbol: "), BOTH_STATIC},
115 {_T("^CouldNotLoad"), _T("Could not load: "), BOTH_STATIC},
116 {_T("^CreateFolder"), _T("Create folder: "), BOTH_STATIC},
117 {_T("^CreateShortcut"), _T("Create shortcut: "), BOTH_STATIC},
118 {_T("^CreatedUninstaller"), _T("Created uninstaller: "), BOTH_STATIC},
119 {_T("^Delete"), _T("Delete file: "), BOTH_STATIC},
120 {_T("^DeleteOnReboot"), _T("Delete on reboot: "), BOTH_STATIC},
121 {_T("^ErrorCreatingShortcut"), _T("Error creating shortcut: "), BOTH_STATIC},
122 {_T("^ErrorCreating"), _T("Error creating: "), BOTH_STATIC},
123 {_T("^ErrorDecompressing"), _T("Error decompressing data! Corrupted installer?"), BOTH_STATIC},
124 {_T("^ErrorRegistering"), _T("Error registering DLL"), BOTH_STATIC},
125 {_T("^ExecShell"), _T("ExecShell: "), BOTH_STATIC},
126 {_T("^Exec"), _T("Execute: "), BOTH_STATIC},
127 {_T("^Extract"), _T("Extract: "), BOTH_STATIC},
128 {_T("^ErrorWriting"), _T("Extract: error writing to file "), BOTH_STATIC},
129 {_T("^InvalidOpcode"), _T("Installer corrupted: invalid opcode"), BOTH_STATIC},
130 {_T("^NoOLE"), _T("No OLE for: "), BOTH_STATIC},
131 {_T("^OutputFolder"), _T("Output folder: "), BOTH_STATIC},
132 {_T("^RemoveFolder"), _T("Remove folder: "), BOTH_STATIC},
133 {_T("^RenameOnReboot"), _T("Rename on reboot: "), BOTH_STATIC},
134 {_T("^Rename"), _T("Rename: "), BOTH_STATIC},
135 {_T("^Skipped"), _T("Skipped: "), BOTH_STATIC},
136 {_T("^CopyDetails"), _T("Copy Details To Clipboard"), BOTH_STATIC},
137 {_T("^LogInstall"), _T("Log install process"), BOTH_STATIC},
138 {_T("^Byte"), _T("B"), BOTH_STATIC},
139 {_T("^Kilo"), _T(" K"), BOTH_STATIC},
140 {_T("^Mega"), _T(" M"), BOTH_STATIC},
141 {_T("^Giga"), _T(" G"), BOTH_STATIC},
142 {_T("^Font"), _T("MS Shell Dlg"), NONE_STATIC},
143 {_T("^FontSize"), _T("8"), NONE_STATIC},
144 {_T("^RTL"), _T("0"), NONE_STATIC},
145 {_T("^Language"), _T("English"), NONE_STATIC}
146 };
147
148 // ==============
149 // LangStringList
150 // ==============
151
152
153 int LangStringList::add(const TCHAR *name, int *sn/*=0*/)
154 {
155 int pos = SortedStringListND<struct langstring>::add(name);
156 if (pos == -1) return -1;
157
158 langstring* lstrPtr = (langstring*)(m_gr.get()) + pos;
159 lstrPtr->sn = m_count;
160 if (sn) *sn = m_count;
161 m_count++;
162 lstrPtr->index = -1;
163 lstrPtr->uindex = -1;
164 lstrPtr->process = 1;
165
166 return pos;
167 }
168
169 int LangStringList::get(const TCHAR *name, int *sn/*=0*/, int *index/*=0*/, int *uindex/*=0*/, int *process/*=0*/)
170 {
171 if (index) *index = -1;
172 if (uindex) *uindex = -1;
173 if (sn) *sn = -1;
174 int v=find(name);
175 if (v==-1) return -1;
176 langstring* lstrPtr = (langstring*)(m_gr.get()) + v;
177 if (index) *index = lstrPtr->index;
178 if (uindex) *uindex = lstrPtr->uindex;
179 if (sn) *sn = lstrPtr->sn;
180 if (process) *process = lstrPtr->process;
181 return v;
182 }
183
184 void LangStringList::set(int pos, int index/*=-1*/, int uindex/*=-1*/, int process/*=-1*/)
185 {
186 if ((unsigned int)pos > (m_gr.getlen() / sizeof(struct langstring)))
187 return;
188
189 struct langstring *data=((struct langstring *) m_gr.get()) + pos;
190
191 if (index >= 0) data->index = index;
192 if (uindex >= 0) data->uindex = uindex;
193 if (process >= 0) data->process = process;
194 }
195
196 void LangStringList::set(const TCHAR *name, int index, int uindex/*=-1*/, int process/*=-1*/)
197 {
198 set(find(name), index, uindex, process);
199 }
200
201 const TCHAR* LangStringList::pos2name(int pos)
202 {
203 struct langstring *data=(struct langstring *) m_gr.get();
204
205 if (pos < 0 || (unsigned int)pos > (m_gr.getlen() / sizeof(struct langstring)))
206 return 0;
207
208 return ((const TCHAR*) m_strings.get() + data[pos].name);
209 }
210
211 const TCHAR* LangStringList::offset2name(int name)
212 {
213 if (name < 0 || (unsigned int)name > m_strings.getlen()/sizeof(TCHAR))
214 return 0;
215
216 return (const TCHAR*) m_strings.get() + name;
217 }
218
219 int LangStringList::getnum()
220 {
221 return m_gr.getlen() / sizeof(struct langstring);
222 }
223
224 int LangStringList::compare_index(const void *item1, const void *item2)
225 {
226 struct langstring *ls1 = (struct langstring *)item1;
227 struct langstring *ls2 = (struct langstring *)item2;
228
229 return ls1->index - ls2->index;
230 }
231
232 langstring* LangStringList::sort_index(int *num)
233 {
234 if (!num) return 0;
235 m_sortbuf.resize(0);
236 m_sortbuf.add(m_gr.get(), m_gr.getlen());
237 *num = m_sortbuf.getlen() / sizeof(struct langstring);
238 qsort(m_sortbuf.get(), *num, sizeof(struct langstring), compare_index);
239 return (struct langstring*) m_sortbuf.get();
240 }
241
242 int LangStringList::compare_uindex(const void *item1, const void *item2)
243 {
244 struct langstring *ls1 = (struct langstring *)item1;
245 struct langstring *ls2 = (struct langstring *)item2;
246
247 return ls1->uindex - ls2->uindex;
248 }
249
250 langstring* LangStringList::sort_uindex(int *num)
251 {
252 if (!num) return 0;
253 m_sortbuf.resize(0);
254 m_sortbuf.add(m_gr.get(), m_gr.getlen());
255 *num = m_sortbuf.getlen() / sizeof(struct langstring);
256 qsort(m_sortbuf.get(), *num, sizeof(struct langstring), compare_uindex);
257 return (struct langstring*) m_sortbuf.get();
258 }
259
260 // ============
261 // StringsArray
262 // ============
263
264 StringsArray::StringsArray()
265 {
266 // We make zero an invalid index. Using 0 will get back an empty string.
267 m_offsets.set_zeroing(1);
268
269 m_strings.add(_T(""), sizeof(_T("")));
270 }
271
272 void StringsArray::resize(int num)
273 {
274 m_offsets.resize(num * sizeof(int));
275 }
276
277 int StringsArray::set(int idx, const TCHAR *str)
278 {
279 if (idx < 0)
280 return 0;
281
282 if (idx >= (int)(m_offsets.getlen() / sizeof(int)))
283 resize(idx+1);
284
285 int old = ((int*) m_offsets.get())[idx];
286
287 // Need to store the TCHAR index so we divide the return value of add by sizeof(TCHAR).
288 ((int*)m_offsets.get())[idx] = m_strings.add(str, (DWORD)(_tcslen(str)+1)*sizeof(TCHAR))/sizeof(TCHAR);
289
290 return old;
291 }
292
293 const TCHAR* StringsArray::get(int idx)
294 {
295 if (idx < 0 || (unsigned int)idx >= (m_offsets.getlen() / sizeof(int)))
296 return 0;
297
298 return (const TCHAR *) m_strings.get() + ((int*) m_offsets.get())[idx];
299 }
300
301 // =========
302 // CEXEBuild
303 // =========
304
305 void CEXEBuild::InitLangTables() {
306 keep_ref = false;
307
308 for (int i = 0; i < NLF_STRINGS; i++) {
309 NLFRefs[i].iRef = 0;
310 NLFRefs[i].iUnRef = 0;
311
312 #ifdef NSIS_CONFIG_LOG
313 if (i == NLF_NAME) {
314 NLFRefs[i].iRef++;
315 NLFRefs[i].iUnRef++;
316 }
317 #endif
318
319 if (NLFStrings[i].eStaticID & INSTALL_STATIC) {
320 set_uninstall_mode(0);
321 DefineLangString(NLFStrings[i].szLangStringName);
322 }
323
324 #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
325 if (NLFStrings[i].eStaticID & UNINSTALL_STATIC) {
326 set_uninstall_mode(1);
327 DefineLangString(NLFStrings[i].szLangStringName);
328 }
329 #endif
330 }
331
332 set_uninstall_mode(0);
333
334 keep_ref = true;
335 }
336
337 //////////////////////////////////////////////////////////////////////////////
338 // class CEXEBuild
339 //
340 // Note: The functions below refer to the methods related to Languages.
341 //////////////////////////////////////////////////////////////////////////////
342
343 LanguageTable* CEXEBuild::GetLangTable(LANGID &lang, bool create/*=true*/) {
344 int nlt = lang_tables.getlen() / sizeof(LanguageTable);
345 LanguageTable *nla = (LanguageTable*)lang_tables.get();
346
347 lang = lang ? lang : last_used_lang;
348 LanguageTable *table = NULL;
349
350 for (int i = 0; i < nlt; i++) {
351 if (lang == nla[i].lang_id) {
352 table = &nla[i];
353 break;
354 }
355 }
356 if (!table && create) {
357 LanguageTable newtable;
358
359 newtable.lang_id = lang;
360 newtable.dlg_offset = 0;
361 memset(&newtable.nlf, 0, sizeof(NLF));
362
363 newtable.lang_strings = new StringsArray;
364
365 lang_tables.add(&newtable, sizeof(LanguageTable));
366 table = (LanguageTable*)lang_tables.get() + nlt;
367 }
368
369 if (table) // update last used language if a table was loaded
370 last_used_lang = lang;
371
372 return table;
373 }
374
375 const TCHAR *CEXEBuild::GetLangNameAndCP(LANGID lang, unsigned int *codepage/*=NULL*/) {
376 LanguageTable *table = GetLangTable(lang, false);
377
378 if (table && table->nlf.m_bLoaded) {
379 if (codepage)
380 *codepage = table->nlf.m_uCodePage;
381
382 return table->nlf.m_szName;
383 }
384 else {
385 // If the language table does not exist, then we default to Unicode or ANSI
386 // depending on the target installer type
387 if (codepage)
388 *codepage = build_unicode ? 1200 : 1252; // Unicode or CP1252
389
390 if (lang == 1033)
391 return _T("English");
392 else
393 return _T("???");
394 }
395 }
396
397 const TCHAR *CEXEBuild::GetLangNameAndCPForVersionResource(LANGID &lang, unsigned int *codepage/*=NULL*/, bool deflangfallback/*=true*/) {
398 const TCHAR *langname = GetLangNameAndCP(lang, codepage);
399 if (0 == lang) {
400 if (deflangfallback)
401 lang = last_used_lang;
402 else
403 langname = _T("Neutral");
404 }
405 return langname;
406 }
407
408 int CEXEBuild::DefineLangString(const TCHAR *name, int process/*=-1*/) {
409 int index, uindex, pos, ret, sn;
410
411 /* If not exist, index and uindex will get -1. */
412 pos = build_langstrings.get(name, &sn, &index, &uindex);
413 if (pos < 0) {
414 pos = build_langstrings.add(name);
415 }
416
417 #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
418 if (!this->uninstall_mode) {
419 #endif
420 if (index < 0) {
421 // Did not exist. Increment.
422 index = this->build_langstring_num++;
423 }
424 ret = -index - 1;
425 #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
426 }
427 else {
428 if (uindex < 0) {
429 // Did not exist. Increment.
430 uindex = this->ubuild_langstring_num++;
431 }
432 ret = -uindex - 1;
433 }
434 #endif
435
436 // Now set the new index and uindex values with the
437 // passed in process value.
438 build_langstrings.set(pos, index, uindex, process);
439
440 // set reference count for NLF strings
441 if (this->keep_ref && name[0] == _T('^')) {
442 for (int i = 0; i < NLF_STRINGS; i++) {
443 if (!_tcscmp(name, NLFStrings[i].szLangStringName)) {
444 #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
445 if (this->uninstall_mode)
446 this->NLFRefs[i].iUnRef++;
447 else
448 #endif
449 this->NLFRefs[i].iRef++;
450
451 break;
452 }
453 }
454 }
455
456 return ret;
457 }
458
459 int CEXEBuild::DefineInnerLangString(int id, int process/*=-1*/) {
460 bool old_keep_ref = keep_ref;
461
462 // set reference count for NLF strings
463 if (keep_ref) {
464 #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
465 if (uninstall_mode)
466 NLFRefs[id].iUnRef++;
467 else
468 #endif
469 NLFRefs[id].iRef++;
470
471 keep_ref = false;
472 }
473
474 int ret = DefineLangString(NLFStrings[id].szLangStringName, process);
475
476 keep_ref = old_keep_ref;
477
478 return ret;
479 }
480
481 // A LangString is a string variable that varies in value depending on what
482 // language is being used. This function sets the string value for the
483 // variable 'name' for a given language ID.
484 //
485 // @return If the language id, the variable name or string is invalid, it will
486 // return a PS_ERROR. If this function call is overwriting a set user string,
487 // this will return a PS_WARNING.
488 int CEXEBuild::SetLangString(const TCHAR *name, LANGID lang, const TCHAR *str, BOOL LicenseData) {
489 if (!str || !name) return PS_ERROR;
490
491 LanguageTable *table = GetLangTable(lang);
492 if (!table) return PS_ERROR;
493
494 int sn;
495
496 if (!LicenseData && _tcsclen(str) > NSIS_MAX_STRLEN-1)
497 warning_fl(DW_LANGSTRING_OVERLONGLENGTH, _T("LangString \"%") NPRIs _T("\" longer than NSIS_MAX_STRLEN!"), name);
498
499 int pos = build_langstrings.get(name, &sn);
500 if (pos < 0)
501 pos = build_langstrings.add(name, &sn);
502
503 if (table->lang_strings->set(sn, str))
504 return PS_WARNING;
505
506 return PS_OK;
507 }
508
509 int CEXEBuild::SetLangString(const TCHAR *name, LANGID lang, const TCHAR *str)
510 {
511 return SetLangString(name, lang, str, false);
512 }
513
514
515 // Sets the user string to the specific NLF_STRINGS id.
516 //
517 // @return If the id is invalid or the string is not valid, it will return a
518 // PS_ERROR. If this function call is overwriting a set user string, this
519 // will return a PS_WARNING.
520 int CEXEBuild::SetInnerString(int id, const TCHAR *str) {
521 if ((unsigned int)id >= NLF_STRINGS || !str) return PS_ERROR;
522
523 int ret = PS_OK;
524
525 const TCHAR *ps = UserInnerStrings.get(id);
526 if (ps && *ps)
527 ret = PS_WARNING;
528
529 UserInnerStrings.set(id, str);
530
531 return ret;
532 }
533
534 int CEXEBuild::GenerateLangTable(LanguageTable *lt, int num_lang_tables) {
535 // Add all installer language strings
536 int i, j, l, tabsset;
537 struct langstring* lang_strings = NULL;
538 TinyGrowBuf *string_ptrs = new TinyGrowBuf[num_lang_tables];
539
540 tabsset = 1;
541 while (tabsset)
542 {
543 tabsset = 0;
544 for (i = num_lang_tables; i--; )
545 {
546 // Fill in default values for all used language strings that we can
547 FillLanguageTable(&lt[i]);
548 // Make sure the string lists are large enough
549 string_ptrs[i].set_zeroing(1);
550 if (!uninstall_mode)
551 string_ptrs[i].resize(build_langstring_num * sizeof(int));
552 else
553 string_ptrs[i].resize(ubuild_langstring_num * sizeof(int));
554 }
555
556 // For all current language strings
557 if (!uninstall_mode)
558 lang_strings = build_langstrings.sort_index(&l);
559 else
560 lang_strings = build_langstrings.sort_uindex(&l);
561
562 for (j = 0; j < l; j++)
563 {
564 int lang_string_index;
565
566 if (!uninstall_mode)
567 lang_string_index = lang_strings[j].index;
568 else
569 lang_string_index = lang_strings[j].uindex;
570
571 // Is this language string used (in the installer)?
572 if (lang_string_index >= 0)
573 {
574 // For each language
575 for (i = num_lang_tables; i--; )
576 {
577 // Get the current string pointer
578 int *ptr = (int *)string_ptrs[i].get() + lang_string_index;
579 // Not already set?
580 if (!*ptr)
581 {
582 // Get the language string and its name
583 const TCHAR *str = lt[i].lang_strings->get(lang_strings[j].sn);
584 const TCHAR *lsn = build_langstrings.offset2name(lang_strings[j].name);
585 // lsn = variable name, str = value
586 if (!str || !*str)
587 {
588 // No string is defined; give a warning (for user strings only)
589 if (lsn[0] != _T('^'))
590 {
591 if (lt[i].nlf.m_bLoaded)
592 warning(DW_LANGSTRING_NOTSETINLANG, _T("LangString \"%") NPRIs _T("\" is not set in language table of language %") NPRIs, lsn, lt[i].nlf.m_szName);
593 else
594 warning(DW_LANGSTRING_NOTSETINLANG, _T("LangString \"%") NPRIs _T("\" is not set in language table of language %d"), lsn, lt[i].lang_id);
595 }
596 }
597 else
598 {
599 // Add the language string to the string data block
600 TCHAR fn[1024];
601 _stprintf(fn, _T("LangString %") NPRIs, lsn);
602 curfilename = fn;
603 linecnt = lt[i].lang_id;
604 *ptr = add_string(str, lang_strings[j].process, (WORD) lt[i].nlf.m_uCodePage);
605 curfilename = 0;
606 // Indicate that we should check again for any newly referenced language strings
607 tabsset++;
608 }
609 }
610 }
611 }
612 }
613 }
614
615 // Optimize langstrings and check for recursion
616 for (i = num_lang_tables; i--; )
617 {
618 TinyGrowBuf rec;
619 int *lst = (int *)string_ptrs[i].get();
620 int langstring_num = uninstall_mode ? ubuild_langstring_num : build_langstring_num;
621
622 for (j = 0; j < langstring_num; j++)
623 {
624 // Does this string reference another language string directly?
625 while (lst[j] < 0)
626 {
627 // Search through list of language string references
628 for (l = 0; (unsigned int)l < rec.getlen() / sizeof(int); l++)
629 {
630 if (((int*)rec.get())[l] == lst[j])
631 {
632 // We have the index of a recursive language string; now find the name
633 const TCHAR *name = _T("(unnamed)");
634 for (l = 0; l < langstring_num; l++)
635 {
636 int recidx = uninstall_mode ? lang_strings[l].uindex : lang_strings[l].index;
637 if (recidx == j)
638 {
639 name = build_langstrings.offset2name(lang_strings[l].name);
640 }
641 }
642 ERROR_MSG(_T("Error: LangString %") NPRIs _T(" in language %u is recursive!\n"), name, lt->lang_id);
643 delete [] string_ptrs;
644 return PS_ERROR;
645 }
646 }
647 // Add this reference to the list
648 rec.add(&lst[j], sizeof(int));
649 // and dereference it
650 lst[j] = lst[-lst[j] - 1];
651 }
652 rec.resize(0);
653 }
654 }
655
656 // Add language tables into their datablock
657 for (i = num_lang_tables; i--; )
658 {
659 cur_langtables->add(&lt[i].lang_id, sizeof(LANGID));
660 cur_langtables->add(&lt[i].dlg_offset, sizeof(int));
661 int rtl = lt[i].nlf.m_bRTL ? 1 : 0;
662 cur_langtables->add(&rtl, sizeof(int));
663 cur_langtables->add(string_ptrs[i].get(), string_ptrs[i].getlen());
664 string_ptrs[i].resize(0);
665 }
666
667 cur_header->blocks[NB_LANGTABLES].num = num_lang_tables;
668 cur_header->langtable_size = cur_langtables->getlen() / num_lang_tables;
669
670 delete [] string_ptrs;
671
672 return PS_OK;
673 }
674
675 int CEXEBuild::GenerateLangTables() {
676 int i;
677 LanguageTable *lt = (LanguageTable*)lang_tables.get();
678
679 SCRIPT_MSG(_T("Generating language tables... "));
680
681 if (
682 #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
683 ubuild_langstring_num > MAX_CODED ||
684 #endif
685 build_langstring_num > MAX_CODED
686 )
687 {
688 ERROR_MSG(_T("\nError: too many LangStrings. Maximum allowed is %u.\n"), MAX_CODED);
689 return PS_ERROR;
690 }
691
692 // If we have no tables (user didn't set any string and didn't load any NLF) create the default one
693 if (!lang_tables.getlen()) {
694 LANGID lang = NSIS_DEFAULT_LANG;
695 LanguageTable *table = GetLangTable(lang);
696 if (!table) return PS_ERROR;
697
698 lt = (LanguageTable*)lang_tables.get();
699 }
700
701 // Apply default font
702 if (*build_font)
703 {
704 try {
705 init_res_editor();
706
707 #define ADD_FONT(id) { \
708 BYTE* dlg = res_editor->GetResource(RT_DIALOG, id, NSIS_DEFAULT_LANG); \
709 if (dlg) { \
710 CDialogTemplate td(dlg,build_unicode); \
711 res_editor->FreeResource(dlg); \
712 td.SetFont(build_font, (WORD) build_font_size); \
713 DWORD dwSize; \
714 dlg = td.Save(dwSize); \
715 res_editor->UpdateResource(RT_DIALOG, id, NSIS_DEFAULT_LANG, dlg, dwSize); \
716 td.FreeSavedTemplate(dlg); \
717 } \
718 }
719
720 #ifdef NSIS_CONFIG_LICENSEPAGE
721 ADD_FONT(IDD_LICENSE);
722 ADD_FONT(IDD_LICENSE_FSRB);
723 ADD_FONT(IDD_LICENSE_FSCB);
724 #endif
725 ADD_FONT(IDD_DIR);
726 #ifdef NSIS_CONFIG_COMPONENTPAGE
727 ADD_FONT(IDD_SELCOM);
728 #endif
729 ADD_FONT(IDD_INST);
730 ADD_FONT(IDD_INSTFILES);
731 #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
732 ADD_FONT(IDD_UNINST);
733 #endif
734 #ifdef NSIS_CONFIG_CRC_SUPPORT
735 ADD_FONT(IDD_VERIFY);
736 #endif
737 #undef ADD_FONT
738 }
739 catch (exception& err) {
740 ERROR_MSG(_T("\nError while applying font: %") NPRIs _T("\n"), CtoTStrParam(err.what()));
741 return PS_ERROR;
742 }
743 }
744
745 // Fill tables with defaults (if needed) and with instruction strings
746 // Create language specific resources (currently only dialogs with different fonts)
747 int num_lang_tables = lang_tables.getlen() / sizeof(LanguageTable);
748 // if there is one string table then there is no need for two sets of dialogs
749 int cur_offset = num_lang_tables == 1 ? 0 : 100;
750 for (i = 0; i < num_lang_tables; i++)
751 {
752 // A Unicode-only language is never displayed correctly by ANSI exehead
753 if (!build_unicode && 1200 == lt[i].nlf.m_uCodePage)
754 {
755 ERROR_MSG(_T("\nError: Unicode-only language %") NPRIs _T(" cannot be used in ANSI installer!\n"), lt[i].nlf.m_szName);
756 return PS_ERROR;
757 }
758
759 if ((lt[i].nlf.m_szFont && !*build_font) || lt[i].nlf.m_bRTL)
760 {
761 lt[i].dlg_offset = cur_offset;
762
763 TCHAR *font = lt[i].nlf.m_szFont;
764 if (*build_font) font = 0;
765
766 try {
767 init_res_editor();
768
769 #define ADD_FONT(id) { \
770 BYTE* dlg = res_editor->GetResource(RT_DIALOG, id, NSIS_DEFAULT_LANG); \
771 if (dlg) { \
772 CDialogTemplate td(dlg,build_unicode,lt[i].nlf.m_uCodePage); \
773 res_editor->FreeResource(dlg); \
774 if (font) td.SetFont(font, (WORD) lt[i].nlf.m_iFontSize); \
775 if (lt[i].nlf.m_bRTL) { \
776 td.ConvertToRTL(); \
777 DialogItemTemplate* dir = td.GetItem(IDC_DIR); \
778 if (id == IDD_DIR && dir) { \
779 if ((dir->dwStyle & ES_CENTER) == 0) dir->dwStyle ^= ES_RIGHT; \
780 dir->dwExtStyle &= ~(WS_EX_RTLREADING | WS_EX_LEFTSCROLLBAR); \
781 } \
782 } \
783 DWORD dwSize; \
784 dlg = td.Save(dwSize); \
785 res_editor->UpdateResource(RT_DIALOG, id+cur_offset, NSIS_DEFAULT_LANG, dlg, dwSize); \
786 td.FreeSavedTemplate(dlg); \
787 } \
788 }
789
790 #ifdef NSIS_CONFIG_LICENSEPAGE
791 ADD_FONT(IDD_LICENSE);
792 ADD_FONT(IDD_LICENSE_FSRB);
793 ADD_FONT(IDD_LICENSE_FSCB);
794 #endif
795 ADD_FONT(IDD_DIR);
796 #ifdef NSIS_CONFIG_COMPONENTPAGE
797 ADD_FONT(IDD_SELCOM);
798 #endif
799 ADD_FONT(IDD_INST);
800 ADD_FONT(IDD_INSTFILES);
801 #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
802 ADD_FONT(IDD_UNINST);
803 #endif
804 #ifdef NSIS_CONFIG_CRC_SUPPORT
805 ADD_FONT(IDD_VERIFY);
806 #endif
807 #undef ADD_FONT
808 }
809 catch (exception& err) {
810 ERROR_MSG(_T("\nError while applying NLF font/RTL: %") NPRIs _T("\n"), CtoTStrParam(err.what()));
811 return PS_ERROR;
812 }
813
814 cur_offset += 100;
815 }
816 }
817
818 const int orig_uninstall_mode = uninstall_mode;
819
820 set_uninstall_mode(0);
821 if (GenerateLangTable(lt, num_lang_tables) != PS_OK)
822 return PS_ERROR;
823
824 #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
825 set_uninstall_mode(1);
826 if (GenerateLangTable(lt, num_lang_tables) != PS_OK)
827 return PS_ERROR;
828 #endif
829
830 set_uninstall_mode(orig_uninstall_mode);
831
832 SCRIPT_MSG(_T("Done!\n"));
833
834 return PS_OK;
835 }
836
837 static void CreatePlatformStrfmt(const TCHAR *templ, TCHAR *out) {
838 // NOTE: Only supports plain %s with no options
839 for ( ;; out++ )
840 {
841 *out = *templ++;
842 if (!*out) break;
843 if (*out == L'%' && *templ == L's')
844 {
845 out++, templ++;
846 size_t cch = my_strncpy(out, NPRIs, -1);
847 out += --cch; // --cch because for loop does out++
848 }
849 }
850 }
851
852 void CEXEBuild::FillLanguageTable(LanguageTable *table) {
853 for (int i = 0; i < NLF_STRINGS; i++) {
854 #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
855 if (!NLFRefs[i].iUnRef && !NLFRefs[i].iRef)
856 continue;
857 #else
858 if (!NLFRefs[i].iRef)
859 continue;
860 #endif
861
862 else if (i == NLF_SPACE_REQ || i == NLF_SPACE_AVAIL)
863 {
864 if (no_space_texts)
865 {
866 continue;
867 }
868 }
869
870 int sn, index;
871 int pos = build_langstrings.get(NLFStrings[i].szLangStringName, &sn, &index);
872 if (pos >= 0) {
873 const TCHAR *str = table->lang_strings->get(sn);
874 if (!str || !*str) {
875 const TCHAR *us = UserInnerStrings.get(i);
876 if (i == NLF_NAME_DA && (!us || !*us))
877 {
878 // if the user didn't set NLF_NAME_DA we set it to $(^Name)
879 table->lang_strings->set(sn, _T("$(^Name)"));
880 }
881 if (us && *us) {
882 table->lang_strings->set(sn, (TCHAR *) us);
883 }
884 else {
885 const TCHAR *dstr = table->nlf.m_szStrings[i] ? table->nlf.m_szStrings[i] : NLFStrings[i].szDefault;
886 if (!dstr)
887 continue;
888 if (i == NLF_BRANDING) {
889 TCHAR temp[NSIS_MAX_STRLEN + sizeof(NSIS_VERSION)], temp2[COUNTOF(temp)];
890 CreatePlatformStrfmt(dstr, temp2); // Change %s to %ls if required
891 _stprintf(temp, temp2, NSIS_VERSION);
892 table->lang_strings->set(sn, temp);
893 continue;
894 }
895 else if (i == NLF_FONT)
896 {
897 TCHAR *font = *build_font ? build_font : table->nlf.m_szFont;
898 if (font)
899 table->lang_strings->set(sn, font);
900 else
901 table->lang_strings->set(sn, dstr);
902 continue;
903 }
904 else if (i == NLF_FONTSIZE)
905 {
906 WORD font_size = *build_font ? (WORD) build_font_size : (WORD) table->nlf.m_iFontSize;
907 if (font_size)
908 {
909 TCHAR temp[64];
910 _stprintf(temp, _T("%d"), font_size);
911 table->lang_strings->set(sn, temp);
912 }
913 else
914 table->lang_strings->set(sn, dstr);
915 continue;
916 }
917 table->lang_strings->set(sn, dstr);
918 }
919 }
920 }
921 }
922 }
923
924 void TrimTrailingNewlines(TCHAR *s) {
925 size_t cch = _tcslen(s);
926 while (s[cch-1] == _T('\n') || s[cch-1] == _T('\r'))
927 s[cch-1] = 0, --cch;
928 }
929
930 static UINT GetNextNLFLine(NStreamLineReader&lr, TCHAR*Buf, UINT cchBuf) {
931 for (;;) {
932 UINT err = lr.ReadLine(Buf, cchBuf);
933 if (NStream::OK != err) {
934 if (lr.IsEOF()) err = NStream::OK;
935 return err;
936 }
937 if (NStream::IsNewline(*Buf, false)) continue;
938 if (_T('#') != *Buf && _T(';') != *Buf) return err;
939 }
940 }
941 static inline bool GetNextNLFLine(NStreamLineReader&lr, TCHAR*Buf, UINT cchBuf, UINT&errlr) {
942 errlr = GetNextNLFLine(lr, Buf, cchBuf);
943 return NStream::OK == errlr;
944 }
945
946 // NSIS Language File parser
947 LanguageTable * CEXEBuild::LoadLangFile(TCHAR *filename) {
948 NIStream strm;
949 strm.StreamEncoding().SetCodepage(NStreamEncoding::ACP);
950 if (!strm.OpenFileForReading(filename)) {
951 ERROR_MSG(_T("Error: Can't open language file - \"%") NPRIs _T("\"!\n"),filename);
952 return 0;
953 }
954 NStreamLineReader lr(strm);
955 UINT errlr;
956
957 // Check header
958 TCHAR buf[NSIS_MAX_STRLEN];
959 if (!GetNextNLFLine(lr, buf, NSIS_MAX_STRLEN, errlr)) {
960 l_readerr:
961 ERROR_MSG(lr.GetErrorMessage(errlr).c_str());
962 return 0;
963 }
964 if (_tcsncmp(buf, _T("NLF v"), 5)) {
965 ERROR_MSG(_T("Error: Invalid language file.\n"));
966 return 0;
967 }
968 int nlf_version = _ttoi(buf+5);
969 if (nlf_version != NLF_VERSION) {
970 if (nlf_version != 2 && nlf_version != 3 && nlf_version != 4 && nlf_version != 5) {
971 ERROR_MSG(_T("Error: Language file version doesn't match NSIS version.\n"));
972 return 0;
973 }
974 }
975
976 // Get language ID
977 if (!GetNextNLFLine(lr, buf, NSIS_MAX_STRLEN, errlr)) goto l_readerr;
978 LANGID lang_id = _ttoi(buf);
979
980 // Get appropriate table
981 LanguageTable *table = GetLangTable(lang_id);
982 if (!table) return 0;
983
984 NLF *nlf = &table->nlf;
985 if (nlf->m_bLoaded) {
986 ERROR_MSG(_T("Error: can't load same language file twice.\n"));
987 return 0;
988 }
989
990 // Generate language name
991 TCHAR *p, *p2, *p3, t = 0;
992
993 p = _tcsrchr(filename, _T('.'));
994 if (p) {
995 t = *p;
996 *p = 0;
997 }
998 p2 = _tcsrchr(filename, _T('\\')), p3 = _tcsrchr(filename, _T('/'));
999 if (p3 > p2) p2 = p3;
1000 if (p2) {
1001 p2++;
1002 nlf->m_szName = (TCHAR*)malloc((_tcslen(p2)+1)*sizeof(TCHAR));
1003 _tcscpy(nlf->m_szName, p2);
1004 }
1005 else {
1006 nlf->m_szName = (TCHAR*)malloc((_tcslen(filename)+1)*sizeof(TCHAR));
1007 _tcscpy(nlf->m_szName, filename);
1008 }
1009 if (p) *p = t;
1010
1011 if (nlf_version != NLF_VERSION) {
1012 warning_fl(DW_NLF_OLDVERSION, _T("%") NPRIs _T(" language file version doesn't match. Using default English texts for missing strings."), nlf->m_szName);
1013 }
1014
1015 // set ^Language
1016 nlf->m_szStrings[NLF_LANGUAGE] = _tcsdup(nlf->m_szName);
1017
1018 size_t temp;
1019
1020 // Get font
1021 if (!GetNextNLFLine(lr, buf, NSIS_MAX_STRLEN, errlr)) goto l_readerr;
1022 if (!nlf->m_szFont) {
1023 TrimTrailingNewlines(buf);
1024 if (buf[0] != _T('-') || buf[1] != 0) {
1025 nlf->m_szFont = (TCHAR*)malloc((_tcslen(buf)+1)*sizeof(TCHAR));
1026 _tcscpy(nlf->m_szFont, buf);
1027 }
1028 }
1029
1030 if (!GetNextNLFLine(lr, buf, NSIS_MAX_STRLEN, errlr)) goto l_readerr;
1031 if (!nlf->m_iFontSize) {
1032 if (buf[0] != _T('-') || buf[1] != 0) {
1033 nlf->m_iFontSize = _ttoi(buf);
1034 }
1035 }
1036
1037 // Get code page
1038 bool isnlfdataucp = false; // Unicode-only language?
1039 nlf->m_uCodePage = NSISRT_GetASCIICodepage();
1040 if (!GetNextNLFLine(lr, buf, NSIS_MAX_STRLEN, errlr)) goto l_readerr;
1041 TrimTrailingNewlines(buf);
1042 if (buf[0] != _T('-') || buf[1] != 0) {
1043 nlf->m_uCodePage = _ttoi(buf);
1044 isnlfdataucp = NStreamEncoding::IsUnicodeCodepage(nlf->m_uCodePage);
1045 if (isnlfdataucp && 1200 != nlf->m_uCodePage)
1046 {
1047 ERROR_MSG(_T("Error: Unicode-only language files must use codepage 1200!\n"));
1048 return 0;
1049 }
1050 if ((unsigned)nlf->m_uCodePage <= 1 && !lr.IsUnicode()) // Warn if someone uses a system specific codepage
1051 {
1052 warning_fl(DW_NLF_SYSCP, _T("%") NPRIs _T(" language file uses the system default codepage!"), nlf->m_szName);
1053 }
1054 if (CP_ACP != nlf->m_uCodePage && !isnlfdataucp && !IsValidCodePage(nlf->m_uCodePage))
1055 {
1056 warning_fl(DW_NLF_UNSUPPORTED_CP, _T("%") NPRIs _T(" language file uses a codepage (%d) that is not supported on this system, using ACP!"), nlf->m_szName, nlf->m_uCodePage);
1057 nlf->m_uCodePage = CP_ACP;
1058 }
1059 }
1060
1061 // SVN is not a big fan of UTF16 so we should always use UTF8SIG
1062 if (isnlfdataucp && !lr.StreamEncoding().IsUTF8())
1063 {
1064 warning_fl(DW_NLF_NOT_PREFERRED_ENC, _T("%") NPRIs _T(" Unicode language file is not UTF8SIG."), nlf->m_szName);
1065 }
1066
1067 #ifdef _UNICODE
1068 if (!lr.IsUnicode())
1069 {
1070 if (nlf->m_szFont)
1071 {
1072 // Convert font name now that we know the codepage
1073 TCHAR* oldfont = nlf->m_szFont;
1074 nlf->m_szFont = _tcsdup(CtoTString2(TtoCString(oldfont), nlf->m_uCodePage)); // BUGBUG: Depends on lossless ACP -> TCHAR -> NLF CP -> TCHAR conversion!
1075 free(oldfont);
1076 }
1077 lr.StreamEncoding().SetCodepage(nlf->m_uCodePage); // Read the rest of this NLF file with the correct MBCS > TCHAR conversion
1078 }
1079 #endif
1080
1081 // Get RTL setting
1082 if (!GetNextNLFLine(lr, buf, NSIS_MAX_STRLEN, errlr)) goto l_readerr;
1083 nlf->m_szStrings[NLF_RTL] = (TCHAR*) malloc(2*sizeof(TCHAR));
1084 nlf->m_bRTL = false;
1085 if (buf[0] == _T('R') && buf[1] == _T('T') && buf[2] == _T('L') && (!buf[3] || buf[3] == _T('\r') || buf[3] == _T('\n'))) {
1086 nlf->m_bRTL = true;
1087 }
1088 _tcscpy(nlf->m_szStrings[NLF_RTL], nlf->m_bRTL ? _T("1") : _T("0"));
1089
1090 // Read strings
1091 for (int i = 0; i < NLF_STRINGS_NO_SPECIAL; i++) {
1092
1093 // skip virtual strings
1094 if (!NLFStrings[i].szDefault)
1095 continue;
1096
1097 // Fill in for missing strings
1098 // 0 will mean default will be used from NLFStrings
1099 switch (i) {
1100 case NLF_BTN_LICENSE_AGREE:
1101 case NLF_BTN_LICENSE_DISAGREE:
1102 if (nlf_version >= 3) break;
1103 case NLF_LOG_INSTALL_PROCESS:
1104 case NLF_BYTE:
1105 case NLF_KILO:
1106 case NLF_MEGA:
1107 case NLF_GIGA:
1108 case NLF_REGISTERING:
1109 case NLF_UNREGISTERING:
1110 if (nlf_version >= 4) break;
1111 case NLF_FILE_ERROR_NOIGNORE:
1112 if (nlf_version >= 5) break;
1113 case NLF_USUBCAPTION_OPTIONS:
1114 case NLF_USUBCAPTION_DIR:
1115 case NLF_CLICK_NEXT:
1116 case NLF_CLICK_INSTALL:
1117 case NLF_CLICK_UNINSTALL:
1118 case NLF_LICENSE_TEXT:
1119 case NLF_LICENSE_TEXT_FSCB:
1120 case NLF_LICENSE_TEXT_FSRB:
1121 case NLF_ULICENSE_TEXT:
1122 case NLF_ULICENSE_TEXT_FSCB:
1123 case NLF_ULICENSE_TEXT_FSRB:
1124 case NLF_COMP_TEXT:
1125 case NLF_UCOMP_TEXT:
1126 case NLF_UCOMP_SUBTEXT1:
1127 case NLF_UCOMP_SUBTEXT1_NO_INST_TYPES:
1128 case NLF_UCOMP_SUBTEXT2:
1129 case NLF_DIR_TEXT:
1130 case NLF_DIR_BROWSETEXT:
1131 case NLF_UDIR_TEXT:
1132 case NLF_UDIR_SUBTEXT:
1133 case NLF_UDIR_BROWSETEXT:
1134 case NLF_UNINST_TEXT:
1135 if (nlf_version >= 6) break;
1136 nlf->m_szStrings[i] = 0;
1137 continue; // This applies to the for loop and not this switch!
1138 }
1139
1140 errlr = GetNextNLFLine(lr, buf, NSIS_MAX_STRLEN);
1141 if (_tcslen(buf) == NSIS_MAX_STRLEN-1) {
1142 ERROR_MSG(_T("Error: String too long (string #%d - \"%") NPRIs _T("\")\n"), i, NLFStrings[i].szLangStringName);
1143 return 0;
1144 }
1145 if (NStream::OK != errlr) goto l_readerr;
1146
1147 temp=_tcslen(buf);
1148 // Not using TrimTrailingNewlines because we need temp to be correct for the quote trimming
1149 while (buf[temp-1] == _T('\n') || buf[temp-1] == _T('\r')) {
1150 buf[--temp] = 0;
1151 }
1152
1153 TCHAR *in = buf;
1154
1155 // trim quotes
1156 if (buf[0] == _T('"') && buf[temp-1] == _T('"')) {
1157 in++;
1158 buf[--temp] = 0;
1159 }
1160
1161 nlf->m_szStrings[i] = (TCHAR*)malloc((temp+1)*sizeof(TCHAR));
1162 TCHAR *out;
1163 for (out = nlf->m_szStrings[i]; *in; in++, out++) {
1164 if (*in == _T('\\')) {
1165 in++;
1166 switch (*in) {
1167 case _T('n'):
1168 *out = _T('\n');
1169 break;
1170 case _T('r'):
1171 *out = _T('\r');
1172 break;
1173 case _T('t'):
1174 *out = _T('\t');
1175 break;
1176 default:
1177 *out++ = _T('\\');
1178 *out = *in;
1179 }
1180 }
1181 else *out = *in;
1182 }
1183 *out = 0;
1184 }
1185
1186 nlf->m_bLoaded = true;
1187 return table;
1188 }
1189
1190 void CEXEBuild::DeleteLangTable(LanguageTable *table) {
1191 if (table->nlf.m_szName)
1192 free(table->nlf.m_szName);
1193 if (table->nlf.m_szFont)
1194 free(table->nlf.m_szFont);
1195 delete table->lang_strings;
1196 for (int i = 0; i < NLF_STRINGS; i++) {
1197 if (table->nlf.m_szStrings[i])
1198 free(table->nlf.m_szStrings[i]);
1199 }
1200 }