Ticket #8904: bs2-archive.patch

File bs2-archive.patch, 25.2 KB (added by peres, 16 years ago)

Updated BS2 patch for Archive/SearchSet.

  • animation.cpp

     
    2727
    2828
    2929#include "common/config-manager.h"
    30 #include "common/file.h"
    3130#include "common/events.h"
    3231#include "common/system.h"
    3332
     
    865864// Factory function for creating the appropriate cutscene player
    866865///////////////////////////////////////////////////////////////////////////////
    867866
    868 MoviePlayer *makeMoviePlayer(Sword2Engine *vm, const char *name) {
     867MoviePlayer *Sword2Engine::makeMoviePlayer(const char *name) {
    869868        static char filename[20];
    870869
    871870#ifdef USE_ZLIB
    872871        snprintf(filename, sizeof(filename), "%s.dxa", name);
    873872
    874         if (Common::File::exists(filename)) {
    875                 return new MoviePlayerDXA(vm, name);
     873        if (_vm->_searchSet.hasFile(filename)) {
     874                return new MoviePlayerDXA(this, name);
    876875        }
    877876#endif
    878877
    879878#ifdef USE_MPEG2
    880879        snprintf(filename, sizeof(filename), "%s.mp2", name);
    881880
    882         if (Common::File::exists(filename)) {
    883                 return new MoviePlayerMPEG(vm, name);
     881        if (_vm->_searchSet.hasFile(filename)) {
     882                return new MoviePlayerMPEG(this, name);
    884883        }
    885884#endif
    886885
    887         return new MoviePlayerDummy(vm, name);
     886        return new MoviePlayerDummy(this, name);
    888887}
    889888
    890889} // End of namespace Sword2
  • anims.cpp

     
    3232// ---------------------------------------------------------------------------
    3333
    3434
    35 #include "common/file.h"
    3635
    3736#include "sword2/sword2.h"
    3837#include "sword2/defs.h"
  • function.cpp

     
    2727
    2828
    2929#include "common/system.h"
    30 #include "common/file.h"
    3130
    3231#include "sword2/sword2.h"
    3332#include "sword2/defs.h"
     
    21392138        // pause sfx during sequence
    21402139        _vm->_sound->pauseFx();
    21412140
    2142         MoviePlayer *player = makeMoviePlayer(_vm, filename);
     2141        MoviePlayer *player = _vm->makeMoviePlayer(filename);
    21432142
    21442143        if (player->load()) {
    21452144                player->play(_sequenceTextList, _sequenceTextLines, _smackerLeadIn, _smackerLeadOut);
  • music.cpp

     
    3232// All things considered, I think this is more bother than it's worth.
    3333
    3434
    35 #include "common/file.h"
    3635#include "common/system.h"
    3736
    3837#include "sound/mp3.h"
     
    4948
    5049namespace Sword2 {
    5150
    52 static Audio::AudioStream *makeCLUStream(Common::File *fp, int size);
     51static Audio::AudioStream *makeCLUStream(Common::SharedPtr<Common::SeekableReadStream> stream, int size);
    5352
    54 static Audio::AudioStream *getAudioStream(SoundFileHandle *fh, const char *base, int cd, uint32 id, uint32 *numSamples) {
    55         bool alreadyOpen;
     53Audio::AudioStream *resetAudioStream(SoundFileHandle *fh, const char *base, uint32 id, uint32 *numSamples, bool alreadyOpen) {
    5654
    57         if (!fh->file.isOpen()) {
    58                 alreadyOpen = false;
    59 
    60                 struct {
    61                         const char *ext;
    62                         int mode;
    63                 } file_types[] = {
    64         #ifdef USE_FLAC
    65                         { "clf", kFlacMode },
    66         #endif
    67         #ifdef USE_VORBIS
    68                         { "clg", kVorbisMode },
    69         #endif
    70         #ifdef USE_MAD
    71                         { "cl3", kMP3Mode },
    72         #endif
    73                         { "clu", kCLUMode }
    74                 };
    75 
    76                 int soundMode = 0;
    77                 char filename[20];
    78 
    79                 for (int i = 0; i < ARRAYSIZE(file_types); i++) {
    80                         sprintf(filename, "%s%d.%s", base, cd, file_types[i].ext);
    81                         if (Common::File::exists(filename)) {
    82                                 soundMode = file_types[i].mode;
    83                                 break;
    84                         }
    85 
    86                         sprintf(filename, "%s.%s", base, file_types[i].ext);
    87                         if (Common::File::exists(filename)) {
    88                                 soundMode = file_types[i].mode;
    89                                 break;
    90                         }
    91                 }
    92 
    93                 if (soundMode == 0)
    94                         return NULL;
    95 
    96                 fh->file.open(filename);
    97                 fh->fileType = soundMode;
    98                 if (!fh->file.isOpen()) {
    99                         warning("BS2 getAudioStream: Failed opening file '%s'", filename);
    100                         return NULL;
    101                 }
    102                 if (fh->fileSize != fh->file.size()) {
    103                         if (fh->idxTab) {
    104                                 free(fh->idxTab);
    105                                 fh->idxTab = NULL;
    106                         }
    107                 }
    108         } else
    109                 alreadyOpen = true;
    110 
    11155        uint32 entrySize = (fh->fileType == kCLUMode) ? 2 : 3;
    11256
    11357        if (!fh->idxTab) {
    114                 fh->file.seek(0);
    115                 fh->idxLen = fh->file.readUint32LE();
    116                 fh->file.seek(entrySize * 4);
     58                fh->stream->seek(0);
     59                fh->idxLen = fh->stream->readUint32LE();
     60                fh->stream->seek(entrySize * 4);
    11761
    11862                fh->idxTab = (uint32*)malloc(fh->idxLen * 3 * sizeof(uint32));
    11963                for (uint32 cnt = 0; cnt < fh->idxLen; cnt++) {
    120                         fh->idxTab[cnt * 3 + 0] = fh->file.readUint32LE();
    121                         fh->idxTab[cnt * 3 + 1] = fh->file.readUint32LE();
     64                        fh->idxTab[cnt * 3 + 0] = fh->stream->readUint32LE();
     65                        fh->idxTab[cnt * 3 + 1] = fh->stream->readUint32LE();
    12266                        if (fh->fileType == kCLUMode) {
    12367                                fh->idxTab[cnt * 3 + 2] = fh->idxTab[cnt * 3 + 1];
    12468                                fh->idxTab[cnt * 3 + 1]--;
    12569                        } else
    126                                 fh->idxTab[cnt * 3 + 2] = fh->file.readUint32LE();
     70                                fh->idxTab[cnt * 3 + 2] = fh->stream->readUint32LE();
    12771                }
    12872        }
    12973
     
    14185                // open though, because something is playing from it.
    14286                warning("getAudioStream: Could not find %s ID %d! Possibly the wrong file", base, id);
    14387                if (!alreadyOpen)
    144                         fh->file.close();
     88                        fh->stream.reset();
    14589                return NULL;
    14690        }
    14791
    148         fh->file.seek(pos, SEEK_SET);
     92        fh->stream->seek(pos, SEEK_SET);
    14993
    15094        Common::MemoryReadStream *tmp = 0;
    15195
    15296        switch (fh->fileType) {
    15397        case kCLUMode:
    154                 return makeCLUStream(&fh->file, enc_len);
     98                return makeCLUStream(fh->stream, enc_len);
    15599#ifdef USE_MAD
    156100        case kMP3Mode:
    157                 tmp = fh->file.readStream(enc_len);
     101                tmp = fh->stream->readStream(enc_len);
    158102                assert(tmp);
    159103                return Audio::makeMP3Stream(tmp, true);
    160104#endif
    161105#ifdef USE_VORBIS
    162106        case kVorbisMode:
    163                 tmp = fh->file.readStream(enc_len);
     107                tmp = fh->stream->readStream(enc_len);
    164108                assert(tmp);
    165109                return Audio::makeVorbisStream(tmp, true);
    166110#endif
    167111#ifdef USE_FLAC
    168112        case kFlacMode:
    169                 tmp = fh->file.readStream(enc_len);
     113                tmp = fh->stream->readStream(enc_len);
    170114                assert(tmp);
    171115                return Audio::makeFlacStream(tmp, true);
    172116#endif
    173117        default:
    174118                return NULL;
    175119        }
     120
    176121}
    177122
     123Audio::AudioStream *Sound::getAudioStream(SoundFileHandle *fh, const char *base, int cd, uint32 id, uint32 *numSamples) {
     124        bool alreadyOpen;
     125
     126        if (!fh->stream) {
     127                alreadyOpen = false;
     128
     129                struct {
     130                        const char *ext;
     131                        int mode;
     132                } file_types[] = {
     133        #ifdef USE_FLAC
     134                        { "clf", kFlacMode },
     135        #endif
     136        #ifdef USE_VORBIS
     137                        { "clg", kVorbisMode },
     138        #endif
     139        #ifdef USE_MAD
     140                        { "cl3", kMP3Mode },
     141        #endif
     142                        { "clu", kCLUMode }
     143                };
     144
     145                int soundMode = 0;
     146                char filename[20];
     147
     148                for (int i = 0; i < ARRAYSIZE(file_types); i++) {
     149                        sprintf(filename, "%s%d.%s", base, cd, file_types[i].ext);
     150                        if (_vm->_searchSet.hasFile(filename)) {
     151                                soundMode = file_types[i].mode;
     152                                break;
     153                        }
     154
     155                        sprintf(filename, "%s.%s", base, file_types[i].ext);
     156                        if (_vm->_searchSet.hasFile(filename)) {
     157                                soundMode = file_types[i].mode;
     158                                break;
     159                        }
     160                }
     161
     162                if (soundMode == 0)
     163                        return NULL;
     164
     165                fh->stream = _vm->_searchSet.openFile(filename);
     166                fh->fileType = soundMode;
     167                if (!fh->stream) {
     168                        warning("BS2 getAudioStream: Failed opening file '%s'", filename);
     169                        return NULL;
     170                }
     171                if (fh->fileSize != fh->stream->size()) {
     172                        if (fh->idxTab) {
     173                                free(fh->idxTab);
     174                                fh->idxTab = NULL;
     175                        }
     176                }
     177        } else
     178                alreadyOpen = true;
     179
     180        return resetAudioStream(fh, base, id, numSamples, alreadyOpen);
     181}
     182
     183
    178184// ----------------------------------------------------------------------------
    179185// Custom AudioStream class to handle Broken Sword 2's audio compression.
    180186// ----------------------------------------------------------------------------
     
    183189#define GetCompressedSign(n)       ((n) & 0x08)
    184190#define GetCompressedAmplitude(n)  ((n) & 0x07)
    185191
    186 CLUInputStream::CLUInputStream(Common::File *file, int size)
    187         : _file(file), _firstTime(true), _bufferEnd(_outbuf + BUFFER_SIZE) {
     192CLUInputStream::CLUInputStream(Common::SharedPtr<Common::SeekableReadStream> stream, int size)
     193        : _stream(stream), _firstTime(true), _bufferEnd(_outbuf + BUFFER_SIZE) {
    188194
    189195        // Determine the end position.
    190         _file_pos = _file->pos();
     196        _file_pos = _stream->pos();
    191197        _end_pos = _file_pos + size;
    192198
    193199        // Read in initial data
     
    216222        byte *in = _inbuf;
    217223        int16 *out = _outbuf;
    218224
    219         _file->seek(_file_pos, SEEK_SET);
     225        _stream->seek(_file_pos, SEEK_SET);
    220226
    221         uint len_left = _file->read(in, MIN((uint32)BUFFER_SIZE, _end_pos - _file->pos()));
     227        uint len_left = _stream->read(in, MIN((uint32)BUFFER_SIZE, _end_pos - _stream->pos()));
    222228
    223         _file_pos = _file->pos();
     229        _file_pos = _stream->pos();
    224230
    225231        while (len_left > 0) {
    226232                uint16 sample;
     
    250256        _bufferEnd = out;
    251257}
    252258
    253 Audio::AudioStream *makeCLUStream(Common::File *file, int size) {
    254         return new CLUInputStream(file, size);
     259Audio::AudioStream *makeCLUStream(Common::SharedPtr<Common::SeekableReadStream> stream, int size) {
     260        return new CLUInputStream(stream, size);
    255261}
    256262
    257263// ----------------------------------------------------------------------------
     
    262268// The length of a fade-in/out, in milliseconds.
    263269#define FADE_LENGTH 3000
    264270
    265 MusicInputStream::MusicInputStream(int cd, SoundFileHandle *fh, uint32 musicId, bool looping) {
    266         _cd = cd;
     271MusicInputStream::MusicInputStream(Audio::AudioStream *decoder, SoundFileHandle *fh, uint32 musicId, uint32 numSamples, bool looping) {
    267272        _fh = fh;
    268273        _musicId = musicId;
     274        _numSamples = numSamples;
    269275        _looping = looping;
    270276
    271277        _bufferEnd = _buffer + BUFFER_SIZE;
    272278        _remove = false;
    273279        _fading = 0;
    274280
    275         _decoder = getAudioStream(_fh, "music", _cd, _musicId, &_numSamples);
     281        _decoder = decoder;
    276282        if (_decoder) {
    277283                _samplesLeft = _numSamples;
    278284                _fadeSamples = (getRate() * FADE_LENGTH) / 1000;
     
    283289        }
    284290}
    285291
     292
    286293MusicInputStream::~MusicInputStream() {
    287294        delete _decoder;
    288295        _decoder = NULL;
     
    390397        if (!_samplesLeft) {
    391398                if (_looping) {
    392399                        delete _decoder;
    393                         _decoder = getAudioStream(_fh, "music", _cd, _musicId, &_numSamples);
     400                        _decoder = resetAudioStream(_fh, "music", _musicId, &_numSamples, true);
    394401                        _samplesLeft = _numSamples;
    395402                } else
    396403                        _remove = true;
     
    485492        }
    486493
    487494        for (i = 0; i < MAXMUS; i++) {
    488                 if (!inUse[i] && !_musicFile[i].inUse && _musicFile[i].file.isOpen())
    489                         _musicFile[i].file.close();
     495                if (!inUse[i] && !_musicFile[i].inUse && _musicFile[i].stream)
     496                        _musicFile[i].stream.reset();
    490497        }
    491498
    492499        return numSamples;
     
    617624        fh->inUse = true;
    618625        _mutex.unlock();
    619626
    620         MusicInputStream *tmp = new MusicInputStream(cd, fh, musicId, loop);
     627        uint32 numSamples;
     628        Audio::AudioStream *decoder = getAudioStream(fh, "music", cd, musicId, &numSamples);
     629        MusicInputStream *tmp = new MusicInputStream(decoder, fh, musicId, numSamples, loop);
    621630
    622631        if (tmp->isReady()) {
    623632                _mutex.lock();
  • resman.cpp

     
    2626 */
    2727
    2828
    29 #include "common/file.h"
    3029#include "common/system.h"
    3130
    3231#include "sword2/sword2.h"
     
    103102        // within the clusters at this point it makes no difference. We only
    104103        // wish to know what resource files there are and what is in each
    105104
    106         Common::File file;
    107 
    108         if (!file.open("resource.inf")) {
     105        Common::SharedPtr<Common::SeekableReadStream> stream;
     106        stream = _vm->_searchSet.openFile("resource.inf");
     107        if (!stream) {
    109108                _vm->GUIErrorMessage("Broken Sword 2: Cannot open resource.inf");
    110109                return false;
    111110        }
     
    113112        // The resource.inf file is a simple text file containing the names of
    114113        // all the resource files.
    115114
    116         while (file.readLine(_resFiles[_totalClusters].fileName, sizeof(_resFiles[_totalClusters].fileName))) {
     115        while (stream->readLine(_resFiles[_totalClusters].fileName, sizeof(_resFiles[_totalClusters].fileName))) {
    117116                _resFiles[_totalClusters].numEntries = -1;
    118117                _resFiles[_totalClusters].entryTab = NULL;
    119118                if (++_totalClusters >= MAX_res_files) {
     
    122121                }
    123122        }
    124123
    125         file.close();
    126 
    127124        // Now load in the binary id to res conversion table
    128         if (!file.open("resource.tab")) {
     125        stream = _vm->_searchSet.openFile("resource.tab");
     126        if (!stream) {
    129127                _vm->GUIErrorMessage("Broken Sword 2: Cannot open resource.tab");
    130128                return false;
    131129        }
    132130
    133131        // Find how many resources
    134         uint32 size = file.size();
     132        uint32 size = stream->size();
    135133
    136134        _totalResFiles = size / 4;
    137135
     
    139137        _resConvTable = (uint16 *)malloc(size);
    140138
    141139        for (i = 0; i < size / 2; i++)
    142                 _resConvTable[i] = file.readUint16LE();
     140                _resConvTable[i] = stream->readUint16LE();
    143141
    144         if (file.ioFailed()) {
    145                 file.close();
     142        if (stream->ioFailed()) {
    146143                _vm->GUIErrorMessage("Broken Sword 2: Cannot read resource.tab");
    147144                return false;
    148145        }
    149146
    150         file.close();
    151147
    152         if (!file.open("cd.inf")) {
     148        stream = _vm->_searchSet.openFile("cd.inf");
     149        if (!stream) {
    153150                _vm->GUIErrorMessage("Broken Sword 2: Cannot open cd.inf");
    154151                return false;
    155152        }
     
    157154        CdInf *cdInf = new CdInf[_totalClusters];
    158155
    159156        for (i = 0; i < _totalClusters; i++) {
    160                 file.read(cdInf[i].clusterName, sizeof(cdInf[i].clusterName));
     157                stream->read(cdInf[i].clusterName, sizeof(cdInf[i].clusterName));
    161158
    162                 cdInf[i].cd = file.readByte();
     159                cdInf[i].cd = stream->readByte();
    163160
    164                 if (file.ioFailed()) {
     161                if (stream->ioFailed()) {
    165162                        delete cdInf;
    166                         file.close();
    167163                        _vm->GUIErrorMessage("Broken Sword 2: Cannot read cd.inf");
    168164                        return false;
    169165                }
     
    189185                // during game-play (oh, that wascally wabbit!) in which case
    190186                // the resource manager will print a fatal error.
    191187
    192                 if (cdInf[i].cd == 0 && !Common::File::exists((char *)cdInf[i].clusterName)) {
     188                if (cdInf[i].cd == 0 && !_vm->_searchSet.hasFile((char*)cdInf[i].clusterName)) {
    193189                        _vm->GUIErrorMessage("Broken Sword 2: Cannot find " + Common::String((char *)cdInf[i].clusterName));
    194190                        delete[] cdInf;
    195191                        return false;
    196192                }
    197193        }
    198194
    199         file.close();
    200 
    201195        for (i = 0; i < _totalClusters; i++) {
    202196                for (j = 0; j < _totalClusters; j++) {
    203197                        if (scumm_stricmp((char *)cdInf[j].clusterName, _resFiles[i].fileName) == 0)
     
    260254                // care which CD it's on. But if we can't find it, keep asking
    261255                // for the CD until we do.
    262256
    263                 Common::File *file = openCluFile(cluFileNum);
     257                Common::SharedPtr<Common::SeekableReadStream> stream = openCluFile(cluFileNum);
    264258
    265259                if (_resFiles[cluFileNum].entryTab == NULL) {
    266260                        // we didn't read from this file before, get its index table
    267                         readCluIndex(cluFileNum, file);
     261                        readCluIndex(cluFileNum, stream);
    268262                }
    269263
    270264                uint32 pos = _resFiles[cluFileNum].entryTab[actual_res * 2 + 0];
    271265                uint32 len = _resFiles[cluFileNum].entryTab[actual_res * 2 + 1];
    272266
    273                 file->seek(pos, SEEK_SET);
     267                stream->seek(pos, SEEK_SET);
    274268
    275269                debug(6, "res len %d", len);
    276270
     
    279273                _resList[res].size = len;
    280274                _resList[res].refCount = 0;
    281275
    282                 file->read(_resList[res].ptr, len);
     276                stream->read(_resList[res].ptr, len);
    283277
    284278                debug(3, "Loaded resource '%s' (%d) from '%s' on CD %d (%d)", fetchName(_resList[res].ptr), res, _resFiles[cluFileNum].fileName, getCD(), _resFiles[cluFileNum].cd);
    285279
     
    334328
    335329                        sprintf(buf, "dumps/%s-%d.dmp", tag, res);
    336330
    337                         if (!Common::File::exists(buf)) {
     331                        if (!_vm->_searchSet.hasFile(buf)) {
    338332                                Common::DumpFile out;
    339333                                if (out.open(buf))
    340334                                        out.write(_resList[res].ptr, len);
    341335                        }
    342336                }
    343337
    344                 // close the cluster
    345                 file->close();
    346                 delete file;
    347 
    348338                _usedMem += len;
    349339                checkMemUsage();
    350340        } else if (_resList[res].refCount == 0)
     
    405395                _cacheEnd = res;
    406396}
    407397
    408 Common::File *ResourceManager::openCluFile(uint16 fileNum) {
    409         Common::File *file = new Common::File;
    410         while (!file->open(_resFiles[fileNum].fileName)) {
     398Common::SharedPtr<Common::SeekableReadStream> ResourceManager::openCluFile(uint16 fileNum) {
     399        while (!_vm->_searchSet.hasFile(_resFiles[fileNum].fileName)) {
    411400                // HACK: We have to check for this, or it'll be impossible to
    412401                // quit while the game is asking for the user to insert a CD.
    413402                // But recovering from this situation gracefully is just too
     
    424413
    425414                askForCD(_resFiles[fileNum].cd);
    426415        }
    427         return file;
     416
     417        Common::SharedPtr<Common::SeekableReadStream> stream = _vm->_searchSet.openFile(_resFiles[fileNum].fileName);
     418        return stream;
    428419}
    429420
    430 void ResourceManager::readCluIndex(uint16 fileNum, Common::File *file) {
     421void ResourceManager::readCluIndex(uint16 fileNum, Common::SharedPtr<Common::SeekableReadStream> file) {
    431422        // we didn't read from this file before, get its index table
    432423        assert(_resFiles[fileNum].entryTab == NULL);
    433424        assert(file);
     
    492483        // open the cluster file
    493484
    494485        if (_resFiles[parent_res_file].entryTab == NULL) {
    495                 Common::File *file = openCluFile(parent_res_file);
    496                 readCluIndex(parent_res_file, file);
    497                 delete file;
     486                Common::SharedPtr<Common::SeekableReadStream> stream = openCluFile(parent_res_file);
     487                readCluIndex(parent_res_file, stream);
    498488        }
    499489        return _resFiles[parent_res_file].entryTab[actual_res * 2 + 1];
    500490}
  • resman.h

     
    2828#ifndef SWORD2_RESMAN_H
    2929#define SWORD2_RESMAN_H
    3030
    31 namespace Common {
    32         class File;
    33 }
     31#include "common/ptr.h"
    3432
     33
    3534#ifdef PALMOS_MODE
    3635#define MAX_MEM_CACHE (4 * 1024 * 1024) // 4 seems to be enough, 8 = out of memory
    3736#else
     
    5958
    6059class ResourceManager {
    6160private:
    62         Common::File *openCluFile(uint16 fileNum);
    63         void readCluIndex(uint16 fileNum, Common::File *file);
     61        Common::SharedPtr<Common::SeekableReadStream> openCluFile(uint16 fileNum);
     62        void readCluIndex(uint16 fileNum, Common::SharedPtr<Common::SeekableReadStream> stream);
    6463        void removeFromCacheList(Resource *res);
    6564        void addToCacheList(Resource *res);
    6665        void checkMemUsage();
  • screen.cpp

     
    867867        //     now, let's just the standard speech font instead.
    868868
    869869        SpriteInfo spriteInfo;
    870         Common::File f;
     870        Common::SharedPtr<Common::SeekableReadStream> stream;
    871871        int i;
    872872
    873873        // Read the "Smacker" logo
     
    877877        byte *logoData = NULL;
    878878        byte palette[256 * 4];
    879879
    880         if (f.open("credits.bmp")) {
    881                 logoWidth = f.readUint16LE();
    882                 logoHeight = f.readUint16LE();
     880        stream = _vm->_searchSet.openFile("credits.bmp");
     881        if (stream) {
     882                logoWidth = stream->readUint16LE();
     883                logoHeight = stream->readUint16LE();
    883884
    884885                for (i = 0; i < 256; i++) {
    885                         palette[i * 4 + 0] = f.readByte() << 2;
    886                         palette[i * 4 + 1] = f.readByte() << 2;
    887                         palette[i * 4 + 2] = f.readByte() << 2;
     886                        palette[i * 4 + 0] = stream->readByte() << 2;
     887                        palette[i * 4 + 1] = stream->readByte() << 2;
     888                        palette[i * 4 + 2] = stream->readByte() << 2;
    888889                        palette[i * 4 + 3] = 0;
    889890                }
    890891
    891892                logoData = (byte *)malloc(logoWidth * logoHeight);
    892893
    893                 f.read(logoData, logoWidth * logoHeight);
    894                 f.close();
     894                stream->read(logoData, logoWidth * logoHeight);
    895895        } else {
    896896                warning("Can't find credits.bmp");
    897897                memset(palette, 0, sizeof(palette));
     
    912912        int paragraphStart = 0;
    913913        bool hasCenterMark = false;
    914914
    915         if (!f.open("credits.clu")) {
     915        stream = _vm->_searchSet.openFile("credits.clu");
     916        if (!stream) {
    916917                warning("Can't find credits.clu");
    917918                return;
    918919        }
    919920
    920921        while (1) {
    921922                char buffer[80];
    922                 char *line = f.readLine(buffer, sizeof(buffer));
     923                char *line = stream->readLine(buffer, sizeof(buffer));
    923924
    924925                if (!line || *line == 0) {
    925926                        if (!hasCenterMark) {
     
    9991000                lineCount++;
    10001001        }
    10011002
    1002         f.close();
    1003 
    10041003        // We could easily add some ScummVM stuff to the credits, if we wanted
    10051004        // to. On the other hand, anyone with the attention span to actually
    10061005        // read all the credits probably already knows. :-)
  • sound.cpp

     
    3636// ---------------------------------------------------------------------------
    3737
    3838
    39 #include "common/file.h"
    4039#include "common/system.h"
    4140
    4241#include "sword2/sword2.h"
     
    102101        free(_mixBuffer);
    103102
    104103        for (int i = 0; i < MAXMUS; i++) {
    105                 if (_musicFile[i].file.isOpen())
    106                         _musicFile[i].file.close();
    107                 if (_speechFile[i].file.isOpen())
    108                         _speechFile[i].file.close();
     104                if (_musicFile[i].stream)
     105                        _musicFile[i].stream.reset();
     106                if (_speechFile[i].stream)
     107                        _speechFile[i].stream.reset();
    109108
    110109                free(_musicFile[i].idxTab);
    111110                free(_speechFile[i].idxTab);
  • sound.h

     
    3838#ifndef SWORD2_SOUND_H
    3939#define SWORD2_SOUND_H
    4040
    41 #include "common/file.h"
    4241#include "sound/audiostream.h"
    4342#include "sound/mixer.h"
    4443
     
    9291
    9392class CLUInputStream : public Audio::AudioStream {
    9493private:
    95         Common::File *_file;
     94        Common::SharedPtr<Common::SeekableReadStream> _stream;
    9695        bool _firstTime;
    9796        uint32 _file_pos;
    9897        uint32 _end_pos;
     
    106105        void refill();
    107106
    108107        inline bool eosIntern() const {
    109                 return !_file->isOpen() || _pos >= _bufferEnd;
     108                return !_stream || _pos >= _bufferEnd;
    110109        }
    111110
    112111public:
    113         CLUInputStream(Common::File *file, int size);
     112        CLUInputStream(Common::SharedPtr<Common::SeekableReadStream> stream, int size);
    114113        ~CLUInputStream();
    115114
    116115        int readBuffer(int16 *buffer, const int numSamples);
     
    121120};
    122121
    123122struct SoundFileHandle {
    124         Common::File file;
     123        Common::SharedPtr<Common::SeekableReadStream> stream;
    125124        uint32 *idxTab;
    126125        uint32 idxLen;
    127126        uint32 fileSize;
     
    155154        }
    156155
    157156public:
    158         MusicInputStream(int cd, SoundFileHandle *fh, uint32 musicId, bool looping);
     157        MusicInputStream(Audio::AudioStream *decoder, SoundFileHandle *fh, uint32 musicId, uint32 numSamples, bool looping);
    159158        ~MusicInputStream();
    160159
    161160        int readBuffer(int16 *buffer, const int numSamples);
     
    281280        int32 streamCompMusic(uint32 musicId, bool loop);
    282281        void stopMusic(bool immediately);
    283282        int32 musicTimeRemaining();
     283
     284        Audio::AudioStream *getAudioStream(SoundFileHandle *fh, const char *base, int cd, uint32 id, uint32 *numSamples);
    284285};
    285286
    286287} // End of namespace Sword2
  • speech.cpp

     
    2626 */
    2727
    2828
    29 #include "common/file.h"
    3029
    3130#include "sword2/sword2.h"
    3231#include "sword2/defs.h"
  • startup.cpp

     
    2626 */
    2727
    2828
    29 #include "common/file.h"
    30 
    3129#include "sword2/sword2.h"
    3230#include "sword2/defs.h"
    3331#include "sword2/header.h"
     
    4846        // We query each in turn and setup an array of start structures.
    4947        // If the file doesn't exist then we say so and return a 0.
    5048
    51         Common::File fp;
     49        Common::SharedPtr<Common::SeekableReadStream> stream;
    5250
    5351        // ok, load in the master screen manager file
    5452
    5553        _totalStartups = 0;
    5654        _totalScreenManagers = 0;
    5755
    58         if (!fp.open("startup.inf")) {
     56        stream = _searchSet.openFile("startup.inf");
     57        if (!stream) {
    5958                warning("Cannot open startup.inf - the debugger won't have a start menu");
    6059                return false;
    6160        }
     
    6867
    6968        int lineno = 0;
    7069
    71         while (fp.readLine(buf, sizeof(buf))) {
     70        while (stream->readLine(buf, sizeof(buf))) {
    7271                char *errptr;
    7372                int id;
    7473
     
    9897                }
    9998        }
    10099
    101         fp.close();
    102 
    103100        // Using this method the Gode generated resource.inf must have #0d0a
    104101        // on the last entry
    105102
  • sword2.cpp

     
    3030#include "base/plugins.h"
    3131
    3232#include "common/config-manager.h"
    33 #include "common/file.h"
    34 #include "common/fs.h"
     33
    3534#include "common/events.h"
    3635#include "common/system.h"
    3736
     
    189188namespace Sword2 {
    190189
    191190Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst) {
     191
     192        Common::SharedPtr<Common::FSDirectory> _baseDir(new Common::FSDirectory(_gameDataPath));
     193
    192194        // Add default file directories
    193         Common::File::addDefaultDirectory(_gameDataPath + "CLUSTERS/");
    194         Common::File::addDefaultDirectory(_gameDataPath + "SWORD2/");
    195         Common::File::addDefaultDirectory(_gameDataPath + "VIDEO/");
    196         Common::File::addDefaultDirectory(_gameDataPath + "clusters/");
    197         Common::File::addDefaultDirectory(_gameDataPath + "sword2/");
    198         Common::File::addDefaultDirectory(_gameDataPath + "video/");
     195        _searchSet.add("base", _baseDir);
     196        _searchSet.add("vid", _baseDir->getSubDirectory("VIDEO"));
     197        _searchSet.add("clu", _baseDir->getSubDirectory("CLUSTERS"));
     198        _searchSet.add("s2", _baseDir->getSubDirectory("SWORD2"));
    199199
    200200        if (0 == scumm_stricmp(ConfMan.get("gameid").c_str(), "sword2demo"))
    201201                _features = GF_DEMO;
  • sword2.h

     
    4040#include "engines/engine.h"
    4141
    4242#include "common/events.h"
     43#include "common/archive.h"
    4344#include "common/util.h"
    4445
    4546#define MAX_starts      100
     
    6263class FontRenderer;
    6364class Gui;
    6465class Debugger;
     66class MoviePlayer;
    6567
    6668enum {
    6769        RD_LEFTBUTTONDOWN               = 0x01,
     
    152154        Mouse *_mouse;
    153155        Logic *_logic;
    154156        FontRenderer *_fontRenderer;
     157        Common::SearchSet       _searchSet;
    155158
    156159        Debugger *_debugger;
    157160
     
    228231
    229232        void runStart(int start);
    230233
     234        MoviePlayer *makeMoviePlayer(const char *name);
     235
    231236        // Convenience alias for OSystem::getMillis().
    232237        // This is a bit hackish, of course :-).
    233238        uint32 getMillis();