diff options
author | Thierry Crozat | 2011-06-22 22:41:57 +0100 |
---|---|---|
committer | Thierry Crozat | 2011-06-22 22:48:08 +0100 |
commit | 2109fc7a3c2f0e6c64401a07f24d292526ddbf2a (patch) | |
tree | 7c1035576fa36b002c7a21260842033e69150c40 | |
parent | 52d91368af89541284fbc525ff1357c5e38cb071 (diff) | |
download | scummvm-rg350-2109fc7a3c2f0e6c64401a07f24d292526ddbf2a.tar.gz scummvm-rg350-2109fc7a3c2f0e6c64401a07f24d292526ddbf2a.tar.bz2 scummvm-rg350-2109fc7a3c2f0e6c64401a07f24d292526ddbf2a.zip |
COMMON: Improve loading of translations data file
Now if the header of the file is not correct it continues to look for a
valid file, while before if the first file found was obsolete or corrupted
translation was disabled even if a valid file was present in the search
path.
-rw-r--r-- | common/translation.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/common/translation.cpp b/common/translation.cpp index 526bebcec6..59488c2dd5 100644 --- a/common/translation.cpp +++ b/common/translation.cpp @@ -223,9 +223,17 @@ String TranslationManager::getLangById(int id) const { } bool TranslationManager::openTranslationsFile(File& inFile) { - // First try to open it directly (i.e. using the SearchMan). - if (inFile.open("translations.dat")) - return true; + // First try to open it using the SearchMan. + ArchiveMemberList fileList; + SearchMan.listMatchingMembers(fileList, "translations.dat"); + for (ArchiveMemberList::iterator it = fileList.begin(); it != fileList.end(); ++it) { + SeekableReadStream *stream = it->get()->createReadStream(); + if (stream && inFile.open(stream, it->get()->getName())) { + if (checkHeader(inFile)) + return true; + inFile.close(); + } + } // Then look in the Themepath if we can find the file. if (ConfMan.hasKey("themepath")) @@ -243,8 +251,11 @@ bool TranslationManager::openTranslationsFile(const FSNode &node, File& inFile, // necessary to make them here. But it avoid printing warnings. FSNode fileNode = node.getChild("translations.dat"); if (fileNode.exists() && fileNode.isReadable() && !fileNode.isDirectory()) { - if (inFile.open(fileNode)) - return true; + if (inFile.open(fileNode)) { + if (checkHeader(inFile)) + return true; + inFile.close(); + } } // Check if we exceeded the given recursion depth @@ -268,13 +279,10 @@ bool TranslationManager::openTranslationsFile(const FSNode &node, File& inFile, void TranslationManager::loadTranslationsInfoDat() { File in; if (!openTranslationsFile(in)) { - warning("You are missing the 'translations.dat' file. GUI translation will not be available"); + warning("You are missing a valid 'translations.dat' file. GUI translation will not be available"); return; } - if (!checkHeader(in)) - return; - char buf[256]; int len; @@ -326,9 +334,6 @@ void TranslationManager::loadLanguageDat(int index) { if (!openTranslationsFile(in)) return; - if (!checkHeader(in)) - return; - char buf[1024]; int len; @@ -386,7 +391,7 @@ bool TranslationManager::checkHeader(File &in) { // Check header if (strcmp(buf, "TRANSLATIONS")) { - warning("Your 'translations.dat' file is corrupt. GUI translation will not be available"); + warning("File '%s' is not a valid translations data file. Skipping this file", in.getName()); return false; } @@ -394,7 +399,7 @@ bool TranslationManager::checkHeader(File &in) { ver = in.readByte(); if (ver != TRANSLATIONS_DAT_VER) { - warning("Your 'translations.dat' file has a mismatching version, expected was %d but you got %d. GUI translation will not be available", TRANSLATIONS_DAT_VER, ver); + warning("File '%s' has a mismatching version, expected was %d but you got %d. Skipping this file", in.getName(), TRANSLATIONS_DAT_VER, ver); return false; } |