add update button
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Blueberry.Redmine;
|
using Blueberry;
|
||||||
|
using Blueberry.Redmine;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
@@ -65,6 +66,11 @@ namespace BlueMine
|
|||||||
await _host.StopAsync();
|
await _host.StopAsync();
|
||||||
|
|
||||||
_host.Dispose();
|
_host.Dispose();
|
||||||
|
|
||||||
|
if (await UpdateManager.IsUpdateAvailable())
|
||||||
|
{
|
||||||
|
await UpdateManager.WaitUntilDownloadCompleteAndUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
"Nem elszámolható telefon, chat, email kommunikáció",
|
"Nem elszámolható telefon, chat, email kommunikáció",
|
||||||
];
|
];
|
||||||
|
|
||||||
public static readonly string UpdateScript = @"# Wait for the main app to close completely
|
public static readonly string UpdateScriptRestart = @"# Wait for the main app to close completely
|
||||||
Start-Sleep -Seconds 2
|
Start-Sleep -Seconds 2
|
||||||
|
|
||||||
$exePath = '{currentExe}'
|
$exePath = '{currentExe}'
|
||||||
@@ -62,6 +62,38 @@ Remove-Item $zipPath -Force
|
|||||||
# 'Start-Process' is the robust way to launch detached processes in PS
|
# 'Start-Process' is the robust way to launch detached processes in PS
|
||||||
Start-Process -FilePath $exePath -WorkingDirectory $destDir
|
Start-Process -FilePath $exePath -WorkingDirectory $destDir
|
||||||
|
|
||||||
|
# SELF-DESTRUCT: Remove this script
|
||||||
|
Remove-Item -LiteralPath $MyInvocation.MyCommand.Path -Force";
|
||||||
|
|
||||||
|
public static readonly string UpdateScriptNoRestart = @"# Wait for the main app to close completely
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
|
||||||
|
$exePath = '{currentExe}'
|
||||||
|
$zipPath = '{tempZip}'
|
||||||
|
$destDir = '{appDir}'
|
||||||
|
|
||||||
|
# Retry logic for deletion (in case antivirus or OS holds the lock)
|
||||||
|
$maxRetries = 10
|
||||||
|
$retryCount = 0
|
||||||
|
|
||||||
|
while ($retryCount -lt $maxRetries) {
|
||||||
|
try {
|
||||||
|
# Attempt to delete the old executable
|
||||||
|
if (Test-Path $exePath) { Remove-Item $exePath -Force -ErrorAction Stop }
|
||||||
|
break # If successful, exit loop
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Start-Sleep -Milliseconds 500
|
||||||
|
$retryCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Unzip the new version
|
||||||
|
Expand-Archive -Path $zipPath -DestinationPath $destDir -Force
|
||||||
|
|
||||||
|
# CLEANUP: Delete the zip
|
||||||
|
Remove-Item $zipPath -Force
|
||||||
|
|
||||||
# SELF-DESTRUCT: Remove this script
|
# SELF-DESTRUCT: Remove this script
|
||||||
Remove-Item -LiteralPath $MyInvocation.MyCommand.Path -Force";
|
Remove-Item -LiteralPath $MyInvocation.MyCommand.Path -Force";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,8 +262,7 @@
|
|||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<ui:SymbolIcon x:Name="updateIcon" Symbol="ArrowCircleUp24" Grid.Column="1" Margin="10" Filled="True"
|
<ui:Button x:Name="updateButton" Content="Frissítés" Grid.Column="1" Margin="2" Visibility="Hidden" Click="updateButton_Click" />
|
||||||
Foreground="{ui:ThemeResource AccentTextFillColorPrimaryBrush}" Visibility="Hidden" />
|
|
||||||
<ui:TextBlock x:Name="versionTextBlock" Grid.Column="2" HorizontalAlignment="Right" FontSize="8" Text="0.0.0" Margin="10" />
|
<ui:TextBlock x:Name="versionTextBlock" Grid.Column="2" HorizontalAlignment="Right" FontSize="8" Text="0.0.0" Margin="10" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace BlueMine
|
|||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
if(await UpdateManager.IsUpdateAvailable())
|
if(await UpdateManager.IsUpdateAvailable())
|
||||||
{
|
{
|
||||||
updateIcon.Visibility = Visibility.Visible;
|
updateButton.Visibility = Visibility.Visible;
|
||||||
UpdateManager.DownloadCompleted += UpdateManager_DownloadCompleted;
|
UpdateManager.DownloadCompleted += UpdateManager_DownloadCompleted;
|
||||||
await UpdateManager.DownloadUpdateAsync();
|
await UpdateManager.DownloadUpdateAsync();
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ namespace BlueMine
|
|||||||
}.ShowDialogAsync();
|
}.ShowDialogAsync();
|
||||||
|
|
||||||
if (result == Wpf.Ui.Controls.MessageBoxResult.Primary)
|
if (result == Wpf.Ui.Controls.MessageBoxResult.Primary)
|
||||||
await UpdateManager.PerformUpdate();
|
await UpdateManager.PerformUpdate(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,6 +373,11 @@ namespace BlueMine
|
|||||||
Title = "Under construction"
|
Title = "Under construction"
|
||||||
}.ShowDialogAsync();
|
}.ShowDialogAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
UpdateManager_DownloadCompleted();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class MainWindow : FluentWindow
|
public partial class MainWindow : FluentWindow
|
||||||
|
|||||||
@@ -23,6 +23,43 @@ namespace Blueberry
|
|||||||
return release != null && release.tag_name != CurrentVersion;
|
return release != null && release.tag_name != CurrentVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task WaitUntilDownloadCompleteAndUpdate()
|
||||||
|
{
|
||||||
|
var json = await client.GetStringAsync(releaseUrl);
|
||||||
|
var release = JsonSerializer.Deserialize<Root>(json);
|
||||||
|
var file = release.assets.Find(x => x.name.Contains(".zip"));
|
||||||
|
if (!File.Exists(zipPath))
|
||||||
|
await Download(client, file.browser_download_url, 0);
|
||||||
|
|
||||||
|
long localSize = new FileInfo(zipPath).Length;
|
||||||
|
if (localSize != file.size)
|
||||||
|
{
|
||||||
|
if (!isDownloading)
|
||||||
|
{
|
||||||
|
await Download(client, file.browser_download_url, localSize);
|
||||||
|
if (localSize != file.size)
|
||||||
|
await PerformUpdate();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
await Task.Delay(500);
|
||||||
|
localSize = new FileInfo(zipPath).Length;
|
||||||
|
} while (localSize != file.size);
|
||||||
|
localSize = new FileInfo(zipPath).Length;
|
||||||
|
if (localSize != file.size)
|
||||||
|
await PerformUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
localSize = new FileInfo(zipPath).Length;
|
||||||
|
if (localSize != file.size)
|
||||||
|
return;
|
||||||
|
else
|
||||||
|
await PerformUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task DownloadUpdateAsync()
|
public static async Task DownloadUpdateAsync()
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Add("User-Agent", "Blueberry-Updater");
|
client.DefaultRequestHeaders.Add("User-Agent", "Blueberry-Updater");
|
||||||
@@ -103,11 +140,11 @@ namespace Blueberry
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task PerformUpdate()
|
public static async Task PerformUpdate(bool restart = false)
|
||||||
{
|
{
|
||||||
string currentExe = Process.GetCurrentProcess().MainModule.FileName;
|
string currentExe = Process.GetCurrentProcess().MainModule.FileName;
|
||||||
|
|
||||||
string psScript = Constants.UpdateScript
|
string psScript = (restart ? Constants.UpdateScriptRestart : Constants.UpdateScriptNoRestart)
|
||||||
.Replace("{currentExe}", $"{currentExe}")
|
.Replace("{currentExe}", $"{currentExe}")
|
||||||
.Replace("{tempZip}", $"{zipPath}")
|
.Replace("{tempZip}", $"{zipPath}")
|
||||||
.Replace("{appDir}", $"{appDir}");
|
.Replace("{appDir}", $"{appDir}");
|
||||||
|
|||||||
Reference in New Issue
Block a user