mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-23 11:16:59 -04:00
Update Onova
This commit is contained in:
parent
77bf32aa5a
commit
6d1cfef729
2 changed files with 43 additions and 24 deletions
|
@ -23,7 +23,7 @@
|
|||
<PackageReference Include="ByteSize" Version="1.3.0" />
|
||||
<PackageReference Include="Failsafe" Version="1.1.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
||||
<PackageReference Include="Onova" Version="2.2.0" />
|
||||
<PackageReference Include="Onova" Version="2.4.2" />
|
||||
<PackageReference Include="Scriban" Version="1.2.9" />
|
||||
<PackageReference Include="Tyrrrz.Extensions" Version="1.5.1" />
|
||||
<PackageReference Include="Tyrrrz.Settings" Version="1.3.3" />
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Onova;
|
||||
using Onova.Exceptions;
|
||||
using Onova.Services;
|
||||
|
||||
namespace DiscordChatExporter.Core.Services
|
||||
{
|
||||
public class UpdateService
|
||||
public class UpdateService : IDisposable
|
||||
{
|
||||
private readonly SettingsService _settingsService;
|
||||
|
||||
|
@ -22,27 +23,36 @@ namespace DiscordChatExporter.Core.Services
|
|||
}
|
||||
|
||||
public async Task<Version> CheckPrepareUpdateAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// If auto-update is disabled - don't check for updates
|
||||
if (!_settingsService.IsAutoUpdateEnabled)
|
||||
return null;
|
||||
|
||||
// Cleanup leftover files
|
||||
_updateManager.Cleanup();
|
||||
|
||||
// Check for updates
|
||||
var check = await _updateManager.CheckForUpdatesAsync();
|
||||
if (!check.CanUpdate)
|
||||
return null;
|
||||
|
||||
// Prepare the update
|
||||
if (!_updateManager.IsUpdatePrepared(check.LastVersion))
|
||||
await _updateManager.PrepareUpdateAsync(check.LastVersion);
|
||||
|
||||
return _updateVersion = check.LastVersion;
|
||||
}
|
||||
catch (UpdaterAlreadyLaunchedException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
catch (LockFileNotAcquiredException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void FinalizeUpdate(bool needRestart)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Check if an update is pending
|
||||
if (_updateVersion == null)
|
||||
|
@ -56,5 +66,14 @@ namespace DiscordChatExporter.Core.Services
|
|||
_updateManager.LaunchUpdater(_updateVersion, needRestart);
|
||||
_updaterLaunched = true;
|
||||
}
|
||||
catch (UpdaterAlreadyLaunchedException)
|
||||
{
|
||||
}
|
||||
catch (LockFileNotAcquiredException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() => _updateManager.Dispose();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue