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.
|
2002-12-17 01:15:13 +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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-12-17 01:15:13 +00:00
|
|
|
*
|
2006-02-11 09:53:53 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-12-17 01:15:13 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMMON_SAVEFILE_H
|
|
|
|
#define COMMON_SAVEFILE_H
|
|
|
|
|
2007-03-17 10:36:14 +00:00
|
|
|
#include "common/noncopyable.h"
|
2003-08-10 20:49:13 +00:00
|
|
|
#include "common/scummsys.h"
|
2004-04-17 09:57:15 +00:00
|
|
|
#include "common/stream.h"
|
2007-07-12 17:58:15 +00:00
|
|
|
#include "common/str.h"
|
2007-09-18 20:02:04 +00:00
|
|
|
#include "common/error.h"
|
2003-08-10 20:49:13 +00:00
|
|
|
|
2005-05-10 23:17:38 +00:00
|
|
|
namespace Common {
|
|
|
|
|
2005-04-10 15:13:40 +00:00
|
|
|
/**
|
|
|
|
* A class which allows game engines to load game state data.
|
|
|
|
* That typically means "save games", but also includes things like the
|
|
|
|
* IQ points in Indy3.
|
|
|
|
*/
|
2008-08-04 11:38:25 +00:00
|
|
|
typedef SeekableReadStream InSaveFile;
|
2003-08-10 20:49:13 +00:00
|
|
|
|
2005-04-10 15:13:40 +00:00
|
|
|
/**
|
|
|
|
* A class which allows game engines to save game state data.
|
|
|
|
* That typically means "save games", but also includes things like the
|
|
|
|
* IQ points in Indy3.
|
|
|
|
*/
|
2008-08-04 11:38:25 +00:00
|
|
|
typedef WriteStream OutSaveFile;
|
2005-04-10 15:13:40 +00:00
|
|
|
|
2007-02-17 22:11:00 +00:00
|
|
|
|
2005-04-10 15:13:40 +00:00
|
|
|
/**
|
2008-02-22 00:22:31 +00:00
|
|
|
* The SaveFileManager is serving as a factory for InSaveFile
|
2007-02-17 22:11:00 +00:00
|
|
|
* and OutSaveFile objects.
|
|
|
|
*
|
|
|
|
* Engines and other code should use SaveFiles whenever they need to
|
2008-02-22 00:22:31 +00:00
|
|
|
* store data which they need to be able to retrieve again later on --
|
2007-02-17 22:11:00 +00:00
|
|
|
* i.e. typically save states, but also configuration files and similar
|
|
|
|
* things.
|
|
|
|
*
|
2008-02-22 00:22:31 +00:00
|
|
|
* While not declared as a singleton, it is effectively used as such,
|
|
|
|
* with OSystem::getSavefileManager returning a pointer to the single
|
|
|
|
* SaveFileManager instances to be used.
|
2005-04-10 15:13:40 +00:00
|
|
|
*/
|
2007-03-17 10:36:14 +00:00
|
|
|
class SaveFileManager : NonCopyable {
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-07-18 20:51:26 +00:00
|
|
|
protected:
|
2008-11-06 16:40:00 +00:00
|
|
|
Error _error;
|
2007-07-18 20:51:26 +00:00
|
|
|
String _errorDesc;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-12-23 18:12:03 +00:00
|
|
|
/**
|
2008-02-22 00:22:31 +00:00
|
|
|
* Set some information about the last error which occurred .
|
2007-12-23 18:12:03 +00:00
|
|
|
* @param error Code identifying the last error.
|
|
|
|
* @param errorDesc String describing the last error.
|
|
|
|
*/
|
2008-11-06 16:40:00 +00:00
|
|
|
virtual void setError(Error error, const String &errorDesc) { _error = error; _errorDesc = errorDesc; }
|
2007-12-23 18:12:03 +00:00
|
|
|
|
2002-12-17 01:15:13 +00:00
|
|
|
public:
|
|
|
|
virtual ~SaveFileManager() {}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-07-18 20:51:26 +00:00
|
|
|
/**
|
|
|
|
* Clears the last set error code and string.
|
|
|
|
*/
|
2008-11-06 16:40:00 +00:00
|
|
|
virtual void clearError() { _error = kNoError; _errorDesc.clear(); }
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-07-18 20:51:26 +00:00
|
|
|
/**
|
2008-11-06 16:40:00 +00:00
|
|
|
* Returns the last occurred error code. If none occurred, returns kNoError.
|
2007-09-19 08:40:12 +00:00
|
|
|
*
|
2008-11-06 16:40:00 +00:00
|
|
|
* @return A value indicating the type of the last error.
|
2007-07-18 20:51:26 +00:00
|
|
|
*/
|
2008-11-06 16:40:00 +00:00
|
|
|
virtual Error getError() { return _error; }
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-07-18 20:51:26 +00:00
|
|
|
/**
|
2008-02-22 00:22:31 +00:00
|
|
|
* Returns the last occurred error description. If none occurred, returns 0.
|
2007-09-19 08:40:12 +00:00
|
|
|
*
|
2007-07-18 20:51:26 +00:00
|
|
|
* @return A string describing the last error.
|
|
|
|
*/
|
|
|
|
virtual String getErrorDesc() { return _errorDesc; }
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-12-28 07:37:04 +00:00
|
|
|
/**
|
2008-02-22 00:22:31 +00:00
|
|
|
* Returns the last occurred error description. If none occurred, returns 0.
|
2007-12-28 07:37:04 +00:00
|
|
|
* Also clears the last error state and description.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2007-12-28 07:37:04 +00:00
|
|
|
* @return A string describing the last error.
|
|
|
|
*/
|
|
|
|
virtual String popErrorDesc();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2004-06-25 22:11:48 +00:00
|
|
|
/**
|
2008-02-22 00:22:31 +00:00
|
|
|
* Open the savefile with the specified name in the given directory for saving.
|
|
|
|
* @param name the name of the savefile
|
2006-04-26 11:15:13 +00:00
|
|
|
* @return pointer to an OutSaveFile, or NULL if an error occured.
|
2004-06-25 22:11:48 +00:00
|
|
|
*/
|
2008-02-22 00:22:31 +00:00
|
|
|
virtual OutSaveFile *openForSaving(const char *name) = 0;
|
2005-04-10 15:13:40 +00:00
|
|
|
|
|
|
|
/**
|
2008-02-22 00:22:31 +00:00
|
|
|
* Open the file with the specified name in the given directory for loading.
|
|
|
|
* @param name the name of the savefile
|
2006-04-26 11:15:13 +00:00
|
|
|
* @return pointer to an InSaveFile, or NULL if an error occured.
|
2005-04-10 15:13:40 +00:00
|
|
|
*/
|
2008-02-22 00:22:31 +00:00
|
|
|
virtual InSaveFile *openForLoading(const char *name) = 0;
|
2005-04-10 15:13:40 +00:00
|
|
|
|
2006-04-26 11:15:13 +00:00
|
|
|
/**
|
2008-02-22 00:22:31 +00:00
|
|
|
* Removes the given savefile from the system.
|
|
|
|
* @param name the name of the savefile to be removed.
|
|
|
|
* @return true if no error occurred, false otherwise.
|
2007-07-29 01:36:59 +00:00
|
|
|
*/
|
2008-02-22 00:22:31 +00:00
|
|
|
virtual bool removeSavefile(const char *name) = 0;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-11-06 10:52:47 +00:00
|
|
|
/**
|
|
|
|
* Renames the given savefile.
|
2008-02-22 00:22:31 +00:00
|
|
|
* @param oldName Old name.
|
|
|
|
* @param newName New name.
|
|
|
|
* @return true if no error occurred. false otherwise.
|
2007-11-06 10:52:47 +00:00
|
|
|
*/
|
2008-02-22 00:22:31 +00:00
|
|
|
virtual bool renameSavefile(const char *oldName, const char *newName);
|
2007-11-06 10:52:47 +00:00
|
|
|
|
2006-04-26 11:15:13 +00:00
|
|
|
/**
|
2007-12-30 00:00:03 +00:00
|
|
|
* Request a list of available savegames with a given DOS-style pattern,
|
2008-11-06 14:03:38 +00:00
|
|
|
* also known as "glob" in the UNIX world. Refer to the Common::matchString()
|
2007-12-30 00:00:03 +00:00
|
|
|
* function to learn about the precise pattern format.
|
|
|
|
* @param pattern Pattern to match. Wildcards like * or ? are available.
|
|
|
|
* @return list of strings for all present file names.
|
2008-11-06 14:03:38 +00:00
|
|
|
* @see Common::matchString()
|
2006-04-26 11:15:13 +00:00
|
|
|
*/
|
2007-12-30 00:00:03 +00:00
|
|
|
virtual Common::StringList listSavefiles(const char *pattern) = 0;
|
2004-06-25 22:11:48 +00:00
|
|
|
};
|
|
|
|
|
2005-05-10 23:17:38 +00:00
|
|
|
} // End of namespace Common
|
|
|
|
|
2003-08-07 14:57:55 +00:00
|
|
|
#endif
|