diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-19 15:33:24 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-19 15:33:24 +0200 |
commit | ec60c4ee9e5d5a4452bf43cba44d4fefa56261da (patch) | |
tree | 27ac3f38ae4c8c5f18167a482441a54dfdd38662 /core/io/file_access.h | |
parent | 4ebf7d14ac5e9b0c6c86535cb7bb5e428f00542a (diff) | |
parent | 9f2dc68279761bb5c4ed569ba4fcae002facd810 (diff) |
Merge pull request #65271 from KoBeWi/FirAccess🌲
Replace File/Directory with FileAccess/DirAccess
Diffstat (limited to 'core/io/file_access.h')
-rw-r--r-- | core/io/file_access.h | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/core/io/file_access.h b/core/io/file_access.h index fc0eb95d44..f8c42d3c0d 100644 --- a/core/io/file_access.h +++ b/core/io/file_access.h @@ -31,6 +31,7 @@ #ifndef FILE_ACCESS_H #define FILE_ACCESS_H +#include "core/io/compression.h" #include "core/math/math_defs.h" #include "core/object/ref_counted.h" #include "core/os/memory.h" @@ -42,6 +43,8 @@ */ class FileAccess : public RefCounted { + GDCLASS(FileAccess, RefCounted); + public: enum AccessType { ACCESS_RESOURCES, @@ -60,15 +63,18 @@ public: virtual Error _set_unix_permissions(const String &p_file, uint32_t p_permissions) = 0; protected: + static void _bind_methods(); + AccessType get_access_type() const; String fix_path(const String &p_path) const; - virtual Error _open(const String &p_path, int p_mode_flags) = 0; ///< open a file + virtual Error open_internal(const String &p_path, int p_mode_flags) = 0; ///< open a file virtual uint64_t _get_modified_time(const String &p_file) = 0; static FileCloseFailNotify close_fail_notify; private: static bool backup_save; + thread_local static Error last_file_open_error; AccessType _access_type = ACCESS_FILESYSTEM; static CreateFunc create_func[ACCESS_MAX]; /** default file access creation function for a platform */ @@ -89,6 +95,13 @@ public: WRITE_READ = 7, }; + enum CompressionMode { + COMPRESSION_FASTLZ = Compression::MODE_FASTLZ, + COMPRESSION_DEFLATE = Compression::MODE_DEFLATE, + COMPRESSION_ZSTD = Compression::MODE_ZSTD, + COMPRESSION_GZIP = Compression::MODE_GZIP + }; + 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 @@ -110,10 +123,14 @@ public: virtual double get_double() const; virtual real_t get_real() const; + Variant get_var(bool p_allow_objects = false) const; + virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const; ///< get an array of bytes + Vector<uint8_t> _get_buffer(int64_t p_length) const; virtual String get_line() const; virtual String get_token() const; virtual Vector<String> get_csv_line(const String &p_delim = ",") const; + String get_as_text(bool p_skip_cr = false) const; virtual String get_as_utf8_string(bool p_skip_cr = false) const; /** @@ -144,6 +161,9 @@ public: virtual String get_pascal_string(); virtual void store_buffer(const uint8_t *p_src, uint64_t p_length); ///< store an array of bytes + void _store_buffer(const Vector<uint8_t> &p_buffer); + + void store_var(const Variant &p_var, bool p_full_objects = false); virtual bool file_exists(const String &p_name) = 0; ///< return true if a file exists @@ -152,6 +172,13 @@ public: static Ref<FileAccess> create(AccessType p_access); /// Create a file access (for the current platform) this is the only portable way of accessing files. static Ref<FileAccess> create_for_path(const String &p_path); static Ref<FileAccess> open(const String &p_path, int p_mode_flags, Error *r_error = nullptr); /// Create a file access (for the current platform) this is the only portable way of accessing files. + + static Ref<FileAccess> _open(const String &p_path, ModeFlags p_mode_flags); + static Ref<FileAccess> open_encrypted(const String &p_path, ModeFlags p_mode_flags, const Vector<uint8_t> &p_key); + static Ref<FileAccess> open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, const String &p_pass); + static Ref<FileAccess> open_compressed(const String &p_path, ModeFlags p_mode_flags, CompressionMode p_compress_mode = COMPRESSION_FASTLZ); + static Error get_open_error(); + static CreateFunc get_create_func(AccessType p_access); static bool exists(const String &p_name); ///< return true if a file exists static uint64_t get_modified_time(const String &p_file); @@ -177,4 +204,7 @@ public: virtual ~FileAccess() {} }; +VARIANT_ENUM_CAST(FileAccess::CompressionMode); +VARIANT_ENUM_CAST(FileAccess::ModeFlags); + #endif // FILE_ACCESS_H |