Update nuget packages and rework UpdateService

pull/37/merge
Alexey Golub 7 years ago
parent 9988300942
commit 5a84fb25e6

@ -1,7 +1,7 @@
using DiscordChatExporter.Cli.ViewModels;
using CommonServiceLocator;
using DiscordChatExporter.Cli.ViewModels;
using DiscordChatExporter.Core.Services;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;
namespace DiscordChatExporter.Cli
{

@ -10,9 +10,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommonServiceLocator" Version="1.3" />
<PackageReference Include="CommonServiceLocator" Version="2.0.3" />
<PackageReference Include="FluentCommandLineParser" Version="1.4.3" />
<PackageReference Include="MvvmLightLibs" Version="5.3.0.0" />
<PackageReference Include="MvvmLightLibs" Version="5.4.1" />
<PackageReference Include="Tyrrrz.Extensions" Version="1.5.0" />
</ItemGroup>

@ -15,7 +15,7 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
<PackageReference Include="Onova" Version="1.0.0" />
<PackageReference Include="Onova" Version="2.0.0" />
<PackageReference Include="Tyrrrz.Extensions" Version="1.5.0" />
<PackageReference Include="Tyrrrz.Settings" Version="1.3.2" />
</ItemGroup>

@ -5,10 +5,10 @@ namespace DiscordChatExporter.Core.Services
{
public interface IUpdateService
{
Task<Version> CheckForUpdatesAsync();
bool NeedRestart { get; set; }
Task PrepareUpdateAsync();
Task<Version> CheckPrepareUpdateAsync();
Task ApplyUpdateAsync(bool restart = true);
Task FinalizeUpdateAsync();
}
}

@ -8,82 +8,55 @@ namespace DiscordChatExporter.Core.Services
public class UpdateService : IUpdateService
{
private readonly ISettingsService _settingsService;
private readonly UpdateManager _updateManager;
private readonly IUpdateManager _manager;
private Version _lastVersion;
private bool _applied;
private Version _updateVersion;
private bool _updateFinalized;
public bool NeedRestart { get; set; }
public UpdateService(ISettingsService settingsService)
{
_settingsService = settingsService;
_updateManager = new UpdateManager(
_manager = new UpdateManager(
new GithubPackageResolver("Tyrrrz", "DiscordChatExporter", "DiscordChatExporter.zip"),
new ZipPackageExtractor());
}
public async Task<Version> CheckForUpdatesAsync()
public async Task<Version> CheckPrepareUpdateAsync()
{
#if DEBUG
// Never update in DEBUG mode
return null;
#endif
// Don't update if user disabled it
// If auto-update is disabled - don't check for updates
if (!_settingsService.IsAutoUpdateEnabled)
return null;
try
{
// Remove some junk left over from last update
_updateManager.Cleanup();
// Cleanup leftover files
_manager.Cleanup();
// Check for updates
var check = await _updateManager.CheckForUpdatesAsync();
// Return latest version or null if running latest version already
return check.CanUpdate ? _lastVersion = check.LastVersion : null;
}
catch
{
// It's okay for update to fail
// Check for updates
var check = await _manager.CheckForUpdatesAsync();
if (!check.CanUpdate)
return null;
}
}
public async Task PrepareUpdateAsync()
{
if (_lastVersion == null)
return;
// Prepare the update
await _manager.PrepareUpdateAsync(check.LastVersion);
try
{
// Download and prepare update
await _updateManager.PreparePackageAsync(_lastVersion);
}
catch
{
// It's okay for update to fail
}
return _updateVersion = check.LastVersion;
}
public async Task ApplyUpdateAsync(bool restart = true)
public async Task FinalizeUpdateAsync()
{
if (_lastVersion == null)
// Check if an update is pending
if (_updateVersion == null)
return;
if (_applied)
// Check if the update has already been finalized
if (_updateFinalized)
return;
try
{
// Enqueue an update
await _updateManager.EnqueueApplyPackageAsync(_lastVersion, restart);
_applied = true;
}
catch
{
// It's okay for update to fail
}
// Launch the updater
await _manager.LaunchUpdaterAsync(_updateVersion, NeedRestart);
_updateFinalized = true;
}
}
}

@ -1,7 +1,7 @@
using DiscordChatExporter.Core.Services;
using CommonServiceLocator;
using DiscordChatExporter.Core.Services;
using DiscordChatExporter.Gui.ViewModels;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;
namespace DiscordChatExporter.Gui
{

@ -45,28 +45,28 @@
<Reference Include="AmmySidekick, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7c1296d24569a67d, processorArchitecture=MSIL">
<HintPath>..\packages\Ammy.WPF.1.2.94\lib\net40\AmmySidekick.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight, Version=5.3.0.19026, Culture=neutral, PublicKeyToken=e7570ab207bcb616, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.dll</HintPath>
<Reference Include="CommonServiceLocator, Version=2.0.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight.Extras, Version=5.3.0.19032, Culture=neutral, PublicKeyToken=669f0b5e8f868abf, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.Extras.dll</HintPath>
<Reference Include="GalaSoft.MvvmLight, Version=5.4.1.0, Culture=neutral, PublicKeyToken=e7570ab207bcb616, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1\lib\net45\GalaSoft.MvvmLight.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight.Platform, Version=5.3.0.19032, Culture=neutral, PublicKeyToken=5f873c45e98af8a1, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.Platform.dll</HintPath>
<Reference Include="GalaSoft.MvvmLight.Extras, Version=5.4.1.0, Culture=neutral, PublicKeyToken=669f0b5e8f868abf, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1\lib\net45\GalaSoft.MvvmLight.Extras.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight.Platform, Version=5.4.1.0, Culture=neutral, PublicKeyToken=5f873c45e98af8a1, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1\lib\net45\GalaSoft.MvvmLight.Platform.dll</HintPath>
</Reference>
<Reference Include="MaterialDesignColors, Version=1.1.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MaterialDesignColors.1.1.3\lib\net45\MaterialDesignColors.dll</HintPath>
</Reference>
<Reference Include="MaterialDesignThemes.Wpf, Version=2.3.1.953, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll</HintPath>
<Reference Include="MaterialDesignThemes.Wpf, Version=2.4.0.1044, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MaterialDesignThemes.2.4.0.1044\lib\net45\MaterialDesignThemes.Wpf.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.3.0.0\lib\net45\System.Windows.Interactivity.dll</HintPath>
<HintPath>..\packages\MvvmLightLibs.5.4.1\lib\net45\System.Windows.Interactivity.dll</HintPath>
</Reference>
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
@ -74,6 +74,7 @@
<Reference Include="Tyrrrz.Extensions, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Tyrrrz.Extensions.1.5.0\lib\net45\Tyrrrz.Extensions.dll</HintPath>
</Reference>
<Reference Include="Tyrrrz.Settings, Version=1.3.2.0, Culture=neutral, PublicKeyToken=null" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
@ -146,6 +147,7 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="App.ammy" />
<None Include="app.config" />
<None Include="lib.ammy" />
<None Include="packages.config">
<SubType>Designer</SubType>

@ -111,7 +111,7 @@ namespace DiscordChatExporter.Gui.ViewModels
// Messages
MessengerInstance.Register<StartExportMessage>(this,
m => { Export(m.Channel, m.FilePath, m.Format, m.From, m.To); });
m => Export(m.Channel, m.FilePath, m.Format, m.From, m.To));
}
private async void ViewLoaded()
@ -122,33 +122,34 @@ namespace DiscordChatExporter.Gui.ViewModels
// Set last token
Token = _settingsService.LastToken;
// Check for updates
var lastVersion = await _updateService.CheckForUpdatesAsync();
if (lastVersion != null)
// Check and prepare update
try
{
// Download updates
await _updateService.PrepareUpdateAsync();
// Notify user
MessengerInstance.Send(
new ShowNotificationMessage(
$"DiscordChatExporter v{lastVersion} has been downloaded it will be installed when you exit",
"INSTALL NOW",
async () =>
var updateVersion = await _updateService.CheckPrepareUpdateAsync();
if (updateVersion != null)
{
MessengerInstance.Send(new ShowNotificationMessage(
$"Update to DiscordChatExporter v{updateVersion} will be installed when you exit",
"INSTALL NOW", () =>
{
await _updateService.ApplyUpdateAsync();
_updateService.NeedRestart = true;
Application.Current.Shutdown();
}));
}
}
catch
{
MessengerInstance.Send(new ShowNotificationMessage("Failed to perform application auto-update"));
}
}
private void ViewClosed()
private async void ViewClosed()
{
// Save settings
_settingsService.Save();
// Apply updates if available
_updateService.ApplyUpdateAsync(false);
// Finalize updates if available
await _updateService.FinalizeUpdateAsync();
}
private async void PullData()
@ -185,13 +186,11 @@ namespace DiscordChatExporter.Gui.ViewModels
}
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Unauthorized)
{
const string message = "Unauthorized make sure the token is valid";
MessengerInstance.Send(new ShowNotificationMessage(message));
MessengerInstance.Send(new ShowNotificationMessage("Unauthorized make sure the token is valid"));
}
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
{
const string message = "Forbidden account may be locked by 2FA";
MessengerInstance.Send(new ShowNotificationMessage(message));
MessengerInstance.Send(new ShowNotificationMessage("Forbidden account may be locked by 2FA"));
}
AvailableGuilds = _guildChannelsMap.Keys.ToArray();
@ -237,13 +236,11 @@ namespace DiscordChatExporter.Gui.ViewModels
// Notify completion
MessengerInstance.Send(new ShowNotificationMessage($"Export completed for channel [{channel.Name}]",
"OPEN",
() => Process.Start(filePath)));
"OPEN", () => Process.Start(filePath)));
}
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
{
const string message = "You don't have access to that channel";
MessengerInstance.Send(new ShowNotificationMessage(message));
MessengerInstance.Send(new ShowNotificationMessage("You don't have access to that channel"));
}
IsBusy = false;

