summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/core_bind.cpp2
-rw-r--r--core/io/dir_access.cpp42
-rw-r--r--core/io/file_access.cpp2
-rw-r--r--core/io/file_access_compressed.cpp8
-rw-r--r--core/io/file_access_encrypted.cpp6
-rw-r--r--core/io/file_access_pack.cpp14
-rw-r--r--core/io/logger.cpp2
-rw-r--r--core/io/pck_packer.cpp4
-rw-r--r--core/io/resource_format_binary.cpp15
-rw-r--r--core/io/resource_uid.cpp2
-rw-r--r--core/os/os.cpp4
11 files changed, 56 insertions, 45 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index 7d8ec6064d..53c58084ac 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -1088,7 +1088,7 @@ void File::flush() {
void File::close() {
ERR_FAIL_COND_MSG(f.is_null(), "File must be opened.");
- f = Ref<FileAccess>();
+ f.unref();
}
bool File::is_open() const {
diff --git a/core/io/dir_access.cpp b/core/io/dir_access.cpp
index dd994fe2fb..433a7efb21 100644
--- a/core/io/dir_access.cpp
+++ b/core/io/dir_access.cpp
@@ -275,27 +275,29 @@ String DirAccess::get_full_path(const String &p_path, AccessType p_access) {
Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
//printf("copy %s -> %s\n",p_from.ascii().get_data(),p_to.ascii().get_data());
Error err;
- Ref<FileAccess> fsrc = FileAccess::open(p_from, FileAccess::READ, &err);
- ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to open " + p_from);
-
- Ref<FileAccess> fdst = FileAccess::open(p_to, FileAccess::WRITE, &err);
- ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to open " + p_to);
-
- fsrc->seek_end(0);
- int size = fsrc->get_position();
- fsrc->seek(0);
- err = OK;
- while (size--) {
- if (fsrc->get_error() != OK) {
- err = fsrc->get_error();
- break;
- }
- if (fdst->get_error() != OK) {
- err = fdst->get_error();
- break;
- }
+ {
+ Ref<FileAccess> fsrc = FileAccess::open(p_from, FileAccess::READ, &err);
+ ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to open " + p_from);
+
+ Ref<FileAccess> fdst = FileAccess::open(p_to, FileAccess::WRITE, &err);
+ ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to open " + p_to);
+
+ fsrc->seek_end(0);
+ int size = fsrc->get_position();
+ fsrc->seek(0);
+ err = OK;
+ while (size--) {
+ if (fsrc->get_error() != OK) {
+ err = fsrc->get_error();
+ break;
+ }
+ if (fdst->get_error() != OK) {
+ err = fdst->get_error();
+ break;
+ }
- fdst->store_8(fsrc->get_8());
+ fdst->store_8(fsrc->get_8());
+ }
}
if (err == OK && p_chmod_flags != -1) {
diff --git a/core/io/file_access.cpp b/core/io/file_access.cpp
index 87c10074af..7d8da1b11c 100644
--- a/core/io/file_access.cpp
+++ b/core/io/file_access.cpp
@@ -105,7 +105,7 @@ Ref<FileAccess> FileAccess::open(const String &p_path, int p_mode_flags, Error *
*r_error = err;
}
if (err != OK) {
- ret = Ref<FileAccess>();
+ ret.unref();
}
return ret;
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index 0c961ba8fb..ebd729cc64 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -63,7 +63,7 @@ Error FileAccessCompressed::open_after_magic(Ref<FileAccess> p_base) {
cmode = (Compression::Mode)f->get_32();
block_size = f->get_32();
if (block_size == 0) {
- f = Ref<FileAccess>();
+ f.unref();
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Can't open compressed file '" + p_base->get_path() + "' with block size 0, it is corrupted.");
}
read_total = f->get_32();
@@ -106,7 +106,7 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
f = FileAccess::open(p_path, p_mode_flags, &err);
if (err != OK) {
//not openable
- f = Ref<FileAccess>();
+ f.unref();
return err;
}
@@ -126,7 +126,7 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
rmagic[4] = 0;
err = ERR_FILE_UNRECOGNIZED;
if (magic != rmagic || (err = open_after_magic(f)) != OK) {
- f = Ref<FileAccess>();
+ f.unref();
return err;
}
}
@@ -180,7 +180,7 @@ void FileAccessCompressed::close() {
buffer.clear();
read_blocks.clear();
}
- f = Ref<FileAccess>();
+ f.unref();
}
bool FileAccessCompressed::is_open() const {
diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp
index 2443e2bea0..5d44ff3f10 100644
--- a/core/io/file_access_encrypted.cpp
+++ b/core/io/file_access_encrypted.cpp
@@ -122,9 +122,7 @@ void FileAccessEncrypted::close() {
_release();
- file->close();
-
- file = Ref<FileAccess>();
+ file.unref();
}
void FileAccessEncrypted::release() {
@@ -134,7 +132,7 @@ void FileAccessEncrypted::release() {
_release();
- file = Ref<FileAccess>();
+ file.unref();
}
void FileAccessEncrypted::_release() {
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index 0b8deb8ec2..1254ecbca9 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -227,14 +227,20 @@ Error FileAccessPack::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessPack::close() {
- f->close();
+ f.unref();
}
bool FileAccessPack::is_open() const {
- return f->is_open();
+ if (f.is_valid()) {
+ return f->is_open();
+ } else {
+ return false;
+ }
}
void FileAccessPack::seek(uint64_t p_position) {
+ ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use.");
+
if (p_position > pf.size) {
eof = true;
} else {
@@ -262,6 +268,7 @@ bool FileAccessPack::eof_reached() const {
}
uint8_t FileAccessPack::get_8() const {
+ ERR_FAIL_COND_V_MSG(f.is_null(), 0, "File must be opened before use.");
if (pos >= pf.size) {
eof = true;
return 0;
@@ -272,6 +279,7 @@ uint8_t FileAccessPack::get_8() const {
}
uint64_t FileAccessPack::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
+ ERR_FAIL_COND_V_MSG(f.is_null(), -1, "File must be opened before use.");
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
if (eof) {
@@ -295,6 +303,8 @@ uint64_t FileAccessPack::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
}
void FileAccessPack::set_big_endian(bool p_big_endian) {
+ ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use.");
+
FileAccess::set_big_endian(p_big_endian);
f->set_big_endian(p_big_endian);
}
diff --git a/core/io/logger.cpp b/core/io/logger.cpp
index 0caa2af5c4..c19fc2820b 100644
--- a/core/io/logger.cpp
+++ b/core/io/logger.cpp
@@ -148,7 +148,7 @@ void RotatedFileLogger::clear_old_backups() {
}
void RotatedFileLogger::rotate_file() {
- file = Ref<FileAccess>();
+ file.unref();
if (FileAccess::exists(base_path)) {
if (max_files > 1) {
diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp
index d1a305e836..6240370504 100644
--- a/core/io/pck_packer.cpp
+++ b/core/io/pck_packer.cpp
@@ -216,7 +216,7 @@ Error PCKPacker::flush(bool p_verbose) {
Ref<FileAccess> src = FileAccess::open(files[i].src_path, FileAccess::READ);
uint64_t to_write = files[i].size;
- fae = Ref<FileAccess>();
+ fae.unref();
Ref<FileAccess> ftmp = file;
if (files[i].encrypted) {
fae.instantiate();
@@ -253,7 +253,7 @@ Error PCKPacker::flush(bool p_verbose) {
printf("\n");
}
- file = Ref<FileAccess>();
+ file.unref();
memdelete_arr(buf);
return OK;
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 87e4a01819..8d4dbc3f73 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -789,7 +789,7 @@ Error ResourceLoaderBinary::load() {
resource_cache.push_back(res);
if (main) {
- f = Ref<FileAccess>();
+ f.unref();
resource = res;
resource->set_as_translation_remapped(translation_remapped);
error = OK;
@@ -868,7 +868,7 @@ void ResourceLoaderBinary::open(Ref<FileAccess> p_f, bool p_no_resources, bool p
fac.instantiate();
error = fac->open_after_magic(f);
if (error != OK) {
- f = Ref<FileAccess>();
+ f.unref();
ERR_FAIL_MSG("Failed to open binary resource file: " + local_path + ".");
}
f = fac;
@@ -876,7 +876,7 @@ void ResourceLoaderBinary::open(Ref<FileAccess> p_f, bool p_no_resources, bool p
} else if (header[0] != 'R' || header[1] != 'S' || header[2] != 'R' || header[3] != 'C') {
// Not normal.
error = ERR_FILE_UNRECOGNIZED;
- f = Ref<FileAccess>();
+ f.unref();
ERR_FAIL_MSG("Unrecognized binary resource file: " + local_path + ".");
}
@@ -901,7 +901,7 @@ void ResourceLoaderBinary::open(Ref<FileAccess> p_f, bool p_no_resources, bool p
print_bl("format: " + itos(ver_format));
if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
- f = Ref<FileAccess>();
+ f.unref();
ERR_FAIL_MSG(vformat("File '%s' can't be loaded, as it uses a format version (%d) or engine version (%d.%d) which are not supported by your engine version (%s).",
local_path, ver_format, ver_major, ver_minor, VERSION_BRANCH));
}
@@ -978,6 +978,7 @@ void ResourceLoaderBinary::open(Ref<FileAccess> p_f, bool p_no_resources, bool p
if (f->eof_reached()) {
error = ERR_FILE_CORRUPT;
+ f.unref();
ERR_FAIL_MSG("Premature end of file (EOF): " + local_path + ".");
}
}
@@ -994,7 +995,7 @@ String ResourceLoaderBinary::recognize(Ref<FileAccess> p_f) {
fac.instantiate();
error = fac->open_after_magic(f);
if (error != OK) {
- f = Ref<FileAccess>();
+ f.unref();
return "";
}
f = fac;
@@ -1002,7 +1003,7 @@ String ResourceLoaderBinary::recognize(Ref<FileAccess> p_f) {
} else if (header[0] != 'R' || header[1] != 'S' || header[2] != 'R' || header[3] != 'C') {
// Not normal.
error = ERR_FILE_UNRECOGNIZED;
- f = Ref<FileAccess>();
+ f.unref();
return "";
}
@@ -1016,7 +1017,7 @@ String ResourceLoaderBinary::recognize(Ref<FileAccess> p_f) {
uint32_t ver_format = f->get_32();
if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
- f = Ref<FileAccess>();
+ f.unref();
return "";
}
diff --git a/core/io/resource_uid.cpp b/core/io/resource_uid.cpp
index 8f1f354e90..515b7c710e 100644
--- a/core/io/resource_uid.cpp
+++ b/core/io/resource_uid.cpp
@@ -220,7 +220,7 @@ Error ResourceUID::update_cache() {
}
}
- if (f != nullptr) {
+ if (f.is_valid()) {
f->seek(0);
f->store_32(cache_entries); //update amount of entries
}
diff --git a/core/os/os.cpp b/core/os/os.cpp
index bf6cd4c9ab..846aeb16c5 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -201,14 +201,14 @@ void OS::print_all_resources(String p_to_file) {
Error err;
_OSPRF = FileAccess::open(p_to_file, FileAccess::WRITE, &err);
if (err != OK) {
- _OSPRF = Ref<FileAccess>();
+ _OSPRF.unref();
ERR_FAIL_MSG("Can't print all resources to file: " + String(p_to_file) + ".");
}
}
ObjectDB::debug_objects(_OS_printres);
- _OSPRF = Ref<FileAccess>();
+ _OSPRF.unref();
}
void OS::print_resources_in_use(bool p_short) {