diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 5af684d..f0a96cc 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -10,6 +10,8 @@ namespace Bloxstrap public class Bootstrapper { #region Properties + private const int ProgressBarMaximum = 10000; + // in case a new package is added, you can find the corresponding directory // by opening the stock bootstrapper in a hex editor // TODO - there ideally should be a less static way to do this that's not hardcoded? @@ -91,15 +93,16 @@ namespace Bloxstrap private void UpdateProgressBar() { - int newProgress = (int)Math.Floor(_progressIncrement * _totalDownloadedBytes); + if (Dialog is null) + return; + + int progressValue = (int)Math.Floor(_progressIncrement * _totalDownloadedBytes); // bugcheck: if we're restoring a file from a package, it'll incorrectly increment the progress beyond 100 // too lazy to fix properly so lol - if (newProgress > 100) - return; + progressValue = Math.Clamp(progressValue, 0, ProgressBarMaximum); - if (Dialog is not null) - Dialog.ProgressValue = newProgress; + Dialog.ProgressValue = progressValue; } public async Task Run() @@ -806,10 +809,12 @@ namespace Bloxstrap { Dialog.CancelEnabled = true; Dialog.ProgressStyle = ProgressBarStyle.Continuous; - } - // compute total bytes to download - _progressIncrement = (double)100 / _versionPackageManifest.Sum(package => package.PackedSize); + Dialog.ProgressMaximum = ProgressBarMaximum; + + // compute total bytes to download + _progressIncrement = (double)ProgressBarMaximum / _versionPackageManifest.Sum(package => package.PackedSize); + } foreach (Package package in _versionPackageManifest) { diff --git a/Bloxstrap/UI/Elements/Bootstrapper/Base/WinFormsDialogBase.cs b/Bloxstrap/UI/Elements/Bootstrapper/Base/WinFormsDialogBase.cs index 69d4b36..d59bdc5 100644 --- a/Bloxstrap/UI/Elements/Bootstrapper/Base/WinFormsDialogBase.cs +++ b/Bloxstrap/UI/Elements/Bootstrapper/Base/WinFormsDialogBase.cs @@ -14,6 +14,7 @@ namespace Bloxstrap.UI.Elements.Bootstrapper.Base protected virtual string _message { get; set; } = "Please wait..."; protected virtual ProgressBarStyle _progressStyle { get; set; } protected virtual int _progressValue { get; set; } + protected virtual int _progressMaximum { get; set; } protected virtual bool _cancelEnabled { get; set; } public string Message @@ -40,6 +41,18 @@ namespace Bloxstrap.UI.Elements.Bootstrapper.Base } } + public int ProgressMaximum + { + get => _progressMaximum; + set + { + if (InvokeRequired) + Invoke(() => _progressMaximum = value); + else + _progressMaximum = value; + } + } + public int ProgressValue { get => _progressValue; diff --git a/Bloxstrap/UI/Elements/Bootstrapper/ByfronDialog.xaml b/Bloxstrap/UI/Elements/Bootstrapper/ByfronDialog.xaml index 183be50..1a0b6c8 100644 --- a/Bloxstrap/UI/Elements/Bootstrapper/ByfronDialog.xaml +++ b/Bloxstrap/UI/Elements/Bootstrapper/ByfronDialog.xaml @@ -38,7 +38,7 @@ - + diff --git a/Bloxstrap/UI/Elements/Bootstrapper/ByfronDialog.xaml.cs b/Bloxstrap/UI/Elements/Bootstrapper/ByfronDialog.xaml.cs index b01d083..83dc818 100644 --- a/Bloxstrap/UI/Elements/Bootstrapper/ByfronDialog.xaml.cs +++ b/Bloxstrap/UI/Elements/Bootstrapper/ByfronDialog.xaml.cs @@ -41,6 +41,16 @@ namespace Bloxstrap.UI.Elements.Bootstrapper } } + public int ProgressMaximum + { + get => _viewModel.ProgressMaximum; + set + { + _viewModel.ProgressMaximum = value; + _viewModel.OnPropertyChanged(nameof(_viewModel.ProgressMaximum)); + } + } + public int ProgressValue { get => _viewModel.ProgressValue; diff --git a/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml b/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml index 40cc7f9..ce265a6 100644 --- a/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml +++ b/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml @@ -36,7 +36,7 @@ - + diff --git a/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml.cs b/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml.cs index 7ab6cdc..780e75d 100644 --- a/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml.cs +++ b/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml.cs @@ -42,6 +42,16 @@ namespace Bloxstrap.UI.Elements.Bootstrapper } } + public int ProgressMaximum + { + get => _viewModel.ProgressMaximum; + set + { + _viewModel.ProgressMaximum = value; + _viewModel.OnPropertyChanged(nameof(_viewModel.ProgressMaximum)); + } + } + public int ProgressValue { get => _viewModel.ProgressValue; diff --git a/Bloxstrap/UI/Elements/Bootstrapper/LegacyDialog2008.cs b/Bloxstrap/UI/Elements/Bootstrapper/LegacyDialog2008.cs index ce2a1e8..c1dd219 100644 --- a/Bloxstrap/UI/Elements/Bootstrapper/LegacyDialog2008.cs +++ b/Bloxstrap/UI/Elements/Bootstrapper/LegacyDialog2008.cs @@ -21,6 +21,12 @@ namespace Bloxstrap.UI.Elements.Bootstrapper set => ProgressBar.Style = value; } + protected override int _progressMaximum + { + get => ProgressBar.Maximum; + set => ProgressBar.Maximum = value; + } + protected override int _progressValue { get => ProgressBar.Value; diff --git a/Bloxstrap/UI/Elements/Bootstrapper/LegacyDialog2011.cs b/Bloxstrap/UI/Elements/Bootstrapper/LegacyDialog2011.cs index 5f92d4e..7248b1c 100644 --- a/Bloxstrap/UI/Elements/Bootstrapper/LegacyDialog2011.cs +++ b/Bloxstrap/UI/Elements/Bootstrapper/LegacyDialog2011.cs @@ -20,6 +20,12 @@ namespace Bloxstrap.UI.Elements.Bootstrapper set => ProgressBar.Style = value; } + protected override int _progressMaximum + { + get => ProgressBar.Maximum; + set => ProgressBar.Maximum = value; + } + protected override int _progressValue { get => ProgressBar.Value; diff --git a/Bloxstrap/UI/Elements/Bootstrapper/ProgressDialog.cs b/Bloxstrap/UI/Elements/Bootstrapper/ProgressDialog.cs index 4f9bb01..b00e8c6 100644 --- a/Bloxstrap/UI/Elements/Bootstrapper/ProgressDialog.cs +++ b/Bloxstrap/UI/Elements/Bootstrapper/ProgressDialog.cs @@ -21,6 +21,12 @@ namespace Bloxstrap.UI.Elements.Bootstrapper set => ProgressBar.Style = value; } + protected override int _progressMaximum + { + get => ProgressBar.Maximum; + set => ProgressBar.Maximum = value; + } + protected override int _progressValue { get => ProgressBar.Value; diff --git a/Bloxstrap/UI/Elements/Bootstrapper/VistaDialog.cs b/Bloxstrap/UI/Elements/Bootstrapper/VistaDialog.cs index 8a47f9c..c228bf8 100644 --- a/Bloxstrap/UI/Elements/Bootstrapper/VistaDialog.cs +++ b/Bloxstrap/UI/Elements/Bootstrapper/VistaDialog.cs @@ -37,6 +37,18 @@ namespace Bloxstrap.UI.Elements.Bootstrapper } } + protected sealed override int _progressMaximum + { + get => _dialogPage.ProgressBar?.Maximum ?? 0; + set + { + if (_dialogPage.ProgressBar is null) + return; + + _dialogPage.ProgressBar.Maximum = value; + } + } + protected sealed override int _progressValue { get => _dialogPage.ProgressBar?.Value ?? 0; diff --git a/Bloxstrap/UI/IBootstrapperDialog.cs b/Bloxstrap/UI/IBootstrapperDialog.cs index 4b44900..e15f7fb 100644 --- a/Bloxstrap/UI/IBootstrapperDialog.cs +++ b/Bloxstrap/UI/IBootstrapperDialog.cs @@ -9,6 +9,7 @@ namespace Bloxstrap.UI string Message { get; set; } ProgressBarStyle ProgressStyle { get; set; } int ProgressValue { get; set; } + int ProgressMaximum { get; set; } bool CancelEnabled { get; set; } void ShowBootstrapper(); diff --git a/Bloxstrap/UI/ViewModels/Bootstrapper/BootstrapperDialogViewModel.cs b/Bloxstrap/UI/ViewModels/Bootstrapper/BootstrapperDialogViewModel.cs index 593921d..2a5c523 100644 --- a/Bloxstrap/UI/ViewModels/Bootstrapper/BootstrapperDialogViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Bootstrapper/BootstrapperDialogViewModel.cs @@ -16,6 +16,7 @@ namespace Bloxstrap.UI.ViewModels.Bootstrapper public ImageSource Icon { get; set; } = App.Settings.Prop.BootstrapperIcon.GetIcon().GetImageSource(); public string Message { get; set; } = "Please wait..."; public bool ProgressIndeterminate { get; set; } = true; + public int ProgressMaximum { get; set; } = 0; public int ProgressValue { get; set; } = 0; public bool CancelEnabled { get; set; } = false;