Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,396 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/scummsys.h"
#ifdef USE_CLOUD
#include "backends/cloud/cloudmanager.h"
#endif
#include "common/file.h"
#include "common/system.h"
#if !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
#include "backends/saves/default/default-saves.h"
#include "common/savefile.h"
#include "common/util.h"
#include "common/fs.h"
#include "common/archive.h"
#include "common/config-manager.h"
#include "common/compression/deflate.h"
#include <errno.h> // for removeSavefile()
#ifdef USE_CLOUD
const char *const DefaultSaveFileManager::TIMESTAMPS_FILENAME = "timestamps";
#endif
DefaultSaveFileManager::DefaultSaveFileManager() {
}
DefaultSaveFileManager::DefaultSaveFileManager(const Common::Path &defaultSavepath) {
ConfMan.registerDefault("savepath", defaultSavepath);
}
void DefaultSaveFileManager::checkPath(const Common::FSNode &dir) {
clearError();
if (!dir.exists()) {
if (!dir.createDirectory()) {
setError(Common::kPathDoesNotExist, Common::String::format("Failed to create directory '%s'", dir.getPath().toString(Common::Path::kNativeSeparator).c_str()));
}
} else if (!dir.isDirectory()) {
setError(Common::kPathNotDirectory, Common::String::format("The savepath '%s' is not a directory", dir.getPath().toString(Common::Path::kNativeSeparator).c_str()));
}
}
void DefaultSaveFileManager::updateSavefilesList(Common::StringArray &lockedFiles) {
//make it refresh the cache next time it lists the saves
_cachedDirectory = "";
//remember the locked files list because some of these files don't exist yet
_lockedFiles = lockedFiles;
}
Common::StringArray DefaultSaveFileManager::listSavefiles(const Common::String &pattern) {
// Assure the savefile name cache is up-to-date.
assureCached(getSavePath());
if (getError().getCode() != Common::kNoError)
return Common::StringArray();
Common::HashMap<Common::String, bool> locked;
for (const auto &lockedFile : _lockedFiles) {
locked[lockedFile] = true;
}
Common::StringArray results;
for (const auto &file : _saveFileCache) {
if (!locked.contains(file._key) && file._key.matchString(pattern, true)) {
results.push_back(file._key);
}
}
return results;
}
Common::InSaveFile *DefaultSaveFileManager::openRawFile(const Common::String &filename) {
// Assure the savefile name cache is up-to-date.
assureCached(getSavePath());
if (getError().getCode() != Common::kNoError)
return nullptr;
SaveFileCache::const_iterator file = _saveFileCache.find(filename);
if (file == _saveFileCache.end()) {
return nullptr;
} else {
// Open the file for loading.
Common::SeekableReadStream *sf = file->_value.createReadStream();
return sf;
}
}
Common::InSaveFile *DefaultSaveFileManager::openForLoading(const Common::String &filename) {
// Assure the savefile name cache is up-to-date.
assureCached(getSavePath());
if (getError().getCode() != Common::kNoError)
return nullptr;
for (const auto &lockedFile : _lockedFiles) {
if (filename == lockedFile) {
setError(Common::kReadingFailed, Common::String::format("Savefile '%s' is locked and cannot be loaded", filename.c_str()));
return nullptr; // file is locked, no loading available
}
}
SaveFileCache::const_iterator file = _saveFileCache.find(filename);
if (file == _saveFileCache.end()) {
setError(Common::kPathDoesNotExist, Common::String::format("Savefile '%s' does not exist", filename.c_str()));
return nullptr;
} else {
// Open the file for loading.
Common::SeekableReadStream *sf = file->_value.createReadStream();
return Common::wrapCompressedReadStream(sf);
}
}
Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const Common::String &filename, bool compress) {
// Assure the savefile name cache is up-to-date.
const Common::Path savePathName = getSavePath();
assureCached(savePathName);
if (getError().getCode() != Common::kNoError)
return nullptr;
for (const auto &lockedFile : _lockedFiles) {
if (filename == lockedFile) {
return nullptr; // file is locked, no saving available
}
}
#ifdef USE_CLOUD
// Update file's timestamp
Common::HashMap<Common::String, uint32> timestamps = loadTimestamps();
timestamps[filename] = INVALID_TIMESTAMP;
saveTimestamps(timestamps);
#endif
// Obtain node.
SaveFileCache::const_iterator file = _saveFileCache.find(filename);
Common::FSNode fileNode;
// If the file did not exist before, we add it to the cache.
if (file == _saveFileCache.end()) {
const Common::FSNode savePath(savePathName);
fileNode = savePath.getChild(filename);
} else {
fileNode = file->_value;
}
// Open the file for saving.
Common::SeekableWriteStream *const sf = fileNode.createWriteStream(false);
if (!sf)
return nullptr;
Common::OutSaveFile *const result = new Common::OutSaveFile(compress ? Common::wrapCompressedWriteStream(sf) : sf);
// Add file to cache now that it exists.
_saveFileCache[filename] = Common::FSNode(fileNode.getPath());
return result;
}
bool DefaultSaveFileManager::removeSavefile(const Common::String &filename) {
// Assure the savefile name cache is up-to-date.
assureCached(getSavePath());
if (getError().getCode() != Common::kNoError)
return false;
#ifdef USE_CLOUD
// Update file's timestamp
Common::HashMap<Common::String, uint32> timestamps = loadTimestamps();
Common::HashMap<Common::String, uint32>::iterator it = timestamps.find(filename);
if (it != timestamps.end()) {
timestamps.erase(it);
saveTimestamps(timestamps);
}
#endif
// Obtain node if exists.
SaveFileCache::const_iterator file = _saveFileCache.find(filename);
if (file == _saveFileCache.end()) {
return false;
} else {
const Common::FSNode fileNode = file->_value;
// Remove from cache, this invalidates the 'file' iterator.
_saveFileCache.erase(file);
file = _saveFileCache.end();
Common::ErrorCode result = removeFile(fileNode);
if (result == Common::kNoError)
return true;
Common::Error error(result);
setError(error, "Failed to remove savefile '" + fileNode.getName() + "': " + error.getDesc());
return false;
}
}
Common::ErrorCode DefaultSaveFileManager::removeFile(const Common::FSNode &fileNode) {
Common::String filepath(fileNode.getPath().toString(Common::Path::kNativeSeparator));
if (remove(filepath.c_str()) == 0)
return Common::kNoError;
if (errno == EACCES)
return Common::kWritePermissionDenied;
if (errno == ENOENT)
return Common::kPathDoesNotExist;
return Common::kUnknownError;
}
bool DefaultSaveFileManager::exists(const Common::String &filename) {
// Assure the savefile name cache is up-to-date.
assureCached(getSavePath());
if (getError().getCode() != Common::kNoError)
return false;
for (const auto &lockedFile : _lockedFiles) {
if (filename == lockedFile)
return true;
}
return _saveFileCache.contains(filename);
}
Common::Path DefaultSaveFileManager::getSavePath() const {
Common::Path dir;
// Try to use game specific savepath from config
dir = ConfMan.getPath("savepath");
// Work around a bug (#1689) in the original 0.6.1 release of
// ScummVM, which would insert a bad savepath value into config files.
if (dir == "None") {
ConfMan.removeKey("savepath", ConfMan.getActiveDomainName());
ConfMan.flushToDisk();
dir = ConfMan.getPath("savepath");
}
return dir;
}
void DefaultSaveFileManager::assureCached(const Common::Path &savePathName) {
// Check that path exists and is usable.
checkPath(Common::FSNode(savePathName));
#ifdef USE_CLOUD
Common::Array<Common::String> files = CloudMan.getSyncingFiles(); //returns empty array if not syncing
if (!files.empty()) updateSavefilesList(files); //makes this cache invalid
else _lockedFiles = files;
#endif
if (_cachedDirectory == savePathName) {
return;
}
_saveFileCache.clear();
_cachedDirectory.clear();
if (getError().getCode() != Common::kNoError) {
warning("DefaultSaveFileManager::assureCached: Can not cache path '%s': '%s'", savePathName.toString(Common::Path::kNativeSeparator).c_str(), getErrorDesc().c_str());
return;
}
// FSNode can cache its members, thus create it after checkPath to reflect
// actual file system state.
const Common::FSNode savePath(savePathName);
Common::FSList children;
if (!savePath.getChildren(children, Common::FSNode::kListFilesOnly)) {
return;
}
// Build the savefile name cache.
for (const auto &file : children) {
if (_saveFileCache.contains(file.getName())) {
warning("DefaultSaveFileManager::assureCached: Name clash when building cache, ignoring file '%s'", file.getName().c_str());
} else {
_saveFileCache[file.getName()] = file;
}
}
// Only now store that we cached 'savePathName' to indicate we successfully
// cached the directory.
_cachedDirectory = savePathName;
}
#ifdef USE_CLOUD
Common::HashMap<Common::String, uint32> DefaultSaveFileManager::loadTimestamps() {
Common::HashMap<Common::String, uint32> timestamps;
//refresh the files list
Common::Array<Common::String> files;
g_system->getSavefileManager()->updateSavefilesList(files);
//start with listing all the files in saves/ directory and setting invalid timestamp to them
Common::StringArray localFiles = g_system->getSavefileManager()->listSavefiles("*");
for (uint32 i = 0; i < localFiles.size(); ++i)
timestamps[localFiles[i]] = INVALID_TIMESTAMP;
//now actually load timestamps from file
Common::InSaveFile *file = g_system->getSavefileManager()->openRawFile(TIMESTAMPS_FILENAME);
if (!file) {
warning("DefaultSaveFileManager: failed to open '%s' file to load timestamps", TIMESTAMPS_FILENAME);
return timestamps;
}
while (!file->eos()) {
//read filename into buffer (reading until the first ' ')
Common::String buffer;
while (true) {
byte b = file->readByte();
if (file->eos()) break;
if (b == ' ') break;
buffer += (char)b;
}
//read timestamp info buffer (reading until ' ' or some line ending char)
Common::String filename = buffer;
while (true) {
bool lineEnded = false;
buffer = "";
while (true) {
byte b = file->readByte();
if (file->eos()) break;
if (b == ' ' || b == '\n' || b == '\r') {
lineEnded = (b == '\n');
break;
}
buffer += (char)b;
}
if (buffer == "" && file->eos()) break;
if (!lineEnded) filename += " " + buffer;
else break;
}
//parse timestamp
uint32 timestamp = buffer.asUint64();
if (buffer == "" || timestamp == 0) break;
if (timestamps.contains(filename))
timestamps[filename] = timestamp;
}
delete file;
return timestamps;
}
void DefaultSaveFileManager::saveTimestamps(Common::HashMap<Common::String, uint32> &timestamps) {
Common::DumpFile f;
Common::Path filename = concatWithSavesPath(TIMESTAMPS_FILENAME);
if (!f.open(filename, true)) {
warning("DefaultSaveFileManager: failed to open '%s' file to save timestamps", filename.toString(Common::Path::kNativeSeparator).c_str());
return;
}
for (auto &timestamp : timestamps) {
uint32 v = timestamp._value;
if (v < 1) v = 1; // 0 timestamp is treated as EOF up there, so we should never save zeros
Common::String data = timestamp._key + Common::String::format(" %u\n", v);
if (f.write(data.c_str(), data.size()) != data.size()) {
warning("DefaultSaveFileManager: failed to write timestamps data into '%s'", filename.toString(Common::Path::kNativeSeparator).c_str());
return;
}
}
f.flush();
f.finalize();
f.close();
}
#endif // ifdef USE_CLOUD
Common::Path DefaultSaveFileManager::concatWithSavesPath(Common::String name) {
DefaultSaveFileManager *manager = dynamic_cast<DefaultSaveFileManager *>(g_system->getSavefileManager());
Common::Path path = (manager ? manager->getSavePath() : ConfMan.getPath("savepath"));
path.joinInPlace(name);
return path;
}
#endif // !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)

