Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Show more detailed progress messages in fallback dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Feb 21, 2022
1 parent 1e3ddb9 commit 430da60
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/Update/ComposedWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public void SetProgress(ulong completed, ulong total)
public void SetProgressIndeterminate()
=> LogThrow("Failed to set progress indeterminate.", () => _window?.SetProgressIndeterminate());

public void SetMessage(string message)
=> LogThrow("Failed to set progress indeterminate.", () => _window?.SetMessage(message));

public void Show()
=> LogThrow("Failed to show window.", () => _window?.Show());

Expand All @@ -69,7 +72,11 @@ public bool ShowQuestionDialog(string title, string message)

private void LogThrow(string msg, Action act)
{
try { act(); } catch (Exception ex) { this.Log().ErrorException(msg, ex); }
try {
act();
} catch (Exception ex) {
this.Log().ErrorException(msg, ex);
}
}

private T LogThrow<T>(string msg, Func<T> act, T errRet)
Expand Down
1 change: 1 addition & 0 deletions src/Update/ISplashWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ internal interface ISplashWindow : IDisposable, IEnableLogger
void Hide();
void SetProgressIndeterminate();
void SetProgress(ulong completed, ulong total);
void SetMessage(string message);
void ShowErrorDialog(string title, string message);
void ShowInfoDialog(string title, string message);
bool ShowQuestionDialog(string title, string message);
Expand Down
5 changes: 4 additions & 1 deletion src/Update/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Squirrel.SimpleSplat;
using Squirrel.SimpleSplat;
using Squirrel.Json;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -187,6 +187,7 @@ static async Task Setup(string setupPath, bool silentInstall, bool checkInstall)
// iterate through each missing dependency and download/run the installer.
foreach (var f in missingFrameworks) {
var localPath = Path.Combine(tempFolder, f.Id + ".exe");
splash.SetMessage($"Downloading {f.DisplayName}...");
await f.DownloadToFile(localPath, e => splash.SetProgress((ulong) e, 100));
splash.SetProgressIndeterminate();

Expand Down Expand Up @@ -217,6 +218,7 @@ static async Task Setup(string setupPath, bool silentInstall, bool checkInstall)
}
}

splash.SetMessage("Extracting package...");
Log.Info($"Starting package install from directory " + tempFolder);
splash.SetProgressIndeterminate();

Expand All @@ -237,6 +239,7 @@ static async Task Setup(string setupPath, bool silentInstall, bool checkInstall)
else splash.SetProgress((ulong) p, 90);
};

splash.SetMessage(null);
await Install(silentInstall, progressSource, tempFolder);
splash.Dispose();
}
Expand Down
19 changes: 19 additions & 0 deletions src/Update/Windows/ComCtlProgressDialog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using Squirrel.SimpleSplat;
using Vanara.PInvoke;
Expand Down Expand Up @@ -61,6 +62,24 @@ public override void SetProgressIndeterminate()
}
}

public override unsafe void SetMessage(string message)
{
lock (_lock) {
if (Handle == IntPtr.Zero) return;
if (String.IsNullOrWhiteSpace(message)) {
var arr = stackalloc byte[2];
SendMessage(_hwnd, (uint) TaskDialogMessage.TDM_SET_ELEMENT_TEXT, (IntPtr) 0, (IntPtr) arr);
} else {
var hg = Marshal.StringToHGlobalUni(message);
try {
SendMessage(_hwnd, (uint) TaskDialogMessage.TDM_SET_ELEMENT_TEXT, (IntPtr) 0, hg);
} finally {
Marshal.FreeHGlobal(hg);
}
}
}
}

public override void Show()
{
lock (_lock) {
Expand Down
6 changes: 5 additions & 1 deletion src/Update/Windows/User32SplashWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using Squirrel.SimpleSplat;
Expand Down Expand Up @@ -109,6 +108,11 @@ public override void SetProgress(ulong completed, ulong total)
InvalidateRect(_hwnd, null, false);
}

public override void SetMessage(string message)
{
// TODO: where to show the message in this splash window?
}

public override void Dispose()
{
if (_thread == null) return;
Expand Down
2 changes: 2 additions & 0 deletions src/Update/Windows/WindowBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public WindowBase(string appName)

public abstract void SetProgressIndeterminate();

public abstract void SetMessage(string message);

public abstract void Show();

public virtual void ShowErrorDialog(string title, string message)
Expand Down

0 comments on commit 430da60

Please sign in to comment.