dir_access_jandroid.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #ifndef DIR_ACCESS_JANDROID_H
  31. #define DIR_ACCESS_JANDROID_H
  32. #include "java_godot_lib_jni.h"
  33. #include "core/io/dir_access.h"
  34. #include "drivers/unix/dir_access_unix.h"
  35. #include <stdio.h>
  36. /// Android implementation of the DirAccess interface used to provide access to
  37. /// ACCESS_FILESYSTEM and ACCESS_RESOURCES directory resources.
  38. /// The implementation use jni in order to comply with Android filesystem
  39. /// access restriction.
  40. class DirAccessJAndroid : public DirAccessUnix {
  41. static jobject dir_access_handler;
  42. static jclass cls;
  43. static jmethodID _dir_open;
  44. static jmethodID _dir_next;
  45. static jmethodID _dir_close;
  46. static jmethodID _dir_is_dir;
  47. static jmethodID _dir_exists;
  48. static jmethodID _file_exists;
  49. static jmethodID _get_drive_count;
  50. static jmethodID _get_drive;
  51. static jmethodID _make_dir;
  52. static jmethodID _get_space_left;
  53. static jmethodID _rename;
  54. static jmethodID _remove;
  55. static jmethodID _current_is_hidden;
  56. public:
  57. virtual Error list_dir_begin() override; ///< This starts dir listing
  58. virtual String get_next() override;
  59. virtual bool current_is_dir() const override;
  60. virtual bool current_is_hidden() const override;
  61. virtual void list_dir_end() override; ///<
  62. virtual int get_drive_count() override;
  63. virtual String get_drive(int p_drive) override;
  64. virtual String get_current_dir(bool p_include_drive = true) const override; ///< return current dir location
  65. virtual Error change_dir(String p_dir) override; ///< can be relative or absolute, return false on success
  66. virtual bool file_exists(String p_file) override;
  67. virtual bool dir_exists(String p_dir) override;
  68. virtual Error make_dir(String p_dir) override;
  69. virtual Error make_dir_recursive(const String &p_dir) override;
  70. virtual Error rename(String p_from, String p_to) override;
  71. virtual Error remove(String p_name) override;
  72. virtual bool is_link(String p_file) override { return false; }
  73. virtual String read_link(String p_file) override { return p_file; }
  74. virtual Error create_link(String p_source, String p_target) override { return ERR_UNAVAILABLE; }
  75. virtual uint64_t get_space_left() override;
  76. static void setup(jobject p_dir_access_handler);
  77. static void terminate();
  78. DirAccessJAndroid();
  79. ~DirAccessJAndroid();
  80. protected:
  81. String _get_root_string() const override;
  82. private:
  83. int id = 0;
  84. int dir_open(String p_path);
  85. void dir_close(int p_id);
  86. String get_absolute_path(String p_path);
  87. };
  88. #endif // DIR_ACCESS_JANDROID_H