View File

@@ -0,0 +1,109 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#if !defined(BACKEND_SAVES_DEFAULT_H) && !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
#define BACKEND_SAVES_DEFAULT_H
#include "common/scummsys.h"
#include "common/savefile.h"
#include "common/str.h"
#include "common/fs.h"
#include "common/hash-str.h"
/**
* Provides a default savefile manager implementation for common platforms.
*/
class DefaultSaveFileManager : public Common::SaveFileManager {
public:
DefaultSaveFileManager();
DefaultSaveFileManager(const Common::Path &defaultSavepath);
void updateSavefilesList(Common::StringArray &lockedFiles) override;
Common::StringArray listSavefiles(const Common::String &pattern) override;
Common::InSaveFile *openRawFile(const Common::String &filename) override;
Common::InSaveFile *openForLoading(const Common::String &filename) override;
Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true) override;
bool removeSavefile(const Common::String &filename) override;
bool exists(const Common::String &filename) override;
#ifdef USE_CLOUD
static const uint32 INVALID_TIMESTAMP = UINT_MAX;
static const char *const TIMESTAMPS_FILENAME;
static Common::HashMap<Common::String, uint32> loadTimestamps();
static void saveTimestamps(Common::HashMap<Common::String, uint32> &timestamps);
#endif
static Common::Path concatWithSavesPath(Common::String name);
protected:
/**
* Get the path to the savegame directory.
* Should only be used internally since some platforms
* might implement savefiles in a completely different way.
*/
virtual Common::Path getSavePath() const;
/**
* Checks the given path for read access, existence, etc.
* Sets the internal error and error message accordingly.
*/
virtual void checkPath(const Common::FSNode &dir);
/**
* Removes the given file.
* This is called from removeSavefile() with the full file path.
*/
virtual Common::ErrorCode removeFile(const Common::FSNode &fileNode);
/**
* Assure that the given save path is cached.
*
* @param savePathName String representation of save path to cache.
*/
void assureCached(const Common::Path &savePathName);
typedef Common::HashMap<Common::String, Common::FSNode, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> SaveFileCache;
/**
* Cache of all the save files in the currently cached directory.
*
* Modify with caution because we only re-cache when the save path changed!
* This needs to be updated inside at least openForSaving and
* removeSavefile.
*/
SaveFileCache _saveFileCache;
/**
* List of "locked" files. These cannot be used for saving/loading
* because CloudManager is downloading those.
*/
Common::StringArray _lockedFiles;
private:
/**
* The currently cached directory.
*/
Common::Path _cachedDirectory;
};
#endif

