Unify upgrade process and add update progress bar

This commit is contained in:
Mbucari 2023-02-27 14:07:52 -07:00
parent ded58f687d
commit d787843fd2
20 changed files with 264 additions and 247 deletions

View file

@ -71,7 +71,9 @@
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.visibleCountLbl = new LibationWinForms.FormattableToolStripStatusLabel();
this.upgradePb = new System.Windows.Forms.ToolStripProgressBar();
this.upgradeLbl = new System.Windows.Forms.ToolStripStatusLabel();
this.visibleCountLbl = new LibationWinForms.FormattableToolStripStatusLabel();
this.springLbl = new System.Windows.Forms.ToolStripStatusLabel();
this.backupsCountsLbl = new System.Windows.Forms.ToolStripStatusLabel();
this.pdfsCountsLbl = new LibationWinForms.FormattableToolStripStatusLabel();
@ -418,7 +420,9 @@
//
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(40, 40);
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.visibleCountLbl,
this.upgradeLbl,
this.upgradePb,
this.visibleCountLbl,
this.springLbl,
this.backupsCountsLbl,
this.pdfsCountsLbl});
@ -429,10 +433,21 @@
this.statusStrip1.Size = new System.Drawing.Size(1025, 22);
this.statusStrip1.TabIndex = 6;
this.statusStrip1.Text = "statusStrip1";
//
// visibleCountLbl
//
this.visibleCountLbl.FormatText = "Visible: {0}";
//
// upgradePb
//
this.upgradePb.Name = "upgradePb";
this.upgradePb.Size = new System.Drawing.Size(100, 16);
//
// upgradeLbl
//
this.upgradeLbl.Name = "upgradeLbl";
this.upgradeLbl.Size = new System.Drawing.Size(66, 17);
this.upgradeLbl.Text = "Upgrading:";
//
// visibleCountLbl
//
this.visibleCountLbl.FormatText = "Visible: {0}";
this.visibleCountLbl.Name = "visibleCountLbl";
this.visibleCountLbl.Size = new System.Drawing.Size(61, 17);
this.visibleCountLbl.Text = "Visible: {0}";
@ -671,5 +686,7 @@
private System.Windows.Forms.Button removeBooksBtn;
private System.Windows.Forms.Button doneRemovingBtn;
private System.Windows.Forms.ToolStripMenuItem setPdfDownloadedManualToolStripMenuItem;
}
private System.Windows.Forms.ToolStripProgressBar upgradePb;
private System.Windows.Forms.ToolStripStatusLabel upgradeLbl;
}
}

View file

@ -0,0 +1,34 @@
using LibationUiBase;
using LibationWinForms.Dialogs;
using System.Threading.Tasks;
namespace LibationWinForms
{
public partial class Form1
{
private void Configure_Update()
{
setProgressVisible(false);
#if !DEBUG
var upgrader = new Upgrader();
upgrader.DownloadProgress += (_, e) => Invoke(() => upgradePb.Value = int.Max(0, int.Min(100, (int)(e.ProgressPercentage ?? 0))));
upgrader.DownloadBegin += (_, _) => Invoke(() => setProgressVisible(true));
upgrader.DownloadCompleted += (_, _) => Invoke(() => setProgressVisible(false));
Shown += async (_, _) => await upgrader.CheForUpgradeAsync(UpgradeAvailable);
#endif
}
private void setProgressVisible(bool visible) => upgradeLbl.Visible = upgradePb.Visible = visible;
private Task UpgradeAvailable(UpgradeEventArgs e)
{
var notificationResult = new UpgradeNotificationDialog(e.UpgradeProperties).ShowDialog(this);
e.Ignore = notificationResult == System.Windows.Forms.DialogResult.Ignore;
e.InstallUpdate = notificationResult == System.Windows.Forms.DialogResult.Yes;
return Task.CompletedTask;
}
}
}

View file

@ -51,6 +51,7 @@ namespace LibationWinForms
Configure_Settings();
Configure_ProcessQueue();
Configure_Filter();
Configure_Update();
// misc which belongs in winforms app but doesn't have a UI element
Configure_NonUI();

