mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
Merge pull request #42 from HueByte/dev_fix_update_service
fix: update service
This commit is contained in:
@@ -40,7 +40,37 @@ public static class UpdateBackupService
|
|||||||
|
|
||||||
Log.Information("Creating pre-update backup of {AppDir} (v{Version})", appDir, version);
|
Log.Information("Creating pre-update backup of {AppDir} (v{Version})", appDir, version);
|
||||||
|
|
||||||
ZipFile.CreateFromDirectory(appDir, BackupZipPath, CompressionLevel.Fastest, includeBaseDirectory: false);
|
using (var archive = ZipFile.Open(BackupZipPath, ZipArchiveMode.Create))
|
||||||
|
{
|
||||||
|
foreach (var file in Directory.EnumerateFiles(appDir, "*", SearchOption.AllDirectories))
|
||||||
|
{
|
||||||
|
var relativePath = Path.GetRelativePath(appDir, file);
|
||||||
|
|
||||||
|
// Skip log files to prevent locking errors with Serilog while zipping
|
||||||
|
if (relativePath.StartsWith("logs" + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
relativePath.StartsWith("logs" + Path.AltDirectorySeparatorChar, StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
relativePath.EndsWith(".log", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalize path separators for the zip archive format
|
||||||
|
var entryName = relativePath.Replace(Path.DirectorySeparatorChar, '/').Replace(Path.AltDirectorySeparatorChar, '/');
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
archive.CreateEntryFromFile(file, entryName, CompressionLevel.Fastest);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
Log.Warning(ex, "Skipped locked file {FileName} during backup calculation", relativePath);
|
||||||
|
}
|
||||||
|
catch (UnauthorizedAccessException ex)
|
||||||
|
{
|
||||||
|
Log.Warning(ex, "Skipped inaccessible file {FileName} during backup calculation", relativePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var info = new BackupInfo(version, appDir, DateTimeOffset.UtcNow);
|
var info = new BackupInfo(version, appDir, DateTimeOffset.UtcNow);
|
||||||
var json = JsonSerializer.Serialize(info, BackupJsonContext.Default.BackupInfo);
|
var json = JsonSerializer.Serialize(info, BackupJsonContext.Default.BackupInfo);
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public sealed class UpdateChecker : IDisposable
|
|||||||
// Create backup before the update starts
|
// Create backup before the update starts
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_app.Invoke(() => _progressDialog?.UpdateProgress(0f, "Creating backup..."));
|
_progressDialog?.UpdateProgress(0f, "Creating backup...");
|
||||||
UpdateBackupService.CreateBackup();
|
UpdateBackupService.CreateBackup();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -79,27 +79,21 @@ public sealed class UpdateChecker : IDisposable
|
|||||||
Log.Error(ex, "Failed to create pre-update backup");
|
Log.Error(ex, "Failed to create pre-update backup");
|
||||||
|
|
||||||
var proceed = false;
|
var proceed = false;
|
||||||
_app.Invoke(() =>
|
|
||||||
{
|
|
||||||
proceed = MessageBox.Query(
|
proceed = MessageBox.Query(
|
||||||
_app,
|
_app,
|
||||||
"Backup Warning",
|
"Backup Warning",
|
||||||
$"Could not create backup: {ex.Message}\n\nContinue update without backup?",
|
$"Could not create backup: {ex.Message}\n\nContinue update without backup?",
|
||||||
"Continue", "Cancel") == 0;
|
"Continue", "Cancel") == 0;
|
||||||
});
|
|
||||||
|
|
||||||
if (!proceed)
|
if (!proceed)
|
||||||
{
|
|
||||||
_app.Invoke(() =>
|
|
||||||
{
|
{
|
||||||
_progressDialog?.Close();
|
_progressDialog?.Close();
|
||||||
_progressDialog = null;
|
_progressDialog = null;
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_app.Invoke(() => _progressDialog?.UpdateProgress(0f, "Downloading update..."));
|
_progressDialog?.UpdateProgress(0f, "Downloading update...");
|
||||||
await _updater.UpdateAsync();
|
await _updater.UpdateAsync();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -118,7 +112,7 @@ public sealed class UpdateChecker : IDisposable
|
|||||||
statusText = $"{step}...";
|
statusText = $"{step}...";
|
||||||
}
|
}
|
||||||
|
|
||||||
_app.Invoke(() => _progressDialog?.UpdateProgress(fraction, statusText));
|
_progressDialog?.UpdateProgress(fraction, statusText);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUpdateStarted(string version)
|
private void OnUpdateStarted(string version)
|
||||||
|
|||||||
Reference in New Issue
Block a user