[Scummvm-git-logs] scummvm master -> 2c089c4ed3459696bd347ba4ca675dca9b64e17f

antoniou79 noreply at scummvm.org
Tue Feb 28 17:12:18 UTC 2023


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

Summary:
ba4694fc3e ANDROID: Factorize SAF flags computation
075c3f4246 ANDROID: Add remove feature to Android filesystem abstraction
2c089c4ed3 ANDROID: Don't directly use remove() for save files


Commit: ba4694fc3e319b3d43e22a108443db0eb0e1c508
    https://github.com/scummvm/scummvm/commit/ba4694fc3e319b3d43e22a108443db0eb0e1c508
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-02-28T19:12:11+02:00

Commit Message:
ANDROID: Factorize SAF flags computation

Changed paths:
    backends/platform/android/org/scummvm/scummvm/SAFFSTree.java


diff --git a/backends/platform/android/org/scummvm/scummvm/SAFFSTree.java b/backends/platform/android/org/scummvm/scummvm/SAFFSTree.java
index 8f22bfc2d01..298077636a0 100644
--- a/backends/platform/android/org/scummvm/scummvm/SAFFSTree.java
+++ b/backends/platform/android/org/scummvm/scummvm/SAFFSTree.java
@@ -77,9 +77,11 @@ public class SAFFSTree {
 	}
 
 	public static class SAFFSNode {
-		public static final int DIRECTORY = 1;
-		public static final int WRITABLE  = 2;
-		public static final int READABLE  = 4;
+		public static final int DIRECTORY = 0x01;
+		public static final int WRITABLE  = 0x02;
+		public static final int READABLE  = 0x04;
+		public static final int DELETABLE = 0x08;
+		public static final int REMOVABLE = 0x10;
 
 		public SAFFSNode _parent;
 		public String _path;
@@ -95,6 +97,26 @@ public class SAFFSTree {
 			_documentId = documentId;
 			_flags = flags;
 		}
+
+		private static int computeFlags(String mimeType, int flags) {
+			int ourFlags = 0;
+			if (DocumentsContract.Document.MIME_TYPE_DIR.equals(mimeType)) {
+				ourFlags |= SAFFSNode.DIRECTORY;
+			}
+			if ((flags & (DocumentsContract.Document.FLAG_SUPPORTS_WRITE | DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE)) != 0) {
+				ourFlags |= SAFFSNode.WRITABLE;
+			}
+			if ((flags & DocumentsContract.Document.FLAG_VIRTUAL_DOCUMENT) == 0) {
+				ourFlags |= SAFFSNode.READABLE;
+			}
+			if ((flags & DocumentsContract.Document.FLAG_SUPPORTS_DELETE) != 0) {
+				ourFlags |= SAFFSNode.DELETABLE;
+			}
+			if ((flags & DocumentsContract.Document.FLAG_SUPPORTS_REMOVE) != 0) {
+				ourFlags |= SAFFSNode.REMOVABLE;
+			}
+			return ourFlags;
+		}
 	}
 
 	// Sentinel object