View file

@ -13,19 +13,12 @@
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<StartupObject />
<IsPublishable>true</IsPublishable>
<!-- Version is now in AppScaffolding.csproj -->
</PropertyGroup>
<PropertyGroup>
<!--
HACK FOR COMPILER BUG 2021-09-14. Hopefully will be fixed in future versions
- Not using SatelliteResourceLanguages will load all language packs: works
- Specifying 'en' semicolon 1 more should load 1 language pack: works
- Specifying only 'en' should load no language packs: broken, still loads all
-->
<SatelliteResourceLanguages>en;es</SatelliteResourceLanguages>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@ -44,7 +37,6 @@
<ItemGroup>
<PackageReference Include="Autoupdater.NET.Official" Version="1.7.6" />
<PackageReference Include="Dinah.Core.WindowsDesktop" Version="7.2.2.1" />
</ItemGroup>

View file

@ -51,9 +51,6 @@ namespace LibationWinForms
MessageBoxLib.VerboseLoggingWarning_ShowIfTrue();
#if !DEBUG
checkForUpdate();
#endif
// logging is init'd here
AppScaffolding.LibationScaffolding.RunPostMigrationScaffolding(config);
}
@ -165,31 +162,6 @@ namespace LibationWinForms
// - long running. won't get a chance to finish in cli. don't move to app scaffolding
}
private static void checkForUpdate()
{
AppScaffolding.UpgradeProperties upgradeProperties;
try
{
upgradeProperties = AppScaffolding.LibationScaffolding.GetLatestRelease();
if (upgradeProperties is null)
return;
}
catch (Exception ex)
{
MessageBoxLib.ShowAdminAlert(null, "Error checking for update", "Error checking for update", ex);
return;
}
if (upgradeProperties.ZipUrl is null)
{
MessageBox.Show(upgradeProperties.HtmlUrl, "New version available");
return;
}
Updater.Run(upgradeProperties);
}
private static void postLoggingGlobalExceptionHandling()
{
// this line is all that's needed for strict handling

View file

@ -1,57 +0,0 @@
using System;
using System.Windows.Forms;
using AppScaffolding;
using AutoUpdaterDotNET;
using LibationFileManager;
using LibationWinForms.Dialogs;
namespace LibationWinForms
{
public static class Updater
{
public static void Run(UpgradeProperties upgradeProperties)
{
string latestVersionOnServer = upgradeProperties.LatestRelease.ToString();
string downloadZipUrl = upgradeProperties.ZipUrl;
AutoUpdater.ParseUpdateInfoEvent +=
args => args.UpdateInfo = new()
{
CurrentVersion = latestVersionOnServer,
DownloadURL = downloadZipUrl,
ChangelogURL = LibationScaffolding.RepositoryLatestUrl
};
void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args)
{
if (args is null || !args.IsUpdateAvailable)
return;
const string ignoreUpdate = "IgnoreUpdate";
var config = Configuration.Instance;
if (config.GetString(propertyName: ignoreUpdate) == args.CurrentVersion)
return;
var notificationResult = new UpgradeNotificationDialog(upgradeProperties).ShowDialog();
if (notificationResult == DialogResult.Ignore)
config.SetString(upgradeProperties.LatestRelease.ToString(), ignoreUpdate);
if (notificationResult != DialogResult.Yes) return;
try
{
Serilog.Log.Logger.Information("Start upgrade. {@DebugInfo}", new { CurrentlyInstalled = args.InstalledVersion, TargetVersion = args.CurrentVersion });
AutoUpdater.DownloadUpdate(args);
}
catch (Exception ex)
{
MessageBoxLib.ShowAdminAlert(null, "Error downloading update", "Error downloading update", ex);
}
}
AutoUpdater.CheckForUpdateEvent += AutoUpdaterOnCheckForUpdateEvent;
AutoUpdater.Start(LibationScaffolding.RepositoryLatestUrl);
}
}
}