diff options
Diffstat (limited to 'core/io')
29 files changed, 250 insertions, 106 deletions
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 414742deeb..f7fb72c089 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -30,7 +30,7 @@ #include "config_file.h" -#include "core/os/file_access.h" +#include "core/io/file_access_encrypted.h" #include "core/os/keyboard.h" #include "core/variant_parser.h" @@ -137,6 +137,48 @@ Error ConfigFile::save(const String &p_path) { return err; } + return _internal_save(file); +} + +Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_key) { + + Error err; + FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err); + + if (err) + return err; + + FileAccessEncrypted *fae = memnew(FileAccessEncrypted); + err = fae->open_and_parse(f, p_key, FileAccessEncrypted::MODE_WRITE_AES256); + if (err) { + memdelete(fae); + memdelete(f); + return err; + } + return _internal_save(fae); +} + +Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass) { + + Error err; + FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err); + + if (err) + return err; + + FileAccessEncrypted *fae = memnew(FileAccessEncrypted); + err = fae->open_and_parse_password(f, p_pass, FileAccessEncrypted::MODE_WRITE_AES256); + if (err) { + memdelete(fae); + memdelete(f); + return err; + } + + return _internal_save(fae); +} + +Error ConfigFile::_internal_save(FileAccess *file) { + for (OrderedHashMap<String, OrderedHashMap<String, Variant> >::Element E = values.front(); E; E = E.next()) { if (E != values.front()) @@ -164,6 +206,48 @@ Error ConfigFile::load(const String &p_path) { if (!f) return ERR_CANT_OPEN; + return _internal_load(p_path, f); +} + +Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_key) { + + Error err; + FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); + + if (err) + return err; + + FileAccessEncrypted *fae = memnew(FileAccessEncrypted); + err = fae->open_and_parse(f, p_key, FileAccessEncrypted::MODE_READ); + if (err) { + memdelete(fae); + memdelete(f); + return err; + } + return _internal_load(p_path, fae); +} + +Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass) { + + Error err; + FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); + + if (err) + return err; + + FileAccessEncrypted *fae = memnew(FileAccessEncrypted); + err = fae->open_and_parse_password(f, p_pass, FileAccessEncrypted::MODE_READ); + if (err) { + memdelete(fae); + memdelete(f); + return err; + } + + return _internal_load(p_path, fae); +} + +Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) { + VariantParser::StreamFile stream; stream.f = f; @@ -182,7 +266,7 @@ Error ConfigFile::load(const String &p_path) { next_tag.fields.clear(); next_tag.name = String(); - err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); + Error err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); if (err == ERR_FILE_EOF) { memdelete(f); return OK; @@ -198,10 +282,6 @@ Error ConfigFile::load(const String &p_path) { section = next_tag.name; } } - - memdelete(f); - - return OK; } void ConfigFile::_bind_methods() { @@ -219,6 +299,12 @@ void ConfigFile::_bind_methods() { ClassDB::bind_method(D_METHOD("load", "path"), &ConfigFile::load); ClassDB::bind_method(D_METHOD("save", "path"), &ConfigFile::save); + + ClassDB::bind_method(D_METHOD("load_encrypted", "path", "key"), &ConfigFile::load_encrypted); + ClassDB::bind_method(D_METHOD("load_encrypted_pass", "path", "pass"), &ConfigFile::load_encrypted_pass); + + ClassDB::bind_method(D_METHOD("save_encrypted", "path", "key"), &ConfigFile::save_encrypted); + ClassDB::bind_method(D_METHOD("save_encrypted_pass", "path", "pass"), &ConfigFile::save_encrypted_pass); } ConfigFile::ConfigFile() { diff --git a/core/io/config_file.h b/core/io/config_file.h index 36e5c0ca7d..3ab6fef868 100644 --- a/core/io/config_file.h +++ b/core/io/config_file.h @@ -32,6 +32,7 @@ #define CONFIG_FILE_H #include "core/ordered_hash_map.h" +#include "core/os/file_access.h" #include "core/reference.h" class ConfigFile : public Reference { @@ -42,6 +43,8 @@ class ConfigFile : public Reference { PoolStringArray _get_sections() const; PoolStringArray _get_section_keys(const String &p_section) const; + Error _internal_load(const String &p_path, FileAccess *f); + Error _internal_save(FileAccess *file); protected: static void _bind_methods(); @@ -61,6 +64,12 @@ public: Error save(const String &p_path); Error load(const String &p_path); + Error load_encrypted(const String &p_path, const Vector<uint8_t> &p_key); + Error load_encrypted_pass(const String &p_path, const String &p_pass); + + Error save_encrypted(const String &p_path, const Vector<uint8_t> &p_key); + Error save_encrypted_pass(const String &p_path, const String &p_pass); + ConfigFile(); }; diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp index 83ff532aa4..15523a49a9 100644 --- a/core/io/file_access_buffered.cpp +++ b/core/io/file_access_buffered.cpp @@ -35,79 +35,79 @@ Error FileAccessBuffered::set_error(Error p_error) const { return (last_error = p_error); -}; +} void FileAccessBuffered::set_cache_size(int p_size) { cache_size = p_size; -}; +} int FileAccessBuffered::get_cache_size() { return cache_size; -}; +} int FileAccessBuffered::cache_data_left() const { if (file.offset >= file.size) { return 0; - }; + } if (cache.offset == -1 || file.offset < cache.offset || file.offset >= cache.offset + cache.buffer.size()) { return read_data_block(file.offset, cache_size); + } - } else { - - return cache.buffer.size() - (file.offset - cache.offset); - }; - - return 0; -}; + return cache.buffer.size() - (file.offset - cache.offset); +} void FileAccessBuffered::seek(size_t p_position) { file.offset = p_position; -}; +} void FileAccessBuffered::seek_end(int64_t p_position) { file.offset = file.size + p_position; -}; +} size_t FileAccessBuffered::get_position() const { return file.offset; -}; +} size_t FileAccessBuffered::get_len() const { return file.size; -}; +} bool FileAccessBuffered::eof_reached() const { return file.offset > file.size; -}; +} uint8_t FileAccessBuffered::get_8() const { - - ERR_FAIL_COND_V(!file.open, 0); + if (!file.open) { + ERR_EXPLAIN("Can't get data, when file is not opened."); + ERR_FAIL_V(0); + } uint8_t byte = 0; if (cache_data_left() >= 1) { byte = cache.buffer[file.offset - cache.offset]; - }; + } ++file.offset; return byte; -}; +} int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const { - - ERR_FAIL_COND_V(!file.open, -1); + if (!file.open) { + ERR_EXPLAIN("Can't get buffer, when file is not opened."); + ERR_FAIL_V(-1); + } if (p_length > cache_size) { @@ -124,16 +124,16 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const { p_length -= size; file.offset += size; total_read += size; - }; + } int err = read_data_block(file.offset, p_length, p_dest); if (err >= 0) { total_read += err; file.offset += err; - }; + } return total_read; - }; + } int to_read = p_length; int total_read = 0; @@ -141,14 +141,12 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const { int left = cache_data_left(); if (left == 0) { - if (to_read > 0) { - file.offset += to_read; - }; + file.offset += to_read; return total_read; - }; + } if (left < 0) { return left; - }; + } int r = MIN(left, to_read); //PoolVector<uint8_t>::Read read = cache.buffer.read(); @@ -158,25 +156,25 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const { file.offset += r; total_read += r; to_read -= r; - }; + } return p_length; -}; +} bool FileAccessBuffered::is_open() const { return file.open; -}; +} Error FileAccessBuffered::get_error() const { return last_error; -}; +} FileAccessBuffered::FileAccessBuffered() { cache_size = DEFAULT_CACHE_SIZE; -}; +} FileAccessBuffered::~FileAccessBuffered() { } diff --git a/core/io/file_access_buffered_fa.h b/core/io/file_access_buffered_fa.h index 24b40cbce8..6e806e7b3f 100644 --- a/core/io/file_access_buffered_fa.h +++ b/core/io/file_access_buffered_fa.h @@ -40,7 +40,10 @@ class FileAccessBufferedFA : public FileAccessBuffered { int read_data_block(int p_offset, int p_size, uint8_t *p_dest = 0) const { - ERR_FAIL_COND_V(!f.is_open(), -1); + if (!f.is_open()) { + ERR_EXPLAIN("Can't read data block, when file is not opened."); + ERR_FAIL_V(-1); + } ((T *)&f)->seek(p_offset); diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 5dd167c581..d1c7f5c334 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -435,7 +435,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const { _queue_page(page + j); } - buff = pages.write[page].buffer.ptrw(); //queue pages buffer_mutex->unlock(); } diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index ce2054db36..170bef4430 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -346,6 +346,12 @@ Error HTTPClient::poll() { } else { // We are already handshaking, which means we can use your already active SSL connection ssl = static_cast<Ref<StreamPeerSSL> >(connection); + if (ssl.is_null()) { + close(); + status = STATUS_SSL_HANDSHAKE_ERROR; + return ERR_CANT_CONNECT; + } + ssl->poll(); // Try to finish the handshake } @@ -476,8 +482,6 @@ Error HTTPClient::poll() { return OK; } } - // Wait for response - return OK; } break; case STATUS_DISCONNECTED: { return ERR_UNCONFIGURED; @@ -769,7 +773,7 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() { get_response_headers(&rh); Dictionary ret; for (const List<String>::Element *E = rh.front(); E; E = E->next()) { - String s = E->get(); + const String &s = E->get(); int sp = s.find(":"); if (sp == -1) continue; diff --git a/core/io/image_loader.h b/core/io/image_loader.h index 95c562b7a9..ae4b72a534 100644 --- a/core/io/image_loader.h +++ b/core/io/image_loader.h @@ -88,7 +88,6 @@ public: }; class ResourceFormatLoaderImage : public ResourceFormatLoader { - GDCLASS(ResourceFormatLoaderImage, ResourceFormatLoader) public: virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); virtual void get_recognized_extensions(List<String> *p_extensions) const; diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 420e48f839..3d87131b51 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -234,6 +234,41 @@ Array IP::_get_local_addresses() const { return addresses; } +Array IP::_get_local_interfaces() const { + + Array results; + Map<String, Interface_Info> interfaces; + get_local_interfaces(&interfaces); + for (Map<String, Interface_Info>::Element *E = interfaces.front(); E; E = E->next()) { + Interface_Info &c = E->get(); + Dictionary rc; + rc["name"] = c.name; + rc["friendly"] = c.name_friendly; + rc["index"] = c.index; + + Array ips; + for (const List<IP_Address>::Element *F = c.ip_addresses.front(); F; F = F->next()) { + ips.push_front(F->get()); + } + rc["addresses"] = ips; + + results.push_front(rc); + } + + return results; +} + +void IP::get_local_addresses(List<IP_Address> *r_addresses) const { + + Map<String, Interface_Info> interfaces; + get_local_interfaces(&interfaces); + for (Map<String, Interface_Info>::Element *E = interfaces.front(); E; E = E->next()) { + for (const List<IP_Address>::Element *F = E->get().ip_addresses.front(); F; F = F->next()) { + r_addresses->push_front(F->get()); + } + } +} + void IP::_bind_methods() { ClassDB::bind_method(D_METHOD("resolve_hostname", "host", "ip_type"), &IP::resolve_hostname, DEFVAL(IP::TYPE_ANY)); @@ -242,6 +277,7 @@ void IP::_bind_methods() { ClassDB::bind_method(D_METHOD("get_resolve_item_address", "id"), &IP::get_resolve_item_address); ClassDB::bind_method(D_METHOD("erase_resolve_item", "id"), &IP::erase_resolve_item); ClassDB::bind_method(D_METHOD("get_local_addresses"), &IP::_get_local_addresses); + ClassDB::bind_method(D_METHOD("get_local_interfaces"), &IP::_get_local_interfaces); ClassDB::bind_method(D_METHOD("clear_cache", "hostname"), &IP::clear_cache, DEFVAL("")); BIND_ENUM_CONSTANT(RESOLVER_STATUS_NONE); diff --git a/core/io/ip.h b/core/io/ip.h index ead71ebb54..59b18ef986 100644 --- a/core/io/ip.h +++ b/core/io/ip.h @@ -73,16 +73,25 @@ protected: virtual IP_Address _resolve_hostname(const String &p_hostname, Type p_type = TYPE_ANY) = 0; Array _get_local_addresses() const; + Array _get_local_interfaces() const; static IP *(*_create)(); public: + struct Interface_Info { + String name; + String name_friendly; + String index; + List<IP_Address> ip_addresses; + }; + IP_Address resolve_hostname(const String &p_hostname, Type p_type = TYPE_ANY); // async resolver hostname ResolverID resolve_hostname_queue_item(const String &p_hostname, Type p_type = TYPE_ANY); ResolverStatus get_resolve_item_status(ResolverID p_id) const; IP_Address get_resolve_item_address(ResolverID p_id) const; - virtual void get_local_addresses(List<IP_Address> *r_addresses) const = 0; + virtual void get_local_addresses(List<IP_Address> *r_addresses) const; + virtual void get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const = 0; void erase_resolve_item(ResolverID p_id); void clear_cache(const String &p_hostname = ""); diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp index 763a5fbb9a..9305afac5f 100644 --- a/core/io/ip_address.cpp +++ b/core/io/ip_address.cpp @@ -40,6 +40,9 @@ IP_Address::operator Variant() const { IP_Address::operator String() const { + if (wildcard) + return "*"; + if (!valid) return ""; diff --git a/core/io/json.cpp b/core/io/json.cpp index c211ca2ed4..4e729cb355 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -347,8 +347,6 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in r_err_str = "Expected value, got " + String(tk_name[token.type]) + "."; return ERR_PARSE_ERROR; } - - return ERR_PARSE_ERROR; } Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) { diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index d1b6b82cf0..17a3f52a65 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -37,13 +37,11 @@ #include <limits.h> #include <stdio.h> -#define _S(a) ((int32_t)a) -#define ERR_FAIL_ADD_OF(a, b, err) ERR_FAIL_COND_V(_S(b) < 0 || _S(a) < 0 || _S(a) > INT_MAX - _S(b), err) -#define ERR_FAIL_MUL_OF(a, b, err) ERR_FAIL_COND_V(_S(a) < 0 || _S(b) <= 0 || _S(a) > INT_MAX / _S(b), err) - void EncodedObjectAsID::_bind_methods() { ClassDB::bind_method(D_METHOD("set_object_id", "id"), &EncodedObjectAsID::set_object_id); ClassDB::bind_method(D_METHOD("get_object_id"), &EncodedObjectAsID::get_object_id); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "object_id"), "set_object_id", "get_object_id"); } void EncodedObjectAsID::set_object_id(ObjectID p_id) { @@ -59,6 +57,10 @@ EncodedObjectAsID::EncodedObjectAsID() : id(0) { } +#define _S(a) ((int32_t)a) +#define ERR_FAIL_ADD_OF(a, b, err) ERR_FAIL_COND_V(_S(b) < 0 || _S(a) < 0 || _S(a) > INT_MAX - _S(b), err) +#define ERR_FAIL_MUL_OF(a, b, err) ERR_FAIL_COND_V(_S(a) < 0 || _S(b) <= 0 || _S(a) > INT_MAX / _S(b), err) + #define ENCODE_MASK 0xFF #define ENCODE_FLAG_64 1 << 16 #define ENCODE_FLAG_OBJECT_AS_ID 1 << 16 @@ -103,10 +105,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int const uint8_t *buf = p_buffer; int len = p_len; - if (len < 4) { - - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); - } + ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); uint32_t type = decode_uint32(buf); @@ -684,8 +683,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int if (r_len) (*r_len) += adv; - len -= adv; - buf += adv; } r_variant = varray; @@ -722,8 +719,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int if (r_len) (*r_len) += adv; - len -= adv; - buf += adv; } r_variant = varray; @@ -761,8 +756,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int if (r_len) (*r_len) += adv; - len -= adv; - buf += adv; } r_variant = carray; @@ -1095,7 +1088,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo if (!obj) { if (buf) { encode_uint32(0, buf); - buf += 4; } r_len += 4; diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index 2779837190..33dc4dbde4 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -874,6 +874,7 @@ void MultiplayerAPI::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_object_decoding"), "set_allow_object_decoding", "is_object_decoding_allowed"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "refuse_new_network_connections"), "set_refuse_new_network_connections", "is_refusing_new_network_connections"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "network_peer", PROPERTY_HINT_RESOURCE_TYPE, "NetworkedMultiplayerPeer", 0), "set_network_peer", "get_network_peer"); + ADD_PROPERTY_DEFAULT("refuse_new_network_connections", false); ADD_SIGNAL(MethodInfo("network_peer_connected", PropertyInfo(Variant::INT, "id"))); ADD_SIGNAL(MethodInfo("network_peer_disconnected", PropertyInfo(Variant::INT, "id"))); diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h index 779dd043bd..5258dde5d7 100644 --- a/core/io/multiplayer_api.h +++ b/core/io/multiplayer_api.h @@ -77,7 +77,7 @@ protected: void _process_raw(int p_from, const uint8_t *p_packet, int p_packet_len); void _send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount); - bool _send_confirm_path(NodePath p_path, PathSentCache *psc, int p_from); + bool _send_confirm_path(NodePath p_path, PathSentCache *psc, int p_target); public: enum NetworkCommands { diff --git a/core/io/net_socket.h b/core/io/net_socket.h index 94e7ef6f75..3bc1369487 100644 --- a/core/io/net_socket.h +++ b/core/io/net_socket.h @@ -74,6 +74,8 @@ public: virtual void set_ipv6_only_enabled(bool p_enabled) = 0; virtual void set_tcp_no_delay_enabled(bool p_enabled) = 0; virtual void set_reuse_address_enabled(bool p_enabled) = 0; + virtual Error join_multicast_group(const IP_Address &p_multi_address, String p_if_name) = 0; + virtual Error leave_multicast_group(const IP_Address &p_multi_address, String p_if_name) = 0; }; #endif // NET_SOCKET_H diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index 5912b8df94..7e9471c053 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -37,6 +37,27 @@ void PacketPeerUDP::set_blocking_mode(bool p_enable) { blocking = p_enable; } +Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_if_name) { + + ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); + ERR_FAIL_COND_V(!p_multi_address.is_valid(), ERR_INVALID_PARAMETER); + + if (!_sock->is_open()) { + IP::Type ip_type = p_multi_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; + Error err = _sock->open(NetSocket::TYPE_UDP, ip_type); + ERR_FAIL_COND_V(err != OK, err); + _sock->set_blocking_enabled(false); + } + return _sock->join_multicast_group(p_multi_address, p_if_name); +} + +Error PacketPeerUDP::leave_multicast_group(IP_Address p_multi_address, String p_if_name) { + + ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); + ERR_FAIL_COND_V(!_sock->is_open(), ERR_UNCONFIGURED); + return _sock->leave_multicast_group(p_multi_address, p_if_name); +} + String PacketPeerUDP::_get_packet_ip() const { return get_packet_address(); @@ -237,6 +258,8 @@ void PacketPeerUDP::_bind_methods() { ClassDB::bind_method(D_METHOD("get_packet_ip"), &PacketPeerUDP::_get_packet_ip); ClassDB::bind_method(D_METHOD("get_packet_port"), &PacketPeerUDP::get_packet_port); ClassDB::bind_method(D_METHOD("set_dest_address", "host", "port"), &PacketPeerUDP::_set_dest_address); + ClassDB::bind_method(D_METHOD("join_multicast_group", "multicast_address", "interface_name"), &PacketPeerUDP::join_multicast_group); + ClassDB::bind_method(D_METHOD("leave_multicast_group", "multicast_address", "interface_name"), &PacketPeerUDP::leave_multicast_group); } PacketPeerUDP::PacketPeerUDP() : diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h index 0593137604..068bd5cd5a 100644 --- a/core/io/packet_peer_udp.h +++ b/core/io/packet_peer_udp.h @@ -77,6 +77,8 @@ public: Error get_packet(const uint8_t **r_buffer, int &r_buffer_size); int get_available_packet_count() const; int get_max_packet_size() const; + Error join_multicast_group(IP_Address p_multi_address, String p_if_name); + Error leave_multicast_group(IP_Address p_multi_address, String p_if_name); PacketPeerUDP(); ~PacketPeerUDP(); diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp index 8920bbfb81..c16d89d695 100644 --- a/core/io/pck_packer.cpp +++ b/core/io/pck_packer.cpp @@ -63,10 +63,11 @@ void PCKPacker::_bind_methods() { Error PCKPacker::pck_start(const String &p_file, int p_alignment) { file = FileAccess::open(p_file, FileAccess::WRITE); - if (file == NULL) { - return ERR_CANT_CREATE; - }; + if (!file) { + ERR_EXPLAIN("Can't open file to write: " + String(p_file)); + ERR_FAIL_V(ERR_CANT_CREATE); + } alignment = p_alignment; @@ -109,10 +110,7 @@ Error PCKPacker::add_file(const String &p_file, const String &p_src) { Error PCKPacker::flush(bool p_verbose) { - if (!file) { - ERR_FAIL_COND_V(!file, ERR_INVALID_PARAMETER); - return ERR_INVALID_PARAMETER; - }; + ERR_FAIL_COND_V(!file, ERR_INVALID_PARAMETER); // write the index diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index f25abc4aab..688dfc21e5 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -720,7 +720,7 @@ Error ResourceInteractiveLoaderBinary::poll() { error = ERR_FILE_CORRUPT; memdelete(obj); //bye ERR_EXPLAIN(local_path + ":Resource type in resource field not a resource, type is: " + obj->get_class()); - ERR_FAIL_COND_V(!r, ERR_FILE_CORRUPT); + ERR_FAIL_V(ERR_FILE_CORRUPT); } RES res = RES(r); @@ -991,10 +991,7 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(cons Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (err != OK) { - - ERR_FAIL_COND_V(err != OK, Ref<ResourceInteractiveLoader>()); - } + ERR_FAIL_COND_V(err != OK, Ref<ResourceInteractiveLoader>()); Ref<ResourceInteractiveLoaderBinary> ria = memnew(ResourceInteractiveLoaderBinary); String path = p_original_path != "" ? p_original_path : p_path; @@ -1129,9 +1126,8 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons Error err; f = FileAccess::open(p_path, FileAccess::READ, &err); - if (err != OK) { - ERR_FAIL_COND_V(err != OK, ERR_FILE_CANT_OPEN); - } + + ERR_FAIL_COND_V(err != OK, ERR_FILE_CANT_OPEN); Ref<ResourceInteractiveLoaderBinary> ria = memnew(ResourceInteractiveLoaderBinary); ria->local_path = ProjectSettings::get_singleton()->localize_path(p_path); @@ -1698,7 +1694,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant int len = varray.size(); for (int i = 0; i < len; i++) { - Variant v = varray.get(i); + const Variant &v = varray.get(i); _find_resources(v); } diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index a4894e4033..27777c8e8b 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -100,7 +100,6 @@ public: }; class ResourceFormatLoaderBinary : public ResourceFormatLoader { - GDCLASS(ResourceFormatLoaderBinary, ResourceFormatLoader) public: virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; @@ -162,7 +161,6 @@ public: }; class ResourceFormatSaverBinary : public ResourceFormatSaver { - GDCLASS(ResourceFormatSaverBinary, ResourceFormatSaver) public: static ResourceFormatSaverBinary *singleton; virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0); diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index 4a58d37ca5..63d7ba547c 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -161,7 +161,8 @@ void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extension void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const { if (p_type == "") { - return get_recognized_extensions(p_extensions); + get_recognized_extensions(p_extensions); + return; } Set<String> found; @@ -347,7 +348,7 @@ void ResourceFormatImporter::get_dependencies(const String &p_path, List<String> return; } - return ResourceLoader::get_dependencies(pat.path, p_dependencies, p_add_types); + ResourceLoader::get_dependencies(pat.path, p_dependencies, p_add_types); } Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String &p_name) const { diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h index 2e01989564..9cf298a7f5 100644 --- a/core/io/resource_importer.h +++ b/core/io/resource_importer.h @@ -37,8 +37,6 @@ class ResourceImporter; class ResourceFormatImporter : public ResourceFormatLoader { - GDCLASS(ResourceFormatImporter, ResourceFormatLoader) - struct PathAndType { String path; String type; @@ -96,7 +94,8 @@ public: class ResourceImporter : public Reference { - GDCLASS(ResourceImporter, Reference) + GDCLASS(ResourceImporter, Reference); + public: virtual String get_importer_name() const = 0; virtual String get_visible_name() const = 0; diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 56d3b8b133..a29b9d1ddb 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -207,8 +207,6 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa ERR_FAIL_COND_V(err != OK, RES()); } - - return RES(); } void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { @@ -283,7 +281,6 @@ RES ResourceLoader::_load(const String &p_path, const String &p_original_path, c ERR_EXPLAIN("No loader found for resource: " + p_path); } ERR_FAIL_V(RES()); - return RES(); } bool ResourceLoader::_add_to_loading_map(const String &p_path) { @@ -543,7 +540,6 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_ ERR_EXPLAIN("No loader found for resource: " + path); } ERR_FAIL_V(Ref<ResourceInteractiveLoader>()); - return Ref<ResourceInteractiveLoader>(); } void ResourceLoader::add_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader, bool p_at_front) { diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 9e7020be7c..70e7bdc224 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -62,7 +62,7 @@ public: class ResourceFormatLoader : public Reference { - GDCLASS(ResourceFormatLoader, Reference) + GDCLASS(ResourceFormatLoader, Reference); protected: static void _bind_methods(); diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index 7df3bfb1f8..0fba47a5e8 100644 --- a/core/io/resource_saver.h +++ b/core/io/resource_saver.h @@ -38,7 +38,7 @@ */ class ResourceFormatSaver : public Reference { - GDCLASS(ResourceFormatSaver, Reference) + GDCLASS(ResourceFormatSaver, Reference); protected: static void _bind_methods(); diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index 45f3e46e35..bcdae343b8 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -352,7 +352,6 @@ void StreamPeerTCP::_bind_methods() { StreamPeerTCP::StreamPeerTCP() : _sock(Ref<NetSocket>(NetSocket::create())), status(STATUS_NONE), - peer_host(IP_Address()), peer_port(0) { } diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 6599c4eb5b..be87f47d50 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -83,11 +83,7 @@ bool TCP_Server::is_connection_available() const { return false; Error err = _sock->poll(NetSocket::POLL_TYPE_IN, 0); - if (err != OK) { - return false; - } - - return true; + return (err == OK); } Ref<StreamPeerTCP> TCP_Server::take_connection() { diff --git a/core/io/translation_loader_po.h b/core/io/translation_loader_po.h index d5fd264385..9d9c5d16ee 100644 --- a/core/io/translation_loader_po.h +++ b/core/io/translation_loader_po.h @@ -36,7 +36,6 @@ #include "core/translation.h" class TranslationLoaderPO : public ResourceFormatLoader { - GDCLASS(TranslationLoaderPO, ResourceFormatLoader) public: static RES load_translation(FileAccess *f, Error *r_error, const String &p_path = String()); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index 4638ddcc09..82527d3f38 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -348,7 +348,7 @@ uint64_t XMLParser::get_node_offset() const { Error XMLParser::seek(uint64_t p_pos) { - ERR_FAIL_COND_V(!data, ERR_FILE_EOF) + ERR_FAIL_COND_V(!data, ERR_FILE_EOF); ERR_FAIL_COND_V(p_pos >= length, ERR_FILE_EOF); P = data + p_pos; @@ -486,9 +486,7 @@ Error XMLParser::open(const String &p_path) { Error err; FileAccess *file = FileAccess::open(p_path, FileAccess::READ, &err); - if (err) { - ERR_FAIL_COND_V(err != OK, err); - } + ERR_FAIL_COND_V(err != OK, err); length = file->get_len(); ERR_FAIL_COND_V(length < 1, ERR_FILE_CORRUPT); |