[Scummvm-git-logs] scummvm master -> eeda6bc15357199c8d0596fb64ed4ddef1ab80bf

dreammaster dreammaster at scummvm.org
Thu Sep 2 04:30:56 UTC 2021


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
94be258edb AGS: Consolidate opening save files for writing
eeda6bc153 AGS: Fix loading of images from save folder


Commit: 94be258edbe2fc0c65c815e1c5d25c6e35026dda
    https://github.com/scummvm/scummvm/commit/94be258edbe2fc0c65c815e1c5d25c6e35026dda
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-09-01T18:54:38-07:00

Commit Message:
AGS: Consolidate opening save files for writing

Changed paths:
    engines/ags/shared/util/file_stream.cpp
    engines/ags/shared/util/file_stream.h


diff --git a/engines/ags/shared/util/file_stream.cpp b/engines/ags/shared/util/file_stream.cpp
index 3f4ff4646c..74cad944b3 100644
--- a/engines/ags/shared/util/file_stream.cpp
+++ b/engines/ags/shared/util/file_stream.cpp
@@ -164,10 +164,6 @@ bool FileStream::Seek(soff_t offset, StreamSeek origin) {
 	return ags_fseek(_file, (file_off_t)offset, stdclib_origin) == 0;
 }
 
-String FileStream::getSaveName(const String &filename) {
-	return String(filename.GetCStr() + strlen(SAVE_FOLDER_PREFIX));
-}
-
 void FileStream::Open(const String &file_name, FileOpenMode open_mode, FileWorkMode work_mode) {
 	if (open_mode == kFile_Open) {
 		if (!file_name.CompareLeftNoCase(SAVE_FOLDER_PREFIX)) {
@@ -186,40 +182,12 @@ void FileStream::Open(const String &file_name, FileOpenMode open_mode, FileWorkM
 		}
 
 	} else {
+		String saveName;
 
 		if (!file_name.CompareLeftNoCase(SAVE_FOLDER_PREFIX)) {
-			String saveName = getSaveName(file_name);
-			Common::InSaveFile *existing = nullptr;
-
-			if (open_mode == kFile_Create &&
-				(existing = g_system->getSavefileManager()->openForLoading(saveName)) != nullptr) {
-				// kFile_Create mode allows opening existing files for read/write.
-				// Since ScummVM doesn't support this via the save file manager,
-				// we need to do a bit of a hack and load the existing contents,
-				// then recreate the file and write out the contents so that further
-				// writes will be possible without affecting the old data
-				size_t fileSize = existing->size();
-				byte *data = new byte[fileSize];
-				existing->read(data, fileSize);
-				delete existing;
-
-				Common::OutSaveFile *out = g_system->getSavefileManager()->openForSaving(saveName, false);
-				assert(out);
-
-				out->write(data, fileSize);
-				if (work_mode != kFile_Write)
-					out->seek(0, SEEK_SET);
-				delete[] data;
-
-				_file = out;
-			} else {
-				_file = g_system->getSavefileManager()->openForSaving(saveName, false);
-			}
+			saveName = getSaveName(file_name);
 
 		} else {
-			if (open_mode == kFile_Create)
-				warning("Non-save file opened in kFile_Create mode");
-
 			Common::String fname = file_name;
 			if (fname.hasPrefix("./"))
 				fname = fname.substr(2);
@@ -228,14 +196,55 @@ void FileStream::Open(const String &file_name, FileOpenMode open_mode, FileWorkM
 			else if (fname.findFirstOf('/') != Common::String::npos)
 				error("Invalid attempt to create file - %s", fname.c_str());
 
-			_file = g_system->getSavefileManager()->openForSaving(fname, false);
+			saveName = fname;
 		}
 
+		_file = openForWriting(saveName, open_mode, work_mode);
+
 		if (!_file)
 			error("Invalid attempt to create file - %s", file_name.GetCStr());
 	}
 }
 
+
+String FileStream::getSaveName(const String &filename) {
+	return String(filename.GetCStr() + strlen(SAVE_FOLDER_PREFIX));
+}
+
+Common::OutSaveFile *FileStream::openForWriting(const String &saveName, FileOpenMode open_mode, FileWorkMode work_mode) {
+	bool seek0 = false, duplicate = false;
+	assert(open_mode != kFile_Open);
+
+	if (work_mode == kFile_Read || work_mode == kFile_ReadWrite)
+		// In the original these modes result in [aw]+b, which seems to result
+		// in a file with arbitrary reading, but writing always appending
+		warning("FileOpen: independant read/write positions not supported");
+
+	Common::InSaveFile *existing = nullptr;
+	if (open_mode == kFile_Create &&
+		(existing = g_system->getSavefileManager()->openForLoading(saveName)) != nullptr) {
+		// kFile_Create mode allows opening existing files for read/write.
+		// Since ScummVM doesn't support this via the save file manager,
+		// we need to do a bit of a hack and load the existing contents,
+		// then recreate the file and write out the contents so that further
+		// writes will be possible without affecting the old data
+		size_t fileSize = existing->size();
+		byte *data = new byte[fileSize];
+		existing->read(data, fileSize);
+		delete existing;
+
+		Common::OutSaveFile *out = g_system->getSavefileManager()->openForSaving(saveName, false);
+		assert(out);
+
+		out->write(data, fileSize);
+		delete[] data;
+
+		return out;
+	}
+
+	return g_system->getSavefileManager()->openForSaving(saveName);
+}
+
 } // namespace Shared
 } // namespace AGS
 } // namespace AGS3
