|
|
|
@ -9,8 +9,6 @@ namespace DiscordChatExporter.Gui.Services
|
|
|
|
|
{
|
|
|
|
|
public class UpdateService : IDisposable
|
|
|
|
|
{
|
|
|
|
|
private readonly SettingsService _settingsService;
|
|
|
|
|
|
|
|
|
|
private readonly IUpdateManager _updateManager = new UpdateManager(
|
|
|
|
|
new GithubPackageResolver("Tyrrrz", "DiscordChatExporter", "DiscordChatExporter.zip"),
|
|
|
|
|
new ZipPackageExtractor());
|
|
|
|
@ -18,36 +16,25 @@ namespace DiscordChatExporter.Gui.Services
|
|
|
|
|
private Version _updateVersion;
|
|
|
|
|
private bool _updaterLaunched;
|
|
|
|
|
|
|
|
|
|
public UpdateService(SettingsService settingsService)
|
|
|
|
|
public async Task<Version> CheckForUpdatesAsync()
|
|
|
|
|
{
|
|
|
|
|
_settingsService = settingsService;
|
|
|
|
|
var check = await _updateManager.CheckForUpdatesAsync();
|
|
|
|
|
return check.CanUpdate ? check.LastVersion : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<Version> CheckPrepareUpdateAsync()
|
|
|
|
|
public async Task PrepareUpdateAsync(Version version)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// If auto-update is disabled - don't check for updates
|
|
|
|
|
if (!_settingsService.IsAutoUpdateEnabled)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
// Check for updates
|
|
|
|
|
var check = await _updateManager.CheckForUpdatesAsync();
|
|
|
|
|
if (!check.CanUpdate)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
// Prepare the update
|
|
|
|
|
await _updateManager.PrepareUpdateAsync(check.LastVersion);
|
|
|
|
|
|
|
|
|
|
return _updateVersion = check.LastVersion;
|
|
|
|
|
await _updateManager.PrepareUpdateAsync(_updateVersion = version);
|
|
|
|
|
}
|
|
|
|
|
catch (UpdaterAlreadyLaunchedException)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
// Ignore race conditions
|
|
|
|
|
}
|
|
|
|
|
catch (LockFileNotAcquiredException)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
// Ignore race conditions
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -55,23 +42,20 @@ namespace DiscordChatExporter.Gui.Services
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Check if an update is pending
|
|
|
|
|
if (_updateVersion == null)
|
|
|
|
|
if (_updateVersion == null || _updaterLaunched)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Check if the updater has already been launched
|
|
|
|
|
if (_updaterLaunched)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Launch the updater
|
|
|
|
|
_updateManager.LaunchUpdater(_updateVersion, needRestart);
|
|
|
|
|
|
|
|
|
|
_updaterLaunched = true;
|
|
|
|
|
}
|
|
|
|
|
catch (UpdaterAlreadyLaunchedException)
|
|
|
|
|
{
|
|
|
|
|
// Ignore race conditions
|
|
|
|
|
}
|
|
|
|
|
catch (LockFileNotAcquiredException)
|
|
|
|
|
{
|
|
|
|
|
// Ignore race conditions
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|