[Scummvm-cvs-logs] SF.net SVN: scummvm:[54332] scummvm/trunk/backends/platform/ds/arm9/source

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Nov 18 18:31:13 CET 2010


Revision: 54332
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54332&view=rev
Author:   fingolfin
Date:     2010-11-18 17:31:12 +0000 (Thu, 18 Nov 2010)

Log Message:
-----------
DS: Replace GBAMPSaveFile by DSFileStream + wrapBufferedWriteStream

Modified Paths:
--------------
    scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.cpp
    scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.h

Modified: scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.cpp
===================================================================
--- scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.cpp	2010-11-18 17:30:00 UTC (rev 54331)
+++ scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.cpp	2010-11-18 17:31:12 UTC (rev 54332)
@@ -31,162 +31,54 @@
 #include "backends/fs/ds/ds-fs.h"
 #include "common/config-manager.h"
 
-/////////////////////////
-// GBAMP Save File
-/////////////////////////
 
-GBAMPSaveFile::GBAMPSaveFile(char *name, bool saveOrLoad) {
-	handle = DS::std_fopen(name, saveOrLoad? "w": "r");
-//	consolePrintf("%s handle is %d\n", name, handle);
-//	consolePrintf("Created %s\n", name);
-	bufferPos = 0;
-	saveSize = 0;
-	flushed = 0;
-}
+#define SAVE_BUFFER_SIZE 100000
 
