ScummVM API documentation
android-saf-fs.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ANDROID_SAF_FILESYSTEM_H
23 #define ANDROID_SAF_FILESYSTEM_H
24 
25 #include <jni.h>
26 
27 #include "backends/fs/abstract-fs.h"
28 
29 #include "backends/fs/android/android-fs.h"
30 
37 protected:
38  // SAFFSTree
39  static jmethodID _MID_getTreeId;
40  static jmethodID _MID_pathToNode;
41  static jmethodID _MID_getChildren;
42  static jmethodID _MID_getChild;
43  static jmethodID _MID_createDirectory;
44  static jmethodID _MID_createFile;
45  static jmethodID _MID_createReadStream;
46  static jmethodID _MID_createWriteStream;
47  static jmethodID _MID_removeNode;
48  static jmethodID _MID_removeTree;
49 
50  static jfieldID _FID__treeName;
51  static jfieldID _FID__root;
52 
53  // SAFFSNode
54  static jfieldID _FID__parent;
55  static jfieldID _FID__path;
56  static jfieldID _FID__documentId;
57  static jfieldID _FID__flags;
58 
59  static bool _JNIinit;
60 
61 protected:
62  static const int DIRECTORY = 1;
63  static const int WRITABLE = 2;
64  static const int READABLE = 4;
65 
66  jobject _safTree;
67  // When null, node doesn't exist yet
68  // In this case _path is the parent path, _newName the node name and _safParent the parent SAF object
69  jobject _safNode;
70 
71  Common::String _path;
72  int _flags;
73  jobject _safParent;
74 
75  // Used when creating a new node
76  // Also used for root node to store its pretty name
77  Common::String _newName;
78 
85  AndroidSAFFilesystemNode(jobject safTree, jobject safNode);
86 
87 public:
88  static const char SAF_MOUNT_POINT[];
89 
94  static void initJNI();
95 
102 
108  static AndroidSAFFilesystemNode *makeFromTree(jobject safTree);
109 
116 
120  ~AndroidSAFFilesystemNode() override;
121 
122  bool exists() const override { return _safNode != nullptr; }
124  Common::String getName() const override;
125  Common::String getPath() const override;
126  bool isDirectory() const override { return _flags & DIRECTORY; }
127  bool isReadable() const override { return _flags & READABLE; }
128  bool isWritable() const override { return _flags & WRITABLE; }
129 
130  AbstractFSNode *getChild(const Common::String &n) const override;
131  bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const override;
132  AbstractFSNode *getParent() const override;
133 
135  Common::SeekableWriteStream *createWriteStream(bool atomic) override;
136  bool createDirectory() override;
137 
138  bool remove() override;
139 
144  void removeTree();
145 protected:
154  AndroidSAFFilesystemNode(jobject safTree, jobject safParent,
155  const Common::String &path, const Common::String &name);
156 
157  void cacheData();
158 };
159 
160 class AddSAFFakeNode final : public AbstractFSNode, public AndroidFSNode {
161 protected:
162  AbstractFSNode *getChild(const Common::String &name) const override;
163  AbstractFSNode *getParent() const override;
164 
165 public:
166  static const char SAF_ADD_FAKE_PATH[];
167 
168  AddSAFFakeNode(bool fromPath) : _proxied(nullptr), _fromPath(fromPath) { }
169  ~AddSAFFakeNode() override;
170 
171  bool exists() const override;
172 
173  bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const override;
174 
175  // I18N: This is displayed in the file browser to let the user choose a new folder for Android Storage Attached Framework
176  Common::U32String getDisplayName() const override;
177  Common::String getName() const override;
178  Common::String getPath() const override;
179 
180  bool isDirectory() const override { return true; }
181  bool isReadable() const override;
182  bool isWritable() const override;
183 
184  Common::SeekableReadStream *createReadStream() override { return nullptr; }
185  Common::SeekableWriteStream *createWriteStream(bool atomic) override { return nullptr; }
186 
187  bool createDirectory() override { return false; }
188  bool remove() override { return false; }
189 
190 private:
191  void makeProxySAF() const;
192 
193  bool _fromPath;
194  mutable AbstractFSNode *_proxied;
195 };
196 #endif
Definition: str.h:59
Common::SeekableReadStream * createReadStream() override
bool isWritable() const override
Definition: android-saf-fs.h:128
Definition: array.h:52
bool isReadable() const override
Definition: android-saf-fs.h:127
static AndroidSAFFilesystemNode * makeFromPath(const Common::String &path)
Definition: stream.h:745
Definition: android-saf-fs.h:36
bool isDirectory() const override
Definition: android-saf-fs.h:180
Common::SeekableWriteStream * createWriteStream(bool atomic) override
Definition: android-fs.h:29
bool createDirectory() override
Definition: ustr.h:57
AbstractFSNode * getChild(const Common::String &n) const override
Definition: android-saf-fs.h:160
~AndroidSAFFilesystemNode() override
ListMode
Definition: fs.h:86
Common::String getName() const override
AndroidSAFFilesystemNode(jobject safTree, jobject safNode)
Common::String getPath() const override
Common::SeekableWriteStream * createWriteStream(bool atomic) override
Definition: android-saf-fs.h:185
AbstractFSNode * getParent() const override
bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const override
Definition: stream.h:351
Common::SeekableReadStream * createReadStream() override
Definition: android-saf-fs.h:184
bool createDirectory() override
Definition: android-saf-fs.h:187
Definition: abstract-fs.h:41
static AndroidSAFFilesystemNode * makeFromTree(jobject safTree)
Common::U32String getDisplayName() const override
Definition: android-saf-fs.h:123
bool isDirectory() const override
Definition: android-saf-fs.h:126