Debian Codegraph @

platform/android/dir_access_jandroid.h

raw symbols SCIP
1 /**************************************************************************/
2 /* dir_access_jandroid.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "java_godot_lib_jni.h"
34
35 #include "core/io/dir_access.h"
36 #include "drivers/unix/dir_access_unix.h"
37
38 #include <cstdio>
39
40 /// Android implementation of the DirAccess interface used to provide access to
41 /// ACCESS_FILESYSTEM and ACCESS_RESOURCES directory resources.
42 /// The implementation use jni in order to comply with Android filesystem
43 /// access restriction.
44 class DirAccessJAndroid : public DirAccessUnix {
45 GDSOFTCLASS(DirAccessJAndroid, DirAccessUnix);
46 static jobject dir_access_handler;
47 static jclass cls;
48
49 static jmethodID _dir_open;
50 static jmethodID _dir_next;
51 static jmethodID _dir_close;
52 static jmethodID _dir_is_dir;
53 static jmethodID _dir_exists;
54 static jmethodID _file_exists;
55 static jmethodID _get_drive_count;
56 static jmethodID _get_drive;
57 static jmethodID _make_dir;
58 static jmethodID _get_space_left;
59 static jmethodID _rename;
60 static jmethodID _remove;
61 static jmethodID _current_is_hidden;
62
63 public:
64 virtual Error list_dir_begin() override; ///< This starts dir listing
65 virtual String get_next() override;
66 virtual bool current_is_dir() const override;
67 virtual bool current_is_hidden() const override;
68 virtual void list_dir_end() override; ///<
69
70 virtual int get_drive_count() override;
71 virtual String get_drive(int p_drive) override;
72 virtual String get_current_dir(bool p_include_drive = true) const override; ///< return current dir location
73
74 virtual Error change_dir(String p_dir) override; ///< can be relative or absolute, return false on success
75
76 virtual bool file_exists(String p_file) override;
77 virtual bool dir_exists(String p_dir) override;
78
79 virtual Error make_dir(String p_dir) override;
80 virtual Error make_dir_recursive(const String &p_dir) override;
81
82 virtual Error rename(String p_from, String p_to) override;
83 virtual Error remove(String p_name) override;
84
85 virtual bool is_link(String p_file) override { return false; }
86 virtual String read_link(String p_file) override { return p_file; }
87 virtual Error create_link(String p_source, String p_target) override { return ERR_UNAVAILABLE; }
88
89 virtual uint64_t get_space_left() override;
90
91 static void setup(jobject p_dir_access_handler);
92 static void terminate();
93
94 DirAccessJAndroid();
95 ~DirAccessJAndroid();
96
97 protected:
98 String _get_root_string() const override;
99
100 private:
101 int id = 0;
102
103 int dir_open(String p_path);
104 void dir_close(int p_id);
105 String get_absolute_path(String p_path);
106 };