Make FileAccess and DirAccess classes reference counted.

This commit is contained in:
bruvzg
2022-03-23 11:08:58 +02:00
parent ca9372622f
commit 9381acb6a4
193 changed files with 1122 additions and 1776 deletions

View File

@ -36,7 +36,7 @@
#include <stdio.h>
Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8_t> &p_key, Mode p_mode, bool p_with_magic) {
Error FileAccessEncrypted::open_and_parse(Ref<FileAccess> p_base, const Vector<uint8_t> &p_key, Mode p_mode, bool p_with_magic) {
ERR_FAIL_COND_V_MSG(file != nullptr, ERR_ALREADY_IN_USE, "Can't open file while another file from path '" + file->get_path_absolute() + "' is open.");
ERR_FAIL_COND_V(p_key.size() != 32, ERR_INVALID_PARAMETER);
@ -99,7 +99,7 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
return OK;
}
Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base, const String &p_key, Mode p_mode) {
Error FileAccessEncrypted::open_and_parse_password(Ref<FileAccess> p_base, const String &p_key, Mode p_mode) {
String cs = p_key.md5_text();
ERR_FAIL_COND_V(cs.length() != 32, ERR_INVALID_PARAMETER);
Vector<uint8_t> key;
@ -116,26 +116,25 @@ Error FileAccessEncrypted::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessEncrypted::close() {
if (!file) {
if (file.is_null()) {
return;
}
_release();
file->close();
memdelete(file);
file = nullptr;
file = Ref<FileAccess>();
}
void FileAccessEncrypted::release() {
if (!file) {
if (file.is_null()) {
return;
}
_release();
file = nullptr;
file = Ref<FileAccess>();
}
void FileAccessEncrypted::_release() {
@ -183,7 +182,7 @@ bool FileAccessEncrypted::is_open() const {
}
String FileAccessEncrypted::get_path() const {
if (file) {
if (file.is_valid()) {
return file->get_path();
} else {
return "";
@ -191,7 +190,7 @@ String FileAccessEncrypted::get_path() const {
}
String FileAccessEncrypted::get_path_absolute() const {
if (file) {
if (file.is_valid()) {
return file->get_path_absolute();
} else {
return "";
@ -291,11 +290,10 @@ void FileAccessEncrypted::store_8(uint8_t p_dest) {
}
bool FileAccessEncrypted::file_exists(const String &p_name) {
FileAccess *fa = FileAccess::open(p_name, FileAccess::READ);
if (!fa) {
Ref<FileAccess> fa = FileAccess::open(p_name, FileAccess::READ);
if (fa.is_null()) {
return false;
}
memdelete(fa);
return true;
}
@ -313,7 +311,7 @@ Error FileAccessEncrypted::_set_unix_permissions(const String &p_file, uint32_t
}
FileAccessEncrypted::~FileAccessEncrypted() {
if (file) {
if (file.is_valid()) {
close();
}
}