Пример #1
0
void DoCdChange() {
	if (g_bChangingCD && (g_system->getMillis() > (g_lastTime + 1000))) {
		g_lastTime = g_system->getMillis();
		_vm->_sound->closeSampleStream();

		// Use the filesize of the sample file to determine, for Discworld 2, which CD it is
		if (TinselV2) {
			TinselFile f;
			if (!f.open(_vm->getSampleFile(g_sampleLanguage)))
				// No CD present
				return;

			char sampleCdNumber = (f.size() >= (200 * 1024 * 1024)) ? '1' : '2';

			f.close();

			if (g_currentCD != sampleCdNumber)
				return;
		}

		_vm->_sound->openSampleFiles();
		ChangeLanguage(TextLanguage());
		g_bChangingCD = false;
	}
}
Пример #2
0
/**
 * Called to load a resource file for a different language
 * @param newLang			The new language
 */
void ChangeLanguage(LANGUAGE newLang) {
	TinselFile f;
	uint32 textLen = 0;	// length of buffer

	textLanguage = newLang;
	sampleLanguage = newLang;

	// free the previous buffer
	free(textBuffer);
	textBuffer = NULL;

	// Try and open the specified language file. If it fails, and the language
	// isn't English, try falling back on opening 'english.txt' - some foreign
	// language versions reused it rather than their proper filename
	if (!f.open(_vm->getTextFile(newLang))) {
		if ((newLang == TXT_ENGLISH) || !f.open(_vm->getTextFile(TXT_ENGLISH))) {
			char buf[50];
			sprintf(buf, CANNOT_FIND_FILE, _vm->getTextFile(newLang));
			GUI::MessageDialog dialog(buf, "OK");
			dialog.runModal();

			error(CANNOT_FIND_FILE, _vm->getTextFile(newLang));
		}
	}

	// Check whether the file is compressed or not -  for compressed files the
	// first long is the filelength and for uncompressed files it is the chunk
	// identifier
	textLen = f.readUint32();
	if (f.eos() || f.err())
		error(FILE_IS_CORRUPT, _vm->getTextFile(newLang));

	if (textLen == CHUNK_STRING || textLen == CHUNK_MBSTRING) {
		// the file is uncompressed

		bMultiByte = (textLen == CHUNK_MBSTRING);

		// get length of uncompressed file
		textLen = f.size();
		f.seek(0, SEEK_SET);	// Set to beginning of file

		if (textBuffer == NULL) {
			// allocate a text buffer for the strings
			textBuffer = (uint8 *)malloc(textLen);

			// make sure memory allocated
			assert(textBuffer);
		}

		// load data
		if (f.read(textBuffer, textLen) != textLen)
			// file must be corrupt if we get to here
			error(FILE_IS_CORRUPT, _vm->getTextFile(newLang));

		// close the file
		f.close();
	} else {	// the file must be compressed
		error("Compression handling has been removed");
	}
}