View File

@@ -0,0 +1,74 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
#define FORBIDDEN_SYMBOL_EXCEPTION_getenv
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
#include "common/scummsys.h"
#if !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
#include "backends/saves/kolibrios/kolibrios-saves.h"
#include "backends/fs/kolibrios/kolibrios-fs.h"
#include "common/config-manager.h"
#include "common/savefile.h"
#include "common/textconsole.h"
#include <sys/stat.h>
KolibriOSSaveFileManager::KolibriOSSaveFileManager(const Common::Path& writeablePath) {
// Register default savepath.
Common::Path savePath;
if (KolibriOS::assureDirectoryExists("saves", writeablePath.toString().c_str())) {
savePath = writeablePath.join("saves");
}
if (!savePath.empty() && savePath.size() < MAXPATHLEN) {
ConfMan.registerDefault("savepath", savePath);
}
// The user can override the savepath with the SCUMMVM_SAVEPATH
// environment variable. This is weaker than a --savepath on the
// command line, but overrides the default savepath.
//
// To ensure that the command line option (if given) has precedence,
// we only set the value in the transient domain if it is not
// yet present there.
if (!ConfMan.hasKey("savepath", Common::ConfigManager::kTransientDomain)) {
const char *dir = getenv("SCUMMVM_SAVEPATH");
if (dir && *dir && strlen(dir) < MAXPATHLEN) {
Common::FSNode saveDir(dir);
if (!saveDir.exists()) {
warning("Ignoring non-existent SCUMMVM_SAVEPATH '%s'", dir);
} else if (!saveDir.isWritable()) {
warning("Ignoring non-writable SCUMMVM_SAVEPATH '%s'", dir);
} else {
ConfMan.setPath("savepath", dir, Common::ConfigManager::kTransientDomain);
}
}
}
}
#endif

