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 9cc17a8439
commit 469fa47e06
No known key found for this signature in database
GPG key ID: C3336907360768E1
65 changed files with 326 additions and 342 deletions

View file

@ -1259,6 +1259,7 @@ 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);
} }
@ -1267,12 +1268,12 @@ void _File::seek_end(int64_t p_position) {
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();
} }
@ -1317,7 +1318,7 @@ real_t _File::get_real() const {
return f->get_real(); return f->get_real();
} }
Vector<uint8_t> _File::get_buffer(int p_length) const { Vector<uint8_t> _File::get_buffer(int64_t p_length) const {
Vector<uint8_t> data; Vector<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.");
@ -1330,8 +1331,7 @@ Vector<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.");
uint8_t *w = data.ptrw(); uint8_t *w = data.ptrw();
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, Vector<uint8_t>());
if (len < p_length) { if (len < p_length) {
data.resize(len); data.resize(len);
@ -1344,7 +1344,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();
@ -1473,7 +1473,7 @@ void _File::store_csv_line(const Vector<String> &p_values, const String &p_delim
void _File::store_buffer(const Vector<uint8_t> &p_buffer) { void _File::store_buffer(const Vector<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;
} }
@ -1721,9 +1721,9 @@ bool _Directory::dir_exists(String p_dir) {
return d->dir_exists(p_dir); return d->dir_exists(p_dir);
} }
int _Directory::get_space_left() { uint64_t _Directory::get_space_left() {
ERR_FAIL_COND_V_MSG(!is_open(), 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

@ -390,8 +390,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.
@ -406,7 +406,7 @@ public:
Variant get_var(bool p_allow_objects = false) const; Variant get_var(bool p_allow_objects = false) const;
Vector<uint8_t> get_buffer(int p_length) const; // Get an array of bytes. Vector<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;
@ -486,7 +486,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/string/print_string.h" #include "core/string/print_string.h"
void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, int p_block_size) { void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, uint32_t p_block_size) {
magic = p_magic.ascii().get_data(); 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();
@ -148,15 +148,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;
@ -168,7 +168,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();
@ -190,8 +190,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);
@ -204,7 +205,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);
@ -227,7 +228,7 @@ void FileAccessCompressed::seek_end(int64_t p_position) {
} }
} }
size_t FileAccessCompressed::get_position() const { uint64_t FileAccessCompressed::get_position() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
if (writing) { if (writing) {
return write_pos; return write_pos;
@ -236,7 +237,7 @@ size_t FileAccessCompressed::get_position() const {
} }
} }
size_t FileAccessCompressed::get_len() const { uint64_t FileAccessCompressed::get_len() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
if (writing) { if (writing) {
return write_max; return write_max;
@ -285,9 +286,8 @@ 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.");
@ -296,7 +296,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_ZSTD; Compression::Mode cmode = Compression::MODE_ZSTD;
bool writing = false; bool writing = false;
uint32_t write_pos = 0; uint64_t write_pos = 0;
uint8_t *write_ptr = nullptr; uint8_t *write_ptr = nullptr;
uint32_t write_buffer_size = 0; uint32_t write_buffer_size = 0;
uint32_t write_max = 0; uint64_t write_max = 0;
uint32_t block_size = 0; uint32_t block_size = 0;
mutable bool read_eof = false; mutable bool read_eof = false;
mutable bool at_end = false; mutable bool at_end = false;
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 = nullptr; uint8_t *read_ptr = nullptr;
mutable int read_block = 0; mutable uint32_t read_block = 0;
int read_block_count = 0; uint32_t read_block_count = 0;
mutable int read_block_size = 0; mutable uint32_t read_block_size = 0;
mutable int read_pos = 0; mutable uint64_t read_pos = 0;
Vector<ReadBlock> read_blocks; Vector<ReadBlock> read_blocks;
uint32_t read_total = 0; uint64_t read_total = 0;
String magic = "GCMP"; String magic = "GCMP";
mutable Vector<uint8_t> buffer; mutable Vector<uint8_t> buffer;
FileAccess *f = nullptr; FileAccess *f = nullptr;
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

@ -70,13 +70,13 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
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);
{ {
@ -141,7 +141,7 @@ void FileAccessEncrypted::release() {
void FileAccessEncrypted::_release() { void FileAccessEncrypted::_release() {
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);
} }
@ -198,9 +198,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;
@ -208,14 +208,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();
} }
@ -225,7 +225,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;
} }
@ -235,13 +235,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++];
} }
@ -256,16 +255,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;
@ -281,10 +280,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

