Jim Park's Unicode NSIS merging - Step 1 : switch to TCHARs where relevant.

Compiler output is identical before & after this step

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/branches/wizou@6036 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
wizou 2010-03-24 17:22:56 +00:00
parent 4e48722b63
commit 752d7d239a
209 changed files with 9698 additions and 7658 deletions

View file

@ -12,16 +12,20 @@
*
* This software is provided 'as-is', without any express or implied
* warranty.
*
* Unicode support and Doxygen comments by Jim Park -- 07/25/2007
*/
#include "Platform.h"
#include <stdio.h>
#include <stdlib.h>
#include "tchar.h"
#include "build.h"
#include "util.h"
#include "DialogTemplate.h"
#include "exehead/resource.h"
#include <nsis-version.h>
#include "tstring.h"
using namespace std;
@ -37,107 +41,107 @@ typedef enum {
} STATICID;
struct NLFString {
const char *szLangStringName;
const char *szDefault;
const TCHAR *szLangStringName;
const TCHAR *szDefault;
STATICID eStaticID;
};
NLFString NLFStrings[NLF_STRINGS] = {
{"^Branding", "Nullsoft Install System %s", BOTH_STATIC},
{"^SetupCaption", "$(^Name) Setup", INSTALL_STATIC},
{"^UninstallCaption", "$(^Name) Uninstall", UNINSTALL_STATIC},
{"^LicenseSubCaption", ": License Agreement", NONE_STATIC},
{"^ComponentsSubCaption", ": Installation Options", NONE_STATIC},
{"^DirSubCaption", ": Installation Folder", NONE_STATIC},
{"^InstallingSubCaption", ": Installing", NONE_STATIC},
{"^CompletedSubCaption", ": Completed", NONE_STATIC},
{"^UnComponentsSubCaption", ": Uninstallation Options", NONE_STATIC},
{"^UnDirSubCaption", ": Uninstallation Folder", NONE_STATIC},
{"^ConfirmSubCaption", ": Confirmation", NONE_STATIC},
{"^UninstallingSubCaption", ": Uninstalling", NONE_STATIC},
{"^UnCompletedSubCaption", ": Completed", NONE_STATIC},
{"^BackBtn", "< &Back", NONE_STATIC},
{"^NextBtn", "&Next >", NONE_STATIC},
{"^AgreeBtn", "I &Agree", NONE_STATIC},
{"^AcceptBtn", "I &accept the terms of the License Agreement", NONE_STATIC},
{"^DontAcceptBtn", "I &do not accept the terms of the License Agreement", NONE_STATIC},
{"^InstallBtn", "&Install", NONE_STATIC},
{"^UninstallBtn", "&Uninstall", NONE_STATIC},
{"^CancelBtn", "Cancel", NONE_STATIC},
{"^CloseBtn", "&Close", NONE_STATIC},
{"^BrowseBtn", "B&rowse...", NONE_STATIC},
{"^ShowDetailsBtn", "Show &details", NONE_STATIC},
{"^ClickNext", "Click Next to continue.", NONE_STATIC},
{"^ClickInstall", "Click Install to start the installation.", NONE_STATIC},
{"^ClickUninstall", "Click Uninstall to start the uninstallation.", NONE_STATIC},
{"^Name", "Name", BOTH_STATIC},
{"^NameDA", 0, NONE_STATIC}, // virtual
{"^Completed", "Completed", NONE_STATIC},
{"^LicenseText", "Please review the license agreement before installing $(^NameDA). If you accept all terms of the agreement, click I Agree.", NONE_STATIC},
{"^LicenseTextCB", "Please review the license agreement before installing $(^NameDA). If you accept all terms of the agreement, click the check box below. $_CLICK", NONE_STATIC},
{"^LicenseTextRB", "Please review the license agreement before installing $(^NameDA). If you accept all terms of the agreement, select the first option below. $_CLICK", NONE_STATIC},
{"^UnLicenseText", "Please review the license agreement before uninstalling $(^NameDA). If you accept all terms of the agreement, click I Agree.", NONE_STATIC},
{"^UnLicenseTextCB", "Please review the license agreement before uninstalling $(^NameDA). If you accept all terms of the agreement, click the check box below. $_CLICK", NONE_STATIC},
{"^UnLicenseTextRB", "Please review the license agreement before uninstalling $(^NameDA). If you accept all terms of the agreement, select the first option below. $_CLICK", NONE_STATIC},
{"^LicenseData", 0, NONE_STATIC}, // virtual - not processed
{"^Custom", "Custom", NONE_STATIC},
{"^ComponentsText", "Check the components you want to install and uncheck the components you don't want to install. $_CLICK", NONE_STATIC},
{"^ComponentsSubText1", "Select the type of install:", NONE_STATIC},
{"^ComponentsSubText2_NoInstTypes", "Select components to install:", NONE_STATIC},
{"^ComponentsSubText2", "Or, select the optional components you wish to install:", NONE_STATIC},
{"^UnComponentsText", "Check the components you want to uninstall and uncheck the components you don't want to uninstall. $_CLICK", NONE_STATIC},
{"^UnComponentsSubText1", "Select the type of uninstall:", NONE_STATIC},
{"^UnComponentsSubText2_NoInstTypes", "Select components to uninstall:", NONE_STATIC},
{"^UnComponentsSubText2", "Or, select the optional components you wish to uninstall:", NONE_STATIC},
{"^DirText", "Setup will install $(^NameDA) in the following folder. To install in a different folder, click Browse and select another folder. $_CLICK", NONE_STATIC},
{"^DirSubText", "Destination Folder", NONE_STATIC},
{"^DirBrowseText", "Select the folder to install $(^NameDA) in:", NONE_STATIC},
{"^UnDirText", "Setup will uninstall $(^NameDA) from the following folder. To uninstall from a different folder, click Browse and select another folder. $_CLICK", NONE_STATIC},
{"^UnDirSubText", "", NONE_STATIC},
{"^UnDirBrowseText", "Select the folder to uninstall $(^NameDA) from:", NONE_STATIC},
{"^SpaceAvailable", "Space available: ", BOTH_STATIC},
{"^SpaceRequired", "Space required: ", BOTH_STATIC},
{"^UninstallingText", "This wizard will uninstall $(^NameDA) from your computer. $_CLICK", NONE_STATIC},
{"^UninstallingSubText", "Uninstalling from:", NONE_STATIC},
{"^FileError", "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},
{"^FileError_NoIgnore", "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},
{"^CantWrite", "Can't write: ", BOTH_STATIC},
{"^CopyFailed", "Copy failed", BOTH_STATIC},
{"^CopyTo", "Copy to ", BOTH_STATIC},
{"^Registering", "Registering: ", NONE_STATIC},
{"^Unregistering", "Unregistering: ", NONE_STATIC},
{"^SymbolNotFound", "Could not find symbol: ", BOTH_STATIC},
{"^CouldNotLoad", "Could not load: ", BOTH_STATIC},
{"^CreateFolder", "Create folder: ", BOTH_STATIC},
{"^CreateShortcut", "Create shortcut: ", BOTH_STATIC},
{"^CreatedUninstaller", "Created uninstaller: ", BOTH_STATIC},
{"^Delete", "Delete file: ", BOTH_STATIC},
{"^DeleteOnReboot", "Delete on reboot: ", BOTH_STATIC},
{"^ErrorCreatingShortcut", "Error creating shortcut: ", BOTH_STATIC},
{"^ErrorCreating", "Error creating: ", BOTH_STATIC},
{"^ErrorDecompressing", "Error decompressing data! Corrupted installer?", BOTH_STATIC},
{"^ErrorRegistering", "Error registering DLL", BOTH_STATIC},
{"^ExecShell", "ExecShell: ", BOTH_STATIC},
{"^Exec", "Execute: ", BOTH_STATIC},
{"^Extract", "Extract: ", BOTH_STATIC},
{"^ErrorWriting", "Extract: error writing to file ", BOTH_STATIC},
{"^InvalidOpcode", "Installer corrupted: invalid opcode", BOTH_STATIC},
{"^NoOLE", "No OLE for: ", BOTH_STATIC},
{"^OutputFolder", "Output folder: ", BOTH_STATIC},
{"^RemoveFolder", "Remove folder: ", BOTH_STATIC},
{"^RenameOnReboot", "Rename on reboot: ", BOTH_STATIC},
{"^Rename", "Rename: ", BOTH_STATIC},
{"^Skipped", "Skipped: ", BOTH_STATIC},
{"^CopyDetails", "Copy Details To Clipboard", BOTH_STATIC},
{"^LogInstall", "Log install process", BOTH_STATIC},
{"^Byte", "B", BOTH_STATIC},
{"^Kilo", "K", BOTH_STATIC},
{"^Mega", "M", BOTH_STATIC},
{"^Giga", "G", BOTH_STATIC},
{"^Font", "MS Shell Dlg", NONE_STATIC},
{"^FontSize", "8", NONE_STATIC},
{"^RTL", "0", NONE_STATIC},
{"^Language", "English", NONE_STATIC}
{_T("^Branding"), _T("Nullsoft Install System %s"), BOTH_STATIC},
{_T("^SetupCaption"), _T("$(^Name) Setup"), INSTALL_STATIC},
{_T("^UninstallCaption"), _T("$(^Name) Uninstall"), UNINSTALL_STATIC},
{_T("^LicenseSubCaption"), _T(": License Agreement"), NONE_STATIC},
{_T("^ComponentsSubCaption"), _T(": Installation Options"), NONE_STATIC},
{_T("^DirSubCaption"), _T(": Installation Folder"), NONE_STATIC},
{_T("^InstallingSubCaption"), _T(": Installing"), NONE_STATIC},
{_T("^CompletedSubCaption"), _T(": Completed"), NONE_STATIC},
{_T("^UnComponentsSubCaption"), _T(": Uninstallation Options"), NONE_STATIC},
{_T("^UnDirSubCaption"), _T(": Uninstallation Folder"), NONE_STATIC},
{_T("^ConfirmSubCaption"), _T(": Confirmation"), NONE_STATIC},
{_T("^UninstallingSubCaption"), _T(": Uninstalling"), NONE_STATIC},
{_T("^UnCompletedSubCaption"), _T(": Completed"), NONE_STATIC},
{_T("^BackBtn"), _T("< &Back"), NONE_STATIC},
{_T("^NextBtn"), _T("&Next >"), NONE_STATIC},
{_T("^AgreeBtn"), _T("I &Agree"), NONE_STATIC},
{_T("^AcceptBtn"), _T("I &accept the terms of the License Agreement"), NONE_STATIC},
{_T("^DontAcceptBtn"), _T("I &do not accept the terms of the License Agreement"), NONE_STATIC},
{_T("^InstallBtn"), _T("&Install"), NONE_STATIC},
{_T("^UninstallBtn"), _T("&Uninstall"), NONE_STATIC},
{_T("^CancelBtn"), _T("Cancel"), NONE_STATIC},
{_T("^CloseBtn"), _T("&Close"), NONE_STATIC},
{_T("^BrowseBtn"), _T("B&rowse..."), NONE_STATIC},
{_T("^ShowDetailsBtn"), _T("Show &details"), NONE_STATIC},
{_T("^ClickNext"), _T("Click Next to continue."), NONE_STATIC},
{_T("^ClickInstall"), _T("Click Install to start the installation."), NONE_STATIC},
{_T("^ClickUninstall"), _T("Click Uninstall to start the uninstallation."), NONE_STATIC},
{_T("^Name"), _T("Name"), BOTH_STATIC},
{_T("^NameDA"), 0, NONE_STATIC}, // virtual
{_T("^Completed"), _T("Completed"), NONE_STATIC},
{_T("^LicenseText"), _T("Please review the license agreement before installing $(^NameDA). If you accept all terms of the agreement, click I Agree."), NONE_STATIC},
{_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},
{_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},
{_T("^UnLicenseText"), _T("Please review the license agreement before uninstalling $(^NameDA). If you accept all terms of the agreement, click I Agree."), NONE_STATIC},
{_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},
{_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},
{_T("^LicenseData"), 0, NONE_STATIC}, // virtual - not processed
{_T("^Custom"), _T("Custom"), NONE_STATIC},
{_T("^ComponentsText"), _T("Check the components you want to install and uncheck the components you don't want to install. $_CLICK"), NONE_STATIC},
{_T("^ComponentsSubText1"), _T("Select the type of install:"), NONE_STATIC},
{_T("^ComponentsSubText2_NoInstTypes"), _T("Select components to install:"), NONE_STATIC},
{_T("^ComponentsSubText2"), _T("Or, select the optional components you wish to install:"), NONE_STATIC},
{_T("^UnComponentsText"), _T("Check the components you want to uninstall and uncheck the components you don't want to uninstall. $_CLICK"), NONE_STATIC},
{_T("^UnComponentsSubText1"), _T("Select the type of uninstall:"), NONE_STATIC},
{_T("^UnComponentsSubText2_NoInstTypes"), _T("Select components to uninstall:"), NONE_STATIC},
{_T("^UnComponentsSubText2"), _T("Or, select the optional components you wish to uninstall:"), NONE_STATIC},
{_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},
{_T("^DirSubText"), _T("Destination Folder"), NONE_STATIC},
{_T("^DirBrowseText"), _T("Select the folder to install $(^NameDA) in:"), NONE_STATIC},
{_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},
{_T("^UnDirSubText"), _T(""), NONE_STATIC},
{_T("^UnDirBrowseText"), _T("Select the folder to uninstall $(^NameDA) from:"), NONE_STATIC},
{_T("^SpaceAvailable"), _T("Space available: "), BOTH_STATIC},
{_T("^SpaceRequired"), _T("Space required: "), BOTH_STATIC},
{_T("^UninstallingText"), _T("This wizard will uninstall $(^NameDA) from your computer. $_CLICK"), NONE_STATIC},
{_T("^UninstallingSubText"), _T("Uninstalling from:"), NONE_STATIC},
{_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},
{_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},
{_T("^CantWrite"), _T("Can't write: "), BOTH_STATIC},
{_T("^CopyFailed"), _T("Copy failed"), BOTH_STATIC},
{_T("^CopyTo"), _T("Copy to "), BOTH_STATIC},
{_T("^Registering"), _T("Registering: "), NONE_STATIC},
{_T("^Unregistering"), _T("Unregistering: "), NONE_STATIC},
{_T("^SymbolNotFound"), _T("Could not find symbol: "), BOTH_STATIC},
{_T("^CouldNotLoad"), _T("Could not load: "), BOTH_STATIC},
{_T("^CreateFolder"), _T("Create folder: "), BOTH_STATIC},
{_T("^CreateShortcut"), _T("Create shortcut: "), BOTH_STATIC},
{_T("^CreatedUninstaller"), _T("Created uninstaller: "), BOTH_STATIC},
{_T("^Delete"), _T("Delete file: "), BOTH_STATIC},
{_T("^DeleteOnReboot"), _T("Delete on reboot: "), BOTH_STATIC},
{_T("^ErrorCreatingShortcut"), _T("Error creating shortcut: "), BOTH_STATIC},
{_T("^ErrorCreating"), _T("Error creating: "), BOTH_STATIC},
{_T("^ErrorDecompressing"), _T("Error decompressing data! Corrupted installer?"), BOTH_STATIC},
{_T("^ErrorRegistering"), _T("Error registering DLL"), BOTH_STATIC},
{_T("^ExecShell"), _T("ExecShell: "), BOTH_STATIC},
{_T("^Exec"), _T("Execute: "), BOTH_STATIC},
{_T("^Extract"), _T("Extract: "), BOTH_STATIC},
{_T("^ErrorWriting"), _T("Extract: error writing to file "), BOTH_STATIC},
{_T("^InvalidOpcode"), _T("Installer corrupted: invalid opcode"), BOTH_STATIC},
{_T("^NoOLE"), _T("No OLE for: "), BOTH_STATIC},
{_T("^OutputFolder"), _T("Output folder: "), BOTH_STATIC},
{_T("^RemoveFolder"), _T("Remove folder: "), BOTH_STATIC},
{_T("^RenameOnReboot"), _T("Rename on reboot: "), BOTH_STATIC},
{_T("^Rename"), _T("Rename: "), BOTH_STATIC},
{_T("^Skipped"), _T("Skipped: "), BOTH_STATIC},
{_T("^CopyDetails"), _T("Copy Details To Clipboard"), BOTH_STATIC},
{_T("^LogInstall"), _T("Log install process"), BOTH_STATIC},
{_T("^Byte"), _T("B"), BOTH_STATIC},
{_T("^Kilo"), _T("K"), BOTH_STATIC},
{_T("^Mega"), _T("M"), BOTH_STATIC},
{_T("^Giga"), _T("G"), BOTH_STATIC},
{_T("^Font"), _T("MS Shell Dlg"), NONE_STATIC},
{_T("^FontSize"), _T("8"), NONE_STATIC},
{_T("^RTL"), _T("0"), NONE_STATIC},
{_T("^Language"), _T("English"), NONE_STATIC}
};
// ==============
@ -148,7 +152,7 @@ LangStringList::LangStringList() {
count = 0;
}
int LangStringList::add(const char *name, int *sn/*=0*/)
int LangStringList::add(const TCHAR *name, int *sn/*=0*/)
{
int pos = SortedStringListND<struct langstring>::add(name);
if (pos == -1) return -1;
@ -163,9 +167,9 @@ int LangStringList::add(const char *name, int *sn/*=0*/)
return pos;
}
int LangStringList::get(const char *name, int *sn/*=0*/, int *index/*=0*/, int *uindex/*=0*/, int *process/*=0*/)
int LangStringList::get(const TCHAR *name, int *sn/*=0*/, int *index/*=0*/, int *uindex/*=0*/, int *process/*=0*/)
{
if (index) *index = -1;
if (index) *index = -1;
if (uindex) *uindex = -1;
if (sn) *sn = -1;
int v=find(name);
@ -192,27 +196,27 @@ void LangStringList::set(int pos, int index/*=-1*/, int uindex/*=-1*/, int proce
data[pos].process = process;
}
void LangStringList::set(const char *name, int index, int uindex/*=-1*/, int process/*=-1*/)
void LangStringList::set(const TCHAR *name, int index, int uindex/*=-1*/, int process/*=-1*/)
{
set(get(name), index, uindex, process);
}
const char* LangStringList::pos2name(int pos)
const TCHAR* LangStringList::pos2name(int pos)
{
struct langstring *data=(struct langstring *)gr.get();
if ((unsigned int)pos > (gr.getlen() / sizeof(struct langstring)))
return 0;
return ((const char*)strings.get() + data[pos].name);
return ((const TCHAR*)strings.get() + data[pos].name);
}
const char* LangStringList::offset2name(int name)
const TCHAR* LangStringList::offset2name(int name)
{
if ((unsigned int)name > (unsigned int)strings.getlen())
return 0;
return (const char*)strings.get() + name;
return (const TCHAR*)strings.get() + name;
}
int LangStringList::getnum()
@ -264,7 +268,7 @@ StringsArray::StringsArray()
{
offsets.set_zeroing(1);
strings.add("", sizeof(""));
strings.add(_T(""), sizeof(_T("")));
}
void StringsArray::resize(int num)
@ -272,7 +276,7 @@ void StringsArray::resize(int num)
offsets.resize(num * sizeof(int));
}
int StringsArray::set(int idx, const char *str)
int StringsArray::set(int idx, const TCHAR *str)
{
if (idx < 0)
return 0;
@ -287,12 +291,12 @@ int StringsArray::set(int idx, const char *str)
return old;
}
const char* StringsArray::get(int idx)
const TCHAR* StringsArray::get(int idx)
{
if ((unsigned int)idx >= (offsets.getlen() / sizeof(int)))
return 0;
return (const char *)strings.get() + ((int*)offsets.get())[idx];
return (const TCHAR *)strings.get() + ((int*)offsets.get())[idx];
}
// =========
@ -331,6 +335,12 @@ void CEXEBuild::InitLangTables() {
keep_ref = true;
}
//////////////////////////////////////////////////////////////////////////////
// class CEXEBuild
//
// Note: The functions below refer to the methods related to Languages.
//////////////////////////////////////////////////////////////////////////////
LanguageTable* CEXEBuild::GetLangTable(LANGID &lang, bool create/*=true*/) {
int nlt = lang_tables.getlen() / sizeof(LanguageTable);
LanguageTable *nla = (LanguageTable*)lang_tables.get();
@ -363,7 +373,7 @@ LanguageTable* CEXEBuild::GetLangTable(LANGID &lang, bool create/*=true*/) {
return table;
}
const char *CEXEBuild::GetLangNameAndCP(LANGID lang, unsigned int *codepage/*=NULL*/) {
const TCHAR *CEXEBuild::GetLangNameAndCP(LANGID lang, unsigned int *codepage/*=NULL*/) {
LanguageTable *table = GetLangTable(lang, false);
if (table && table->nlf.m_bLoaded) {
@ -377,48 +387,54 @@ const char *CEXEBuild::GetLangNameAndCP(LANGID lang, unsigned int *codepage/*=NU
*codepage = 1252; // English US
if (lang == 1033)
return "English";
return _T("English");
else
return "???";
return _T("???");
}
}
int CEXEBuild::DefineLangString(const char *name, int process/*=-1*/) {
int CEXEBuild::DefineLangString(const TCHAR *name, int process/*=-1*/) {
int index, uindex, pos, ret, sn;
/* If not exist, index and uindex will get -1. */
pos = build_langstrings.get(name, &sn, &index, &uindex);
if (pos < 0) {
pos = build_langstrings.add(name);
}
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
if (!uninstall_mode) {
if (!this->uninstall_mode) {
#endif
if (index < 0) {
index = build_langstring_num++;
// Did not exist. Increment.
index = this->build_langstring_num++;
}
ret = -index - 1;
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
}
else {
if (uindex < 0) {
uindex = ubuild_langstring_num++;
// Did not exist. Increment.
uindex = this->ubuild_langstring_num++;
}
ret = -uindex - 1;
}
#endif
// Now set the new index and uindex values with the
// passed in proces value.
build_langstrings.set(pos, index, uindex, process);
// set reference count for NLF strings
if (keep_ref && name[0] == '^') {
if (this->keep_ref && name[0] == _T('^')) {
for (int i = 0; i < NLF_STRINGS; i++) {
if (!strcmp(name, NLFStrings[i].szLangStringName)) {
if (!_tcscmp(name, NLFStrings[i].szLangStringName)) {
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
if (uninstall_mode)
NLFRefs[i].iUnRef++;
if (this->uninstall_mode)
this->NLFRefs[i].iUnRef++;
else
#endif
NLFRefs[i].iRef++;
this->NLFRefs[i].iRef++;
break;
}
@ -450,8 +466,15 @@ int CEXEBuild::DefineInnerLangString(int id, int process/*=-1*/) {
return ret;
}
int CEXEBuild::SetLangString(char *name, LANGID lang, char *string) {
if (!string || !name) return PS_ERROR;
// A LangString is a string variable that varies in value depending on what
// language is being used. This function sets the string value for the
// variable 'name' for a given language ID.
//
// @return If the language id, the variable name or string is invalid, it will
// return a PS_ERROR. If this function call is overwriting a set user string,
// this will return a PS_WARNING.
int CEXEBuild::SetLangString(TCHAR *name, LANGID lang, TCHAR *str) {
if (!str || !name) return PS_ERROR;
LanguageTable *table = GetLangTable(lang);
if (!table) return PS_ERROR;
@ -462,22 +485,27 @@ int CEXEBuild::SetLangString(char *name, LANGID lang, char *string) {
if (pos < 0)
pos = build_langstrings.add(name, &sn);
if (table->lang_strings->set(sn, string))
if (table->lang_strings->set(sn, str))
return PS_WARNING;
return PS_OK;
}
int CEXEBuild::SetInnerString(int id, char *string) {
if ((unsigned int)id >= NLF_STRINGS || !string) return PS_ERROR;
// Sets the user string to the specific NLF_STRINGS id.
//
// @return If the id is invalid or the string is not valid, it will return a
// PS_ERROR. If this function call is overwriting a set user string, this
// will return a PS_WARNING.
int CEXEBuild::SetInnerString(int id, TCHAR *str) {
if ((unsigned int)id >= NLF_STRINGS || !str) return PS_ERROR;
int ret = PS_OK;
const char *ps = UserInnerStrings.get(id);
const TCHAR *ps = UserInnerStrings.get(id);
if (ps && *ps)
ret = PS_WARNING;
UserInnerStrings.set(id, string);
UserInnerStrings.set(id, str);
return ret;
}
@ -531,24 +559,25 @@ int CEXEBuild::GenerateLangTable(LanguageTable *lt, int num_lang_tables) {
if (!*ptr)
{
// Get the language string and its name
const char *str = lt[i].lang_strings->get(lang_strings[j].sn);
const char *lsn = build_langstrings.offset2name(lang_strings[j].name);
const TCHAR *str = lt[i].lang_strings->get(lang_strings[j].sn);
const TCHAR *lsn = build_langstrings.offset2name(lang_strings[j].name);
// lsn = variable name, str = value
if (!str || !*str)
{
// No string is defined; give a warning (for user strings only)
if (lsn[0] != '^')
if (lsn[0] != _T('^'))
{
if (lt[i].nlf.m_bLoaded)
warning("LangString \"%s\" is not set in language table of language %s", lsn, lt[i].nlf.m_szName);
warning(_T("LangString \"%s\" is not set in language table of language %s"), lsn, lt[i].nlf.m_szName);
else
warning("LangString \"%s\" is not set in language table of language %d", lsn, lt[i].lang_id);
warning(_T("LangString \"%s\" is not set in language table of language %d"), lsn, lt[i].lang_id);
}
}
else
{
// Add the language string to the string data block
char fn[1024];
sprintf(fn, "LangString %s", lsn);
TCHAR fn[1024];
_stprintf(fn, _T("LangString %s"), lsn);
curfilename = fn;
linecnt = lt[i].lang_id;
*ptr = add_string(str, lang_strings[j].process, (WORD) lt[i].nlf.m_uCodePage);
@ -586,7 +615,7 @@ int CEXEBuild::GenerateLangTable(LanguageTable *lt, int num_lang_tables) {
if (((int*)rec.get())[l] == lst[j])
{
// We have the index of a recursive language string; now find the name
const char *name = "(unnamed)";
const TCHAR *name = _T("(unnamed)");
for (l = 0; l < langstring_num; l++)
{
int index;
@ -601,7 +630,7 @@ int CEXEBuild::GenerateLangTable(LanguageTable *lt, int num_lang_tables) {
name = build_langstrings.offset2name(lang_strings[l].name);
}
}
ERROR_MSG("Error: LangString %s is recursive!\n", name);
ERROR_MSG(_T("Error: LangString %s is recursive!\n"), name);
delete [] string_ptrs;
return PS_ERROR;
}
@ -638,7 +667,7 @@ int CEXEBuild::GenerateLangTables() {
int i;
LanguageTable *lt = (LanguageTable*)lang_tables.get();
SCRIPT_MSG("Generating language tables... ");
SCRIPT_MSG(_T("Generating language tables... "));
if (
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
@ -647,7 +676,7 @@ int CEXEBuild::GenerateLangTables() {
build_langstring_num > MAX_CODED
)
{
ERROR_MSG("\nError: too many LangStrings. Maximum allowed is %u.\n", MAX_CODED);
ERROR_MSG(_T("\nError: too many LangStrings. Maximum allowed is %u.\n"), MAX_CODED);
return PS_ERROR;
}
@ -699,7 +728,7 @@ int CEXEBuild::GenerateLangTables() {
#undef ADD_FONT
}
catch (exception& err) {
ERROR_MSG("\nError while applying font: %s\n", err.what());
ERROR_MSG(_T("\nError while applying font: %s\n"), err.what());
return PS_ERROR;
}
}
@ -715,7 +744,7 @@ int CEXEBuild::GenerateLangTables() {
{
lt[i].dlg_offset = cur_offset;
char *font = lt[i].nlf.m_szFont;
TCHAR *font = lt[i].nlf.m_szFont;
if (*build_font) font = 0;
try {
@ -762,7 +791,7 @@ int CEXEBuild::GenerateLangTables() {
#undef ADD_FONT
}
catch (exception& err) {
ERROR_MSG("\nError while applying NLF font/RTL: %s\n", err.what());
ERROR_MSG(_T("\nError while applying NLF font/RTL: %s\n"), err.what());
return PS_ERROR;
}
@ -784,7 +813,7 @@ int CEXEBuild::GenerateLangTables() {
set_uninstall_mode(orig_uninstall_mode);
SCRIPT_MSG("Done!\n");
SCRIPT_MSG(_T("Done!\n"));
return PS_OK;
}
@ -810,30 +839,30 @@ void CEXEBuild::FillLanguageTable(LanguageTable *table) {
int sn, index;
int pos = build_langstrings.get(NLFStrings[i].szLangStringName, &sn, &index);
if (pos >= 0) {
const char *str = table->lang_strings->get(sn);
const TCHAR *str = table->lang_strings->get(sn);
if (!str || !*str) {
const char *us = UserInnerStrings.get(i);
const TCHAR *us = UserInnerStrings.get(i);
if (i == NLF_NAME_DA && (!us || !*us))
{
// if the user didn't set NLF_NAME_DA we set it to $(^Name)
table->lang_strings->set(sn, "$(^Name)");
table->lang_strings->set(sn, _T("$(^Name)"));
}
if (us && *us) {
table->lang_strings->set(sn, (char *) us);
table->lang_strings->set(sn, (TCHAR *) us);
}
else {
const char *dstr = table->nlf.m_szStrings[i] ? table->nlf.m_szStrings[i] : NLFStrings[i].szDefault;
const TCHAR *dstr = table->nlf.m_szStrings[i] ? table->nlf.m_szStrings[i] : NLFStrings[i].szDefault;
if (!dstr)
continue;
if (i == NLF_BRANDING) {
char temp[NSIS_MAX_STRLEN + sizeof(NSIS_VERSION)];
sprintf(temp, dstr, NSIS_VERSION);
TCHAR temp[NSIS_MAX_STRLEN + sizeof(NSIS_VERSION)];
_stprintf(temp, dstr, NSIS_VERSION);
table->lang_strings->set(sn, temp);
continue;
}
else if (i == NLF_FONT)
{
char *font = *build_font ? build_font : table->nlf.m_szFont;
TCHAR *font = *build_font ? build_font : table->nlf.m_szFont;
if (font)
table->lang_strings->set(sn, font);
else
@ -845,8 +874,8 @@ void CEXEBuild::FillLanguageTable(LanguageTable *table) {
WORD font_size = *build_font ? (WORD) build_font_size : (WORD) table->nlf.m_iFontSize;
if (font_size)
{
char temp[64];
sprintf(temp, "%d", font_size);
TCHAR temp[64];
_stprintf(temp, _T("%d"), font_size);
table->lang_strings->set(sn, temp);
}
else
@ -860,51 +889,51 @@ void CEXEBuild::FillLanguageTable(LanguageTable *table) {
}
}
char SkipComments(FILE *f) {
TCHAR SkipComments(FILE *f) {
int c;
while ((c = fgetc(f))) {
while (c == '\n' || c == '\r') {
c = fgetc(f); // Skip empty lines
while ((c = _fgettc(f))) {
while (c == _T('\n') || c == _T('\r')) {
c = _fgettc(f); // Skip empty lines
}
if (c == '#' || c == ';') {
while ((c = fgetc(f))) {
if (c == '\n') break;
if (c == _T('#') || c == _T(';')) {
while ((c = _fgettc(f))) {
if (c == _T('\n')) break;
}
}
else break;
}
return (char) c;
return (TCHAR) c;
}
// NSIS Language File parser
LanguageTable * CEXEBuild::LoadLangFile(char *filename) {
FILE *f = FOPEN(filename, "r");
LanguageTable * CEXEBuild::LoadLangFile(TCHAR *filename) {
FILE *f = FOPEN(filename, _T("r"));
if (!f) {
ERROR_MSG("Error: Can't open language file - \"%s\"!\n",filename);
ERROR_MSG(_T("Error: Can't open language file - \"%s\"!\n"),filename);
return 0;
}
// Check header
char buf[NSIS_MAX_STRLEN];
TCHAR buf[NSIS_MAX_STRLEN];
buf[0] = SkipComments(f);
fgets(buf+1, NSIS_MAX_STRLEN, f);
_fgetts(buf+1, NSIS_MAX_STRLEN, f);
if (strncmp(buf, "NLF v", 5)) {
ERROR_MSG("Error: Invalid language file.\n");
if (_tcsncmp(buf, _T("NLF v"), 5)) {
ERROR_MSG(_T("Error: Invalid language file.\n"));
return 0;
}
int nlf_version = atoi(buf+5);
int nlf_version = _ttoi(buf+5);
if (nlf_version != NLF_VERSION) {
if (nlf_version != 2 && nlf_version != 3 && nlf_version != 4 && nlf_version != 5) {
ERROR_MSG("Error: Language file version doesn't match NSIS version.\n");
ERROR_MSG(_T("Error: Language file version doesn't match NSIS version.\n"));
return 0;
}
}
// Get language ID
buf[0] = SkipComments(f);
fgets(buf+1, NSIS_MAX_STRLEN, f);
LANGID lang_id = atoi(buf);
_fgetts(buf+1, NSIS_MAX_STRLEN, f);
LANGID lang_id = _ttoi(buf);
// Get appropriate table
LanguageTable *table = GetLangTable(lang_id);
@ -914,32 +943,32 @@ LanguageTable * CEXEBuild::LoadLangFile(char *filename) {
NLF *nlf = &table->nlf;
if (nlf->m_bLoaded) {
ERROR_MSG("Error: can't load same language file twice.\n");
ERROR_MSG(_T("Error: can't load same language file twice.\n"));
return 0;
}
// Generate language name
char *p, *p2, t = 0;
TCHAR *p, *p2, t = 0;
p = strrchr(filename, '.');
p = _tcsrchr(filename, _T('.'));
if (p) {
t = *p;
*p = 0;
}
p2 = strrchr(filename, '\\');
p2 = _tcsrchr(filename, _T('\\'));
if (p2) {
p2++;
nlf->m_szName = (char*)malloc(strlen(p2)+1);
strcpy(nlf->m_szName, p2);
nlf->m_szName = (TCHAR*)malloc((_tcsclen(p2)+1)*sizeof(TCHAR));
_tcscpy(nlf->m_szName, p2);
}
else {
nlf->m_szName = (char*)malloc(strlen(filename)+1);
strcpy(nlf->m_szName, filename);
nlf->m_szName = (TCHAR*)malloc((_tcsclen(filename)+1)*sizeof(TCHAR));
_tcscpy(nlf->m_szName, filename);
}
if (p) *p = t;
if (nlf_version != NLF_VERSION) {
warning_fl("%s language file version doesn't match. Using default English texts for missing strings.", nlf->m_szName);
warning_fl(_T("%s language file version doesn't match. Using default English texts for missing strings."), nlf->m_szName);
}
// set ^Language
@ -949,48 +978,48 @@ LanguageTable * CEXEBuild::LoadLangFile(char *filename) {
// Get font
buf[0] = SkipComments(f);
fgets(buf+1, NSIS_MAX_STRLEN, f);
_fgetts(buf+1, NSIS_MAX_STRLEN, f);
if (!nlf->m_szFont) {
temp=strlen(buf);
while (buf[temp-1] == '\n' || buf[temp-1] == '\r') {
temp=_tcsclen(buf);
while (buf[temp-1] == _T('\n') || buf[temp-1] == _T('\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 (buf[0] != _T('-') || buf[1] != 0) {
nlf->m_szFont = (TCHAR*)malloc((_tcsclen(buf)+1)*sizeof(TCHAR));
_tcscpy(nlf->m_szFont, buf);
}
}
buf[0] = SkipComments(f);
fgets(buf+1, NSIS_MAX_STRLEN, f);
_fgetts(buf+1, NSIS_MAX_STRLEN, f);
if (!nlf->m_iFontSize) {
if (buf[0] != '-' || buf[1] != 0) {
nlf->m_iFontSize = atoi(buf);
if (buf[0] != _T('-') || buf[1] != 0) {
nlf->m_iFontSize = _ttoi(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) {
nlf->m_uCodePage = atoi(buf);
_fgetts(buf+1, NSIS_MAX_STRLEN, f);
if (buf[0] != _T('-') || buf[1] != 0) {
nlf->m_uCodePage = _ttoi(buf);
if (!IsValidCodePage(nlf->m_uCodePage))
nlf->m_uCodePage = CP_ACP;
}
// Get RTL setting
nlf->m_szStrings[NLF_RTL] = (char *)malloc(2);
nlf->m_szStrings[NLF_RTL] = (TCHAR *)malloc(2*sizeof(TCHAR));
nlf->m_bRTL = false;
buf[0] = SkipComments(f);
fgets(buf+1, NSIS_MAX_STRLEN, f);
if (buf[0] == 'R' && buf[1] == 'T' && buf[2] == 'L' && (!buf[3] || buf[3] == '\r' || buf[3] == '\n')) {
_fgetts(buf+1, NSIS_MAX_STRLEN, f);
if (buf[0] == _T('R') && buf[1] == _T('T') && buf[2] == _T('L') && (!buf[3] || buf[3] == _T('\r') || buf[3] == _T('\n'))) {
nlf->m_bRTL = true;
strcpy(nlf->m_szStrings[NLF_RTL], "1");
_tcscpy(nlf->m_szStrings[NLF_RTL], _T("1"));
}
else {
strcpy(nlf->m_szStrings[NLF_RTL], "0");
_tcscpy(nlf->m_szStrings[NLF_RTL], _T("0"));
}
// Read strings
@ -1045,42 +1074,42 @@ LanguageTable * CEXEBuild::LoadLangFile(char *filename) {
buf[0] = SkipComments(f);
fgets(buf+1, NSIS_MAX_STRLEN, f);
if (strlen(buf) == NSIS_MAX_STRLEN-1) {
ERROR_MSG("Error: String too long (string #%d - \"%s\")", i, NLFStrings[i].szLangStringName);
_fgetts(buf+1, NSIS_MAX_STRLEN, f);
if (_tcsclen(buf) == NSIS_MAX_STRLEN-1) {
ERROR_MSG(_T("Error: String too long (string #%d - \"%s\")"), i, NLFStrings[i].szLangStringName);
return 0;
}
temp=strlen(buf);
temp=_tcsclen(buf);
while (buf[temp-1] == '\n' || buf[temp-1] == '\r') {
while (buf[temp-1] == _T('\n') || buf[temp-1] == _T('\r')) {
buf[--temp] = 0;
}
char *in = buf;
TCHAR *in = buf;
// trim quotes
if (buf[0] == '"' && buf[temp-1] == '"') {
if (buf[0] == _T('"') && buf[temp-1] == _T('"')) {
in++;
buf[--temp] = 0;
}
nlf->m_szStrings[i] = (char*)malloc(temp+1);
char *out;
nlf->m_szStrings[i] = (TCHAR*)malloc((temp+1)*sizeof(TCHAR));
TCHAR *out;
for (out = nlf->m_szStrings[i]; *in; in++, out++) {
if (*in == '\\') {
if (*in == _T('\\')) {
in++;
switch (*in) {
case 'n':
*out = '\n';
case _T('n'):
*out = _T('\n');
break;
case 'r':
*out = '\r';
case _T('r'):
*out = _T('\r');
break;
case 't':
*out = '\t';
case _T('t'):
*out = _T('\t');
break;
default:
*out++ = '\\';
*out++ = _T('\\');
*out = *in;
}
}