MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / FillLanguageList

Function FillLanguageList

src/strings.cpp:2220–2243  ·  view source on GitHub ↗

* Search for the languages in the given directory and add them to the #_languages list. * @param path the base directory to search in */

Source from the content-addressed store, hash-verified

2218 * @param path the base directory to search in
2219 */
2220static void FillLanguageList(const std::string &path)
2221{
2222 std::error_code error_code;
2223 for (const auto &dir_entry : std::filesystem::directory_iterator(OTTD2FS(path), error_code)) {
2224 if (!dir_entry.is_regular_file()) continue;
2225 if (dir_entry.path().extension() != ".lng") continue;
2226
2227 LanguageMetadata lmd;
2228 lmd.file = dir_entry.path();
2229
2230 /* Check whether the file is of the correct version */
2231 std::string file = FS2OTTD(lmd.file.native());
2232 if (!GetLanguageFileHeader(file, &lmd)) {
2233 Debug(misc, 3, "{} is not a valid language file", file);
2234 } else if (GetLanguage(lmd.newgrflangid) != nullptr) {
2235 Debug(misc, 3, "{}'s language ID is already known", file);
2236 } else {
2237 _languages.push_back(std::move(lmd));
2238 }
2239 }
2240 if (error_code) {
2241 Debug(misc, 9, "Unable to open directory {}: {}", path, error_code.message());
2242 }
2243}
2244
2245/**
2246 * Make a list of the available language packs. Put the data in

Callers 1

InitializeLanguagePacksFunction · 0.85

Calls 6

GetLanguageFileHeaderFunction · 0.85
GetLanguageFunction · 0.85
push_backMethod · 0.80
messageMethod · 0.80
OTTD2FSFunction · 0.70
FS2OTTDFunction · 0.70

Tested by

no test coverage detected