diff --git a/Application/FileConverter/Services/IUpgradeService.cs b/Application/FileConverter/Services/IUpgradeService.cs index 5bcca07..3ca8457 100644 --- a/Application/FileConverter/Services/IUpgradeService.cs +++ b/Application/FileConverter/Services/IUpgradeService.cs @@ -11,5 +11,9 @@ namespace FileConverter.Services } void CheckForUpgrade(); + + void StartUpgrade(); + + void CancelUpgrade(); } } diff --git a/Application/FileConverter/Services/UpgradeService.cs b/Application/FileConverter/Services/UpgradeService.cs index 3fb45fe..b3d7a2f 100644 --- a/Application/FileConverter/Services/UpgradeService.cs +++ b/Application/FileConverter/Services/UpgradeService.cs @@ -30,18 +30,56 @@ namespace FileConverter.Services public void CheckForUpgrade() { -#if DEBUG - Task task = Upgrade.Helpers.GetLatestVersionDescriptionAsync(this.OnGetLatestVersionDescription); -#else - long fileTime = Registry.GetValue(Registry.Keys.LastUpdateCheckDate); - DateTime lastUpdateDateTime = DateTime.FromFileTime(fileTime); - - TimeSpan durationSinceLastUpdate = DateTime.Now.Subtract(lastUpdateDateTime); - if (durationSinceLastUpdate > new TimeSpan(1, 0, 0, 0)) + try { +#if DEBUG Task task = Upgrade.Helpers.GetLatestVersionDescriptionAsync(this.OnGetLatestVersionDescription); - } +#else + long fileTime = Registry.GetValue(Registry.Keys.LastUpdateCheckDate); + DateTime lastUpdateDateTime = DateTime.FromFileTime(fileTime); + + TimeSpan durationSinceLastUpdate = DateTime.Now.Subtract(lastUpdateDateTime); + if (durationSinceLastUpdate > new TimeSpan(1, 0, 0, 0)) + { + Task task = Upgrade.Helpers.GetLatestVersionDescriptionAsync(this.OnGetLatestVersionDescription); + } #endif + } + catch (Exception exception) + { + Diagnostics.Debug.Log($"Failed to check upgrade: {exception.Message}."); + } + } + + public void StartUpgrade() + { + if (this.UpgradeVersionDescription == null) + { + Diagnostics.Debug.Log("Can't start upgrade because no check upgrade have been done."); + return; + } + + try + { + this.UpgradeVersionDescription.NeedToUpgrade = true; + Task task = Upgrade.Helpers.DownloadInstallerAsync(this.upgradeVersionDescription); + } + catch (Exception exception) + { + Diagnostics.Debug.Log($"Failed to download upgrade: {exception.Message}."); + } + } + + public void CancelUpgrade() + { + if (this.UpgradeVersionDescription == null) + { + Diagnostics.Debug.Log("Can't cancel upgrade because there is no upgrade in progress."); + return; + } + + Diagnostics.Debug.Log("Cancel application upgrade."); + this.UpgradeVersionDescription.NeedToUpgrade = false; } private void OnGetLatestVersionDescription(UpgradeVersionDescription description) diff --git a/Application/FileConverter/ViewModels/UpgradeViewModel.cs b/Application/FileConverter/ViewModels/UpgradeViewModel.cs index faa833d..04b3ad7 100644 --- a/Application/FileConverter/ViewModels/UpgradeViewModel.cs +++ b/Application/FileConverter/ViewModels/UpgradeViewModel.cs @@ -127,8 +127,8 @@ namespace FileConverter.ViewModels private void ExecuteDownloadInstallerCommand() { - this.upgradeVersionDescription.NeedToUpgrade = true; - Upgrade.Helpers.DownloadInstallerAsync(this.upgradeVersionDescription); + IUpgradeService upgradeService = SimpleIoc.Default.GetInstance(); + upgradeService.StartUpgrade(); INavigationService navigationService = SimpleIoc.Default.GetInstance(); navigationService.GoBack();