ScummVM
Common::SaveFileManager Class Referenceabstract

The SaveFileManager is serving as a factory for InSaveFile and OutSaveFile objects. More...

#include <savefile.h>

Inheritance diagram for Common::SaveFileManager:
Collaboration diagram for Common::SaveFileManager:

Public Member Functions

virtual ~SaveFileManager ()
 
virtual void clearError ()
 Clears the last set error code and string. More...
 
virtual Error getError ()
 Returns the last occurred error code. More...
 
virtual String getErrorDesc ()
 Returns the last occurred error description. More...
 
virtual String popErrorDesc ()
 Returns the last occurred error description. More...
 
virtual OutSaveFileopenForSaving (const String &name, bool compress=true)=0
 Open the savefile with the specified name in the given directory for saving. More...
 
virtual InSaveFileopenForLoading (const String &name)=0
 Open the file with the specified name in the given directory for loading. More...
 
virtual InSaveFileopenRawFile (const String &name)=0
 Open the file with the specified name in the given directory for loading. More...
 
virtual bool removeSavefile (const String &name)=0
 Removes the given savefile from the system. More...
 
virtual bool renameSavefile (const String &oldName, const String &newName)
 Renames the given savefile. More...
 
virtual bool copySavefile (const String &oldName, const String &newName)
 Copy the given savefile. More...
 
virtual StringArray listSavefiles (const String &pattern)=0
 List available savegames matching a given pattern. More...
 