@ -47,10 +47,10 @@ private:
Vector<uint8_t> key; Vector<uint8_t> key;
bool writing = false; bool writing = false;
FileAccess *file = nullptr; FileAccess *file = nullptr;
size_t base = 0; uint64_t base = 0;
size_t length = 0; uint64_t length = 0;
Vector<uint8_t> data; Vector<uint8_t> data;
mutable int pos = 0; mutable uint64_t pos = 0;
mutable bool eofed = false; mutable bool eofed = false;
bool use_magic = true; bool use_magic = true;
@ -68,21 +68,21 @@ public:
virtual String get_path() const; /// returns the path for the current open file virtual String get_path() 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,13 +136,12 @@ 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");
@ -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 = nullptr; uint8_t *data = nullptr;
int length = 0; uint64_t length = 0;
mutable int pos = 0; mutable uint64_t pos = 0;
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

@ -126,7 +126,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));
} }
@ -135,7 +135,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);
@ -219,13 +219,13 @@ FileAccessNetworkClient::~FileAccessNetworkClient() {
thread.wait_to_finish(); thread.wait_to_finish();
} }
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);
} }
{ {
@ -240,7 +240,7 @@ void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block)
} }
} }
void FileAccessNetwork::_respond(size_t p_len, Error p_status) { void FileAccessNetwork::_respond(uint64_t p_len, Error p_status) {
DEBUG_PRINT("GOT RESPONSE - len: " + itos(p_len) + " status: " + itos(p_status)); DEBUG_PRINT("GOT RESPONSE - len: " + itos(p_len) + " status: " + itos(p_status));
response = p_status; response = p_status;
if (response != OK) { if (response != OK) {
@ -248,7 +248,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);
} }
@ -307,8 +307,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) {
@ -322,12 +323,12 @@ 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 +344,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;
} }
@ -354,7 +355,7 @@ void FileAccessNetwork::_queue_page(int p_page) const {
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;
@ -365,11 +366,9 @@ void FileAccessNetwork::_queue_page(int p_page) const {
} }
} }
int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const { uint64_t FileAccessNetwork::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); ERR_FAIL_COND_V(!p_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;
} }
@ -377,18 +376,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.is_empty()) { if (pages[page].buffer.is_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();
@ -396,10 +393,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();
} }

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,17 +54,17 @@ 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 = 0; int32_t last_id = 0;
int lockcount = 0; int32_t lockcount = 0;
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();
void lock_mutex(); void lock_mutex();
void unlock_mutex(); void unlock_mutex();
@ -86,15 +86,15 @@ class FileAccessNetwork : public FileAccess {
Semaphore page_sem; Semaphore page_sem;
Mutex buffer_mutex; Mutex buffer_mutex;
bool opened = false; bool opened = false;
size_t total_size; uint64_t total_size;
mutable size_t pos = 0; mutable uint64_t pos = 0;
int id; int32_t id;
mutable bool eof_flag = false; mutable bool eof_flag = false;
mutable int last_page = -1; mutable int32_t last_page = -1;
mutable uint8_t *last_page_buff = nullptr; mutable uint8_t *last_page_buff = nullptr;
int page_size; int32_t page_size;
int read_ahead; int32_t read_ahead;
mutable int waiting_on_page = -1; mutable int waiting_on_page = -1;
@ -110,9 +110,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 {
@ -134,15 +134,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

@ -36,7 +36,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;
@ -46,17 +46,16 @@ 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, bool p_encrypted) { void PackedData::add_path(const String &p_pkg_path, const String &p_path, uint64_t p_ofs, uint64_t p_size, const uint8_t *p_md5, PackSource *p_src, bool p_replace_files, bool p_encrypted) {
PathMD5 pmd5(path.md5_buffer()); PathMD5 pmd5(p_path.md5_buffer());
//printf("adding path %s, %lli, %lli\n", path.utf8().get_data(), pmd5.a, pmd5.b);
bool exists = files.has(pmd5); bool exists = files.has(pmd5);
PackedFile pf; PackedFile pf;
pf.encrypted = p_encrypted; pf.encrypted = p_encrypted;
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];
} }
@ -68,7 +67,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
@ -87,7 +86,7 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o
} }
} }
} }
String filename = path.get_file(); String filename = p_path.get_file();
// Don't add as a file if the path points to a directory // Don't add as a file if the path points to a directory
if (!filename.is_empty()) { if (!filename.is_empty()) {
cd->files.insert(filename); cd->files.insert(filename);
@ -126,7 +125,7 @@ PackedData::~PackedData() {
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset) { bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ); FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) { if (!f) {
return false; return false;
@ -261,7 +260,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 {
@ -276,11 +275,11 @@ 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;
} }
@ -298,18 +297,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;
@ -342,7 +340,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();
} }
@ -549,7 +547,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