diff --git a/engines/ags/shared/util/file_stream.h b/engines/ags/shared/util/file_stream.h
index feb3a4b1db..200b8fc96d 100644
--- a/engines/ags/shared/util/file_stream.h
+++ b/engines/ags/shared/util/file_stream.h
@@ -68,6 +68,7 @@ public:
 private:
 	void Open(const String &file_name, FileOpenMode open_mode, FileWorkMode work_mode);
 	String getSaveName(const String &filename);
+	Common::OutSaveFile *openForWriting(const String &saveName, FileOpenMode open_mode, FileWorkMode work_mode);
 
 	Common::Stream *_file;
 	const FileWorkMode  _workMode;


Commit: eeda6bc15357199c8d0596fb64ed4ddef1ab80bf
    https://github.com/scummvm/scummvm/commit/eeda6bc15357199c8d0596fb64ed4ddef1ab80bf
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-09-01T21:30:44-07:00

Commit Message:
AGS: Fix loading of images from save folder

Changed paths:
    engines/ags/shared/gfx/image.cpp


diff --git a/engines/ags/shared/gfx/image.cpp b/engines/ags/shared/gfx/image.cpp
index ce58591c52..8d738f8296 100644
--- a/engines/ags/shared/gfx/image.cpp
+++ b/engines/ags/shared/gfx/image.cpp
@@ -21,6 +21,8 @@
  */
 
 #include "ags/shared/gfx/image.h"
+#include "ags/shared/util/file.h"
+#include "ags/shared/util/stream.h"
 #include "ags/lib/allegro.h"
 #include "common/file.h"
 #include "common/str.h"
@@ -38,9 +40,13 @@ namespace AGS3 {
 template<class DECODER>
 BITMAP *decodeImage(const char *filename, color *pal) {
 	DECODER decoder;
-	Common::File f;
 
-	if (f.open(filename) && decoder.loadStream(f)) {
+	AGS::Shared::Stream *file = AGS3::AGS::Shared::File::OpenFileRead(filename);
+	if (!file)
+		return nullptr;
+
+	AGS::Shared::ScummVMReadStream f(file);
+	if (decoder.loadStream(f)) {
 		// Create the output surface
 		const Graphics::Surface *src = decoder.getSurface();
 




More information about the Scummvm-git-logs mailing list