Rework waiting time into the installer process instead.

This commit is contained in:
Dario 2025-02-04 20:19:47 -03:00 committed by Hyper
parent 4fb6bf4d0d
commit 42d22ff91d
3 changed files with 16 additions and 9 deletions

View file

@ -435,7 +435,7 @@ bool Installer::parseSources(const Input &input, Journal &journal, Sources &sour
return true; return true;
} }
bool Installer::install(const Sources &sources, const std::filesystem::path &targetDirectory, bool skipHashChecks, Journal &journal, const std::function<bool()> &progressCallback) bool Installer::install(const Sources &sources, const std::filesystem::path &targetDirectory, bool skipHashChecks, Journal &journal, std::chrono::seconds endWaitTime, const std::function<bool()> &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 // 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. // missing critical files required for the game to run. These files are used as the way to detect if the game is installed.
@ -504,6 +504,8 @@ bool Installer::install(const Sources &sources, const std::filesystem::path &tar
// Update the progress with the artificial amount attributed to the patching. // Update the progress with the artificial amount attributed to the patching.
journal.progressCounter += PatcherContribution; journal.progressCounter += PatcherContribution;
for (uint32_t i = 0; i < 2; i++)
{
if (!progressCallback()) if (!progressCallback())
{ {
journal.lastResult = Journal::Result::Cancelled; journal.lastResult = Journal::Result::Cancelled;
@ -511,6 +513,13 @@ bool Installer::install(const Sources &sources, const std::filesystem::path &tar
return false; 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; return true;
} }

View file

@ -79,7 +79,7 @@ struct Installer
static bool copyFiles(std::span<const FilePair> filePairs, const uint64_t *fileHashes, VirtualFileSystem &sourceVfs, const std::filesystem::path &targetDirectory, const std::string &validationFile, bool skipHashChecks, Journal &journal, const std::function<bool()> &progressCallback); static bool copyFiles(std::span<const FilePair> filePairs, const uint64_t *fileHashes, VirtualFileSystem &sourceVfs, const std::filesystem::path &targetDirectory, const std::string &validationFile, bool skipHashChecks, Journal &journal, const std::function<bool()> &progressCallback);
static bool parseContent(const std::filesystem::path &sourcePath, std::unique_ptr<VirtualFileSystem> &targetVfs, Journal &journal); static bool parseContent(const std::filesystem::path &sourcePath, std::unique_ptr<VirtualFileSystem> &targetVfs, Journal &journal);
static bool parseSources(const Input &input, Journal &journal, Sources &sources); 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<bool()> &progressCallback); static bool install(const Sources &sources, const std::filesystem::path &targetDirectory, bool skipHashChecks, Journal &journal, std::chrono::seconds endWaitTime, const std::function<bool()> &progressCallback);
static void rollback(Journal &journal); 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. // Convenience method for checking if the specified file contains the game. This should be used when the user selects the file.

View file

@ -1286,7 +1286,7 @@ static void DrawInstallingProgress()
static void InstallerThread() 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)); 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. // 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); 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_installerFinished = true;
g_installerCancelled = false; g_installerCancelled = false;
} }