[Scummvm-cvs-logs] SF.net SVN: scummvm: [28046] scummvm/branches/gsoc2007-fsnode

david_corrales at users.sourceforge.net david_corrales at users.sourceforge.net
Thu Jul 12 19:58:15 CEST 2007


Revision: 28046
          http://scummvm.svn.sourceforge.net/scummvm/?rev=28046&view=rev
Author:   david_corrales
Date:     2007-07-12 10:58:15 -0700 (Thu, 12 Jul 2007)

Log Message:
-----------
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.

Modified Paths:
--------------
    scummvm/branches/gsoc2007-fsnode/backends/saves/default/default-saves.cpp
    scummvm/branches/gsoc2007-fsnode/backends/saves/default/default-saves.h
    scummvm/branches/gsoc2007-fsnode/common/savefile.h
    scummvm/branches/gsoc2007-fsnode/engines/agos/saveload.cpp
    scummvm/branches/gsoc2007-fsnode/engines/queen/queen.cpp
    scummvm/branches/gsoc2007-fsnode/engines/saga/saveload.cpp
    scummvm/branches/gsoc2007-fsnode/engines/scumm/dialogs.cpp
    scummvm/branches/gsoc2007-fsnode/engines/scumm/saveload.cpp
    scummvm/branches/gsoc2007-fsnode/engines/touche/saveload.cpp
    scummvm/branches/gsoc2007-fsnode/engines/touche/ui.cpp

Modified: scummvm/branches/gsoc2007-fsnode/backends/saves/default/default-saves.cpp
===================================================================
--- scummvm/branches/gsoc2007-fsnode/backends/saves/default/default-saves.cpp	2007-07-12 17:25:04 UTC (rev 28045)
+++ scummvm/branches/gsoc2007-fsnode/backends/saves/default/default-saves.cpp	2007-07-12 17:58:15 UTC (rev 28046)
@@ -180,29 +180,19 @@
 	return wrapInSaveFile(sf);
 }
 
-void DefaultSaveFileManager::listSavefiles(const char *prefix , bool *marks, int num) {
+Common::StringList DefaultSaveFileManager::listSavefiles(const char *regex) {
 	FilesystemNode savePath(getSavePath());
 	FSList savefiles;
-	Common::String search(prefix);
-	search = search + '*';	//match all files that start with the given prefix. += causes a strange bug.
+	Common::StringList results;
+	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)) {
-		char slot[2];
-		int slotNum;
 		for(FSList::const_iterator file = savefiles.begin(); file != savefiles.end(); file++) {
-			//TODO: check if this is the behavior for all engines
-			//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
+			results.push_back(file->getPath());
 		}
 	}
+				
+	return results;
 }
 
 #endif // !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)

Modified: scummvm/branches/gsoc2007-fsnode/backends/saves/default/default-saves.h
===================================================================
--- scummvm/branches/gsoc2007-fsnode/backends/saves/default/default-saves.h	2007-07-12 17:25:04 UTC (rev 28045)
+++ scummvm/branches/gsoc2007-fsnode/backends/saves/default/default-saves.h	2007-07-12 17:58:15 UTC (rev 28046)
@@ -28,12 +28,13 @@
 
 #include "common/stdafx.h"
 #include "common/savefile.h"