@ -17,13 +17,18 @@ namespace DiscordChatExporter.Gui.Views
Snackbar.MessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(5));
// Notification messages
Messenger.Default.Register<ShowNotificationMessage>(this,
m => Snackbar.MessageQueue.Enqueue(m.Message, m.CallbackCaption, m.Callback));
Messenger.Default.Register<ShowNotificationMessage>(this, m =>
{
if (m.CallbackCaption != null && m.Callback != null)
Snackbar.MessageQueue.Enqueue(m.Message, m.CallbackCaption, m.Callback);
else
Snackbar.MessageQueue.Enqueue(m.Message);
});
// Dialog messages
Messenger.Default.Register<ShowExportSetupMessage>(this,
m => DialogHost.Show(new ExportSetupDialog()).Forget());
Messenger.Default.Register<ShowSettingsMessage>(this,
Messenger.Default.Register<ShowSettingsMessage>(this,
m => DialogHost.Show(new SettingsDialog()).Forget());
}
}

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="CommonServiceLocator" publicKeyToken="489b6accfaf20ef0" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.3.0" newVersion="2.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

@ -2,9 +2,9 @@
<packages>
<package id="Ammy" version="1.2.94" targetFramework="net461" />
<package id="Ammy.WPF" version="1.2.94" targetFramework="net461" />
<package id="CommonServiceLocator" version="1.3" targetFramework="net461" />
<package id="CommonServiceLocator" version="2.0.3" targetFramework="net461" />
<package id="MaterialDesignColors" version="1.1.3" targetFramework="net461" />
<package id="MaterialDesignThemes" version="2.3.1.953" targetFramework="net461" />
<package id="MvvmLightLibs" version="5.3.0.0" targetFramework="net461" />
<package id="MaterialDesignThemes" version="2.4.0.1044" targetFramework="net461" />
<package id="MvvmLightLibs" version="5.4.1" targetFramework="net461" />
<package id="Tyrrrz.Extensions" version="1.5.0" targetFramework="net461" />
</packages>
Loading…
Cancel
Save