fix updater

This commit is contained in:
2025-12-16 05:35:22 +01:00
parent 7811b36edf
commit 136ceb1a9b
2 changed files with 11 additions and 14 deletions

View File

@@ -40,17 +40,17 @@ $destDir = '{appDir}'
$maxRetries = 10 $maxRetries = 10
$retryCount = 0 $retryCount = 0
while ($retryCount -lt $maxRetries) {{ while ($retryCount -lt $maxRetries) {
try {{ try {
# Attempt to delete the old executable # Attempt to delete the old executable
if (Test-Path $exePath) {{ Remove-Item $exePath -Force -ErrorAction Stop }} if (Test-Path $exePath) { Remove-Item $exePath -Force -ErrorAction Stop }
break # If successful, exit loop break # If successful, exit loop
}} }
catch {{ catch {
Start-Sleep -Milliseconds 500 Start-Sleep -Milliseconds 500
$retryCount++ $retryCount++
}} }
}} }
# Unzip the new version # Unzip the new version
Expand-Archive -Path $zipPath -DestinationPath $destDir -Force Expand-Archive -Path $zipPath -DestinationPath $destDir -Force

View File

@@ -9,7 +9,8 @@ namespace Blueberry
{ {
private const string releaseUrl = "https://git.technopunk.space/api/v1/repos/tomi/Blueberry/releases/latest"; private const string releaseUrl = "https://git.technopunk.space/api/v1/repos/tomi/Blueberry/releases/latest";
public const string CurrentVersion = "0.1.4"; public const string CurrentVersion = "0.1.4";
private static readonly string AppDir = AppDomain.CurrentDomain.BaseDirectory; private static readonly string appDir = AppDomain.CurrentDomain.BaseDirectory;
private static readonly string zipPath = Path.Combine(appDir, "blueberry_update.zip");
private static readonly HttpClient client = new(); private static readonly HttpClient client = new();
public delegate void DownloadCompletedEventArgs(); public delegate void DownloadCompletedEventArgs();
public static event DownloadCompletedEventArgs DownloadCompleted; public static event DownloadCompletedEventArgs DownloadCompleted;
@@ -39,7 +40,6 @@ namespace Blueberry
var file = release.assets.Find(x => x.name.Contains(".zip")); var file = release.assets.Find(x => x.name.Contains(".zip"));
if (file == null) return; if (file == null) return;
string zipPath = Path.Combine(AppDir, "blueberry_update.zip");
long offset = 0; long offset = 0;
if (File.Exists(zipPath)) if (File.Exists(zipPath))
@@ -90,10 +90,9 @@ namespace Blueberry
// If offset > 0, we APPEND. If 0, we CREATE/OVERWRITE. // If offset > 0, we APPEND. If 0, we CREATE/OVERWRITE.
var fileMode = offset > 0 ? FileMode.Append : FileMode.Create; var fileMode = offset > 0 ? FileMode.Append : FileMode.Create;
string filePath = Path.Combine(AppDir, "blueberry_update.zip");
using var contentStream = await response.Content.ReadAsStreamAsync(); using var contentStream = await response.Content.ReadAsStreamAsync();
using var fileStream = new FileStream(filePath, fileMode, FileAccess.Write, FileShare.None); using var fileStream = new FileStream(zipPath, fileMode, FileAccess.Write, FileShare.None);
await contentStream.CopyToAsync(fileStream); await contentStream.CopyToAsync(fileStream);
isDownloading = false; isDownloading = false;
@@ -106,13 +105,11 @@ namespace Blueberry
public static async Task PerformUpdate() public static async Task PerformUpdate()
{ {
string tempZip = Path.Combine(Path.GetTempPath(), "blueberry_update.zip");
string currentExe = Process.GetCurrentProcess().MainModule.FileName; string currentExe = Process.GetCurrentProcess().MainModule.FileName;
string appDir = AppDomain.CurrentDomain.BaseDirectory;
string psScript = Constants.UpdateScript string psScript = Constants.UpdateScript
.Replace("{currentExe}", $"{currentExe}") .Replace("{currentExe}", $"{currentExe}")
.Replace("{tempZip}", $"{tempZip}") .Replace("{tempZip}", $"{zipPath}")
.Replace("{appDir}", $"{appDir}"); .Replace("{appDir}", $"{appDir}");
string psPath = Path.Combine(Path.GetTempPath(), "blueberry_updater.ps1"); string psPath = Path.Combine(Path.GetTempPath(), "blueberry_updater.ps1");
File.WriteAllText(psPath, psScript); File.WriteAllText(psPath, psScript);