View File

@@ -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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#if !defined(BACKEND_KOLIBRIOS_SAVES_H) && !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
#define BACKEND_KOLIBRIOS_SAVES_H
#include "backends/saves/default/default-saves.h"
#if !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
/**
* Customization of the DefaultSaveFileManager for KolibriOS.
* The only two differences are that the default constructor sets
* up the savepath based on HOME, and that checkPath tries to
* create the savedir, if missing, via the mkdir() syscall.
*/
class KolibriOSSaveFileManager : public DefaultSaveFileManager {
public:
KolibriOSSaveFileManager(const Common::Path& writeablePath);
};
#endif
#endif

View File

@@ -0,0 +1,130 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
// Re-enable some forbidden symbols to avoid clashes with stat.h and unistd.h.
// Also with clock() in sys/time.h in some macOS SDKs.
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h //On IRIX, sys/stat.h includes sys/time.h
#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
#define FORBIDDEN_SYMBOL_EXCEPTION_getenv
#include "common/scummsys.h"
#if defined(POSIX) && !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
#include "backends/saves/posix/posix-saves.h"
#include "backends/fs/posix/posix-fs.h"
#if defined(MACOSX)
#include "backends/platform/sdl/macosx/macosx_wrapper.h"
#endif
#include "common/config-manager.h"
#include "common/savefile.h"
#include "common/textconsole.h"
#include <sys/stat.h>
POSIXSaveFileManager::POSIXSaveFileManager() {
// Register default savepath.
Common::Path savePath;
#if defined(MACOSX)
savePath = getAppSupportPathMacOSX();
if (!savePath.empty()) {
savePath.joinInPlace("Savegames");
ConfMan.registerDefault("savepath", savePath);
}
#elif defined(EMSCRIPTEN)
savePath = getenv("HOME");
savePath.joinInPlace("saves");
ConfMan.registerDefault("savepath", savePath);
#else
const char *envVar;
// Previously we placed our default savepath in HOME. If the directory
// still exists, we will use it for backwards compatibility.
envVar = getenv("HOME");
if (envVar && *envVar) {
savePath = envVar;
savePath.joinInPlace("/.scummvm");
struct stat sb;
if (stat(savePath.toString(Common::Path::kNativeSeparator).c_str(), &sb) != 0 || !S_ISDIR(sb.st_mode)) {
savePath.clear();
}
}
if (savePath.empty()) {
Common::String prefix;
// On POSIX systems we follow the XDG Base Directory Specification for
// where to store files. The version we based our code upon can be found
// over here: https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.8.html
envVar = getenv("XDG_DATA_HOME");
if (!envVar || !*envVar) {
envVar = getenv("HOME");
if (envVar && *envVar) {
prefix = envVar;
savePath = Common::Path(".local/share");
}
} else {
prefix = envVar;
}
// Our default save path is '$XDG_DATA_HOME/scummvm/saves'
savePath.joinInPlace("scummvm/saves");
if (!Posix::assureDirectoryExists(savePath.toString(Common::Path::kNativeSeparator), prefix.c_str())) {
savePath.clear();
} else {
savePath = Common::Path(prefix).join(savePath);
}
}
if (!savePath.empty() && savePath.toString(Common::Path::kNativeSeparator).size() < MAXPATHLEN) {
ConfMan.registerDefault("savepath", savePath);
}
#endif
// The user can override the savepath with the SCUMMVM_SAVEPATH
// environment variable. This is weaker than a --savepath on the
// command line, but overrides the default savepath.
//
// To ensure that the command line option (if given) has precedence,
// we only set the value in the transient domain if it is not
// yet present there.
if (!ConfMan.hasKey("savepath", Common::ConfigManager::kTransientDomain)) {
const char *dir = getenv("SCUMMVM_SAVEPATH");
if (dir && *dir && strlen(dir) < MAXPATHLEN) {
Common::FSNode saveDir(dir);
if (!saveDir.exists()) {
warning("Ignoring non-existent SCUMMVM_SAVEPATH '%s'", dir);
} else if (!saveDir.isWritable()) {
warning("Ignoring non-writable SCUMMVM_SAVEPATH '%s'", dir);
} else {
ConfMan.setPath("savepath", dir, Common::ConfigManager::kTransientDomain);
}
}
}
}
#endif

