diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/io/file_access.h | 1 | ||||
-rw-r--r-- | core/io/file_access_compressed.cpp | 11 | ||||
-rw-r--r-- | core/io/file_access_compressed.h | 3 | ||||
-rw-r--r-- | core/io/file_access_encrypted.cpp | 24 | ||||
-rw-r--r-- | core/io/file_access_encrypted.h | 4 | ||||
-rw-r--r-- | core/io/file_access_memory.cpp | 4 | ||||
-rw-r--r-- | core/io/file_access_memory.h | 1 | ||||
-rw-r--r-- | core/io/file_access_network.cpp | 9 | ||||
-rw-r--r-- | core/io/file_access_network.h | 2 | ||||
-rw-r--r-- | core/io/file_access_pack.cpp | 4 | ||||
-rw-r--r-- | core/io/file_access_pack.h | 1 | ||||
-rw-r--r-- | core/io/file_access_zip.cpp | 6 | ||||
-rw-r--r-- | core/io/file_access_zip.h | 3 | ||||
-rw-r--r-- | core/io/pck_packer.cpp | 7 |
14 files changed, 24 insertions, 56 deletions
diff --git a/core/io/file_access.h b/core/io/file_access.h index 60abfe3c5e..e2c11142d7 100644 --- a/core/io/file_access.h +++ b/core/io/file_access.h @@ -88,7 +88,6 @@ public: WRITE_READ = 7, }; - virtual void close() = 0; ///< close a file virtual bool is_open() const = 0; ///< true when file is open virtual String get_path() const { return ""; } /// returns the path for the current open file diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index ebd729cc64..1d0a718166 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -97,10 +97,7 @@ Error FileAccessCompressed::open_after_magic(Ref<FileAccess> p_base) { Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { ERR_FAIL_COND_V(p_mode_flags == READ_WRITE, ERR_UNAVAILABLE); - - if (f.is_valid()) { - close(); - } + _close(); Error err; f = FileAccess::open(p_path, p_mode_flags, &err); @@ -134,7 +131,7 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { return OK; } -void FileAccessCompressed::close() { +void FileAccessCompressed::_close() { if (f.is_null()) { return; } @@ -373,7 +370,5 @@ Error FileAccessCompressed::_set_unix_permissions(const String &p_file, uint32_t } FileAccessCompressed::~FileAccessCompressed() { - if (f.is_valid()) { - close(); - } + _close(); } diff --git a/core/io/file_access_compressed.h b/core/io/file_access_compressed.h index cd28c576cf..b8382e61d9 100644 --- a/core/io/file_access_compressed.h +++ b/core/io/file_access_compressed.h @@ -63,13 +63,14 @@ class FileAccessCompressed : public FileAccess { mutable Vector<uint8_t> buffer; Ref<FileAccess> f; + void _close(); + public: void configure(const String &p_magic, Compression::Mode p_mode = Compression::MODE_ZSTD, uint32_t p_block_size = 4096); Error open_after_magic(Ref<FileAccess> p_base); virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file - virtual void close(); ///< close a file virtual bool is_open() const; ///< true when file is open virtual void seek(uint64_t p_position); ///< seek to a given position diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index 5d44ff3f10..d1b014a0be 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -115,27 +115,11 @@ Error FileAccessEncrypted::_open(const String &p_path, int p_mode_flags) { return OK; } -void FileAccessEncrypted::close() { +void FileAccessEncrypted::_close() { if (file.is_null()) { return; } - _release(); - - file.unref(); -} - -void FileAccessEncrypted::release() { - if (file.is_null()) { - return; - } - - _release(); - - file.unref(); -} - -void FileAccessEncrypted::_release() { if (writing) { Vector<uint8_t> compressed; uint64_t len = data.size(); @@ -173,6 +157,8 @@ void FileAccessEncrypted::_release() { file->store_buffer(compressed.ptr(), compressed.size()); data.clear(); } + + file.unref(); } bool FileAccessEncrypted::is_open() const { @@ -309,7 +295,5 @@ Error FileAccessEncrypted::_set_unix_permissions(const String &p_file, uint32_t } FileAccessEncrypted::~FileAccessEncrypted() { - if (file.is_valid()) { - close(); - } + _close(); } diff --git a/core/io/file_access_encrypted.h b/core/io/file_access_encrypted.h index 5d0b369fbf..0d1ee6a4d8 100644 --- a/core/io/file_access_encrypted.h +++ b/core/io/file_access_encrypted.h @@ -54,15 +54,13 @@ private: mutable bool eofed = false; bool use_magic = true; - void _release(); + void _close(); public: Error open_and_parse(Ref<FileAccess> p_base, const Vector<uint8_t> &p_key, Mode p_mode, bool p_with_magic = true); Error open_and_parse_password(Ref<FileAccess> p_base, const String &p_key, Mode p_mode); virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file - virtual void close(); ///< close a file - virtual void release(); ///< finish and keep base file open virtual bool is_open() const; ///< true when file is open virtual String get_path() const; /// returns the path for the current open file diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index 62da51b09f..943dc72307 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -94,10 +94,6 @@ Error FileAccessMemory::_open(const String &p_path, int p_mode_flags) { return OK; } -void FileAccessMemory::close() { - data = nullptr; -} - bool FileAccessMemory::is_open() const { return data != nullptr; } diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h index baaad5f086..868b8ed481 100644 --- a/core/io/file_access_memory.h +++ b/core/io/file_access_memory.h @@ -46,7 +46,6 @@ public: virtual Error open_custom(const uint8_t *p_data, uint64_t p_len); ///< open a file virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file - virtual void close(); ///< close a file virtual bool is_open() const; ///< true when file is open virtual void seek(uint64_t p_position); ///< seek to a given position diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 612181f8d5..1365b4b593 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -254,9 +254,8 @@ void FileAccessNetwork::_respond(uint64_t p_len, Error p_status) { Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) { ERR_FAIL_COND_V(p_mode_flags != READ, ERR_UNAVAILABLE); - if (opened) { - close(); - } + _close(); + FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; DEBUG_PRINT("open: " + p_path); @@ -287,7 +286,7 @@ Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) { return response; } -void FileAccessNetwork::close() { +void FileAccessNetwork::_close() { if (!opened) { return; } @@ -483,7 +482,7 @@ FileAccessNetwork::FileAccessNetwork() { } FileAccessNetwork::~FileAccessNetwork() { - close(); + _close(); FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; nc->lock_mutex(); diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h index 6cae49b540..6afbf6adf5 100644 --- a/core/io/file_access_network.h +++ b/core/io/file_access_network.h @@ -113,6 +113,7 @@ class FileAccessNetwork : public FileAccess { void _queue_page(int32_t p_page) const; void _respond(uint64_t p_len, Error p_status); void _set_block(uint64_t p_offset, const Vector<uint8_t> &p_block); + void _close(); public: enum Command { @@ -131,7 +132,6 @@ public: }; virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file - virtual void close(); ///< close a file virtual bool is_open() const; ///< true when file is open virtual void seek(uint64_t p_position); ///< seek to a given position diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index 1254ecbca9..c6e14ffee7 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -226,10 +226,6 @@ Error FileAccessPack::_open(const String &p_path, int p_mode_flags) { return ERR_UNAVAILABLE; } -void FileAccessPack::close() { - f.unref(); -} - bool FileAccessPack::is_open() const { if (f.is_valid()) { return f->is_open(); diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index 399b345b35..44df2029bd 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -157,7 +157,6 @@ class FileAccessPack : public FileAccess { virtual Error _set_unix_permissions(const String &p_file, uint32_t p_permissions) { return FAILED; } public: - virtual void close(); virtual bool is_open() const; virtual void seek(uint64_t p_position); diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index 1caff2dc02..17f2335a8e 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -235,7 +235,7 @@ ZipArchive::~ZipArchive() { } Error FileAccessZip::_open(const String &p_path, int p_mode_flags) { - close(); + _close(); ERR_FAIL_COND_V(p_mode_flags & FileAccess::WRITE, FAILED); ZipArchive *arch = ZipArchive::get_singleton(); @@ -249,7 +249,7 @@ Error FileAccessZip::_open(const String &p_path, int p_mode_flags) { return OK; } -void FileAccessZip::close() { +void FileAccessZip::_close() { if (!zfile) { return; } @@ -341,7 +341,7 @@ FileAccessZip::FileAccessZip(const String &p_path, const PackedData::PackedFile } FileAccessZip::~FileAccessZip() { - close(); + _close(); } #endif // MINIZIP_ENABLED diff --git a/core/io/file_access_zip.h b/core/io/file_access_zip.h index f6249add4b..2504aeedc4 100644 --- a/core/io/file_access_zip.h +++ b/core/io/file_access_zip.h @@ -82,9 +82,10 @@ class FileAccessZip : public FileAccess { mutable bool at_eof; + void _close(); + public: virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file - virtual void close(); ///< close a file virtual bool is_open() const; ///< true when file is open virtual void seek(uint64_t p_position); ///< seek to a given position diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp index 6240370504..aa1b323db2 100644 --- a/core/io/pck_packer.cpp +++ b/core/io/pck_packer.cpp @@ -195,7 +195,8 @@ Error PCKPacker::flush(bool p_verbose) { } if (fae.is_valid()) { - fae->release(); + fhead.unref(); + fae.unref(); } int header_padding = _get_pad(alignment, file->get_position()); @@ -216,7 +217,6 @@ 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.unref(); Ref<FileAccess> ftmp = file; if (files[i].encrypted) { fae.instantiate(); @@ -234,7 +234,8 @@ Error PCKPacker::flush(bool p_verbose) { } if (fae.is_valid()) { - fae->release(); + ftmp.unref(); + fae.unref(); } int pad = _get_pad(alignment, file->get_position()); |