This commit is contained in:
Spartan322
2024-12-04 20:11:58 -05:00
798 changed files with 28373 additions and 5874 deletions

View File

@@ -54,10 +54,18 @@
#define S_ISREG(m) ((m) & _S_IFREG)
#endif
void FileAccessWindows::check_errors() const {
void FileAccessWindows::check_errors(bool p_write) const {
ERR_FAIL_NULL(f);
if (feof(f)) {
last_error = OK;
if (ferror(f)) {
if (p_write) {
last_error = ERR_FILE_CANT_WRITE;
} else {
last_error = ERR_FILE_CANT_READ;
}
}
if (!p_write && feof(f)) {
last_error = ERR_FILE_EOF;
}
}
@@ -286,7 +294,6 @@ bool FileAccessWindows::is_open() const {
void FileAccessWindows::seek(uint64_t p_position) {
ERR_FAIL_NULL(f);
last_error = OK;
if (_fseeki64(f, p_position, SEEK_SET)) {
check_errors();
}
@@ -322,8 +329,7 @@ uint64_t FileAccessWindows::get_length() const {
}
bool FileAccessWindows::eof_reached() const {
check_errors();
return last_error == ERR_FILE_EOF;
return feof(f);
}
uint64_t FileAccessWindows::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
@@ -374,9 +380,9 @@ void FileAccessWindows::flush() {
}
}
void FileAccessWindows::store_buffer(const uint8_t *p_src, uint64_t p_length) {
ERR_FAIL_NULL(f);
ERR_FAIL_COND(!p_src && p_length > 0);
bool FileAccessWindows::store_buffer(const uint8_t *p_src, uint64_t p_length) {
ERR_FAIL_NULL_V(f, false);
ERR_FAIL_COND_V(!p_src && p_length > 0, false);
if (flags == READ_WRITE || flags == WRITE_READ) {
if (prev_op == READ) {
@@ -387,7 +393,9 @@ void FileAccessWindows::store_buffer(const uint8_t *p_src, uint64_t p_length) {
prev_op = WRITE;
}
ERR_FAIL_COND(fwrite(p_src, 1, p_length, f) != (size_t)p_length);
bool res = fwrite(p_src, 1, p_length, f) == (size_t)p_length;
check_errors(true);
return res;
}
bool FileAccessWindows::file_exists(const String &p_name) {
@@ -527,6 +535,9 @@ void FileAccessWindows::initialize() {
invalid_files.insert(reserved_files[reserved_file_index]);
reserved_file_index++;
}
_setmaxstdio(8192);
print_verbose(vformat("Maximum number of file handles: %d", _getmaxstdio()));
}
void FileAccessWindows::finalize() {

View File

@@ -43,7 +43,7 @@
class FileAccessWindows : public FileAccess {
FILE *f = nullptr;
int flags = 0;
void check_errors() const;
void check_errors(bool p_write = false) const;
mutable int prev_op = 0;
mutable Error last_error = OK;
String path;
@@ -77,7 +77,7 @@ public:
virtual Error resize(int64_t p_length) override;
virtual void flush() override;
virtual void store_buffer(const uint8_t *p_src, uint64_t p_length) override; ///< store an array of bytes
virtual bool store_buffer(const uint8_t *p_src, uint64_t p_length) override; ///< store an array of bytes
virtual bool file_exists(const String &p_name) override; ///< return true if a file exists

View File

@@ -121,16 +121,18 @@ Error FileAccessWindowsPipe::get_error() const {
return last_error;
}
void FileAccessWindowsPipe::store_buffer(const uint8_t *p_src, uint64_t p_length) {
ERR_FAIL_COND_MSG(fd[1] == nullptr, "Pipe must be opened before use.");
ERR_FAIL_COND(!p_src && p_length > 0);
bool FileAccessWindowsPipe::store_buffer(const uint8_t *p_src, uint64_t p_length) {
ERR_FAIL_COND_V_MSG(fd[1] == nullptr, false, "Pipe must be opened before use.");
ERR_FAIL_COND_V(!p_src && p_length > 0, false);
DWORD read = -1;
bool ok = WriteFile(fd[1], p_src, p_length, &read, nullptr);
if (!ok || read != p_length) {
last_error = ERR_FILE_CANT_WRITE;
return false;
} else {
last_error = OK;
return true;
}
}

View File

@@ -72,7 +72,7 @@ public:
virtual Error resize(int64_t p_length) override { return ERR_UNAVAILABLE; }
virtual void flush() override {}
virtual void store_buffer(const uint8_t *p_src, uint64_t p_length) override; ///< store an array of bytes
virtual bool store_buffer(const uint8_t *p_src, uint64_t p_length) override; ///< store an array of bytes
virtual bool file_exists(const String &p_name) override { return false; }