View File

@@ -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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#if !defined(BACKEND_POSIX_SAVES_H) && !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
#define BACKEND_POSIX_SAVES_H
#include "backends/saves/default/default-saves.h"
#if defined(POSIX) && !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
/**
* Customization of the DefaultSaveFileManager for POSIX platforms.
* The only two differences are that the default constructor sets
* up the savepath based on HOME, and that checkPath tries to
* create the savedir, if missing, via the mkdir() syscall.
*/
class POSIXSaveFileManager : public DefaultSaveFileManager {
public:
POSIXSaveFileManager();
};
#endif
#endif

View File

@@ -0,0 +1,33 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "backends/saves/recorder/recorder-saves.h"
#include "gui/EventRecorder.h"
#include "common/savefile.h"
Common::InSaveFile *RecorderSaveFileManager::openForLoading(const Common::String &filename) {
Common::InSaveFile *result = g_eventRec.processSaveStream(filename);
return result;
}
Common::StringArray RecorderSaveFileManager::listSaveFiles(const Common::String &pattern) {
return g_eventRec.listSaveFiles(pattern);
}

View File

@@ -0,0 +1,35 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BACKEND_SAVES_RECORDER_H
#define BACKEND_SAVES_RECORDER_H
#include "backends/saves/default/default-saves.h"
/**
* Provides a savefile manager implementation for event recorder.
*/
class RecorderSaveFileManager : public DefaultSaveFileManager {
virtual Common::StringArray listSaveFiles(const Common::String &pattern);
virtual Common::InSaveFile *openForLoading(const Common::String &filename);
};
#endif