+#include "common/str.h"
 
 class DefaultSaveFileManager : public Common::SaveFileManager {
 public:
 	virtual Common::OutSaveFile *openForSaving(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

Modified: scummvm/branches/gsoc2007-fsnode/common/savefile.h
===================================================================
--- scummvm/branches/gsoc2007-fsnode/common/savefile.h	2007-07-12 17:25:04 UTC (rev 28045)
+++ scummvm/branches/gsoc2007-fsnode/common/savefile.h	2007-07-12 17:58:15 UTC (rev 28046)
@@ -30,6 +30,7 @@
 #include "common/noncopyable.h"
 #include "common/scummsys.h"
 #include "common/stream.h"
+#include "common/str.h"
 
 namespace Common {
 
@@ -94,12 +95,11 @@
 	virtual InSaveFile *openForLoading(const char *filename) = 0;
 
 	/**
-	 * Request a list of available savegames with a given prefix.
-	 * TODO: Document this better!
-	 * TODO: Or even replace it with a better API. For example, one that
-	 * returns a list of strings for all present file names. 
+	 * Request a list of available savegames with a given regex.
+	 * @param regex Regular expression to match. Wildcards like * or ? are available.
+	 * 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.

Modified: scummvm/branches/gsoc2007-fsnode/engines/agos/saveload.cpp
===================================================================
--- scummvm/branches/gsoc2007-fsnode/engines/agos/saveload.cpp	2007-07-12 17:25:04 UTC (rev 28045)
+++ scummvm/branches/gsoc2007-fsnode/engines/agos/saveload.cpp	2007-07-12 17:58:15 UTC (rev 28046)
@@ -38,13 +38,29 @@
 
 int AGOSEngine::countSaveGames() {
 	Common::InSaveFile *f;
+	Common::StringList filenames;
 	uint i = 1;
+	char slot[3];
+	int slotNum;
 	bool marks[256];
 
 	char *prefix = genSaveName(998);
-	prefix[strlen(prefix)-3] = '\0';
-	_saveFileMan->listSavefiles(prefix, marks, 256);
+	prefix[strlen(prefix)-3] = '*';
+	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) {
 		if (marks[i] &&
 		    (f = _saveFileMan->openForLoading(genSaveName(i)))) {
@@ -53,6 +69,7 @@
 		} else
 			break;
 	}
+	
 	return i;
 }
 

Modified: scummvm/branches/gsoc2007-fsnode/engines/queen/queen.cpp
===================================================================
--- scummvm/branches/gsoc2007-fsnode/engines/queen/queen.cpp	2007-07-12 17:25:04 UTC (rev 28045)
+++ scummvm/branches/gsoc2007-fsnode/engines/queen/queen.cpp	2007-07-12 17:58:15 UTC (rev 28046)
@@ -317,11 +317,28 @@
 }
 
 void QueenEngine::findGameStateDescriptions(char descriptions[100][32]) {
-	char filename[20];
-	makeGameStateName(0, filename);
-	filename[strlen(filename) - 2] = 0;
+	char prefix[20];
+	makeGameStateName(0, prefix);
+	prefix[strlen(prefix) - 2] = '*';
+	prefix[strlen(prefix) - 1] = 0;
 	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) {
 		if (marks[i]) {
 			GameStateHeader header;

Modified: scummvm/branches/gsoc2007-fsnode/engines/saga/saveload.cpp
===================================================================
--- scummvm/branches/gsoc2007-fsnode/engines/saga/saveload.cpp	2007-07-12 17:25:04 UTC (rev 28045)
+++ scummvm/branches/gsoc2007-fsnode/engines/saga/saveload.cpp	2007-07-12 17:58:15 UTC (rev 28046)
@@ -112,14 +112,32 @@
 }
 
 void SagaEngine::fillSaveList() {
+	assert(_saveMarks);
+	
 	int i;
 	Common::InSaveFile *in;
+	Common::StringList filenames;
+	char slot[2];
+	int slotNum;
 	char *name;
 
 	name = calcSaveFileName(MAX_SAVES);
-	name[strlen(name) - 2] = 0;
-	_saveFileMan->listSavefiles(name, _saveMarks, MAX_SAVES);
-
+	name[strlen(name) - 2] = '*';
+	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;
 	for (i = 0; i < MAX_SAVES; i++) {
 		if (_saveMarks[i]) {

Modified: scummvm/branches/gsoc2007-fsnode/engines/scumm/dialogs.cpp
===================================================================
--- scummvm/branches/gsoc2007-fsnode/engines/scumm/dialogs.cpp	2007-07-12 17:25:04 UTC (rev 28045)
+++ scummvm/branches/gsoc2007-fsnode/engines/scumm/dialogs.cpp	2007-07-12 17:58:15 UTC (rev 28046)
@@ -427,10 +427,10 @@
 #pragma mark -
 
 Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode) {
-	// Get savegame names
-	Common::StringList l;
+	// Get savegame descriptions
+	Common::StringList descriptions;
 	char name[32];
-	uint i = saveMode ? 1 : 0;
+	uint i = saveMode ? 1 : 0;		//the autosave is on slot #0
 	bool avail_saves[81];
 
 	scumm->listSavegames(avail_saves, ARRAYSIZE(avail_saves));
@@ -439,10 +439,10 @@
 			scumm->getSavegameName(i, name);
 		else
 			name[0] = 0;
-		l.push_back(name);
+		descriptions.push_back(name);
 	}
-
-	return l;
+	
+	return descriptions;
 }
 
 MainMenuDialog::MainMenuDialog(ScummEngine *scumm)

Modified: scummvm/branches/gsoc2007-fsnode/engines/scumm/saveload.cpp
===================================================================
--- scummvm/branches/gsoc2007-fsnode/engines/scumm/saveload.cpp	2007-07-12 17:25:04 UTC (rev 28045)
+++ scummvm/branches/gsoc2007-fsnode/engines/scumm/saveload.cpp	2007-07-12 17:58:15 UTC (rev 28046)
@@ -384,10 +384,28 @@
 }
 
 void ScummEngine::listSavegames(bool *marks, int num) {
+	assert(marks);
+	
 	char prefix[256];
+	char slot[2];
+	int slotNum;
+	Common::StringList filenames;
+	
 	makeSavegameName(prefix, 99, false);
-	prefix[strlen(prefix)-2] = 0;
-	_saveFileMan->listSavefiles(prefix, marks, num);
+	prefix[strlen(prefix)-2] = '*';
+	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) {

Modified: scummvm/branches/gsoc2007-fsnode/engines/touche/saveload.cpp
===================================================================
--- scummvm/branches/gsoc2007-fsnode/engines/touche/saveload.cpp	2007-07-12 17:25:04 UTC (rev 28045)
+++ scummvm/branches/gsoc2007-fsnode/engines/touche/saveload.cpp	2007-07-12 17:58:15 UTC (rev 28046)
@@ -398,7 +398,7 @@
 
 void ToucheEngine::generateGameStateFileName(int num, char *dst, int len, bool prefixOnly) const {
 	if (prefixOnly) {
-		snprintf(dst, len, "%s.", _targetName.c_str());
+		snprintf(dst, len, "%s.*", _targetName.c_str());
 	} else {
 		snprintf(dst, len, "%s.%d", _targetName.c_str(), num);
 	}

Modified: scummvm/branches/gsoc2007-fsnode/engines/touche/ui.cpp
===================================================================
--- scummvm/branches/gsoc2007-fsnode/engines/touche/ui.cpp	2007-07-12 17:25:04 UTC (rev 28045)
+++ scummvm/branches/gsoc2007-fsnode/engines/touche/ui.cpp	2007-07-12 17:58:15 UTC (rev 28046)
@@ -370,9 +370,33 @@
 				setupMenu(menuData.mode, &menuData);
 				curMode = menuData.mode;
 				if (menuData.mode == kMenuLoadStateMode || menuData.mode == kMenuSaveStateMode) {
+					assert(menuData.saveLoadMarks);
+					
 					char gameStateFileName[16];
 					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) {
 						menuData.saveLoadDescriptionsTable[i][0] = 0;
 						if (menuData.saveLoadMarks[i]) {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list