MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / Load

Method Load

engine/Poseidon/UI/Controls/UIControlsExt.cpp:1276–1339  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1274}
1275
1276void CHTMLContainer::Load(const char* filename, bool add)
1277{
1278 if (!QIFStreamB::FileExist(filename))
1279 {
1280 // try to find alternate location
1281 RString fullname = Poseidon::GetMissionDirectory() + _filename;
1282 if (QIFStreamB::FileExist(fullname))
1283 {
1284 filename = _filename = fullname;
1285 }
1286 else
1287 {
1288 fullname = Poseidon::GetBaseDirectory() + _filename;
1289 if (QIFStreamB::FileExist(fullname))
1290 {
1291 filename = _filename = fullname;
1292 }
1293 else
1294 {
1295 return;
1296 }
1297 }
1298 }
1299
1300 // Slurp the whole file. Mission/overview HTML is small (a few KB) and we
1301 // need an in-memory copy anyway to transcode legacy codepages to UTF-8
1302 // before parsing — the parser appends to RString text segments and would
1303 // otherwise leak raw W1250/W1251 bytes into the UTF-8 string pool, causing
1304 // the modern font renderer to draw garbage glyphs.
1305 //
1306 // Encoding is decided as follows:
1307 // - filename ends with ".utf8.html" → input is already UTF-8
1308 // - otherwise → use Poseidon::CodepageForLanguage(GLanguage)
1309 // (CP1250 for Czech, CP1252 for Western, CP1251 for Russian, ...)
1310 std::string utf8Buf;
1311 {
1312 QIFStreamB raw;
1313 raw.AutoOpen(filename);
1314 while (!raw.eof() && !raw.fail())
1315 {
1316 int c = raw.get();
1317 if (c < 0)
1318 break;
1319 utf8Buf.push_back(static_cast<char>(c));
1320 }
1321 const size_t flen = strlen(filename);
1322 const bool isUtf8 = flen >= 10 && stricmp(filename + flen - 10, ".utf8.html") == 0;
1323 if (!isUtf8)
1324 {
1325 const Poseidon::Codepage cp = Poseidon::CodepageForLanguage((const char*)GLanguage);
1326 utf8Buf = Poseidon::DecodeLegacyTextToUtf8(utf8Buf, cp);
1327 }
1328 }
1329
1330 // Expand `$STR_*` / `@KEY` tokens against the global stringtable
1331 // so any HTML can carry remaster localization markers — currently
1332 // used by the briefing equipment library (a single
1333 // `equipment.utf8.html` resolves all 8 UI languages via

Callers

nothing calls this directly

Calls 11

GetMissionDirectoryFunction · 0.85
GetBaseDirectoryFunction · 0.85
CodepageForLanguageFunction · 0.85
DecodeLegacyTextToUtf8Function · 0.85
AutoOpenMethod · 0.80
stricmpFunction · 0.50
RStringClass · 0.50
eofMethod · 0.45
failMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected