2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* dir_access_android.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:11:45 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-08 00:45:00 +02:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifdef ANDROID_NATIVE_ACTIVITY
|
|
|
|
#include "dir_access_android.h"
|
|
|
|
#include "file_access_android.h"
|
|
|
|
|
|
|
|
DirAccess *DirAccessAndroid::create_fs() {
|
|
|
|
|
|
|
|
return memnew(DirAccessAndroid);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DirAccessAndroid::list_dir_begin() {
|
|
|
|
|
|
|
|
list_dir_end();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
AAssetDir *aad = AAssetManager_openDir(FileAccessAndroid::asset_manager, current_dir.utf8().get_data());
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!aad)
|
|
|
|
return true; //nothing
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String DirAccessAndroid::get_next() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
const char *fn = AAssetDir_getNextFileName(aad);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!fn)
|
|
|
|
return "";
|
|
|
|
String s;
|
|
|
|
s.parse_utf8(fn);
|
2017-03-19 00:36:26 +01:00
|
|
|
current = s;
|
2014-02-10 02:10:30 +01:00
|
|
|
return s;
|
|
|
|
}
|
2016-07-21 12:07:01 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool DirAccessAndroid::current_is_dir() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String sd;
|
2017-03-19 00:36:26 +01:00
|
|
|
if (current_dir == "")
|
|
|
|
sd = current;
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
2017-03-19 00:36:26 +01:00
|
|
|
sd = current_dir + "/" + current;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
AAssetDir *aad2 = AAssetManager_openDir(FileAccessAndroid::asset_manager, sd.utf8().get_data());
|
2014-02-10 02:10:30 +01:00
|
|
|
if (aad2) {
|
|
|
|
|
|
|
|
AAssetDir_close(aad2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-21 12:07:01 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool DirAccessAndroid::current_is_hidden() const {
|
|
|
|
return current != "." && current != ".." && current.begins_with(".");
|
2015-03-21 18:33:32 +01:00
|
|
|
}
|
2016-07-21 12:07:01 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void DirAccessAndroid::list_dir_end() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (aad == NULL)
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
AAssetDir_close(aad);
|
2017-03-19 00:36:26 +01:00
|
|
|
aad = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int DirAccessAndroid::get_drive_count() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-07-21 12:07:01 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String DirAccessAndroid::get_drive(int p_drive) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Error DirAccessAndroid::change_dir(String p_dir) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
p_dir = p_dir.simplify_path();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_dir == "" || p_dir == "." || (p_dir == ".." && current_dir == ""))
|
2014-02-10 02:10:30 +01:00
|
|
|
return OK;
|
|
|
|
|
|
|
|
String new_dir;
|
|
|
|
|
|
|
|
if (p_dir.begins_with("/"))
|
2017-03-19 00:36:26 +01:00
|
|
|
new_dir = p_dir.substr(1, p_dir.length());
|
2014-02-10 02:10:30 +01:00
|
|
|
else if (p_dir.begins_with("res://"))
|
2017-03-19 00:36:26 +01:00
|
|
|
new_dir = p_dir.substr(6, p_dir.length());
|
|
|
|
else //relative
|
|
|
|
new_dir = new_dir + "/" + p_dir;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
//test if newdir exists
|
|
|
|
new_dir = new_dir.simplify_path();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
AAssetDir *aad = AAssetManager_openDir(FileAccessAndroid::asset_manager, new_dir.utf8().get_data());
|
2014-02-10 02:10:30 +01:00
|
|
|
if (aad) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
current_dir = new_dir;
|
2014-02-10 02:10:30 +01:00
|
|
|
AAssetDir_close(aad);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String DirAccessAndroid::get_current_dir() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
return "/" + current_dir;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool DirAccessAndroid::file_exists(String p_file) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String sd;
|
2017-03-19 00:36:26 +01:00
|
|
|
if (current_dir == "")
|
|
|
|
sd = p_file;
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
2017-03-19 00:36:26 +01:00
|
|
|
sd = current_dir + "/" + p_file;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
AAsset *a = AAssetManager_open(FileAccessAndroid::asset_manager, sd.utf8().get_data(), AASSET_MODE_STREAMING);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (a) {
|
|
|
|
AAsset_close(a);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Error DirAccessAndroid::make_dir(String p_dir) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ERR_FAIL_V(ERR_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Error DirAccessAndroid::rename(String p_from, String p_to) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ERR_FAIL_V(ERR_UNAVAILABLE);
|
|
|
|
}
|
2016-07-21 12:07:01 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Error DirAccessAndroid::remove(String p_name) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ERR_FAIL_V(ERR_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
//FileType get_file_type() const;
|
|
|
|
size_t DirAccessAndroid::get_space_left() {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirAccessAndroid::make_default() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
instance_func = create_fs;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DirAccessAndroid::DirAccessAndroid() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
aad = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DirAccessAndroid::~DirAccessAndroid() {
|
|
|
|
|
2017-01-14 18:03:38 +01:00
|
|
|
list_dir_end();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
#endif
|