Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -73,7 +72,6 @@ uint8_t *loadfile(const char *fn, size_t *num, size_t extra) {
}
}
}

if (num) *num = j;
return buf;
}
Expand Down
38 changes: 21 additions & 17 deletions core/file_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions core/file_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

// 读写操作
Expand Down
1 change: 1 addition & 0 deletions main_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion pages/page_connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"));
Expand Down
Loading