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