| 1 |
/* |
| 2 |
* lang.h |
| 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/30/2007 |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef ___NLF___H_____ |
| 20 |
#define ___NLF___H_____ |
| 21 |
|
| 22 |
#include "strlist.h" |
| 23 |
#include "growbuf.h" |
| 24 |
#include "exehead/fileform.h" |
| 25 |
|
| 26 |
struct NLFRef { |
| 27 |
int iRef; |
| 28 |
int iUnRef; |
| 29 |
}; |
| 30 |
|
| 31 |
struct langstring { |
| 32 |
int name; |
| 33 |
int sn; |
| 34 |
int index; |
| 35 |
int uindex; |
| 36 |
int process; |
| 37 |
}; |
| 38 |
|
| 39 |
class LangStringList : public SortedStringListND<struct langstring> |
| 40 |
{ |
| 41 |
public: |
| 42 |
/* Default constructor */ |
| 43 |
LangStringList() : m_count(0) {} |
| 44 |
|
| 45 |
/** |
| 46 |
* Adds a langstring struct with the string name of 'name' into this |
| 47 |
* structure. |
| 48 |
* |
| 49 |
* @param name The string to use as key. |
| 50 |
* @param sn [out] The string number. |
| 51 |
* @return Returns the position where T was stored. |
| 52 |
*/ |
| 53 |
int add(const TCHAR *name, int *sn=0); |
| 54 |
|
| 55 |
/** |
| 56 |
* Gets the values in the langstring struct that is mapped to the string |
| 57 |
* 'name'. Sets sn, index, and uindex to -1 before looking for the |
| 58 |
* 'name'. If not found, -1 is returned. If found, then the values |
| 59 |
* associated with 'name' are set to the sn, index, uindex, process |
| 60 |
* variables. |
| 61 |
* |
| 62 |
* TODO: Need better documentation here. |
| 63 |
* @param sn [out] Set to string ID number. |
| 64 |
* @param index [out] Set to index value in langstring. |
| 65 |
* @param uindex [out] Set to uindex value in langstring. |
| 66 |
* @param process [out] Set to process value in langstring. |
| 67 |
* @return The index into langstring array. -1 if not found. |
| 68 |
*/ |
| 69 |
int get(const TCHAR *name, int *sn=0, int *index=0, int *uindex=0, int *process=0); |
| 70 |
|
| 71 |
/** |
| 72 |
* Sets the values in the langstring struct that is in the position 'pos'. |
| 73 |
* |
| 74 |
* @param pos The langstring index into m_gr. |
| 75 |
* @param index Value to set langstring[pos].index. |
| 76 |
* @param uindex Value to set langstring[pos].uindex. |
| 77 |
* @param process Value to set langstring[pos].process. |
| 78 |
*/ |
| 79 |
void set(int pos, int index=-1, int uindex=-1, int process=-1); |
| 80 |
|
| 81 |
/** |
| 82 |
* Sets the values in the langstring struct that is mapped to the string |
| 83 |
* 'name'. |
| 84 |
* |
| 85 |
* @param name The string key to lookup langstring. |
| 86 |
* @param index Value to set langstring[pos].index. |
| 87 |
* @param uindex Value to set langstring[pos].uindex. |
| 88 |
* @param process Value to set langstring[pos].process. |
| 89 |
*/ |
| 90 |
void set(const TCHAR *name, int index, int uindex=-1, int process=-1); |
| 91 |
|
| 92 |
/** |
| 93 |
* From the position index, get the pointer to the key string. |
| 94 |
* Basically, get the string referenced by langstring[pos].name. |
| 95 |
* |
| 96 |
* @param pos The position index. |
| 97 |
* @return The TCHAR* to the string referenced by pos. |
| 98 |
*/ |
| 99 |
const TCHAR *pos2name(int pos); |
| 100 |
|
| 101 |
/** |
| 102 |
* From the index into the strings, get the pointer to the |
| 103 |
* key string. Note: the positional index into the storage of |
| 104 |
* key strings probably should not be exposed to the outside. |
| 105 |
* |
| 106 |
* @param name Index into the m_strings array. |
| 107 |
* @return The TCHAR* to the string referenced by name. |
| 108 |
*/ |
| 109 |
const TCHAR *offset2name(int name); |
| 110 |
|
| 111 |
/** |
| 112 |
* Get the number of entries. |
| 113 |
* |
| 114 |
* @return The number of langstring entries. |
| 115 |
*/ |
| 116 |
int getnum(); |
| 117 |
|
| 118 |
/** |
| 119 |
* Compare two langstring structs pointed by item1 and item2 by looking at |
| 120 |
* their .index values via their difference (item1->index - item2->index). |
| 121 |
* |
| 122 |
* @return 0 if equal, negative value if item1 is smaller, positive value |
| 123 |
* if item1 is bigger. |
| 124 |
*/ |
| 125 |
static int compare_index(const void *item1, const void *item2); |
| 126 |
|
| 127 |
/** |
| 128 |
* Sorts the langstrings by their index. Then return the sorted array |
| 129 |
* via m_sortbuf. Warning: This function is not thread-safe! |
| 130 |
* |
| 131 |
* @param num [out] Set to the size of langstring items in the array. |
| 132 |
* @return The sorted langstring array via m_sortbuf. |
| 133 |
*/ |
| 134 |
langstring *sort_index(int *num); |
| 135 |
|
| 136 |
/** |
| 137 |
* Compare two langstring structs pointed by item1 and item2 by looking at |
| 138 |
* their .uindex values via their difference (item1->uindex - item2->uindex). |
| 139 |
* |
| 140 |
* @return 0 if equal, negative value if item1 is smaller, positive value |
| 141 |
* if item1 is bigger. |
| 142 |
*/ |
| 143 |
static int compare_uindex(const void *item1, const void *item2); |
| 144 |
|
| 145 |
/** |
| 146 |
* Sorts the langstrings by their index. Then return the sorted array |
| 147 |
* via m_sortbuf. Warning: This function is not thread-safe! |
| 148 |
* |
| 149 |
* @param num [out] Set to the size of langstring items in the array. |
| 150 |
* @return The sorted langstring array via m_sortbuf. |
| 151 |
*/ |
| 152 |
langstring *sort_uindex(int *num); |
| 153 |
|
| 154 |
private: |
| 155 |
int m_count; // Used to set string number (sn) |
| 156 |
TinyGrowBuf m_sortbuf; // Used only to sort. |
| 157 |
}; |
| 158 |
|
| 159 |
/** |
| 160 |
* This class implements an array of C-style strings in a flat buffer. |
| 161 |
* |
| 162 |
* Implementation: Resetting the string at a particular index does not delete |
| 163 |
* the old string. Instead a new string is added to the end of m_strings and |
| 164 |
* the old string can no longer be looked up. |
| 165 |
*/ |
| 166 |
class StringsArray |
| 167 |
{ |
| 168 |
public: |
| 169 |
StringsArray(); |
| 170 |
|
| 171 |
/** |
| 172 |
* Resizes the m_offsets so that the index num is valid. |
| 173 |
* |
| 174 |
* @param num New size. |
| 175 |
*/ |
| 176 |
void resize(int num); |
| 177 |
|
| 178 |
/** |
| 179 |
* Set the string 'str' at index idx. This class cannot really delete |
| 180 |
* strings. It can "overwrite" them in the sense that the string is no |
| 181 |
* longer referenceable via the index but they are never gone. |
| 182 |
* |
| 183 |
* @param idx The index position to set the string to. |
| 184 |
* @param str The string value to set. |
| 185 |
* @return If overwriting, the position in m_strings of the old string. |
| 186 |
*/ |
| 187 |
int set(int idx, const TCHAR *str); |
| 188 |
|
| 189 |
/** |
| 190 |
* Get the string at index 'idx'. |
| 191 |
* |
| 192 |
* @param idx The logical index to the string. |
| 193 |
* @return Returns the TCHAR* to the string. |
| 194 |
*/ |
| 195 |
const TCHAR *get(int idx); |
| 196 |
|
| 197 |
private: |
| 198 |
TinyGrowBuf m_offsets; /* Positional offsets of the stored string. */ |
| 199 |
GrowBuf m_strings; /* Storage of the actual strings. */ |
| 200 |
}; |
| 201 |
|
| 202 |
#define NLF_VERSION 6 |
| 203 |
|
| 204 |
enum { |
| 205 |
NLF_BRANDING, |
| 206 |
NLF_CAPTION, |
| 207 |
NLF_UCAPTION, |
| 208 |
NLF_SUBCAPTION_LICENSE, |
| 209 |
NLF_SUBCAPTION_OPTIONS, |
| 210 |
NLF_SUBCAPTION_DIR, |
| 211 |
NLF_SUBCAPTION_INSTFILES, |
| 212 |
NLF_SUBCAPTION_COMPLETED, |
| 213 |
NLF_USUBCAPTION_OPTIONS, |
| 214 |
NLF_USUBCAPTION_DIR, |
| 215 |
NLF_USUBCAPTION_CONFIRM, |
| 216 |
NLF_USUBCAPTION_INSTFILES, |
| 217 |
NLF_USUBCAPTION_COMPLETED, |
| 218 |
NLF_BTN_BACK, |
| 219 |
NLF_BTN_NEXT, |
| 220 |
NLF_BTN_LICENSE, |
| 221 |
NLF_BTN_LICENSE_AGREE, |
| 222 |
NLF_BTN_LICENSE_DISAGREE, |
| 223 |
NLF_BTN_INSTALL, |
| 224 |
NLF_BTN_UNINSTALL, |
| 225 |
NLF_BTN_CANCEL, |
| 226 |
NLF_BTN_CLOSE, |
| 227 |
NLF_BTN_BROWSE, |
| 228 |
NLF_BTN_DETAILS, |
| 229 |
NLF_CLICK_NEXT, |
| 230 |
NLF_CLICK_INSTALL, |
| 231 |
NLF_CLICK_UNINSTALL, |
| 232 |
NLF_NAME, |
| 233 |
NLF_NAME_DA, // name with doubled ampersands - virtual |
| 234 |
NLF_COMPLETED, |
| 235 |
NLF_LICENSE_TEXT, |
| 236 |
NLF_LICENSE_TEXT_FSCB, |
| 237 |
NLF_LICENSE_TEXT_FSRB, |
| 238 |
NLF_ULICENSE_TEXT, |
| 239 |
NLF_ULICENSE_TEXT_FSCB, |
| 240 |
NLF_ULICENSE_TEXT_FSRB, |
| 241 |
NLF_LICENSE_DATA, // virtual |
| 242 |
NLF_COMP_CUSTOM, |
| 243 |
NLF_COMP_TEXT, |
| 244 |
NLF_COMP_SUBTEXT1, |
| 245 |
NLF_COMP_SUBTEXT1_NO_INST_TYPES, |
| 246 |
NLF_COMP_SUBTEXT2, |
| 247 |
NLF_UCOMP_TEXT, |
| 248 |
NLF_UCOMP_SUBTEXT1, |
| 249 |
NLF_UCOMP_SUBTEXT1_NO_INST_TYPES, |
| 250 |
NLF_UCOMP_SUBTEXT2, |
| 251 |
NLF_DIR_TEXT, |
| 252 |
NLF_DIR_SUBTEXT, |
| 253 |
NLF_DIR_BROWSETEXT, |
| 254 |
NLF_UDIR_TEXT, |
| 255 |
NLF_UDIR_SUBTEXT, |
| 256 |
NLF_UDIR_BROWSETEXT, |
| 257 |
NLF_SPACE_AVAIL, |
| 258 |
NLF_SPACE_REQ, |
| 259 |
NLF_UNINST_TEXT, |
| 260 |
NLF_UNINST_SUBTEXT, |
| 261 |
NLF_FILE_ERROR, |
| 262 |
NLF_FILE_ERROR_NOIGNORE, |
| 263 |
NLF_CANT_WRITE, |
| 264 |
NLF_COPY_FAILED, |
| 265 |
NLF_COPY_TO, |
| 266 |
NLF_REGISTERING, |
| 267 |
NLF_UNREGISTERING, |
| 268 |
NLF_SYMBOL_NOT_FOUND, |
| 269 |
NLF_COULD_NOT_LOAD, |
| 270 |
NLF_CREATE_DIR, |
| 271 |
NLF_CREATE_SHORTCUT, |
| 272 |
NLF_CREATED_UNINST, |
| 273 |
NLF_DEL_FILE, |
| 274 |
NLF_DEL_ON_REBOOT, |
| 275 |
NLF_ERR_CREATING_SHORTCUT, |
| 276 |
NLF_ERR_CREATING, |
| 277 |
NLF_ERR_DECOMPRESSING, |
| 278 |
NLF_ERR_REG_DLL, |
| 279 |
NLF_EXEC_SHELL, |
| 280 |
NLF_EXEC, |
| 281 |
NLF_EXTRACT, |
| 282 |
NLF_ERR_WRITING, |
| 283 |
NLF_INST_CORRUPTED, |
| 284 |
NLF_NO_OLE, |
| 285 |
NLF_OUTPUT_DIR, |
| 286 |
NLF_REMOVE_DIR, |
| 287 |
NLF_RENAME_ON_REBOOT, |
| 288 |
NLF_RENAME, |
| 289 |
NLF_SKIPPED, |
| 290 |
NLF_COPY_DETAILS, |
| 291 |
NLF_LOG_INSTALL_PROCESS, |
| 292 |
NLF_BYTE, |
| 293 |
NLF_KILO, |
| 294 |
NLF_MEGA, |
| 295 |
NLF_GIGA, |
| 296 |
|
| 297 |
NLF_STRINGS_NO_SPECIAL, |
| 298 |
|
| 299 |
NLF_FONT = NLF_STRINGS_NO_SPECIAL, |
| 300 |
NLF_FONTSIZE, |
| 301 |
NLF_RTL, |
| 302 |
NLF_LANGUAGE, |
| 303 |
|
| 304 |
NLF_STRINGS |
| 305 |
}; |
| 306 |
|
| 307 |
struct NLF { |
| 308 |
bool m_bLoaded; /* Is the table loaded? */ |
| 309 |
TCHAR *m_szName; /* The language name */ |
| 310 |
TCHAR *m_szFont; |
| 311 |
int m_iFontSize; |
| 312 |
unsigned int m_uCodePage; /* Code page associated with language. When |
| 313 |
* using Unicode, this value will be 1200. |
| 314 |
*/ |
| 315 |
bool m_bRTL; /* Is this a right-to-left language like Hebrew? */ |
| 316 |
TCHAR *m_szStrings[NLF_STRINGS]; |
| 317 |
}; |
| 318 |
|
| 319 |
/** |
| 320 |
* LanguageTable stores within the lang_strings, all the user strings and |
| 321 |
* variables for that specific language. |
| 322 |
*/ |
| 323 |
struct LanguageTable { |
| 324 |
LANGID lang_id; /* Windows Language ID identifier */ |
| 325 |
|
| 326 |
int dlg_offset; |
| 327 |
|
| 328 |
StringsArray *lang_strings; |
| 329 |
|
| 330 |
NLF nlf; |
| 331 |
}; |
| 332 |
|
| 333 |
#endif |