diff options
Diffstat (limited to 'core/os/file_access.cpp')
-rw-r--r-- | core/os/file_access.cpp | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index cb8705f706..f31842bcae 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -43,7 +43,6 @@ FileAccess::FileCloseFailNotify FileAccess::close_fail_notify = nullptr; bool FileAccess::backup_save = false; FileAccess *FileAccess::create(AccessType p_access) { - ERR_FAIL_INDEX_V(p_access, ACCESS_MAX, nullptr); FileAccess *ret = create_func[p_access](); @@ -52,7 +51,6 @@ FileAccess *FileAccess::create(AccessType p_access) { } bool FileAccess::exists(const String &p_name) { - if (PackedData::get_singleton() && PackedData::get_singleton()->has_path(p_name)) return true; @@ -64,22 +62,17 @@ bool FileAccess::exists(const String &p_name) { } void FileAccess::_set_access_type(AccessType p_access) { - _access_type = p_access; }; FileAccess *FileAccess::create_for_path(const String &p_path) { - FileAccess *ret = nullptr; if (p_path.begins_with("res://")) { - ret = create(ACCESS_RESOURCES); } else if (p_path.begins_with("user://")) { - ret = create(ACCESS_USERDATA); } else { - ret = create(ACCESS_FILESYSTEM); } @@ -87,12 +80,10 @@ FileAccess *FileAccess::create_for_path(const String &p_path) { } Error FileAccess::reopen(const String &p_path, int p_mode_flags) { - return _open(p_path, p_mode_flags); }; FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_error) { - //try packed data first FileAccess *ret = nullptr; @@ -111,7 +102,6 @@ FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_er if (r_error) *r_error = err; if (err != OK) { - memdelete(ret); ret = nullptr; } @@ -120,7 +110,6 @@ FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_er } FileAccess::CreateFunc FileAccess::get_create_func(AccessType p_access) { - return create_func[p_access]; }; @@ -130,15 +119,11 @@ String FileAccess::fix_path(const String &p_path) const { String r_path = p_path.replace("\\", "/"); switch (_access_type) { - case ACCESS_RESOURCES: { - if (ProjectSettings::get_singleton()) { if (r_path.begins_with("res://")) { - String resource_path = ProjectSettings::get_singleton()->get_resource_path(); if (resource_path != "") { - return r_path.replace("res:/", resource_path); }; return r_path.replace("res://", ""); @@ -147,12 +132,9 @@ String FileAccess::fix_path(const String &p_path) const { } break; case ACCESS_USERDATA: { - if (r_path.begins_with("user://")) { - String data_dir = OS::get_singleton()->get_user_data_dir(); if (data_dir != "") { - return r_path.replace("user:/", data_dir); }; return r_path.replace("user://", ""); @@ -160,7 +142,6 @@ String FileAccess::fix_path(const String &p_path) const { } break; case ACCESS_FILESYSTEM: { - return r_path; } break; case ACCESS_MAX: @@ -173,7 +154,6 @@ String FileAccess::fix_path(const String &p_path) const { /* these are all implemented for ease of porting, then can later be optimized */ uint16_t FileAccess::get_16() const { - uint16_t res; uint8_t a, b; @@ -181,7 +161,6 @@ uint16_t FileAccess::get_16() const { b = get_8(); if (endian_swap) { - SWAP(a, b); } @@ -192,7 +171,6 @@ uint16_t FileAccess::get_16() const { return res; } uint32_t FileAccess::get_32() const { - uint32_t res; uint16_t a, b; @@ -200,7 +178,6 @@ uint32_t FileAccess::get_32() const { b = get_16(); if (endian_swap) { - SWAP(a, b); } @@ -211,7 +188,6 @@ uint32_t FileAccess::get_32() const { return res; } uint64_t FileAccess::get_64() const { - uint64_t res; uint32_t a, b; @@ -219,7 +195,6 @@ uint64_t FileAccess::get_64() const { b = get_32(); if (endian_swap) { - SWAP(a, b); } @@ -231,14 +206,12 @@ uint64_t FileAccess::get_64() const { } float FileAccess::get_float() const { - MarshallFloat m; m.i = get_32(); return m.f; }; real_t FileAccess::get_real() const { - if (real_is_double) return get_double(); else @@ -246,20 +219,17 @@ real_t FileAccess::get_real() const { } double FileAccess::get_double() const { - MarshallDouble m; m.l = get_64(); return m.d; }; String FileAccess::get_token() const { - CharString token; CharType c = get_8(); while (!eof_reached()) { - if (c <= ' ') { if (token.length()) break; @@ -281,16 +251,13 @@ class CharBuffer { int written = 0; bool grow() { - if (vector.resize(next_power_of_2(1 + written)) != OK) { - return false; } if (buffer == stack_buffer) { // first chunk? for (int i = 0; i < written; i++) { - vector.write[i] = stack_buffer[i]; } } @@ -309,9 +276,7 @@ public: } _FORCE_INLINE_ void push_back(char c) { - if (written >= capacity) { - ERR_FAIL_COND(!grow()); } @@ -319,19 +284,16 @@ public: } _FORCE_INLINE_ const char *get_data() const { - return buffer; } }; String FileAccess::get_line() const { - CharBuffer line; CharType c = get_8(); while (!eof_reached()) { - if (c == '\n' || c == '\0') { line.push_back(0); return String::utf8(line.get_data()); @@ -345,7 +307,6 @@ String FileAccess::get_line() const { } Vector<String> FileAccess::get_csv_line(const String &p_delim) const { - ERR_FAIL_COND_V(p_delim.length() != 1, Vector<String>()); String l; @@ -357,7 +318,6 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const { l += get_line() + "\n"; qc = 0; for (int i = 0; i < l.length(); i++) { - if (l[i] == '"') qc++; } @@ -371,7 +331,6 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const { bool in_quote = false; String current; for (int i = 0; i < l.length(); i++) { - CharType c = l[i]; CharType s[2] = { 0, 0 }; @@ -384,7 +343,6 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const { current += s; i++; } else { - in_quote = !in_quote; } } else { @@ -399,7 +357,6 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const { } int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const { - int i = 0; for (i = 0; i < p_length && !eof_reached(); i++) p_dst[i] = get_8(); @@ -425,14 +382,12 @@ String FileAccess::get_as_utf8_string() const { } void FileAccess::store_16(uint16_t p_dest) { - uint8_t a, b; a = p_dest & 0xFF; b = p_dest >> 8; if (endian_swap) { - SWAP(a, b); } @@ -440,14 +395,12 @@ void FileAccess::store_16(uint16_t p_dest) { store_8(b); } void FileAccess::store_32(uint32_t p_dest) { - uint16_t a, b; a = p_dest & 0xFFFF; b = p_dest >> 16; if (endian_swap) { - SWAP(a, b); } @@ -455,14 +408,12 @@ void FileAccess::store_32(uint32_t p_dest) { store_16(b); } void FileAccess::store_64(uint64_t p_dest) { - uint32_t a, b; a = p_dest & 0xFFFFFFFF; b = p_dest >> 32; if (endian_swap) { - SWAP(a, b); } @@ -471,7 +422,6 @@ void FileAccess::store_64(uint64_t p_dest) { } void FileAccess::store_real(real_t p_real) { - if (sizeof(real_t) == 4) store_float(p_real); else @@ -479,21 +429,18 @@ void FileAccess::store_real(real_t p_real) { } void FileAccess::store_float(float p_dest) { - MarshallFloat m; m.f = p_dest; store_32(m.i); }; void FileAccess::store_double(double p_dest) { - MarshallDouble m; m.d = p_dest; store_64(m.l); }; uint64_t FileAccess::get_modified_time(const String &p_file) { - if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) return 0; @@ -506,7 +453,6 @@ uint64_t FileAccess::get_modified_time(const String &p_file) { } uint32_t FileAccess::get_unix_permissions(const String &p_file) { - if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) return 0; @@ -519,7 +465,6 @@ uint32_t FileAccess::get_unix_permissions(const String &p_file) { } Error FileAccess::set_unix_permissions(const String &p_file, uint32_t p_permissions) { - FileAccess *fa = create_for_path(p_file); ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create FileAccess for path '" + p_file + "'."); @@ -529,7 +474,6 @@ Error FileAccess::set_unix_permissions(const String &p_file, uint32_t p_permissi } void FileAccess::store_string(const String &p_string) { - if (p_string.length() == 0) return; @@ -538,14 +482,12 @@ void FileAccess::store_string(const String &p_string) { } void FileAccess::store_pascal_string(const String &p_string) { - CharString cs = p_string.utf8(); store_32(cs.length()); store_buffer((uint8_t *)&cs[0], cs.length()); }; String FileAccess::get_pascal_string() { - uint32_t sl = get_32(); CharString cs; cs.resize(sl + 1); @@ -559,13 +501,11 @@ String FileAccess::get_pascal_string() { }; void FileAccess::store_line(const String &p_line) { - store_string(p_line); store_8('\n'); } void FileAccess::store_csv_line(const Vector<String> &p_values, const String &p_delim) { - ERR_FAIL_COND(p_delim.length() != 1); String line = ""; @@ -587,13 +527,11 @@ void FileAccess::store_csv_line(const Vector<String> &p_values, const String &p_ } void FileAccess::store_buffer(const uint8_t *p_src, int p_length) { - for (int i = 0; i < p_length; i++) store_8(p_src[i]); } Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_error) { - FileAccess *f = FileAccess::open(p_path, READ, r_error); if (!f) { if (r_error) { // if error requested, do not throw error @@ -609,7 +547,6 @@ Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_err } String FileAccess::get_file_as_string(const String &p_path, Error *r_error) { - Error err; Vector<uint8_t> array = get_file_as_array(p_path, &err); if (r_error) { @@ -628,7 +565,6 @@ String FileAccess::get_file_as_string(const String &p_path, Error *r_error) { } String FileAccess::get_md5(const String &p_file) { - FileAccess *f = FileAccess::open(p_file, READ); if (!f) return String(); @@ -639,10 +575,8 @@ String FileAccess::get_md5(const String &p_file) { unsigned char step[32768]; while (true) { - int br = f->get_buffer(step, 32768); if (br > 0) { - ctx.update(step, br); } if (br < 4096) @@ -658,7 +592,6 @@ String FileAccess::get_md5(const String &p_file) { } String FileAccess::get_multiple_md5(const Vector<String> &p_file) { - CryptoCore::MD5Context ctx; ctx.start(); @@ -669,10 +602,8 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) { unsigned char step[32768]; while (true) { - int br = f->get_buffer(step, 32768); if (br > 0) { - ctx.update(step, br); } if (br < 4096) @@ -688,7 +619,6 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) { } String FileAccess::get_sha256(const String &p_file) { - FileAccess *f = FileAccess::open(p_file, READ); if (!f) return String(); @@ -699,10 +629,8 @@ String FileAccess::get_sha256(const String &p_file) { unsigned char step[32768]; while (true) { - int br = f->get_buffer(step, 32768); if (br > 0) { - ctx.update(step, br); } if (br < 4096) |