diff options
author | lolbot-iichan | 2019-07-14 21:48:46 +0300 |
---|---|---|
committer | Filippos Karapetis | 2019-07-16 20:24:42 +0300 |
commit | 9eca2b4c549a6e20c351b6ced4442d36f7601964 (patch) | |
tree | 1fdf9d95498066d66ad13f32145f38224c3eb70b /engines/wintermute/base | |
parent | a96d127b1f07db20f66e74ae3011cc643ba7a9bd (diff) | |
download | scummvm-rg350-9eca2b4c549a6e20c351b6ced4442d36f7601964.tar.gz scummvm-rg350-9eca2b4c549a6e20c351b6ced4442d36f7601964.tar.bz2 scummvm-rg350-9eca2b4c549a6e20c351b6ced4442d36f7601964.zip |
WINTERMUTE: Implement saving files using SavefileManager
Diffstat (limited to 'engines/wintermute/base')
5 files changed, 121 insertions, 2 deletions
diff --git a/engines/wintermute/base/base_file_manager.cpp b/engines/wintermute/base/base_file_manager.cpp index 16ae85f41d..7ae499e368 100644 --- a/engines/wintermute/base/base_file_manager.cpp +++ b/engines/wintermute/base/base_file_manager.cpp @@ -29,6 +29,7 @@ #include "engines/wintermute/base/base_file_manager.h" #include "engines/wintermute/base/base_persistence_manager.h" #include "engines/wintermute/base/file/base_disk_file.h" +#include "engines/wintermute/base/file/base_savefile_manager_file.h" #include "engines/wintermute/base/file/base_save_thumb_file.h" #include "engines/wintermute/base/file/base_package.h" #include "engines/wintermute/base/base_engine.h" @@ -355,6 +356,17 @@ Common::SeekableReadStream *BaseFileManager::openFile(const Common::String &file ////////////////////////////////////////////////////////////////////////// +Common::WriteStream *BaseFileManager::openFileForWrite(const Common::String &filename) { + if (strcmp(filename.c_str(), "") == 0) { + return nullptr; + } + debugC(kWintermuteDebugFileAccess, "Open file %s for write", filename.c_str()); + + return openFileForWriteRaw(filename); +} + + +////////////////////////////////////////////////////////////////////////// bool BaseFileManager::closeFile(Common::SeekableReadStream *File) { for (uint32 i = 0; i < _openFiles.size(); i++) { if (_openFiles[i] == File) { @@ -404,6 +416,19 @@ Common::SeekableReadStream *BaseFileManager::openFileRaw(const Common::String &f return nullptr; } +////////////////////////////////////////////////////////////////////////// +Common::WriteStream *BaseFileManager::openFileForWriteRaw(const Common::String &filename) { + Common::WriteStream *ret = nullptr; + + ret = openSfmFileForWrite(filename); + if (ret) { + return ret; + } + + debugC(kWintermuteDebugFileAccess ,"BFileManager::OpenFileRaw - Failed to open %s", filename.c_str()); + return nullptr; +} + BaseFileManager *BaseFileManager::getEngineInstance() { if (BaseEngine::instance().getFileManager()) { return BaseEngine::instance().getFileManager(); diff --git a/engines/wintermute/base/base_file_manager.h b/engines/wintermute/base/base_file_manager.h index 2c67d83462..85181f1f58 100644 --- a/engines/wintermute/base/base_file_manager.h +++ b/engines/wintermute/base/base_file_manager.h @@ -44,6 +44,7 @@ public: bool hasFile(const Common::String &filename); int listMatchingMembers(Common::ArchiveMemberList &list, const Common::String &pattern); Common::SeekableReadStream *openFile(const Common::String &filename, bool absPathWarning = true, bool keepTrackOf = true); + Common::WriteStream *openFileForWrite(const Common::String &filename); byte *readWholeFile(const Common::String &filename, uint32 *size = nullptr, bool mustExist = true); BaseFileManager(Common::Language lang, bool detectionMode = false); @@ -62,6 +63,7 @@ private: bool registerPackages(); void initResources(); Common::SeekableReadStream *openFileRaw(const Common::String &filename); + Common::WriteStream *openFileForWriteRaw(const Common::String &filename); Common::SeekableReadStream *openPkgFile(const Common::String &filename); Common::FSList _packagePaths; bool registerPackage(Common::FSNode package, const Common::String &filename = "", bool searchSignature = false); diff --git a/engines/wintermute/base/file/base_savefile_manager_file.cpp b/engines/wintermute/base/file/base_savefile_manager_file.cpp new file mode 100644 index 0000000000..8bf684192a --- /dev/null +++ b/engines/wintermute/base/file/base_savefile_manager_file.cpp @@ -0,0 +1,53 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +/* + * This file is based on WME Lite. + * http://dead-code.org/redir.php?target=wmelite + * Copyright (c) 2011 Jan Nedoma + */ + +#include "engines/wintermute/base/file/base_savefile_manager_file.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_engine.h" +#include "common/system.h" +#include "common/savefile.h" + + +namespace Wintermute { + +Common::String makeSfmFilename(const Common::String &filename) { + Common::String smFilename = filename; + for (size_t i = 0; i < smFilename.size(); i++) { + if (smFilename[i] == '/' || smFilename[i] == '\\') { + smFilename.setChar('_', i); + } + } + return BaseEngine::instance().getGameTargetName() + "." + smFilename; +} + +Common::SeekableReadStream *openSfmFile(const Common::String &filename) { + Common::String smFilename = makeSfmFilename(filename); + return g_system->getSavefileManager()->openRawFile(smFilename); +} + +} // End of namespace Wintermute diff --git a/engines/wintermute/base/file/base_savefile_manager_file.h b/engines/wintermute/base/file/base_savefile_manager_file.h new file mode 100644 index 0000000000..fb9e150503 --- /dev/null +++ b/engines/wintermute/base/file/base_savefile_manager_file.h @@ -0,0 +1,40 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +/* + * This file is based on WME Lite. + * http://dead-code.org/redir.php?target=wmelite + * Copyright (c) 2011 Jan Nedoma + */ + +#ifndef WINTERMUTE_BASE_SAVEFILEMANAGERFILE_H +#define WINTERMUTE_BASE_SAVEFILEMANAGERFILE_H + +#include "common/stream.h" + +namespace Wintermute { + +Common::WriteStream *openSfmFileForWrite(const Common::String &filename); + +} // End of namespace Wintermute + +#endif diff --git a/engines/wintermute/base/scriptables/script_ext_file.cpp b/engines/wintermute/base/scriptables/script_ext_file.cpp index 15ddd4bcca..daded7057c 100644 --- a/engines/wintermute/base/scriptables/script_ext_file.cpp +++ b/engines/wintermute/base/scriptables/script_ext_file.cpp @@ -815,9 +815,8 @@ bool SXFile::persist(BasePersistenceManager *persistMgr) { return STATUS_OK; } -// Should replace fopen(..., "wb+") and fopen(..., "w+") Common::WriteStream *SXFile::openForWrite(const Common::String &filename, bool binary) { - error("SXFile::openForWrite - WriteFiles not supported"); + return BaseFileManager::getEngineInstance()->openFileForWrite(_filename); } // Should replace fopen(..., "ab+") and fopen(..., "a+") |