Browse Source

language: Fix codepage used for Inno Setup 4.0.0 to 4.2.2

Currently the codepage is only used to decode messages and the language
name.
pull/108/head
Daniel Scharrer 7 years ago
parent
commit
684eccfb32
  1. 112
      src/setup/language.cpp

112
src/setup/language.cpp

@ -20,11 +20,105 @@
#include "setup/language.hpp"
#include <algorithm>
#include "boost/range/begin.hpp"
#include "boost/range/end.hpp"
#include "setup/version.hpp"
#include "util/load.hpp"
namespace setup {
namespace {
struct windows_language {
boost::uint16_t language_id;
boost::uint16_t codepage;
bool operator<(boost::uint32_t language) {
return language_id < language;
}
};
/*
* Sorted list of Windows language IDs with their default ANSI codepages.
* This list omits unicode-only languages and languages using the default Windows-1252 codepage.
*/
windows_language languages[] = {
{ 0x0401, 1256 },
{ 0x0402, 1251 },
{ 0x0404, 950 },
{ 0x0405, 1250 },
{ 0x0408, 1253 },
{ 0x040d, 1255 },
{ 0x040e, 1250 },
{ 0x0411, 932 },
{ 0x0412, 949 },
{ 0x0415, 1250 },
{ 0x0418, 1250 },
{ 0x0419, 1251 },
{ 0x041a, 1250 },
{ 0x041b, 1250 },
{ 0x041c, 1250 },
{ 0x041e, 874 },
{ 0x041f, 1254 },
{ 0x0420, 1256 },
{ 0x0422, 1251 },
{ 0x0423, 1251 },
{ 0x0424, 1250 },
{ 0x0425, 1257 },
{ 0x0426, 1257 },
{ 0x0427, 1257 },
{ 0x0429, 1256 },
{ 0x042a, 1258 },
{ 0x042c, 1254 },
{ 0x042f, 1251 },
{ 0x043f, 1251 },
{ 0x0440, 1251 },
{ 0x0443, 1254 },
{ 0x0444, 1251 },
{ 0x0450, 1251 },
{ 0x0492, 28604 },
{ 0x0801, 1256 },
{ 0x0804, 936 },
{ 0x081a, 1250 },
{ 0x082c, 1251 },
{ 0x0843, 1251 },
{ 0x0c01, 1256 },
{ 0x0c04, 950 },
{ 0x0c1a, 1251 },
{ 0x1001, 1256 },
{ 0x1004, 936 },
{ 0x1401, 1256 },
{ 0x1404, 950 },
{ 0x1801, 1256 },
{ 0x1c01, 1256 },
{ 0x2001, 1256 },
{ 0x2401, 1256 },
{ 0x2801, 1256 },
{ 0x2c01, 1256 },
{ 0x3001, 1256 },
{ 0x3401, 1256 },
{ 0x3801, 1256 },
{ 0x3c01, 1256 },
{ 0x4001, 1256 },
};
util::codepage_id default_codepage_for_language(boost::uint32_t language) {
windows_language * entry = std::lower_bound(boost::begin(languages), boost::end(languages), language);
if(entry != boost::end(languages) && entry->language_id == language) {
return entry->codepage;
}
return util::cp_windows1252;
}
} // anonymous namespace
void language_entry::load(std::istream & is, const version & version) {
if(version >= INNO_VERSION(4, 0, 0)) {
@ -33,7 +127,7 @@ void language_entry::load(std::istream & is, const version & version) {
name = "default";
}
is >> util::encoded_string(language_name, (version >= INNO_VERSION(4, 2, 2)) ? 1200u : 1252u);
is >> util::binary_string(language_name);
if(version == INNO_VERSION_EXT(5, 5, 7, 1)) {
util::load<boost::uint32_t>(is); // always 0?
@ -58,13 +152,21 @@ void language_entry::load(std::istream & is, const version & version) {
language_id = util::load<boost::uint32_t>(is);
if(version >= INNO_VERSION(4, 2, 2) && (version < INNO_VERSION(5, 3, 0) || !version.is_unicode())) {
if(version < INNO_VERSION(4, 2, 2)) {
codepage = default_codepage_for_language(language_id);
} else if(version < INNO_VERSION(5, 3, 0) || !version.is_unicode()) {
codepage = util::load<boost::uint32_t>(is);
if(!codepage) {
codepage = version.codepage();
}
} else {
codepage = 0;
codepage = util::cp_utf16le;
}
if(!codepage) {
codepage = version.codepage();
if(version >= INNO_VERSION(4, 2, 2)) {
util::to_utf8(language_name, util::cp_utf16le);
} else {
util::to_utf8(language_name, codepage);
}
dialog_font_size = util::load<boost::uint32_t>(is);

Loading…
Cancel
Save