| 19 | } |
| 20 | |
| 21 | void CLocalizationDatabase::LoadIndexfile(IStorage *pStorage, IConsole *pConsole) |
| 22 | { |
| 23 | m_vLanguages.clear(); |
| 24 | |
| 25 | const std::vector<std::string> vEnglishLanguageCodes = {"en"}; |
| 26 | m_vLanguages.emplace_back("English", "", 826, vEnglishLanguageCodes); |
| 27 | |
| 28 | const char *pFilename = "languages/index.txt"; |
| 29 | CLineReader LineReader; |
| 30 | if(!LineReader.OpenFile(pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL))) |
| 31 | { |
| 32 | log_error("localization", "Couldn't open index file '%s'", pFilename); |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | while(const char *pLine = LineReader.Get()) |
| 37 | { |
| 38 | if(!str_length(pLine) || pLine[0] == '#') // skip empty lines and comments |
| 39 | continue; |
| 40 | |
| 41 | char aEnglishName[128]; |
| 42 | str_copy(aEnglishName, pLine); |
| 43 | |
| 44 | pLine = LineReader.Get(); |
| 45 | if(!pLine) |
| 46 | { |
| 47 | log_error("localization", "Unexpected end of index file after language '%s'", aEnglishName); |
| 48 | break; |
| 49 | } |
| 50 | if(!str_startswith(pLine, "== ")) |
| 51 | { |
| 52 | log_error("localization", "Missing native name for language '%s'", aEnglishName); |
| 53 | (void)LineReader.Get(); |
| 54 | (void)LineReader.Get(); |
| 55 | continue; |
| 56 | } |
| 57 | char aNativeName[128]; |
| 58 | str_copy(aNativeName, pLine + 3); |
| 59 | |
| 60 | pLine = LineReader.Get(); |
| 61 | if(!pLine) |
| 62 | { |
| 63 | log_error("localization", "Unexpected end of index file after language '%s'", aEnglishName); |
| 64 | break; |
| 65 | } |
| 66 | if(!str_startswith(pLine, "== ")) |
| 67 | { |
| 68 | log_error("localization", "Missing country code for language '%s'", aEnglishName); |
| 69 | (void)LineReader.Get(); |
| 70 | continue; |
| 71 | } |
| 72 | char aCountryCode[128]; |
| 73 | str_copy(aCountryCode, pLine + 3); |
| 74 | |
| 75 | pLine = LineReader.Get(); |
| 76 | if(!pLine) |
| 77 | { |
| 78 | log_error("localization", "Unexpected end of index file after language '%s'", aEnglishName); |
no test coverage detected