Skip to content

Commit

Permalink
Properly set "Install and Relaunch" text
Browse files Browse the repository at this point in the history
  • Loading branch information
Deadpikle committed Apr 19, 2021
1 parent 623214b commit 45af290
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/NetSparkle.Samples.NetCore.WinForms/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public Form1()
_sparkleUpdateDetector = new SparkleUpdater(appcastUrl, new DSAChecker(Enums.SecurityMode.Strict))
{
UIFactory = new NetSparkleUpdater.UI.WinForms.UIFactory(icon),
//RelaunchAfterUpdate = true,
//ShowsUIOnMainThread = true,
//UseNotificationToast = true
};
Expand Down
1 change: 1 addition & 0 deletions src/NetSparkle.Samples.NetFramework.WinForms/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public Form1()
_sparkleUpdateDetector = new SparkleUpdater(appcastUrl, new DSAChecker(Enums.SecurityMode.Strict))
{
UIFactory = new NetSparkleUpdater.UI.WinForms.UIFactory(icon),
//RelaunchAfterUpdate = true,
//ShowsUIOnMainThread = true,
//UseNotificationToast = true
};
Expand Down
3 changes: 2 additions & 1 deletion src/NetSparkle.UI.Avalonia/UIFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public virtual IDownloadProgress CreateProgressWindow(SparkleUpdater sparkle, Ap
{
var viewModel = new DownloadProgressWindowViewModel()
{
ItemToDownload = item
ItemToDownload = item,
SoftwareWillRelaunchAfterUpdateInstalled = sparkle.RelaunchAfterUpdate
};
return new DownloadProgressWindow(viewModel, _iconBitmap)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ public bool IsActionButtonVisible
set { _isActionButtonVisible = value; NotifyPropertyChanged(); }
}

/// <summary>
/// Whether or not the software will relaunch after the update has been installed
/// </summary>
public bool SoftwareWillRelaunchAfterUpdateInstalled { get; set; } = false;

/// <summary>
/// Change whether or not the <see cref="AppCastItem"/> download file has finished downloading
/// </summary>
Expand All @@ -174,7 +179,7 @@ public void SetFinishedDownloading(bool isInstallFileValid)
if (isInstallFileValid)
{
IsActionButtonVisible = true;
ActionButtonTitle = "Install and Relaunch";
ActionButtonTitle = SoftwareWillRelaunchAfterUpdateInstalled ? "Install and Relaunch" : "Install";
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion src/NetSparkle.UI.WPF/UIFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public virtual IDownloadProgress CreateProgressWindow(SparkleUpdater sparkle, Ap
{
var viewModel = new DownloadProgressWindowViewModel()
{
ItemToDownload = item
ItemToDownload = item,
SoftwareWillRelaunchAfterUpdateInstalled = sparkle.RelaunchAfterUpdate
};
return new DownloadProgressWindow(viewModel)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ public bool IsActionButtonVisible
set { _isActionButtonVisible = value; NotifyPropertyChanged(); }
}

/// <summary>
/// Whether or not the software will relaunch after the update has been installed
/// </summary>
public bool SoftwareWillRelaunchAfterUpdateInstalled { get; set; } = false;

/// <summary>
/// Change whether or not the <see cref="AppCastItem"/> download file has finished downloading
/// </summary>
Expand All @@ -173,7 +178,7 @@ public void SetFinishedDownloading(bool isInstallFileValid)
if (isInstallFileValid)
{
IsActionButtonVisible = true;
ActionButtonTitle = "Install and Relaunch";
ActionButtonTitle = SoftwareWillRelaunchAfterUpdateInstalled ? "Install and Relaunch" : "Install";
}
else
{
Expand Down
12 changes: 12 additions & 0 deletions src/NetSparkle.UI.WinForms.NetCore/DownloadProgressWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ public partial class DownloadProgressWindow : Form, IDownloadProgress
private bool _shouldLaunchInstallFileOnClose = false;
private bool _didCallDownloadProcessCompletedHandler = false;

/// <summary>
/// Whether or not the software will relaunch after the update has been installed
/// </summary>
public bool SoftwareWillRelaunchAfterUpdateInstalled
{
set
{
btnInstallAndReLaunch.Text = value ? "Install and Relaunch" : "Install";
}
}

/// <summary>
/// Constructor
/// </summary>
Expand All @@ -35,6 +46,7 @@ public DownloadProgressWindow(AppCastItem item, Icon applicationIcon)

// init ui
btnInstallAndReLaunch.Visible = false;
btnInstallAndReLaunch.Text = "Install and Relaunch";
lblHeader.Text = lblHeader.Text.Replace("APP", item.AppName + " " + item.Version);
downloadProgressLbl.Text = "";
progressDownload.Maximum = 100;
Expand Down
5 changes: 4 additions & 1 deletion src/NetSparkle.UI.WinForms.NetCore/UIFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ public virtual IUpdateAvailable CreateUpdateAvailableWindow(SparkleUpdater spark
/// <inheritdoc/>
public virtual IDownloadProgress CreateProgressWindow(SparkleUpdater sparkle, AppCastItem item)
{
return new DownloadProgressWindow(item, _applicationIcon);
return new DownloadProgressWindow(item, _applicationIcon)
{
SoftwareWillRelaunchAfterUpdateInstalled = sparkle.RelaunchAfterUpdate
};
}

/// <inheritdoc/>
Expand Down
12 changes: 12 additions & 0 deletions src/NetSparkle.UI.WinForms.NetFramework/DownloadProgressWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ public partial class DownloadProgressWindow : Form, IDownloadProgress
private bool _shouldLaunchInstallFileOnClose = false;
private bool _didCallDownloadProcessCompletedHandler = false;

/// <summary>
/// Whether or not the software will relaunch after the update has been installed
/// </summary>
public bool SoftwareWillRelaunchAfterUpdateInstalled
{
set
{
btnInstallAndReLaunch.Text = value ? "Install and Relaunch" : "Install";
}
}

/// <summary>
/// Constructor
/// </summary>
Expand All @@ -35,6 +46,7 @@ public DownloadProgressWindow(AppCastItem item, Icon applicationIcon)

// init ui
btnInstallAndReLaunch.Visible = false;
btnInstallAndReLaunch.Text = "Install and Relaunch";
lblHeader.Text = lblHeader.Text.Replace("APP", item.AppName + " " + item.Version);
downloadProgressLbl.Text = "";
progressDownload.Maximum = 100;
Expand Down
5 changes: 4 additions & 1 deletion src/NetSparkle.UI.WinForms.NetFramework/UIFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ public virtual IUpdateAvailable CreateUpdateAvailableWindow(SparkleUpdater spark
/// <inheritdoc/>
public virtual IDownloadProgress CreateProgressWindow(SparkleUpdater sparkle, AppCastItem item)
{
return new DownloadProgressWindow(item, _applicationIcon);
return new DownloadProgressWindow(item, _applicationIcon)
{
SoftwareWillRelaunchAfterUpdateInstalled = sparkle.RelaunchAfterUpdate
};
}

/// <inheritdoc/>
Expand Down
9 changes: 5 additions & 4 deletions src/NetSparkle/SparkleUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,11 +1307,11 @@ protected virtual async Task RunDownloadedInstaller(string downloadFilePath)

string processID = Process.GetCurrentProcess().Id.ToString();

using (StreamWriter write = new StreamWriter(batchFilePath, false, new UTF8Encoding(false)))
using (FileStream stream = new FileStream(batchFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 4096, true))
using (StreamWriter write = new StreamWriter(stream, new UTF8Encoding(false))/*new StreamWriter(batchFilePath, false, new UTF8Encoding(false))*/)
{
if (isWindows)
{
await write.WriteLineAsync("@echo off");
// We should wait until the host process has died before starting the installer.
// This way, any DLLs or other items can be replaced properly.
// Code from: http://stackoverflow.com/a/22559462/3938401
Expand All @@ -1320,10 +1320,11 @@ protected virtual async Task RunDownloadedInstaller(string downloadFilePath)
{
relaunchAfterUpdate = $@"
cd ""{workingDir}""
{executableName}";
""{executableName}""";
}

string output = $@"
@echo off
chcp 65001 > nul
set /A counter=0
setlocal ENABLEDELAYEDEXPANSION
Expand All @@ -1340,7 +1341,7 @@ setlocal ENABLEDELAYEDEXPANSION
:install
{installerCmd}
:afterinstall
{relaunchAfterUpdate}
{relaunchAfterUpdate.Trim()}
endlocal";
await write.WriteAsync(output);
write.Close();
Expand Down

0 comments on commit 45af290

Please sign in to comment.