@ -112,13 +112,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, bool p_encrypted = false); // for PackSource void add_path(const String &p_pkg_path, const String &p_path, uint64_t p_ofs, uint64_t p_size, const uint8_t *p_md5, PackSource *p_src, bool p_replace_files, bool p_encrypted = false); // for PackSource
void set_disabled(bool p_disabled) { disabled = p_disabled; } 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);
@ -132,21 +132,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;
uint64_t off; uint64_t off;
@ -160,16 +160,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);
@ -178,7 +178,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);
@ -243,7 +243,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;
@ -144,8 +144,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 %s, %i, %i\n", p_name.utf8().get_data(), 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.");
@ -265,8 +264,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);
} }
@ -275,12 +275,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;
} }
@ -297,17 +297,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

@ -67,7 +67,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();
@ -87,20 +87,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

@ -236,7 +236,7 @@ Error PCKPacker::flush(bool p_verbose) {
} }
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));
ftmp->store_buffer(buf, read); ftmp->store_buffer(buf, read);
to_write -= read; to_write -= read;
} }

View file

@ -1157,8 +1157,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 is_readable(String p_dir) { return true; }; virtual bool is_readable(String p_dir) { return true; };
virtual bool is_writable(String p_dir) { return true; }; virtual bool is_writable(String p_dir) { return true; };
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

@ -367,10 +367,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();
} }
@ -380,11 +380,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 {
Vector<uint8_t> sourcef; Vector<uint8_t> sourcef;
int len = get_len(); uint64_t len = get_len();
sourcef.resize(len + 1); sourcef.resize(len + 1);
uint8_t *w = sourcef.ptrw(); uint8_t *w = sourcef.ptrw();
int r = get_buffer(w, len); uint64_t r = get_buffer(w, len);
ERR_FAIL_COND_V(r != len, String()); ERR_FAIL_COND_V(r != len, String());
w[len] = 0; w[len] = 0;
@ -550,8 +550,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]);
} }
} }
@ -601,7 +601,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);
} }
@ -629,7 +629,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);
} }
@ -658,7 +658,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

