From 355c068068b7619d49dc222eddd46047b1a95e1e Mon Sep 17 00:00:00 2001 From: Ralph Sennhauser Date: Thu, 18 Jun 2026 21:36:15 +0200 Subject: [PATCH] Remove helper function FileSize Use std::filesystem at caller site instead. Signed-off-by: Ralph Sennhauser --- source/lib/file/file_system.cpp | 14 -------------- source/lib/file/file_system.h | 5 +---- source/ps/ModIo.cpp | 9 +++++++-- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/source/lib/file/file_system.cpp b/source/lib/file/file_system.cpp index 0551c7dbe3..b802e79095 100644 --- a/source/lib/file/file_system.cpp +++ b/source/lib/file/file_system.cpp @@ -62,20 +62,6 @@ bool FileExists(const OsPath& pathname) } -u64 FileSize(const OsPath& pathname) -{ - try - { - return static_cast(std::filesystem::file_size(pathname.string())); - } - catch (std::filesystem::filesystem_error& err) - { - debug_printf("FileSize: failed to get filesize for '%s', reason: %s\n", pathname.string8().c_str(), err.what()); - } - return 0; -} - - Status GetFileInfo(const OsPath& pathname, CFileInfo* pPtrInfo) { try diff --git a/source/lib/file/file_system.h b/source/lib/file/file_system.h index 457d41d2c3..a8e97e8a74 100644 --- a/source/lib/file/file_system.h +++ b/source/lib/file/file_system.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -38,9 +38,6 @@ bool DirectoryExists(const OsPath& path); bool FileExists(const OsPath& pathname); -u64 FileSize(const OsPath& pathname); - - // (bundling size and mtime avoids a second expensive call to stat()) class CFileInfo { diff --git a/source/ps/ModIo.cpp b/source/ps/ModIo.cpp index e2ac664b46..73c90299d0 100644 --- a/source/ps/ModIo.cpp +++ b/source/ps/ModIo.cpp @@ -558,8 +558,13 @@ bool ModIo::VerifyDownloadedFile(std::string& err) { // Verify filesize, as a first basic download check. { - u64 filesize = std::stoull(m_ModData[m_DownloadModID].properties.at("filesize")); - if (filesize != FileSize(m_DownloadFilePath)) + std::error_code ec{}; + const u64 fileSize{static_cast(std::filesystem::file_size(std::filesystem::path(m_DownloadFilePath.string()), ec))}; + if (ec) + LOGERROR("Failed to get filesize for '%s', reason: %s", m_DownloadFilePath.string8().c_str(), ec.message()); + const u64 expectedFileSize{std::stoull(m_ModData[m_DownloadModID].properties.at("filesize"))}; + + if (ec || fileSize != expectedFileSize) { err = g_L10n.Translate("Mismatched filesize."); return false;