Compare commits

...
3 Commits
12 changed files with 156 additions and 12 deletions
+5
View File
@@ -25,6 +25,11 @@ catch
}
Console.WriteLine("Deleting package");
File.Delete(tempFile);
Console.WriteLine("Deleting browser caches");
Directory.Delete("BrowserData", true);
Directory.Delete("Daybreak.exe.WebView2", true);
Console.WriteLine("Launching application");
var process = new Process
{
+14 -3
View File
@@ -23,6 +23,9 @@ using Daybreak.Services.Options;
using Daybreak.Models;
using Microsoft.CorrelationVector;
using System.Logging;
using Daybreak.Services.Updater.PostUpdate;
using System.Core.Extensions;
using Daybreak.Services.Updater.PostUpdate.Actions;
namespace Daybreak.Configuration
{
@@ -30,7 +33,7 @@ namespace Daybreak.Configuration
{
public static void RegisterResolvers(IServiceManager serviceManager)
{
serviceManager.ThrowIfNull(nameof(serviceManager));
serviceManager.ThrowIfNull();
serviceManager.RegisterHttpFactory((serviceProvider, categoryType) =>
{
@@ -44,7 +47,7 @@ namespace Daybreak.Configuration
public static void RegisterServices(IServiceProducer serviceProducer)
{
serviceProducer.ThrowIfNull(nameof(serviceProducer));
serviceProducer.ThrowIfNull();
serviceProducer.RegisterSingleton<ILogsManager, JsonLogsManager>();
serviceProducer.RegisterSingleton<IDebugLogsWriter, Services.Logging.DebugLogsWriter>();
@@ -60,6 +63,7 @@ namespace Daybreak.Configuration
serviceProducer.RegisterScoped((sp) => new ScopeMetadata(new CorrelationVector()));
serviceProducer.RegisterSingleton<ViewManager>(registerAllInterfaces: true);
serviceProducer.RegisterSingleton<PostUpdateActionManager>(registerAllInterfaces: true);
serviceProducer.RegisterSingleton<IConfigurationManager, ConfigurationManager>();
serviceProducer.RegisterSingleton<ILiteDatabase, LiteDatabase>(sp => new LiteDatabase("Daybreak.db"));
serviceProducer.RegisterSingleton<IMutexHandler, MutexHandler>();
@@ -79,7 +83,7 @@ namespace Daybreak.Configuration
public static void RegisterViews(IViewProducer viewProducer)
{
viewProducer.ThrowIfNull(nameof(viewProducer));
viewProducer.ThrowIfNull();
viewProducer.RegisterView<MainView>();
viewProducer.RegisterView<SettingsView>();
@@ -97,5 +101,12 @@ namespace Daybreak.Configuration
viewProducer.RegisterView<LogsView>();
viewProducer.RegisterView<IconDownloadView>();
}
public static void RegisterPostUpdateActions(IPostUpdateActionProducer postUpdateActionProducer)
{
postUpdateActionProducer.ThrowIfNull();
postUpdateActionProducer.AddPostUpdateAction<RenameInstallerAction>();
}
}
}
+1 -1
View File
@@ -10,7 +10,7 @@
<LangVersion>preview</LangVersion>
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
<Version>0.9.4</Version>
<Version>0.9.5</Version>
</PropertyGroup>
<ItemGroup>
+2
View File
@@ -1,5 +1,6 @@
using Daybreak.Configuration;
using Daybreak.Exceptions;
using Daybreak.Services.Updater.PostUpdate;
using Daybreak.Services.ViewManagement;
using Microsoft.Extensions.Logging;
using Slim;
@@ -33,6 +34,7 @@ namespace Daybreak.Launch
ProjectConfiguration.RegisterServices(this.ServiceManager);
ServiceManager.BuildSingletons();
ProjectConfiguration.RegisterViews(this.ServiceManager.GetService<IViewManager>());
ProjectConfiguration.RegisterPostUpdateActions(this.ServiceManager.GetService<IPostUpdateActionProducer>());
}
protected override bool HandleException(Exception e)
{
@@ -2,6 +2,7 @@
using Daybreak.Exceptions;
using Daybreak.Models.Github;
using Daybreak.Models.Progress;
using Daybreak.Services.Updater.PostUpdate;
using Daybreak.Services.ViewManagement;
using Daybreak.Views;
using Microsoft.Extensions.Logging;
@@ -9,6 +10,7 @@ using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Core.Extensions;
using System.Diagnostics;
using System.Extensions;
using System.IO;
@@ -24,6 +26,7 @@ namespace Daybreak.Services.Updater
{
public sealed class ApplicationUpdater : IApplicationUpdater
{
private const string TemporaryInstallerFileName = "Daybreak.Installer.Temp.exe";
private const string InstallerFileName = "Daybreak.Installer.exe";
private const string UpdatedKey = "Updating";
private const string RegistryKey = "Daybreak";
@@ -35,24 +38,29 @@ namespace Daybreak.Services.Updater
private const string DownloadUrl = $"https://github.com/AlexMacocian/Daybreak/releases/download/{VersionTag}/Daybreak{VersionTag}.zip";
private readonly CancellationTokenSource updateCancellationTokenSource = new();
private readonly ILogger<ApplicationUpdater> logger;
private readonly IViewManager viewManager;
private readonly IPostUpdateActionProvider postUpdateActionProvider;
private readonly ILiveOptions<ApplicationConfiguration> liveOptions;
private readonly IHttpClient<ApplicationUpdater> httpClient;
private readonly ILogger<ApplicationUpdater> logger;
public Version CurrentVersion { get; }
public ApplicationUpdater(
ILogger<ApplicationUpdater> logger,
ILiveOptions<ApplicationConfiguration> liveOptions,
IViewManager viewManager,
IHttpClient<ApplicationUpdater> httpClient)
IPostUpdateActionProvider postUpdateActionProvider,
ILiveOptions<ApplicationConfiguration> liveOptions,
IHttpClient<ApplicationUpdater> httpClient,
ILogger<ApplicationUpdater> logger)
{
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
this.liveOptions = liveOptions.ThrowIfNull(nameof(liveOptions));
this.logger = logger.ThrowIfNull(nameof(logger));
this.httpClient = httpClient.ThrowIfNull(nameof(httpClient));
this.viewManager = viewManager.ThrowIfNull();
this.postUpdateActionProvider = postUpdateActionProvider.ThrowIfNull();
this.liveOptions = liveOptions.ThrowIfNull();
this.httpClient = httpClient.ThrowIfNull();
this.logger = logger.ThrowIfNull();
this.httpClient.DefaultRequestHeaders.Add("user-agent", "Daybreak Client");
if (Version.TryParse(Assembly.GetExecutingAssembly().GetName().Version.ToString(), out var currentVersion))
{
if (currentVersion.HasPrefix is false)
@@ -178,6 +186,7 @@ namespace Daybreak.Services.Updater
if (UpdateMarkedInRegistry())
{
UnmarkUpdateInRegistry();
this.ExecutePostUpdateActions();
}
}
@@ -213,6 +222,18 @@ namespace Daybreak.Services.Updater
}
}
private async void ExecutePostUpdateActions()
{
this.logger.LogInformation("Executing post-update actions");
foreach(var action in this.postUpdateActionProvider.GetPostUpdateActions())
{
this.logger.LogInformation($"Starting [{action.GetType().Name}]");
action.DoPostUpdateAction();
await action.DoPostUpdateActionAsync();
this.logger.LogInformation($"Finished [{action.GetType().Name}]");
}
}
private static void MarkUpdateInRegistry()
{
var homeRegistryKey = GetOrCreateHomeKey();
@@ -0,0 +1,32 @@
using Microsoft.Extensions.Logging;
using System.Core.Extensions;
using System.IO;
namespace Daybreak.Services.Updater.PostUpdate.Actions
{
public sealed class RenameInstallerAction : PostUpdateActionBase
{
private const string TemporaryInstallerFileName = "Daybreak.Installer.Temp.exe";
private const string InstallerFileName = "Daybreak.Installer.exe";
private readonly ILogger<RenameInstallerAction> logger;
public RenameInstallerAction(
ILogger<RenameInstallerAction> logger)
{
this.logger = logger.ThrowIfNull();
}
public override void DoPostUpdateAction()
{
if (File.Exists(TemporaryInstallerFileName))
{
this.logger.LogInformation("Detected new installer version. Overwriting old installer with new one");
File.Copy(TemporaryInstallerFileName, InstallerFileName, true);
this.logger.LogInformation("Deleting new installer temporary file");
File.Delete(TemporaryInstallerFileName);
}
}
}
}
@@ -0,0 +1,6 @@
namespace Daybreak.Services.Updater.PostUpdate
{
public interface IPostUpdateActionManager : IPostUpdateActionProducer, IPostUpdateActionProvider
{
}
}
@@ -0,0 +1,8 @@
namespace Daybreak.Services.Updater.PostUpdate
{
public interface IPostUpdateActionProducer
{
void AddPostUpdateAction<T>()
where T : PostUpdateActionBase;
}
}
@@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace Daybreak.Services.Updater.PostUpdate
{
public interface IPostUpdateActionProvider
{
IEnumerable<PostUpdateActionBase> GetPostUpdateActions();
}
}
@@ -0,0 +1,16 @@
using System.Threading.Tasks;
namespace Daybreak.Services.Updater.PostUpdate
{
public abstract class PostUpdateActionBase
{
public virtual void DoPostUpdateAction()
{
}
public virtual Task DoPostUpdateActionAsync()
{
return Task.CompletedTask;
}
}
}
@@ -0,0 +1,33 @@
using Microsoft.Extensions.Logging;
using Slim;
using System.Collections.Generic;
using System.Core.Extensions;
namespace Daybreak.Services.Updater.PostUpdate
{
public sealed class PostUpdateActionManager : IPostUpdateActionManager
{
private readonly IServiceManager serviceManager;
private readonly ILogger<PostUpdateActionManager> logger;
public PostUpdateActionManager(
IServiceManager serviceManager,
ILogger<PostUpdateActionManager> logger)
{
this.serviceManager = serviceManager.ThrowIfNull();
this.logger = logger.ThrowIfNull();
}
public void AddPostUpdateAction<T>()
where T : PostUpdateActionBase
{
this.serviceManager.RegisterSingleton<T>();
this.logger.LogDebug($"Added post update action {typeof(T).Name}");
}
public IEnumerable<PostUpdateActionBase> GetPostUpdateActions()
{
return this.serviceManager.GetServicesOfType<PostUpdateActionBase>();
}
}
}
+1
View File
@@ -6,6 +6,7 @@ Param(
Write-Output "Deleting pdb file"
Remove-item .\Publish\Daybreak.pdb
Remove-item .\Publish\Daybreak.Installer.pdb
Move-Item -Path .\Publish\Daybreak.Installer.exe -Destination .\Publish\Daybreak.Installer.Temp.exe
$zipPath = "Publish\daybreakv$version.zip"
Write-Output "Compressing binaries to $zipPath"
Compress-Archive .\Publish\* $zipPath -Force