summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
Diffstat (limited to 'core/io')
-rw-r--r--core/io/file_access_compressed.cpp34
-rw-r--r--core/io/file_access_compressed.h28
-rw-r--r--core/io/file_access_encrypted.cpp41
-rw-r--r--core/io/file_access_encrypted.h16
-rw-r--r--core/io/file_access_memory.cpp21
-rw-r--r--core/io/file_access_memory.h16
-rw-r--r--core/io/file_access_network.cpp40
-rw-r--r--core/io/file_access_network.h38
-rw-r--r--core/io/file_access_pack.cpp36
-rw-r--r--core/io/file_access_pack.h22
-rw-r--r--core/io/file_access_zip.cpp20
-rw-r--r--core/io/file_access_zip.h11
-rw-r--r--core/io/pck_packer.cpp2
-rw-r--r--core/io/resource_format_binary.cpp4
-rw-r--r--core/io/zip_io.cpp2
15 files changed, 162 insertions, 169 deletions
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index b2440629e3..efcaa80fc5 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -32,7 +32,7 @@
#include "core/string/print_string.h"
-void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, int p_block_size) {
+void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, uint32_t p_block_size) {
magic = p_magic.ascii().get_data();
if (magic.length() > 4) {
magic = magic.substr(0, 4);
@@ -67,10 +67,10 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Can't open compressed file '" + p_base->get_path() + "' with block size 0, it is corrupted.");
}
read_total = f->get_32();
- int bc = (read_total / block_size) + 1;
- int acc_ofs = f->get_position() + bc * 4;
- int max_bs = 0;
- for (int i = 0; i < bc; i++) {
+ uint32_t bc = (read_total / block_size) + 1;
+ uint64_t acc_ofs = f->get_position() + bc * 4;
+ uint32_t max_bs = 0;
+ for (uint32_t i = 0; i < bc; i++) {
ReadBlock rb;
rb.offset = acc_ofs;
rb.csize = f->get_32();
@@ -148,15 +148,15 @@ void FileAccessCompressed::close() {
f->store_32(cmode); //write compression mode 4
f->store_32(block_size); //write block size 4
f->store_32(write_max); //max amount of data written 4
- int bc = (write_max / block_size) + 1;
+ uint32_t bc = (write_max / block_size) + 1;
- for (int i = 0; i < bc; i++) {
+ for (uint32_t i = 0; i < bc; i++) {
f->store_32(0); //compressed sizes, will update later
}
Vector<int> block_sizes;
- for (int i = 0; i < bc; i++) {
- int bl = i == (bc - 1) ? write_max % block_size : block_size;
+ for (uint32_t i = 0; i < bc; i++) {
+ uint32_t bl = i == (bc - 1) ? write_max % block_size : block_size;
uint8_t *bp = &write_ptr[i * block_size];
Vector<uint8_t> cblock;
@@ -168,7 +168,7 @@ void FileAccessCompressed::close() {
}
f->seek(16); //ok write block sizes
- for (int i = 0; i < bc; i++) {
+ for (uint32_t i = 0; i < bc; i++) {
f->store_32(block_sizes[i]);
}
f->seek_end();
@@ -190,8 +190,9 @@ bool FileAccessCompressed::is_open() const {
return f != nullptr;
}
-void FileAccessCompressed::seek(size_t p_position) {
+void FileAccessCompressed::seek(uint64_t p_position) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
+
if (writing) {
ERR_FAIL_COND(p_position > write_max);
@@ -204,7 +205,7 @@ void FileAccessCompressed::seek(size_t p_position) {
} else {
at_end = false;
read_eof = false;
- int block_idx = p_position / block_size;
+ uint32_t block_idx = p_position / block_size;
if (block_idx != read_block) {
read_block = block_idx;
f->seek(read_blocks[read_block].offset);
@@ -227,7 +228,7 @@ void FileAccessCompressed::seek_end(int64_t p_position) {
}
}
-size_t FileAccessCompressed::get_position() const {
+uint64_t FileAccessCompressed::get_position() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
if (writing) {
return write_pos;
@@ -236,7 +237,7 @@ size_t FileAccessCompressed::get_position() const {
}
}
-size_t FileAccessCompressed::get_len() const {
+uint64_t FileAccessCompressed::get_len() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
if (writing) {
return write_max;
@@ -285,9 +286,8 @@ uint8_t FileAccessCompressed::get_8() const {
return ret;
}
-int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
+uint64_t FileAccessCompressed::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
- ERR_FAIL_COND_V(p_length < 0, -1);
ERR_FAIL_COND_V_MSG(!f, -1, "File must be opened before use.");
ERR_FAIL_COND_V_MSG(writing, -1, "File has not been opened in read mode.");
@@ -296,7 +296,7 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
return 0;
}
- for (int i = 0; i < p_length; i++) {
+ for (uint64_t i = 0; i < p_length; i++) {
p_dst[i] = read_ptr[read_pos];
read_pos++;
if (read_pos >= read_block_size) {
diff --git a/core/io/file_access_compressed.h b/core/io/file_access_compressed.h
index 118d05ea57..d8a81c2417 100644
--- a/core/io/file_access_compressed.h
+++ b/core/io/file_access_compressed.h
@@ -37,34 +37,34 @@
class FileAccessCompressed : public FileAccess {
Compression::Mode cmode = Compression::MODE_ZSTD;
bool writing = false;
- uint32_t write_pos = 0;
+ uint64_t write_pos = 0;
uint8_t *write_ptr = nullptr;
uint32_t write_buffer_size = 0;
- uint32_t write_max = 0;
+ uint64_t write_max = 0;
uint32_t block_size = 0;
mutable bool read_eof = false;
mutable bool at_end = false;
struct ReadBlock {
- int csize;
- int offset;
+ uint32_t csize;
+ uint64_t offset;
};
mutable Vector<uint8_t> comp_buffer;
uint8_t *read_ptr = nullptr;
- mutable int read_block = 0;
- int read_block_count = 0;
- mutable int read_block_size = 0;
- mutable int read_pos = 0;
+ mutable uint32_t read_block = 0;
+ uint32_t read_block_count = 0;
+ mutable uint32_t read_block_size = 0;
+ mutable uint64_t read_pos = 0;
Vector<ReadBlock> read_blocks;
- uint32_t read_total = 0;
+ uint64_t read_total = 0;
String magic = "GCMP";
mutable Vector<uint8_t> buffer;
FileAccess *f = nullptr;
public:
- void configure(const String &p_magic, Compression::Mode p_mode = Compression::MODE_ZSTD, int p_block_size = 4096);
+ void configure(const String &p_magic, Compression::Mode p_mode = Compression::MODE_ZSTD, uint32_t p_block_size = 4096);
Error open_after_magic(FileAccess *p_base);
@@ -72,15 +72,15 @@ public:
virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open
- virtual void seek(size_t p_position); ///< seek to a given position
+ virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
- virtual size_t get_position() const; ///< get position in the file
- virtual size_t get_len() const; ///< get size of the file
+ virtual uint64_t get_position() const; ///< get position in the file
+ virtual uint64_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte
- virtual int get_buffer(uint8_t *p_dst, int p_length) const;
+ virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const;
virtual Error get_error() const; ///< get last error
diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp
index 13377a3a25..9a6bee7348 100644
--- a/core/io/file_access_encrypted.cpp
+++ b/core/io/file_access_encrypted.cpp
@@ -70,13 +70,13 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
base = p_base->get_position();
ERR_FAIL_COND_V(p_base->get_len() < base + length, ERR_FILE_CORRUPT);
- uint32_t ds = length;
+ uint64_t ds = length;
if (ds % 16) {
ds += 16 - (ds % 16);
}
data.resize(ds);
- uint32_t blen = p_base->get_buffer(data.ptrw(), ds);
+ uint64_t blen = p_base->get_buffer(data.ptrw(), ds);
ERR_FAIL_COND_V(blen != ds, ERR_FILE_CORRUPT);
{
@@ -141,7 +141,7 @@ void FileAccessEncrypted::release() {
void FileAccessEncrypted::_release() {
if (writing) {
Vector<uint8_t> compressed;
- size_t len = data.size();
+ uint64_t len = data.size();
if (len % 16) {
len += 16 - (len % 16);
}
@@ -198,9 +198,9 @@ String FileAccessEncrypted::get_path_absolute() const {
}
}
-void FileAccessEncrypted::seek(size_t p_position) {
- if (p_position > (size_t)data.size()) {
- p_position = data.size();
+void FileAccessEncrypted::seek(uint64_t p_position) {
+ if (p_position > get_len()) {
+ p_position = get_len();
}
pos = p_position;
@@ -208,14 +208,14 @@ void FileAccessEncrypted::seek(size_t p_position) {
}
void FileAccessEncrypted::seek_end(int64_t p_position) {
- seek(data.size() + p_position);
+ seek(get_len() + p_position);
}
-size_t FileAccessEncrypted::get_position() const {
+uint64_t FileAccessEncrypted::get_position() const {
return pos;
}
-size_t FileAccessEncrypted::get_len() const {
+uint64_t FileAccessEncrypted::get_len() const {
return data.size();
}
@@ -225,7 +225,7 @@ bool FileAccessEncrypted::eof_reached() const {
uint8_t FileAccessEncrypted::get_8() const {
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
- if (pos >= data.size()) {
+ if (pos >= get_len()) {
eofed = true;
return 0;
}
@@ -235,13 +235,12 @@ uint8_t FileAccessEncrypted::get_8() const {
return b;
}
-int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const {
+uint64_t FileAccessEncrypted::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
- ERR_FAIL_COND_V(p_length < 0, -1);
ERR_FAIL_COND_V_MSG(writing, -1, "File has not been opened in read mode.");
- int to_copy = MIN(p_length, data.size() - pos);
- for (int i = 0; i < to_copy; i++) {
+ uint64_t to_copy = MIN(p_length, get_len() - pos);
+ for (uint64_t i = 0; i < to_copy; i++) {
p_dst[i] = data[pos++];
}
@@ -256,16 +255,16 @@ Error FileAccessEncrypted::get_error() const {
return eofed ? ERR_FILE_EOF : OK;
}
-void FileAccessEncrypted::store_buffer(const uint8_t *p_src, int p_length) {
+void FileAccessEncrypted::store_buffer(const uint8_t *p_src, uint64_t p_length) {
ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
- if (pos < data.size()) {
- for (int i = 0; i < p_length; i++) {
+ if (pos < get_len()) {
+ for (uint64_t i = 0; i < p_length; i++) {
store_8(p_src[i]);
}
- } else if (pos == data.size()) {
+ } else if (pos == get_len()) {
data.resize(pos + p_length);
- for (int i = 0; i < p_length; i++) {
+ for (uint64_t i = 0; i < p_length; i++) {
data.write[pos + i] = p_src[i];
}
pos += p_length;
@@ -281,10 +280,10 @@ void FileAccessEncrypted::flush() {
void FileAccessEncrypted::store_8(uint8_t p_dest) {
ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
- if (pos < data.size()) {
+ if (pos < get_len()) {
data.write[pos] = p_dest;
pos++;
- } else if (pos == data.size()) {
+ } else if (pos == get_len()) {
data.push_back(p_dest);
pos++;
}
diff --git a/core/io/file_access_encrypted.h b/core/io/file_access_encrypted.h
index 969052d04f..8bea8c2585 100644
--- a/core/io/file_access_encrypted.h
+++ b/core/io/file_access_encrypted.h
@@ -47,10 +47,10 @@ private:
Vector<uint8_t> key;
bool writing = false;
FileAccess *file = nullptr;
- size_t base = 0;
- size_t length = 0;
+ uint64_t base = 0;
+ uint64_t length = 0;
Vector<uint8_t> data;
- mutable int pos = 0;
+ mutable uint64_t pos = 0;
mutable bool eofed = false;
bool use_magic = true;
@@ -68,21 +68,21 @@ public:
virtual String get_path() const; /// returns the path for the current open file
virtual String get_path_absolute() const; /// returns the absolute path for the current open file
- virtual void seek(size_t p_position); ///< seek to a given position
+ virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
- virtual size_t get_position() const; ///< get position in the file
- virtual size_t get_len() const; ///< get size of the file
+ virtual uint64_t get_position() const; ///< get position in the file
+ virtual uint64_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte
- virtual int get_buffer(uint8_t *p_dst, int p_length) const;
+ virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const;
virtual Error get_error() const; ///< get last error
virtual void flush();
virtual void store_8(uint8_t p_dest); ///< store a byte
- virtual void store_buffer(const uint8_t *p_src, int p_length); ///< store an array of bytes
+ virtual void store_buffer(const uint8_t *p_src, uint64_t 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_memory.cpp b/core/io/file_access_memory.cpp
index af155a77a8..14e24d6668 100644
--- a/core/io/file_access_memory.cpp
+++ b/core/io/file_access_memory.cpp
@@ -71,7 +71,7 @@ bool FileAccessMemory::file_exists(const String &p_name) {
return files && (files->find(name) != nullptr);
}
-Error FileAccessMemory::open_custom(const uint8_t *p_data, int p_len) {
+Error FileAccessMemory::open_custom(const uint8_t *p_data, uint64_t p_len) {
data = (uint8_t *)p_data;
length = p_len;
pos = 0;
@@ -102,7 +102,7 @@ bool FileAccessMemory::is_open() const {
return data != nullptr;
}
-void FileAccessMemory::seek(size_t p_position) {
+void FileAccessMemory::seek(uint64_t p_position) {
ERR_FAIL_COND(!data);
pos = p_position;
}
@@ -112,12 +112,12 @@ void FileAccessMemory::seek_end(int64_t p_position) {
pos = length + p_position;
}
-size_t FileAccessMemory::get_position() const {
+uint64_t FileAccessMemory::get_position() const {
ERR_FAIL_COND_V(!data, 0);
return pos;
}
-size_t FileAccessMemory::get_len() const {
+uint64_t FileAccessMemory::get_len() const {
ERR_FAIL_COND_V(!data, 0);
return length;
}
@@ -136,13 +136,12 @@ uint8_t FileAccessMemory::get_8() const {
return ret;
}
-int FileAccessMemory::get_buffer(uint8_t *p_dst, int p_length) const {
+uint64_t FileAccessMemory::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
- ERR_FAIL_COND_V(p_length < 0, -1);
ERR_FAIL_COND_V(!data, -1);
- int left = length - pos;
- int read = MIN(p_length, left);
+ uint64_t left = length - pos;
+ uint64_t read = MIN(p_length, left);
if (read < p_length) {
WARN_PRINT("Reading less data than requested");
@@ -168,9 +167,9 @@ void FileAccessMemory::store_8(uint8_t p_byte) {
data[pos++] = p_byte;
}
-void FileAccessMemory::store_buffer(const uint8_t *p_src, int p_length) {
- int left = length - pos;
- int write = MIN(p_length, left);
+void FileAccessMemory::store_buffer(const uint8_t *p_src, uint64_t p_length) {
+ uint64_t left = length - pos;
+ uint64_t write = MIN(p_length, left);
if (write < p_length) {
WARN_PRINT("Writing less data than requested");
}
diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h
index 0e3b0ad7b1..cc589dc259 100644
--- a/core/io/file_access_memory.h
+++ b/core/io/file_access_memory.h
@@ -35,8 +35,8 @@
class FileAccessMemory : public FileAccess {
uint8_t *data = nullptr;
- int length = 0;
- mutable int pos = 0;
+ uint64_t length = 0;
+ mutable uint64_t pos = 0;
static FileAccess *create();
@@ -44,27 +44,27 @@ public:
static void register_file(String p_name, Vector<uint8_t> p_data);
static void cleanup();
- virtual Error open_custom(const uint8_t *p_data, int p_len); ///< open a file
+ virtual Error open_custom(const uint8_t *p_data, uint64_t p_len); ///< open a file
virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file
virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open
- virtual void seek(size_t p_position); ///< seek to a given position
+ virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position); ///< seek from the end of file
- virtual size_t get_position() const; ///< get position in the file
- virtual size_t get_len() const; ///< get size of the file
+ virtual uint64_t get_position() const; ///< get position in the file
+ virtual uint64_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte
- virtual int get_buffer(uint8_t *p_dst, int p_length) const; ///< get an array of bytes
+ virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const; ///< get an array of bytes
virtual Error get_error() const; ///< get last error
virtual void flush();
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 void store_buffer(const uint8_t *p_src, uint64_t 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_network.cpp b/core/io/file_access_network.cpp
index 4cc73bcd22..dedd5523ed 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -126,7 +126,7 @@ void FileAccessNetworkClient::_thread_func() {
if (status != OK) {
fa->_respond(0, Error(status));
} else {
- uint64_t len = get_64();
+ int64_t len = get_64();
fa->_respond(len, Error(status));
}
@@ -135,7 +135,7 @@ void FileAccessNetworkClient::_thread_func() {
} break;
case FileAccessNetwork::RESPONSE_DATA: {
int64_t offset = get_64();
- uint32_t len = get_32();
+ int32_t len = get_32();
Vector<uint8_t> block;
block.resize(len);
@@ -219,13 +219,13 @@ FileAccessNetworkClient::~FileAccessNetworkClient() {
thread.wait_to_finish();
}
-void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) {
- int page = p_offset / page_size;
+void FileAccessNetwork::_set_block(uint64_t p_offset, const Vector<uint8_t> &p_block) {
+ int32_t page = p_offset / page_size;
ERR_FAIL_INDEX(page, pages.size());
if (page < pages.size() - 1) {
ERR_FAIL_COND(p_block.size() != page_size);
} else {
- ERR_FAIL_COND((p_block.size() != (int)(total_size % page_size)));
+ ERR_FAIL_COND((uint64_t)p_block.size() != total_size % page_size);
}
{
@@ -240,7 +240,7 @@ void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block)
}
}
-void FileAccessNetwork::_respond(size_t p_len, Error p_status) {
+void FileAccessNetwork::_respond(uint64_t p_len, Error p_status) {
DEBUG_PRINT("GOT RESPONSE - len: " + itos(p_len) + " status: " + itos(p_status));
response = p_status;
if (response != OK) {
@@ -248,7 +248,7 @@ void FileAccessNetwork::_respond(size_t p_len, Error p_status) {
}
opened = true;
total_size = p_len;
- int pc = ((total_size - 1) / page_size) + 1;
+ int32_t pc = ((total_size - 1) / page_size) + 1;
pages.resize(pc);
}
@@ -307,8 +307,9 @@ bool FileAccessNetwork::is_open() const {
return opened;
}
-void FileAccessNetwork::seek(size_t p_position) {
+void FileAccessNetwork::seek(uint64_t p_position) {
ERR_FAIL_COND_MSG(!opened, "File must be opened before use.");
+
eof_flag = p_position > total_size;
if (p_position >= total_size) {
@@ -322,12 +323,12 @@ void FileAccessNetwork::seek_end(int64_t p_position) {
seek(total_size + p_position);
}
-size_t FileAccessNetwork::get_position() const {
+uint64_t FileAccessNetwork::get_position() const {
ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use.");
return pos;
}
-size_t FileAccessNetwork::get_len() const {
+uint64_t FileAccessNetwork::get_len() const {
ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use.");
return total_size;
}
@@ -343,7 +344,7 @@ uint8_t FileAccessNetwork::get_8() const {
return v;
}
-void FileAccessNetwork::_queue_page(int p_page) const {
+void FileAccessNetwork::_queue_page(int32_t p_page) const {
if (p_page >= pages.size()) {
return;
}
@@ -354,7 +355,7 @@ void FileAccessNetwork::_queue_page(int p_page) const {
FileAccessNetworkClient::BlockRequest br;
br.id = id;
- br.offset = size_t(p_page) * page_size;
+ br.offset = (uint64_t)p_page * page_size;
br.size = page_size;
nc->block_requests.push_back(br);
pages.write[p_page].queued = true;
@@ -365,11 +366,9 @@ void FileAccessNetwork::_queue_page(int p_page) const {
}
}
-int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
+uint64_t FileAccessNetwork::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
- ERR_FAIL_COND_V(p_length < 0, -1);
- //bool eof=false;
if (pos + p_length > total_size) {
eof_flag = true;
}
@@ -377,18 +376,16 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
p_length = total_size - pos;
}
- //FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
-
uint8_t *buff = last_page_buff;
- for (int i = 0; i < p_length; i++) {
- int page = pos / page_size;
+ for (uint64_t i = 0; i < p_length; i++) {
+ int32_t page = pos / page_size;
if (page != last_page) {
buffer_mutex.lock();
if (pages[page].buffer.is_empty()) {
waiting_on_page = page;
- for (int j = 0; j < read_ahead; j++) {
+ for (int32_t j = 0; j < read_ahead; j++) {
_queue_page(page + j);
}
buffer_mutex.unlock();
@@ -396,10 +393,9 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
page_sem.wait();
DEBUG_PRINT("done");
} else {
- for (int j = 0; j < read_ahead; j++) {
+ for (int32_t j = 0; j < read_ahead; j++) {
_queue_page(page + j);
}
- //queue pages
buffer_mutex.unlock();
}
diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h
index 1f5de3e5dd..4810cca195 100644
--- a/core/io/file_access_network.h
+++ b/core/io/file_access_network.h
@@ -40,9 +40,9 @@ class FileAccessNetwork;
class FileAccessNetworkClient {
struct BlockRequest {
- int id;
+ int32_t id;
uint64_t offset;
- int size;
+ int32_t size;
};
List<BlockRequest> block_requests;
@@ -54,17 +54,17 @@ class FileAccessNetworkClient {
Mutex blockrequest_mutex;
Map<int, FileAccessNetwork *> accesses;
Ref<StreamPeerTCP> client;
- int last_id = 0;
- int lockcount = 0;
+ int32_t last_id = 0;
+ int32_t lockcount = 0;
Vector<uint8_t> block;
void _thread_func();
static void _thread_func(void *s);
- void put_32(int p_32);
+ void put_32(int32_t p_32);
void put_64(int64_t p_64);
- int get_32();
+ int32_t get_32();
int64_t get_64();
void lock_mutex();
void unlock_mutex();
@@ -86,15 +86,15 @@ class FileAccessNetwork : public FileAccess {
Semaphore page_sem;
Mutex buffer_mutex;
bool opened = false;
- size_t total_size;
- mutable size_t pos = 0;
- int id;
+ uint64_t total_size;
+ mutable uint64_t pos = 0;
+ int32_t id;
mutable bool eof_flag = false;
- mutable int last_page = -1;
+ mutable int32_t last_page = -1;
mutable uint8_t *last_page_buff = nullptr;
- int page_size;
- int read_ahead;
+ int32_t page_size;
+ int32_t read_ahead;
mutable int waiting_on_page = -1;
@@ -110,9 +110,9 @@ class FileAccessNetwork : public FileAccess {
uint64_t exists_modtime;
friend class FileAccessNetworkClient;
- void _queue_page(int p_page) const;
- void _respond(size_t p_len, Error p_status);
- void _set_block(int p_offset, const Vector<uint8_t> &p_block);
+ void _queue_page(int32_t p_page) const;
+ void _respond(uint64_t p_len, Error p_status);
+ void _set_block(uint64_t p_offset, const Vector<uint8_t> &p_block);
public:
enum Command {
@@ -134,15 +134,15 @@ public:
virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open
- virtual void seek(size_t p_position); ///< seek to a given position
+ virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
- virtual size_t get_position() const; ///< get position in the file
- virtual size_t get_len() const; ///< get size of the file
+ virtual uint64_t get_position() const; ///< get position in the file
+ virtual uint64_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte
- virtual int get_buffer(uint8_t *p_dst, int p_length) const;
+ virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const;
virtual Error get_error() const; ///< get last error
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index e24dc40166..3e1c51b733 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -36,7 +36,7 @@
#include <stdio.h>
-Error PackedData::add_pack(const String &p_path, bool p_replace_files, size_t p_offset) {
+Error PackedData::add_pack(const String &p_path, bool p_replace_files, uint64_t p_offset) {
for (int i = 0; i < sources.size(); i++) {
if (sources[i]->try_open_pack(p_path, p_replace_files, p_offset)) {
return OK;
@@ -46,17 +46,16 @@ Error PackedData::add_pack(const String &p_path, bool p_replace_files, size_t p_
return ERR_FILE_UNRECOGNIZED;
}
-void PackedData::add_path(const String &pkg_path, const String &path, uint64_t ofs, uint64_t size, const uint8_t *p_md5, PackSource *p_src, bool p_replace_files, bool p_encrypted) {
- PathMD5 pmd5(path.md5_buffer());
- //printf("adding path %s, %lli, %lli\n", path.utf8().get_data(), pmd5.a, pmd5.b);
+void PackedData::add_path(const String &p_pkg_path, const String &p_path, uint64_t p_ofs, uint64_t p_size, const uint8_t *p_md5, PackSource *p_src, bool p_replace_files, bool p_encrypted) {
+ PathMD5 pmd5(p_path.md5_buffer());
bool exists = files.has(pmd5);
PackedFile pf;
pf.encrypted = p_encrypted;
- pf.pack = pkg_path;
- pf.offset = ofs;
- pf.size = size;
+ pf.pack = p_pkg_path;
+ pf.offset = p_ofs;
+ pf.size = p_size;
for (int i = 0; i < 16; i++) {
pf.md5[i] = p_md5[i];
}
@@ -68,7 +67,7 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o
if (!exists) {
//search for dir
- String p = path.replace_first("res://", "");
+ String p = p_path.replace_first("res://", "");
PackedDir *cd = root;
if (p.find("/") != -1) { //in a subdir
@@ -87,7 +86,7 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o
}
}
}
- String filename = path.get_file();
+ String filename = p_path.get_file();
// Don't add as a file if the path points to a directory
if (!filename.is_empty()) {
cd->files.insert(filename);
@@ -126,7 +125,7 @@ PackedData::~PackedData() {
//////////////////////////////////////////////////////////////////
-bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset) {
+bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) {
return false;
@@ -261,7 +260,7 @@ bool FileAccessPack::is_open() const {
return f->is_open();
}
-void FileAccessPack::seek(size_t p_position) {
+void FileAccessPack::seek(uint64_t p_position) {
if (p_position > pf.size) {
eof = true;
} else {
@@ -276,11 +275,11 @@ void FileAccessPack::seek_end(int64_t p_position) {
seek(pf.size + p_position);
}
-size_t FileAccessPack::get_position() const {
+uint64_t FileAccessPack::get_position() const {
return pos;
}
-size_t FileAccessPack::get_len() const {
+uint64_t FileAccessPack::get_len() const {
return pf.size;
}
@@ -298,18 +297,17 @@ uint8_t FileAccessPack::get_8() const {
return f->get_8();
}
-int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const {
+uint64_t FileAccessPack::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
- ERR_FAIL_COND_V(p_length < 0, -1);
if (eof) {
return 0;
}
- uint64_t to_read = p_length;
+ int64_t to_read = p_length;
if (to_read + pos > pf.size) {
eof = true;
- to_read = int64_t(pf.size) - int64_t(pos);
+ to_read = (int64_t)pf.size - (int64_t)pos;
}
pos += p_length;
@@ -342,7 +340,7 @@ void FileAccessPack::store_8(uint8_t p_dest) {
ERR_FAIL();
}
-void FileAccessPack::store_buffer(const uint8_t *p_src, int p_length) {
+void FileAccessPack::store_buffer(const uint8_t *p_src, uint64_t p_length) {
ERR_FAIL();
}
@@ -549,7 +547,7 @@ Error DirAccessPack::remove(String p_name) {
return ERR_UNAVAILABLE;
}
-size_t DirAccessPack::get_space_left() {
+uint64_t DirAccessPack::get_space_left() {
return 0;
}
diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h
index 955108f455..e47c9ea543 100644
--- a/core/io/file_access_pack.h
+++ b/core/io/file_access_pack.h
@@ -112,13 +112,13 @@ private:
public:
void add_pack_source(PackSource *p_source);
- void add_path(const String &pkg_path, const String &path, uint64_t ofs, uint64_t size, const uint8_t *p_md5, PackSource *p_src, bool p_replace_files, bool p_encrypted = false); // for PackSource
+ void add_path(const String &p_pkg_path, const String &p_path, uint64_t p_ofs, uint64_t p_size, const uint8_t *p_md5, PackSource *p_src, bool p_replace_files, bool p_encrypted = false); // for PackSource
void set_disabled(bool p_disabled) { disabled = p_disabled; }
_FORCE_INLINE_ bool is_disabled() const { return disabled; }
static PackedData *get_singleton() { return singleton; }
- Error add_pack(const String &p_path, bool p_replace_files, size_t p_offset);
+ Error add_pack(const String &p_path, bool p_replace_files, uint64_t p_offset);
_FORCE_INLINE_ FileAccess *try_open_path(const String &p_path);
_FORCE_INLINE_ bool has_path(const String &p_path);
@@ -132,21 +132,21 @@ public:
class PackSource {
public:
- virtual bool try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset) = 0;
+ virtual bool try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset) = 0;
virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file) = 0;
virtual ~PackSource() {}
};
class PackedSourcePCK : public PackSource {
public:
- virtual bool try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset);
+ virtual bool try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset);
virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file);
};
class FileAccessPack : public FileAccess {
PackedData::PackedFile pf;
- mutable size_t pos;
+ mutable uint64_t pos;
mutable bool eof;
uint64_t off;
@@ -160,16 +160,16 @@ public:
virtual void close();
virtual bool is_open() const;
- virtual void seek(size_t p_position);
+ virtual void seek(uint64_t p_position);
virtual void seek_end(int64_t p_position = 0);
- virtual size_t get_position() const;
- virtual size_t get_len() const;
+ virtual uint64_t get_position() const;
+ virtual uint64_t get_len() const;
virtual bool eof_reached() const;
virtual uint8_t get_8() const;
- virtual int get_buffer(uint8_t *p_dst, int p_length) const;
+ virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const;
virtual void set_endian_swap(bool p_swap);
@@ -178,7 +178,7 @@ public:
virtual void flush();
virtual void store_8(uint8_t p_dest);
- virtual void store_buffer(const uint8_t *p_src, int p_length);
+ virtual void store_buffer(const uint8_t *p_src, uint64_t p_length);
virtual bool file_exists(const String &p_name);
@@ -243,7 +243,7 @@ public:
virtual Error rename(String p_from, String p_to);
virtual Error remove(String p_name);
- size_t get_space_left();
+ uint64_t get_space_left();
virtual String get_filesystem_type() const;
diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp
index dbedb5254f..304e24ee90 100644
--- a/core/io/file_access_zip.cpp
+++ b/core/io/file_access_zip.cpp
@@ -67,7 +67,7 @@ static long godot_tell(voidpf opaque, voidpf stream) {
static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
FileAccess *f = (FileAccess *)stream;
- int pos = offset;
+ uint64_t pos = offset;
switch (origin) {
case ZLIB_FILEFUNC_SEEK_CUR:
pos = f->get_position() + offset;
@@ -144,8 +144,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const {
return pkg;
}
-bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset = 0) {
- //printf("opening zip pack %s, %i, %i\n", p_name.utf8().get_data(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz"));
+bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset = 0) {
// load with offset feature only supported for PCK files
ERR_FAIL_COND_V_MSG(p_offset != 0, false, "Invalid PCK data. Note that loading files with a non-zero offset isn't supported with ZIP archives.");
@@ -265,8 +264,9 @@ bool FileAccessZip::is_open() const {
return zfile != nullptr;
}
-void FileAccessZip::seek(size_t p_position) {
+void FileAccessZip::seek(uint64_t p_position) {
ERR_FAIL_COND(!zfile);
+
unzSeekCurrentFile(zfile, p_position);
}
@@ -275,12 +275,12 @@ void FileAccessZip::seek_end(int64_t p_position) {
unzSeekCurrentFile(zfile, get_len() + p_position);
}
-size_t FileAccessZip::get_position() const {
+uint64_t FileAccessZip::get_position() const {
ERR_FAIL_COND_V(!zfile, 0);
return unztell(zfile);
}
-size_t FileAccessZip::get_len() const {
+uint64_t FileAccessZip::get_len() const {
ERR_FAIL_COND_V(!zfile, 0);
return file_info.uncompressed_size;
}
@@ -297,17 +297,17 @@ uint8_t FileAccessZip::get_8() const {
return ret;
}
-int FileAccessZip::get_buffer(uint8_t *p_dst, int p_length) const {
+uint64_t FileAccessZip::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
- ERR_FAIL_COND_V(p_length < 0, -1);
ERR_FAIL_COND_V(!zfile, -1);
+
at_eof = unzeof(zfile);
if (at_eof) {
return 0;
}
- int read = unzReadCurrentFile(zfile, p_dst, p_length);
+ int64_t read = unzReadCurrentFile(zfile, p_dst, p_length);
ERR_FAIL_COND_V(read < 0, read);
- if (read < p_length) {
+ if ((uint64_t)read < p_length) {
at_eof = true;
}
return read;
diff --git a/core/io/file_access_zip.h b/core/io/file_access_zip.h
index 8559f871ce..91bdaafb68 100644
--- a/core/io/file_access_zip.h
+++ b/core/io/file_access_zip.h
@@ -67,7 +67,7 @@ public:
bool file_exists(String p_name) const;
- virtual bool try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset);
+ virtual bool try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset);
FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file);
static ZipArchive *get_singleton();
@@ -87,20 +87,21 @@ public:
virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open
- virtual void seek(size_t p_position); ///< seek to a given position
+ virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
- virtual size_t get_position() const; ///< get position in the file
- virtual size_t get_len() const; ///< get size of the file
+ virtual uint64_t get_position() const; ///< get position in the file
+ virtual uint64_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte
- virtual int get_buffer(uint8_t *p_dst, int p_length) const;
+ virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const;
virtual Error get_error() const; ///< get last error
virtual void flush();
virtual void store_8(uint8_t p_dest); ///< store a byte
+
virtual bool file_exists(const String &p_name); ///< return true if a file exists
virtual uint64_t _get_modified_time(const String &p_file) { return 0; } // todo
diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp
index a0697ca18b..4fe22e57d8 100644
--- a/core/io/pck_packer.cpp
+++ b/core/io/pck_packer.cpp
@@ -236,7 +236,7 @@ Error PCKPacker::flush(bool p_verbose) {
}
while (to_write > 0) {
- int read = src->get_buffer(buf, MIN(to_write, buf_max));
+ uint64_t read = src->get_buffer(buf, MIN(to_write, buf_max));
ftmp->store_buffer(buf, read);
to_write -= read;
}
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index c4eb2a20bb..50c9b2371a 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -1157,8 +1157,8 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
save_ustring(fw, get_ustring(f)); //type
- size_t md_ofs = f->get_position();
- size_t importmd_ofs = f->get_64();
+ uint64_t md_ofs = f->get_position();
+ uint64_t importmd_ofs = f->get_64();
fw->store_64(0); //metadata offset
for (int i = 0; i < 14; i++) {
diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp
index fe46868dd0..e0e491dc85 100644
--- a/core/io/zip_io.cpp
+++ b/core/io/zip_io.cpp
@@ -68,7 +68,7 @@ long zipio_tell(voidpf opaque, voidpf stream) {
long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
FileAccess *f = *(FileAccess **)opaque;
- int pos = offset;
+ uint64_t pos = offset;
switch (origin) {
case ZLIB_FILEFUNC_SEEK_CUR:
pos = f->get_position() + offset;