From 535e7eccda01c2d9b95426d6e73933cdaa8f1743 Mon Sep 17 00:00:00 2001 From: scawful Date: Wed, 7 Aug 2024 15:07:03 -0400 Subject: [PATCH] add alternate file size seek to Rom::LoadFromFile --- src/app/rom.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/rom.cc b/src/app/rom.cc index 5540c35e..6baaafc3 100644 --- a/src/app/rom.cc +++ b/src/app/rom.cc @@ -159,8 +159,13 @@ absl::Status Rom::LoadFromFile(const std::string& filename, bool z3_load) { try { size_ = std::filesystem::file_size(filename_); } catch (const std::filesystem::filesystem_error& e) { - return absl::InternalError( - absl::StrCat("Could not get file size: ", filename_, " - ", e.what())); + // Try to get the file size from the open file stream + file.seekg(0, std::ios::end); + if (!file) { + return absl::InternalError(absl::StrCat( + "Could not get file size: ", filename_, " - ", e.what())); + } + size_ = file.tellg(); } rom_data_.resize(size_);