virtual void updateSavefilesList (StringArray &lockedFiles)=0
 Refreshes the save files list (because some new files could've been added) and remembers the "locked" files list. More...
 

Protected Member Functions

virtual void setError (Error error, const String &errorDesc)
 Set some information about the last error which occurred . More...
 

Protected Attributes

Error _error
 
String _errorDesc
 

Additional Inherited Members

- Private Member Functions inherited from Common::NonCopyable
 NonCopyable ()
 

Detailed Description

The SaveFileManager is serving as a factory for InSaveFile and OutSaveFile objects.

Engines and other code should use SaveFiles whenever they need to store data which they need to be able to retrieve again later on – i.e. typically save states, but also configuration files and similar things.

Savefile names represent SaveFiles. These names are case insensitive, that means a name of "Kq1.000" represents the same savefile as "kq1.000". In addition, SaveFileManager does not allow for names which contain path separators like '/' or '\'. This is because we do not support directories in SaveFileManager.

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.

Definition at line 82 of file savefile.h.

Constructor & Destructor Documentation

◆ ~SaveFileManager()

virtual Common::SaveFileManager::~SaveFileManager ( )
inlinevirtual

Definition at line 96 of file savefile.h.

Member Function Documentation

◆ clearError()

virtual void Common::SaveFileManager::clearError ( )
inlinevirtual

Clears the last set error code and string.

Definition at line 101 of file savefile.h.

◆ copySavefile()

bool Common::SaveFileManager::copySavefile ( const String oldName,
const String newName 
)
virtual

Copy the given savefile.

Parameters
oldNameOld name.
newNameNew name.
Returns
true if no error occurred. false otherwise.

Definition at line 59 of file savefile.cpp.

◆ getError()

virtual Error Common::SaveFileManager::getError ( )
inlinevirtual

Returns the last occurred error code.

If none occurred, returns kNoError.

Returns
A value indicating the type of the last error.

Definition at line 108 of file savefile.h.

◆ getErrorDesc()

virtual String Common::SaveFileManager::getErrorDesc ( )
inlinevirtual

Returns the last occurred error description.

If none occurred, returns 0.

Returns
A string describing the last error.

Definition at line 115 of file savefile.h.

◆ listSavefiles()

virtual StringArray Common::SaveFileManager::listSavefiles ( const String pattern)
pure virtual

List available savegames matching a given pattern.

Our pattern format is based on DOS paterns, also known as "glob" in the POSIX world. Please refer to the Common::matchString() function to learn about the precise pattern format.

Parameters
patternPattern to match. Wildcards like * or ? are available.
Returns
List of strings for all present file names.
See also
Common::matchString()

Implemented in VMSaveManager, PAKSaveManager, FRAMSaveManager, Ps2SaveFileManager, DefaultSaveFileManager, and GBAMPSaveFileManager.

◆ openForLoading()

virtual InSaveFile* Common::SaveFileManager::openForLoading ( const String name)
pure virtual

Open the file with the specified name in the given directory for loading.

Parameters
nameThe name of the savefile.
Returns
Pointer to an InSaveFile, or NULL if an error occurred.

Implemented in VMSaveManager, PAKSaveManager, FRAMSaveManager, DefaultSaveFileManager, Ps2SaveFileManager, GBAMPSaveFileManager, and RecorderSaveFileManager.

◆ openForSaving()

virtual OutSaveFile* Common::SaveFileManager::openForSaving ( const String name,
bool  compress = true 
)
pure virtual

Open the savefile with the specified name in the given directory for saving.

Saved games are compressed by default, and engines are expected to always write compressed saves.

A notable exception is if uncompressed files are needed for compatibility with games not supported by ScummVM, such as character exports from the Quest for Glory series. QfG5 is a 3D game and won't be supported by ScummVM.

Parameters
nameThe name of the savefile.
compressToggles whether to compress the resulting save file (default) or not.
Returns
Pointer to an OutSaveFile, or NULL if an error occurred.

Implemented in VMSaveManager, PAKSaveManager, FRAMSaveManager, DefaultSaveFileManager, Ps2SaveFileManager, and GBAMPSaveFileManager.

◆ openRawFile()

virtual InSaveFile* Common::SaveFileManager::openRawFile ( const String name)
pure virtual

Open the file with the specified name in the given directory for loading.

In contrast to openForLoading(), it returns raw file instead of unpacked.

Parameters
nameThe name of the savefile.
Returns
Pointer to an InSaveFile, or NULL if an error occurred.

Implemented in VMSaveManager, PAKSaveManager, FRAMSaveManager, DefaultSaveFileManager, Ps2SaveFileManager, and GBAMPSaveFileManager.

◆ popErrorDesc()

String Common::SaveFileManager::popErrorDesc ( )
virtual

Returns the last occurred error description.

If none occurred, returns 0. Also clears the last error state and description.

Returns
A string describing the last error.

Definition at line 104 of file savefile.cpp.

◆ removeSavefile()

virtual bool Common::SaveFileManager::removeSavefile ( const String name)
pure virtual

Removes the given savefile from the system.

Parameters
nameThe name of the savefile to be removed.
Returns
true if no error occurred, false otherwise.

Implemented in VMSaveManager, PAKSaveManager, FRAMSaveManager, TizenSaveFileManager, DefaultSaveFileManager, Ps2SaveFileManager, and GBAMPSaveFileManager.

◆ renameSavefile()

bool Common::SaveFileManager::renameSavefile ( const String oldName,
const String newName 
)
virtual

Renames the given savefile.

Parameters
oldNameOld name.
newNameNew name.
Returns
true if no error occurred. false otherwise.

Definition at line 97 of file savefile.cpp.

◆ setError()

virtual void Common::SaveFileManager::setError ( Error  error,
const String errorDesc 
)
inlineprotectedvirtual

Set some information about the last error which occurred .

Parameters
errorCode identifying the last error.
errorDescString describing the last error.

Definition at line 93 of file savefile.h.

◆ updateSavefilesList()

virtual void Common::SaveFileManager::updateSavefilesList ( StringArray lockedFiles)
pure virtual

Refreshes the save files list (because some new files could've been added) and remembers the "locked" files list.

These files could not be used for saving or loading because they are being synced by CloudManager.

Implemented in VMSaveManager, PAKSaveManager, FRAMSaveManager, DefaultSaveFileManager, Ps2SaveFileManager, and GBAMPSaveFileManager.

Member Data Documentation

◆ _error

Error Common::SaveFileManager::_error
protected

Definition at line 85 of file savefile.h.

◆ _errorDesc

String Common::SaveFileManager::_errorDesc
protected

Definition at line 86 of file savefile.h.


The documentation for this class was generated from the following files: