[Scummvm-git-logs] scummvm branch-2-3 -> ebc4e0b354b1dd96733faab36102b114aff5b13d

criezy criezy at scummvm.org
Tue Aug 31 17:53:43 UTC 2021


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

Summary:
be34657b0f AGS: Flatten paths in the save directory
870149b6c2 AGS: Remove unused variable
813aaa942b AGS: Add some debug messages to ResolveScriptPath
d71ec9238f AGS: Simultate opening existing save files for read/write
ebc4e0b354 AGS; Fix opening stream in append mode


Commit: be34657b0fced69c05f041787c4dd6333cc90040
    https://github.com/scummvm/scummvm/commit/be34657b0fced69c05f041787c4dd6333cc90040
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-08-31T18:50:42+01:00

Commit Message:
AGS: Flatten paths in the save directory

ScummVM does not support using sub-directories in the save directory,
so we flatten the path by replacing '/' with '-'.

This fixes saving and loading with the in-game dialogs in Strangeland.
Fixes bug #12864.

Changed paths:
    engines/ags/engine/ac/file.cpp


diff --git a/engines/ags/engine/ac/file.cpp b/engines/ags/engine/ac/file.cpp
index 105a2c3ca4..6b285ea3e4 100644
--- a/engines/ags/engine/ac/file.cpp
+++ b/engines/ags/engine/ac/file.cpp
@@ -351,8 +351,10 @@ bool ResolveScriptPath(const String &orig_sc_path, bool read_only, ResolvedPath
 #if AGS_PLATFORM_SCUMMVM
 	// For files on savepath, always ensure it starts with the game target prefix to avoid
 	// conflicts (as we usually have the same save dir for all games).
+	// Also flatten the path if needed as we do not support subdirectories in the save folder.
 	if (parent_dir.BaseDir == SAVE_FOLDER_PREFIX) {
-		debugC(::AGS::kDebugFilePath, "Adding ScummVM game target prefix");
+		debugC(::AGS::kDebugFilePath, "Adding ScummVM game target prefix and flatten path");
+		child_path.Replace('/', '-');
 		String gameTarget = ConfMan.getActiveDomainName();
 		if (child_path.CompareLeft(gameTarget) != 0)
 			child_path = String::FromFormat("%s-%s", gameTarget.GetCStr(), child_path.GetCStr());


Commit: 870149b6c229170a30b7a6876924a11b5faeb5d6
    https://github.com/scummvm/scummvm/commit/870149b6c229170a30b7a6876924a11b5faeb5d6
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-08-31T18:50:58+01:00

Commit Message:
AGS: Remove unused variable

This is not present in the upstream code either. I guess this was
part of some intermediate changes we did, but is no longer needed.

Changed paths:
    engines/ags/engine/ac/file.cpp


diff --git a/engines/ags/engine/ac/file.cpp b/engines/ags/engine/ac/file.cpp
index 6b285ea3e4..93767af907 100644
--- a/engines/ags/engine/ac/file.cpp
+++ b/engines/ags/engine/ac/file.cpp
@@ -361,7 +361,6 @@ bool ResolveScriptPath(const String &orig_sc_path, bool read_only, ResolvedPath
 	}
 #endif
 
-	String full_path = String::FromFormat("%s%s", parent_dir.BaseDir.GetCStr(), child_path.GetCStr());
 	// don't allow write operations for relative paths outside game dir
 	ResolvedPath test_rp = ResolvedPath(parent_dir, child_path, alt_path);
 	if (!read_only) {


Commit: 813aaa942be1924b67e4af974d2d52a91253c4e6
    https://github.com/scummvm/scummvm/commit/813aaa942be1924b67e4af974d2d52a91253c4e6
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-08-31T18:51:11+01:00

Commit Message:
AGS: Add some debug messages to ResolveScriptPath

Changed paths:
    engines/ags/engine/ac/file.cpp


diff --git a/engines/ags/engine/ac/file.cpp b/engines/ags/engine/ac/file.cpp
index 93767af907..3fc6de3849 100644
--- a/engines/ags/engine/ac/file.cpp
+++ b/engines/ags/engine/ac/file.cpp
@@ -371,6 +371,9 @@ bool ResolveScriptPath(const String &orig_sc_path, bool read_only, ResolvedPath
 	}
 
 	rp = test_rp;
+	debugC(::AGS::kDebugFilePath, "Final path: %s", rp.FullPath.GetCStr());
+	if (!rp.AltPath.IsEmpty())
+		debugC(::AGS::kDebugFilePath, "Alt path: %s", rp.AltPath.GetCStr());
 	return true;
 }
 


Commit: d71ec9238f347f1d8e3459635e0aeea1179bf685
    https://github.com/scummvm/scummvm/commit/d71ec9238f347f1d8e3459635e0aeea1179bf685
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-08-31T18:51:24+01:00

Commit Message:
AGS: Simultate opening existing save files for read/write

When the open mode of kFile_Create is passed, files are
meant to be opened in read/write mode if they already exist,
rather than simply replacing them. The code of this commit
should allow this to be simulated, by opening the file first
for reading, and then duplicating into a new OutSaveFile 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 28d8ee464a..0907d899a6 100644
--- a/engines/ags/shared/util/file_stream.cpp
+++ b/engines/ags/shared/util/file_stream.cpp
@@ -164,11 +164,15 @@ 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)) {
-			_file = g_system->getSavefileManager()->openForLoading(
-			            file_name.GetCStr() + strlen(SAVE_FOLDER_PREFIX));
+			String saveName = getSaveName(file_name);
+			_file = g_system->getSavefileManager()->openForLoading(saveName);
 
 		} else {
 			// First try to open file in game folder
@@ -184,9 +188,37 @@ void FileStream::Open(const String &file_name, FileOpenMode open_mode, FileWorkM
 	} else {
 
 		if (!file_name.CompareLeftNoCase(SAVE_FOLDER_PREFIX)) {
-			_file = g_system->getSavefileManager()->openForSaving(
-			               file_name.GetCStr() + strlen(SAVE_FOLDER_PREFIX), false);
+			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);
+				out->seek(0, SEEK_SET);
+				delete[] data;
+
+				_file = out;
+			} else {
+				_file = g_system->getSavefileManager()->openForSaving(saveName, false);
+			}
+
 		} 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);
