Changed SaveFileManager::listSavegames() function to be engine agnostic. It now returns a list will the full paths of existing files that match a given regex.
Additionally, modified the 5 engines which use the default manager (Agos, Queen, Saga, Scumm and Touche) to parse the filename list and mark the available saves bool array correctly. svn-id: r28046
This commit is contained in:
parent
c1961f1f76
commit
720c974faf
10 changed files with 126 additions and 41 deletions
|
@ -180,29 +180,19 @@ Common::InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename)
|
||||||
return wrapInSaveFile(sf);
|
return wrapInSaveFile(sf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultSaveFileManager::listSavefiles(const char *prefix , bool *marks, int num) {
|
Common::StringList DefaultSaveFileManager::listSavefiles(const char *regex) {
|
||||||
FilesystemNode savePath(getSavePath());
|
FilesystemNode savePath(getSavePath());
|
||||||
FSList savefiles;
|
FSList savefiles;
|
||||||
Common::String search(prefix);
|
Common::StringList results;
|
||||||
search = search + '*'; //match all files that start with the given prefix. += causes a strange bug.
|
Common::String search(regex);
|
||||||
|
|
||||||
assert(marks);
|
|
||||||
memset(marks, false, num * sizeof(bool)); //assume no savegames for this title
|
|
||||||
|
|
||||||
if(savePath.lookupFile(savefiles, savePath, search, false, true)) {
|
if(savePath.lookupFile(savefiles, savePath, search, false, true)) {
|
||||||
char slot[2];
|
|
||||||
int slotNum;
|
|
||||||
for(FSList::const_iterator file = savefiles.begin(); file != savefiles.end(); file++) {
|
for(FSList::const_iterator file = savefiles.begin(); file != savefiles.end(); file++) {
|
||||||
//TODO: check if this is the behavior for all engines
|
results.push_back(file->getPath());
|
||||||
//Obtain the last 2 digits of the filename, since they correspond to the save slot
|
|
||||||
slot[0] = file->getName()[file->getName().size()-2];
|
|
||||||
slot[1] = file->getName()[file->getName().size()-1];
|
|
||||||
|
|
||||||
slotNum = atoi(slot);
|
|
||||||
if(slotNum >= 0 && slotNum < num)
|
|
||||||
marks[slotNum] = true; //mark this slot as valid
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
|
#endif // !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
|
||||||
|
|
|
@ -28,12 +28,13 @@
|
||||||
|
|
||||||
#include "common/stdafx.h"
|
#include "common/stdafx.h"
|
||||||
#include "common/savefile.h"
|
#include "common/savefile.h"
|
||||||
|
#include "common/str.h"
|
||||||
|
|
||||||
class DefaultSaveFileManager : public Common::SaveFileManager {
|
class DefaultSaveFileManager : public Common::SaveFileManager {
|
||||||
public:
|
public:
|
||||||
virtual Common::OutSaveFile *openForSaving(const char *filename);
|
virtual Common::OutSaveFile *openForSaving(const char *filename);
|
||||||
virtual Common::InSaveFile *openForLoading(const char *filename);
|
virtual Common::InSaveFile *openForLoading(const char *filename);
|
||||||
virtual void listSavefiles(const char *prefix, bool *marks, int num);
|
virtual Common::StringList listSavefiles(const char *regex);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "common/noncopyable.h"
|
#include "common/noncopyable.h"
|
||||||
#include "common/scummsys.h"
|
#include "common/scummsys.h"
|
||||||
#include "common/stream.h"
|
#include "common/stream.h"
|
||||||
|
#include "common/str.h"
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
|
@ -94,12 +95,11 @@ public:
|
||||||
virtual InSaveFile *openForLoading(const char *filename) = 0;
|
virtual InSaveFile *openForLoading(const char *filename) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request a list of available savegames with a given prefix.
|
* Request a list of available savegames with a given regex.
|
||||||
* TODO: Document this better!
|
* @param regex Regular expression to match. Wildcards like * or ? are available.
|
||||||
* TODO: Or even replace it with a better API. For example, one that
|
|
||||||
* returns a list of strings for all present file names.
|
* returns a list of strings for all present file names.
|
||||||
*/
|
*/
|
||||||
virtual void listSavefiles(const char *prefix , bool *marks, int num) = 0;
|
virtual Common::StringList listSavefiles(const char *regex) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the path to the save game directory.
|
* Get the path to the save game directory.
|
||||||
|
|
|
@ -38,12 +38,28 @@ namespace AGOS {
|
||||||
|
|
||||||
int AGOSEngine::countSaveGames() {
|
int AGOSEngine::countSaveGames() {
|
||||||
Common::InSaveFile *f;
|
Common::InSaveFile *f;
|
||||||
|
Common::StringList filenames;
|
||||||
uint i = 1;
|
uint i = 1;
|
||||||
|
char slot[3];
|
||||||
|
int slotNum;
|
||||||
bool marks[256];
|
bool marks[256];
|
||||||
|
|
||||||
char *prefix = genSaveName(998);
|
char *prefix = genSaveName(998);
|
||||||
prefix[strlen(prefix)-3] = '\0';
|
prefix[strlen(prefix)-3] = '*';
|
||||||
_saveFileMan->listSavefiles(prefix, marks, 256);
|
prefix[strlen(prefix)-2] = '\0';
|
||||||
|
memset(marks, false, 256 * sizeof(bool)); //assume no savegames for this title
|
||||||
|
filenames = _saveFileMan->listSavefiles(prefix);
|
||||||
|
|
||||||
|
for(Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++){
|
||||||
|
//Obtain the last 3 digits of the filename, since they correspond to the save slot
|
||||||
|
slot[0] = file->c_str()[file->size()-3];
|
||||||
|
slot[1] = file->c_str()[file->size()-2];
|
||||||
|
slot[2] = file->c_str()[file->size()-1];
|
||||||
|
|
||||||
|
slotNum = atoi(slot);
|
||||||
|
if(slotNum >= 0 && slotNum < 256)
|
||||||
|
marks[slotNum] = true; //mark this slot as valid
|
||||||
|
}
|
||||||
|
|
||||||
while (i < 256) {
|
while (i < 256) {
|
||||||
if (marks[i] &&
|
if (marks[i] &&
|
||||||
|
@ -53,6 +69,7 @@ int AGOSEngine::countSaveGames() {
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -317,11 +317,28 @@ void QueenEngine::makeGameStateName(uint16 slot, char *buf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueenEngine::findGameStateDescriptions(char descriptions[100][32]) {
|
void QueenEngine::findGameStateDescriptions(char descriptions[100][32]) {
|
||||||
char filename[20];
|
char prefix[20];
|
||||||
makeGameStateName(0, filename);
|
makeGameStateName(0, prefix);
|
||||||
filename[strlen(filename) - 2] = 0;
|
prefix[strlen(prefix) - 2] = '*';
|
||||||
|
prefix[strlen(prefix) - 1] = 0;
|
||||||
bool marks[SAVESTATE_MAX_NUM];
|
bool marks[SAVESTATE_MAX_NUM];
|
||||||
_saveFileMan->listSavefiles(filename, marks, SAVESTATE_MAX_NUM);
|
char slot[2];
|
||||||
|
int slotNum;
|
||||||
|
Common::StringList filenames;
|
||||||
|
|
||||||
|
memset(marks, false, SAVESTATE_MAX_NUM * sizeof(bool)); //assume no savegames for this title
|
||||||
|
filenames = _saveFileMan->listSavefiles(prefix);
|
||||||
|
|
||||||
|
for(Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++){
|
||||||
|
//Obtain the last 2 digits of the filename, since they correspond to the save slot
|
||||||
|
slot[0] = file->c_str()[file->size()-2];
|
||||||
|
slot[1] = file->c_str()[file->size()-1];
|
||||||
|
|
||||||
|
slotNum = atoi(slot);
|
||||||
|
if(slotNum >= 0 && slotNum < SAVESTATE_MAX_NUM)
|
||||||
|
marks[slotNum] = true; //mark this slot as valid
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < SAVESTATE_MAX_NUM; ++i) {
|
for (int i = 0; i < SAVESTATE_MAX_NUM; ++i) {
|
||||||
if (marks[i]) {
|
if (marks[i]) {
|
||||||
GameStateHeader header;
|
GameStateHeader header;
|
||||||
|
|
|
@ -112,13 +112,31 @@ uint SagaEngine::getNewSaveSlotNumber() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SagaEngine::fillSaveList() {
|
void SagaEngine::fillSaveList() {
|
||||||
|
assert(_saveMarks);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
Common::InSaveFile *in;
|
Common::InSaveFile *in;
|
||||||
|
Common::StringList filenames;
|
||||||
|
char slot[2];
|
||||||
|
int slotNum;
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
name = calcSaveFileName(MAX_SAVES);
|
name = calcSaveFileName(MAX_SAVES);
|
||||||
name[strlen(name) - 2] = 0;
|
name[strlen(name) - 2] = '*';
|
||||||
_saveFileMan->listSavefiles(name, _saveMarks, MAX_SAVES);
|
name[strlen(name) - 1] = 0;
|
||||||
|
|
||||||
|
memset(_saveMarks, false, MAX_SAVES * sizeof(bool)); //assume no savegames for this title
|
||||||
|
filenames = _saveFileMan->listSavefiles(name);
|
||||||
|
|
||||||
|
for(Common::StringList::iterator file = filenames.begin(); file != filenames.end(); file++){
|
||||||
|
//Obtain the last 2 digits of the filename, since they correspond to the save slot
|
||||||
|
slot[0] = file->c_str()[file->size()-2];
|
||||||
|
slot[1] = file->c_str()[file->size()-1];
|
||||||
|
|
||||||
|
slotNum = atoi(slot);
|
||||||
|
if(slotNum >= 0 && slotNum < MAX_SAVES)
|
||||||
|
_saveMarks[slotNum] = true; //mark this slot as valid
|
||||||
|
}
|
||||||
|
|
||||||
_saveFilesMaxCount = 0;
|
_saveFilesMaxCount = 0;
|
||||||
for (i = 0; i < MAX_SAVES; i++) {
|
for (i = 0; i < MAX_SAVES; i++) {
|
||||||
|
|
|
@ -427,10 +427,10 @@ void SaveLoadChooser::updateInfos() {
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
||||||
Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode) {
|
Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode) {
|
||||||
// Get savegame names
|
// Get savegame descriptions
|
||||||
Common::StringList l;
|
Common::StringList descriptions;
|
||||||
char name[32];
|
char name[32];
|
||||||
uint i = saveMode ? 1 : 0;
|
uint i = saveMode ? 1 : 0; //the autosave is on slot #0
|
||||||
bool avail_saves[81];
|
bool avail_saves[81];
|
||||||
|
|
||||||
scumm->listSavegames(avail_saves, ARRAYSIZE(avail_saves));
|
scumm->listSavegames(avail_saves, ARRAYSIZE(avail_saves));
|
||||||
|
@ -439,10 +439,10 @@ Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode) {
|
||||||
scumm->getSavegameName(i, name);
|
scumm->getSavegameName(i, name);
|
||||||
else
|
else
|
||||||
name[0] = 0;
|
name[0] = 0;
|
||||||
l.push_back(name);
|
descriptions.push_back(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return l;
|
return descriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainMenuDialog::MainMenuDialog(ScummEngine *scumm)
|
MainMenuDialog::MainMenuDialog(ScummEngine *scumm)
|
||||||
|
|
|
@ -384,10 +384,28 @@ void ScummEngine::makeSavegameName(char *out, int slot, bool temporary) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScummEngine::listSavegames(bool *marks, int num) {
|
void ScummEngine::listSavegames(bool *marks, int num) {
|
||||||
|
assert(marks);
|
||||||
|
|
||||||
char prefix[256];
|
char prefix[256];
|
||||||
|
char slot[2];
|
||||||
|
int slotNum;
|
||||||
|
Common::StringList filenames;
|
||||||
|
|
||||||
makeSavegameName(prefix, 99, false);
|
makeSavegameName(prefix, 99, false);
|
||||||
prefix[strlen(prefix)-2] = 0;
|
prefix[strlen(prefix)-2] = '*';
|
||||||
_saveFileMan->listSavefiles(prefix, marks, num);
|
prefix[strlen(prefix)-1] = 0;
|
||||||
|
memset(marks, false, num * sizeof(bool)); //assume no savegames for this title
|
||||||
|
filenames = _saveFileMan->listSavefiles(prefix);
|
||||||
|
|
||||||
|
for(Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++){
|
||||||
|
//Obtain the last 2 digits of the filename, since they correspond to the save slot
|
||||||
|
slot[0] = file->c_str()[file->size()-2];
|
||||||
|
slot[1] = file->c_str()[file->size()-1];
|
||||||
|
|
||||||
|
slotNum = atoi(slot);
|
||||||
|
if(slotNum >= 0 && slotNum < num)
|
||||||
|
marks[slotNum] = true; //mark this slot as valid
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScummEngine::getSavegameName(int slot, char *desc) {
|
bool ScummEngine::getSavegameName(int slot, char *desc) {
|
||||||
|
|
|
@ -398,7 +398,7 @@ void ToucheEngine::readGameStateDescription(int num, char *description, int len)
|
||||||
|
|
||||||
void ToucheEngine::generateGameStateFileName(int num, char *dst, int len, bool prefixOnly) const {
|
void ToucheEngine::generateGameStateFileName(int num, char *dst, int len, bool prefixOnly) const {
|
||||||
if (prefixOnly) {
|
if (prefixOnly) {
|
||||||
snprintf(dst, len, "%s.", _targetName.c_str());
|
snprintf(dst, len, "%s.*", _targetName.c_str());
|
||||||
} else {
|
} else {
|
||||||
snprintf(dst, len, "%s.%d", _targetName.c_str(), num);
|
snprintf(dst, len, "%s.%d", _targetName.c_str(), num);
|
||||||
}
|
}
|
||||||
|
|
|
@ -370,9 +370,33 @@ void ToucheEngine::handleOptions(int forceDisplay) {
|
||||||
setupMenu(menuData.mode, &menuData);
|
setupMenu(menuData.mode, &menuData);
|
||||||
curMode = menuData.mode;
|
curMode = menuData.mode;
|
||||||
if (menuData.mode == kMenuLoadStateMode || menuData.mode == kMenuSaveStateMode) {
|
if (menuData.mode == kMenuLoadStateMode || menuData.mode == kMenuSaveStateMode) {
|
||||||
|
assert(menuData.saveLoadMarks);
|
||||||
|
|
||||||
char gameStateFileName[16];
|
char gameStateFileName[16];
|
||||||
generateGameStateFileName(999, gameStateFileName, 15, true);
|
generateGameStateFileName(999, gameStateFileName, 15, true);
|
||||||
_saveFileMan->listSavefiles(gameStateFileName, menuData.saveLoadMarks, 100);
|
char slot[2];
|
||||||
|
int slotNum;
|
||||||
|
Common::StringList filenames;
|
||||||
|
|
||||||
|
memset(menuData.saveLoadMarks, false, 100 * sizeof(bool)); //assume no savegames for this title
|
||||||
|
filenames = _saveFileMan->listSavefiles(gameStateFileName);
|
||||||
|
|
||||||
|
for(Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++){
|
||||||
|
//Obtain the last 1 or 2 digits of the filename, since they correspond to the save slot
|
||||||
|
//This engine can save games either with one or two digits, hence the additional if statement
|
||||||
|
slot[0] = file->c_str()[file->size()-2];
|
||||||
|
slot[1] = file->c_str()[file->size()-1];
|
||||||
|
|
||||||
|
if(!atoi(&slot[0])){
|
||||||
|
slotNum = atoi(&slot[1]);
|
||||||
|
} else {
|
||||||
|
slotNum = atoi(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(slotNum >= 0 && slotNum < 100)
|
||||||
|
menuData.saveLoadMarks[slotNum] = true; //mark this slot as valid
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 100; ++i) {
|
for (int i = 0; i < 100; ++i) {
|
||||||
menuData.saveLoadDescriptionsTable[i][0] = 0;
|
menuData.saveLoadDescriptionsTable[i][0] = 0;
|
||||||
if (menuData.saveLoadMarks[i]) {
|
if (menuData.saveLoadMarks[i]) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue