diff --git a/common.cpp b/common.cpp index 202a29c..ab257a0 100644 --- a/common.cpp +++ b/common.cpp @@ -57,7 +57,6 @@ uint8_t *loadfile(const char *fn, size_t *num, size_t extra) { size_t n = 0, j = 0; uint8_t *buf = nullptr; EnhancedFile fi = oxfopen_enhanced(fn, "rb"); - if (fi) { if (fi.seek(0, SEEK_END) == 0) { long n_long = fi.tell(); @@ -73,7 +72,6 @@ uint8_t *loadfile(const char *fn, size_t *num, size_t extra) { } } } - if (num) *num = j; return buf; } diff --git a/core/file_io.cpp b/core/file_io.cpp index 6dde573..007e787 100644 --- a/core/file_io.cpp +++ b/core/file_io.cpp @@ -139,9 +139,9 @@ UniqueFile my_oxfopen_unique(const char* fn, const char* mode) { } // EnhancedFile 实现 -EnhancedFile::EnhancedFile(FILE* f) noexcept : file(f) {} +EnhancedFile::EnhancedFile(FILE* f) noexcept { file = UniqueFile(f); } -EnhancedFile::EnhancedFile(UniqueFile&& f) noexcept : file(std::move(f)) {} +EnhancedFile::EnhancedFile(UniqueFile&& f) noexcept { file = std::move(f); } EnhancedFile::operator bool() const noexcept { return file != nullptr; @@ -175,9 +175,9 @@ void EnhancedFile::close() noexcept { file.reset(); } -bool EnhancedFile::flush() noexcept { - if (file) return fflush(file.get()) == 0; - return false; +int EnhancedFile::flush() noexcept { + if (file) return fflush(file.get()); + return -1; } long EnhancedFile::tell() const noexcept { @@ -190,30 +190,34 @@ long EnhancedFile::tello() const noexcept { return -1L; } -bool EnhancedFile::seek(long offset, int origin) noexcept { - if (file) return fseek(file.get(), offset, origin) == 0; - return false; +int EnhancedFile::seek(long offset, int origin) noexcept { + if (file) return fseek(file.get(), offset, origin); + return -1; } -bool EnhancedFile::seeko(long offset, int origin) noexcept { - if (file) return fseeko(file.get(), offset, origin) == 0; - return false; +int EnhancedFile::seeko(long offset, int origin) noexcept { + if (file) return fseeko(file.get(), offset, origin); + return -1; } -bool EnhancedFile::eof() const noexcept { - if (file) return feof(file.get()) != 0; - return true; +int EnhancedFile::eof() const noexcept { + if (file) return feof(file.get()); + return -1; } -bool EnhancedFile::error() const noexcept { - if (file) return ferror(file.get()) != 0; - return true; +int EnhancedFile::error() const noexcept { + if (file) return ferror(file.get()); + return -1; } void EnhancedFile::clearerr() noexcept { if (file) ::clearerr(file.get()); } +void EnhancedFile::rewind() noexcept { + if (file) ::rewind(file.get()); +} + size_t EnhancedFile::write(const void* buffer, size_t size, size_t count) noexcept { if (file) return fwrite(buffer, size, count, file.get()); return 0; diff --git a/core/file_io.h b/core/file_io.h index 23aa891..2afb173 100644 --- a/core/file_io.h +++ b/core/file_io.h @@ -69,14 +69,14 @@ class EnhancedFile { UniqueFile release() noexcept; void reset(FILE* f = nullptr) noexcept; void close() noexcept; - bool flush() noexcept; + int flush() noexcept; long tell() const noexcept; long tello() const noexcept; - bool seek(long offset, int origin) noexcept; - bool seeko(long offset, int origin) noexcept; - void rewind() noexcept { seek(0, SEEK_SET); } - bool eof() const noexcept; - bool error() const noexcept; + int seek(long offset, int origin) noexcept; + int seeko(long offset, int origin) noexcept; + void rewind() noexcept; + int eof() const noexcept; + int error() const noexcept; void clearerr() noexcept; // 读写操作 diff --git a/main_console.cpp b/main_console.cpp index 3a3d313..db09fff 100644 --- a/main_console.cpp +++ b/main_console.cpp @@ -946,6 +946,7 @@ int main_console(int argc, char** argv) { argv += argchange; continue; } + fi.close(); if (cve_v2) { size_t execsize = send_file(io, fn, addr, 0, 528, 0, 0); int n, gapsize = exec_addr - addr - execsize; diff --git a/pages/page_connect.cpp b/pages/page_connect.cpp index a3ab6a0..377ce78 100644 --- a/pages/page_connect.cpp +++ b/pages/page_connect.cpp @@ -144,6 +144,7 @@ void on_button_clicked_fdl_exec(GtkWidgetHelper helper) { DEG_LOG(W, "File does not exist."); return; } + fi.close(); if (!isKickMode) send_file(io, fdl_path, fdl_addr, end_data, blk_size ? blk_size : 528, 0, 0); else send_file(io, fdl_path, fdl_addr, 0, 528, 0, 0); } else { @@ -381,7 +382,8 @@ void on_button_clicked_fdl_exec(GtkWidgetHelper helper) { if (!fi) { DEG_LOG(W, "File does not exist.\n"); return; - } else fi.close(); + } + fi.close(); send_file(io, fdl_path, fdl_addr, end_data, 528, 0, 0); if (cve_addr && strlen(cve_addr) > 0 && isCve) { bool isCVEv2 = helper.getSwitchState(helper.getWidget("cve_v2"));