summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
authorqarmin <mikrutrafal54@gmail.com>2019-07-01 12:59:42 +0200
committerqarmin <mikrutrafal54@gmail.com>2019-07-01 12:59:42 +0200
commit3c154eb93b3a098354bf6d18a9428826ec193f90 (patch)
treed9c8c44f13883ceadaefc95953f9cb077137b7c8 /core/io
parenteaaff9da3178fa515a0f051fda932c1dd04d53db (diff)
Remove unnecessary code and add some error explanations
Diffstat (limited to 'core/io')
-rw-r--r--core/io/file_access_buffered.cpp64
-rw-r--r--core/io/file_access_buffered_fa.h5
-rw-r--r--core/io/http_client.cpp2
-rw-r--r--core/io/json.cpp2
-rw-r--r--core/io/pck_packer.cpp7
-rw-r--r--core/io/resource_importer.cpp5
-rw-r--r--core/io/resource_loader.cpp4
7 files changed, 43 insertions, 46 deletions
diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp
index 93eaeb08c5..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;
@@ -143,10 +143,10 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const {
if (left == 0) {
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();
@@ -156,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/http_client.cpp b/core/io/http_client.cpp
index c3626bfe31..170bef4430 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -482,8 +482,6 @@ Error HTTPClient::poll() {
return OK;
}
}
- // Wait for response
- return OK;
} break;
case STATUS_DISCONNECTED: {
return ERR_UNCONFIGURED;
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/pck_packer.cpp b/core/io/pck_packer.cpp
index 55685a2d9a..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;
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_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) {