[Scummvm-cvs-logs] SF.net SVN: scummvm:[34543] scummvm/trunk/engines/scumm

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sun Sep 14 23:34:50 CEST 2008


Revision: 34543
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34543&view=rev
Author:   lordhoto
Date:     2008-09-14 21:34:49 +0000 (Sun, 14 Sep 2008)

Log Message:
-----------
Little cleanup.

Modified Paths:
--------------
    scummvm/trunk/engines/scumm/detection.cpp
    scummvm/trunk/engines/scumm/saveload.cpp
    scummvm/trunk/engines/scumm/scumm.cpp
    scummvm/trunk/engines/scumm/scumm.h

Modified: scummvm/trunk/engines/scumm/detection.cpp
===================================================================
--- scummvm/trunk/engines/scumm/detection.cpp	2008-09-14 21:32:45 UTC (rev 34542)
+++ scummvm/trunk/engines/scumm/detection.cpp	2008-09-14 21:34:49 UTC (rev 34543)
@@ -979,12 +979,7 @@
 }
 
 void ScummMetaEngine::removeSaveState(const char *target, int slot) const {
-	char extension[6];
-	snprintf(extension, sizeof(extension), ".s%02d", slot);
-
-	Common::String filename = target;
-	filename += extension;
-
+	Common::String filename = ScummEngine::makeSavegameName(target, slot, false);
 	g_system->getSavefileManager()->removeSavefile(filename.c_str());
 }
 

Modified: scummvm/trunk/engines/scumm/saveload.cpp
===================================================================
--- scummvm/trunk/engines/scumm/saveload.cpp	2008-09-14 21:32:45 UTC (rev 34542)
+++ scummvm/trunk/engines/scumm/saveload.cpp	2008-09-14 21:34:49 UTC (rev 34543)
@@ -103,17 +103,17 @@
 }
 
 bool ScummEngine::saveState(int slot, bool compat) {
-	char filename[256];
+	Common::String filename;
 	Common::OutSaveFile *out;
 	SaveGameHeader hdr;
 
 	if (_saveLoadSlot == 255) {
 		// Allow custom filenames for save game system in HE Games
-		memcpy(filename, _saveLoadFileName, sizeof(_saveLoadFileName));
+		filename = _saveLoadFileName;
 	} else {
-		makeSavegameName(filename, slot, compat);
+		filename = makeSavegameName(slot, compat);
 	}
-	if (!(out = _saveFileMan->openForSaving(filename)))
+	if (!(out = _saveFileMan->openForSaving(filename.c_str())))
 		return false;
 
 	memcpy(hdr.name, _saveLoadName, sizeof(hdr.name));
@@ -128,11 +128,11 @@
 	out->finalize();
 	if (out->ioFailed()) {
 		delete out;
-		debug(1, "State save as '%s' FAILED", filename);
+		debug(1, "State save as '%s' FAILED", filename.c_str());
 		return false;
 	}
 	delete out;
-	debug(1, "State saved as '%s'", filename);
+	debug(1, "State saved as '%s'", filename.c_str());
 	return true;
 }
 
@@ -145,7 +145,7 @@
 }
 
 bool ScummEngine::loadState(int slot, bool compat) {
-	char filename[256];
+	Common::String filename;
 	Common::SeekableReadStream *in;
 	int i, j;
 	SaveGameHeader hdr;
@@ -153,15 +153,15 @@
 
 	if (_saveLoadSlot == 255) {
 		// Allow custom filenames for save game system in HE Games
-		memcpy(filename, _saveLoadFileName, sizeof(_saveLoadFileName));
+		filename = _saveLoadFileName;
 	} else {
-		makeSavegameName(filename, slot, compat);
+		filename = makeSavegameName(slot, compat);
 	}
-	if (!(in = _saveFileMan->openForLoading(filename)))
+	if (!(in = _saveFileMan->openForLoading(filename.c_str())))
 		return false;
 
 	if (!loadSaveGameHeader(in, hdr)) {
-		warning("Invalid savegame '%s'", filename);
+		warning("Invalid savegame '%s'", filename.c_str());
 		delete in;
 		return false;
 	}
@@ -177,14 +177,14 @@
 	// to work around a bug from the stone age (see below for more
 	// information).
 	if (hdr.ver < VER(7) || hdr.ver > CURRENT_VER) {
-		warning("Invalid version of '%s'", filename);
+		warning("Invalid version of '%s'", filename.c_str());
 		delete in;
 		return false;
 	}
 
 	// We (deliberately) broke HE savegame compatibility at some point.
 	if (hdr.ver < VER(50) && _game.heversion >= 71) {
-		warning("Unsupported version of '%s'", filename);
+		warning("Unsupported version of '%s'", filename.c_str());
 		delete in;
 		return false;
 	}
@@ -391,7 +391,7 @@
 	if (VAR_VOICE_MODE != 0xFF)
 		VAR(VAR_VOICE_MODE) = ConfMan.getBool("subtitles");
 
-	debug(1, "State loaded from '%s'", filename);
+	debug(1, "State loaded from '%s'", filename.c_str());
 
 	_sound->pauseSounds(false);
 
@@ -407,23 +407,24 @@
 	return true;
 }
 
