[Emulator] use filesystem::file_size instead of ftell where possible

This commit is contained in:
Gliniak 2024-03-22 11:03:34 +01:00
parent c9bf44f4f4
commit a966143823
3 changed files with 4 additions and 9 deletions

View File

@ -26,9 +26,8 @@ RawModule::~RawModule() {}
bool RawModule::LoadFile(uint32_t base_address, bool RawModule::LoadFile(uint32_t base_address,
const std::filesystem::path& path) { const std::filesystem::path& path) {
FILE* file = xe::filesystem::OpenFile(path, "rb"); FILE* file = xe::filesystem::OpenFile(path, "rb");
fseek(file, 0, SEEK_END); const uint32_t file_length =
uint32_t file_length = static_cast<uint32_t>(ftell(file)); static_cast<uint32_t>(std::filesystem::file_size(path));
fseek(file, 0, SEEK_SET);
// Allocate memory. // Allocate memory.
// Since we have no real heap just load it wherever. // Since we have no real heap just load it wherever.

View File

@ -100,9 +100,7 @@ int shader_compiler_main(const std::vector<std::string>& args) {
xe::path_to_utf8(cvars::shader_input)); xe::path_to_utf8(cvars::shader_input));
return 1; return 1;
} }
fseek(input_file, 0, SEEK_END); size_t input_file_size = std::filesystem::file_size(cvars::shader_input);
size_t input_file_size = ftell(input_file);
fseek(input_file, 0, SEEK_SET);
std::vector<uint32_t> ucode_dwords(input_file_size / 4); std::vector<uint32_t> ucode_dwords(input_file_size / 4);
fread(ucode_dwords.data(), 4, ucode_dwords.size(), input_file); fread(ucode_dwords.data(), 4, ucode_dwords.size(), input_file);
fclose(input_file); fclose(input_file);

View File

@ -307,9 +307,7 @@ X_RESULT ContentManager::GetContentThumbnail(
auto thumb_path = package_path / kThumbnailFileName; auto thumb_path = package_path / kThumbnailFileName;
if (std::filesystem::exists(thumb_path)) { if (std::filesystem::exists(thumb_path)) {
auto file = xe::filesystem::OpenFile(thumb_path, "rb"); auto file = xe::filesystem::OpenFile(thumb_path, "rb");
fseek(file, 0, SEEK_END); size_t file_len = std::filesystem::file_size(thumb_path);
size_t file_len = ftell(file);
fseek(file, 0, SEEK_SET);
buffer->resize(file_len); buffer->resize(file_len);
fread(const_cast<uint8_t*>(buffer->data()), 1, buffer->size(), file); fread(const_cast<uint8_t*>(buffer->data()), 1, buffer->size(), file);
fclose(file); fclose(file);