diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game/game.hpp | 5 | ||||
-rw-r--r-- | src/game/game_core.cpp | 5 | ||||
-rw-r--r-- | src/game/game_text.cpp | 59 |
3 files changed, 35 insertions, 34 deletions
diff --git a/src/game/game.hpp b/src/game/game.hpp index 66a155bd5..faa9650bf 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -112,11 +112,6 @@ public: */ static class GameInstance *GetInstance() { return Game::instance; } - /** - * Get the current active mainscript. - */ - static const char *GetMainScript(); - #if defined(ENABLE_NETWORK) /** Wrapper function for GameScanner::HasGame */ static bool HasGame(const struct ContentInfo *ci, bool md5sum); diff --git a/src/game/game_core.cpp b/src/game/game_core.cpp index 6f301d35a..e1a21872a 100644 --- a/src/game/game_core.cpp +++ b/src/game/game_core.cpp @@ -27,11 +27,6 @@ /* static */ GameScannerInfo *Game::scanner_info = NULL; /* static */ GameScannerLibrary *Game::scanner_library = NULL; -/* static */ const char *Game::GetMainScript() -{ - return Game::info->GetMainScript(); -} - /* static */ void Game::GameLoop() { if (_networking && !_network_server) return; diff --git a/src/game/game_text.cpp b/src/game/game_text.cpp index 07388c842..07b8a323d 100644 --- a/src/game/game_text.cpp +++ b/src/game/game_text.cpp @@ -13,10 +13,12 @@ #include "../strgen/strgen.h" #include "../debug.h" #include "../fileio_func.h" +#include "../tar_type.h" #include "../script/squirrel_class.hpp" #include "../strings_func.h" #include "game_text.hpp" #include "game.hpp" +#include "game_info.hpp" #include "table/strings.h" @@ -208,22 +210,6 @@ struct StringNameWriter : HeaderWriter { } }; -static void GetBasePath(char *buffer, size_t length) -{ - strecpy(buffer, Game::GetMainScript(), buffer + length); - char *s = strrchr(buffer, PATHSEPCHAR); - if (s != NULL) { - /* Keep the PATHSEPCHAR there, remove the rest */ - s++; - *s = '\0'; - } - - /* Tars dislike opening files with '/' on Windows.. so convert it to '\\' */ -#if (PATHSEPCHAR != '/') - for (char *n = buffer; *n != '\0'; n++) if (*n == '/') *n = PATHSEPCHAR; -#endif -} - /** * Scanner to find language files in a GameScript directory. */ @@ -260,20 +246,45 @@ public: */ GameStrings *LoadTranslations() { + const GameInfo *info = Game::GetInfo(); + char filename[512]; + strecpy(filename, info->GetMainScript(), lastof(filename)); + char *e = strrchr(filename, PATHSEPCHAR); + if (e == NULL) return NULL; + e++; // Make 'e' point after the PATHSEPCHAR + + strecpy(e, "lang" PATHSEP "english.txt", lastof(filename)); + if (!FioCheckFileExists(filename, GAME_DIR)) return NULL; + GameStrings *gs = new GameStrings(); try { - char filename[512]; - GetBasePath(filename, sizeof(filename)); - char *e = filename + strlen(filename); - - seprintf(e, filename + sizeof(filename), "lang" PATHSEP "english.txt"); - if (!FioCheckFileExists(filename, GAME_DIR)) throw std::exception(); *gs->raw_strings.Append() = ReadRawLanguageStrings(filename); /* Scan for other language files */ LanguageScanner scanner(gs, filename); - strecpy(e, "lang" PATHSEP, filename + sizeof(filename)); - scanner.Scan(filename); + strecpy(e, "lang" PATHSEP, lastof(filename)); + uint len = strlen(filename); + + const char *tar_filename = info->GetTarFile(); + TarList::iterator iter; + if (tar_filename != NULL && (iter = _tar_list[GAME_DIR].find(tar_filename)) != _tar_list[GAME_DIR].end()) { + /* The main script is in a tar file, so find all files that + * are in the same tar and add them to the langfile scanner. */ + TarFileList::iterator tar; + FOR_ALL_TARS(tar, GAME_DIR) { + /* Not in the same tar. */ + if (tar->second.tar_filename != iter->first) continue; + + /* Check the path and extension. */ + if (tar->first.size() <= len || tar->first.compare(0, len, filename) != 0) continue; + if (tar->first.compare(tar->first.size() - 4, 4, ".txt") != 0) continue; + + scanner.AddFile(tar->first.c_str(), 0, tar_filename); + } + } else { + /* Scan filesystem */ + scanner.Scan(filename); + } gs->Compile(); return gs; |