-void ScummEngine::makeSavegameName(char *out, int slot, bool temporary) {
-	sprintf(out, "%s.%c%.2d", _targetName.c_str(), temporary ? 'c' : 's', slot);
+Common::String ScummEngine::makeSavegameName(const Common::String &target, int slot, bool temporary) {
+	char extension[6];
+	snprintf(extension, sizeof(extension), ".%c%02d", temporary ? 'c' : 's', slot);
+	return (target + extension);
 }
 
 void ScummEngine::listSavegames(bool *marks, int num) {
 	assert(marks);
 
-	char prefix[256];
 	char slot[3];
 	int slotNum;
 	Common::StringList files;
 
-	makeSavegameName(prefix, 99, false);
-	prefix[strlen(prefix)-2] = '*';
-	prefix[strlen(prefix)-1] = 0;
+	Common::String prefix = makeSavegameName(99, false);
+	prefix.setChar(prefix.size()-2, '*');
+	prefix.setChar(prefix.size()-1, 0);
 	memset(marks, false, num * sizeof(bool));	//assume no savegames for this title
-	files = _saveFileMan->listSavefiles(prefix);
+	files = _saveFileMan->listSavefiles(prefix.c_str());
 
 	for (Common::StringList::const_iterator file = files.begin(); file != files.end(); ++file) {
 		//Obtain the last 2 digits of the filename, since they correspond to the save slot
@@ -442,11 +443,10 @@
 bool ScummEngine::getSavegameName(int slot, Common::String &desc) {
 	Common::InSaveFile *in = 0;
 	bool result = false;
-	char filename[256];
 
 	desc.clear();
-	makeSavegameName(filename, slot, false);
-	in = _saveFileMan->openForLoading(filename);
+	Common::String filename = makeSavegameName(slot, false);
+	in = _saveFileMan->openForLoading(filename.c_str());
 	if (in) {
 		result = Scumm::getSavegameName(in, desc, _game.heversion);
 		delete in;
@@ -481,16 +481,14 @@
 }
 
 Graphics::Surface *ScummEngine::loadThumbnailFromSlot(const char *target, int slot) {
-	char filename[256];
 	Common::SeekableReadStream *in;
 	SaveGameHeader hdr;
 
 	if (slot < 0)
 		return  0;
 
-	// TODO: Remove code duplication (check: makeSavegameName)
-	snprintf(filename, sizeof(filename), "%s.s%02d", target, slot);
-	if (!(in = g_system->getSavefileManager()->openForLoading(filename))) {
+	Common::String filename = ScummEngine::makeSavegameName(target, slot, false);
+	if (!(in = g_system->getSavefileManager()->openForLoading(filename.c_str()))) {
 		return 0;
 	}
 
@@ -521,15 +519,14 @@
 }
 
 bool ScummEngine::loadInfosFromSlot(int slot, InfoStuff *stuff) {
-	char filename[256];
 	Common::SeekableReadStream *in;
 	SaveGameHeader hdr;
 
 	if (slot < 0)
 		return  0;
 
-	makeSavegameName(filename, slot, false);
-	if (!(in = _saveFileMan->openForLoading(filename))) {
+	Common::String filename = makeSavegameName(slot, false);
+	if (!(in = _saveFileMan->openForLoading(filename.c_str()))) {
 		return false;
 	}
 

Modified: scummvm/trunk/engines/scumm/scumm.cpp
===================================================================
--- scummvm/trunk/engines/scumm/scumm.cpp	2008-09-14 21:32:45 UTC (rev 34542)
+++ scummvm/trunk/engines/scumm/scumm.cpp	2008-09-14 21:34:49 UTC (rev 34543)
@@ -2014,7 +2014,6 @@
 	if (_saveLoadFlag) {
 		bool success;
 		const char *errMsg = 0;
-		char filename[256];
 
 		if (_game.version == 8 && _saveTemporaryState)
 			VAR(VAR_GAME_LOADED) = 0;
@@ -2035,13 +2034,13 @@
 				VAR(VAR_GAME_LOADED) = (_game.version == 8) ? 1 : 203;
 		}
 
-		makeSavegameName(filename, _saveLoadSlot, _saveTemporaryState);
+		Common::String filename = makeSavegameName(_saveLoadSlot, _saveTemporaryState);
 		if (!success) {
-			displayMessage(0, errMsg, filename);
+			displayMessage(0, errMsg, filename.c_str());
 		} else if (_saveLoadFlag == 1 && _saveLoadSlot != 0 && !_saveTemporaryState) {
 			// Display "Save successful" message, except for auto saves
 			char buf[256];
-			snprintf(buf, sizeof(buf), "Successfully saved game state in file:\n\n%s", filename);
+			snprintf(buf, sizeof(buf), "Successfully saved game state in file:\n\n%s", filename.c_str());
 
 			GUI::TimedMessageDialog dialog(buf, 1500);
 			runDialog(dialog);

Modified: scummvm/trunk/engines/scumm/scumm.h
===================================================================
--- scummvm/trunk/engines/scumm/scumm.h	2008-09-14 21:32:45 UTC (rev 34542)
+++ scummvm/trunk/engines/scumm/scumm.h	2008-09-14 21:34:49 UTC (rev 34543)
@@ -614,11 +614,16 @@
 	void saveLoadResource(Serializer *ser, int type, int index);	// "Obsolete"
 	void saveResource(Serializer *ser, int type, int index);
 	void loadResource(Serializer *ser, int type, int index);
-	void makeSavegameName(char *out, int slot, bool temporary);
 
+	Common::String makeSavegameName(int slot, bool temporary) const {
+		return makeSavegameName(_targetName, slot, temporary);		
+	}
+
 	int getKeyState(int key);
 
 public:
+	static Common::String makeSavegameName(const Common::String &target, int slot, bool temporary);
+
 	bool getSavegameName(int slot, Common::String &desc);
 	void listSavegames(bool *marks, int num);
 


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