Make all file access 64-bit (uint64_t)

This changes the types of a big number of variables.

General rules:
- Using `uint64_t` in general. We also considered `int64_t` but eventually
  settled on keeping it unsigned, which is also closer to what one would expect
  with `size_t`/`off_t`.
- We only keep `int64_t` for `seek_end` (takes a negative offset from the end)
  and for the `Variant` bindings, since `Variant::INT` is `int64_t`. This means
  we only need to guard against passing negative values in `core_bind.cpp`.
- Using `uint32_t` integers for concepts not needing such a huge range, like
  pages, blocks, etc.

In addition:
- Improve usage of integer types in some related places; namely, `DirAccess`,
  core binds.

Note:
- On Windows, `_ftelli64` reports invalid values when using 32-bit MinGW with
  version < 8.0. This was an upstream bug fixed in 8.0. It breaks support for
  big files on 32-bit Windows builds made with that toolchain. We might add a
  workaround.

Fixes #44363.
Fixes godotengine/godot-proposals#400.

Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
This commit is contained in:
Pedro J. Estébanez 2019-03-26 18:51:13 +01:00 committed by Rémi Verschelde
parent 74174676b8
commit 817ffc01e1
No known key found for this signature in database
GPG Key ID: C3336907360768E1
66 changed files with 353 additions and 364 deletions

View File