134
backends/saves/savefile.cpp Normal file
View File

@@ -0,0 +1,134 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/util.h"
#include "common/savefile.h"
#include "common/str.h"
#ifdef USE_CLOUD
#include "backends/cloud/cloudmanager.h"
#endif
namespace Common {
OutSaveFile::OutSaveFile(WriteStream *w): _wrapped(w) {}
OutSaveFile::~OutSaveFile() {
delete _wrapped;
#ifdef USE_CLOUD
CloudMan.syncSaves();
#endif
}
bool OutSaveFile::err() const { return _wrapped->err(); }
void OutSaveFile::clearErr() { _wrapped->clearErr(); }
void OutSaveFile::finalize() {
_wrapped->finalize();
}
bool OutSaveFile::flush() { return _wrapped->flush(); }
uint32 OutSaveFile::write(const void *dataPtr, uint32 dataSize) {
return _wrapped->write(dataPtr, dataSize);
}
int64 OutSaveFile::pos() const {
return _wrapped->pos();
}
bool OutSaveFile::seek(int64 offset, int whence) {
Common::SeekableWriteStream *sws =
dynamic_cast<Common::SeekableWriteStream *>(_wrapped);
if (sws) {
return sws->seek(offset, whence);
} else {
warning("Seeking isn't supported for compressed save files");
return false;
}
}
int64 OutSaveFile::size() const {
Common::SeekableWriteStream *sws =
dynamic_cast<Common::SeekableWriteStream *>(_wrapped);
if (sws) {
return sws->size();
} else {
warning("Size isn't supported for compressed save files");
return -1;
}
}
bool SaveFileManager::copySavefile(const String &oldFilename, const String &newFilename, bool compress) {
InSaveFile *inFile = nullptr;
OutSaveFile *outFile = nullptr;
uint32 size = 0;
void *buffer = nullptr;
bool success = false;
inFile = openForLoading(oldFilename);
if (inFile) {
size = inFile->size();
buffer = malloc(size);
assert(buffer);
outFile = openForSaving(newFilename, compress);
if (buffer && outFile) {
inFile->read(buffer, size);
bool error = inFile->err();
delete inFile;
inFile = nullptr;
if (!error) {
outFile->write(buffer, size);
outFile->finalize();
success = !outFile->err();
}
}
free(buffer);
delete outFile;
delete inFile;
}
return success;
}
bool SaveFileManager::renameSavefile(const String &oldFilename, const String &newFilename, bool compress) {
if (!copySavefile(oldFilename, newFilename, compress))
return false;
return removeSavefile(oldFilename);
}
String SaveFileManager::popErrorDesc() {
String err = _errorDesc;
clearError();
return err;
}
} // End of namespace Common

