Make FileAccess and DirAccess classes reference counted.
This commit is contained in:
parent
ca9372622f
commit
9381acb6a4
193 changed files with 1122 additions and 1776 deletions
|
|
@ -42,7 +42,7 @@ jmethodID DirAccessJAndroid::_dir_next = nullptr;
|
|||
jmethodID DirAccessJAndroid::_dir_close = nullptr;
|
||||
jmethodID DirAccessJAndroid::_dir_is_dir = nullptr;
|
||||
|
||||
DirAccess *DirAccessJAndroid::create_fs() {
|
||||
Ref<DirAccess> DirAccessJAndroid::create_fs() {
|
||||
return memnew(DirAccessJAndroid);
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ Error DirAccessJAndroid::change_dir(String p_dir) {
|
|||
return OK;
|
||||
}
|
||||
|
||||
String DirAccessJAndroid::get_current_dir(bool p_include_drive) {
|
||||
String DirAccessJAndroid::get_current_dir(bool p_include_drive) const {
|
||||
return "res://" + current_dir;
|
||||
}
|
||||
|
||||
|
|
@ -155,9 +155,9 @@ bool DirAccessJAndroid::file_exists(String p_file) {
|
|||
sd = current_dir.plus_file(p_file);
|
||||
}
|
||||
|
||||
FileAccessAndroid *f = memnew(FileAccessAndroid);
|
||||
Ref<FileAccessAndroid> f;
|
||||
f.instantiate();
|
||||
bool exists = f->file_exists(sd);
|
||||
memdelete(f);
|
||||
|
||||
return exists;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class DirAccessJAndroid : public DirAccess {
|
|||
String current_dir;
|
||||
String current;
|
||||
|
||||
static DirAccess *create_fs();
|
||||
static Ref<DirAccess> create_fs();
|
||||
|
||||
public:
|
||||
virtual Error list_dir_begin(); ///< This starts dir listing
|
||||
|
|
@ -64,7 +64,7 @@ public:
|
|||
virtual String get_drive(int p_drive);
|
||||
|
||||
virtual Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
|
||||
virtual String get_current_dir(bool p_include_drive = true); ///< return current dir location
|
||||
virtual String get_current_dir(bool p_include_drive = true) const; ///< return current dir location
|
||||
|
||||
virtual bool file_exists(String p_file);
|
||||
virtual bool dir_exists(String p_dir);
|
||||
|
|
|
|||
|
|
@ -596,8 +596,8 @@ Vector<String> EditorExportPlatformAndroid::get_abis() {
|
|||
/// List the gdap files in the directory specified by the p_path parameter.
|
||||
Vector<String> EditorExportPlatformAndroid::list_gdap_files(const String &p_path) {
|
||||
Vector<String> dir_files;
|
||||
DirAccessRef da = DirAccess::open(p_path);
|
||||
if (da) {
|
||||
Ref<DirAccess> da = DirAccess::open(p_path);
|
||||
if (da.is_valid()) {
|
||||
da->list_dir_begin();
|
||||
while (true) {
|
||||
String file = da->get_next();
|
||||
|
|
@ -2008,7 +2008,7 @@ String EditorExportPlatformAndroid::get_apksigner_path() {
|
|||
|
||||
Error errn;
|
||||
String build_tools_dir = sdk_path.plus_file("build-tools");
|
||||
DirAccessRef da = DirAccess::open(build_tools_dir, &errn);
|
||||
Ref<DirAccess> da = DirAccess::open(build_tools_dir, &errn);
|
||||
if (errn != OK) {
|
||||
print_error("Unable to open Android 'build-tools' directory.");
|
||||
return apksigner_path;
|
||||
|
|
@ -2125,7 +2125,7 @@ bool EditorExportPlatformAndroid::can_export(const Ref<EditorExportPreset> &p_pr
|
|||
} else {
|
||||
Error errn;
|
||||
// Check for the platform-tools directory.
|
||||
DirAccessRef da = DirAccess::open(sdk_path.plus_file("platform-tools"), &errn);
|
||||
Ref<DirAccess> da = DirAccess::open(sdk_path.plus_file("platform-tools"), &errn);
|
||||
if (errn != OK) {
|
||||
err += TTR("Invalid Android SDK path in Editor Settings.");
|
||||
err += TTR("Missing 'platform-tools' directory!");
|
||||
|
|
@ -2143,7 +2143,7 @@ bool EditorExportPlatformAndroid::can_export(const Ref<EditorExportPreset> &p_pr
|
|||
}
|
||||
|
||||
// Check for the build-tools directory.
|
||||
DirAccessRef build_tools_da = DirAccess::open(sdk_path.plus_file("build-tools"), &errn);
|
||||
Ref<DirAccess> build_tools_da = DirAccess::open(sdk_path.plus_file("build-tools"), &errn);
|
||||
if (errn != OK) {
|
||||
err += TTR("Invalid Android SDK path in Editor Settings.");
|
||||
err += TTR("Missing 'build-tools' directory!");
|
||||
|
|
@ -2422,12 +2422,12 @@ Error EditorExportPlatformAndroid::sign_apk(const Ref<EditorExportPreset> &p_pre
|
|||
}
|
||||
|
||||
void EditorExportPlatformAndroid::_clear_assets_directory() {
|
||||
DirAccessRef da_res = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||
Ref<DirAccess> da_res = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||
|
||||
// Clear the APK assets directory
|
||||
if (da_res->dir_exists(APK_ASSETS_DIRECTORY)) {
|
||||
print_verbose("Clearing APK assets directory..");
|
||||
DirAccessRef da_assets = DirAccess::open(APK_ASSETS_DIRECTORY);
|
||||
Ref<DirAccess> da_assets = DirAccess::open(APK_ASSETS_DIRECTORY);
|
||||
da_assets->erase_contents_recursive();
|
||||
da_res->remove(APK_ASSETS_DIRECTORY);
|
||||
}
|
||||
|
|
@ -2435,7 +2435,7 @@ void EditorExportPlatformAndroid::_clear_assets_directory() {
|
|||
// Clear the AAB assets directory
|
||||
if (da_res->dir_exists(AAB_ASSETS_DIRECTORY)) {
|
||||
print_verbose("Clearing AAB assets directory..");
|
||||
DirAccessRef da_assets = DirAccess::open(AAB_ASSETS_DIRECTORY);
|
||||
Ref<DirAccess> da_assets = DirAccess::open(AAB_ASSETS_DIRECTORY);
|
||||
da_assets->erase_contents_recursive();
|
||||
da_res->remove(AAB_ASSETS_DIRECTORY);
|
||||
}
|
||||
|
|
@ -2455,7 +2455,7 @@ void EditorExportPlatformAndroid::_remove_copied_libs() {
|
|||
ERR_FAIL_COND_MSG(error, "Error parsing \"" + libs_json + "\" on line " + itos(json.get_error_line()) + ": " + json.get_error_message());
|
||||
|
||||
Vector<String> libs = json.get_data();
|
||||
DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||
for (int i = 0; i < libs.size(); i++) {
|
||||
print_verbose("Removing previously installed library " + libs[i]);
|
||||
da->remove(libs[i]);
|
||||
|
|
@ -2544,14 +2544,13 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
|
|||
//test that installed build version is alright
|
||||
{
|
||||
print_verbose("Checking build version..");
|
||||
FileAccessRef f = FileAccess::open("res://android/.build_version", FileAccess::READ);
|
||||
if (!f) {
|
||||
Ref<FileAccess> f = FileAccess::open("res://android/.build_version", FileAccess::READ);
|
||||
if (f.is_null()) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Trying to build from a custom built template, but no version info for it exists. Please reinstall from the 'Project' menu."));
|
||||
return ERR_UNCONFIGURED;
|
||||
}
|
||||
String version = f->get_line().strip_edges();
|
||||
print_verbose("- build version: " + version);
|
||||
f->close();
|
||||
if (version != VERSION_FULL_CONFIG) {
|
||||
EditorNode::get_singleton()->show_warning(vformat(TTR("Android build version mismatch:\n Template installed: %s\n Godot Version: %s\nPlease reinstall Android build template from 'Project' menu."), version, VERSION_FULL_CONFIG));
|
||||
return ERR_UNCONFIGURED;
|
||||
|
|
@ -2587,10 +2586,9 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
|
|||
return err;
|
||||
}
|
||||
if (user_data.libs.size() > 0) {
|
||||
FileAccessRef fa = FileAccess::open(GDNATIVE_LIBS_PATH, FileAccess::WRITE);
|
||||
Ref<FileAccess> fa = FileAccess::open(GDNATIVE_LIBS_PATH, FileAccess::WRITE);
|
||||
JSON json;
|
||||
fa->store_string(json.stringify(user_data.libs, "\t"));
|
||||
fa->close();
|
||||
}
|
||||
} else {
|
||||
print_verbose("Saving apk expansion file..");
|
||||
|
|
@ -2770,8 +2768,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
|
|||
return ERR_FILE_BAD_PATH;
|
||||
}
|
||||
|
||||
FileAccess *src_f = nullptr;
|
||||
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
|
||||
zlib_filefunc_def io = zipio_create_io();
|
||||
|
||||
if (ep.step(TTR("Creating APK..."), 0)) {
|
||||
return ERR_SKIP;
|
||||
|
|
@ -2785,9 +2782,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
|
|||
|
||||
int ret = unzGoToFirstFile(pkg);
|
||||
|
||||
zlib_filefunc_def io2 = io;
|
||||
FileAccess *dst_f = nullptr;
|
||||
io2.opaque = &dst_f;
|
||||
zlib_filefunc_def io2 = zipio_create_io();
|
||||
|
||||
String tmp_unaligned_path = EditorPaths::get_singleton()->get_cache_dir().plus_file("tmpexport-unaligned." + uitos(OS::get_singleton()->get_unix_time()) + ".apk");
|
||||
|
||||
|
|
@ -2983,9 +2978,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
|
|||
|
||||
ret = unzGoToFirstFile(tmp_unaligned);
|
||||
|
||||
io2 = io;
|
||||
dst_f = nullptr;
|
||||
io2.opaque = &dst_f;
|
||||
io2 = zipio_create_io();
|
||||
zipFile final_apk = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io2);
|
||||
|
||||
// Take files from the unaligned APK and write them out to the aligned one
|
||||
|
|
|
|||
|
|
@ -75,8 +75,8 @@ String _get_android_orientation_label(DisplayServer::ScreenOrientation screen_or
|
|||
// Utility method used to create a directory.
|
||||
Error create_directory(const String &p_dir) {
|
||||
if (!DirAccess::exists(p_dir)) {
|
||||
DirAccessRef filesystem_da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||
ERR_FAIL_COND_V_MSG(!filesystem_da, ERR_CANT_CREATE, "Cannot create directory '" + p_dir + "'.");
|
||||
Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||
ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create directory '" + p_dir + "'.");
|
||||
Error err = filesystem_da->make_dir_recursive(p_dir);
|
||||
ERR_FAIL_COND_V_MSG(err, ERR_CANT_CREATE, "Cannot create directory '" + p_dir + "'.");
|
||||
}
|
||||
|
|
@ -91,10 +91,9 @@ Error store_file_at_path(const String &p_path, const Vector<uint8_t> &p_data) {
|
|||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
FileAccess *fa = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
|
||||
Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
ERR_FAIL_COND_V_MSG(fa.is_null(), ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
|
||||
fa->store_buffer(p_data.ptr(), p_data.size());
|
||||
memdelete(fa);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
|
@ -109,10 +108,9 @@ Error store_string_at_path(const String &p_path, const String &p_data) {
|
|||
}
|
||||
return err;
|
||||
}
|
||||
FileAccess *fa = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
|
||||
Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
ERR_FAIL_COND_V_MSG(fa.is_null(), ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
|
||||
fa->store_string(p_data);
|
||||
memdelete(fa);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
|
@ -152,8 +150,8 @@ Error _create_project_name_strings_files(const Ref<EditorExportPreset> &p_preset
|
|||
store_string_at_path("res://android/build/res/values/godot_project_name_string.xml", processed_default_xml_string);
|
||||
|
||||
// Searches the Gradle project res/ directory to find all supported locales
|
||||
DirAccessRef da = DirAccess::open("res://android/build/res");
|
||||
if (!da) {
|
||||
Ref<DirAccess> da = DirAccess::open("res://android/build/res");
|
||||
if (da.is_null()) {
|
||||
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||
print_error("Unable to open Android resources directory.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
AAssetManager *FileAccessAndroid::asset_manager = nullptr;
|
||||
|
||||
FileAccess *FileAccessAndroid::create_android() {
|
||||
Ref<FileAccess> FileAccessAndroid::create_android() {
|
||||
return memnew(FileAccessAndroid);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
//#include <android_native_app_glue.h>
|
||||
|
||||
class FileAccessAndroid : public FileAccess {
|
||||
static FileAccess *create_android();
|
||||
static Ref<FileAccess> create_android();
|
||||
mutable AAsset *a = nullptr;
|
||||
mutable uint64_t len = 0;
|
||||
mutable uint64_t pos = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue