/** * 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"); } }
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; } }
/** * Opens and inits all sound sample files. */ void SoundManager::openSampleFiles() { // Floppy and demo versions have no sample files, except for the Discworld 2 demo if (_vm->getFeatures() & GF_FLOPPY || (IsDemo && !TinselV2)) return; TinselFile f; if (_sampleIndex) // already allocated return; // open sample index file in binary mode if (f.open(_vm->getSampleIndex(sampleLanguage))) { // get length of index file f.seek(0, SEEK_END); // move to end of file _sampleIndexLen = f.pos(); // get file pointer f.seek(0, SEEK_SET); // back to beginning if (_sampleIndex == NULL) { // allocate a buffer for the indices _sampleIndex = (uint32 *)malloc(_sampleIndexLen); // make sure memory allocated if (_sampleIndex == NULL) { // disable samples if cannot alloc buffer for indices // TODO: Disabled sound if we can't load the sample index? return; } } // load data if (f.read(_sampleIndex, _sampleIndexLen) != (uint32)_sampleIndexLen) // file must be corrupt if we get to here error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); // close the file f.close(); // convert file size to size in DWORDs _sampleIndexLen /= sizeof(uint32); #ifdef SCUMM_BIG_ENDIAN // Convert all ids from LE to native format for (int i = 0; i < _sampleIndexLen; ++i) { _sampleIndex[i] = SWAP_BYTES_32(_sampleIndex[i]); } #endif // Detect format of soundfile by looking at 1st sample-index switch (TO_BE_32(_sampleIndex[0])) { case MKID_BE('MP3 '): debugC(DEBUG_DETAILED, kTinselDebugSound, "Detected MP3 sound-data"); _soundMode = kMP3Mode; break; case MKID_BE('OGG '): debugC(DEBUG_DETAILED, kTinselDebugSound, "Detected OGG sound-data"); _soundMode = kVorbisMode; break; case MKID_BE('FLAC'): debugC(DEBUG_DETAILED, kTinselDebugSound, "Detected FLAC sound-data"); _soundMode = kFLACMode; break; default: debugC(DEBUG_DETAILED, kTinselDebugSound, "Detected original sound-data"); break; } // Normally the 1st sample-index points to nothing at all _sampleIndex[0] = 0; } else { char buf[50]; sprintf(buf, CANNOT_FIND_FILE, _vm->getSampleIndex(sampleLanguage)); GUI::MessageDialog dialog(buf, "OK"); dialog.runModal(); error(CANNOT_FIND_FILE, _vm->getSampleIndex(sampleLanguage)); } // open sample file in binary mode if (!_sampleStream.open(_vm->getSampleFile(sampleLanguage))) { char buf[50]; sprintf(buf, CANNOT_FIND_FILE, _vm->getSampleFile(sampleLanguage)); GUI::MessageDialog dialog(buf, "OK"); dialog.runModal(); error(CANNOT_FIND_FILE, _vm->getSampleFile(sampleLanguage)); } /* // gen length of the largest sample sampleBuffer.size = _sampleStream.readUint32LE(); if (_sampleStream.eos() || _sampleStream.err()) error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); */ }