From 42d22ff91da4bd7f8c34edf8cfdaca779ebdd21d Mon Sep 17 00:00:00 2001 From: Dario Date: Tue, 4 Feb 2025 20:19:47 -0300 Subject: [PATCH] Rework waiting time into the installer process instead. --- UnleashedRecomp/install/installer.cpp | 19 ++++++++++++++----- UnleashedRecomp/install/installer.h | 2 +- UnleashedRecomp/ui/installer_wizard.cpp | 4 +--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/UnleashedRecomp/install/installer.cpp b/UnleashedRecomp/install/installer.cpp index 05df864b..8a3e7b35 100644 --- a/UnleashedRecomp/install/installer.cpp +++ b/UnleashedRecomp/install/installer.cpp @@ -435,7 +435,7 @@ bool Installer::parseSources(const Input &input, Journal &journal, Sources &sour return true; } -bool Installer::install(const Sources &sources, const std::filesystem::path &targetDirectory, bool skipHashChecks, Journal &journal, const std::function &progressCallback) +bool Installer::install(const Sources &sources, const std::filesystem::path &targetDirectory, bool skipHashChecks, Journal &journal, std::chrono::seconds endWaitTime, const std::function &progressCallback) { // Install files in reverse order of importance. In case of a process crash or power outage, this will increase the likelihood of the installation // missing critical files required for the game to run. These files are used as the way to detect if the game is installed. @@ -504,11 +504,20 @@ bool Installer::install(const Sources &sources, const std::filesystem::path &tar // Update the progress with the artificial amount attributed to the patching. journal.progressCounter += PatcherContribution; - if (!progressCallback()) + for (uint32_t i = 0; i < 2; i++) { - journal.lastResult = Journal::Result::Cancelled; - journal.lastErrorMessage = "Installation was cancelled."; - return false; + if (!progressCallback()) + { + journal.lastResult = Journal::Result::Cancelled; + journal.lastErrorMessage = "Installation was cancelled."; + return false; + } + + if (i == 0) + { + // Wait the specified amount of time to allow the consumer of the callbacks to animate, halt or cancel the installation for a while after it's finished. + std::this_thread::sleep_for(endWaitTime); + } } return true; diff --git a/UnleashedRecomp/install/installer.h b/UnleashedRecomp/install/installer.h index 92a95cc2..198076dd 100644 --- a/UnleashedRecomp/install/installer.h +++ b/UnleashedRecomp/install/installer.h @@ -79,7 +79,7 @@ struct Installer static bool copyFiles(std::span filePairs, const uint64_t *fileHashes, VirtualFileSystem &sourceVfs, const std::filesystem::path &targetDirectory, const std::string &validationFile, bool skipHashChecks, Journal &journal, const std::function &progressCallback); static bool parseContent(const std::filesystem::path &sourcePath, std::unique_ptr &targetVfs, Journal &journal); static bool parseSources(const Input &input, Journal &journal, Sources &sources); - static bool install(const Sources &sources, const std::filesystem::path &targetDirectory, bool skipHashChecks, Journal &journal, const std::function &progressCallback); + static bool install(const Sources &sources, const std::filesystem::path &targetDirectory, bool skipHashChecks, Journal &journal, std::chrono::seconds endWaitTime, const std::function &progressCallback); static void rollback(Journal &journal); // Convenience method for checking if the specified file contains the game. This should be used when the user selects the file. diff --git a/UnleashedRecomp/ui/installer_wizard.cpp b/UnleashedRecomp/ui/installer_wizard.cpp index f1c8657a..2506e3f5 100644 --- a/UnleashedRecomp/ui/installer_wizard.cpp +++ b/UnleashedRecomp/ui/installer_wizard.cpp @@ -1286,7 +1286,7 @@ static void DrawInstallingProgress() static void InstallerThread() { - if (!Installer::install(g_installerSources, g_installPath, false, g_installerJournal, [&]() { + if (!Installer::install(g_installerSources, g_installPath, false, g_installerJournal, std::chrono::seconds(1), [&]() { g_installerProgressRatioTarget = float(double(g_installerJournal.progressCounter) / double(g_installerJournal.progressTotal)); // If user is being asked for confirmation on cancelling the installation, halt the installer from progressing further. @@ -1303,8 +1303,6 @@ static void InstallerThread() Installer::rollback(g_installerJournal); } - // Rest for a bit after finishing the installation, the device is tired - std::this_thread::sleep_for(std::chrono::seconds(1)); g_installerFinished = true; g_installerCancelled = false; }