@@ -242,16 +264,7 @@ public class SAFFSTree {
 				final String mimeType = c.getString(2);
 				final int flags = c.getInt(3);
 
-				int ourFlags = 0;
-				if (DocumentsContract.Document.MIME_TYPE_DIR.equals(mimeType)) {
-					ourFlags |= SAFFSNode.DIRECTORY;
-				}
-				if ((flags & (DocumentsContract.Document.FLAG_SUPPORTS_WRITE | DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE)) != 0) {
-					ourFlags |= SAFFSNode.WRITABLE;
-				}
-				if ((flags & DocumentsContract.Document.FLAG_VIRTUAL_DOCUMENT) == 0) {
-					ourFlags |= SAFFSNode.READABLE;
-				}
+				final int ourFlags = SAFFSNode.computeFlags(mimeType, flags);
 
 				SAFFSNode newnode = new SAFFSNode(node, node._path + "/" + displayName, documentId, ourFlags);
 				_cache.put(newnode._path, newnode);
@@ -300,16 +313,7 @@ public class SAFFSTree {
 
 				final int flags = c.getInt(3);
 
-				int ourFlags = 0;
-				if (DocumentsContract.Document.MIME_TYPE_DIR.equals(mimeType)) {
-					ourFlags |= SAFFSNode.DIRECTORY;
-				}
-				if ((flags & (DocumentsContract.Document.FLAG_SUPPORTS_WRITE | DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE)) != 0) {
-					ourFlags |= SAFFSNode.WRITABLE;
-				}
-				if ((flags & DocumentsContract.Document.FLAG_VIRTUAL_DOCUMENT) == 0) {
-					ourFlags |= SAFFSNode.READABLE;
-				}
+				final int ourFlags = SAFFSNode.computeFlags(mimeType, flags);
 
 				newnode = new SAFFSNode(node, childPath, documentId, ourFlags);
 				_cache.put(newnode._path, newnode);
@@ -418,18 +422,8 @@ public class SAFFSTree {
 				final String mimeType = c.getString(1);
 				final int flags = c.getInt(2);
 
-				int ourFlags = 0;
-				if (DocumentsContract.Document.MIME_TYPE_DIR.equals(mimeType)) {
-					ourFlags |= SAFFSNode.DIRECTORY;
-				}
-				if ((flags & (DocumentsContract.Document.FLAG_SUPPORTS_WRITE | DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE)) != 0) {
-					ourFlags |= SAFFSNode.WRITABLE;
-				}
-				if ((flags & DocumentsContract.Document.FLAG_VIRTUAL_DOCUMENT) == 0) {
-					ourFlags |= SAFFSNode.READABLE;
-				}
+				node._flags = SAFFSNode.computeFlags(mimeType, flags);
 
-				node._flags = ourFlags;
 				return displayName;
 			}
 		} catch (Exception e) {


Commit: 075c3f42461c4816eff5ff9c0900f592a81eb886
    https://github.com/scummvm/scummvm/commit/075c3f42461c4816eff5ff9c0900f592a81eb886
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-02-28T19:12:11+02:00

Commit Message:
ANDROID: Add remove feature to Android filesystem abstraction

Changed paths:
    backends/fs/android/android-posix-fs.cpp
    backends/fs/android/android-posix-fs.h
    backends/fs/android/android-saf-fs.cpp
    backends/fs/android/android-saf-fs.h
    backends/platform/android/org/scummvm/scummvm/SAFFSTree.java


diff --git a/backends/fs/android/android-posix-fs.cpp b/backends/fs/android/android-posix-fs.cpp
index 2bc7fd4e7a9..a03e7f66a3d 100644
--- a/backends/fs/android/android-posix-fs.cpp
+++ b/backends/fs/android/android-posix-fs.cpp
@@ -21,6 +21,9 @@
 
 #if defined(__ANDROID__)
 
+// For remove()
+#include <stdio.h>
+
 #include "backends/fs/android/android-fs-factory.h"
 #include "backends/fs/android/android-posix-fs.h"
 #include "backends/fs/android/android-saf-fs.h"
@@ -33,4 +36,12 @@ AbstractFSNode *AndroidPOSIXFilesystemNode::makeNode(const Common::String &path)
 	return AndroidFilesystemFactory::instance().makeFileNodePath(path);
 }
 
+bool AndroidPOSIXFilesystemNode::remove() {
+	if (::remove(_path.c_str()) != 0)
+		return false;
+
+	setFlags();
+	return true;
+}
+
 #endif
diff --git a/backends/fs/android/android-posix-fs.h b/backends/fs/android/android-posix-fs.h
index c4305778e9e..4628a1e9a50 100644
--- a/backends/fs/android/android-posix-fs.h
+++ b/backends/fs/android/android-posix-fs.h
@@ -24,13 +24,17 @@
 
 #include "backends/fs/posix-drives/posix-drives-fs.h"
 
-class AndroidPOSIXFilesystemNode : public DrivePOSIXFilesystemNode {
+#include "backends/fs/android/android-fs.h"
+
+class AndroidPOSIXFilesystemNode : public DrivePOSIXFilesystemNode, public AndroidFSNode {
 	// To let the factory redefine the displayed name
 	friend class AndroidFilesystemFactory;
 protected:
 	AbstractFSNode *makeNode() const override;
 	AbstractFSNode *makeNode(const Common::String &path) const override;
 
+	bool remove() override;
+
 public:
 	AndroidPOSIXFilesystemNode(const Common::String &path, const Config &config)
 		: DrivePOSIXFilesystemNode(path, config) { }
diff --git a/backends/fs/android/android-saf-fs.cpp b/backends/fs/android/android-saf-fs.cpp
index cfa2510794a..5e29dd5b145 100644
--- a/backends/fs/android/android-saf-fs.cpp
+++ b/backends/fs/android/android-saf-fs.cpp
@@ -64,6 +64,7 @@ jmethodID AndroidSAFFilesystemNode::_MID_createDirectory = 0;
 jmethodID AndroidSAFFilesystemNode::_MID_createFile = 0;
 jmethodID AndroidSAFFilesystemNode::_MID_createReadStream = 0;
 jmethodID AndroidSAFFilesystemNode::_MID_createWriteStream = 0;
+jmethodID AndroidSAFFilesystemNode::_MID_removeNode = 0;
 jmethodID AndroidSAFFilesystemNode::_MID_removeTree = 0;
 
 jfieldID AndroidSAFFilesystemNode::_FID__treeName = 0;
@@ -107,6 +108,7 @@ void AndroidSAFFilesystemNode::initJNI() {
 	FIND_METHOD(, createFile, "(" SAFFSNodeSig "Ljava/lang/String;)" SAFFSNodeSig);
 	FIND_METHOD(, createReadStream, "(" SAFFSNodeSig ")I");
 	FIND_METHOD(, createWriteStream, "(" SAFFSNodeSig ")I");
+	FIND_METHOD(, removeNode, "(" SAFFSNodeSig ")Z");
 	FIND_METHOD(, removeTree, "()V");
 
 	FIND_FIELD(, _treeName, "Ljava/lang/String;");
@@ -542,6 +544,59 @@ bool AndroidSAFFilesystemNode::createDirectory() {
 	return true;
 }
 
+bool AndroidSAFFilesystemNode::remove() {
+	assert(_safTree != nullptr);
+
+	if (!_safNode) {
+		return false;
+	}
+
+	if (!_safParent) {
+		// It's the root of the tree: we can't delete it
+		return false;
+	}
+
+	if (isDirectory()) {
+		// Don't delete folders (yet?)
+		return false;
+	}
+
+	JNIEnv *env = JNI::getEnv();
+
+	bool result = env->CallBooleanMethod(_safTree, _MID_removeNode, _safNode);
+
+	if (env->ExceptionCheck()) {
+		LOGE("SAFFSTree::removeNode failed");
+
+		env->ExceptionDescribe();
+		env->ExceptionClear();
+
+		return false;
+	}
+
+	if (!result) {
+		return false;
+	}
+
+	env->DeleteGlobalRef(_safNode);
+	_safNode = nullptr;
+
+	// Create the parent node to fetch informations needed to make us a non-existent node
+	AndroidSAFFilesystemNode *parent = new AndroidSAFFilesystemNode(_safTree, _safParent);
+
+	size_t pos = _path.findLastOf('/');
+	if (pos == Common::String::npos) {
+		_newName = _path;
+	} else {
+		_newName = _path.substr(pos + 1);
+	}
+	_path = parent->_path;
+
+	delete parent;
+
+	return true;
+}
+
 void AndroidSAFFilesystemNode::removeTree() {
 	assert(_safParent == nullptr);
 
diff --git a/backends/fs/android/android-saf-fs.h b/backends/fs/android/android-saf-fs.h
index 931c9f6b282..53e5bbec2bf 100644
--- a/backends/fs/android/android-saf-fs.h
+++ b/backends/fs/android/android-saf-fs.h
@@ -27,12 +27,14 @@
 #include "common/translation.h"
 #include "backends/fs/abstract-fs.h"
 
+#include "backends/fs/android/android-fs.h"
+
 /**
  * Implementation of the ScummVM file system API.
  *
  * Parts of this class are documented in the base interface class, AbstractFSNode.
  */
-class AndroidSAFFilesystemNode final : public AbstractFSNode {
+class AndroidSAFFilesystemNode final : public AbstractFSNode, public AndroidFSNode {
 protected:
 	// SAFFSTree
 	static jmethodID _MID_getTreeId;
@@ -43,6 +45,7 @@ protected:
 	static jmethodID _MID_createFile;
 	static jmethodID _MID_createReadStream;
 	static jmethodID _MID_createWriteStream;
+	static jmethodID _MID_removeNode;
 	static jmethodID _MID_removeTree;
 
 	static jfieldID _FID__treeName;
@@ -134,6 +137,8 @@ public:
 	Common::SeekableWriteStream *createWriteStream() override;
 	bool createDirectory() override;
 
+	bool remove() override;
+
 	/**
 	 * Removes the SAF tree.
 	 * Only works on the root node
@@ -154,7 +159,7 @@ protected:
 	void cacheData(bool force = false);
 };
 
-class AddSAFFakeNode final : public AbstractFSNode {
+class AddSAFFakeNode final : public AbstractFSNode, public AndroidFSNode {
 protected:
 	AbstractFSNode *getChild(const Common::String &name) const override;
 	AbstractFSNode *getParent() const override;
@@ -178,11 +183,11 @@ public:
 	bool isReadable() const override;
 	bool isWritable() const override;
 
-
 	Common::SeekableReadStream *createReadStream() override { return nullptr; }
-	virtual Common::SeekableWriteStream *createWriteStream() override { return nullptr; }
+	Common::SeekableWriteStream *createWriteStream() override { return nullptr; }
 
-	virtual bool createDirectory() { return false; }
+	bool createDirectory() override { return false; }
+	bool remove() override { return false; }
 
 private:
 	void makeProxySAF() const;
diff --git a/backends/platform/android/org/scummvm/scummvm/SAFFSTree.java b/backends/platform/android/org/scummvm/scummvm/SAFFSTree.java
index 298077636a0..8ea88ce4547 100644
--- a/backends/platform/android/org/scummvm/scummvm/SAFFSTree.java
+++ b/backends/platform/android/org/scummvm/scummvm/SAFFSTree.java
@@ -347,6 +347,40 @@ public class SAFFSTree {
 		return createStream(node, "wt");
 	}
 
+	public boolean removeNode(SAFFSNode node) {
+		final ContentResolver resolver = _context.getContentResolver();
+		final Uri uri = DocumentsContract.buildDocumentUriUsingTree(_treeUri, node._documentId);
+
+		if ((node._flags & SAFFSNode.REMOVABLE) != 0) {
+			final Uri parentUri = DocumentsContract.buildDocumentUriUsingTree(_treeUri, node._parent._documentId);
+			try {
+				if (!DocumentsContract.removeDocument(resolver, uri, parentUri)) {
+					return false;
+				}
+			} catch(FileNotFoundException e) {
+				return false;
+			}
+		} else if ((node._flags & SAFFSNode.DELETABLE) != 0) {
+			try {
+				if (!DocumentsContract.deleteDocument(resolver, uri)) {
+					return false;
+				}
+			} catch(FileNotFoundException e) {
+				return false;
+			}
+		} else {
+			return false;
+		}
+
+		for(Map.Entry<String, SAFFSNode> e : _cache.entrySet()) {
+			if (e.getValue() == node) {
+				e.setValue(NOT_FOUND_NODE);
+			}
+		}
+
+		return true;
+	}
+
 	public void removeTree() {
 		final ContentResolver resolver = _context.getContentResolver();
 


Commit: 2c089c4ed3459696bd347ba4ca675dca9b64e17f
    https://github.com/scummvm/scummvm/commit/2c089c4ed3459696bd347ba4ca675dca9b64e17f
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-02-28T19:12:11+02:00

Commit Message:
ANDROID: Don't directly use remove() for save files

Use our brand new remove feature in filesystem

Changed paths:
    backends/platform/android/android.cpp


diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index a06a5ca224f..4f21d14140b 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -70,6 +70,7 @@
 #include "backends/graphics3d/android/android-graphics3d.h"
 #include "backends/platform/android/jni-android.h"
 #include "backends/platform/android/android.h"
+#include "backends/fs/android/android-fs.h"
 #include "backends/fs/android/android-fs-factory.h"
 
 const char *android_log_tag = "ScummVM";
@@ -122,6 +123,38 @@ void checkGlError(const char *expr, const char *file, int line) {
 }
 #endif
 
+class AndroidSaveFileManager : public DefaultSaveFileManager {
+public:
+	AndroidSaveFileManager(const Common::String &defaultSavepath) : DefaultSaveFileManager(defaultSavepath) {}
+
+	bool removeSavefile(const Common::String &filename) override {
+		Common::String path = getSavePath() + "/" + filename;
+		AbstractFSNode *node = AndroidFilesystemFactory::instance().makeFileNodePath(path);
+
+		if (!node) {
+			return false;
+		}
+
+		AndroidFSNode *anode = dynamic_cast<AndroidFSNode *>(node);
+
+		if (!anode) {
+			// This should never happen
+			warning("Invalid node received");
+			delete node;
+			return false;
+		}
+
+		bool ret = anode->remove();
+
+		delete anode;
+
+		if (!ret) {
+			setError(Common::kUnknownError, Common::String("Couldn't delete the save file: %s", path.c_str()));
+		}
+		return ret;
+	}
+};
+
 OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) :
 	_audio_sample_rate(audio_sample_rate),
 	_audio_buffer_size(audio_buffer_size),
@@ -450,9 +483,7 @@ void OSystem_Android::initBackend() {
 		ConfMan.setInt("gui_scale", 125); // "Large" (see gui/options.cpp and guiBaseValues[])
 	}
 
-
-	ConfMan.registerDefault("savepath", ConfMan.get("path") + "/saves");
-	_savefileManager = new DefaultSaveFileManager(ConfMan.get("savepath"));
+	_savefileManager = new AndroidSaveFileManager(ConfMan.get("path") + "/saves");
 	// TODO remove the debug message eventually
 	LOGD("Setting DefaultSaveFileManager path to: %s", ConfMan.get("savepath").c_str());
 




More information about the Scummvm-git-logs mailing list