@ -93,10 +93,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
@ -109,7 +109,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;
@ -142,7 +142,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();
Vector<uint8_t> file_buffer; Vector<uint8_t> file_buffer;
Error err = file_buffer.resize(buffer_size); Error err = file_buffer.resize(buffer_size);
if (err) { if (err) {

View file

@ -406,7 +406,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

@ -79,7 +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 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,14 +325,15 @@ FileType DirAccessWindows::get_file_type(const String& p_file) const {
} }
*/ */
size_t DirAccessWindows::get_space_left() {
uint64_t DirAccessWindows::get_space_left() {
uint64_t bytes = 0; uint64_t bytes = 0;
if (!GetDiskFreeSpaceEx(nullptr, (PULARGE_INTEGER)&bytes, nullptr, nullptr)) { if (!GetDiskFreeSpaceEx(nullptr, (PULARGE_INTEGER)&bytes, nullptr, nullptr)) {
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

@ -78,8 +78,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

@ -193,10 +193,11 @@ bool FileAccessWindows::is_open() const {
return (f != nullptr); return (f != nullptr);
} }
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;
@ -204,28 +205,27 @@ void FileAccessWindows::seek(size_t p_position) {
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 { uint64_t FileAccessWindows::get_position() const {
size_t aux_position = 0; int64_t aux_position = _ftelli64(f);
aux_position = ftell(f); if (aux_position < 0) {
if (!aux_position) {
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;
} }
@ -252,17 +252,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;
}; };
@ -292,7 +292,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

@ -1222,12 +1222,12 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c
} }
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);
fhead->store_32(string_len + pad); fhead->store_32(string_len + pad);
fhead->store_buffer((const uint8_t *)pd.file_ofs[i].path_utf8.get_data(), string_len); fhead->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++) {
fhead->store_8(0); fhead->store_8(0);
} }
@ -1269,8 +1269,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);
@ -1280,13 +1280,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

@ -230,8 +230,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

@ -75,7 +75,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

@ -441,10 +441,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);
uint8_t *w = sourcef.ptrw(); uint8_t *w = sourcef.ptrw();
int r = f->get_buffer(w, len); uint64_t r = f->get_buffer(w, 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

@ -1045,10 +1045,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);
uint8_t *w = sourcef.ptrw(); uint8_t *w = sourcef.ptrw();
int r = f->get_buffer(w, len); uint64_t r = f->get_buffer(w, 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

@ -153,9 +153,9 @@ String GDScriptCache::get_source_code(const String &p_path) {
ERR_FAIL_COND_V(err, ""); ERR_FAIL_COND_V(err, "");
} }
int len = f->get_len(); uint64_t len = f->get_len();
source_file.resize(len + 1); source_file.resize(len + 1);
int r = f->get_buffer(source_file.ptrw(), len); uint64_t r = f->get_buffer(source_file.ptrw(), len);
f->close(); f->close();
ERR_FAIL_COND_V(r != len, ""); ERR_FAIL_COND_V(r != len, "");
source_file.write[len] = 0; source_file.write[len] = 0;

View file

@ -215,7 +215,7 @@ void test(TestType p_type) {
init_language(fa->get_path_absolute().get_base_dir()); init_language(fa->get_path_absolute().get_base_dir());
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

@ -105,7 +105,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) {
Vector<uint8_t> src_image; Vector<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

@ -58,7 +58,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);
f->get_buffer(out.ptrw(), flen); f->get_buffer(out.ptrw(), flen);
out.write[flen] = 0; // string terminator out.write[flen] = 0; // string terminator
@ -146,7 +146,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);
f->get_buffer(out.ptrw(), flen); f->get_buffer(out.ptrw(), flen);
out.write[flen] = 0; // string terminator out.write[flen] = 0; // string terminator

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();
Vector<uint8_t> data; Vector<uint8_t> data;
data.resize(len); data.resize(len);

View file

@ -170,10 +170,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);
uint8_t *w = sourcef.ptrw(); uint8_t *w = sourcef.ptrw();
int r = f->get_buffer(w, len); uint64_t r = f->get_buffer(w, 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

@ -79,7 +79,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();
Vector<uint8_t> data; Vector<uint8_t> data;
data.resize(len); data.resize(len);

View file

@ -140,7 +140,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();
Vector<uint8_t> src_image; Vector<uint8_t> src_image;
src_image.resize(size + 1); src_image.resize(size + 1);
uint8_t *src_w = src_image.ptrw(); uint8_t *src_w = src_image.ptrw();

View file

@ -66,7 +66,7 @@ DynamicFontDataAdvanced::DataAtSize *DynamicFontDataAdvanced::get_data_for_size(
ERR_FAIL_V_MSG(nullptr, "Cannot open font file '" + font_path + "'."); ERR_FAIL_V_MSG(nullptr, "Cannot open font file '" + font_path + "'.");
} }
size_t len = f->get_len(); uint64_t len = f->get_len();
font_mem_cache.resize(len); font_mem_cache.resize(len);
f->get_buffer(font_mem_cache.ptrw(), len); f->get_buffer(font_mem_cache.ptrw(), len);
font_mem = font_mem_cache.ptr(); font_mem = font_mem_cache.ptr();