diff --git a/engines/ags/shared/util/file_stream.h b/engines/ags/shared/util/file_stream.h
index 590f971706..feb3a4b1db 100644
--- a/engines/ags/shared/util/file_stream.h
+++ b/engines/ags/shared/util/file_stream.h
@@ -67,6 +67,7 @@ public:
 
 private:
 	void Open(const String &file_name, FileOpenMode open_mode, FileWorkMode work_mode);
+	String getSaveName(const String &filename);
 
 	Common::Stream *_file;
 	const FileWorkMode  _workMode;


Commit: ebc4e0b354b1dd96733faab36102b114aff5b13d
    https://github.com/scummvm/scummvm/commit/ebc4e0b354b1dd96733faab36102b114aff5b13d
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-08-31T18:51:37+01:00

Commit Message:
AGS; Fix opening stream in append mode

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


diff --git a/engines/ags/shared/util/file_stream.cpp b/engines/ags/shared/util/file_stream.cpp
index 0907d899a6..3f4ff4646c 100644
--- a/engines/ags/shared/util/file_stream.cpp
+++ b/engines/ags/shared/util/file_stream.cpp
@@ -207,7 +207,8 @@ void FileStream::Open(const String &file_name, FileOpenMode open_mode, FileWorkM
 				assert(out);
 
 				out->write(data, fileSize);
-				out->seek(0, SEEK_SET);
+				if (work_mode != kFile_Write)
+					out->seek(0, SEEK_SET);
 				delete[] data;
 
 				_file = out;




More information about the Scummvm-git-logs mailing list