-GBAMPSaveFile::~GBAMPSaveFile() {
-	flushSaveBuffer();
-	if (handle)
-		DS::std_fclose((FILE *)handle);
-//	consolePrintf("Closed file\n");
+// This method copied from an old version of the savefile.cpp, since it's been removed from there and
+// placed in default-saves.cpp, where I cannot call it.
+// FIXME: Does it even make sense to change the "savepath" on the NDS? Considering
+// that nothing sets a default value for the "savepath" either, wouldn't it better
+// to return a fixed path here?
+static Common::String getSavePath() {
+	// Try to use game specific savepath from config
+	return ConfMan.get("savepath");
 }
 
-uint32 GBAMPSaveFile::read(void *buf, uint32 length) {
-	saveSize += length;
-//	consolePrintf("Read %d %d ", length, saveSize);
-	return DS::std_fread(buf, 1, length, (FILE *)handle);
-}
-
-bool GBAMPSaveFile::eos() const {
-	return DS::std_feof((FILE *)handle);
-}
-
-bool GBAMPSaveFile::skip(uint32 bytes) {
-	return DS::std_fseek((FILE *)handle, bytes, SEEK_CUR) == 0;
-}
-
-void GBAMPSaveFile::flushSaveBuffer() {
-	if (bufferPos != 0) {
-//		consolePrintf("Flushing %d bytes from %x\n", bufferPos, buffer);
-		flushed += bufferPos;
-		DS::std_fwrite(buffer, 1, bufferPos, (FILE *)handle);
-		bufferPos = 0;
-	}
-}
-
-int32 GBAMPSaveFile::pos() const {
-	return DS::std_ftell((FILE *)handle);
-}
-
-int32 GBAMPSaveFile::size() const {
-	int position = pos();
-	DS::std_fseek((FILE *)handle, 0, SEEK_END);
-	int length = DS::std_ftell((FILE *)handle);
-	DS::std_fseek((FILE *)handle, position, SEEK_SET);
-	return length;
-}
-
-bool GBAMPSaveFile::seek(int32 newPos, int whence) {
-	return DS::std_fseek((FILE *)handle, newPos, whence) == 0;
-}
-
-
-uint32 GBAMPSaveFile::write(const void *buf, uint32 length) {
-	if (bufferPos + length > SAVE_BUFFER_SIZE) {
-		flushSaveBuffer();
-		saveSize += length;
-//		consolePrintf("Writing %d bytes from %x", length, buf);
-//		DS::std_fwrite(buf, 1, length, handle);
-
-		memcpy(buffer + bufferPos, buf, length);
-		bufferPos += length;
-
-		saveSize += length;
-
-
-/*		int pos = 0;
-
-		int rest = SAVE_BUFFER_SIZE - bufferPos;
-		memcpy(buffer + bufferPos, buf, rest);
-		bufferPos = 512;
-		pos += rest;
-		flushSaveBuffer();
-		length -= rest;
-//		consolePrintf("First section: %d\n", rest);
-
-		while (length >= 512) {
-			DS::std_fwrite(((char *) (buf)) + pos, 1, 512, handle);
-			length -= 512;
-			pos += 512;
-//			consolePrintf("Full chunk, %d left ", length);
-		}
-
-		bufferPos = 0;
-		memcpy(buffer + bufferPos, ((char *) (buf)) + pos, length);
-		bufferPos += length;
-//		consolePrintf("%d left in buffer ", bufferPos);*/
-
-	} else {
-
-		memcpy(buffer + bufferPos, buf, length);
-		bufferPos += length;
-
-		saveSize += length;
-	}
-
-//	if ((length > 100) || (length <= 0)) consolePrintf("Write %d bytes\n", length);
-	return length;
-}
-
-
 //////////////////////////
 // GBAMP Save File Manager
 //////////////////////////
 
-GBAMPSaveFileManager::GBAMPSaveFileManager() {
+Common::OutSaveFile *GBAMPSaveFileManager::openForSaving(const Common::String &filename) {
+	Common::String fileSpec = getSavePath();
+	if (fileSpec.lastChar() != '/')
+		fileSpec += '/';
+	fileSpec += filename;
 
+//	consolePrintf("Opening the file: %s\n", fileSpec.c_str());
+	
+	Common::WriteStream *stream = DS::DSFileStream::makeFromPath(fileSpec, true);
+	// Use a write buffer
+	stream = Common::wrapBufferedWriteStream(stream, SAVE_BUFFER_SIZE, DisposeAfterUse::YES);
+	return stream;
 }
 
-GBAMPSaveFileManager::~GBAMPSaveFileManager() {
+Common::InSaveFile *GBAMPSaveFileManager::openForLoading(const Common::String &filename) {
+	Common::String fileSpec = getSavePath();
+	if (fileSpec.lastChar() != '/')
+		fileSpec += '/';
+	fileSpec += filename;
 
+//	consolePrintf("Opening the file: %s\n", fileSpec.c_str());
+	
+	return DS::DSFileStream::makeFromPath(fileSpec, false);
 }
 
-GBAMPSaveFile *GBAMPSaveFileManager::openSavefile(const char *name, bool saveOrLoad) {
-	char fileSpec[128];
 
-	strcpy(fileSpec, getSavePath());
-
-	if (fileSpec[strlen(fileSpec) - 1] == '/') {
-		sprintf(fileSpec, "%s%s", getSavePath(), name);
-	} else {
-		sprintf(fileSpec, "%s/%s", getSavePath(), name);
-	}
-
-//	consolePrintf("Opening the file: %s\n", fileSpec);
-	GBAMPSaveFile *sf = new GBAMPSaveFile(fileSpec, saveOrLoad);
-	if (sf->isOpen()) {
-//		consolePrintf("Ok");
-		return sf;
-	} else {
-//		consolePrintf("Fail");
-		delete sf;
-		return NULL;
-	}
+bool GBAMPSaveFileManager::removeSavefile(const Common::String &filename) {
+	return false; // TODO: Implement this
 }
 
-// This method copied from an old version of the savefile.cpp, since it's been removed from there and
-// placed in default-saves.cpp, where I cannot call it.
-// FIXME: Does it even make sense to change the "savepath" on the NDS? Considering
-// that nothing sets a default value for the "savepath" either, wouldn't it better
-// to return a fixed path here?
-const char *GBAMPSaveFileManager::getSavePath() const {
-	// Try to use game specific savepath from config
-	const char *dir = ConfMan.get("savepath").c_str();
-	assert(dir);
 
-	return dir;
-}
-
 Common::StringArray GBAMPSaveFileManager::listSavefiles(const Common::String &pattern) {
 
 	enum { TYPE_NO_MORE = 0, TYPE_FILE = 1, TYPE_DIR = 2 };
@@ -194,7 +86,7 @@
 
 	{
 		char dir[128];
-		strcpy(dir, getSavePath());
+		strcpy(dir, getSavePath().c_str());
 		char *realName = dir;
 
 		if ((strlen(dir) >= 4) && (dir[0] == 'm') && (dir[1] == 'p') && (dir[2] == ':') && (dir[3] == '/')) {

Modified: scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.h
===================================================================
--- scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.h	2010-11-18 17:30:00 UTC (rev 54331)
+++ scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.h	2010-11-18 17:31:12 UTC (rev 54332)
@@ -26,59 +26,15 @@
 #ifndef _GBAMPSAVE_H_
 #define _GBAMPSAVE_H_
 
-#include "common/system.h"
 #include "common/savefile.h"
 
-#define SAVE_BUFFER_SIZE 100000
-
-class GBAMPSaveFile : public Common::InSaveFile, public Common::OutSaveFile {
-	void *handle;
-	char buffer[SAVE_BUFFER_SIZE];
-	int bufferPos;
-	int saveSize;
-	int flushed;
-
-public:
-	GBAMPSaveFile(char *name, bool saveOrLoad);
-	virtual ~GBAMPSaveFile();
-
-	virtual uint32 read(void *buf, uint32 size);
-	virtual uint32 write(const void *buf, uint32 size);
-
-	virtual bool eos() const;
-	virtual bool skip(uint32 bytes);
-
-	virtual int32 pos() const;
-	virtual int32 size() const;
-	virtual bool seek(int32 pos, int whence);
-
-	void flushSaveBuffer();
-
-	virtual bool isOpen() const {
-		return handle != 0;
-	}
-};
-
-
 class GBAMPSaveFileManager : public Common::SaveFileManager {
 public:
-	GBAMPSaveFileManager();
-	~GBAMPSaveFileManager();
+	virtual Common::OutSaveFile *openForSaving(const Common::String &filename);
+	virtual Common::InSaveFile *openForLoading(const Common::String &filename);
 
-//	static GBAMPSaveFileManager *instance() { return instancePtr; }
-
-	GBAMPSaveFile *openSavefile(const char *filename, bool saveOrLoad);
-
-	virtual Common::OutSaveFile *openForSaving(const Common::String &filename) { return openSavefile(filename.c_str(), true); }
-	virtual Common::InSaveFile *openForLoading(const Common::String &filename) { return openSavefile(filename.c_str(), false); }
-
-	virtual bool removeSavefile(const Common::String &filename) { return false; } // TODO: Implement this
+	virtual bool removeSavefile(const Common::String &filename);
 	virtual Common::StringArray listSavefiles(const Common::String &pattern);
-
-	void deleteFile(const Common::String &name);
-	void listFiles();
-
-	const char *getSavePath() const;
 };
 
 #endif


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