View file

@ -181,7 +181,7 @@ bool TextServerAdvanced::load_support_data(const String &p_filename) {
UErrorCode err = U_ZERO_ERROR; UErrorCode err = U_ZERO_ERROR;
// ICU data found. // ICU data found.
size_t len = f->get_len(); uint64_t len = f->get_len();
icu_data = (uint8_t *)memalloc(len); icu_data = (uint8_t *)memalloc(len);
f->get_buffer(icu_data, len); f->get_buffer(icu_data, len);
f->close(); f->close();

View file

@ -65,7 +65,7 @@ DynamicFontDataFallback::DataAtSize *DynamicFontDataFallback::get_data_for_size(
ERR_FAIL_V_MSG(nullptr, "Cannot open font file '" + font_path + "'."); ERR_FAIL_V_MSG(nullptr, "Cannot open font file '" + font_path + "'.");
} }
size_t len = f->get_len(); uint64_t len = f->get_len();
font_mem_cache.resize(len); font_mem_cache.resize(len);
f->get_buffer(font_mem_cache.ptrw(), len); f->get_buffer(font_mem_cache.ptrw(), len);
font_mem = font_mem_cache.ptr(); font_mem = font_mem_cache.ptr();

View file

@ -226,9 +226,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) {
Vector<uint8_t> src_image; Vector<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);
@ -632,8 +632,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) {
Vector<uint8_t> src_image; Vector<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

@ -147,7 +147,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) {
Vector<uint8_t> src_image; Vector<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

@ -285,6 +285,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

@ -71,8 +71,9 @@ bool FileAccessAndroid::is_open() const {
return a != nullptr; return a != nullptr;
} }
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) {
@ -89,11 +90,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;
} }
@ -113,11 +114,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 = nullptr; mutable AAsset *a = nullptr;
mutable size_t len = 0; mutable uint64_t len = 0;
mutable size_t pos = 0; mutable uint64_t pos = 0;
mutable bool eof = false; mutable bool eof = false;
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

@ -79,7 +79,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

@ -363,6 +363,7 @@ def configure(env):
env.Prepend(CPPPATH=["#platform/linuxbsd"]) env.Prepend(CPPPATH=["#platform/linuxbsd"])
env.Append(CPPDEFINES=["X11_ENABLED", "UNIX_ENABLED"]) env.Append(CPPDEFINES=["X11_ENABLED", "UNIX_ENABLED"])
env.Append(CPPDEFINES=[("_FILE_OFFSET_BITS", 64)])
env.Append(CPPDEFINES=["VULKAN_ENABLED"]) env.Append(CPPDEFINES=["VULKAN_ENABLED"])
if not env["builtin_vulkan"]: if not env["builtin_vulkan"]:

View file

@ -3467,7 +3467,7 @@ void DisplayServerOSX::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

@ -312,7 +312,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

@ -978,7 +978,7 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
} }
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
@ -1041,7 +1041,7 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
//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";
@ -1050,8 +1050,8 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
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;
@ -1089,7 +1089,7 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
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;
@ -1159,7 +1159,7 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
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;
@ -1185,7 +1185,7 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
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);
uint8_t *w = sourcef.ptrw(); uint8_t *w = sourcef.ptrw();
int r = f->get_buffer(w, len); uint64_t r = f->get_buffer(w, 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

@ -335,7 +335,7 @@ Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit
//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;
bool first = true; bool first = true;

View file

@ -529,7 +529,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;