diff options
| author | Willem Jan Palenstijn | 2013-04-18 23:35:23 +0200 | 
|---|---|---|
| committer | Willem Jan Palenstijn | 2013-05-08 20:40:58 +0200 | 
| commit | 9c2341678ef4984bf92b3878295250faf980b066 (patch) | |
| tree | 2fb4805e05e16b9924e80c9947e6bad723b28c4b /common/translation.cpp | |
| parent | 8172d679df5148a4a32f46074b20cb6caf91844f (diff) | |
| parent | a5f4ff36ffc386d48f2da49387a9655ce9295a4d (diff) | |
| download | scummvm-rg350-9c2341678ef4984bf92b3878295250faf980b066.tar.gz scummvm-rg350-9c2341678ef4984bf92b3878295250faf980b066.tar.bz2 scummvm-rg350-9c2341678ef4984bf92b3878295250faf980b066.zip  | |
Merge branch 'master'
Diffstat (limited to 'common/translation.cpp')
| -rw-r--r-- | common/translation.cpp | 70 | 
1 files changed, 57 insertions, 13 deletions
diff --git a/common/translation.cpp b/common/translation.cpp index 3570e8c5ae..219fce8794 100644 --- a/common/translation.cpp +++ b/common/translation.cpp @@ -26,7 +26,7 @@  #undef ARRAYSIZE  #endif -#define TRANSLATIONS_DAT_VER 2 +#define TRANSLATIONS_DAT_VER 3  #include "common/translation.h"  #include "common/config-manager.h" @@ -45,7 +45,7 @@ bool operator<(const TLanguage &l, const TLanguage &r) {  	return strcmp(l.name, r.name) < 0;  } -TranslationManager::TranslationManager() : _currentLang(-1) { +TranslationManager::TranslationManager() : _currentLang(-1), _charmap(0) {  	loadTranslationsInfoDat();  	// Set the default language @@ -53,6 +53,7 @@ TranslationManager::TranslationManager() : _currentLang(-1) {  }  TranslationManager::~TranslationManager() { +	delete[] _charmap;  }  int32 TranslationManager::findMatchingLanguage(const String &lang) { @@ -130,14 +131,14 @@ const char *TranslationManager::getTranslation(const char *message, const char *  			// Get the range of messages with the same ID (but different context)  			leftIndex = rightIndex = midIndex;  			while ( -				leftIndex > 0 && -				_currentTranslationMessages[leftIndex - 1].msgid == m->msgid +			    leftIndex > 0 && +			    _currentTranslationMessages[leftIndex - 1].msgid == m->msgid  			) {  				--leftIndex;  			}  			while ( -				rightIndex < (int)_currentTranslationMessages.size() - 1 && -				_currentTranslationMessages[rightIndex + 1].msgid == m->msgid +			    rightIndex < (int)_currentTranslationMessages.size() - 1 && +			    _currentTranslationMessages[rightIndex + 1].msgid == m->msgid  			) {  				++rightIndex;  			} @@ -222,7 +223,7 @@ String TranslationManager::getLangById(int id) const {  	return "";  } -bool TranslationManager::openTranslationsFile(File& inFile) { +bool TranslationManager::openTranslationsFile(File &inFile) {  	// First look in the Themepath if we can find the file.  	if (ConfMan.hasKey("themepath") && openTranslationsFile(FSNode(ConfMan.get("themepath")), inFile))  		return true; @@ -242,7 +243,7 @@ bool TranslationManager::openTranslationsFile(File& inFile) {  	return false;  } -bool TranslationManager::openTranslationsFile(const FSNode &node, File& inFile, int depth) { +bool TranslationManager::openTranslationsFile(const FSNode &node, File &inFile, int depth) {  	if (!node.exists() || !node.isReadable() || !node.isDirectory())  		return false; @@ -289,9 +290,14 @@ void TranslationManager::loadTranslationsInfoDat() {  	// Get number of translations  	int nbTranslations = in.readUint16BE(); -	// Skip all the block sizes -	for (int i = 0; i < nbTranslations + 2; ++i) -		in.readUint16BE(); +	// Get number of codepages +	int nbCodepages = in.readUint16BE(); + +	// Determine where the codepages start +	_charmapStart = 0; +	for (int i = 0; i < nbTranslations + 3; ++i) +		_charmapStart += in.readUint16BE(); +	_charmapStart += in.pos();  	// Read list of languages  	_langs.resize(nbTranslations); @@ -305,6 +311,14 @@ void TranslationManager::loadTranslationsInfoDat() {  		_langNames[i] = String(buf, len - 1);  	} +	// Read list of codepages +	_charmaps.resize(nbCodepages); +	for (int i = 0; i < nbCodepages; ++i) { +		len = in.readUint16BE(); +		in.read(buf, len); +		_charmaps[i] = String(buf, len - 1); +	} +  	// Read messages  	int numMessages = in.readUint16BE();  	_messageIds.resize(numMessages); @@ -344,9 +358,16 @@ void TranslationManager::loadLanguageDat(int index) {  		return;  	} +	// Get the number of codepages +	int nbCodepages = in.readUint16BE(); +	if (nbCodepages != (int)_charmaps.size()) { +		warning("The 'translations.dat' file has changed since starting ScummVM. GUI translation will not be available"); +		return; +	} +  	// Get size of blocks to skip.  	int skipSize = 0; -	for (int i = 0; i < index + 2; ++i) +	for (int i = 0; i < index + 3; ++i)  		skipSize += in.readUint16BE();  	// We also need to skip the remaining block sizes  	skipSize += 2 * (nbTranslations - index); @@ -380,6 +401,29 @@ void TranslationManager::loadLanguageDat(int index) {  			_currentTranslationMessages[i].msgctxt = String(buf, len - 1);  		}  	} + +	// Find the charset +	int charmapNum = -1; +	for (uint i = 0; i < _charmaps.size(); ++i) { +		if (_charmaps[i].equalsIgnoreCase(_currentCharset)) { +			charmapNum = i; +			break; +		} +	} + +	// Setup the new charset mapping +	if (charmapNum == -1) { +		delete[] _charmap; +		_charmap = 0; +	} else { +		if (!_charmap) +			_charmap = new uint32[256]; + +		in.seek(_charmapStart + charmapNum * 256 * 4, SEEK_SET); +		for (int i = 0; i < 256; ++i) +			_charmap[i] = in.readUint32BE(); +	} +  }  bool TranslationManager::checkHeader(File &in) { @@ -390,7 +434,7 @@ bool TranslationManager::checkHeader(File &in) {  	buf[12] = '\0';  	// Check header -	if (strcmp(buf, "TRANSLATIONS")) { +	if (strcmp(buf, "TRANSLATIONS") != 0) {  		warning("File '%s' is not a valid translations data file. Skipping this file", in.getName());  		return false;  	}  | 
