From 58d13dac34daf15abeb1868bda21715106ec7412 Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Sat, 14 Dec 2024 14:43:01 +0000 Subject: [PATCH] FileSystem: Add ReadFileWithPartialProgress for multiple files --- common/FileSystem.cpp | 10 +++++++++- common/FileSystem.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/common/FileSystem.cpp b/common/FileSystem.cpp index a73dab6700..07dc498441 100644 --- a/common/FileSystem.cpp +++ b/common/FileSystem.cpp @@ -1230,6 +1230,14 @@ size_t FileSystem::ReadFileWithProgress(std::FILE* fp, void* dst, size_t length, { progress->SetProgressRange(100); + return FileSystem::ReadFileWithPartialProgress(fp, dst, length, progress, 0, 100, error, chunk_size); +} + +size_t FileSystem::ReadFileWithPartialProgress(std::FILE* fp, void* dst, size_t length, + ProgressCallback* progress, int startPercent, int endPercent, Error* error, size_t chunk_size) +{ + const int deltaPercent = endPercent - startPercent; + size_t done = 0; while (done < length) { @@ -1243,7 +1251,7 @@ size_t FileSystem::ReadFileWithProgress(std::FILE* fp, void* dst, size_t length, break; } - progress->SetProgressValue((done * 100) / length); + progress->SetProgressValue(startPercent + (done * deltaPercent) / length); done += read_size; } diff --git a/common/FileSystem.h b/common/FileSystem.h index f731542b5a..0ffccbb4c9 100644 --- a/common/FileSystem.h +++ b/common/FileSystem.h @@ -144,6 +144,8 @@ namespace FileSystem bool WriteStringToFile(const char* filename, const std::string_view sv); size_t ReadFileWithProgress(std::FILE* fp, void* dst, size_t length, ProgressCallback* progress, Error* error = nullptr, size_t chunk_size = 16 * 1024 * 1024); + size_t ReadFileWithPartialProgress(std::FILE* fp, void* dst, size_t length, ProgressCallback* progress, + int startPercent, int endPercent, Error* error = nullptr, size_t chunk_size = 16 * 1024 * 1024); /// creates a directory in the local filesystem /// if the directory already exists, the return value will be true.