2007-05-30 21:56:52 +00:00
|
|
|
/* 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.
|
2006-06-24 10:08:43 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-29 16:18:43 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
2007-03-16 23:07:08 +00:00
|
|
|
#if !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
|
|
|
|
|
2008-11-03 10:45:59 +00:00
|
|
|
#include "backends/saves/default/default-saves.h"
|
|
|
|
|
2006-07-09 13:10:45 +00:00
|
|
|
#include "common/savefile.h"
|
2007-01-21 15:17:28 +00:00
|
|
|
#include "common/util.h"
|
2007-07-08 07:19:50 +00:00
|
|
|
#include "common/fs.h"
|
2008-11-21 20:02:55 +00:00
|
|
|
#include "common/archive.h"
|
2007-12-28 07:37:04 +00:00
|
|
|
#include "common/config-manager.h"
|
2009-01-22 23:14:16 +00:00
|
|
|
#include "common/zlib.h"
|
2006-06-24 10:08:43 +00:00
|
|
|
|
2010-11-05 10:31:36 +00:00
|
|
|
#ifndef _WIN32_WCE
|
2008-11-03 10:45:59 +00:00
|
|
|
#include <errno.h> // for removeSavefile()
|
2010-11-05 10:31:36 +00:00
|
|
|
#endif
|
2008-08-04 17:17:37 +00:00
|
|
|
|
|
|
|
DefaultSaveFileManager::DefaultSaveFileManager() {
|
|
|
|
}
|
|
|
|
|
2008-08-04 19:38:28 +00:00
|
|
|
DefaultSaveFileManager::DefaultSaveFileManager(const Common::String &defaultSavepath) {
|
|
|
|
ConfMan.registerDefault("savepath", defaultSavepath);
|
|
|
|
}
|
2008-08-04 17:17:37 +00:00
|
|
|
|
|
|
|
|
2008-11-06 16:40:00 +00:00
|
|
|
void DefaultSaveFileManager::checkPath(const Common::FSNode &dir) {
|
|
|
|
clearError();
|
|
|
|
if (!dir.exists()) {
|
|
|
|
setError(Common::kPathDoesNotExist, "The savepath '"+dir.getPath()+"' does not exist");
|
|
|
|
} else if (!dir.isDirectory()) {
|
|
|
|
setError(Common::kPathNotDirectory, "The savepath '"+dir.getPath()+"' is not a directory");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 15:44:59 +00:00
|
|
|
Common::StringArray DefaultSaveFileManager::listSavefiles(const Common::String &pattern) {
|
2009-07-10 22:29:25 +00:00
|
|
|
Common::String savePathName = getSavePath();
|
|
|
|
checkPath(Common::FSNode(savePathName));
|
2008-11-06 16:40:00 +00:00
|
|
|
if (getError() != Common::kNoError)
|
2010-03-18 15:44:59 +00:00
|
|
|
return Common::StringArray();
|
2008-11-06 16:40:00 +00:00
|
|
|
|
2009-07-10 22:29:25 +00:00
|
|
|
// recreate FSNode since checkPath may have changed/created the directory
|
|
|
|
Common::FSNode savePath(savePathName);
|
|
|
|
|
2008-11-21 20:02:55 +00:00
|
|
|
Common::FSDirectory dir(savePath);
|
|
|
|
Common::ArchiveMemberList savefiles;
|
2010-03-18 15:44:59 +00:00
|
|
|
Common::StringArray results;
|
2007-12-30 13:05:38 +00:00
|
|
|
Common::String search(pattern);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2008-11-21 20:02:55 +00:00
|
|
|
if (dir.listMatchingMembers(savefiles, search) > 0) {
|
|
|
|
for (Common::ArchiveMemberList::const_iterator file = savefiles.begin(); file != savefiles.end(); ++file) {
|
|
|
|
results.push_back((*file)->getName());
|
2007-09-18 20:02:04 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-09-18 20:02:04 +00:00
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
2009-05-29 14:38:22 +00:00
|
|
|
Common::InSaveFile *DefaultSaveFileManager::openForLoading(const Common::String &filename) {
|
2007-12-28 07:37:04 +00:00
|
|
|
// Ensure that the savepath is valid. If not, generate an appropriate error.
|
2009-07-10 22:29:25 +00:00
|
|
|
Common::String savePathName = getSavePath();
|
|
|
|
checkPath(Common::FSNode(savePathName));
|
2008-11-06 16:40:00 +00:00
|
|
|
if (getError() != Common::kNoError)
|
|
|
|
return 0;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2009-07-10 22:29:25 +00:00
|
|
|
// recreate FSNode since checkPath may have changed/created the directory
|
|
|
|
Common::FSNode savePath(savePathName);
|
|
|
|
|
2008-11-06 16:40:00 +00:00
|
|
|
Common::FSNode file = savePath.getChild(filename);
|
2009-02-28 18:07:14 +00:00
|
|
|
if (!file.exists())
|
|
|
|
return 0;
|
2008-08-04 11:32:42 +00:00
|
|
|
|
2008-11-06 16:40:00 +00:00
|
|
|
// Open the file for reading
|
2009-01-23 03:41:36 +00:00
|
|
|
Common::SeekableReadStream *sf = file.createReadStream();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2009-01-22 23:14:16 +00:00
|
|
|
return Common::wrapCompressedReadStream(sf);
|
2007-12-28 07:37:04 +00:00
|
|
|
}
|
2006-06-24 10:08:43 +00:00
|
|
|
|
2009-05-29 14:38:22 +00:00
|
|
|
Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const Common::String &filename) {
|
2007-12-28 07:37:04 +00:00
|
|
|
// Ensure that the savepath is valid. If not, generate an appropriate error.
|
2009-07-10 22:29:25 +00:00
|
|
|
Common::String savePathName = getSavePath();
|
|
|
|
checkPath(Common::FSNode(savePathName));
|
2008-11-06 16:40:00 +00:00
|
|
|
if (getError() != Common::kNoError)
|
|
|
|
return 0;
|
2006-06-24 10:08:43 +00:00
|
|
|
|
2009-07-10 22:29:25 +00:00
|
|
|
// recreate FSNode since checkPath may have changed/created the directory
|
|
|
|
Common::FSNode savePath(savePathName);
|
|
|
|
|
2008-11-06 16:40:00 +00:00
|
|
|
Common::FSNode file = savePath.getChild(filename);
|
2008-08-04 11:32:42 +00:00
|
|
|
|
2008-11-06 16:40:00 +00:00
|
|
|
// Open the file for saving
|
2009-01-23 03:41:36 +00:00
|
|
|
Common::WriteStream *sf = file.createWriteStream();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2009-01-22 23:14:16 +00:00
|
|
|
return Common::wrapCompressedWriteStream(sf);
|
2006-06-24 10:08:43 +00:00
|
|
|
}
|
|
|
|
|
2009-05-29 14:38:22 +00:00
|
|
|
bool DefaultSaveFileManager::removeSavefile(const Common::String &filename) {
|
2009-07-10 22:29:25 +00:00
|
|
|
Common::String savePathName = getSavePath();
|
|
|
|
checkPath(Common::FSNode(savePathName));
|
2008-11-06 16:40:00 +00:00
|
|
|
if (getError() != Common::kNoError)
|
|
|
|
return false;
|
2008-08-04 11:32:42 +00:00
|
|
|
|
2009-07-10 22:29:25 +00:00
|
|
|
// recreate FSNode since checkPath may have changed/created the directory
|
|
|
|
Common::FSNode savePath(savePathName);
|
|
|
|
|
2008-11-06 16:40:00 +00:00
|
|
|
Common::FSNode file = savePath.getChild(filename);
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-11-06 16:40:00 +00:00
|
|
|
// FIXME: remove does not exist on all systems. If your port fails to
|
|
|
|
// compile because of this, please let us know (scummvm-devel or Fingolfin).
|
|
|
|
// There is a nicely portable workaround, too: Make this method overloadable.
|
2008-08-04 11:32:42 +00:00
|
|
|
if (remove(file.getPath().c_str()) != 0) {
|
2007-11-03 21:17:40 +00:00
|
|
|
#ifndef _WIN32_WCE
|
2007-10-31 13:59:59 +00:00
|
|
|
if (errno == EACCES)
|
2008-11-06 16:40:00 +00:00
|
|
|
setError(Common::kWritePermissionDenied, "Search or write permission denied: "+file.getName());
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-10-31 13:59:59 +00:00
|
|
|
if (errno == ENOENT)
|
2008-11-06 16:40:00 +00:00
|
|
|
setError(Common::kPathDoesNotExist, "removeSavefile: '"+file.getName()+"' does not exist or path is invalid");
|
2007-11-03 21:17:40 +00:00
|
|
|
#endif
|
2007-10-31 13:59:59 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
2007-10-31 19:09:23 +00:00
|
|
|
}
|
2006-06-24 10:08:43 +00:00
|
|
|
}
|
2007-03-16 23:07:08 +00:00
|
|
|
|
2007-12-28 21:12:30 +00:00
|
|
|
Common::String DefaultSaveFileManager::getSavePath() const {
|
2007-12-28 07:37:04 +00:00
|
|
|
|
2007-12-28 21:12:30 +00:00
|
|
|
Common::String dir;
|
2007-12-28 07:37:04 +00:00
|
|
|
|
|
|
|
// Try to use game specific savepath from config
|
2007-12-28 21:12:30 +00:00
|
|
|
dir = ConfMan.get("savepath");
|
2007-12-28 07:37:04 +00:00
|
|
|
|
|
|
|
// Work around a bug (#999122) in the original 0.6.1 release of
|
|
|
|
// ScummVM, which would insert a bad savepath value into config files.
|
2007-12-28 21:12:30 +00:00
|
|
|
if (dir == "None") {
|
2007-12-28 07:37:04 +00:00
|
|
|
ConfMan.removeKey("savepath", ConfMan.getActiveDomainName());
|
|
|
|
ConfMan.flushToDisk();
|
2007-12-28 21:12:30 +00:00
|
|
|
dir = ConfMan.get("savepath");
|
2007-12-28 07:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32_WCE
|
2007-12-28 21:12:30 +00:00
|
|
|
if (dir.empty())
|
|
|
|
dir = ConfMan.get("path");
|
2007-12-28 07:37:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2007-03-16 23:07:08 +00:00
|
|
|
#endif // !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
|