@ -1900,18 +1900,21 @@ String _File::get_path_absolute() const {
void _File::seek(int64_t p_position) { void _File::seek(int64_t p_position) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use."); ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
ERR_FAIL_COND_MSG(p_position < 0, "Seek position must be a positive integer.");
f->seek(p_position); f->seek(p_position);
} }
void _File::seek_end(int64_t p_position) { void _File::seek_end(int64_t p_position) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use."); ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->seek_end(p_position); f->seek_end(p_position);
} }
int64_t _File::get_position() const {
uint64_t _File::get_position() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_position(); return f->get_position();
} }
int64_t _File::get_len() const { uint64_t _File::get_len() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_len(); return f->get_len();
} }
@ -1951,7 +1954,7 @@ real_t _File::get_real() const {
return f->get_real(); return f->get_real();
} }
PoolVector<uint8_t> _File::get_buffer(int p_length) const { PoolVector<uint8_t> _File::get_buffer(int64_t p_length) const {
PoolVector<uint8_t> data; PoolVector<uint8_t> data;
ERR_FAIL_COND_V_MSG(!f, data, "File must be opened before use."); ERR_FAIL_COND_V_MSG(!f, data, "File must be opened before use.");
@ -1964,7 +1967,7 @@ PoolVector<uint8_t> _File::get_buffer(int p_length) const {
ERR_FAIL_COND_V_MSG(err != OK, data, "Can't resize data to " + itos(p_length) + " elements."); ERR_FAIL_COND_V_MSG(err != OK, data, "Can't resize data to " + itos(p_length) + " elements.");
PoolVector<uint8_t>::Write w = data.write(); PoolVector<uint8_t>::Write w = data.write();
int len = f->get_buffer(&w[0], p_length); int64_t len = f->get_buffer(&w[0], p_length);
ERR_FAIL_COND_V(len < 0, PoolVector<uint8_t>()); ERR_FAIL_COND_V(len < 0, PoolVector<uint8_t>());
w.release(); w.release();
@ -1980,7 +1983,7 @@ String _File::get_as_text() const {
ERR_FAIL_COND_V_MSG(!f, String(), "File must be opened before use."); ERR_FAIL_COND_V_MSG(!f, String(), "File must be opened before use.");
String text; String text;
size_t original_pos = f->get_position(); uint64_t original_pos = f->get_position();
f->seek(0); f->seek(0);
String l = get_line(); String l = get_line();
@ -2103,7 +2106,7 @@ void _File::store_csv_line(const Vector<String> &p_values, const String &p_delim
void _File::store_buffer(const PoolVector<uint8_t> &p_buffer) { void _File::store_buffer(const PoolVector<uint8_t> &p_buffer) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use."); ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
int len = p_buffer.size(); uint64_t len = p_buffer.size();
if (len == 0) { if (len == 0) {
return; return;
} }
@ -2341,9 +2344,9 @@ bool _Directory::dir_exists(String p_dir) {
} }
} }
int _Directory::get_space_left() { uint64_t _Directory::get_space_left() {
ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use."); ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
return d->get_space_left() / 1024 * 1024; //return value in megabytes, given binding is int return d->get_space_left() / 1024 * 1024; // Truncate to closest MiB.
} }
Error _Directory::copy(String p_from, String p_to) { Error _Directory::copy(String p_from, String p_to) {

View File

@ -516,8 +516,8 @@ public:
void seek(int64_t p_position); // Seek to a given position. void seek(int64_t p_position); // Seek to a given position.
void seek_end(int64_t p_position = 0); // Seek from the end of file. void seek_end(int64_t p_position = 0); // Seek from the end of file.
int64_t get_position() const; // Get position in the file. uint64_t get_position() const; // Get position in the file.
int64_t get_len() const; // Get size of the file. uint64_t get_len() const; // Get size of the file.
bool eof_reached() const; // Reading passed EOF. bool eof_reached() const; // Reading passed EOF.
@ -532,7 +532,7 @@ public:
Variant get_var(bool p_allow_objects = false) const; Variant get_var(bool p_allow_objects = false) const;
PoolVector<uint8_t> get_buffer(int p_length) const; // Get an array of bytes. PoolVector<uint8_t> get_buffer(int64_t p_length) const; // Get an array of bytes.
String get_line() const; String get_line() const;
Vector<String> get_csv_line(const String &p_delim = ",") const; Vector<String> get_csv_line(const String &p_delim = ",") const;
String get_as_text() const; String get_as_text() const;
@ -609,7 +609,7 @@ public:
bool file_exists(String p_file); bool file_exists(String p_file);
bool dir_exists(String p_dir); bool dir_exists(String p_dir);
int get_space_left(); uint64_t get_space_left();
Error copy(String p_from, String p_to); Error copy(String p_from, String p_to);
Error rename(String p_from, String p_to); Error rename(String p_from, String p_to);

View File

@ -32,7 +32,7 @@
#include "core/print_string.h" #include "core/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(); magic = p_magic.ascii().get_data();
if (magic.length() > 4) { if (magic.length() > 4) {
magic = magic.substr(0, 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."); 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(); read_total = f->get_32();
int bc = (read_total / block_size) + 1; uint32_t bc = (read_total / block_size) + 1;
int acc_ofs = f->get_position() + bc * 4; uint64_t acc_ofs = f->get_position() + bc * 4;
int max_bs = 0; uint32_t max_bs = 0;
for (int i = 0; i < bc; i++) { for (uint32_t i = 0; i < bc; i++) {
ReadBlock rb; ReadBlock rb;
rb.offset = acc_ofs; rb.offset = acc_ofs;
rb.csize = f->get_32(); rb.csize = f->get_32();
@ -147,15 +147,15 @@ void FileAccessCompressed::close() {
f->store_32(cmode); //write compression mode 4 f->store_32(cmode); //write compression mode 4
f->store_32(block_size); //write block size 4 f->store_32(block_size); //write block size 4
f->store_32(write_max); //max amount of data written 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 f->store_32(0); //compressed sizes, will update later
} }
Vector<int> block_sizes; Vector<int> block_sizes;
for (int i = 0; i < bc; i++) { for (uint32_t i = 0; i < bc; i++) {
int bl = i == (bc - 1) ? write_max % block_size : block_size; uint32_t bl = i == (bc - 1) ? write_max % block_size : block_size;
uint8_t *bp = &write_ptr[i * block_size]; uint8_t *bp = &write_ptr[i * block_size];
Vector<uint8_t> cblock; Vector<uint8_t> cblock;
@ -167,7 +167,7 @@ void FileAccessCompressed::close() {
} }
f->seek(16); //ok write block sizes 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->store_32(block_sizes[i]);
} }
f->seek_end(); f->seek_end();
@ -189,8 +189,9 @@ bool FileAccessCompressed::is_open() const {
return f != nullptr; 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."); ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
if (writing) { if (writing) {
ERR_FAIL_COND(p_position > write_max); ERR_FAIL_COND(p_position > write_max);
@ -203,7 +204,7 @@ void FileAccessCompressed::seek(size_t p_position) {
} else { } else {
at_end = false; at_end = false;
read_eof = false; read_eof = false;
int block_idx = p_position / block_size; uint32_t block_idx = p_position / block_size;
if (block_idx != read_block) { if (block_idx != read_block) {
read_block = block_idx; read_block = block_idx;
f->seek(read_blocks[read_block].offset); f->seek(read_blocks[read_block].offset);
@ -225,7 +226,8 @@ void FileAccessCompressed::seek_end(int64_t p_position) {
seek(read_total + p_position); seek(read_total + 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."); ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
if (writing) { if (writing) {
return write_pos; return write_pos;
@ -233,7 +235,8 @@ size_t FileAccessCompressed::get_position() const {
return read_block * block_size + read_pos; return read_block * block_size + read_pos;
} }
} }
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."); ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
if (writing) { if (writing) {
return write_max; return write_max;
@ -281,9 +284,9 @@ uint8_t FileAccessCompressed::get_8() const {
return ret; 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_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(!f, -1, "File must be opened before use.");
ERR_FAIL_COND_V_MSG(writing, -1, "File has not been opened in read mode."); ERR_FAIL_COND_V_MSG(writing, -1, "File has not been opened in read mode.");
@ -292,7 +295,7 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
return 0; 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]; p_dst[i] = read_ptr[read_pos];
read_pos++; read_pos++;
if (read_pos >= read_block_size) { if (read_pos >= read_block_size) {

View File

@ -37,34 +37,34 @@
class FileAccessCompressed : public FileAccess { class FileAccessCompressed : public FileAccess {
Compression::Mode cmode; Compression::Mode cmode;
bool writing; bool writing;
uint32_t write_pos; uint64_t write_pos;
uint8_t *write_ptr; uint8_t *write_ptr;
uint32_t write_buffer_size; uint32_t write_buffer_size;
uint32_t write_max; uint64_t write_max;
uint32_t block_size; uint32_t block_size;
mutable bool read_eof; mutable bool read_eof;
mutable bool at_end; mutable bool at_end;
struct ReadBlock { struct ReadBlock {
int csize; uint32_t csize;
int offset; uint64_t offset;
}; };
mutable Vector<uint8_t> comp_buffer; mutable Vector<uint8_t> comp_buffer;
uint8_t *read_ptr; uint8_t *read_ptr;
mutable int read_block; mutable uint32_t read_block;
int read_block_count; uint32_t read_block_count;
mutable int read_block_size; mutable uint32_t read_block_size;
mutable int read_pos; mutable uint64_t read_pos;
Vector<ReadBlock> read_blocks; Vector<ReadBlock> read_blocks;
uint32_t read_total; uint64_t read_total;
String magic; String magic;
mutable Vector<uint8_t> buffer; mutable Vector<uint8_t> buffer;
FileAccess *f; FileAccess *f;
public: 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); Error open_after_magic(FileAccess *p_base);
@ -72,15 +72,15 @@ public:
virtual void close(); ///< close a file virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open 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 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 uint64_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file virtual uint64_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte 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 Error get_error() const; ///< get last error

View File

@ -67,20 +67,20 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
length = p_base->get_64(); length = p_base->get_64();
base = p_base->get_position(); base = p_base->get_position();
ERR_FAIL_COND_V(p_base->get_len() < base + length, ERR_FILE_CORRUPT); ERR_FAIL_COND_V(p_base->get_len() < base + length, ERR_FILE_CORRUPT);
uint32_t ds = length; uint64_t ds = length;
if (ds % 16) { if (ds % 16) {
ds += 16 - (ds % 16); ds += 16 - (ds % 16);
} }
data.resize(ds); 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); ERR_FAIL_COND_V(blen != ds, ERR_FILE_CORRUPT);
CryptoCore::AESContext ctx; CryptoCore::AESContext ctx;
ctx.set_decode_key(key.ptrw(), 256); ctx.set_decode_key(key.ptrw(), 256);
for (size_t i = 0; i < ds; i += 16) { for (uint64_t i = 0; i < ds; i += 16) {
ctx.decrypt_ecb(&data.write[i], &data.write[i]); ctx.decrypt_ecb(&data.write[i], &data.write[i]);
} }
@ -119,7 +119,7 @@ void FileAccessEncrypted::close() {
if (writing) { if (writing) {
Vector<uint8_t> compressed; Vector<uint8_t> compressed;
size_t len = data.size(); uint64_t len = data.size();
if (len % 16) { if (len % 16) {
len += 16 - (len % 16); len += 16 - (len % 16);
} }
@ -136,7 +136,7 @@ void FileAccessEncrypted::close() {
CryptoCore::AESContext ctx; CryptoCore::AESContext ctx;
ctx.set_encode_key(key.ptrw(), 256); ctx.set_encode_key(key.ptrw(), 256);
for (size_t i = 0; i < len; i += 16) { for (uint64_t i = 0; i < len; i += 16) {
ctx.encrypt_ecb(&compressed.write[i], &compressed.write[i]); ctx.encrypt_ecb(&compressed.write[i], &compressed.write[i]);
} }
@ -180,9 +180,9 @@ String FileAccessEncrypted::get_path_absolute() const {
} }
} }
void FileAccessEncrypted::seek(size_t p_position) { void FileAccessEncrypted::seek(uint64_t p_position) {
if (p_position > (size_t)data.size()) { if (p_position > get_len()) {
p_position = data.size(); p_position = get_len();
} }
pos = p_position; pos = p_position;
@ -190,12 +190,14 @@ void FileAccessEncrypted::seek(size_t p_position) {
} }
void FileAccessEncrypted::seek_end(int64_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; return pos;
} }
size_t FileAccessEncrypted::get_len() const {
uint64_t FileAccessEncrypted::get_len() const {
return data.size(); return data.size();
} }
@ -205,7 +207,7 @@ bool FileAccessEncrypted::eof_reached() const {
uint8_t FileAccessEncrypted::get_8() const { uint8_t FileAccessEncrypted::get_8() const {
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode."); 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; eofed = true;
return 0; return 0;
} }
@ -215,13 +217,12 @@ uint8_t FileAccessEncrypted::get_8() const {
return b; 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_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."); ERR_FAIL_COND_V_MSG(writing, -1, "File has not been opened in read mode.");
int to_copy = MIN(p_length, data.size() - pos); uint64_t to_copy = MIN(p_length, get_len() - pos);
for (int i = 0; i < to_copy; i++) { for (uint64_t i = 0; i < to_copy; i++) {
p_dst[i] = data[pos++]; p_dst[i] = data[pos++];
} }
@ -236,16 +237,16 @@ Error FileAccessEncrypted::get_error() const {
return eofed ? ERR_FILE_EOF : OK; 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."); ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
if (pos < data.size()) { if (pos < get_len()) {
for (int i = 0; i < p_length; i++) { for (uint64_t i = 0; i < p_length; i++) {
store_8(p_src[i]); store_8(p_src[i]);
} }
} else if (pos == data.size()) { } else if (pos == get_len()) {
data.resize(pos + p_length); 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]; data.write[pos + i] = p_src[i];
} }
pos += p_length; pos += p_length;
@ -261,10 +262,10 @@ void FileAccessEncrypted::flush() {
void FileAccessEncrypted::store_8(uint8_t p_dest) { void FileAccessEncrypted::store_8(uint8_t p_dest) {
ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode."); 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; data.write[pos] = p_dest;
pos++; pos++;
} else if (pos == data.size()) { } else if (pos == get_len()) {
data.push_back(p_dest); data.push_back(p_dest);
pos++; pos++;
} }

View File

@ -46,10 +46,10 @@ private:
Vector<uint8_t> key; Vector<uint8_t> key;
bool writing; bool writing;
FileAccess *file; FileAccess *file;
size_t base; uint64_t base;
size_t length; uint64_t length;
Vector<uint8_t> data; Vector<uint8_t> data;
mutable int pos; mutable uint64_t pos;
mutable bool eofed; mutable bool eofed;
public: public:
@ -63,21 +63,21 @@ public:
virtual String get_path() const; /// returns the path for the current open file 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 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 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 uint64_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file virtual uint64_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte 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 Error get_error() const; ///< get last error
virtual void flush(); virtual void flush();
virtual void store_8(uint8_t p_dest); ///< store a byte 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 virtual bool file_exists(const String &p_name); ///< return true if a file exists

View File

@ -71,7 +71,7 @@ bool FileAccessMemory::file_exists(const String &p_name) {
return files && (files->find(name) != nullptr); 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; data = (uint8_t *)p_data;
length = p_len; length = p_len;
pos = 0; pos = 0;
@ -102,7 +102,7 @@ bool FileAccessMemory::is_open() const {
return data != nullptr; return data != nullptr;
} }
void FileAccessMemory::seek(size_t p_position) { void FileAccessMemory::seek(uint64_t p_position) {
ERR_FAIL_COND(!data); ERR_FAIL_COND(!data);
pos = p_position; pos = p_position;
} }
@ -112,12 +112,12 @@ void FileAccessMemory::seek_end(int64_t p_position) {
pos = length + p_position; pos = length + p_position;
} }
size_t FileAccessMemory::get_position() const { uint64_t FileAccessMemory::get_position() const {
ERR_FAIL_COND_V(!data, 0); ERR_FAIL_COND_V(!data, 0);
return pos; return pos;
} }
size_t FileAccessMemory::get_len() const { uint64_t FileAccessMemory::get_len() const {
ERR_FAIL_COND_V(!data, 0); ERR_FAIL_COND_V(!data, 0);
return length; return length;
} }
@ -136,17 +136,16 @@ uint8_t FileAccessMemory::get_8() const {
return ret; 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_dst && p_length > 0, -1);
ERR_FAIL_COND_V(p_length < 0, -1);
ERR_FAIL_COND_V(!data, -1); ERR_FAIL_COND_V(!data, -1);
int left = length - pos; uint64_t left = length - pos;
int read = MIN(p_length, left); uint64_t read = MIN(p_length, left);
if (read < p_length) { if (read < p_length) {
WARN_PRINT("Reading less data than requested"); WARN_PRINT("Reading less data than requested");
}; }
memcpy(p_dst, &data[pos], read); memcpy(p_dst, &data[pos], read);
pos += p_length; pos += p_length;
@ -168,9 +167,9 @@ void FileAccessMemory::store_8(uint8_t p_byte) {
data[pos++] = p_byte; data[pos++] = p_byte;
} }
void FileAccessMemory::store_buffer(const uint8_t *p_src, int p_length) { void FileAccessMemory::store_buffer(const uint8_t *p_src, uint64_t p_length) {
int left = length - pos; uint64_t left = length - pos;
int write = MIN(p_length, left); uint64_t write = MIN(p_length, left);
if (write < p_length) { if (write < p_length) {
WARN_PRINT("Writing less data than requested"); WARN_PRINT("Writing less data than requested");
} }

View File

@ -35,8 +35,8 @@
class FileAccessMemory : public FileAccess { class FileAccessMemory : public FileAccess {
uint8_t *data; uint8_t *data;
int length; uint64_t length;
mutable int pos; mutable uint64_t pos;
static FileAccess *create(); static FileAccess *create();
@ -44,27 +44,27 @@ public:
static void register_file(String p_name, Vector<uint8_t> p_data); static void register_file(String p_name, Vector<uint8_t> p_data);
static void cleanup(); 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 Error _open(const String &p_path, int p_mode_flags); ///< open a file
virtual void close(); ///< close a file virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open 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 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 uint64_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file virtual uint64_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte 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 Error get_error() const; ///< get last error
virtual void flush(); virtual void flush();
virtual void store_8(uint8_t p_byte); ///< 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 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 virtual bool file_exists(const String &p_name); ///< return true if a file exists

View File

@ -125,7 +125,7 @@ void FileAccessNetworkClient::_thread_func() {
if (status != OK) { if (status != OK) {
fa->_respond(0, Error(status)); fa->_respond(0, Error(status));
} else { } else {
uint64_t len = get_64(); int64_t len = get_64();
fa->_respond(len, Error(status)); fa->_respond(len, Error(status));
} }
@ -134,7 +134,7 @@ void FileAccessNetworkClient::_thread_func() {
} break; } break;
case FileAccessNetwork::RESPONSE_DATA: { case FileAccessNetwork::RESPONSE_DATA: {
int64_t offset = get_64(); int64_t offset = get_64();
uint32_t len = get_32(); int32_t len = get_32();
Vector<uint8_t> block; Vector<uint8_t> block;
block.resize(len); block.resize(len);
@ -223,13 +223,13 @@ FileAccessNetworkClient::~FileAccessNetworkClient() {
} }
} }
void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) { void FileAccessNetwork::_set_block(uint64_t p_offset, const Vector<uint8_t> &p_block) {
int page = p_offset / page_size; int32_t page = p_offset / page_size;
ERR_FAIL_INDEX(page, pages.size()); ERR_FAIL_INDEX(page, pages.size());
if (page < pages.size() - 1) { if (page < pages.size() - 1) {
ERR_FAIL_COND(p_block.size() != page_size); ERR_FAIL_COND(p_block.size() != page_size);
} else { } else {
ERR_FAIL_COND((p_block.size() != (int)(total_size % page_size))); ERR_FAIL_COND((uint64_t)p_block.size() != total_size % page_size);
} }
buffer_mutex.lock(); buffer_mutex.lock();
@ -243,7 +243,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)); DEBUG_PRINT("GOT RESPONSE - len: " + itos(p_len) + " status: " + itos(p_status));
response = p_status; response = p_status;
if (response != OK) { if (response != OK) {
@ -251,7 +251,7 @@ void FileAccessNetwork::_respond(size_t p_len, Error p_status) {
} }
opened = true; opened = true;
total_size = p_len; total_size = p_len;
int pc = ((total_size - 1) / page_size) + 1; int32_t pc = ((total_size - 1) / page_size) + 1;
pages.resize(pc); pages.resize(pc);
} }
@ -309,8 +309,9 @@ bool FileAccessNetwork::is_open() const {
return opened; 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."); ERR_FAIL_COND_MSG(!opened, "File must be opened before use.");
eof_flag = p_position > total_size; eof_flag = p_position > total_size;
if (p_position >= total_size) { if (p_position >= total_size) {
@ -323,11 +324,13 @@ void FileAccessNetwork::seek(size_t p_position) {
void FileAccessNetwork::seek_end(int64_t p_position) { void FileAccessNetwork::seek_end(int64_t p_position) {
seek(total_size + 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."); ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use.");
return pos; 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."); ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use.");
return total_size; return total_size;
} }
@ -343,7 +346,7 @@ uint8_t FileAccessNetwork::get_8() const {
return v; return v;
} }
void FileAccessNetwork::_queue_page(int p_page) const { void FileAccessNetwork::_queue_page(int32_t p_page) const {
if (p_page >= pages.size()) { if (p_page >= pages.size()) {
return; return;
} }
@ -353,7 +356,7 @@ void FileAccessNetwork::_queue_page(int p_page) const {
nc->blockrequest_mutex.lock(); nc->blockrequest_mutex.lock();
FileAccessNetworkClient::BlockRequest br; FileAccessNetworkClient::BlockRequest br;
br.id = id; br.id = id;
br.offset = size_t(p_page) * page_size; br.offset = (uint64_t)p_page * page_size;
br.size = page_size; br.size = page_size;
nc->block_requests.push_back(br); nc->block_requests.push_back(br);
pages.write[p_page].queued = true; pages.write[p_page].queued = true;
@ -364,11 +367,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_dst && p_length > 0, -1);
ERR_FAIL_COND_V(p_length < 0, -1);
//bool eof=false;
if (pos + p_length > total_size) { if (pos + p_length > total_size) {
eof_flag = true; eof_flag = true;
} }
@ -376,18 +377,16 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
p_length = total_size - pos; p_length = total_size - pos;
} }
//FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
uint8_t *buff = last_page_buff; uint8_t *buff = last_page_buff;
for (int i = 0; i < p_length; i++) { for (uint64_t i = 0; i < p_length; i++) {
int page = pos / page_size; int32_t page = pos / page_size;
if (page != last_page) { if (page != last_page) {
buffer_mutex.lock(); buffer_mutex.lock();
if (pages[page].buffer.empty()) { if (pages[page].buffer.empty()) {
waiting_on_page = page; 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); _queue_page(page + j);
} }
buffer_mutex.unlock(); buffer_mutex.unlock();
@ -395,10 +394,9 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
page_sem.wait(); page_sem.wait();
DEBUG_PRINT("done"); DEBUG_PRINT("done");
} else { } else {
for (int j = 0; j < read_ahead; j++) { for (int32_t j = 0; j < read_ahead; j++) {
_queue_page(page + j); _queue_page(page + j);
} }
//queue pages
buffer_mutex.unlock(); buffer_mutex.unlock();
} }
@ -486,7 +484,6 @@ FileAccessNetwork::FileAccessNetwork() {
nc->unlock_mutex(); nc->unlock_mutex();
page_size = GLOBAL_GET("network/remote_fs/page_size"); page_size = GLOBAL_GET("network/remote_fs/page_size");
read_ahead = GLOBAL_GET("network/remote_fs/page_read_ahead"); read_ahead = GLOBAL_GET("network/remote_fs/page_read_ahead");
last_activity_val = 0;
waiting_on_page = -1; waiting_on_page = -1;
last_page = -1; last_page = -1;
} }

View File

@ -40,9 +40,9 @@ class FileAccessNetwork;
class FileAccessNetworkClient { class FileAccessNetworkClient {
struct BlockRequest { struct BlockRequest {
int id; int32_t id;
uint64_t offset; uint64_t offset;
int size; int32_t size;
}; };
List<BlockRequest> block_requests; List<BlockRequest> block_requests;
@ -54,16 +54,16 @@ class FileAccessNetworkClient {
Mutex blockrequest_mutex; Mutex blockrequest_mutex;
Map<int, FileAccessNetwork *> accesses; Map<int, FileAccessNetwork *> accesses;
Ref<StreamPeerTCP> client; Ref<StreamPeerTCP> client;
int last_id; int32_t last_id;
Vector<uint8_t> block; Vector<uint8_t> block;
void _thread_func(); void _thread_func();
static void _thread_func(void *s); 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); void put_64(int64_t p_64);
int get_32(); int32_t get_32();
int64_t get_64(); int64_t get_64();
int lockcount; int lockcount;
void lock_mutex(); void lock_mutex();
@ -86,18 +86,17 @@ class FileAccessNetwork : public FileAccess {
Semaphore page_sem; Semaphore page_sem;
Mutex buffer_mutex; Mutex buffer_mutex;
bool opened; bool opened;
size_t total_size; uint64_t total_size;
mutable size_t pos; mutable uint64_t pos;
int id; int32_t id;
mutable bool eof_flag; mutable bool eof_flag;
mutable int last_page; mutable int32_t last_page;
mutable uint8_t *last_page_buff; mutable uint8_t *last_page_buff;
int page_size; int32_t page_size;
int read_ahead; int32_t read_ahead;
mutable int waiting_on_page; mutable int waiting_on_page;
mutable int last_activity_val;
struct Page { struct Page {
int activity; int activity;
bool queued; bool queued;
@ -114,9 +113,9 @@ class FileAccessNetwork : public FileAccess {
uint64_t exists_modtime; uint64_t exists_modtime;
friend class FileAccessNetworkClient; friend class FileAccessNetworkClient;
void _queue_page(int p_page) const; void _queue_page(int32_t p_page) const;
void _respond(size_t p_len, Error p_status); void _respond(uint64_t p_len, Error p_status);
void _set_block(int p_offset, const Vector<uint8_t> &p_block); void _set_block(uint64_t p_offset, const Vector<uint8_t> &p_block);
public: public:
enum Command { enum Command {
@ -138,15 +137,15 @@ public:
virtual void close(); ///< close a file virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open 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 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 uint64_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file virtual uint64_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte 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 Error get_error() const; ///< get last error

View File

@ -34,7 +34,7 @@
#include <stdio.h> #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++) { for (int i = 0; i < sources.size(); i++) {
if (sources[i]->try_open_pack(p_path, p_replace_files, p_offset)) { if (sources[i]->try_open_pack(p_path, p_replace_files, p_offset)) {
return OK; return OK;
@ -44,16 +44,15 @@ Error PackedData::add_pack(const String &p_path, bool p_replace_files, size_t p_
return ERR_FILE_UNRECOGNIZED; 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) { 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) {
PathMD5 pmd5(path.md5_buffer()); PathMD5 pmd5(p_path.md5_buffer());
//printf("adding path %ls, %lli, %lli\n", path.c_str(), pmd5.a, pmd5.b);
bool exists = files.has(pmd5); bool exists = files.has(pmd5);
PackedFile pf; PackedFile pf;
pf.pack = pkg_path; pf.pack = p_pkg_path;
pf.offset = ofs; pf.offset = p_ofs;
pf.size = size; pf.size = p_size;
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
pf.md5[i] = p_md5[i]; pf.md5[i] = p_md5[i];
} }
@ -65,7 +64,7 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o
if (!exists) { if (!exists) {
//search for dir //search for dir
String p = path.replace_first("res://", ""); String p = p_path.replace_first("res://", "");
PackedDir *cd = root; PackedDir *cd = root;
if (p.find("/") != -1) { //in a subdir if (p.find("/") != -1) { //in a subdir
@ -84,7 +83,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 // Don't add as a file if the path points to a directory
if (!filename.empty()) { if (!filename.empty()) {
cd->files.insert(filename); cd->files.insert(filename);
@ -125,7 +124,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); FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) { if (!f) {
return false; return false;
@ -229,7 +228,7 @@ bool FileAccessPack::is_open() const {
return f->is_open(); return f->is_open();
} }
void FileAccessPack::seek(size_t p_position) { void FileAccessPack::seek(uint64_t p_position) {
if (p_position > pf.size) { if (p_position > pf.size) {
eof = true; eof = true;
} else { } else {
@ -239,13 +238,16 @@ void FileAccessPack::seek(size_t p_position) {
f->seek(pf.offset + p_position); f->seek(pf.offset + p_position);
pos = p_position; pos = p_position;
} }
void FileAccessPack::seek_end(int64_t p_position) { void FileAccessPack::seek_end(int64_t p_position) {
seek(pf.size + p_position); seek(pf.size + p_position);
} }
size_t FileAccessPack::get_position() const {
uint64_t FileAccessPack::get_position() const {
return pos; return pos;
} }
size_t FileAccessPack::get_len() const {
uint64_t FileAccessPack::get_len() const {
return pf.size; return pf.size;
} }
@ -263,18 +265,17 @@ uint8_t FileAccessPack::get_8() const {
return f->get_8(); 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_dst && p_length > 0, -1);
ERR_FAIL_COND_V(p_length < 0, -1);
if (eof) { if (eof) {
return 0; return 0;
} }
uint64_t to_read = p_length; int64_t to_read = p_length;
if (to_read + pos > pf.size) { if (to_read + pos > pf.size) {
eof = true; eof = true;
to_read = int64_t(pf.size) - int64_t(pos); to_read = (int64_t)pf.size - (int64_t)pos;
} }
pos += p_length; pos += p_length;
@ -307,7 +308,7 @@ void FileAccessPack::store_8(uint8_t p_dest) {
ERR_FAIL(); 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(); ERR_FAIL();
} }
@ -486,7 +487,7 @@ Error DirAccessPack::remove(String p_name) {
return ERR_UNAVAILABLE; return ERR_UNAVAILABLE;
} }
size_t DirAccessPack::get_space_left() { uint64_t DirAccessPack::get_space_left() {
return 0; return 0;
} }

View File

@ -97,7 +97,6 @@ private:
Vector<PackSource *> sources; Vector<PackSource *> sources;
PackedDir *root; PackedDir *root;
//Map<String,PackedDir*> dirs;
static PackedData *singleton; static PackedData *singleton;
bool disabled; bool disabled;
@ -106,13 +105,13 @@ private:
public: public:
void add_pack_source(PackSource *p_source); 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); // 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); // for PackSource
void set_disabled(bool p_disabled) { disabled = p_disabled; } void set_disabled(bool p_disabled) { disabled = p_disabled; }
_FORCE_INLINE_ bool is_disabled() const { return disabled; } _FORCE_INLINE_ bool is_disabled() const { return disabled; }
static PackedData *get_singleton() { return singleton; } 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_ FileAccess *try_open_path(const String &p_path);
_FORCE_INLINE_ bool has_path(const String &p_path); _FORCE_INLINE_ bool has_path(const String &p_path);
@ -126,21 +125,21 @@ public:
class PackSource { class PackSource {
public: 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 FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file) = 0;
virtual ~PackSource() {} virtual ~PackSource() {}
}; };
class PackedSourcePCK : public PackSource { class PackedSourcePCK : public PackSource {
public: 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); virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file);
}; };
class FileAccessPack : public FileAccess { class FileAccessPack : public FileAccess {
PackedData::PackedFile pf; PackedData::PackedFile pf;
mutable size_t pos; mutable uint64_t pos;
mutable bool eof; mutable bool eof;
FileAccess *f; FileAccess *f;
@ -153,16 +152,16 @@ public:
virtual void close(); virtual void close();
virtual bool is_open() const; 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 void seek_end(int64_t p_position = 0);
virtual size_t get_position() const; virtual uint64_t get_position() const;
virtual size_t get_len() const; virtual uint64_t get_len() const;
virtual bool eof_reached() const; virtual bool eof_reached() const;
virtual uint8_t get_8() 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); virtual void set_endian_swap(bool p_swap);
@ -171,7 +170,7 @@ public:
virtual void flush(); virtual void flush();
virtual void store_8(uint8_t p_dest); 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); virtual bool file_exists(const String &p_name);
@ -236,7 +235,7 @@ public:
virtual Error rename(String p_from, String p_to); virtual Error rename(String p_from, String p_to);
virtual Error remove(String p_name); virtual Error remove(String p_name);
size_t get_space_left(); uint64_t get_space_left();
virtual String get_filesystem_type() const; virtual String get_filesystem_type() const;

View File

@ -67,7 +67,7 @@ static long godot_tell(voidpf opaque, voidpf stream) {
static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) { static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
FileAccess *f = (FileAccess *)stream; FileAccess *f = (FileAccess *)stream;
int pos = offset; uint64_t pos = offset;
switch (origin) { switch (origin) {
case ZLIB_FILEFUNC_SEEK_CUR: case ZLIB_FILEFUNC_SEEK_CUR:
pos = f->get_position() + offset; pos = f->get_position() + offset;
@ -145,7 +145,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const {
return pkg; return pkg;
} }
bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset = 0) { bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset = 0) {
//printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz")); //printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz"));
// load with offset feature only supported for PCK files // 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."); 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.");
@ -267,8 +267,9 @@ bool FileAccessZip::is_open() const {
return zfile != nullptr; return zfile != nullptr;
} }
void FileAccessZip::seek(size_t p_position) { void FileAccessZip::seek(uint64_t p_position) {
ERR_FAIL_COND(!zfile); ERR_FAIL_COND(!zfile);
unzSeekCurrentFile(zfile, p_position); unzSeekCurrentFile(zfile, p_position);
} }
@ -277,12 +278,12 @@ void FileAccessZip::seek_end(int64_t p_position) {
unzSeekCurrentFile(zfile, get_len() + 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); ERR_FAIL_COND_V(!zfile, 0);
return unztell(zfile); return unztell(zfile);
} }
size_t FileAccessZip::get_len() const { uint64_t FileAccessZip::get_len() const {
ERR_FAIL_COND_V(!zfile, 0); ERR_FAIL_COND_V(!zfile, 0);
return file_info.uncompressed_size; return file_info.uncompressed_size;
} }
@ -299,17 +300,17 @@ uint8_t FileAccessZip::get_8() const {
return ret; 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_dst && p_length > 0, -1);
ERR_FAIL_COND_V(p_length < 0, -1);
ERR_FAIL_COND_V(!zfile, -1); ERR_FAIL_COND_V(!zfile, -1);
at_eof = unzeof(zfile); at_eof = unzeof(zfile);
if (at_eof) { if (at_eof) {
return 0; 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); ERR_FAIL_COND_V(read < 0, read);
if (read < p_length) { if ((uint64_t)read < p_length) {
at_eof = true; at_eof = true;
} }
return read; return read;

View File

@ -71,7 +71,7 @@ public:
bool file_exists(String p_name) const; 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); FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file);
static ZipArchive *get_singleton(); static ZipArchive *get_singleton();
@ -91,20 +91,21 @@ public:
virtual void close(); ///< close a file virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open 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 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 uint64_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file virtual uint64_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte 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 Error get_error() const; ///< get last error
virtual void flush(); virtual void flush();
virtual void store_8(uint8_t p_dest); ///< store a byte 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 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 virtual uint64_t _get_modified_time(const String &p_file) { return 0; } // todo

View File

@ -138,7 +138,7 @@ Error PCKPacker::flush(bool p_verbose) {
FileAccess *src = FileAccess::open(files[i].src_path, FileAccess::READ); FileAccess *src = FileAccess::open(files[i].src_path, FileAccess::READ);
uint64_t to_write = files[i].size; uint64_t to_write = files[i].size;
while (to_write > 0) { 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));
file->store_buffer(buf, read); file->store_buffer(buf, read);
to_write -= read; to_write -= read;
}; };

View File

@ -46,7 +46,7 @@ class PCKPacker : public Reference {
struct File { struct File {
String path; String path;
String src_path; String src_path;
int size; uint64_t size;
uint64_t offset_offset; uint64_t offset_offset;
}; };
Vector<File> files; Vector<File> files;

View File

@ -1106,8 +1106,8 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
save_ustring(fw, get_ustring(f)); //type save_ustring(fw, get_ustring(f)); //type
size_t md_ofs = f->get_position(); uint64_t md_ofs = f->get_position();
size_t importmd_ofs = f->get_64(); uint64_t importmd_ofs = f->get_64();
fw->store_64(0); //metadata offset fw->store_64(0); //metadata offset
for (int i = 0; i < 14; i++) { for (int i = 0; i < 14; i++) {

View File

@ -68,7 +68,7 @@ long zipio_tell(voidpf opaque, voidpf stream) {
long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) { long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
FileAccess *f = *(FileAccess **)opaque; FileAccess *f = *(FileAccess **)opaque;
int pos = offset; uint64_t pos = offset;
switch (origin) { switch (origin) {
case ZLIB_FILEFUNC_SEEK_CUR: case ZLIB_FILEFUNC_SEEK_CUR:
pos = f->get_position() + offset; pos = f->get_position() + offset;

View File

@ -87,7 +87,7 @@ public:
virtual bool file_exists(String p_file) = 0; virtual bool file_exists(String p_file) = 0;
virtual bool dir_exists(String p_dir) = 0; virtual bool dir_exists(String p_dir) = 0;
static bool exists(String p_dir); static bool exists(String p_dir);
virtual size_t get_space_left() = 0; virtual uint64_t get_space_left() = 0;
Error copy_dir(String p_from, String p_to, int p_chmod_flags = -1); Error copy_dir(String p_from, String p_to, int p_chmod_flags = -1);
virtual Error copy(String p_from, String p_to, int p_chmod_flags = -1); virtual Error copy(String p_from, String p_to, int p_chmod_flags = -1);

View File

@ -366,10 +366,10 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const {
return strings; return strings;
} }
int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const { uint64_t FileAccess::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_dst && p_length > 0, -1);
ERR_FAIL_COND_V(p_length < 0, -1);
int i = 0; uint64_t i = 0;
for (i = 0; i < p_length && !eof_reached(); i++) { for (i = 0; i < p_length && !eof_reached(); i++) {
p_dst[i] = get_8(); p_dst[i] = get_8();
} }
@ -379,11 +379,11 @@ int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const {
String FileAccess::get_as_utf8_string() const { String FileAccess::get_as_utf8_string() const {
PoolVector<uint8_t> sourcef; PoolVector<uint8_t> sourcef;
int len = get_len(); uint64_t len = get_len();
sourcef.resize(len + 1); sourcef.resize(len + 1);
PoolVector<uint8_t>::Write w = sourcef.write(); PoolVector<uint8_t>::Write w = sourcef.write();
int r = get_buffer(w.ptr(), len); uint64_t r = get_buffer(w.ptr(), len);
ERR_FAIL_COND_V(r != len, String()); ERR_FAIL_COND_V(r != len, String());
w[len] = 0; w[len] = 0;
@ -547,8 +547,8 @@ void FileAccess::store_csv_line(const Vector<String> &p_values, const String &p_
store_line(line); store_line(line);
} }
void FileAccess::store_buffer(const uint8_t *p_src, int p_length) { void FileAccess::store_buffer(const uint8_t *p_src, uint64_t p_length) {
for (int i = 0; i < p_length; i++) { for (uint64_t i = 0; i < p_length; i++) {
store_8(p_src[i]); store_8(p_src[i]);
} }
} }
@ -598,7 +598,7 @@ String FileAccess::get_md5(const String &p_file) {
unsigned char step[32768]; unsigned char step[32768];
while (true) { while (true) {
int br = f->get_buffer(step, 32768); uint64_t br = f->get_buffer(step, 32768);
if (br > 0) { if (br > 0) {
ctx.update(step, br); ctx.update(step, br);
} }
@ -626,7 +626,7 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) {
unsigned char step[32768]; unsigned char step[32768];
while (true) { while (true) {
int br = f->get_buffer(step, 32768); uint64_t br = f->get_buffer(step, 32768);
if (br > 0) { if (br > 0) {
ctx.update(step, br); ctx.update(step, br);
} }
@ -655,7 +655,7 @@ String FileAccess::get_sha256(const String &p_file) {
unsigned char step[32768]; unsigned char step[32768];
while (true) { while (true) {
int br = f->get_buffer(step, 32768); uint64_t br = f->get_buffer(step, 32768);
if (br > 0) { if (br > 0) {
ctx.update(step, br); ctx.update(step, br);
} }

View File

@ -94,10 +94,10 @@ public:
virtual String get_path() const { return ""; } /// returns the path for the current open file virtual String get_path() const { return ""; } /// returns the path for the current open file
virtual String get_path_absolute() const { return ""; } /// returns the absolute path for the current open file virtual String get_path_absolute() const { return ""; } /// returns the absolute path for the current open file
virtual void seek(size_t p_position) = 0; ///< seek to a given position virtual void seek(uint64_t p_position) = 0; ///< seek to a given position
virtual void seek_end(int64_t p_position = 0) = 0; ///< seek from the end of file virtual void seek_end(int64_t p_position = 0) = 0; ///< seek from the end of file with negative offset
virtual size_t get_position() const = 0; ///< get position in the file virtual uint64_t get_position() const = 0; ///< get position in the file
virtual size_t get_len() const = 0; ///< get size of the file virtual uint64_t get_len() const = 0; ///< get size of the file
virtual bool eof_reached() const = 0; ///< reading passed EOF virtual bool eof_reached() const = 0; ///< reading passed EOF
@ -110,7 +110,7 @@ public:
virtual double get_double() const; virtual double get_double() const;
virtual real_t get_real() const; virtual real_t get_real() const;
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 String get_line() const; virtual String get_line() const;
virtual String get_token() const; virtual String get_token() const;
virtual Vector<String> get_csv_line(const String &p_delim = ",") const; virtual Vector<String> get_csv_line(const String &p_delim = ",") const;
@ -143,7 +143,7 @@ public:
virtual void store_pascal_string(const String &p_string); virtual void store_pascal_string(const String &p_string);
virtual String get_pascal_string(); virtual String get_pascal_string();
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) = 0; ///< return true if a file exists virtual bool file_exists(const String &p_name) = 0; ///< return true if a file exists

View File

@ -37,7 +37,7 @@
#include <string.h> #include <string.h>
Error ImageLoaderPNG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { Error ImageLoaderPNG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) {
const size_t buffer_size = f->get_len(); const uint64_t buffer_size = f->get_len();
PoolVector<uint8_t> file_buffer; PoolVector<uint8_t> file_buffer;
Error err = file_buffer.resize(buffer_size); Error err = file_buffer.resize(buffer_size);
if (err) { if (err) {

View File

@ -382,7 +382,7 @@ Error DirAccessUnix::remove(String p_path) {
} }
} }
size_t DirAccessUnix::get_space_left() { uint64_t DirAccessUnix::get_space_left() {
#ifndef NO_STATVFS #ifndef NO_STATVFS
struct statvfs vfs; struct statvfs vfs;
if (statvfs(current_dir.utf8().get_data(), &vfs) != 0) { if (statvfs(current_dir.utf8().get_data(), &vfs) != 0) {

View File

@ -77,7 +77,7 @@ public:
virtual Error rename(String p_path, String p_new_path); virtual Error rename(String p_path, String p_new_path);
virtual Error remove(String p_path); virtual Error remove(String p_path);
virtual size_t get_space_left(); virtual uint64_t get_space_left();
virtual String get_filesystem_type() const; virtual String get_filesystem_type() const;

View File

@ -184,11 +184,11 @@ String FileAccessUnix::get_path_absolute() const {
return path; return path;
} }
void FileAccessUnix::seek(size_t p_position) { void FileAccessUnix::seek(uint64_t p_position) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use."); ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
last_error = OK; last_error = OK;
if (fseek(f, p_position, SEEK_SET)) { if (fseeko(f, p_position, SEEK_SET)) {
check_errors(); check_errors();
} }
} }
@ -196,15 +196,15 @@ void FileAccessUnix::seek(size_t p_position) {
void FileAccessUnix::seek_end(int64_t p_position) { void FileAccessUnix::seek_end(int64_t p_position) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use."); ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
if (fseek(f, p_position, SEEK_END)) { if (fseeko(f, p_position, SEEK_END)) {
check_errors(); check_errors();
} }
} }
size_t FileAccessUnix::get_position() const { uint64_t FileAccessUnix::get_position() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
long pos = ftell(f); int64_t pos = ftello(f);
if (pos < 0) { if (pos < 0) {
check_errors(); check_errors();
ERR_FAIL_V(0); ERR_FAIL_V(0);
@ -212,15 +212,15 @@ size_t FileAccessUnix::get_position() const {
return pos; return pos;
} }
size_t FileAccessUnix::get_len() const { uint64_t FileAccessUnix::get_len() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
long pos = ftell(f); int64_t pos = ftello(f);
ERR_FAIL_COND_V(pos < 0, 0); ERR_FAIL_COND_V(pos < 0, 0);
ERR_FAIL_COND_V(fseek(f, 0, SEEK_END), 0); ERR_FAIL_COND_V(fseeko(f, 0, SEEK_END), 0);
long size = ftell(f); int64_t size = ftello(f);
ERR_FAIL_COND_V(size < 0, 0); ERR_FAIL_COND_V(size < 0, 0);
ERR_FAIL_COND_V(fseek(f, pos, SEEK_SET), 0); ERR_FAIL_COND_V(fseeko(f, pos, SEEK_SET), 0);
return size; return size;
} }
@ -239,11 +239,11 @@ uint8_t FileAccessUnix::get_8() const {
return b; return b;
} }
int FileAccessUnix::get_buffer(uint8_t *p_dst, int p_length) const { uint64_t FileAccessUnix::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_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(!f, -1, "File must be opened before use.");
int read = fread(p_dst, 1, p_length, f);
uint64_t read = fread(p_dst, 1, p_length, f);
check_errors(); check_errors();
return read; return read;
}; };
@ -262,10 +262,10 @@ void FileAccessUnix::store_8(uint8_t p_dest) {
ERR_FAIL_COND(fwrite(&p_dest, 1, 1, f) != 1); ERR_FAIL_COND(fwrite(&p_dest, 1, 1, f) != 1);
} }
void FileAccessUnix::store_buffer(const uint8_t *p_src, int p_length) { void FileAccessUnix::store_buffer(const uint8_t *p_src, uint64_t p_length) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use."); ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
ERR_FAIL_COND(!p_src); ERR_FAIL_COND(!p_src);
ERR_FAIL_COND((int)fwrite(p_src, 1, p_length, f) != p_length); ERR_FAIL_COND(fwrite(p_src, 1, p_length, f) != p_length);
} }
bool FileAccessUnix::file_exists(const String &p_path) { bool FileAccessUnix::file_exists(const String &p_path) {

View File

@ -61,21 +61,21 @@ public:
virtual String get_path() const; /// returns the path for the current open file 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 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 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 uint64_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file virtual uint64_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte 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 Error get_error() const; ///< get last error
virtual void flush(); virtual void flush();
virtual void store_8(uint8_t p_dest); ///< store a byte 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_path); ///< return true if a file exists virtual bool file_exists(const String &p_path); ///< return true if a file exists

View File

@ -325,13 +325,14 @@ FileType DirAccessWindows::get_file_type(const String& p_file) const {
return (attr&FILE_ATTRIBUTE_DIRECTORY)?FILE_TYPE_ return (attr&FILE_ATTRIBUTE_DIRECTORY)?FILE_TYPE_
} }
*/ */
size_t DirAccessWindows::get_space_left() {
uint64_t DirAccessWindows::get_space_left() {
uint64_t bytes = 0; uint64_t bytes = 0;
if (!GetDiskFreeSpaceEx(NULL, (PULARGE_INTEGER)&bytes, NULL, NULL)) if (!GetDiskFreeSpaceEx(NULL, (PULARGE_INTEGER)&bytes, NULL, NULL))
return 0; return 0;
//this is either 0 or a value in bytes. //this is either 0 or a value in bytes.
return (size_t)bytes; return bytes;
} }
String DirAccessWindows::get_filesystem_type() const { String DirAccessWindows::get_filesystem_type() const {

View File

@ -79,8 +79,7 @@ public:
virtual Error rename(String p_path, String p_new_path); virtual Error rename(String p_path, String p_new_path);
virtual Error remove(String p_path); virtual Error remove(String p_path);
//virtual FileType get_file_type() const; uint64_t get_space_left();
size_t get_space_left();
virtual String get_filesystem_type() const; virtual String get_filesystem_type() const;

View File

@ -188,34 +188,38 @@ String FileAccessWindows::get_path_absolute() const {
bool FileAccessWindows::is_open() const { bool FileAccessWindows::is_open() const {
return (f != NULL); return (f != NULL);
} }
void FileAccessWindows::seek(size_t p_position) {
void FileAccessWindows::seek(uint64_t p_position) {
ERR_FAIL_COND(!f); ERR_FAIL_COND(!f);
last_error = OK; last_error = OK;
if (fseek(f, p_position, SEEK_SET)) if (_fseeki64(f, p_position, SEEK_SET))
check_errors(); check_errors();
prev_op = 0; prev_op = 0;
} }
void FileAccessWindows::seek_end(int64_t p_position) { void FileAccessWindows::seek_end(int64_t p_position) {
ERR_FAIL_COND(!f); ERR_FAIL_COND(!f);
if (fseek(f, p_position, SEEK_END)) if (_fseeki64(f, p_position, SEEK_END))
check_errors(); check_errors();
prev_op = 0; prev_op = 0;
} }
size_t FileAccessWindows::get_position() const {
size_t aux_position = 0; uint64_t FileAccessWindows::get_position() const {
aux_position = ftell(f); int64_t aux_position = _ftelli64(f);
if (!aux_position) { if (aux_position < 0) {
check_errors(); check_errors();
}; }
return aux_position; return aux_position;
} }
size_t FileAccessWindows::get_len() const {
uint64_t FileAccessWindows::get_len() const {
ERR_FAIL_COND_V(!f, 0); ERR_FAIL_COND_V(!f, 0);
size_t pos = get_position(); uint64_t pos = get_position();
fseek(f, 0, SEEK_END); _fseeki64(f, 0, SEEK_END);
int size = get_position(); uint64_t size = get_position();
fseek(f, pos, SEEK_SET); _fseeki64(f, pos, SEEK_SET);
return size; return size;
} }
@ -242,17 +246,17 @@ uint8_t FileAccessWindows::get_8() const {
return b; return b;
} }
int FileAccessWindows::get_buffer(uint8_t *p_dst, int p_length) const { uint64_t FileAccessWindows::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_dst && p_length > 0, -1);
ERR_FAIL_COND_V(p_length < 0, -1);
ERR_FAIL_COND_V(!f, -1); ERR_FAIL_COND_V(!f, -1);
if (flags == READ_WRITE || flags == WRITE_READ) { if (flags == READ_WRITE || flags == WRITE_READ) {
if (prev_op == WRITE) { if (prev_op == WRITE) {
fflush(f); fflush(f);
} }
prev_op = READ; prev_op = READ;
} }
int read = fread(p_dst, 1, p_length, f); uint64_t read = fread(p_dst, 1, p_length, f);
check_errors(); check_errors();
return read; return read;
}; };
@ -281,7 +285,7 @@ void FileAccessWindows::store_8(uint8_t p_dest) {
fwrite(&p_dest, 1, 1, f); fwrite(&p_dest, 1, 1, f);
} }
void FileAccessWindows::store_buffer(const uint8_t *p_src, int p_length) { void FileAccessWindows::store_buffer(const uint8_t *p_src, uint64_t p_length) {
ERR_FAIL_COND(!f); ERR_FAIL_COND(!f);
if (flags == READ_WRITE || flags == WRITE_READ) { if (flags == READ_WRITE || flags == WRITE_READ) {
if (prev_op == READ) { if (prev_op == READ) {

View File

@ -56,21 +56,21 @@ public:
virtual String get_path() const; /// returns the path for the current open file 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 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 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 uint64_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file virtual uint64_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte 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 Error get_error() const; ///< get last error
virtual void flush(); virtual void flush();
virtual void store_8(uint8_t p_dest); ///< store a byte 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 virtual bool file_exists(const String &p_name); ///< return true if a file exists

View File

@ -1029,12 +1029,12 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c
int header_padding = _get_pad(PCK_PADDING, header_size); int header_padding = _get_pad(PCK_PADDING, header_size);
for (int i = 0; i < pd.file_ofs.size(); i++) { for (int i = 0; i < pd.file_ofs.size(); i++) {
int string_len = pd.file_ofs[i].path_utf8.length(); uint32_t string_len = pd.file_ofs[i].path_utf8.length();
int pad = _get_pad(4, string_len); uint32_t pad = _get_pad(4, string_len);
f->store_32(string_len + pad); f->store_32(string_len + pad);
f->store_buffer((const uint8_t *)pd.file_ofs[i].path_utf8.get_data(), string_len); f->store_buffer((const uint8_t *)pd.file_ofs[i].path_utf8.get_data(), string_len);
for (int j = 0; j < pad; j++) { for (uint32_t j = 0; j < pad; j++) {
f->store_8(0); f->store_8(0);
} }
@ -1060,8 +1060,8 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c
uint8_t buf[bufsize]; uint8_t buf[bufsize];
while (true) { while (true) {
int got = ftmp->get_buffer(buf, bufsize); uint64_t got = ftmp->get_buffer(buf, bufsize);
if (got <= 0) { if (got == 0) {
break; break;
} }
f->store_buffer(buf, got); f->store_buffer(buf, got);
@ -1071,13 +1071,13 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c
if (p_embed) { if (p_embed) {
// Ensure embedded data ends at a 64-bit multiple // Ensure embedded data ends at a 64-bit multiple
int64_t embed_end = f->get_position() - embed_pos + 12; uint64_t embed_end = f->get_position() - embed_pos + 12;
int pad = embed_end % 8; uint64_t pad = embed_end % 8;
for (int i = 0; i < pad; i++) { for (uint64_t i = 0; i < pad; i++) {
f->store_8(0); f->store_8(0);
} }
int64_t pck_size = f->get_position() - pck_start_pos; uint64_t pck_size = f->get_position() - pck_start_pos;
f->store_64(pck_size); f->store_64(pck_size);
f->store_32(PACK_HEADER_MAGIC); f->store_32(PACK_HEADER_MAGIC);

View File

@ -229,8 +229,7 @@ void EditorFileServer::_subthread_start(void *s) {
cd->files[id]->seek(offset); cd->files[id]->seek(offset);
Vector<uint8_t> buf; Vector<uint8_t> buf;
buf.resize(blocklen); buf.resize(blocklen);
int read = cd->files[id]->get_buffer(buf.ptrw(), blocklen); uint32_t read = cd->files[id]->get_buffer(buf.ptrw(), blocklen);
ERR_CONTINUE(read < 0);
print_verbose("GET BLOCK - offset: " + itos(offset) + ", blocklen: " + itos(blocklen)); print_verbose("GET BLOCK - offset: " + itos(offset) + ", blocklen: " + itos(blocklen));

View File

@ -73,7 +73,7 @@ Error ResourceImporterImage::import(const String &p_source_file, const String &p
ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open file from path '" + p_source_file + "'."); ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open file from path '" + p_source_file + "'.");
size_t len = f->get_len(); uint64_t len = f->get_len();
Vector<uint8_t> data; Vector<uint8_t> data;
data.resize(len); data.resize(len);

View File

@ -1357,7 +1357,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
String cache_file_path = base_path.plus_file(file_id + ".unwrap_cache"); String cache_file_path = base_path.plus_file(file_id + ".unwrap_cache");
int *cache_data = nullptr; int *cache_data = nullptr;
unsigned int cache_size = 0; uint64_t cache_size = 0;
if (FileAccess::exists(cache_file_path)) { if (FileAccess::exists(cache_file_path)) {
Error err2; Error err2;
@ -1366,7 +1366,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
if (!err2) { if (!err2) {
cache_size = file->get_len(); cache_size = file->get_len();
cache_data = (int *)memalloc(cache_size); cache_data = (int *)memalloc(cache_size);
file->get_buffer((unsigned char *)cache_data, cache_size); file->get_buffer((uint8_t *)cache_data, cache_size);
} }
if (file) { if (file) {

View File

@ -899,7 +899,7 @@ MainLoop *test(TestType p_type) {
ERR_FAIL_COND_V_MSG(!fa, nullptr, "Could not open file: " + test); ERR_FAIL_COND_V_MSG(!fa, nullptr, "Could not open file: " + test);
Vector<uint8_t> buf; Vector<uint8_t> buf;
int flen = fa->get_len(); uint64_t flen = fa->get_len();
buf.resize(fa->get_len() + 1); buf.resize(fa->get_len() + 1);
fa->get_buffer(buf.ptrw(), flen); fa->get_buffer(buf.ptrw(), flen);
buf.write[flen] = 0; buf.write[flen] = 0;

View File

@ -487,7 +487,7 @@ MainLoop *test() {
ERR_FAIL_COND_V_MSG(!fa, nullptr, "Could not open file: " + test); ERR_FAIL_COND_V_MSG(!fa, nullptr, "Could not open file: " + test);
Vector<uint8_t> buf; Vector<uint8_t> buf;
int flen = fa->get_len(); uint64_t flen = fa->get_len();
buf.resize(fa->get_len() + 1); buf.resize(fa->get_len() + 1);
fa->get_buffer(buf.ptrw(), flen); fa->get_buffer(buf.ptrw(), flen);
buf.write[flen] = 0; buf.write[flen] = 0;

View File

@ -412,10 +412,10 @@ Error PluginScript::load_source_code(const String &p_path) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
ERR_FAIL_COND_V_MSG(err, err, "Cannot open file '" + p_path + "'."); ERR_FAIL_COND_V_MSG(err, err, "Cannot open file '" + p_path + "'.");
int len = f->get_len(); uint64_t len = f->get_len();
sourcef.resize(len + 1); sourcef.resize(len + 1);
PoolVector<uint8_t>::Write w = sourcef.write(); PoolVector<uint8_t>::Write w = sourcef.write();
int r = f->get_buffer(w.ptr(), len); uint64_t r = f->get_buffer(w.ptr(), len);
f->close(); f->close();
memdelete(f); memdelete(f);
ERR_FAIL_COND_V(r != len, ERR_CANT_OPEN); ERR_FAIL_COND_V(r != len, ERR_CANT_OPEN);

View File

@ -47,11 +47,7 @@ godot_int GDAPI godot_videodecoder_file_read(void *ptr, uint8_t *buf, int buf_si
// if file exists // if file exists
if (file) { if (file) {
long bytes_read = file->get_buffer(buf, buf_size); int64_t bytes_read = file->get_buffer(buf, buf_size);
// No bytes to read => EOF
if (bytes_read == 0) {
return 0;
}
return bytes_read; return bytes_read;
} }
return -1; return -1;
@ -62,41 +58,35 @@ int64_t GDAPI godot_videodecoder_file_seek(void *ptr, int64_t pos, int whence) {
FileAccess *file = reinterpret_cast<FileAccess *>(ptr); FileAccess *file = reinterpret_cast<FileAccess *>(ptr);
if (file) { if (file) {
size_t len = file->get_len(); int64_t len = file->get_len();
switch (whence) { switch (whence) {
case SEEK_SET: { case SEEK_SET: {
// Just for explicitness if (pos > len) {
size_t new_pos = static_cast<size_t>(pos);
if (new_pos > len) {
return -1; return -1;
} }
file->seek(new_pos); file->seek(pos);
pos = static_cast<int64_t>(file->get_position()); return file->get_position();
return pos;
} break; } break;
case SEEK_CUR: { case SEEK_CUR: {
// Just in case it doesn't exist // Just in case it doesn't exist
if (pos < 0 && (size_t)-pos > file->get_position()) { if (pos < 0 && -pos > (int64_t)file->get_position()) {
return -1; return -1;
} }
pos = pos + static_cast<int>(file->get_position()); file->seek(file->get_position() + pos);
file->seek(pos); return file->get_position();
pos = static_cast<int64_t>(file->get_position());
return pos;
} break; } break;
case SEEK_END: { case SEEK_END: {
// Just in case something goes wrong // Just in case something goes wrong
if ((size_t)-pos > len) { if (-pos > len) {
return -1; return -1;
} }
file->seek_end(pos); file->seek_end(pos);
pos = static_cast<int64_t>(file->get_position()); return file->get_position();
return pos;
} break; } break;
default: { default: {
// Only 4 possible options, hence default = AVSEEK_SIZE // Only 4 possible options, hence default = AVSEEK_SIZE
// Asks to return the length of file // Asks to return the length of file
return static_cast<int64_t>(len); return len;
} break; } break;
} }
} }

View File

@ -771,10 +771,10 @@ Error GDScript::load_source_code(const String &p_path) {
ERR_FAIL_COND_V(err, err); ERR_FAIL_COND_V(err, err);
} }
int len = f->get_len(); uint64_t len = f->get_len();
sourcef.resize(len + 1); sourcef.resize(len + 1);
PoolVector<uint8_t>::Write w = sourcef.write(); PoolVector<uint8_t>::Write w = sourcef.write();
int r = f->get_buffer(w.ptr(), len); uint64_t r = f->get_buffer(w.ptr(), len);
f->close(); f->close();
memdelete(f); memdelete(f);
ERR_FAIL_COND_V(r != len, ERR_CANT_OPEN); ERR_FAIL_COND_V(r != len, ERR_CANT_OPEN);

View File

@ -106,7 +106,7 @@ Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p
Error ImageLoaderJPG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { Error ImageLoaderJPG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) {
PoolVector<uint8_t> src_image; PoolVector<uint8_t> src_image;
int src_image_len = f->get_len(); uint64_t src_image_len = f->get_len();
ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT);
src_image.resize(src_image_len); src_image.resize(src_image_len);

View File

@ -57,7 +57,7 @@ Error CryptoKeyMbedTLS::load(String p_path, bool p_public_only) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ); FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
ERR_FAIL_COND_V_MSG(!f, ERR_INVALID_PARAMETER, "Cannot open CryptoKeyMbedTLS file '" + p_path + "'."); ERR_FAIL_COND_V_MSG(!f, ERR_INVALID_PARAMETER, "Cannot open CryptoKeyMbedTLS file '" + p_path + "'.");
int flen = f->get_len(); uint64_t flen = f->get_len();
out.resize(flen + 1); out.resize(flen + 1);
{ {
PoolByteArray::Write w = out.write(); PoolByteArray::Write w = out.write();
@ -148,7 +148,7 @@ Error X509CertificateMbedTLS::load(String p_path) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ); FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
ERR_FAIL_COND_V_MSG(!f, ERR_INVALID_PARAMETER, "Cannot open X509CertificateMbedTLS file '" + p_path + "'."); ERR_FAIL_COND_V_MSG(!f, ERR_INVALID_PARAMETER, "Cannot open X509CertificateMbedTLS file '" + p_path + "'.");
int flen = f->get_len(); uint64_t flen = f->get_len();
out.resize(flen + 1); out.resize(flen + 1);
{ {
PoolByteArray::Write w = out.write(); PoolByteArray::Write w = out.write();

View File

@ -79,7 +79,7 @@ Error ResourceImporterMP3::import(const String &p_source_file, const String &p_s
ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); ERR_FAIL_COND_V(!f, ERR_CANT_OPEN);
size_t len = f->get_len(); uint64_t len = f->get_len();
PoolVector<uint8_t> data; PoolVector<uint8_t> data;
data.resize(len); data.resize(len);

View File

@ -166,10 +166,10 @@ Error read_all_file_utf8(const String &p_path, String &r_content) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot open file '" + p_path + "'."); ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot open file '" + p_path + "'.");
int len = f->get_len(); uint64_t len = f->get_len();
sourcef.resize(len + 1); sourcef.resize(len + 1);
PoolVector<uint8_t>::Write w = sourcef.write(); PoolVector<uint8_t>::Write w = sourcef.write();
int r = f->get_buffer(w.ptr(), len); uint64_t r = f->get_buffer(w.ptr(), len);
f->close(); f->close();
memdelete(f); memdelete(f);
ERR_FAIL_COND_V(r != len, ERR_CANT_OPEN); ERR_FAIL_COND_V(r != len, ERR_CANT_OPEN);

View File

@ -77,7 +77,7 @@ Error ResourceImporterOGGVorbis::import(const String &p_source_file, const Strin
ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open file '" + p_source_file + "'."); ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open file '" + p_source_file + "'.");
size_t len = f->get_len(); uint64_t len = f->get_len();
PoolVector<uint8_t> data; PoolVector<uint8_t> data;
data.resize(len); data.resize(len);

View File

@ -141,7 +141,7 @@ Error ImageLoaderSVG::create_image_from_string(Ref<Image> p_image, const char *p
} }
Error ImageLoaderSVG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { Error ImageLoaderSVG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) {
uint32_t size = f->get_len(); uint64_t size = f->get_len();
PoolVector<uint8_t> src_image; PoolVector<uint8_t> src_image;
src_image.resize(size + 1); src_image.resize(size + 1);
PoolVector<uint8_t>::Write src_w = src_image.write(); PoolVector<uint8_t>::Write src_w = src_image.write();

View File

@ -228,9 +228,9 @@ Error ImageLoaderTGA::convert_to_image(Ref<Image> p_image, const uint8_t *p_buff
Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) {
PoolVector<uint8_t> src_image; PoolVector<uint8_t> src_image;
int src_image_len = f->get_len(); uint64_t src_image_len = f->get_len();
ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT);
ERR_FAIL_COND_V(src_image_len < (int)sizeof(tga_header_s), ERR_FILE_CORRUPT); ERR_FAIL_COND_V(src_image_len < (int64_t)sizeof(tga_header_s), ERR_FILE_CORRUPT);
src_image.resize(src_image_len); src_image.resize(src_image_len);
Error err = OK; Error err = OK;

View File

@ -58,7 +58,7 @@ int VideoStreamPlaybackTheora::buffer_data() {
#else #else
int bytes = file->get_buffer((uint8_t *)buffer, 4096); uint64_t bytes = file->get_buffer((uint8_t *)buffer, 4096);
ogg_sync_wrote(&oy, bytes); ogg_sync_wrote(&oy, bytes);
return (bytes); return (bytes);
@ -176,7 +176,7 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) {
thread_eof = false; thread_eof = false;
//pre-fill buffer //pre-fill buffer
int to_read = ring_buffer.space_left(); int to_read = ring_buffer.space_left();
int read = file->get_buffer(read_buffer.ptr(), to_read); uint64_t read = file->get_buffer(read_buffer.ptr(), to_read);
ring_buffer.write(read_buffer.ptr(), read); ring_buffer.write(read_buffer.ptr(), read);
thread.start(_streaming_thread, this); thread.start(_streaming_thread, this);
@ -631,8 +631,8 @@ void VideoStreamPlaybackTheora::_streaming_thread(void *ud) {
//just fill back the buffer //just fill back the buffer
if (!vs->thread_eof) { if (!vs->thread_eof) {
int to_read = vs->ring_buffer.space_left(); int to_read = vs->ring_buffer.space_left();
if (to_read) { if (to_read > 0) {
int read = vs->file->get_buffer(vs->read_buffer.ptr(), to_read); uint64_t read = vs->file->get_buffer(vs->read_buffer.ptr(), to_read);
vs->ring_buffer.write(vs->read_buffer.ptr(), read); vs->ring_buffer.write(vs->read_buffer.ptr(), read);
vs->thread_eof = vs->file->eof_reached(); vs->thread_eof = vs->file->eof_reached();
} }

View File

@ -37,7 +37,7 @@
Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) {
PoolVector<uint8_t> src_image; PoolVector<uint8_t> src_image;
int src_image_len = f->get_len(); uint64_t src_image_len = f->get_len();
ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT);
src_image.resize(src_image_len); src_image.resize(src_image_len);

View File

@ -62,10 +62,10 @@ public:
virtual int Read(long long pos, long len, unsigned char *buf) { virtual int Read(long long pos, long len, unsigned char *buf) {
if (file) { if (file) {
if (file->get_position() != (size_t)pos) { if (file->get_position() != (uint64_t)pos) {
file->seek(pos); file->seek(pos);
} }
if (file->get_buffer(buf, len) == len) { if (file->get_buffer(buf, len) == (uint64_t)len) {
return 0; return 0;
} }
} }
@ -74,7 +74,7 @@ public:
virtual int Length(long long *total, long long *available) { virtual int Length(long long *total, long long *available) {
if (file) { if (file) {
const size_t len = file->get_len(); const uint64_t len = file->get_len();
if (total) { if (total) {
*total = len; *total = len;
} }

View File

@ -150,7 +150,7 @@ static Ref<Image> _webp_mem_loader_func(const uint8_t *p_png, int p_size) {
Error ImageLoaderWEBP::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { Error ImageLoaderWEBP::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) {
PoolVector<uint8_t> src_image; PoolVector<uint8_t> src_image;
int src_image_len = f->get_len(); uint64_t src_image_len = f->get_len();
ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT);
src_image.resize(src_image_len); src_image.resize(src_image_len);

View File

@ -278,6 +278,9 @@ def configure(env):
) )
env.Append(CPPDEFINES=["NO_STATVFS", "GLES_ENABLED"]) env.Append(CPPDEFINES=["NO_STATVFS", "GLES_ENABLED"])
if get_platform(env["ndk_platform"]) >= 24:
env.Append(CPPDEFINES=[("_FILE_OFFSET_BITS", 64)])
env["neon_enabled"] = False env["neon_enabled"] = False
if env["android_arch"] == "x86": if env["android_arch"] == "x86":
target_opts = ["-target", "i686-none-linux-android"] target_opts = ["-target", "i686-none-linux-android"]

View File

@ -201,8 +201,7 @@ String DirAccessJAndroid::get_filesystem_type() const {
return "APK"; return "APK";
} }
//FileType get_file_type() const; uint64_t DirAccessJAndroid::get_space_left() {
size_t DirAccessJAndroid::get_space_left() {
return 0; return 0;
} }

View File

@ -76,8 +76,7 @@ public:
virtual String get_filesystem_type() const; virtual String get_filesystem_type() const;
//virtual FileType get_file_type() const; uint64_t get_space_left();
size_t get_space_left();
static void setup(jobject p_io); static void setup(jobject p_io);

View File

@ -2339,7 +2339,7 @@ public:
text = text.to_upper(); //just in case text = text.to_upper(); //just in case
String end_marker = "//CHUNK_" + text + "_END"; String end_marker = "//CHUNK_" + text + "_END";
size_t pos = f->get_position(); uint64_t pos = f->get_position();
bool found = false; bool found = false;
while (!f->eof_reached()) { while (!f->eof_reached()) {
l = f->get_line(); l = f->get_line();
@ -2378,7 +2378,7 @@ public:
text = text.to_upper(); //just in case text = text.to_upper(); //just in case
String end_marker = "//DIR_" + text + "_END"; String end_marker = "//DIR_" + text + "_END";
size_t pos = f->get_position(); uint64_t pos = f->get_position();
bool found = false; bool found = false;
while (!f->eof_reached()) { while (!f->eof_reached()) {
l = f->get_line(); l = f->get_line();
@ -2448,7 +2448,7 @@ public:
text = text.to_upper(); //just in case text = text.to_upper(); //just in case
String end_marker = "<!--CHUNK_" + text + "_END-->"; String end_marker = "<!--CHUNK_" + text + "_END-->";
size_t pos = f->get_position(); uint64_t pos = f->get_position();
bool found = false; bool found = false;
while (!f->eof_reached()) { while (!f->eof_reached()) {
l = f->get_line(); l = f->get_line();

View File

@ -72,8 +72,9 @@ bool FileAccessAndroid::is_open() const {
return a != NULL; return a != NULL;
} }
void FileAccessAndroid::seek(size_t p_position) { void FileAccessAndroid::seek(uint64_t p_position) {
ERR_FAIL_COND(!a); ERR_FAIL_COND(!a);
AAsset_seek(a, p_position, SEEK_SET); AAsset_seek(a, p_position, SEEK_SET);
pos = p_position; pos = p_position;
if (pos > len) { if (pos > len) {
@ -90,11 +91,11 @@ void FileAccessAndroid::seek_end(int64_t p_position) {
pos = len + p_position; pos = len + p_position;
} }
size_t FileAccessAndroid::get_position() const { uint64_t FileAccessAndroid::get_position() const {
return pos; return pos;
} }
size_t FileAccessAndroid::get_len() const { uint64_t FileAccessAndroid::get_len() const {
return len; return len;
} }
@ -114,11 +115,10 @@ uint8_t FileAccessAndroid::get_8() const {
return byte; return byte;
} }
int FileAccessAndroid::get_buffer(uint8_t *p_dst, int p_length) const { uint64_t FileAccessAndroid::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_dst && p_length > 0, -1);
ERR_FAIL_COND_V(p_length < 0, -1);
off_t r = AAsset_read(a, p_dst, p_length); int r = AAsset_read(a, p_dst, p_length);
if (pos + p_length > len) { if (pos + p_length > len) {
eof = true; eof = true;

View File

@ -40,8 +40,8 @@
class FileAccessAndroid : public FileAccess { class FileAccessAndroid : public FileAccess {
static FileAccess *create_android(); static FileAccess *create_android();
mutable AAsset *a; mutable AAsset *a;
mutable size_t len; mutable uint64_t len;
mutable size_t pos; mutable uint64_t pos;
mutable bool eof; mutable bool eof;
public: public:
@ -51,15 +51,15 @@ public:
virtual void close(); ///< close a file virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open 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 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 uint64_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file virtual uint64_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte 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 Error get_error() const; ///< get last error

View File

@ -84,7 +84,7 @@ void JavaScriptToolsEditorPlugin::_zip_file(String p_path, String p_base_path, z
return; return;
} }
Vector<uint8_t> data; Vector<uint8_t> data;
int len = f->get_len(); uint64_t len = f->get_len();
data.resize(len); data.resize(len);
f->get_buffer(data.ptrw(), len); f->get_buffer(data.ptrw(), len);
f->close(); f->close();

View File

@ -170,8 +170,8 @@ public:
while (true) { while (true) {
uint8_t bytes[4096]; uint8_t bytes[4096];
int read = f->get_buffer(bytes, 4096); uint64_t read = f->get_buffer(bytes, 4096);
if (read < 1) { if (read == 0) {
break; break;
} }
err = peer->put_data(bytes, read); err = peer->put_data(bytes, read);

View File

@ -284,7 +284,7 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_
} }
int ofs = data.size(); int ofs = data.size();
uint32_t len = f->get_len(); uint64_t len = f->get_len();
data.resize(data.size() + len + 8); data.resize(data.size() + len + 8);
f->get_buffer(&data.write[ofs + 8], len); f->get_buffer(&data.write[ofs + 8], len);
memdelete(f); memdelete(f);

View File

@ -2181,7 +2181,7 @@ void OS_OSX::set_native_icon(const String &p_filename) {
ERR_FAIL_COND(!f); ERR_FAIL_COND(!f);
Vector<uint8_t> data; Vector<uint8_t> data;
uint32_t len = f->get_len(); uint64_t len = f->get_len();
data.resize(len); data.resize(len);
f->get_buffer((uint8_t *)&data.write[0], len); f->get_buffer((uint8_t *)&data.write[0], len);
memdelete(f); memdelete(f);

View File

@ -350,7 +350,7 @@ def configure(env):
env.ParseConfig("pkg-config zlib --cflags --libs") env.ParseConfig("pkg-config zlib --cflags --libs")
env.Prepend(CPPPATH=["#platform/x11"]) env.Prepend(CPPPATH=["#platform/x11"])
env.Append(CPPDEFINES=["X11_ENABLED", "UNIX_ENABLED", "OPENGL_ENABLED", "GLES_ENABLED"]) env.Append(CPPDEFINES=["X11_ENABLED", "UNIX_ENABLED", "OPENGL_ENABLED", "GLES_ENABLED", ("_FILE_OFFSET_BITS", 64)])
env.Append(LIBS=["GL", "pthread"]) env.Append(LIBS=["GL", "pthread"])
if platform.system() == "Linux": if platform.system() == "Linux":

View File

@ -78,16 +78,12 @@ FileAccessRef PowerX11::open_power_file(const char *base, const char *node, cons
} }
bool PowerX11::read_power_file(const char *base, const char *node, const char *key, char *buf, size_t buflen) { bool PowerX11::read_power_file(const char *base, const char *node, const char *key, char *buf, size_t buflen) {
ssize_t br = 0;
FileAccessRef fd = open_power_file(base, node, key); FileAccessRef fd = open_power_file(base, node, key);
if (!fd) { if (!fd) {
return false; return false;
} }
br = fd->get_buffer(reinterpret_cast<uint8_t *>(buf), buflen - 1); uint64_t br = fd->get_buffer(reinterpret_cast<uint8_t *>(buf), buflen - 1);
fd->close(); fd->close();
if (br < 0) {
return false;
}
buf[br] = '\0'; // null-terminate the string buf[br] = '\0'; // null-terminate the string
return true; return true;
} }
@ -340,19 +336,14 @@ bool PowerX11::GetPowerInfo_Linux_proc_apm() {
char buf[128]; char buf[128];
char *ptr = &buf[0]; char *ptr = &buf[0];
char *str = nullptr; char *str = nullptr;
ssize_t br;
if (!fd) { if (!fd) {
return false; /* can't use this interface. */ return false; /* can't use this interface. */
} }
br = fd->get_buffer(reinterpret_cast<uint8_t *>(buf), sizeof(buf) - 1); uint64_t br = fd->get_buffer(reinterpret_cast<uint8_t *>(buf), sizeof(buf) - 1);
fd->close(); fd->close();
if (br < 0) {
return false;
}
buf[br] = '\0'; /* null-terminate the string. */ buf[br] = '\0'; /* null-terminate the string. */
if (!next_string(&ptr, &str)) { /* driver version */ if (!next_string(&ptr, &str)) { /* driver version */
return false; return false;

View File

@ -120,7 +120,7 @@ Error DynamicFontAtSize::_load() {
ERR_FAIL_V_MSG(ERR_CANT_OPEN, "Cannot open font file '" + font->font_path + "'."); ERR_FAIL_V_MSG(ERR_CANT_OPEN, "Cannot open font file '" + font->font_path + "'.");
} }
size_t len = f->get_len(); uint64_t len = f->get_len();
font->_fontdata = Vector<uint8_t>(); font->_fontdata = Vector<uint8_t>();
font->_fontdata.resize(len); font->_fontdata.resize(len);
f->get_buffer(font->_fontdata.ptrw(), len); f->get_buffer(font->_fontdata.ptrw(), len);

View File

@ -896,7 +896,7 @@ Error ResourceInteractiveLoaderText::save_as_binary(FileAccess *p_f, const Strin
} }
wf->store_32(0); //string table size, will not be in use wf->store_32(0); //string table size, will not be in use
size_t ext_res_count_pos = wf->get_position(); uint64_t ext_res_count_pos = wf->get_position();
wf->store_32(0); //zero ext resources, still parsing them wf->store_32(0); //zero ext resources, still parsing them
@ -959,7 +959,7 @@ Error ResourceInteractiveLoaderText::save_as_binary(FileAccess *p_f, const Strin
//now, save resources to a separate file, for now //now, save resources to a separate file, for now
size_t sub_res_count_pos = wf->get_position(); uint64_t sub_res_count_pos = wf->get_position();
wf->store_32(0); //zero sub resources, still parsing them wf->store_32(0); //zero sub resources, still parsing them
String temp_file = p_path + ".temp"; String temp_file = p_path + ".temp";
@ -968,8 +968,8 @@ Error ResourceInteractiveLoaderText::save_as_binary(FileAccess *p_f, const Strin
return ERR_CANT_OPEN; return ERR_CANT_OPEN;
} }
Vector<size_t> local_offsets; Vector<uint64_t> local_offsets;
Vector<size_t> local_pointers_pos; Vector<uint64_t> local_pointers_pos;
while (next_tag.name == "sub_resource" || next_tag.name == "resource") { while (next_tag.name == "sub_resource" || next_tag.name == "resource") {
String type; String type;
@ -1007,7 +1007,7 @@ Error ResourceInteractiveLoaderText::save_as_binary(FileAccess *p_f, const Strin
wf->store_64(0); //temp local offset wf->store_64(0); //temp local offset
bs_save_unicode_string(wf2, type); bs_save_unicode_string(wf2, type);
size_t propcount_ofs = wf2->get_position(); uint64_t propcount_ofs = wf2->get_position();
wf2->store_32(0); wf2->store_32(0);
int prop_count = 0; int prop_count = 0;
@ -1077,7 +1077,7 @@ Error ResourceInteractiveLoaderText::save_as_binary(FileAccess *p_f, const Strin
local_offsets.push_back(wf2->get_position()); local_offsets.push_back(wf2->get_position());
bs_save_unicode_string(wf2, "PackedScene"); bs_save_unicode_string(wf2, "PackedScene");
size_t propcount_ofs = wf2->get_position(); uint64_t propcount_ofs = wf2->get_position();
wf2->store_32(0); wf2->store_32(0);
int prop_count = 0; int prop_count = 0;
@ -1103,7 +1103,7 @@ Error ResourceInteractiveLoaderText::save_as_binary(FileAccess *p_f, const Strin
wf2->close(); wf2->close();
size_t offset_from = wf->get_position(); uint64_t offset_from = wf->get_position();
wf->seek(sub_res_count_pos); //plus one because the saved one wf->seek(sub_res_count_pos); //plus one because the saved one
wf->store_32(local_offsets.size()); wf->store_32(local_offsets.size());

View File

@ -55,10 +55,10 @@ Error TextFile::load_text(const String &p_path) {
ERR_FAIL_COND_V_MSG(err, err, "Cannot open TextFile '" + p_path + "'."); ERR_FAIL_COND_V_MSG(err, err, "Cannot open TextFile '" + p_path + "'.");
int len = f->get_len(); uint64_t len = f->get_len();
sourcef.resize(len + 1); sourcef.resize(len + 1);
PoolVector<uint8_t>::Write w = sourcef.write(); PoolVector<uint8_t>::Write w = sourcef.write();
int r = f->get_buffer(w.ptr(), len); uint64_t r = f->get_buffer(w.ptr(), len);
f->close(); f->close();
memdelete(f); memdelete(f);
ERR_FAIL_COND_V(r != len, ERR_CANT_OPEN); ERR_FAIL_COND_V(r != len, ERR_CANT_OPEN);

View File

@ -539,7 +539,7 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &tw_
//mipmaps need to be read independently, they will be later combined //mipmaps need to be read independently, they will be later combined
Vector<Ref<Image>> mipmap_images; Vector<Ref<Image>> mipmap_images;
int total_size = 0; uint64_t total_size = 0;
for (uint32_t i = 0; i < mipmaps; i++) { for (uint32_t i = 0; i < mipmaps; i++) {
if (i) { if (i) {
@ -624,7 +624,7 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &tw_
int sh = th; int sh = th;
int mipmaps2 = Image::get_image_required_mipmaps(tw, th, format); int mipmaps2 = Image::get_image_required_mipmaps(tw, th, format);
int total_size = Image::get_image_data_size(tw, th, format, true); uint64_t total_size = Image::get_image_data_size(tw, th, format, true);
int idx = 0; int idx = 0;
while (mipmaps2 > 1 && p_size_limit > 0 && (sw > p_size_limit || sh > p_size_limit)) { while (mipmaps2 > 1 && p_size_limit > 0 && (sw > p_size_limit || sh > p_size_limit)) {
@ -648,12 +648,12 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &tw_
{ {
PoolVector<uint8_t>::Write w = img_data.write(); PoolVector<uint8_t>::Write w = img_data.write();
int bytes = f->get_buffer(w.ptr(), total_size - ofs); uint64_t bytes = f->get_buffer(w.ptr(), total_size - ofs);
//print_line("requested read: " + itos(total_size - ofs) + " but got: " + itos(bytes)); //print_line("requested read: " + itos(total_size - ofs) + " but got: " + itos(bytes));
memdelete(f); memdelete(f);
int expected = total_size - ofs; uint64_t expected = total_size - ofs;
if (bytes < expected) { if (bytes < expected) {
//this is a compatibility workaround for older format, which saved less mipmaps2. It is still recommended the image is reimported. //this is a compatibility workaround for older format, which saved less mipmaps2. It is still recommended the image is reimported.
memset(w.ptr() + bytes, 0, (expected - bytes)); memset(w.ptr() + bytes, 0, (expected - bytes));
@ -2225,14 +2225,14 @@ Error TextureLayered::load(const String &p_path) {
} else { } else {
//look for regular format //look for regular format
bool mipmaps = (flags & Texture::FLAG_MIPMAPS); bool mipmaps = (flags & Texture::FLAG_MIPMAPS);
int total_size = Image::get_image_data_size(tw, th, format, mipmaps); uint64_t total_size = Image::get_image_data_size(tw, th, format, mipmaps);
PoolVector<uint8_t> img_data; PoolVector<uint8_t> img_data;
img_data.resize(total_size); img_data.resize(total_size);
{ {
PoolVector<uint8_t>::Write w = img_data.write(); PoolVector<uint8_t>::Write w = img_data.write();
int bytes = f->get_buffer(w.ptr(), total_size); uint64_t bytes = f->get_buffer(w.ptr(), total_size);
if (bytes != total_size) { if (bytes != total_size) {
f->close(); f->close();
memdelete(f); memdelete(f);