WINTERMUTE: Avoid starting up the engine to perform detection.

This commit is contained in:
Einar Johan Trøan Sømåen 2012-07-25 00:08:39 +02:00
parent c59965ad4f
commit 8be1e095fd
6 changed files with 68 additions and 33 deletions

View file

@ -27,8 +27,6 @@
*/ */
#include "engines/wintermute/base/base_file_manager.h" #include "engines/wintermute/base/base_file_manager.h"
#include "engines/wintermute/utils/string_util.h"
#include "engines/wintermute/utils/path_util.h"
#include "engines/wintermute/base/file/base_disk_file.h" #include "engines/wintermute/base/file/base_disk_file.h"
#include "engines/wintermute/base/file/base_save_thumb_file.h" #include "engines/wintermute/base/file/base_save_thumb_file.h"
#include "engines/wintermute/base/file/base_file_entry.h" #include "engines/wintermute/base/file/base_file_entry.h"
@ -37,9 +35,8 @@
#include "engines/wintermute/base/file/base_resources.h" #include "engines/wintermute/base/file/base_resources.h"
#include "engines/wintermute/base/base_registry.h" #include "engines/wintermute/base/base_registry.h"
#include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/base_game.h"
#include "engines/wintermute/dcpackage.h" #include "engines/wintermute/base/file/dcpackage.h"
#include "engines/wintermute/utils/utils.h" #include "engines/wintermute/utils/utils.h"
#include "engines/wintermute/platform_osystem.h"
#include "engines/wintermute/wintermute.h" #include "engines/wintermute/wintermute.h"
#include "common/str.h" #include "common/str.h"
#include "common/textconsole.h" #include "common/textconsole.h"
@ -58,12 +55,11 @@ namespace WinterMute {
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
BaseFileManager::BaseFileManager(BaseGame *inGame): BaseClass(inGame) { BaseFileManager::BaseFileManager(BaseGame *inGame) : _gameRef(inGame) {
initPaths(); initPaths();
registerPackages(); registerPackages();
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
BaseFileManager::~BaseFileManager() { BaseFileManager::~BaseFileManager() {
cleanup(); cleanup();
@ -207,6 +203,9 @@ bool BaseFileManager::reloadPaths() {
#define TEMP_BUFFER_SIZE 32768 #define TEMP_BUFFER_SIZE 32768
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
bool BaseFileManager::initPaths() { bool BaseFileManager::initPaths() {
if (!_gameRef) // This function only works when the game-registry is loaded
return STATUS_FAILED;
AnsiString pathList; AnsiString pathList;
int numPaths; int numPaths;
@ -506,6 +505,8 @@ Common::SeekableReadStream *BaseFileManager::openFileRaw(const Common::String &f
Common::SeekableReadStream *ret = NULL; Common::SeekableReadStream *ret = NULL;
if (scumm_strnicmp(filename.c_str(), "savegame:", 9) == 0) { if (scumm_strnicmp(filename.c_str(), "savegame:", 9) == 0) {
if (!_gameRef)
error("Attempt to load filename: %s without BaseGame-object, this is unsupported", filename.c_str());
BaseSaveThumbFile *SaveThumbFile = new BaseSaveThumbFile(_gameRef); BaseSaveThumbFile *SaveThumbFile = new BaseSaveThumbFile(_gameRef);
if (DID_SUCCEED(SaveThumbFile->open(filename))) { if (DID_SUCCEED(SaveThumbFile->open(filename))) {
ret = SaveThumbFile->getMemStream(); ret = SaveThumbFile->getMemStream();

View file

@ -29,20 +29,17 @@
#ifndef WINTERMUTE_BFILEMANAGER_H #ifndef WINTERMUTE_BFILEMANAGER_H
#define WINTERMUTE_BFILEMANAGER_H #define WINTERMUTE_BFILEMANAGER_H
#include "engines/wintermute/base/base.h"
#include "engines/wintermute/base/file/base_package.h"
#include "common/archive.h" #include "common/archive.h"
#include "common/str.h" #include "common/str.h"
#include "common/fs.h" #include "common/fs.h"
#include "common/file.h"
namespace Common {
class File;
}
namespace WinterMute { namespace WinterMute {
class BaseFile; class BaseFile;
class BaseFileEntry; class BaseFileEntry;
class BaseFileManager: BaseClass { class BaseGame;
class BasePackage;
class BaseFileManager {
public: public:
bool cleanup(); bool cleanup();
@ -77,6 +74,7 @@ private:
bool findPackageSignature(Common::SeekableReadStream *f, uint32 *offset); bool findPackageSignature(Common::SeekableReadStream *f, uint32 *offset);
bool registerPackage(Common::FSNode package, const Common::String &filename = "", bool searchSignature = false); bool registerPackage(Common::FSNode package, const Common::String &filename = "", bool searchSignature = false);
// bool registerPackage(const Common::String &filename, bool searchSignature = false); // bool registerPackage(const Common::String &filename, bool searchSignature = false);
BaseGame *_gameRef;
Common::Array<BasePackage *> _packages; Common::Array<BasePackage *> _packages;
Common::Array<Common::SeekableReadStream *> _openFiles; Common::Array<Common::SeekableReadStream *> _openFiles;
Common::HashMap<Common::String, BaseFileEntry *> _files; Common::HashMap<Common::String, BaseFileEntry *> _files;

View file

@ -57,10 +57,10 @@ BasePackage::~BasePackage() {
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
bool BasePackage::open() { bool BasePackage::open() {
if (_file) return STATUS_OK; if (_file) return true;
else { else {
_file = getFilePointer(); _file = getFilePointer();
return _file ? STATUS_OK : STATUS_FAILED; return _file ? true : false;
} }
} }
@ -69,18 +69,18 @@ bool BasePackage::open() {
bool BasePackage::close() { bool BasePackage::close() {
delete _file; delete _file;
_file = NULL; _file = NULL;
return STATUS_OK; return true;
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
bool BasePackage::read(Common::SeekableReadStream *file, uint32 offset, byte *buffer, uint32 size) { bool BasePackage::read(Common::SeekableReadStream *file, uint32 offset, byte *buffer, uint32 size) {
bool ret; bool ret;
if (DID_FAIL(ret = open())) return ret; if (!(ret = open())) return ret;
else { else {
if (file->seek(offset, SEEK_SET)) return STATUS_FAILED; if (file->seek(offset, SEEK_SET)) return false;
if (file->read(buffer, size) != 1) return STATUS_FAILED; if (file->read(buffer, size) != 1) return false;
else return STATUS_OK; else return true;
} }
} }

View file

@ -82,14 +82,14 @@ bool BaseImage::loadFile(const Common::String &filename) {
} }
_filename = filename; _filename = filename;
Common::SeekableReadStream *file = _fileManager->openFile(filename.c_str()); Common::SeekableReadStream *file = _fileManager->openFile(filename.c_str());
if (!file) return STATUS_FAILED; if (!file) return false;
_decoder->loadStream(*file); _decoder->loadStream(*file);
_surface = _decoder->getSurface(); _surface = _decoder->getSurface();
_palette = _decoder->getPalette(); _palette = _decoder->getPalette();
_fileManager->closeFile(file); _fileManager->closeFile(file);
return STATUS_OK; return true;
} }
byte BaseImage::getAlphaAt(int x, int y) { byte BaseImage::getAlphaAt(int x, int y) {
@ -113,7 +113,7 @@ bool BaseImage::saveBMPFile(const char *filename) {
if (FreeImage_Save(FIF_BMP, _bitmap, filename)) return STATUS_OK; if (FreeImage_Save(FIF_BMP, _bitmap, filename)) return STATUS_OK;
else return STATUS_FAILED; else return STATUS_FAILED;
#endif #endif
return STATUS_FAILED; return false;
} }
@ -133,7 +133,7 @@ bool BaseImage::resize(int newWidth, int newHeight) {
return STATUS_OK; return STATUS_OK;
} else return STATUS_FAILED; } else return STATUS_FAILED;
#endif #endif
return STATUS_FAILED; return false;
} }
@ -258,7 +258,7 @@ bool BaseImage::copyFrom(BaseImage *origImage, int newWidth, int newHeight) {
_deletableSurface = NULL; _deletableSurface = NULL;
} }
_surface = _deletableSurface = temp.scale(newWidth, newHeight); _surface = _deletableSurface = temp.scale(newWidth, newHeight);
return STATUS_OK; return true;
} }
} // end of namespace WinterMute } // end of namespace WinterMute

View file

@ -343,15 +343,51 @@ void WinterMuteEngine::deinit() {
bool WinterMuteEngine::getGameInfo(const Common::FSList &fslist, Common::String &name, Common::String &caption) { bool WinterMuteEngine::getGameInfo(const Common::FSList &fslist, Common::String &name, Common::String &caption) {
bool retVal = false; bool retVal = false;
caption = name = "(invalid)"; caption = name = "(invalid)";
Common::SeekableReadStream *stream = NULL;
// Quick-fix, instead of possibly breaking the persistence-system, let's just roll with it // Quick-fix, instead of possibly breaking the persistence-system, let's just roll with it
WinterMuteEngine *engine = new WinterMuteEngine(); BaseFileManager *fileMan = new BaseFileManager();
fileMan->registerPackages(fslist);
engine->_game->initialize1(); stream = fileMan->openFile("startup.settings", false, false);
engine->_game->_fileManager->registerPackages(fslist);
if (engine->_game->loadSettings("startup.settings")) { // The process is as follows: Check the "GAME=" tag in startup.settings, to decide where the
// game-settings are (usually "default.game"), then look into the game-settings to find
// the NAME = and CAPTION = tags, to use them to generate a gameid and extras-field
Common::String settingsGameFile = "default.game";
// If the stream-open failed, lets at least attempt to open the default game file afterwards
// so, we don't call it a failure yet.
if (stream) {
while (!stream->eos() && !stream->err()) {
Common::String line = stream->readLine();
line.trim(); // Get rid of indentation
// Expect "SETTINGS {" or comment, or empty line
if (line.size() == 0 || line[0] == ';' || (line.contains("{")))
continue;
else {
// We are looking for "GAME ="
Common::StringTokenizer token(line, "=");
Common::String key = token.nextToken();
Common::String value = token.nextToken();
if (value.size() == 0)
continue;
if (value[0] == '\"')
value.deleteChar(0);
else
continue;
if (value.lastChar() == '\"')
value.deleteLastChar();
if (key == "GAME") {
settingsGameFile = value;
break;
}
}
}
}
delete stream;
stream = fileMan->openFile(settingsGameFile, false, false);
if (stream) {
// We do some manual parsing here, as the engine needs gfx to be initalized to do that. // We do some manual parsing here, as the engine needs gfx to be initalized to do that.
Common::SeekableReadStream *stream = engine->_game->_fileManager->openFile((engine->_game->_settingsGameFile ? engine->_game->_settingsGameFile : "default.game"), false, false);
while (!stream->eos() && !stream->err()) { while (!stream->eos() && !stream->err()) {
Common::String line = stream->readLine(); Common::String line = stream->readLine();
line.trim(); // Get rid of indentation line.trim(); // Get rid of indentation
@ -381,7 +417,7 @@ bool WinterMuteEngine::getGameInfo(const Common::FSList &fslist, Common::String
} }
delete stream; delete stream;
} }
delete engine; delete fileMan;
return retVal; return retVal;
} }