diff options
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/file_access_buffered.cpp | 12 | ||||
-rw-r--r-- | core/io/file_access_buffered.h | 2 | ||||
-rw-r--r-- | core/io/file_access_memory.h | 2 | ||||
-rw-r--r-- | core/io/file_access_zip.cpp | 12 | ||||
-rw-r--r-- | core/io/ip_address.h | 2 | ||||
-rw-r--r-- | core/io/json.cpp | 60 | ||||
-rw-r--r-- | core/io/packet_peer_udp.h | 2 | ||||
-rw-r--r-- | core/io/resource_import.cpp | 46 | ||||
-rw-r--r-- | core/io/resource_import.h | 1 | ||||
-rw-r--r-- | core/io/stream_peer.cpp | 2 | ||||
-rw-r--r-- | core/io/tcp_server.h | 2 |
11 files changed, 95 insertions, 48 deletions
diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp index 81adbbbaf7..126ec7575e 100644 --- a/core/io/file_access_buffered.cpp +++ b/core/io/file_access_buffered.cpp @@ -106,11 +106,11 @@ uint8_t FileAccessBuffered::get_8() const { return byte; }; -int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_elements) const { +int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const { ERR_FAIL_COND_V(!file.open, -1); - if (p_elements > cache_size) { + if (p_length > cache_size) { int total_read = 0; @@ -122,12 +122,12 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_elements) const { //memcpy(p_dest, read.ptr() + (file.offset - cache.offset), size); memcpy(p_dest, cache.buffer.ptr() + (file.offset - cache.offset), size); p_dest += size; - p_elements -= size; + p_length -= size; file.offset += size; total_read += size; }; - int err = read_data_block(file.offset, p_elements, p_dest); + int err = read_data_block(file.offset, p_length, p_dest); if (err >= 0) { total_read += err; file.offset += err; @@ -136,7 +136,7 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_elements) const { return total_read; }; - int to_read = p_elements; + int to_read = p_length; int total_read = 0; while (to_read > 0) { @@ -161,7 +161,7 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_elements) const { to_read -= r; }; - return p_elements; + return p_length; }; bool FileAccessBuffered::is_open() const { diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h index c5bf120890..0ad2d0e929 100644 --- a/core/io/file_access_buffered.h +++ b/core/io/file_access_buffered.h @@ -81,7 +81,7 @@ public: virtual bool eof_reached() const; virtual uint8_t get_8() const; - virtual int get_buffer(uint8_t *p_dst, int p_length) const; ///< get an array of bytes + virtual int get_buffer(uint8_t *p_dest, int p_length) const; ///< get an array of bytes virtual bool is_open() const; diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h index 8b6abe7e81..ea858c547e 100644 --- a/core/io/file_access_memory.h +++ b/core/io/file_access_memory.h @@ -62,7 +62,7 @@ public: virtual Error get_error() const; ///< get last error - virtual void store_8(uint8_t p_dest); ///< store a byte + virtual void store_8(uint8_t p_byte); ///< store a byte virtual void store_buffer(const uint8_t *p_src, int p_length); ///< store an array of bytes virtual bool file_exists(const String &p_name); ///< return true if a file exists diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index a92014000d..d748d5c773 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -159,15 +159,15 @@ unzFile ZipArchive::get_file_handle(String p_file) const { return pkg; }; -bool ZipArchive::try_open_pack(const String &p_name) { +bool ZipArchive::try_open_pack(const String &p_path) { //printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz")); - if (p_name.get_extension().nocasecmp_to("zip") != 0 && p_name.get_extension().nocasecmp_to("pcz") != 0) + if (p_path.get_extension().nocasecmp_to("zip") != 0 && p_path.get_extension().nocasecmp_to("pcz") != 0) return false; zlib_filefunc_def io; - FileAccess *f = FileAccess::open(p_name, FileAccess::READ); + FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) return false; io.opaque = f; @@ -180,7 +180,7 @@ bool ZipArchive::try_open_pack(const String &p_name) { io.zclose_file = godot_close; io.zerror_file = godot_testerror; - unzFile zfile = unzOpen2(p_name.utf8().get_data(), &io); + unzFile zfile = unzOpen2(p_path.utf8().get_data(), &io); ERR_FAIL_COND_V(!zfile, false); unz_global_info64 gi; @@ -188,7 +188,7 @@ bool ZipArchive::try_open_pack(const String &p_name) { ERR_FAIL_COND_V(err != UNZ_OK, false); Package pkg; - pkg.filename = p_name; + pkg.filename = p_path; pkg.zfile = zfile; packages.push_back(pkg); int pkg_num = packages.size() - 1; @@ -209,7 +209,7 @@ bool ZipArchive::try_open_pack(const String &p_name) { files[fname] = f; uint8_t md5[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - PackedData::get_singleton()->add_path(p_name, fname, 1, 0, md5, this); + PackedData::get_singleton()->add_path(p_path, fname, 1, 0, md5, this); //printf("packed data add path %ls, %ls\n", p_name.c_str(), fname.c_str()); if ((i + 1) < gi.number_entry) { diff --git a/core/io/ip_address.h b/core/io/ip_address.h index ac58283605..da16622a9b 100644 --- a/core/io/ip_address.h +++ b/core/io/ip_address.h @@ -75,7 +75,7 @@ public: void set_ipv4(const uint8_t *p_ip); const uint8_t *get_ipv6() const; - void set_ipv6(const uint8_t *buf); + void set_ipv6(const uint8_t *p_buf); operator String() const; IP_Address(const String &p_string); diff --git a/core/io/json.cpp b/core/io/json.cpp index 10fd60abf7..d537061c5b 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -94,15 +94,15 @@ String JSON::print(const Variant &p_var) { return _print_var(p_var); } -Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_token, int &line, String &r_err_str) { +Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str) { while (p_len > 0) { - switch (p_str[idx]) { + switch (p_str[index]) { case '\n': { line++; - idx++; + index++; break; }; case 0: { @@ -112,54 +112,54 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_toke case '{': { r_token.type = TK_CURLY_BRACKET_OPEN; - idx++; + index++; return OK; }; case '}': { r_token.type = TK_CURLY_BRACKET_CLOSE; - idx++; + index++; return OK; }; case '[': { r_token.type = TK_BRACKET_OPEN; - idx++; + index++; return OK; }; case ']': { r_token.type = TK_BRACKET_CLOSE; - idx++; + index++; return OK; }; case ':': { r_token.type = TK_COLON; - idx++; + index++; return OK; }; case ',': { r_token.type = TK_COMMA; - idx++; + index++; return OK; }; case '"': { - idx++; + index++; String str; while (true) { - if (p_str[idx] == 0) { + if (p_str[index] == 0) { r_err_str = "Unterminated String"; return ERR_PARSE_ERROR; - } else if (p_str[idx] == '"') { - idx++; + } else if (p_str[index] == '"') { + index++; break; - } else if (p_str[idx] == '\\') { + } else if (p_str[index] == '\\') { //escaped characters... - idx++; - CharType next = p_str[idx]; + index++; + CharType next = p_str[index]; if (next == 0) { r_err_str = "Unterminated String"; return ERR_PARSE_ERROR; @@ -177,7 +177,7 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_toke //hexnumbarh - oct is deprecated for (int j = 0; j < 4; j++) { - CharType c = p_str[idx + j + 1]; + CharType c = p_str[index + j + 1]; if (c == 0) { r_err_str = "Unterminated String"; return ERR_PARSE_ERROR; @@ -204,7 +204,7 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_toke res <<= 4; res |= v; } - idx += 4; //will add at the end anyway + index += 4; //will add at the end anyway } break; //case '\"': res='\"'; break; @@ -220,11 +220,11 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_toke str += res; } else { - if (p_str[idx] == '\n') + if (p_str[index] == '\n') line++; - str += p_str[idx]; + str += p_str[index]; } - idx++; + index++; } r_token.type = TK_STRING; @@ -234,28 +234,28 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_toke } break; default: { - if (p_str[idx] <= 32) { - idx++; + if (p_str[index] <= 32) { + index++; break; } - if (p_str[idx] == '-' || (p_str[idx] >= '0' && p_str[idx] <= '9')) { + if (p_str[index] == '-' || (p_str[index] >= '0' && p_str[index] <= '9')) { //a number const CharType *rptr; - double number = String::to_double(&p_str[idx], &rptr); - idx += (rptr - &p_str[idx]); + double number = String::to_double(&p_str[index], &rptr); + index += (rptr - &p_str[index]); r_token.type = TK_NUMBER; r_token.value = number; return OK; - } else if ((p_str[idx] >= 'A' && p_str[idx] <= 'Z') || (p_str[idx] >= 'a' && p_str[idx] <= 'z')) { + } else if ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) { String id; - while ((p_str[idx] >= 'A' && p_str[idx] <= 'Z') || (p_str[idx] >= 'a' && p_str[idx] <= 'z')) { + while ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) { - id += p_str[idx]; - idx++; + id += p_str[index]; + index++; } r_token.type = TK_IDENTIFIER; diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h index a39eb6bcfd..007b810b67 100644 --- a/core/io/packet_peer_udp.h +++ b/core/io/packet_peer_udp.h @@ -49,7 +49,7 @@ protected: public: void set_blocking_mode(bool p_enable); - virtual Error listen(int p_port, IP_Address p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536) = 0; + virtual Error listen(int p_port, const IP_Address &p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536) = 0; virtual void close() = 0; virtual Error wait() = 0; virtual bool is_listening() const = 0; diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp index 61da4f3350..7033dbe5fb 100644 --- a/core/io/resource_import.cpp +++ b/core/io/resource_import.cpp @@ -199,6 +199,52 @@ String ResourceFormatImporter::get_internal_resource_path(const String &p_path) return pat.path; } +void ResourceFormatImporter::get_internal_resource_path_list(const String &p_path, List<String> *r_paths) { + + Error err; + FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err); + + if (!f) + return; + + VariantParser::StreamFile stream; + stream.f = f; + + String assign; + Variant value; + VariantParser::Tag next_tag; + + int lines = 0; + String error_text; + while (true) { + + assign = Variant(); + next_tag.fields.clear(); + next_tag.name = String(); + + err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); + if (err == ERR_FILE_EOF) { + memdelete(f); + return; + } else if (err != OK) { + ERR_PRINTS("ResourceFormatImporter::get_internal_resource_path_list - " + p_path + ".import:" + itos(lines) + " error: " + error_text); + memdelete(f); + return; + } + + if (assign != String()) { + if (assign.begins_with("path.")) { + r_paths->push_back(value); + } else if (assign == "path") { + r_paths->push_back(value); + } + } else if (next_tag.name != "remap") { + break; + } + } + memdelete(f); +} + String ResourceFormatImporter::get_resource_type(const String &p_path) const { PathAndType pat; diff --git a/core/io/resource_import.h b/core/io/resource_import.h index d3f98cbc07..67fd870178 100644 --- a/core/io/resource_import.h +++ b/core/io/resource_import.h @@ -59,6 +59,7 @@ public: virtual bool can_be_imported(const String &p_path) const; String get_internal_resource_path(const String &p_path) const; + void get_internal_resource_path_list(const String &p_path, List<String> *r_paths); void add_importer(const Ref<ResourceImporter> &p_importer) { importers.insert(p_importer); } void remove_importer(const Ref<ResourceImporter> &p_importer) { importers.erase(p_importer); } diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index faf0700edf..7042700d92 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -210,7 +210,7 @@ void StreamPeer::put_double(double p_val) { void StreamPeer::put_utf8_string(const String &p_string) { CharString cs = p_string.utf8(); - put_u32(p_string.length()); + put_u32(cs.length()); put_data((const uint8_t *)cs.get_data(), cs.length()); } void StreamPeer::put_var(const Variant &p_variant) { diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h index 4e7fa7cf3e..b4ff3246ad 100644 --- a/core/io/tcp_server.h +++ b/core/io/tcp_server.h @@ -45,7 +45,7 @@ protected: static void _bind_methods(); public: - virtual Error listen(uint16_t p_port, const IP_Address p_bind_address = IP_Address("*")) = 0; + virtual Error listen(uint16_t p_port, const IP_Address &p_bind_address = IP_Address("*")) = 0; virtual bool is_connection_available() const = 0; virtual Ref<StreamPeerTCP> take_connection() = 0; |