View File

@@ -0,0 +1,71 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#if defined(WIN32) && !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
// For _tcscat
#define FORBIDDEN_SYMBOL_EXCEPTION_strcat
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#include <errno.h>
#include "common/scummsys.h"
#include "common/config-manager.h"
#include "backends/saves/windows/windows-saves.h"
#include "backends/platform/sdl/win32/win32_wrapper.h"
WindowsSaveFileManager::WindowsSaveFileManager(bool isPortable) {
TCHAR defaultSavepath[MAX_PATH];
if (isPortable) {
Win32::getProcessDirectory(defaultSavepath, MAX_PATH);
} else {
// Use the Application Data directory of the user profile
if (!Win32::getApplicationDataDirectory(defaultSavepath)) {
return;
}
}
_tcscat(defaultSavepath, TEXT("\\Saved games"));
if (!CreateDirectory(defaultSavepath, nullptr)) {
if (GetLastError() != ERROR_ALREADY_EXISTS)
error("Cannot create ScummVM Saved games folder");
}
ConfMan.registerDefault("savepath", Common::Path(Win32::tcharToString(defaultSavepath), Common::Path::kNativeSeparator));
}
Common::ErrorCode WindowsSaveFileManager::removeFile(const Common::FSNode &fileNode) {
TCHAR *tFile = Win32::stringToTchar(fileNode.getPath().toString(Common::Path::kNativeSeparator));
int result = _tremove(tFile);
free(tFile);
if (result == 0)
return Common::kNoError;
if (errno == EACCES)
return Common::kWritePermissionDenied;
if (errno == ENOENT)
return Common::kPathDoesNotExist;
return Common::kUnknownError;
}
#endif

View File

@@ -0,0 +1,38 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BACKEND_WINDOWS_SAVES_H
#define BACKEND_WINDOWS_SAVES_H
#include "backends/saves/default/default-saves.h"
/**
* Provides a savefile manager implementation for Windows.
*/
class WindowsSaveFileManager final : public DefaultSaveFileManager {
public:
WindowsSaveFileManager(bool isPortable);
protected:
Common::ErrorCode removeFile(const Common::FSNode &fileNode) override;
};
#endif