From 9ea6c43c975661273950efa60a7e75a6b45cf8af Mon Sep 17 00:00:00 2001 From: athrxx Date: Mon, 5 Aug 2019 20:33:06 +0200 Subject: SCI: error dialog for missing sound patch/driver files After implementing such a dialog into the fb01 driver it did make sense to me to also have this as a feature for all other aftermarket drivers/patches. So now the sound drivers can report missing files after the failed open() call which will then be displayed in a dialog. Which will at least be more helpful than our usual error messages... --- engines/sci/POTFILES | 2 +- engines/sci/sound/drivers/cms.cpp | 19 ++++++++++++++----- engines/sci/sound/drivers/mididriver.h | 8 ++++++++ engines/sci/sound/music.cpp | 19 +++++++++++++++++++ 4 files changed, 42 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/sci/POTFILES b/engines/sci/POTFILES index 24576e871f..4b8e6e663d 100644 --- a/engines/sci/POTFILES +++ b/engines/sci/POTFILES @@ -1,5 +1,4 @@ engines/sci/detection.cpp -engines/sci/sound/drivers/fb01.cpp engines/sci/engine/guest_additions.cpp engines/sci/engine/kfile.cpp engines/sci/engine/kgraphics.cpp @@ -8,3 +7,4 @@ engines/sci/engine/savegame.cpp engines/sci/graphics/controls32.cpp engines/sci/resource.cpp engines/sci/sci.cpp +engines/sci/sound/music.cpp diff --git a/engines/sci/sound/drivers/cms.cpp b/engines/sci/sound/drivers/cms.cpp index 0f79251ea7..091aab2414 100644 --- a/engines/sci/sound/drivers/cms.cpp +++ b/engines/sci/sound/drivers/cms.cpp @@ -740,7 +740,7 @@ int MidiDriver_CMS::open() { Resource *res = _resMan->findResource(ResourceId(kResourceTypePatch, 101), false); if (!res) return -1; - + _patchData->allocateFromSpan(_version < SCI_VERSION_1_EARLY ? res->subspan(30) : *res); _rate = _mixer->getOutputRate(); @@ -1294,7 +1294,7 @@ void MidiDriver_CMS::generateSamples(int16 *buffer, int len) { class MidiPlayer_CMS : public MidiPlayer { public: - MidiPlayer_CMS(SciVersion version) : MidiPlayer(version) {} + MidiPlayer_CMS(SciVersion version) : MidiPlayer(version), _filesMissing(false) {} int open(ResourceManager *resMan); void close(); @@ -1306,6 +1306,12 @@ public: int getPolyphony() const { return 12; } void playSwitch(bool play) { _driver->property(MidiDriver_CMS::MIDI_PROP_PLAYSWITCH, play ? 1 : 0); } + + const char *reportMissingFiles() { return _filesMissing ? _requiredFiles : 0; } + +private: + bool _filesMissing; + static const char _requiredFiles[]; }; int MidiPlayer_CMS::open(ResourceManager *resMan) { @@ -1314,10 +1320,11 @@ int MidiPlayer_CMS::open(ResourceManager *resMan) { _driver = new MidiDriver_CMS(g_system->getMixer(), resMan, _version); int driverRetVal = _driver->open(); - if (driverRetVal != 0) - return driverRetVal; - return 0; + if (driverRetVal == -1) + _filesMissing = true; + + return driverRetVal; } void MidiPlayer_CMS::close() { @@ -1332,6 +1339,8 @@ void MidiPlayer_CMS::initTrack(SciSpan& header) { static_cast(_driver)->initTrack(header); } +const char MidiPlayer_CMS::_requiredFiles[] = "'PATCH.101'"; + MidiPlayer *MidiPlayer_CMS_create(SciVersion version) { return new MidiPlayer_CMS(version); } diff --git a/engines/sci/sound/drivers/mididriver.h b/engines/sci/sound/drivers/mididriver.h index 73c2fd5737..de87d9dbdb 100644 --- a/engines/sci/sound/drivers/mididriver.h +++ b/engines/sci/sound/drivers/mididriver.h @@ -126,6 +126,14 @@ public: // Some drivers also do other things in here. virtual void initTrack(SciSpan &) {} + // There are several sound drivers which weren' part of the + // original game setup and came in the form of aftermarket patches. + // This method allows each driver to report missing patch or other + // required files which will then be displayed in an error dialog box. + // The method returns only a single string (instead of a string list), + // because no more than two files will be required. + virtual const char *reportMissingFiles() { return 0; } + protected: SciVersion _version; }; diff --git a/engines/sci/sound/music.cpp b/engines/sci/sound/music.cpp index dc62acb395..581f1a84ce 100644 --- a/engines/sci/sound/music.cpp +++ b/engines/sci/sound/music.cpp @@ -23,6 +23,8 @@ #include "audio/audiostream.h" #include "audio/decoders/raw.h" #include "common/config-manager.h" +#include "common/translation.h" +#include "gui/error.h" #include "sci/sci.h" #include "sci/console.h" @@ -153,6 +155,23 @@ void SciMusic::init() { // of the Adlib driver (adl.drv) that it includes is unsupported. That demo // doesn't have any sound anyway, so this shouldn't be fatal. } else { + const char *missingFiles = _pMidiDrv->reportMissingFiles(); + if (missingFiles) { + Common::String message = _( + "The selected audio driver requires the following file(s):\n\n" + ); + message += missingFiles; + message += _("\n\n" + "Some audio drivers (at least for some games) were made\n" + "available by Sierra as aftermarket patches and thus might not\n" + "have been installed as part of the original game setup.\n\n" + "Please copy these file(s) into your game data directory.\n\n" + "However, please note that the file(s) might not be available\n" + "separately but only as content of (patched) resource bundles.\n" + "In that case you may need to apply the original Sierra patch.\n\n" + ); + ::GUI::displayErrorDialog(message.c_str()); + } error("Failed to initialize sound driver"); } } -- cgit v1.2.3