mirror of
https://github.com/gwdevhub/Daybreak.git
synced 2026-09-16 13:29:30 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac430305f4 | ||
|
|
3d830cfc16 | ||
|
|
b529aa8861 | ||
|
|
3798daa54e | ||
|
|
624380ed86 | ||
|
|
2b025e225b | ||
|
|
15a67ea28c | ||
|
|
c6b62fd5fd | ||
|
|
3c0877c1a0 | ||
|
|
967b57b9a8 | ||
|
|
f47cc319b5 | ||
|
|
26da84c4e7 | ||
|
|
a39e8dc5c6 | ||
|
|
1bb4669135 | ||
|
|
0203eef006 | ||
|
|
4ab50ee191 | ||
|
|
06c1ec1ac2 |
@@ -52,7 +52,7 @@ jobs:
|
||||
- name: Install .NET Core
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: '5.0.202'
|
||||
dotnet-version: '6.x'
|
||||
|
||||
- name: Setup MSBuild.exe
|
||||
uses: microsoft/setup-msbuild@v1.0.1
|
||||
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
- name: Install .NET Core
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: '5.0.202'
|
||||
dotnet-version: '6.x'
|
||||
|
||||
- name: Setup MSBuild.exe
|
||||
uses: microsoft/setup-msbuild@v1.0.1
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.0.0-alpha0002" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="1.3.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.7.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0-preview-20220707-01" />
|
||||
<PackageReference Include="Moq" Version="4.18.2" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2" />
|
||||
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace Daybreak.Tests.Models
|
||||
[TestClass]
|
||||
public class VersionTests
|
||||
{
|
||||
[DataRow("v0.1.0.0.1", "v0.1.0.0.1")]
|
||||
[DataRow("v0.1.0.0.1.0.0.0.0", "v0.1.0.0.1")]
|
||||
[DataRow("v0.1.0", "v0.1")]
|
||||
[DataRow("0.1.0", "0.1")]
|
||||
[DataRow("v0.1.0.0.0", "v0.1")]
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Services.Configuration;
|
||||
using Daybreak.Services.Options;
|
||||
using FluentAssertions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using System;
|
||||
|
||||
namespace Daybreak.Tests.Services
|
||||
{
|
||||
[TestClass]
|
||||
public class ApplicationConfigurationOptionsManagerTests
|
||||
{
|
||||
private ApplicationConfigurationOptionsManager applicationConfigurationOptionsManager;
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
var configurationManagerMock = new Mock<IConfigurationManager>();
|
||||
configurationManagerMock
|
||||
.Setup(u => u.GetConfiguration())
|
||||
.Returns(new ApplicationConfiguration());
|
||||
|
||||
this.applicationConfigurationOptionsManager = new ApplicationConfigurationOptionsManager(configurationManagerMock.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetApplicationConfiguration_ReturnsObject()
|
||||
{
|
||||
var config = this.applicationConfigurationOptionsManager.GetOptions<ApplicationConfiguration>();
|
||||
|
||||
config.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetOtherOptions_ThrowsInvalidOperationException()
|
||||
{
|
||||
var action = new Action(() =>
|
||||
{
|
||||
this.applicationConfigurationOptionsManager.GetOptions<object>();
|
||||
});
|
||||
|
||||
action.Should().Throw<InvalidOperationException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void UpdateOptions_OnApplicationConfiguration_Succeeds()
|
||||
{
|
||||
this.applicationConfigurationOptionsManager.UpdateOptions(new ApplicationConfiguration());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void UpdateOptions_OnOthers_ThrowsInvalidOperationException()
|
||||
{
|
||||
var action = new Action(() =>
|
||||
{
|
||||
this.applicationConfigurationOptionsManager.UpdateOptions(new object());
|
||||
});
|
||||
|
||||
action.Should().Throw<InvalidOperationException>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Daybreak.Models.Builds;
|
||||
using Daybreak.Services.BuildTemplates;
|
||||
using Daybreak.Services.Logging;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using System.Collections.Generic;
|
||||
@@ -17,7 +17,7 @@ namespace Daybreak.Tests.Services
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
buildTemplateManager = new BuildTemplateManager(new Mock<ILogger>().Object);
|
||||
buildTemplateManager = new BuildTemplateManager(new Mock<ILogger<BuildTemplateManager>>().Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
using Daybreak.Services.Logging;
|
||||
using FluentAssertions;
|
||||
using LiteDB;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Logging;
|
||||
|
||||
namespace Daybreak.Tests.Services
|
||||
{
|
||||
[TestClass]
|
||||
public class JsonLoggerProviderTests
|
||||
{
|
||||
private ILogsManager logsManager;
|
||||
private ILoggerProvider loggerProvider;
|
||||
private ILiteDatabase liteDatabase;
|
||||
|
||||
[TestInitialize]
|
||||
public void InitializeProvider()
|
||||
{
|
||||
File.Delete("Daybreak.db");
|
||||
this.liteDatabase = new LiteDatabase("Daybreak.db");
|
||||
this.logsManager = new JsonLogsManager(this.liteDatabase);
|
||||
this.loggerProvider = new CVLoggerProvider(this.logsManager);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
this.liteDatabase.Dispose();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CreateLoggerReturnsLogger()
|
||||
{
|
||||
var logger = this.loggerProvider.CreateLogger("SomeCategory");
|
||||
logger.Should().NotBeNull();
|
||||
}
|
||||
[TestMethod]
|
||||
public void LoggerLogsAndReaderReadsFiltered()
|
||||
{
|
||||
var logger = this.loggerProvider.CreateLogger("SomeCategory");
|
||||
logger.LogTrace("Logging some trace");
|
||||
logger.LogInformation("Logging some stuff");
|
||||
logger.LogError("Logging some error");
|
||||
|
||||
this.logsManager.GetLogs(l => l.LogLevel < LogLevel.Information).Should().HaveCount(1);
|
||||
var log = this.logsManager.GetLogs(l => l.LogLevel < LogLevel.Information).First();
|
||||
log.LogLevel.Should().Be(LogLevel.Error);
|
||||
}
|
||||
[TestMethod]
|
||||
public void LoggerLogsAndReaderReads()
|
||||
{
|
||||
var logger = this.loggerProvider.CreateLogger("SomeCategory");
|
||||
logger.LogInformation("Logging some stuff");
|
||||
logger.LogError("Logging some error");
|
||||
|
||||
this.logsManager.GetLogs().Should().HaveCount(2);
|
||||
}
|
||||
[TestMethod]
|
||||
public void DeletingLogsShouldDeleteLogs()
|
||||
{
|
||||
var logger = this.loggerProvider.CreateLogger("SomeCategory");
|
||||
logger.LogInformation("Logging some stuff");
|
||||
logger.LogError("Logging some error");
|
||||
|
||||
this.logsManager.GetLogs().Should().HaveCount(2);
|
||||
|
||||
this.logsManager.DeleteLogs();
|
||||
this.logsManager.GetLogs().Should().HaveCount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-7
@@ -1,11 +1,17 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.31005.135
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.2.32616.157
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Daybreak", "Daybreak\Daybreak.csproj", "{AA45C2B1-8BD0-466C-9271-699F168905AF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Daybreak.Tests", "Daybreak.Tests\Daybreak.Tests.csproj", "{C911C1C2-6566-419C-89C7-F802EB3FE709}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Daybreak.Tests", "Daybreak.Tests\Daybreak.Tests.csproj", "{C911C1C2-6566-419C-89C7-F802EB3FE709}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Pipelines", "Pipelines", "{067BF93F-E5B2-4E99-886E-039C04F35EAB}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.github\workflows\cd.yaml = .github\workflows\cd.yaml
|
||||
.github\workflows\ci.yaml = .github\workflows\ci.yaml
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -17,12 +23,12 @@ Global
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Debug|x64.Build.0 = Debug|x64
|
||||
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Release|x64.ActiveCfg = Release|x64
|
||||
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Release|x64.Build.0 = Release|x64
|
||||
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Release|x64.Build.0 = Release|Any CPU
|
||||
{C911C1C2-6566-419C-89C7-F802EB3FE709}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C911C1C2-6566-419C-89C7-F802EB3FE709}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C911C1C2-6566-419C-89C7-F802EB3FE709}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
|
||||
@@ -37,5 +37,7 @@ namespace Daybreak.Configuration
|
||||
public bool PlaceShortcut { get; set; }
|
||||
[JsonProperty("AutoCheckUpdate")]
|
||||
public bool AutoCheckUpdate { get; set; } = true;
|
||||
[JsonProperty("KeepLocalIconCache")]
|
||||
public bool KeepLocalIconCache { get; set; } = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Daybreak.Services.ApplicationLauncher;
|
||||
using Daybreak.Services.ApplicationLifetime;
|
||||
using Daybreak.Services.Bloogum;
|
||||
using Daybreak.Services.BuildTemplates;
|
||||
using Daybreak.Services.Configuration;
|
||||
@@ -8,51 +7,62 @@ using Daybreak.Services.IconRetrieve;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Services.Mutex;
|
||||
using Daybreak.Services.Privilege;
|
||||
using Daybreak.Services.Runtime;
|
||||
using Daybreak.Services.Screens;
|
||||
using Daybreak.Services.Screenshots;
|
||||
using Daybreak.Services.Shortcuts;
|
||||
using Daybreak.Services.Updater;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Daybreak.Views;
|
||||
using Microsoft.Extensions.Http.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Slim;
|
||||
using System.Extensions;
|
||||
using System.Net.Http;
|
||||
using LiteDB;
|
||||
using Daybreak.Services.Options;
|
||||
using Daybreak.Models;
|
||||
using Microsoft.CorrelationVector;
|
||||
|
||||
namespace Daybreak.Configuration
|
||||
{
|
||||
public static class ProjectConfiguration
|
||||
{
|
||||
public static void RegisterResolvers(IServiceManager serviceManager)
|
||||
{
|
||||
serviceManager.ThrowIfNull(nameof(serviceManager));
|
||||
|
||||
serviceManager.RegisterHttpFactory((serviceProvider, categoryType) =>
|
||||
{
|
||||
var loggerType = typeof(ILogger<>).MakeGenericType(categoryType);
|
||||
var logger = serviceProvider.GetService(loggerType).As<ILogger>();
|
||||
var handler = new LoggingHttpMessageHandler(logger) { InnerHandler = new HttpClientHandler() };
|
||||
return handler;
|
||||
});
|
||||
serviceManager.RegisterOptionsManager<ApplicationConfigurationOptionsManager>();
|
||||
}
|
||||
|
||||
public static void RegisterServices(IServiceProducer serviceProducer)
|
||||
{
|
||||
serviceProducer.ThrowIfNull(nameof(serviceProducer));
|
||||
|
||||
serviceProducer.RegisterSingleton<ICredentialManager, CredentialManager>();
|
||||
serviceProducer.RegisterSingleton<ILoggingDatabase, FlatLoggingDatabase>();
|
||||
serviceProducer.RegisterSingleton<ILogger, Logger>();
|
||||
serviceProducer.RegisterSingleton<ApplicationLifetimeManager>();
|
||||
serviceProducer.RegisterSingleton<ViewManager>();
|
||||
serviceProducer.RegisterSingleton<IApplicationLauncher, ApplicationLauncher>();
|
||||
serviceProducer.RegisterSingleton<IScreenshotProvider, ScreenshotProvider>();
|
||||
serviceProducer.RegisterSingleton<ViewManager>(registerAllInterfaces: true);
|
||||
serviceProducer.RegisterSingleton<IConfigurationManager, ConfigurationManager>();
|
||||
serviceProducer.RegisterSingleton<IBloogumClient, BloogumClient>();
|
||||
serviceProducer.RegisterSingleton<IApplicationUpdater, ApplicationUpdater>();
|
||||
serviceProducer.RegisterSingleton<ILiteDatabase, LiteDatabase>(sp => new LiteDatabase("Daybreak.db"));
|
||||
serviceProducer.RegisterSingleton<IMutexHandler, MutexHandler>();
|
||||
serviceProducer.RegisterSingleton<IRuntimeStore, RuntimeStore>();
|
||||
serviceProducer.RegisterSingleton<IBuildTemplateManager, BuildTemplateManager>();
|
||||
serviceProducer.RegisterSingleton<IIconRetriever, IconRetriever>();
|
||||
serviceProducer.RegisterSingleton<IPrivilegeManager, PrivilegeManager>();
|
||||
serviceProducer.RegisterSingleton<IScreenManager, ScreenManager>();
|
||||
serviceProducer.RegisterSingleton<IShortcutManager, ShortcutManager>();
|
||||
serviceProducer.RegisterScoped<ICredentialManager, CredentialManager>();
|
||||
serviceProducer.RegisterScoped<IApplicationLauncher, ApplicationLauncher>();
|
||||
serviceProducer.RegisterScoped<IScreenshotProvider, ScreenshotProvider>();
|
||||
serviceProducer.RegisterScoped<IBloogumClient, BloogumClient>();
|
||||
serviceProducer.RegisterScoped<IApplicationUpdater, ApplicationUpdater>();
|
||||
serviceProducer.RegisterScoped<IBuildTemplateManager, BuildTemplateManager>();
|
||||
serviceProducer.RegisterScoped<IIconRetriever, IconRetriever>();
|
||||
serviceProducer.RegisterScoped<IPrivilegeManager, PrivilegeManager>();
|
||||
serviceProducer.RegisterScoped<IScreenManager, ScreenManager>();
|
||||
serviceProducer.RegisterLogWriter<ILogsManager, JsonLogsManager>();
|
||||
serviceProducer.RegisterScoped((sp) => new ScopeMetadata(new CorrelationVector()));
|
||||
}
|
||||
public static void RegisterLifetimeServices(IApplicationLifetimeProducer applicationLifetimeProducer)
|
||||
{
|
||||
applicationLifetimeProducer.ThrowIfNull(nameof(applicationLifetimeProducer));
|
||||
|
||||
applicationLifetimeProducer.RegisterService<ILoggingDatabase>();
|
||||
applicationLifetimeProducer.RegisterService<IScreenshotProvider>();
|
||||
applicationLifetimeProducer.RegisterService<IApplicationUpdater>();
|
||||
applicationLifetimeProducer.RegisterService<IShortcutManager>();
|
||||
}
|
||||
public static void RegisterViews(IViewProducer viewProducer)
|
||||
{
|
||||
viewProducer.ThrowIfNull(nameof(viewProducer));
|
||||
@@ -70,6 +80,7 @@ namespace Daybreak.Configuration
|
||||
viewProducer.RegisterView<RequestElevationView>();
|
||||
viewProducer.RegisterView<ScreenChoiceView>();
|
||||
viewProducer.RegisterView<VersionManagementView>();
|
||||
viewProducer.RegisterView<LogsView>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using Daybreak.Launch;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Models.Browser;
|
||||
using Daybreak.Models.Builds;
|
||||
using Daybreak.Services.BuildTemplates;
|
||||
using Daybreak.Services.Configuration;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.Extensions;
|
||||
using System.Threading.Tasks;
|
||||
@@ -23,15 +23,18 @@ namespace Daybreak.Controls
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0052:Remove unread private members", Justification = "Used by source generators")]
|
||||
public partial class ChromiumBrowserWrapper : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty AddressProperty =
|
||||
DependencyPropertyExtensions.Register<ChromiumBrowserWrapper, string>(nameof(Address));
|
||||
|
||||
private const string BrowserDownloadLink = "https://developer.microsoft.com/en-us/microsoft-edge/webview2/";
|
||||
|
||||
public event EventHandler<string> FavoriteUriChanged;
|
||||
public event EventHandler MaximizeClicked;
|
||||
public event EventHandler<Build> BuildDecoded;
|
||||
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
private readonly ILogger logger;
|
||||
private readonly IBuildTemplateManager buildTemplateManager;
|
||||
private ILiveOptions<ApplicationConfiguration> liveOptions;
|
||||
private ILogger<ChromiumBrowserWrapper> logger;
|
||||
private IBuildTemplateManager buildTemplateManager;
|
||||
private CoreWebView2Environment coreWebView2Environment;
|
||||
|
||||
[GenerateDependencyProperty(InitialValue = true)]
|
||||
@@ -40,7 +43,7 @@ namespace Daybreak.Controls
|
||||
private bool canNavigate;
|
||||
[GenerateDependencyProperty(InitialValue = true)]
|
||||
private bool controlsEnabled;
|
||||
[GenerateDependencyProperty(InitialValue = true)]
|
||||
[GenerateDependencyProperty]
|
||||
private bool browserSupported;
|
||||
[GenerateDependencyProperty]
|
||||
private bool addressBarReadonly;
|
||||
@@ -50,17 +53,22 @@ namespace Daybreak.Controls
|
||||
private bool navigating;
|
||||
[GenerateDependencyProperty]
|
||||
private string favoriteAddress;
|
||||
[GenerateDependencyProperty]
|
||||
private string address;
|
||||
public string Address
|
||||
{
|
||||
get => this.GetTypedValue<string>(AddressProperty);
|
||||
set
|
||||
{
|
||||
if (this.BrowserSupported is true)
|
||||
{
|
||||
this.SetValue(AddressProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ChromiumBrowserWrapper()
|
||||
{
|
||||
this.configurationManager = Launcher.ApplicationServiceManager.GetService<IConfigurationManager>();
|
||||
this.logger = Launcher.ApplicationServiceManager.GetService<ILogger>();
|
||||
this.buildTemplateManager = Launcher.ApplicationServiceManager.GetService<IBuildTemplateManager>();
|
||||
this.InitializeComponent();
|
||||
this.InitializeEnvironment();
|
||||
this.InitializeBrowser();
|
||||
this.WebBrowser.IsEnabled = false;
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
@@ -72,6 +80,18 @@ namespace Daybreak.Controls
|
||||
}
|
||||
}
|
||||
|
||||
public async void InitializeBrowser(
|
||||
ILiveOptions<ApplicationConfiguration> liveOptions,
|
||||
IBuildTemplateManager buildTemplateManager,
|
||||
ILogger<ChromiumBrowserWrapper> logger)
|
||||
{
|
||||
this.liveOptions = liveOptions;
|
||||
this.buildTemplateManager = buildTemplateManager;
|
||||
this.logger = logger;
|
||||
this.InitializeEnvironment();
|
||||
await this.InitializeBrowser();
|
||||
}
|
||||
|
||||
public async void ReinitializeBrowser()
|
||||
{
|
||||
await this.InitializeBrowser();
|
||||
@@ -79,7 +99,7 @@ namespace Daybreak.Controls
|
||||
|
||||
private void InitializeEnvironment()
|
||||
{
|
||||
if (this.configurationManager.GetConfiguration().BrowsersEnabled is false)
|
||||
if (this.liveOptions.Value.BrowsersEnabled is false)
|
||||
{
|
||||
this.BrowserSupported = false;
|
||||
return;
|
||||
@@ -101,9 +121,10 @@ namespace Daybreak.Controls
|
||||
{
|
||||
if (this.BrowserSupported is true)
|
||||
{
|
||||
this.WebBrowser.IsEnabled = true;
|
||||
await this.WebBrowser.EnsureCoreWebView2Async(this.coreWebView2Environment);
|
||||
this.AddressBarReadonly = this.configurationManager.GetConfiguration().AddressBarReadonly;
|
||||
this.CanDownloadBuild = this.configurationManager.GetConfiguration().ExperimentalFeatures.DynamicBuildLoading;
|
||||
this.AddressBarReadonly = this.liveOptions.Value.AddressBarReadonly;
|
||||
this.CanDownloadBuild = this.liveOptions.Value.ExperimentalFeatures.DynamicBuildLoading;
|
||||
this.WebBrowser.CoreWebView2.NewWindowRequested += (browser, args) => args.Handled = true;
|
||||
this.WebBrowser.NavigationStarting += (browser, args) =>
|
||||
{
|
||||
@@ -174,8 +195,9 @@ namespace Daybreak.Controls
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
this.logger.LogError(e);
|
||||
this.logger.LogError(e, $"Exception encountered when deserializing {nameof(BrowserPayload)}");
|
||||
}
|
||||
|
||||
if (payload?.Key == BrowserPayload.PayloadKeys.ContextMenu)
|
||||
{
|
||||
var contextMenuPayload = args.WebMessageAsJson.Deserialize<BrowserPayload<OnContextMenuPayload>>();
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<UserControl x:Class="Daybreak.Controls.LogsGlyph"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Daybreak.Controls"
|
||||
mc:Ignorable="d"
|
||||
x:Name="_this"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Viewbox>
|
||||
<Path Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
|
||||
Data="m7,3l0,-1.00209c0,-1.09965 0.89762,-1.99791 2.00488,-1.99791l0.99024,0c1.11098,0 2.00488,0.8945 2.00488,1.99791l0,1.00209l2.00442,0c0.55074,0 0.99558,0.44725 0.99558,0.99896l0,1.00208c0,0.5563 -0.44574,0.99896 -0.99558,0.99896l-9.00884,0c-0.55074,0 -0.99558,-0.44725 -0.99558,-0.99896l0,-1.00208c0,-0.5563 0.44574,-0.99896 0.99558,-0.99896l2.00442,0l0,0zm8.99999,1l1.00259,0c1.10649,0 1.99742,0.89704 1.99742,2.00359l0,20.99282c0,1.11383 -0.89428,2.00359 -1.99742,2.00359l-15.00516,0c-1.10649,0 -1.99742,-0.89704 -1.99742,-2.00359l0,-20.99282c0,-1.11383 0.89428,-2.00359 1.99742,-2.00359l1.00259,0c-0.00001,0.00163 -0.00001,0.00325 -0.00001,0.00488l0,0.99024c0,1.10726 0.89354,2.00488 2.00276,2.00488l8.99448,0c1.10609,0 2.00276,-0.8939 2.00276,-2.00488l0,-0.99024c0,-0.00163 0,-0.00325 -0.00001,-0.00488l0,0l0,0zm-6.49999,-1c0.27614,0 0.5,-0.22386 0.5,-0.5c0,-0.27614 -0.22386,-0.5 -0.5,-0.5c-0.27614,0 -0.5,0.22386 -0.5,0.5c0,0.27614 0.22386,0.5 0.5,0.5l0,0zm-6.5,8l0,1l13,0l0,-1l-13,0l0,0zm0,3l0,1l13,0l0,-1l-13,0l0,0zm0,3l0,1l13,0l0,-1l-13,0l0,0zm0,3l0,1l13,0l0,-1l-13,0l0,0zm0,3l0,1l13,0l0,-1l-13,0l0,0z"></Path>
|
||||
</Viewbox>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Daybreak.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LogsGlyph.xaml
|
||||
/// </summary>
|
||||
public partial class LogsGlyph : UserControl
|
||||
{
|
||||
public LogsGlyph()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ namespace Daybreak.Controls
|
||||
public partial class AttributeTemplate : UserControl
|
||||
{
|
||||
public event EventHandler<AttributeEntry> HelpClicked;
|
||||
public event EventHandler<AttributeEntry> AttributeChanged;
|
||||
|
||||
[GenerateDependencyProperty(InitialValue = false)]
|
||||
private bool canAdd;
|
||||
@@ -50,6 +51,7 @@ namespace Daybreak.Controls
|
||||
this.DataContext.As<AttributeEntry>().Points--;
|
||||
this.CanSubtract = this.DataContext.As<AttributeEntry>().Points > 0;
|
||||
this.CanAdd = true;
|
||||
this.AttributeChanged?.Invoke(this, this.DataContext.As<AttributeEntry>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +62,7 @@ namespace Daybreak.Controls
|
||||
this.DataContext.As<AttributeEntry>().Points++;
|
||||
this.CanAdd = this.DataContext.As<AttributeEntry>().Points < 12;
|
||||
this.CanSubtract = true;
|
||||
this.AttributeChanged?.Invoke(this, this.DataContext.As<AttributeEntry>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
HorizontalContentAlignment="Stretch" BorderThickness="0">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<local:AttributeTemplate HelpClicked="AttributeTemplate_HelpClicked"></local:AttributeTemplate>
|
||||
<local:AttributeTemplate HelpClicked="AttributeTemplate_HelpClicked" AttributeChanged="AttributeTemplate_AttributeChanged"></local:AttributeTemplate>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
@@ -95,42 +95,42 @@
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<local:SkillTemplate Grid.Column="0"
|
||||
<local:SkillTemplate Grid.Column="0" x:Name="SkillTemplate0"
|
||||
Foreground="White" Cursor="Hand"
|
||||
FontSize="22" DataContext="{Binding ElementName=_this, Path=Skill0, Mode=TwoWay}"
|
||||
VerticalAlignment="Stretch" Clicked="SkillTemplate_Clicked"
|
||||
RemoveClicked="SkillTemplate_RemoveClicked"></local:SkillTemplate>
|
||||
<local:SkillTemplate Grid.Column="1"
|
||||
<local:SkillTemplate Grid.Column="1" x:Name="SkillTemplate1"
|
||||
Foreground="White" Cursor="Hand"
|
||||
FontSize="22" DataContext="{Binding ElementName=_this, Path=Skill1, Mode=TwoWay}"
|
||||
VerticalAlignment="Stretch" Clicked="SkillTemplate_Clicked"
|
||||
RemoveClicked="SkillTemplate_RemoveClicked"></local:SkillTemplate>
|
||||
<local:SkillTemplate Grid.Column="2"
|
||||
<local:SkillTemplate Grid.Column="2" x:Name="SkillTemplate2"
|
||||
Foreground="White" Cursor="Hand"
|
||||
FontSize="22" DataContext="{Binding ElementName=_this, Path=Skill2, Mode=TwoWay}"
|
||||
VerticalAlignment="Stretch" Clicked="SkillTemplate_Clicked"
|
||||
RemoveClicked="SkillTemplate_RemoveClicked"></local:SkillTemplate>
|
||||
<local:SkillTemplate Grid.Column="3"
|
||||
<local:SkillTemplate Grid.Column="3" x:Name="SkillTemplate3"
|
||||
Foreground="White" Cursor="Hand"
|
||||
FontSize="22" DataContext="{Binding ElementName=_this, Path=Skill3, Mode=TwoWay}"
|
||||
VerticalAlignment="Stretch" Clicked="SkillTemplate_Clicked"
|
||||
RemoveClicked="SkillTemplate_RemoveClicked"></local:SkillTemplate>
|
||||
<local:SkillTemplate Grid.Column="4"
|
||||
<local:SkillTemplate Grid.Column="4" x:Name="SkillTemplate4"
|
||||
Foreground="White" Cursor="Hand"
|
||||
FontSize="22" DataContext="{Binding ElementName=_this, Path=Skill4, Mode=TwoWay}"
|
||||
VerticalAlignment="Stretch" Clicked="SkillTemplate_Clicked"
|
||||
RemoveClicked="SkillTemplate_RemoveClicked"></local:SkillTemplate>
|
||||
<local:SkillTemplate Grid.Column="5"
|
||||
<local:SkillTemplate Grid.Column="5" x:Name="SkillTemplate5"
|
||||
Foreground="White" Cursor="Hand"
|
||||
FontSize="22" DataContext="{Binding ElementName=_this, Path=Skill5, Mode=TwoWay}"
|
||||
VerticalAlignment="Stretch" Clicked="SkillTemplate_Clicked"
|
||||
RemoveClicked="SkillTemplate_RemoveClicked"></local:SkillTemplate>
|
||||
<local:SkillTemplate Grid.Column="6"
|
||||
<local:SkillTemplate Grid.Column="6" x:Name="SkillTemplate6"
|
||||
Foreground="White" Cursor="Hand"
|
||||
FontSize="22" DataContext="{Binding ElementName=_this, Path=Skill6, Mode=TwoWay}"
|
||||
VerticalAlignment="Stretch" Clicked="SkillTemplate_Clicked"
|
||||
RemoveClicked="SkillTemplate_RemoveClicked"></local:SkillTemplate>
|
||||
<local:SkillTemplate Grid.Column="7"
|
||||
<local:SkillTemplate Grid.Column="7" x:Name="SkillTemplate7"
|
||||
Foreground="White" Cursor="Hand"
|
||||
FontSize="22" DataContext="{Binding ElementName=_this, Path=Skill7, Mode=TwoWay}"
|
||||
VerticalAlignment="Stretch" Clicked="SkillTemplate_Clicked"
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
using Daybreak.Models.Builds;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Models.Builds;
|
||||
using Daybreak.Services.BuildTemplates;
|
||||
using Daybreak.Services.IconRetrieve;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Configuration;
|
||||
using System.Extensions;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
@@ -19,10 +25,13 @@ namespace Daybreak.Controls
|
||||
private const string InfoNamePlaceholder = "[NAME]";
|
||||
private const string BaseAddress = $"https://wiki.guildwars.com/wiki/{InfoNamePlaceholder}";
|
||||
|
||||
private bool suppressBuildChanged = false;
|
||||
private bool loadedProperties = false;
|
||||
private BuildEntry loadedBuild;
|
||||
private SkillTemplate selectingSkillTemplate;
|
||||
|
||||
public event EventHandler BuildChanged;
|
||||
|
||||
[GenerateDependencyProperty]
|
||||
private Profession primaryProfession;
|
||||
[GenerateDependencyProperty]
|
||||
@@ -51,7 +60,24 @@ namespace Daybreak.Controls
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.InitializeProperties();
|
||||
this.DataContextChanged += BuildTemplate_DataContextChanged;
|
||||
this.DataContextChanged += this.BuildTemplate_DataContextChanged;
|
||||
}
|
||||
|
||||
public void InitializeTemplate(
|
||||
IIconRetriever iconRetriever,
|
||||
ILiveOptions<ApplicationConfiguration> liveOptions,
|
||||
IBuildTemplateManager buildTemplateManager,
|
||||
ILogger<ChromiumBrowserWrapper> logger)
|
||||
{
|
||||
this.SkillBrowser.InitializeBrowser(liveOptions, buildTemplateManager, logger);
|
||||
this.SkillTemplate0.InitializeSkillTemplate(iconRetriever);
|
||||
this.SkillTemplate1.InitializeSkillTemplate(iconRetriever);
|
||||
this.SkillTemplate2.InitializeSkillTemplate(iconRetriever);
|
||||
this.SkillTemplate3.InitializeSkillTemplate(iconRetriever);
|
||||
this.SkillTemplate4.InitializeSkillTemplate(iconRetriever);
|
||||
this.SkillTemplate5.InitializeSkillTemplate(iconRetriever);
|
||||
this.SkillTemplate6.InitializeSkillTemplate(iconRetriever);
|
||||
this.SkillTemplate7.InitializeSkillTemplate(iconRetriever);
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
@@ -72,8 +98,36 @@ namespace Daybreak.Controls
|
||||
{
|
||||
this.loadedBuild.Build.Secondary = this.SecondaryProfession;
|
||||
}
|
||||
|
||||
this.LoadSkills();
|
||||
this.LoadAttributes();
|
||||
if (this.suppressBuildChanged is false)
|
||||
{
|
||||
this.BuildChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
|
||||
if (e.Property == Skill0Property ||
|
||||
e.Property == Skill1Property ||
|
||||
e.Property == Skill2Property ||
|
||||
e.Property == Skill3Property ||
|
||||
e.Property == Skill4Property ||
|
||||
e.Property == Skill5Property ||
|
||||
e.Property == Skill6Property ||
|
||||
e.Property == Skill7Property)
|
||||
{
|
||||
if (this.suppressBuildChanged is false)
|
||||
{
|
||||
this.loadedBuild.Build.Skills[0] = this.Skill0;
|
||||
this.loadedBuild.Build.Skills[1] = this.Skill1;
|
||||
this.loadedBuild.Build.Skills[2] = this.Skill2;
|
||||
this.loadedBuild.Build.Skills[3] = this.Skill3;
|
||||
this.loadedBuild.Build.Skills[4] = this.Skill4;
|
||||
this.loadedBuild.Build.Skills[5] = this.Skill5;
|
||||
this.loadedBuild.Build.Skills[6] = this.Skill6;
|
||||
this.loadedBuild.Build.Skills[7] = this.Skill7;
|
||||
this.BuildChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,55 +194,62 @@ namespace Daybreak.Controls
|
||||
private void LoadSkills()
|
||||
{
|
||||
var possibleSkills = Skill.Skills
|
||||
.Where(s => s.Profession == PrimaryProfession || s.Profession == SecondaryProfession || s.Profession == Profession.None)
|
||||
.Where(s => s.Profession == this.PrimaryProfession || s.Profession == this.SecondaryProfession || s.Profession == Profession.None)
|
||||
.Where(s => s != Skill.NoSkill)
|
||||
.OrderBy(s => s.Name);
|
||||
this.AvailableSkills.ClearAnd().AddRange(possibleSkills);
|
||||
|
||||
if (this.Skill0.Profession != PrimaryProfession &&
|
||||
this.Skill0.Profession != SecondaryProfession &&
|
||||
if (this.Skill0.Profession != this.PrimaryProfession &&
|
||||
this.Skill0.Profession != this.SecondaryProfession &&
|
||||
this.Skill0.Profession != Profession.None)
|
||||
{
|
||||
this.Skill0 = Skill.NoSkill;
|
||||
}
|
||||
if (this.Skill1.Profession != PrimaryProfession &&
|
||||
this.Skill1.Profession != SecondaryProfession &&
|
||||
|
||||
if (this.Skill1.Profession != this.PrimaryProfession &&
|
||||
this.Skill1.Profession != this.SecondaryProfession &&
|
||||
this.Skill1.Profession != Profession.None)
|
||||
{
|
||||
this.Skill1 = Skill.NoSkill;
|
||||
}
|
||||
if (this.Skill2.Profession != PrimaryProfession &&
|
||||
this.Skill2.Profession != SecondaryProfession &&
|
||||
|
||||
if (this.Skill2.Profession != this.PrimaryProfession &&
|
||||
this.Skill2.Profession != this.SecondaryProfession &&
|
||||
this.Skill2.Profession != Profession.None)
|
||||
{
|
||||
this.Skill2 = Skill.NoSkill;
|
||||
}
|
||||
if (this.Skill3.Profession != PrimaryProfession &&
|
||||
this.Skill3.Profession != SecondaryProfession &&
|
||||
|
||||
if (this.Skill3.Profession != this.PrimaryProfession &&
|
||||
this.Skill3.Profession != this.SecondaryProfession &&
|
||||
this.Skill3.Profession != Profession.None)
|
||||
{
|
||||
this.Skill3 = Skill.NoSkill;
|
||||
}
|
||||
if (this.Skill4.Profession != PrimaryProfession &&
|
||||
this.Skill4.Profession != SecondaryProfession &&
|
||||
|
||||
if (this.Skill4.Profession != this.PrimaryProfession &&
|
||||
this.Skill4.Profession != this.SecondaryProfession &&
|
||||
this.Skill4.Profession != Profession.None)
|
||||
{
|
||||
this.Skill4 = Skill.NoSkill;
|
||||
}
|
||||
if (this.Skill5.Profession != PrimaryProfession &&
|
||||
this.Skill5.Profession != SecondaryProfession &&
|
||||
|
||||
if (this.Skill5.Profession != this.PrimaryProfession &&
|
||||
this.Skill5.Profession != this.SecondaryProfession &&
|
||||
this.Skill5.Profession != Profession.None)
|
||||
{
|
||||
this.Skill5 = Skill.NoSkill;
|
||||
}
|
||||
if (this.Skill6.Profession != PrimaryProfession &&
|
||||
this.Skill6.Profession != SecondaryProfession &&
|
||||
|
||||
if (this.Skill6.Profession != this.PrimaryProfession &&
|
||||
this.Skill6.Profession != this.SecondaryProfession &&
|
||||
this.Skill6.Profession != Profession.None)
|
||||
{
|
||||
this.Skill6 = Skill.NoSkill;
|
||||
}
|
||||
if (this.Skill7.Profession != PrimaryProfession &&
|
||||
this.Skill7.Profession != SecondaryProfession &&
|
||||
|
||||
if (this.Skill7.Profession != this.PrimaryProfession &&
|
||||
this.Skill7.Profession != this.SecondaryProfession &&
|
||||
this.Skill7.Profession != Profession.None)
|
||||
{
|
||||
this.Skill7 = Skill.NoSkill;
|
||||
@@ -197,6 +258,7 @@ namespace Daybreak.Controls
|
||||
|
||||
private void LoadBuild()
|
||||
{
|
||||
this.suppressBuildChanged = true;
|
||||
var build = this.DataContext.As<BuildEntry>();
|
||||
this.loadedBuild = build;
|
||||
this.PrimaryProfession = build.Build.Primary;
|
||||
@@ -209,6 +271,7 @@ namespace Daybreak.Controls
|
||||
this.Skill5 = build.Build.Skills[5];
|
||||
this.Skill6 = build.Build.Skills[6];
|
||||
this.Skill7 = build.Build.Skills[7];
|
||||
this.suppressBuildChanged = false;
|
||||
}
|
||||
|
||||
private void BrowseToInfo(string infoName)
|
||||
@@ -220,13 +283,19 @@ namespace Daybreak.Controls
|
||||
|
||||
private void ShowInfoBrowser()
|
||||
{
|
||||
this.SkillBrowser.Width = 400;
|
||||
this.SkillsListView.Width = 0;
|
||||
if (this.SkillBrowser.BrowserSupported is true)
|
||||
{
|
||||
this.SkillBrowser.Width = 400;
|
||||
this.SkillsListView.Width = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void HideInfoBrowser()
|
||||
{
|
||||
this.SkillBrowser.Width = 0;
|
||||
if (this.SkillBrowser.BrowserSupported is true)
|
||||
{
|
||||
this.SkillBrowser.Width = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowSkillListView()
|
||||
@@ -247,7 +316,7 @@ namespace Daybreak.Controls
|
||||
return;
|
||||
}
|
||||
|
||||
this.BrowseToInfo(PrimaryProfession.Name);
|
||||
this.BrowseToInfo(this.PrimaryProfession.Name);
|
||||
if (e is RoutedEventArgs routedEventArgs)
|
||||
{
|
||||
routedEventArgs.Handled = true;
|
||||
@@ -273,6 +342,11 @@ namespace Daybreak.Controls
|
||||
this.BrowseToInfo(e.Attribute.Name);
|
||||
}
|
||||
|
||||
private void AttributeTemplate_AttributeChanged(object sender, AttributeEntry e)
|
||||
{
|
||||
this.BuildChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
|
||||
private void SkillTemplate_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var skill = sender.As<SkillTemplate>().DataContext.As<Skill>();
|
||||
@@ -285,6 +359,7 @@ namespace Daybreak.Controls
|
||||
{
|
||||
this.BrowseToInfo(skill.Name);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
@@ -303,14 +378,14 @@ namespace Daybreak.Controls
|
||||
|
||||
this.selectingSkillTemplate.DataContext = sender.As<ListView>().SelectedItem;
|
||||
this.HideSkillListView();
|
||||
this.loadedBuild.Build.Skills[0] = Skill0;
|
||||
this.loadedBuild.Build.Skills[1] = Skill1;
|
||||
this.loadedBuild.Build.Skills[2] = Skill2;
|
||||
this.loadedBuild.Build.Skills[3] = Skill3;
|
||||
this.loadedBuild.Build.Skills[4] = Skill4;
|
||||
this.loadedBuild.Build.Skills[5] = Skill5;
|
||||
this.loadedBuild.Build.Skills[6] = Skill6;
|
||||
this.loadedBuild.Build.Skills[7] = Skill7;
|
||||
this.loadedBuild.Build.Skills[0] = this.Skill0;
|
||||
this.loadedBuild.Build.Skills[1] = this.Skill1;
|
||||
this.loadedBuild.Build.Skills[2] = this.Skill2;
|
||||
this.loadedBuild.Build.Skills[3] = this.Skill3;
|
||||
this.loadedBuild.Build.Skills[4] = this.Skill4;
|
||||
this.loadedBuild.Build.Skills[5] = this.Skill5;
|
||||
this.loadedBuild.Build.Skills[6] = this.Skill6;
|
||||
this.loadedBuild.Build.Skills[7] = this.Skill7;
|
||||
}
|
||||
|
||||
private void ListView_NavigateWithMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<UserControl x:Class="Daybreak.Controls.LogMessageTemplate"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Daybreak.Controls"
|
||||
x:Name="_this"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
<BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"></BooleanToVisibilityConverter>
|
||||
</UserControl.Resources>
|
||||
<Grid HorizontalAlignment="Stretch">
|
||||
<TextBlock Text="{Binding ElementName=_this, Path=Message, Mode=OneWay}" Background="Transparent"
|
||||
Foreground="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
|
||||
MouseLeftButtonDown="TextBox_MouseLeftButtonDown" MaxHeight="18" TextWrapping="Wrap"></TextBlock>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Windows.Extensions;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Extensions;
|
||||
|
||||
namespace Daybreak.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LogTemplate.xaml
|
||||
/// </summary>
|
||||
public partial class LogMessageTemplate : UserControl
|
||||
{
|
||||
private bool expanded;
|
||||
|
||||
[GenerateDependencyProperty]
|
||||
private string message;
|
||||
|
||||
public LogMessageTemplate()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void TextBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs eventArgs)
|
||||
{
|
||||
this.expanded = !this.expanded;
|
||||
if (this.expanded)
|
||||
{
|
||||
sender.As<TextBlock>().MaxHeight = double.MaxValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.As<TextBlock>().MaxHeight = 18;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace Daybreak.Controls
|
||||
public event EventHandler<RoutedEventArgs> Clicked;
|
||||
public event EventHandler RemoveClicked;
|
||||
|
||||
private readonly IIconRetriever iconRetriever;
|
||||
private IIconRetriever iconRetriever;
|
||||
|
||||
[GenerateDependencyProperty]
|
||||
private ImageSource imageSource;
|
||||
@@ -32,22 +32,26 @@ namespace Daybreak.Controls
|
||||
|
||||
public SkillTemplate()
|
||||
{
|
||||
this.iconRetriever = Launcher.ApplicationServiceManager.GetService<IIconRetriever>();
|
||||
this.InitializeComponent();
|
||||
this.DataContextChanged += SkillTemplate_DataContextChanged;
|
||||
}
|
||||
|
||||
public void InitializeSkillTemplate(IIconRetriever iconRetriever)
|
||||
{
|
||||
this.iconRetriever = iconRetriever;
|
||||
}
|
||||
|
||||
private void SkillTemplate_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.NewValue is Skill skill)
|
||||
{
|
||||
if (skill != Skill.NoSkill)
|
||||
{
|
||||
Task.Run(() => GetImageStream(skill)).ContinueWith((previousTask) =>
|
||||
Task.Run(() => this.GetImageStream(skill)).ContinueWith((previousTask) =>
|
||||
{
|
||||
this.Dispatcher.Invoke(() =>
|
||||
{
|
||||
this.ImageSource = GetImageSource(previousTask.Result);
|
||||
this.ImageSource = this.GetImageSource(previousTask.Result);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -88,6 +92,11 @@ namespace Daybreak.Controls
|
||||
}
|
||||
private async Task<Stream> GetImageStream(Skill skill)
|
||||
{
|
||||
if (this.iconRetriever is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var maybeStream = await this.iconRetriever.GetIcon(skill);
|
||||
return maybeStream.ExtractValue();
|
||||
}
|
||||
|
||||
@@ -2,29 +2,34 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
|
||||
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
|
||||
<Version>0.8.9</Version>
|
||||
<Version>0.9.2.8</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.32" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.818.41" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.43" />
|
||||
<PackageReference Include="LiteDB" Version="5.0.12" />
|
||||
<PackageReference Include="Microsoft.CorrelationVector" Version="1.0.42" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1264.42" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="NReco.Logging.File" Version="1.1.5" />
|
||||
<PackageReference Include="securifybv.ShellLink" Version="0.1.0" />
|
||||
<PackageReference Include="Slim" Version="1.2.2" />
|
||||
<PackageReference Include="Slim" Version="1.7.3" />
|
||||
<PackageReference Include="System.Windows.Interactivity.WPF" Version="2.0.20525" />
|
||||
<PackageReference Include="SystemExtensions.NetStandard" Version="1.1.4" />
|
||||
<PackageReference Include="SystemExtensions.NetStandard" Version="1.5.0" />
|
||||
<PackageReference Include="WCL" Version="1.0.2" />
|
||||
<PackageReference Include="WpfExtended" Version="0.2.1" />
|
||||
<PackageReference Include="WpfExtended" Version="0.6.2" />
|
||||
<PackageReference Include="WpfExtended.SourceGeneration" Version="0.1.1" />
|
||||
<PackageReference Include="WpfScreenHelper" Version="1.0.0" />
|
||||
<PackageReference Include="WpfScreenHelper" Version="2.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -69,4 +74,12 @@
|
||||
<Exec Command="echo.>$(Version).version" />
|
||||
</Target>
|
||||
|
||||
<Target Name="RemoveDuplicateAnalyzers" BeforeTargets="CoreCompile">
|
||||
<!-- Work around https://github.com/dotnet/wpf/issues/6792 -->
|
||||
<ItemGroup>
|
||||
<FilteredAnalyzer Include="@(Analyzer->Distinct())" />
|
||||
<Analyzer Remove="@(Analyzer)" />
|
||||
<Analyzer Include="@(FilteredAnalyzer)" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
</Project>
|
||||
|
||||
+35
-13
@@ -1,17 +1,13 @@
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Exceptions;
|
||||
using Daybreak.Services.ApplicationLifetime;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Daybreak.Utils;
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using Microsoft.Web.WebView2.Wpf;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Slim;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Extensions;
|
||||
|
||||
@@ -19,7 +15,7 @@ namespace Daybreak.Launch
|
||||
{
|
||||
public sealed class Launcher : ExtendedApplication<MainWindow>
|
||||
{
|
||||
public static IServiceManager ApplicationServiceManager { get; private set; }
|
||||
private ILogger logger;
|
||||
private readonly static Launcher launcher = new();
|
||||
|
||||
[STAThread]
|
||||
@@ -28,10 +24,14 @@ namespace Daybreak.Launch
|
||||
return LaunchMainWindow();
|
||||
}
|
||||
|
||||
protected override void SetupServiceManager(IServiceManager serviceManager)
|
||||
{
|
||||
ProjectConfiguration.RegisterResolvers(serviceManager);
|
||||
}
|
||||
protected override void RegisterServices(IServiceProducer serviceProducer)
|
||||
{
|
||||
ProjectConfiguration.RegisterServices(this.ServiceManager);
|
||||
ProjectConfiguration.RegisterLifetimeServices(this.ServiceManager.GetService<IApplicationLifetimeManager>());
|
||||
ServiceManager.BuildSingletons();
|
||||
ProjectConfiguration.RegisterViews(this.ServiceManager.GetService<IViewManager>());
|
||||
}
|
||||
protected override bool HandleException(Exception e)
|
||||
@@ -41,10 +41,23 @@ namespace Daybreak.Launch
|
||||
return false;
|
||||
}
|
||||
|
||||
this.ServiceManager.GetService<ILogger>().LogCritical(e);
|
||||
if (this.logger is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (e is FatalException fatalException)
|
||||
{
|
||||
this.logger.LogCritical(e, $"{nameof(FatalException)} encountered. Closing application");
|
||||
MessageBox.Show(fatalException.ToString());
|
||||
File.WriteAllText("crash.log", e.ToString());
|
||||
return false;
|
||||
}
|
||||
else if (e is TargetInvocationException targetInvocationException && e.InnerException is FatalException innerFatalException)
|
||||
{
|
||||
this.logger.LogCritical(e, $"{nameof(FatalException)} encountered. Closing application");
|
||||
MessageBox.Show(innerFatalException.ToString());
|
||||
File.WriteAllText("crash.log", e.ToString());
|
||||
return false;
|
||||
}
|
||||
else if (e is AggregateException aggregateException)
|
||||
@@ -54,24 +67,33 @@ namespace Daybreak.Launch
|
||||
{
|
||||
/*
|
||||
* Ignore exception caused by browser failing to initialize due to missing window.
|
||||
* Likely caused by switching windows before browser was initialized.
|
||||
* Likely caused by switching views before browser was initialized.
|
||||
*/
|
||||
this.logger.LogError(e, "Failed to initialize browser");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (e.Message.Contains("Invalid window handle.") && e.StackTrace.Contains("CoreWebView2Environment.CreateCoreWebView2ControllerAsync"))
|
||||
{
|
||||
/*
|
||||
* Ignore exception caused by browser failing to initialize due to missing window.
|
||||
* Likely caused by switching views before the browser was initialized.
|
||||
*/
|
||||
this.logger.LogError(e, "Failed to initialize browser");
|
||||
return true;
|
||||
}
|
||||
|
||||
this.logger.LogError(e, $"Unhandled exception caught {e.GetType()}");
|
||||
MessageBox.Show(e.ToString());
|
||||
return true;
|
||||
}
|
||||
protected override void ApplicationStarting()
|
||||
{
|
||||
ApplicationServiceManager = this.ServiceManager;
|
||||
this.ServiceManager.GetService<IApplicationLifetimeManager>().OnStartup();
|
||||
this.logger = this.ServiceManager.GetService<ILogger<Launcher>>();
|
||||
this.RegisterViewContainer();
|
||||
}
|
||||
protected override void ApplicationClosing()
|
||||
{
|
||||
this.ServiceManager.GetService<IApplicationLifetimeManager>().OnClosing();
|
||||
}
|
||||
|
||||
private void RegisterViewContainer()
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using Daybreak.Services.Bloogum;
|
||||
using Daybreak.Services.Configuration;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Services.Bloogum;
|
||||
using Daybreak.Services.Privilege;
|
||||
using Daybreak.Services.Runtime;
|
||||
using Daybreak.Services.Screenshots;
|
||||
using Daybreak.Services.Updater;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Daybreak.Views;
|
||||
using Pepa.Wpf.Utilities;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.Extensions;
|
||||
using System.Threading;
|
||||
@@ -32,11 +32,9 @@ namespace Daybreak.Launch
|
||||
private readonly IBloogumClient bloogumClient;
|
||||
private readonly IApplicationUpdater applicationUpdater;
|
||||
private readonly IPrivilegeManager privilegeManager;
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
private readonly ILiveOptions<ApplicationConfiguration> liveOptions;
|
||||
private readonly CancellationTokenSource cancellationToken = new();
|
||||
|
||||
private bool canCheckUpdate = false;
|
||||
|
||||
[GenerateDependencyProperty]
|
||||
private string creditText;
|
||||
[GenerateDependencyProperty]
|
||||
@@ -50,26 +48,19 @@ namespace Daybreak.Launch
|
||||
IBloogumClient bloogumClient,
|
||||
IApplicationUpdater applicationUpdater,
|
||||
IPrivilegeManager privilegeManager,
|
||||
IConfigurationManager configurationManager)
|
||||
ILiveOptions<ApplicationConfiguration> liveOptions)
|
||||
{
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
this.screenshotProvider = screenshotProvider.ThrowIfNull(nameof(screenshotProvider));
|
||||
this.bloogumClient = bloogumClient.ThrowIfNull(nameof(bloogumClient));
|
||||
this.applicationUpdater = applicationUpdater.ThrowIfNull(nameof(applicationUpdater));
|
||||
this.privilegeManager = privilegeManager.ThrowIfNull(nameof(privilegeManager));
|
||||
this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager));
|
||||
this.liveOptions = liveOptions.ThrowIfNull(nameof(liveOptions));
|
||||
this.InitializeComponent();
|
||||
this.LoadConfiguration();
|
||||
this.configurationManager.ConfigurationChanged += (s, e) => this.LoadConfiguration();
|
||||
this.CurrentVersionText = this.applicationUpdater.CurrentVersion.ToString();
|
||||
this.IsRunningAsAdmin = this.privilegeManager.AdminPrivileges;
|
||||
}
|
||||
|
||||
private void LoadConfiguration()
|
||||
{
|
||||
var configuration = this.configurationManager.GetConfiguration();
|
||||
this.canCheckUpdate = configuration.AutoCheckUpdate;
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@@ -178,7 +169,7 @@ namespace Daybreak.Launch
|
||||
|
||||
private async void CheckForUpdates()
|
||||
{
|
||||
var updateAvailable = this.canCheckUpdate is true && await this.applicationUpdater.UpdateAvailable().ConfigureAwait(true);
|
||||
var updateAvailable = this.liveOptions.Value.AutoCheckUpdate is true && await this.applicationUpdater.UpdateAvailable().ConfigureAwait(true);
|
||||
if (updateAvailable)
|
||||
{
|
||||
this.viewManager.ShowView<AskUpdateView>();
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
|
||||
namespace Daybreak.Models
|
||||
{
|
||||
public class Log
|
||||
public sealed class Log
|
||||
{
|
||||
public LogLevel LogLevel { get; set; }
|
||||
public string Message { get; set; }
|
||||
public string StackTrace { get; set; }
|
||||
public DateTime Timestamp { get; set; }
|
||||
public string Category { get; set; }
|
||||
public LogLevel LogLevel { get; set; }
|
||||
public string CorrelationVector { get; set; }
|
||||
public string EventId { get; set; }
|
||||
public DateTime LogTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Daybreak.Models
|
||||
{
|
||||
public enum LogLevel
|
||||
{
|
||||
Information,
|
||||
Warning,
|
||||
Error,
|
||||
Critical
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Microsoft.CorrelationVector;
|
||||
|
||||
namespace Daybreak.Models
|
||||
{
|
||||
public class ScopeMetadata
|
||||
{
|
||||
public CorrelationVector CorrelationVector { get; set; }
|
||||
|
||||
public ScopeMetadata(CorrelationVector correlationVector)
|
||||
{
|
||||
this.CorrelationVector = correlationVector;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,49 +9,45 @@ namespace Daybreak.Models
|
||||
[Serializable]
|
||||
public sealed class SecureString
|
||||
{
|
||||
public static SecureString Empty { get => new SecureString(string.Empty); }
|
||||
public static SecureString Empty { get => new(string.Empty); }
|
||||
|
||||
private byte[] encryptedBytes;
|
||||
private readonly byte[] key;
|
||||
|
||||
private byte[] DecryptedValue
|
||||
{
|
||||
get => encryptedBytes.DecryptBytes(key);
|
||||
set => encryptedBytes = value.EncryptBytes(key);
|
||||
get => this.encryptedBytes.DecryptBytes(key);
|
||||
set => this.encryptedBytes = value.EncryptBytes(key);
|
||||
}
|
||||
[JsonProperty("value")]
|
||||
public string Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return encryptedBytes.DecryptBytes(key).AsString();
|
||||
return this.encryptedBytes.DecryptBytes(key).AsString();
|
||||
}
|
||||
set
|
||||
{
|
||||
encryptedBytes = value.AsBytes().EncryptBytes(key);
|
||||
this.encryptedBytes = value.AsBytes().EncryptBytes(key);
|
||||
}
|
||||
}
|
||||
private SecureString(byte[] value)
|
||||
{
|
||||
key = new byte[32];
|
||||
using (var crypto = new RNGCryptoServiceProvider())
|
||||
{
|
||||
crypto.GetBytes(key);
|
||||
}
|
||||
this.key = new byte[32];
|
||||
using var crypto = RandomNumberGenerator.Create();
|
||||
crypto.GetBytes(key);
|
||||
this.DecryptedValue = value;
|
||||
}
|
||||
public SecureString(string value)
|
||||
{
|
||||
key = new byte[32];
|
||||
using (var crypto = new RNGCryptoServiceProvider())
|
||||
{
|
||||
crypto.GetBytes(key);
|
||||
}
|
||||
this.key = new byte[32];
|
||||
using var crypto = RandomNumberGenerator.Create();
|
||||
crypto.GetBytes(key);
|
||||
this.Value = value;
|
||||
}
|
||||
|
||||
public static implicit operator string(SecureString ss) => ss is null ? string.Empty : ss.Value;
|
||||
public static implicit operator SecureString(string s) => new SecureString(s);
|
||||
public static implicit operator SecureString(string s) => new(s);
|
||||
public static SecureString operator +(SecureString ss1, SecureString ss2)
|
||||
{
|
||||
if (ss1 is null) throw new ArgumentNullException(nameof(ss1));
|
||||
@@ -123,12 +119,12 @@ namespace Daybreak.Models
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Value.GetHashCode();
|
||||
return this.Value.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value;
|
||||
return this.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,10 @@ namespace Daybreak.Models.Versioning
|
||||
{
|
||||
parts.RemoveAt(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
parsedVersion = new Version
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
using Daybreak.Exceptions;
|
||||
using Daybreak.Services.Configuration;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Exceptions;
|
||||
using Daybreak.Services.Credentials;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Services.Mutex;
|
||||
using Daybreak.Services.Privilege;
|
||||
using Daybreak.Utils;
|
||||
using Daybreak.Views;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Win32;
|
||||
using Pepa.Wpf.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.Extensions;
|
||||
using System.IO;
|
||||
@@ -30,10 +30,10 @@ namespace Daybreak.Services.ApplicationLauncher
|
||||
private const string ProcessName = "gw";
|
||||
private const string ArenaNetMutex = "AN-Mute";
|
||||
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
private readonly ILiveOptions<ApplicationConfiguration> liveOptions;
|
||||
private readonly ICredentialManager credentialManager;
|
||||
private readonly IMutexHandler mutexHandler;
|
||||
private readonly ILogger logger;
|
||||
private readonly ILogger<ApplicationLauncher> logger;
|
||||
private readonly IPrivilegeManager privilegeManager;
|
||||
|
||||
public bool IsTexmodRunning => TexModProcessDetected();
|
||||
@@ -41,22 +41,22 @@ namespace Daybreak.Services.ApplicationLauncher
|
||||
public bool IsToolboxRunning => GuildwarsToolboxProcessDetected();
|
||||
|
||||
public ApplicationLauncher(
|
||||
IConfigurationManager configurationManager,
|
||||
ILiveOptions<ApplicationConfiguration> liveOptions,
|
||||
ICredentialManager credentialManager,
|
||||
IMutexHandler mutexHandler,
|
||||
ILogger logger,
|
||||
ILogger<ApplicationLauncher> logger,
|
||||
IPrivilegeManager privilegeManager)
|
||||
{
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
this.mutexHandler = mutexHandler.ThrowIfNull(nameof(mutexHandler));
|
||||
this.credentialManager = credentialManager.ThrowIfNull(nameof(credentialManager));
|
||||
this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager));
|
||||
this.liveOptions = liveOptions.ThrowIfNull(nameof(liveOptions));
|
||||
this.privilegeManager = privilegeManager.ThrowIfNull(nameof(privilegeManager));
|
||||
}
|
||||
|
||||
public async Task<bool> LaunchGuildwars()
|
||||
{
|
||||
var configuration = this.configurationManager.GetConfiguration();
|
||||
var configuration = this.liveOptions.Value;
|
||||
var auth = await this.credentialManager.GetDefaultCredentials().ConfigureAwait(false);
|
||||
return await auth.Switch(
|
||||
onSome: async (credentials) =>
|
||||
@@ -69,10 +69,10 @@ namespace Daybreak.Services.ApplicationLauncher
|
||||
return false;
|
||||
}
|
||||
|
||||
ClearGwLocks();
|
||||
this.ClearGwLocks();
|
||||
}
|
||||
|
||||
return await LaunchGuildwarsProcess(credentials.Username, credentials.Password, credentials.CharacterName);
|
||||
return await this.LaunchGuildwarsProcess(credentials.Username, credentials.Password, credentials.CharacterName);
|
||||
},
|
||||
onNone: () =>
|
||||
{
|
||||
@@ -85,7 +85,7 @@ namespace Daybreak.Services.ApplicationLauncher
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var configuration = this.configurationManager.GetConfiguration();
|
||||
var configuration = this.liveOptions.Value;
|
||||
var executable = configuration.ToolboxPath;
|
||||
if (File.Exists(executable) is false)
|
||||
{
|
||||
@@ -103,7 +103,7 @@ namespace Daybreak.Services.ApplicationLauncher
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var configuration = this.configurationManager.GetConfiguration();
|
||||
var configuration = this.liveOptions.Value;
|
||||
var executable = configuration.TexmodPath;
|
||||
if (File.Exists(executable) is false)
|
||||
{
|
||||
@@ -146,7 +146,7 @@ namespace Daybreak.Services.ApplicationLauncher
|
||||
|
||||
private async Task<bool> LaunchGuildwarsProcess(string email, Models.SecureString password, string character)
|
||||
{
|
||||
var executable = this.configurationManager.GetConfiguration().GuildwarsPaths.Where(path => path.Default).FirstOrDefault();
|
||||
var executable = this.liveOptions.Value.GuildwarsPaths.Where(path => path.Default).FirstOrDefault();
|
||||
if (executable is null)
|
||||
{
|
||||
throw new ExecutableNotFoundException($"No executable selected");
|
||||
@@ -170,7 +170,7 @@ namespace Daybreak.Services.ApplicationLauncher
|
||||
args.Add(character);
|
||||
}
|
||||
|
||||
var identity = this.configurationManager.GetConfiguration().ExperimentalFeatures.LaunchGuildwarsAsCurrentUser ?
|
||||
var identity = this.liveOptions.Value.ExperimentalFeatures.LaunchGuildwarsAsCurrentUser ?
|
||||
System.Security.Principal.WindowsIdentity.GetCurrent().Name :
|
||||
System.Security.Principal.WindowsIdentity.GetAnonymous().Name;
|
||||
this.logger.LogInformation($"Launching guildwars as [{identity}] identity");
|
||||
@@ -222,11 +222,11 @@ namespace Daybreak.Services.ApplicationLauncher
|
||||
|
||||
private bool GuildwarsProcessDetected()
|
||||
{
|
||||
if (this.configurationManager.GetConfiguration().ExperimentalFeatures.MultiLaunchSupport is true)
|
||||
if (this.liveOptions.Value.ExperimentalFeatures.MultiLaunchSupport is true)
|
||||
{
|
||||
try
|
||||
{
|
||||
var path = this.configurationManager.GetConfiguration().GuildwarsPaths.Where(path => path.Default).FirstOrDefault();
|
||||
var path = this.liveOptions.Value.GuildwarsPaths.Where(path => path.Default).FirstOrDefault();
|
||||
if (path is null)
|
||||
{
|
||||
return false;
|
||||
@@ -254,7 +254,7 @@ namespace Daybreak.Services.ApplicationLauncher
|
||||
|
||||
private void SetRegistryGuildwarsPath()
|
||||
{
|
||||
var path = this.configurationManager.GetConfiguration().GuildwarsPaths.Where(path => path.Default).FirstOrDefault();
|
||||
var path = this.liveOptions.Value.GuildwarsPaths.Where(path => path.Default).FirstOrDefault();
|
||||
if (path is null)
|
||||
{
|
||||
throw new ExecutableNotFoundException("No executable currently selected");
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Extensions;
|
||||
using IServiceProvider = Slim.IServiceProvider;
|
||||
|
||||
namespace Daybreak.Services.ApplicationLifetime
|
||||
{
|
||||
public sealed class ApplicationLifetimeManager : IApplicationLifetimeManager
|
||||
{
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private List<Type> RegisteredTypes { get; } = new List<Type>();
|
||||
|
||||
public ApplicationLifetimeManager(IServiceProvider serviceProvider)
|
||||
{
|
||||
serviceProvider.ThrowIfNull(nameof(serviceProvider));
|
||||
|
||||
this.serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public void RegisterService<T>() where T : IApplicationLifetimeService
|
||||
{
|
||||
this.RegisteredTypes.Add(typeof(T));
|
||||
}
|
||||
|
||||
public void OnStartup()
|
||||
{
|
||||
foreach (var serviceType in this.RegisteredTypes)
|
||||
{
|
||||
var service = this.serviceProvider.GetService(serviceType);
|
||||
service.As<IApplicationLifetimeService>().OnStartup();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClosing()
|
||||
{
|
||||
foreach (var serviceType in this.RegisteredTypes)
|
||||
{
|
||||
var service = this.serviceProvider.GetService(serviceType);
|
||||
service.As<IApplicationLifetimeService>().OnClosing();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Daybreak.Services.ApplicationLifetime
|
||||
{
|
||||
public interface IApplicationLifetimeManager : IApplicationLifetimeProducer
|
||||
{
|
||||
void OnStartup();
|
||||
void OnClosing();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Daybreak.Services.ApplicationLifetime
|
||||
{
|
||||
public interface IApplicationLifetimeProducer
|
||||
{
|
||||
void RegisterService<T>() where T : IApplicationLifetimeService;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Daybreak.Services.ApplicationLifetime
|
||||
{
|
||||
public interface IApplicationLifetimeService
|
||||
{
|
||||
void OnStartup();
|
||||
void OnClosing();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using Daybreak.Services.Bloogum.Models;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Extensions;
|
||||
using System.IO;
|
||||
@@ -12,15 +11,16 @@ namespace Daybreak.Services.Bloogum
|
||||
public sealed class BloogumClient : IBloogumClient
|
||||
{
|
||||
private const string BaseAddress = "http://bloogum.net/guildwars";
|
||||
private readonly HttpClient httpClient;
|
||||
private readonly IHttpClient<BloogumClient> httpClient;
|
||||
private readonly ILogger logger;
|
||||
private readonly Random random = new();
|
||||
|
||||
public BloogumClient(ILogger logger)
|
||||
public BloogumClient(
|
||||
ILogger<BloogumClient> logger,
|
||||
IHttpClient<BloogumClient> httpClient)
|
||||
{
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
|
||||
this.httpClient = new HttpClient();
|
||||
this.httpClient = httpClient.ThrowIfNull(nameof(httpClient));
|
||||
}
|
||||
|
||||
public async Task<Optional<Stream>> GetRandomScreenShot()
|
||||
@@ -53,7 +53,7 @@ namespace Daybreak.Services.Bloogum
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
this.logger.LogError(e);
|
||||
this.logger.LogError(e.ToString());
|
||||
return Optional.None<Stream>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,13 +81,13 @@ namespace Daybreak.Services.Bloogum.Models
|
||||
new Category("stingraystrand", 15),
|
||||
new Category("fishermenshaven", 4),
|
||||
new Category("riversideprovince", 31),
|
||||
new Category("sanctumcay", 21)
|
||||
new Category("sanctumcay", 21),
|
||||
new Category("majestysrest", 14)
|
||||
});
|
||||
public static readonly Location MaguumaJungle = new(
|
||||
"maguuma",
|
||||
new List<Category>
|
||||
{
|
||||
new Category("majestysrest", 14),
|
||||
new Category("druidsoverlook", 1),
|
||||
new Category("sagelands", 27),
|
||||
new Category("thewilds", 19),
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Daybreak.Models.Builds;
|
||||
using Daybreak.Services.BuildTemplates.Models;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Extensions;
|
||||
@@ -16,10 +15,10 @@ namespace Daybreak.Services.BuildTemplates
|
||||
private const string DecodingLookupTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
private readonly static string BuildsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Guild Wars\\Templates\\Skills";
|
||||
|
||||
private readonly ILogger logger;
|
||||
private readonly ILogger<BuildTemplateManager> logger;
|
||||
|
||||
public BuildTemplateManager(
|
||||
ILogger logger)
|
||||
ILogger<BuildTemplateManager> logger)
|
||||
{
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
}
|
||||
@@ -229,8 +228,10 @@ namespace Daybreak.Services.BuildTemplates
|
||||
{
|
||||
var curedTemplate = template.Trim();
|
||||
|
||||
var buildMetadata = new BuildMetadata();
|
||||
buildMetadata.Base64Decoded = template.Select(c => DecodingLookupTable.IndexOf(c)).ToList();
|
||||
var buildMetadata = new BuildMetadata
|
||||
{
|
||||
Base64Decoded = template.Select(c => DecodingLookupTable.IndexOf(c)).ToList(),
|
||||
};
|
||||
buildMetadata.BinaryDecoded = buildMetadata.Base64Decoded.Select(b => ToBitString(b)).ToList();
|
||||
|
||||
var stream = new DecodeCharStream(buildMetadata.BinaryDecoded.ToArray());
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Extensions;
|
||||
using System.IO;
|
||||
@@ -12,11 +12,11 @@ namespace Daybreak.Services.Configuration
|
||||
private const string ConfigName = "Daybreak.config.json";
|
||||
|
||||
private ApplicationConfiguration applicationConfiguration;
|
||||
private readonly ILogger logger;
|
||||
private readonly ILogger<ConfigurationManager> logger;
|
||||
|
||||
public event EventHandler ConfigurationChanged;
|
||||
|
||||
public ConfigurationManager(ILogger logger)
|
||||
public ConfigurationManager(ILogger<ConfigurationManager> logger)
|
||||
{
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
try
|
||||
@@ -26,7 +26,7 @@ namespace Daybreak.Services.Configuration
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
this.logger.LogWarning($"No configuration detected. Loading default configuration. Details: {e}");
|
||||
this.logger.LogWarning(e, $"Failed to load configuration. Falling back to default configuration");
|
||||
this.applicationConfiguration = new ApplicationConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.Configuration;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Utils;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Extensions;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
@@ -15,14 +15,14 @@ namespace Daybreak.Services.Credentials
|
||||
public sealed class CredentialManager : ICredentialManager
|
||||
{
|
||||
private static readonly byte[] Entropy = Convert.FromBase64String("R3VpbGR3YXJz");
|
||||
private readonly ILogger logger;
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
private readonly ILogger<CredentialManager> logger;
|
||||
private readonly ILiveUpdateableOptions<ApplicationConfiguration> liveOptions;
|
||||
|
||||
public CredentialManager(
|
||||
ILogger logger,
|
||||
IConfigurationManager configurationManager)
|
||||
ILogger<CredentialManager> logger,
|
||||
ILiveUpdateableOptions<ApplicationConfiguration> liveOptions)
|
||||
{
|
||||
this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager));
|
||||
this.liveOptions = liveOptions.ThrowIfNull(nameof(liveOptions));
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Daybreak.Services.Credentials
|
||||
return Task.Run(() =>
|
||||
{
|
||||
this.logger.LogInformation("Retrieving credentials");
|
||||
var config = this.configurationManager.GetConfiguration();
|
||||
var config = this.liveOptions.Value;
|
||||
if (config.ProtectedLoginCredentials is null || config.ProtectedLoginCredentials.Count == 0)
|
||||
{
|
||||
this.logger.LogInformation("No credentials found");
|
||||
@@ -63,9 +63,9 @@ namespace Daybreak.Services.Credentials
|
||||
|
||||
return config
|
||||
.ProtectedLoginCredentials
|
||||
.Select(UnprotectCredentials)
|
||||
.Where(CredentialsUnprotected)
|
||||
.Select(ExtractCredentials)
|
||||
.Select(this.UnprotectCredentials)
|
||||
.Where(this.CredentialsUnprotected)
|
||||
.Select(this.ExtractCredentials)
|
||||
.ToList();
|
||||
});
|
||||
}
|
||||
@@ -74,13 +74,12 @@ namespace Daybreak.Services.Credentials
|
||||
return Task.Run(() =>
|
||||
{
|
||||
this.logger.LogInformation("Storing credentials");
|
||||
var config = this.configurationManager.GetConfiguration();
|
||||
config.ProtectedLoginCredentials = loginCredentials
|
||||
.Select(ProtectCredentials)
|
||||
.Where(CredentialsProtected)
|
||||
.Select(ExtractProtectedCredentials)
|
||||
this.liveOptions.Value.ProtectedLoginCredentials = loginCredentials
|
||||
.Select(this.ProtectCredentials)
|
||||
.Where(this.CredentialsProtected)
|
||||
.Select(this.ExtractProtectedCredentials)
|
||||
.ToList();
|
||||
this.configurationManager.SaveConfiguration(config);
|
||||
this.liveOptions.UpdateOption();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using Daybreak.Models.Builds;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Utils;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Models.Builds;
|
||||
using HtmlAgilityPack;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Extensions;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -16,18 +17,48 @@ namespace Daybreak.Services.IconRetrieve
|
||||
private const string NamePlaceholder = "[SKILLNAME]";
|
||||
private const string BaseUrl = "https://wiki.guildwars.com";
|
||||
private const string QueryUrl = $"wiki/File:{NamePlaceholder}.jpg";
|
||||
private const string IconsDirectoryName = "Icons";
|
||||
private const string IconsLocation = $"{IconsDirectoryName}/{NamePlaceholder}.jpg";
|
||||
|
||||
private readonly HttpClient httpClient = new();
|
||||
private readonly ILogger logger;
|
||||
private readonly IHttpClient<IconRetriever> httpClient;
|
||||
private readonly ILogger<IconRetriever> logger;
|
||||
private readonly ILiveOptions<ApplicationConfiguration> liveOptions;
|
||||
|
||||
public IconRetriever(
|
||||
ILogger logger)
|
||||
ILogger<IconRetriever> logger,
|
||||
IHttpClient<IconRetriever> httpClient,
|
||||
ILiveOptions<ApplicationConfiguration> liveOptions)
|
||||
{
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
this.httpClient = httpClient.ThrowIfNull(nameof(httpClient));
|
||||
this.liveOptions = liveOptions.ThrowIfNull(nameof(liveOptions));
|
||||
this.httpClient.BaseAddress = new Uri(BaseUrl);
|
||||
if (Directory.Exists(IconsDirectoryName) is false)
|
||||
{
|
||||
Directory.CreateDirectory(IconsDirectoryName);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Optional<Stream>> GetIcon(Skill skill)
|
||||
{
|
||||
if (this.liveOptions.Value.KeepLocalIconCache)
|
||||
{
|
||||
this.logger.LogInformation($"{nameof(IconRetriever)} configured to look first in cache before downloading icons");
|
||||
var maybeIcon = await this.GetLocalIcon(skill);
|
||||
if (maybeIcon.ExtractValue() is Stream stream)
|
||||
{
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.logger.LogInformation($"{nameof(IconRetriever)} configured to skip local cache. Downloading icon");
|
||||
}
|
||||
|
||||
return await this.DownloadIcon(skill);
|
||||
}
|
||||
|
||||
private async Task<Optional<Stream>> DownloadIcon(Skill skill)
|
||||
{
|
||||
var curedSkillName = skill.Name
|
||||
.Replace(" ", "_");
|
||||
@@ -55,13 +86,43 @@ namespace Daybreak.Services.IconRetrieve
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
this.logger.LogInformation("Retrieved latest icon stream");
|
||||
return new MemoryStream(await iconResponse.Content.ReadAsByteArrayAsync());
|
||||
var iconData = await iconResponse.Content.ReadAsByteArrayAsync();
|
||||
if (this.liveOptions.Value.KeepLocalIconCache)
|
||||
{
|
||||
await SaveIconLocally(skill, iconData);
|
||||
}
|
||||
|
||||
return new MemoryStream(iconData);
|
||||
}
|
||||
|
||||
this.logger.LogError($"Failed to retrieve icon from {BaseUrl + "/" + url}");
|
||||
return Optional.None<Stream>();
|
||||
}
|
||||
|
||||
private async Task<Optional<Stream>> GetLocalIcon(Skill skill)
|
||||
{
|
||||
var curedSkillName = skill.Name
|
||||
.Replace(" ", "_")
|
||||
.Replace("\"", "");
|
||||
this.logger.LogInformation("Checking local icon cache");
|
||||
if (File.Exists(IconsLocation.Replace(NamePlaceholder, curedSkillName)))
|
||||
{
|
||||
this.logger.LogInformation("Local icon cache found. Retrieving icon");
|
||||
return new MemoryStream(await File.ReadAllBytesAsync(IconsLocation.Replace(NamePlaceholder, curedSkillName)));
|
||||
}
|
||||
|
||||
this.logger.LogWarning("No local icon cache found");
|
||||
return Optional.None<Stream>();
|
||||
}
|
||||
|
||||
private static async Task SaveIconLocally(Skill skill, byte[] data)
|
||||
{
|
||||
var curedSkillName = skill.Name
|
||||
.Replace(" ", "_")
|
||||
.Replace("\"", "");
|
||||
await File.WriteAllBytesAsync(IconsLocation.Replace(NamePlaceholder, curedSkillName), data);
|
||||
}
|
||||
|
||||
private static string GetHref(HtmlDocument doc)
|
||||
{
|
||||
foreach (var child in doc.DocumentNode.Descendants("a"))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.ApplicationLifetime;
|
||||
using System;
|
||||
using System.Windows.Extensions.Services;
|
||||
|
||||
namespace Daybreak.Services.KeyboardHook
|
||||
{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Pepa.Wpf.Utilities;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
@@ -15,7 +14,7 @@ namespace Daybreak.Services.KeyboardHook
|
||||
// https://stackoverflow.com/questions/604410/global-keyboard-capture-in-c-sharp-application
|
||||
public sealed class KeyboardHookService : IKeyboardHookService, IDisposable
|
||||
{
|
||||
private readonly ILogger logger;
|
||||
private readonly ILogger<KeyboardHookService> logger;
|
||||
private IntPtr windowsHookHandle;
|
||||
private IntPtr user32LibraryHandle;
|
||||
private NativeMethods.HookProc hookProc;
|
||||
@@ -23,7 +22,7 @@ namespace Daybreak.Services.KeyboardHook
|
||||
public event EventHandler<KeyboardHookEventArgs> KeyboardPressed;
|
||||
|
||||
public KeyboardHookService(
|
||||
ILogger logger)
|
||||
ILogger<KeyboardHookService> logger)
|
||||
{
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
this.Setup();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Daybreak.Services.ApplicationLifetime;
|
||||
using System.Windows.Extensions.Services;
|
||||
|
||||
namespace Daybreak.Services.KeyboardMacros
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.Configuration;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.KeyboardHook;
|
||||
using Daybreak.Services.Logging;
|
||||
using Pepa.Wpf.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Extensions;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -16,36 +16,24 @@ namespace Daybreak.Services.KeyboardMacros
|
||||
public sealed class MacroService : IMacroService
|
||||
{
|
||||
private readonly CancellationTokenSource cancellationTokenSource = new();
|
||||
private readonly ILogger logger;
|
||||
private readonly IKeyboardHookService keyboardHookService;
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
private readonly ILiveOptions<ApplicationConfiguration> liveOptions;
|
||||
private readonly HashSet<Keys> KeysDown = new();
|
||||
|
||||
private IEnumerable<KeyMacro> loadedMacros;
|
||||
private bool gameActive, hookEnabled;
|
||||
private bool gameActive;
|
||||
private IntPtr gwWindowHwnd;
|
||||
|
||||
public MacroService(
|
||||
ILogger logger,
|
||||
IKeyboardHookService keyboardHookService,
|
||||
IConfigurationManager configurationManager)
|
||||
ILiveOptions<ApplicationConfiguration> liveOptions)
|
||||
{
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
this.keyboardHookService = keyboardHookService.ThrowIfNull(nameof(keyboardHookService));
|
||||
this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager));
|
||||
this.liveOptions = liveOptions.ThrowIfNull(nameof(liveOptions));
|
||||
|
||||
this.configurationManager.ConfigurationChanged += (s, e) => this.LoadConfiguration();
|
||||
this.LoadConfiguration();
|
||||
this.keyboardHookService.KeyboardPressed += this.KeyboardHookService_KeyboardPressed;
|
||||
this.SetupGameActiveChecker();
|
||||
}
|
||||
|
||||
private void LoadConfiguration()
|
||||
{
|
||||
this.hookEnabled = this.configurationManager.GetConfiguration().ExperimentalFeatures.CanInterceptKeys;
|
||||
this.loadedMacros = this.configurationManager.GetConfiguration().ExperimentalFeatures.Macros ?? new List<KeyMacro>();
|
||||
}
|
||||
|
||||
private void SetupGameActiveChecker()
|
||||
{
|
||||
TaskExtensions.RunPeriodicAsync(() =>
|
||||
@@ -65,12 +53,12 @@ namespace Daybreak.Services.KeyboardMacros
|
||||
},
|
||||
TimeSpan.Zero,
|
||||
TimeSpan.FromMilliseconds(33),
|
||||
cancellationTokenSource.Token);
|
||||
this.cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
private void KeyboardHookService_KeyboardPressed(object sender, KeyboardHookEventArgs e)
|
||||
{
|
||||
if (this.gameActive && this.hookEnabled)
|
||||
if (this.gameActive && this.liveOptions.Value.ExperimentalFeatures.CanInterceptKeys)
|
||||
{
|
||||
if (e.KeyboardState == KeyboardState.KeyDown)
|
||||
{
|
||||
@@ -82,7 +70,7 @@ namespace Daybreak.Services.KeyboardMacros
|
||||
return;
|
||||
}
|
||||
|
||||
e.Handled = this.loadedMacros
|
||||
e.Handled = this.liveOptions.Value.ExperimentalFeatures.Macros
|
||||
.Where(keyMacro => MacroContainsKey(keyMacro, e.KeyboardInput.Key))
|
||||
.Where(this.MacroHit)
|
||||
.Do(this.HandleMacro)
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
using Daybreak.Exceptions;
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Extensions;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Daybreak.Services.Logging
|
||||
{
|
||||
public class FlatLoggingDatabase : ILoggingDatabase
|
||||
{
|
||||
private const string Path = "logs.db";
|
||||
private const int bufferSize = 10;
|
||||
private const char separator = '§';
|
||||
private readonly string filePath = Path;
|
||||
private readonly List<string> buffer = new List<string>();
|
||||
|
||||
public FlatLoggingDatabase()
|
||||
{
|
||||
}
|
||||
|
||||
public Task<IEnumerable<Log>> GetLogs()
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
lock (this.buffer)
|
||||
{
|
||||
if (this.buffer.Count > 0)
|
||||
{
|
||||
this.WriteBufferToFile();
|
||||
}
|
||||
}
|
||||
|
||||
return this.GetSerializedLogs().Select(s => s.Deserialize<Log>());
|
||||
});
|
||||
}
|
||||
|
||||
public Task<IEnumerable<Log>> GetLogsByDate(DateTime startTime, DateTime endTime)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
lock (this.buffer)
|
||||
{
|
||||
if (this.buffer.Count > 0)
|
||||
{
|
||||
this.WriteBufferToFile();
|
||||
}
|
||||
}
|
||||
|
||||
return this.GetSerializedLogs()
|
||||
.Select(s => s.Deserialize<Log>())
|
||||
.Where(l => l.Timestamp > startTime && l.Timestamp < endTime);
|
||||
});
|
||||
}
|
||||
|
||||
public Task<bool> InsertLog(Log log)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
lock (this.buffer)
|
||||
{
|
||||
this.buffer.Add(log.Serialize());
|
||||
|
||||
if (this.buffer.Count > bufferSize)
|
||||
{
|
||||
this.WriteBufferToFile();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public Task<bool> ClearDatabase()
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
lock (this.buffer)
|
||||
{
|
||||
this.buffer.Clear();
|
||||
}
|
||||
lock (this.filePath)
|
||||
{
|
||||
File.WriteAllText(this.filePath, string.Empty);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public void OnClosing()
|
||||
{
|
||||
this.WriteBufferToFile();
|
||||
}
|
||||
|
||||
public void OnStartup()
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
using var fs = File.Create(filePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new FatalException("Could not initialize logging. See inner exception for details.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteBufferToFile()
|
||||
{
|
||||
lock (this.filePath)
|
||||
{
|
||||
File.AppendAllLines(this.filePath, this.buffer.Select(s => s + separator), Encoding.UTF8);
|
||||
}
|
||||
this.buffer.Clear();
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetSerializedLogs()
|
||||
{
|
||||
lock (this.filePath)
|
||||
{
|
||||
var stringBuilder = new StringBuilder();
|
||||
using var fileStream = File.OpenRead(this.filePath);
|
||||
using var streamReader = new StreamReader(fileStream, Encoding.UTF8);
|
||||
string serializedLog = null;
|
||||
while ((serializedLog = streamReader.ReadUntil(separator.ToString())) != null
|
||||
&& serializedLog != string.Empty
|
||||
&& serializedLog != "\r"
|
||||
&& serializedLog != "\n"
|
||||
&& serializedLog != "\r\n")
|
||||
{
|
||||
yield return serializedLog;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using Daybreak.Models;
|
||||
using System;
|
||||
|
||||
namespace Daybreak.Services.Logging
|
||||
{
|
||||
public interface ILogger
|
||||
{
|
||||
void Log(LogLevel logLevel, Exception exception);
|
||||
void Log(LogLevel logLevel, string message);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.ApplicationLifetime;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Daybreak.Services.Logging
|
||||
{
|
||||
public interface ILoggingDatabase : IApplicationLifetimeService
|
||||
{
|
||||
Task<bool> ClearDatabase();
|
||||
Task<IEnumerable<Log>> GetLogsByDate(DateTime startTime, DateTime endTime);
|
||||
Task<IEnumerable<Log>> GetLogs();
|
||||
Task<bool> InsertLog(Log log);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Daybreak.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Logging;
|
||||
|
||||
namespace Daybreak.Services.Logging
|
||||
{
|
||||
public interface ILogsManager : ILogsWriter
|
||||
{
|
||||
IEnumerable<Models.Log> GetLogs(Expression<Func<Models.Log, bool>> filter);
|
||||
IEnumerable<Models.Log> GetLogs();
|
||||
int DeleteLogs();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using LiteDB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Extensions;
|
||||
using System.Linq.Expressions;
|
||||
using System.Logging;
|
||||
|
||||
namespace Daybreak.Services.Logging
|
||||
{
|
||||
public sealed class JsonLogsManager : ILogsManager
|
||||
{
|
||||
private readonly ILiteDatabase liteDatabase;
|
||||
|
||||
public JsonLogsManager(ILiteDatabase liteDatabase)
|
||||
{
|
||||
this.liteDatabase = liteDatabase.ThrowIfNull(nameof(liteDatabase));
|
||||
}
|
||||
|
||||
public IEnumerable<Models.Log> GetLogs(Expression<Func<Models.Log, bool>> filter)
|
||||
{
|
||||
return this.liteDatabase.GetCollection<Models.Log>().Find(filter);
|
||||
}
|
||||
public IEnumerable<Models.Log> GetLogs()
|
||||
{
|
||||
return this.liteDatabase.GetCollection<Models.Log>().FindAll();
|
||||
}
|
||||
public void WriteLog(Log log)
|
||||
{
|
||||
var dbLog = new Models.Log
|
||||
{
|
||||
EventId = log.EventId,
|
||||
Message = log.Exception is null ? log.Message : $"{log.Message}{Environment.NewLine}{log.Exception}",
|
||||
Category = log.Category,
|
||||
LogLevel = log.LogLevel,
|
||||
LogTime = log.LogTime,
|
||||
CorrelationVector = log.CorrelationVector
|
||||
};
|
||||
|
||||
this.liteDatabase.GetCollection<Models.Log>().Insert(dbLog);
|
||||
}
|
||||
public int DeleteLogs()
|
||||
{
|
||||
return this.liteDatabase.GetCollection<Models.Log>().DeleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
using Daybreak.Models;
|
||||
using System;
|
||||
|
||||
namespace Daybreak.Services.Logging
|
||||
{
|
||||
public class Logger : ILogger
|
||||
{
|
||||
private readonly ILoggingDatabase loggingDatabase;
|
||||
public Logger(ILoggingDatabase loggingDatabase)
|
||||
{
|
||||
this.loggingDatabase = loggingDatabase;
|
||||
}
|
||||
|
||||
public async void Log(LogLevel logLevel, Exception exception)
|
||||
{
|
||||
if (exception is null) throw new ArgumentNullException(nameof(exception));
|
||||
|
||||
await this.loggingDatabase.InsertLog(
|
||||
new Log
|
||||
{
|
||||
LogLevel = logLevel,
|
||||
Message = exception.Message,
|
||||
StackTrace = exception.StackTrace,
|
||||
Timestamp = DateTime.Now
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async void Log(LogLevel logLevel, string message)
|
||||
{
|
||||
if (message is null) throw new ArgumentNullException(nameof(message));
|
||||
|
||||
await this.loggingDatabase.InsertLog(
|
||||
new Log
|
||||
{
|
||||
LogLevel = logLevel,
|
||||
Message = message,
|
||||
StackTrace = Environment.StackTrace,
|
||||
Timestamp = DateTime.Now
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using Slim;
|
||||
using Daybreak.Models;
|
||||
using Microsoft.CorrelationVector;
|
||||
using Slim;
|
||||
using System;
|
||||
using System.Extensions;
|
||||
using System.Windows;
|
||||
@@ -53,9 +55,10 @@ namespace Daybreak.Services.ViewManagement
|
||||
|
||||
private void ShowViewInner(Type viewType, object dataContext)
|
||||
{
|
||||
var scopedManager = this.serviceManager.CreateScope();
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
var view = this.serviceManager.GetService(viewType).As<UserControl>();
|
||||
var view = scopedManager.GetService(viewType).As<UserControl>();
|
||||
this.container.Children.Clear();
|
||||
this.container.Children.Add(view);
|
||||
view.DataContext = dataContext;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Services.Configuration;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Extensions;
|
||||
|
||||
namespace Daybreak.Services.Options
|
||||
{
|
||||
public sealed class ApplicationConfigurationOptionsManager : IOptionsManager
|
||||
{
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
|
||||
public ApplicationConfigurationOptionsManager(IConfigurationManager configurationManager)
|
||||
{
|
||||
this.configurationManager = configurationManager;
|
||||
}
|
||||
|
||||
public T GetOptions<T>() where T : class
|
||||
{
|
||||
if (typeof(T) == typeof(ApplicationConfiguration))
|
||||
{
|
||||
return this.configurationManager.GetConfiguration().Cast<T>();
|
||||
}
|
||||
|
||||
throw new InvalidOperationException($"{nameof(ApplicationConfigurationOptionsManager)} cannot return options of type {typeof(T).Name}");
|
||||
}
|
||||
|
||||
public void UpdateOptions<T>(T value) where T : class
|
||||
{
|
||||
if (typeof(T) == typeof(ApplicationConfiguration))
|
||||
{
|
||||
this.configurationManager.SaveConfiguration(value.Cast<ApplicationConfiguration>());
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException($"{nameof(ApplicationConfigurationOptionsManager)} cannot save options of type {typeof(T).Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Daybreak.Utils;
|
||||
using Daybreak.Views;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Extensions;
|
||||
using System.Security.Principal;
|
||||
using System.Windows.Controls;
|
||||
@@ -14,11 +13,11 @@ namespace Daybreak.Services.Privilege
|
||||
public bool AdminPrivileges => new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
|
||||
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly ILogger logger;
|
||||
private readonly ILogger<PrivilegeManager> logger;
|
||||
|
||||
public PrivilegeManager(
|
||||
IViewManager viewManager,
|
||||
ILogger logger)
|
||||
ILogger<PrivilegeManager> logger)
|
||||
{
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace Daybreak.Services.Runtime
|
||||
{
|
||||
public interface IRuntimeStore
|
||||
{
|
||||
void StoreValue<T>(string name, T value);
|
||||
bool TryGetValue<T>(string name, out T value);
|
||||
T GetValue<T>(string name);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Extensions;
|
||||
|
||||
namespace Daybreak.Services.Runtime
|
||||
{
|
||||
public sealed class RuntimeStore : IRuntimeStore
|
||||
{
|
||||
private Dictionary<string, object> InnerStore { get; } = new Dictionary<string, object>();
|
||||
|
||||
public T GetValue<T>(string name)
|
||||
{
|
||||
if(this.InnerStore.TryGetValue(name, out var value))
|
||||
{
|
||||
return value.Cast<T>();
|
||||
}
|
||||
|
||||
throw new InvalidOperationException($"Could not find any value stored with name {name}");
|
||||
}
|
||||
public void StoreValue<T>(string name, T value)
|
||||
{
|
||||
this.InnerStore[name] = value;
|
||||
}
|
||||
public bool TryGetValue<T>(string name, out T value)
|
||||
{
|
||||
if (this.InnerStore.TryGetValue(name, out var valueObj))
|
||||
{
|
||||
value = valueObj.Cast<T>();
|
||||
return true;
|
||||
}
|
||||
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Pepa.Wpf.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -12,13 +11,13 @@ namespace Daybreak.Services.Screens
|
||||
{
|
||||
public sealed class ScreenManager : IScreenManager
|
||||
{
|
||||
private readonly ILogger logger;
|
||||
private readonly ILogger<ScreenManager> logger;
|
||||
|
||||
public IEnumerable<Screen> Screens { get; } = WpfScreenHelper.Screen.AllScreens
|
||||
.Select((screen, index) => new Screen { Id = index, Size = screen.Bounds });
|
||||
|
||||
public ScreenManager(
|
||||
ILogger logger)
|
||||
ILogger<ScreenManager> logger)
|
||||
{
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Daybreak.Services.ApplicationLifetime;
|
||||
using System.Extensions;
|
||||
using System.Extensions;
|
||||
using System.Windows.Extensions.Services;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Daybreak.Services.Screenshots
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Extensions;
|
||||
@@ -14,11 +13,11 @@ namespace Daybreak.Services.Screenshots
|
||||
{
|
||||
private const string ScreenshotsFolder = "Screenshots";
|
||||
|
||||
private readonly List<string> Screenshots = new List<string>();
|
||||
private readonly ILogger logger;
|
||||
private readonly List<string> Screenshots = new();
|
||||
private readonly ILogger<ScreenshotProvider> logger;
|
||||
private int innerCount = 0;
|
||||
|
||||
public ScreenshotProvider(ILogger logger)
|
||||
public ScreenshotProvider(ILogger<ScreenshotProvider> logger)
|
||||
{
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
if (Directory.Exists(ScreenshotsFolder) is false)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Daybreak.Services.ApplicationLifetime;
|
||||
using System.Windows.Extensions.Services;
|
||||
|
||||
namespace Daybreak.Services.Shortcuts
|
||||
{
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
using Daybreak.Services.Configuration;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Services.Configuration;
|
||||
using ShellLink;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.Extensions;
|
||||
using System.IO;
|
||||
|
||||
namespace Daybreak.Services.Shortcuts
|
||||
{
|
||||
//TODO: Fix dependency on IConfigurationManager
|
||||
public sealed class ShortcutManager : IShortcutManager
|
||||
{
|
||||
private const string ShortcutName = "Daybreak.lnk";
|
||||
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
private readonly ILiveOptions<ApplicationConfiguration> liveOptions;
|
||||
|
||||
public bool ShortcutEnabled {
|
||||
get => this.ShortcutExists();
|
||||
@@ -27,16 +31,19 @@ namespace Daybreak.Services.Shortcuts
|
||||
}
|
||||
}
|
||||
|
||||
public ShortcutManager(IConfigurationManager configurationManager)
|
||||
public ShortcutManager(
|
||||
IConfigurationManager configurationManager,
|
||||
ILiveOptions<ApplicationConfiguration> liveOptions)
|
||||
{
|
||||
this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager));
|
||||
this.liveOptions = liveOptions.ThrowIfNull(nameof(liveOptions));
|
||||
this.configurationManager.ConfigurationChanged += (_, _) => this.LoadConfiguration();
|
||||
this.LoadConfiguration();
|
||||
}
|
||||
|
||||
private void LoadConfiguration()
|
||||
{
|
||||
var shortcutEnabled = this.configurationManager.GetConfiguration().PlaceShortcut;
|
||||
var shortcutEnabled = this.liveOptions.Value.PlaceShortcut;
|
||||
if (shortcutEnabled && this.ShortcutEnabled is false)
|
||||
{
|
||||
this.ShortcutEnabled = true;
|
||||
@@ -49,7 +56,7 @@ namespace Daybreak.Services.Shortcuts
|
||||
|
||||
private bool ShortcutExists()
|
||||
{
|
||||
var shortcutFolder = this.configurationManager.GetConfiguration().ShortcutLocation;
|
||||
var shortcutFolder = this.liveOptions.Value.ShortcutLocation;
|
||||
var shortcutPath = $"{shortcutFolder}\\{ShortcutName}";
|
||||
if (File.Exists(shortcutPath))
|
||||
{
|
||||
@@ -73,7 +80,7 @@ namespace Daybreak.Services.Shortcuts
|
||||
return;
|
||||
}
|
||||
|
||||
var shortcutFolder = this.configurationManager.GetConfiguration().ShortcutLocation;
|
||||
var shortcutFolder = this.liveOptions.Value.ShortcutLocation;
|
||||
var shortcutPath = $"{shortcutFolder}\\{ShortcutName}";
|
||||
var currentExecutable = Process.GetCurrentProcess()?.MainModule?.FileName;
|
||||
var shortcut = Shortcut.CreateShortcut(currentExecutable);
|
||||
@@ -92,7 +99,7 @@ namespace Daybreak.Services.Shortcuts
|
||||
return;
|
||||
}
|
||||
|
||||
var shortcutFolder = this.configurationManager.GetConfiguration().ShortcutLocation;
|
||||
var shortcutFolder = this.liveOptions.Value.ShortcutLocation;
|
||||
var shortcutPath = $"{shortcutFolder}\\{ShortcutName}";
|
||||
File.Delete(shortcutPath);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
using Daybreak.Exceptions;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Exceptions;
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Models.Github;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Services.Runtime;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Daybreak.Utils;
|
||||
using Daybreak.Views;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.Extensions;
|
||||
using System.Http;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
@@ -25,7 +27,6 @@ namespace Daybreak.Services.Updater
|
||||
public sealed class ApplicationUpdater : IApplicationUpdater
|
||||
{
|
||||
private const string LaunchActionName = "Launch_Daybreak";
|
||||
private const string UpdateDesiredKey = "UpdateDesired";
|
||||
private const string ExecutionPolicyKey = "ExecutionPolicy";
|
||||
private const string UpdatedKey = "Updating";
|
||||
private const string RegistryKey = "Daybreak";
|
||||
@@ -43,7 +44,7 @@ namespace Daybreak.Services.Updater
|
||||
private const string Url = "https://github.com/AlexMacocian/Daybreak/releases/latest";
|
||||
private const string DownloadUrl = $"https://github.com/AlexMacocian/Daybreak/releases/download/{VersionTag}/Daybreak{VersionTag}.zip";
|
||||
private const string GetExecutionPolicyCommand = "Get-ExecutionPolicy -Scope CurrentUser";
|
||||
private const string SetExecutionPolicyCommand = $"Set-ExecutionPolicy {ExecutionPolicyTag} -Scope CurrentUser";
|
||||
private const string SetExecutionPolicyCommand = $"Set-ExecutionPolicy {ExecutionPolicyTag} -Scope CurrentUser -Force";
|
||||
private const string WaitCommand = $"Wait-Process -Id {ProcessIdTag}";
|
||||
private const string ExtractCommandTemplate = $"Expand-Archive -Path '{InputFileTag}' -DestinationPath '{OutputPathTag}' -Force";
|
||||
private const string PrepareScheduledAction = $"$action = New-ScheduledTaskAction -Execute {ExecutableNameTag} -WorkingDirectory {WorkingDirectoryTag}";
|
||||
@@ -56,21 +57,23 @@ namespace Daybreak.Services.Updater
|
||||
private const string RemovePs1 = $"Remove-item {ExtractAndRunPs1}";
|
||||
|
||||
private readonly CancellationTokenSource updateCancellationTokenSource = new();
|
||||
private readonly ILogger logger;
|
||||
private readonly ILogger<ApplicationUpdater> logger;
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly IRuntimeStore runtimeStore;
|
||||
private readonly HttpClient httpClient = new();
|
||||
private readonly ILiveOptions<ApplicationConfiguration> liveOptions;
|
||||
private readonly IHttpClient<ApplicationUpdater> httpClient;
|
||||
|
||||
public Version CurrentVersion { get; }
|
||||
|
||||
public ApplicationUpdater(
|
||||
ILogger logger,
|
||||
IRuntimeStore runtimeStore,
|
||||
IViewManager viewManager)
|
||||
ILogger<ApplicationUpdater> logger,
|
||||
ILiveOptions<ApplicationConfiguration> liveOptions,
|
||||
IViewManager viewManager,
|
||||
IHttpClient<ApplicationUpdater> httpClient)
|
||||
{
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
this.runtimeStore = runtimeStore.ThrowIfNull(nameof(runtimeStore));
|
||||
this.liveOptions = liveOptions.ThrowIfNull(nameof(liveOptions));
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
this.httpClient = httpClient.ThrowIfNull(nameof(httpClient));
|
||||
this.httpClient.DefaultRequestHeaders.Add("user-agent", "Daybreak Client");
|
||||
if (Version.TryParse(Assembly.GetExecutingAssembly().GetName().Version.ToString(), out var currentVersion))
|
||||
{
|
||||
@@ -173,7 +176,7 @@ namespace Daybreak.Services.Updater
|
||||
{
|
||||
System.Extensions.TaskExtensions.RunPeriodicAsync(async () =>
|
||||
{
|
||||
if (this.runtimeStore.TryGetValue<bool>(UpdateDesiredKey, out var desiringUpdate) && desiringUpdate is false)
|
||||
if (this.liveOptions.Value.AutoCheckUpdate is false)
|
||||
{
|
||||
this.updateCancellationTokenSource.Cancel();
|
||||
return;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Models.Versioning;
|
||||
using Daybreak.Services.ApplicationLifetime;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Extensions.Services;
|
||||
|
||||
namespace Daybreak.Services.Updater
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Daybreak
|
||||
}
|
||||
}
|
||||
private static int Iterations { get; } = 10000;
|
||||
private static RNGCryptoServiceProvider Rng { get; } = new RNGCryptoServiceProvider();
|
||||
private static RandomNumberGenerator Rng { get; } = RandomNumberGenerator.Create();
|
||||
|
||||
public static int BlockSize { get => Aes.BlockSize; }
|
||||
|
||||
@@ -31,29 +31,19 @@ namespace Daybreak
|
||||
var saltBytes = Generate128BitsOfRandomEntropy();
|
||||
var ivBytes = Generate128BitsOfRandomEntropy();
|
||||
|
||||
using (var password = new Rfc2898DeriveBytes(key, saltBytes, Iterations))
|
||||
{
|
||||
var keyBytes = password.GetBytes(Aes.KeySize / 8);
|
||||
using (var encryptor = Aes.CreateEncryptor(keyBytes, ivBytes))
|
||||
{
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(bytes, 0, bytes.Length);
|
||||
cryptoStream.FlushFinalBlock();
|
||||
// Create the final bytes as a concatenation of the random salt bytes, the random iv bytes and the cipher bytes.
|
||||
using (var encryptedMemoryStream = new MemoryStream((int)(saltBytes.Length + ivBytes.Length + memoryStream.Length)))
|
||||
{
|
||||
encryptedMemoryStream.Write(saltBytes, 0, saltBytes.Length);
|
||||
encryptedMemoryStream.Write(ivBytes, 0, ivBytes.Length);
|
||||
encryptedMemoryStream.Write(memoryStream.ToArray(), 0, (int)memoryStream.Length);
|
||||
return encryptedMemoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using var password = new Rfc2898DeriveBytes(key, saltBytes, Iterations);
|
||||
var keyBytes = password.GetBytes(Aes.KeySize / 8);
|
||||
using var encryptor = Aes.CreateEncryptor(keyBytes, ivBytes);
|
||||
using var memoryStream = new MemoryStream();
|
||||
using var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write);
|
||||
cryptoStream.Write(bytes, 0, bytes.Length);
|
||||
cryptoStream.FlushFinalBlock();
|
||||
// Create the final bytes as a concatenation of the random salt bytes, the random iv bytes and the cipher bytes.
|
||||
using var encryptedMemoryStream = new MemoryStream((int)(saltBytes.Length + ivBytes.Length + memoryStream.Length));
|
||||
encryptedMemoryStream.Write(saltBytes, 0, saltBytes.Length);
|
||||
encryptedMemoryStream.Write(ivBytes, 0, ivBytes.Length);
|
||||
encryptedMemoryStream.Write(memoryStream.ToArray(), 0, (int)memoryStream.Length);
|
||||
return encryptedMemoryStream.ToArray();
|
||||
}
|
||||
|
||||
public static byte[] DecryptBytes(this byte[] bytes, byte[] key)
|
||||
@@ -61,29 +51,20 @@ namespace Daybreak
|
||||
var saltBytes = new byte[Aes.BlockSize / 8];
|
||||
var ivBytes = new byte[Aes.BlockSize / 8];
|
||||
var cipherBytes = new byte[bytes.Length - Aes.BlockSize / 4];
|
||||
using (MemoryStream encryptedStream = new MemoryStream(bytes))
|
||||
{
|
||||
encryptedStream.Read(saltBytes, 0, saltBytes.Length);
|
||||
encryptedStream.Read(ivBytes, 0, ivBytes.Length);
|
||||
encryptedStream.Read(cipherBytes, 0, cipherBytes.Length);
|
||||
}
|
||||
|
||||
using (var password = new Rfc2898DeriveBytes(key, saltBytes, Iterations))
|
||||
{
|
||||
var keyBytes = password.GetBytes(Aes.KeySize / 8);
|
||||
using (var decryptor = Aes.CreateDecryptor(keyBytes, ivBytes))
|
||||
{
|
||||
using (var memoryStream = new MemoryStream(cipherBytes))
|
||||
{
|
||||
using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
|
||||
{
|
||||
var plainTextBytes = new byte[memoryStream.Length];
|
||||
var decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
|
||||
return plainTextBytes.Take(decryptedByteCount).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using var encryptedStream = new MemoryStream(bytes);
|
||||
encryptedStream.Read(saltBytes, 0, saltBytes.Length);
|
||||
encryptedStream.Read(ivBytes, 0, ivBytes.Length);
|
||||
encryptedStream.Read(cipherBytes, 0, cipherBytes.Length);
|
||||
|
||||
using var password = new Rfc2898DeriveBytes(key, saltBytes, Iterations);
|
||||
var keyBytes = password.GetBytes(Aes.KeySize / 8);
|
||||
using var decryptor = Aes.CreateDecryptor(keyBytes, ivBytes);
|
||||
using var memoryStream = new MemoryStream(cipherBytes);
|
||||
using var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
|
||||
var plainTextBytes = new byte[memoryStream.Length];
|
||||
var decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
|
||||
return plainTextBytes.Take(decryptedByteCount).ToArray();
|
||||
}
|
||||
|
||||
private static byte[] Generate128BitsOfRandomEntropy()
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.Logging;
|
||||
using System;
|
||||
|
||||
namespace Daybreak.Utils
|
||||
{
|
||||
public static class LoggingExtensions
|
||||
{
|
||||
public static void LogInformation(this ILogger logger, string message)
|
||||
{
|
||||
if (logger is null) throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
logger.Log(LogLevel.Information, message);
|
||||
}
|
||||
|
||||
public static void LogError(this ILogger logger, string message)
|
||||
{
|
||||
if (logger is null) throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
logger.Log(LogLevel.Error, message);
|
||||
}
|
||||
|
||||
public static void LogCritical(this ILogger logger, string message)
|
||||
{
|
||||
if (logger is null) throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
logger.Log(LogLevel.Critical, message);
|
||||
}
|
||||
|
||||
public static void LogWarning(this ILogger logger, string message)
|
||||
{
|
||||
if (logger is null) throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
logger.Log(LogLevel.Warning, message);
|
||||
}
|
||||
|
||||
public static void LogInformation(this ILogger logger, Exception e)
|
||||
{
|
||||
if (logger is null) throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
logger.Log(LogLevel.Information, e);
|
||||
}
|
||||
|
||||
public static void LogWarning(this ILogger logger, Exception e)
|
||||
{
|
||||
if (logger is null) throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
logger.Log(LogLevel.Warning, e);
|
||||
}
|
||||
|
||||
public static void LogError(this ILogger logger, Exception e)
|
||||
{
|
||||
if (logger is null) throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
logger.Log(LogLevel.Error, e);
|
||||
}
|
||||
|
||||
public static void LogCritical(this ILogger logger, Exception e)
|
||||
{
|
||||
if (logger is null) throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
logger.Log(LogLevel.Critical, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,9 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
|
||||
namespace Daybreak.Utils
|
||||
{
|
||||
public static class SerializationExtensions
|
||||
{
|
||||
public static string Serialize<T>(this T obj)
|
||||
{
|
||||
return JsonConvert.SerializeObject(obj);
|
||||
}
|
||||
|
||||
public static T Deserialize<T>(this string serializedObject)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(serializedObject);
|
||||
}
|
||||
|
||||
public static byte[] AsBytes(this string s)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(s);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Services.Privilege;
|
||||
using Daybreak.Services.Runtime;
|
||||
using Daybreak.Services.Updater;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Daybreak.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Configuration;
|
||||
using System.Extensions;
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
@@ -15,24 +15,22 @@ namespace Daybreak.Views
|
||||
/// </summary>
|
||||
public partial class AskUpdateView : UserControl
|
||||
{
|
||||
private const string UpdateDesiredKey = "UpdateDesired";
|
||||
|
||||
private readonly ILogger logger;
|
||||
private readonly ILogger<AskUpdateView> logger;
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly IRuntimeStore runtimeStore;
|
||||
private readonly ILiveUpdateableOptions<ApplicationConfiguration> liveOptions;
|
||||
private readonly IPrivilegeManager privilegeManager;
|
||||
private readonly IApplicationUpdater applicationUpdater;
|
||||
|
||||
public AskUpdateView(
|
||||
ILogger logger,
|
||||
ILogger<AskUpdateView> logger,
|
||||
IViewManager viewManager,
|
||||
IRuntimeStore runtimeStore,
|
||||
ILiveUpdateableOptions<ApplicationConfiguration> liveOptions,
|
||||
IPrivilegeManager privilegeManager,
|
||||
IApplicationUpdater applicationUpdater)
|
||||
{
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
this.runtimeStore = runtimeStore.ThrowIfNull(nameof(runtimeStore));
|
||||
this.liveOptions = liveOptions.ThrowIfNull(nameof(liveOptions));
|
||||
this.privilegeManager = privilegeManager.ThrowIfNull(nameof(privilegeManager));
|
||||
this.applicationUpdater = applicationUpdater.ThrowIfNull(nameof(applicationUpdater));
|
||||
this.InitializeComponent();
|
||||
@@ -52,14 +50,14 @@ namespace Daybreak.Views
|
||||
private void NoButton_Clicked(object sender, System.EventArgs e)
|
||||
{
|
||||
this.logger.LogInformation("User declined update");
|
||||
this.runtimeStore.StoreValue(UpdateDesiredKey, false);
|
||||
this.liveOptions.Value.AutoCheckUpdate = false;
|
||||
this.liveOptions.UpdateOption();
|
||||
this.viewManager.ShowView<MainView>();
|
||||
}
|
||||
|
||||
private async void YesButton_Clicked(object sender, System.EventArgs e)
|
||||
{
|
||||
this.logger.LogInformation("User accepted update");
|
||||
this.runtimeStore.StoreValue(UpdateDesiredKey, true);
|
||||
if (this.CheckIfAdmin() is false)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid Background="#A0202020">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
@@ -35,7 +36,17 @@
|
||||
<controls:SaveButton Foreground="White" Height="30" Width="30" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5"
|
||||
Clicked="SaveButton_Clicked" Grid.Column="2" IsEnabled="{Binding ElementName=_this, Path=SaveButtonEnabled, Mode=OneWay}"></controls:SaveButton>
|
||||
</Grid>
|
||||
<controls:BuildTemplate Grid.Row="1" DataContext="{Binding ElementName=_this, Path=CurrentBuild, Mode=OneWay}">
|
||||
<Grid Grid.Row="1" Margin="10, 0, 10, 0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"></ColumnDefinition>
|
||||
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="Code: " Foreground="White" Background="Transparent" FontSize="16"></TextBlock>
|
||||
<TextBox Grid.Column="1" Foreground="White" Background="Transparent" FontSize="16"
|
||||
Text="{Binding ElementName=_this, Path=CurrentBuildCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
|
||||
</Grid>
|
||||
<controls:BuildTemplate x:Name="BuildTemplate" Grid.Row="2" DataContext="{Binding ElementName=_this, Path=CurrentBuild, Mode=OneWay}"
|
||||
BuildChanged="BuildTemplate_BuildChanged">
|
||||
</controls:BuildTemplate>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
using Daybreak.Models.Builds;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Controls;
|
||||
using Daybreak.Models.Builds;
|
||||
using Daybreak.Services.BuildTemplates;
|
||||
using Daybreak.Services.IconRetrieve;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Extensions;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
@@ -17,47 +22,89 @@ namespace Daybreak.Views
|
||||
{
|
||||
private const string DisallowedChars = "\r\n\\/.";
|
||||
|
||||
public readonly static DependencyProperty CurrentBuildProperty =
|
||||
DependencyPropertyExtensions.Register<BuildTemplateView, BuildEntry>(nameof(CurrentBuild));
|
||||
public readonly static DependencyProperty SaveButtonEnabledProperty =
|
||||
DependencyPropertyExtensions.Register<BuildTemplateView, bool>(nameof(SaveButtonEnabled), new PropertyMetadata(false));
|
||||
private bool supressDecode = false;
|
||||
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly IBuildTemplateManager buildTemplateManager;
|
||||
private readonly ILogger<BuildTemplateView> logger;
|
||||
|
||||
public bool SaveButtonEnabled
|
||||
{
|
||||
get => this.GetTypedValue<bool>(SaveButtonEnabledProperty);
|
||||
set => this.SetValue(SaveButtonEnabledProperty, value);
|
||||
}
|
||||
|
||||
public BuildEntry CurrentBuild
|
||||
{
|
||||
get => this.GetTypedValue<BuildEntry>(CurrentBuildProperty);
|
||||
set => this.SetValue(CurrentBuildProperty, value);
|
||||
}
|
||||
[GenerateDependencyProperty(InitialValue = false)]
|
||||
private bool saveButtonEnabled;
|
||||
[GenerateDependencyProperty]
|
||||
private BuildEntry currentBuild;
|
||||
[GenerateDependencyProperty]
|
||||
private string currentBuildCode;
|
||||
|
||||
public BuildTemplateView(
|
||||
IViewManager viewManager,
|
||||
IBuildTemplateManager buildTemplateManager)
|
||||
IBuildTemplateManager buildTemplateManager,
|
||||
IIconRetriever iconRetriever,
|
||||
ILiveOptions<ApplicationConfiguration> liveOptions,
|
||||
ILogger<ChromiumBrowserWrapper> chromiumLogger,
|
||||
ILogger<BuildTemplateView> logger)
|
||||
{
|
||||
this.buildTemplateManager = buildTemplateManager.ThrowIfNull(nameof(buildTemplateManager));
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
this.InitializeComponent();
|
||||
this.BuildTemplate.InitializeTemplate(iconRetriever, liveOptions, buildTemplateManager, chromiumLogger);
|
||||
this.DataContextChanged += (sender, contextArgs) =>
|
||||
{
|
||||
if (contextArgs.NewValue is BuildEntry)
|
||||
{
|
||||
this.logger.LogInformation("Received data context. Setting current build");
|
||||
this.CurrentBuild = contextArgs.NewValue.As<BuildEntry>();
|
||||
this.CurrentBuildCode = this.buildTemplateManager.EncodeTemplate(this.CurrentBuild.Build);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnPropertyChanged(e);
|
||||
if (e.Property == CurrentBuildCodeProperty && this.supressDecode is false)
|
||||
{
|
||||
this.logger.LogInformation($"Attempting to decode provided template {this.CurrentBuildCode}");
|
||||
try
|
||||
{
|
||||
this.CurrentBuild = new BuildEntry
|
||||
{
|
||||
Name = this.CurrentBuild.Name,
|
||||
PreviousName = this.CurrentBuild.PreviousName,
|
||||
Build = this.buildTemplateManager.DecodeTemplate(this.CurrentBuildCode)
|
||||
};
|
||||
|
||||
this.logger.LogInformation($"Template {CurrentBuildCode} decoded");
|
||||
}
|
||||
catch
|
||||
{
|
||||
this.logger.LogWarning($"Failed to decode {this.CurrentBuildCode}. Reverting to default build");
|
||||
this.CurrentBuild = new BuildEntry
|
||||
{
|
||||
Name = this.CurrentBuild.Name,
|
||||
PreviousName = this.CurrentBuild.PreviousName,
|
||||
Build = new Build()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildTemplate_BuildChanged(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.supressDecode = true;
|
||||
this.CurrentBuildCode = this.buildTemplateManager.EncodeTemplate(this.CurrentBuild.Build);
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.supressDecode = false;
|
||||
}
|
||||
}
|
||||
private void BackButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
this.viewManager.ShowView<BuildsListView>();
|
||||
}
|
||||
|
||||
private void SaveButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
this.buildTemplateManager.SaveBuild(this.CurrentBuild);
|
||||
@@ -71,7 +118,6 @@ namespace Daybreak.Views
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(sender.As<TextBox>().Text))
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using Daybreak.Controls;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Controls;
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.Configuration;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Configuration;
|
||||
using System.Extensions;
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
@@ -17,15 +17,15 @@ namespace Daybreak.Views
|
||||
/// </summary>
|
||||
public partial class ExecutablesView : UserControl
|
||||
{
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
private readonly ILiveUpdateableOptions<ApplicationConfiguration> liveUpdateableOptions;
|
||||
private readonly IViewManager viewManager;
|
||||
public ObservableCollection<GuildwarsPath> Paths { get; } = new();
|
||||
|
||||
public ExecutablesView(
|
||||
IConfigurationManager configurationManager,
|
||||
ILiveUpdateableOptions<ApplicationConfiguration> liveUpdateableOptions,
|
||||
IViewManager viewManager)
|
||||
{
|
||||
this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager));
|
||||
this.liveUpdateableOptions = liveUpdateableOptions.ThrowIfNull(nameof(liveUpdateableOptions));
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
this.InitializeComponent();
|
||||
this.GetPaths();
|
||||
@@ -33,7 +33,7 @@ namespace Daybreak.Views
|
||||
|
||||
private void GetPaths()
|
||||
{
|
||||
this.Paths.AddRange(this.configurationManager.GetConfiguration().GuildwarsPaths);
|
||||
this.Paths.AddRange(this.liveUpdateableOptions.Value.GuildwarsPaths);
|
||||
}
|
||||
|
||||
private void BackButton_Clicked(object sender, EventArgs e)
|
||||
@@ -53,9 +53,8 @@ namespace Daybreak.Views
|
||||
|
||||
private void SaveButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
var config = this.configurationManager.GetConfiguration();
|
||||
config.GuildwarsPaths = this.Paths.ToList();
|
||||
this.configurationManager.SaveConfiguration(config);
|
||||
this.liveUpdateableOptions.Value.GuildwarsPaths = this.Paths.ToList();
|
||||
this.liveUpdateableOptions.UpdateOption();
|
||||
this.viewManager.ShowView<SettingsCategoryView>();
|
||||
}
|
||||
|
||||
@@ -81,6 +80,7 @@ namespace Daybreak.Views
|
||||
{
|
||||
path.Default = false;
|
||||
}
|
||||
|
||||
gwPath.Default = true;
|
||||
var view = CollectionViewSource.GetDefaultView(this.Paths);
|
||||
view.Refresh();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Daybreak.Services.Configuration;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Extensions;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
@@ -27,7 +28,7 @@ namespace Daybreak.Views
|
||||
DependencyPropertyExtensions.Register<ExperimentalSettingsView, bool>(nameof(MacrosEnabled));
|
||||
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
private readonly ILiveUpdateableOptions<ApplicationConfiguration> liveUpdateableOptions;
|
||||
|
||||
public bool LaunchAsCurrentUser
|
||||
{
|
||||
@@ -57,17 +58,17 @@ namespace Daybreak.Views
|
||||
|
||||
public ExperimentalSettingsView(
|
||||
IViewManager viewManager,
|
||||
IConfigurationManager configurationManager)
|
||||
ILiveUpdateableOptions<ApplicationConfiguration> liveUpdateableOptions)
|
||||
{
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager));
|
||||
this.liveUpdateableOptions = liveUpdateableOptions.ThrowIfNull(nameof(liveUpdateableOptions));
|
||||
this.InitializeComponent();
|
||||
this.LoadExperimentalSettings();
|
||||
}
|
||||
|
||||
private void LoadExperimentalSettings()
|
||||
{
|
||||
var config = this.configurationManager.GetConfiguration();
|
||||
var config = this.liveUpdateableOptions.Value;
|
||||
this.MultiLaunch = config.ExperimentalFeatures.MultiLaunchSupport;
|
||||
this.GWToolboxLaunchDelay = config.ExperimentalFeatures.ToolboxAutoLaunchDelay.ToString();
|
||||
this.DynamicBuildLoading = config.ExperimentalFeatures.DynamicBuildLoading;
|
||||
@@ -77,7 +78,7 @@ namespace Daybreak.Views
|
||||
|
||||
private void SaveExperimentalSettings()
|
||||
{
|
||||
var config = this.configurationManager.GetConfiguration();
|
||||
var config = this.liveUpdateableOptions.Value;
|
||||
config.ExperimentalFeatures.MultiLaunchSupport = this.MultiLaunch;
|
||||
config.ExperimentalFeatures.DynamicBuildLoading = this.DynamicBuildLoading;
|
||||
config.ExperimentalFeatures.LaunchGuildwarsAsCurrentUser = this.LaunchAsCurrentUser;
|
||||
@@ -87,7 +88,7 @@ namespace Daybreak.Views
|
||||
config.ExperimentalFeatures.ToolboxAutoLaunchDelay = gwToolboxLaunchDelay;
|
||||
}
|
||||
|
||||
this.configurationManager.SaveConfiguration(config);
|
||||
this.liveUpdateableOptions.UpdateOption();
|
||||
}
|
||||
|
||||
private void SaveButton_Clicked(object sender, EventArgs e)
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<UserControl x:Class="Daybreak.Views.LogsView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Daybreak.Views"
|
||||
xmlns:controls="clr-namespace:Daybreak.Controls"
|
||||
mc:Ignorable="d"
|
||||
x:Name="_this"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
<Style TargetType="{x:Type TextBlock}" x:Key="WrapText">
|
||||
<Setter Property="TextWrapping" Value="Wrap"/>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Grid Background="#A0202020">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<controls:BackButton Foreground="White" Height="30" Width="30" HorizontalAlignment="Left" Margin="5"
|
||||
Clicked="BackButton_Clicked"></controls:BackButton>
|
||||
<controls:BinButton Foreground="White" Height="30" Width="30" HorizontalAlignment="Right" Margin="5"
|
||||
Clicked="BinButton_Clicked"></controls:BinButton>
|
||||
<controls:RefreshGlyph Foreground="White" Height="30" Width="30" HorizontalAlignment="Right" Margin="0, 5, 45, 5"
|
||||
Clicked="RefreshGlyph_Clicked"></controls:RefreshGlyph>
|
||||
<controls:BackButton Foreground="White" Height="30" Width="30" HorizontalAlignment="Right" Margin="0, 5, 85, 5"
|
||||
Clicked="ExportButton_Clicked">
|
||||
<controls:BackButton.RenderTransform>
|
||||
<RotateTransform Angle="270" CenterX="15" CenterY="15"></RotateTransform>
|
||||
</controls:BackButton.RenderTransform>
|
||||
</controls:BackButton>
|
||||
<DataGrid IsReadOnly="True" Background="Transparent" Foreground="White" Grid.Row="1"
|
||||
ItemsSource="{Binding ElementName=_this, Path=Logs, Mode=OneWay}" HorizontalScrollBarVisibility="Disabled"
|
||||
AutoGenerateColumns="False" HeadersVisibility="Column" EnableColumnVirtualization="True"
|
||||
EnableRowVirtualization="True">
|
||||
<DataGrid.ColumnHeaderStyle>
|
||||
<Style TargetType="{x:Type DataGridColumnHeader}">
|
||||
<Setter Property="Foreground" Value="White"></Setter>
|
||||
<Setter Property="Background" Value="Transparent"></Setter>
|
||||
<Setter Property="BorderBrush" Value="#80808080"></Setter>
|
||||
<Setter Property="BorderThickness" Value="1"></Setter>
|
||||
</Style>
|
||||
</DataGrid.ColumnHeaderStyle>
|
||||
<DataGrid.CellStyle>
|
||||
<Style TargetType="{x:Type DataGridCell}">
|
||||
<Setter Property="BorderBrush" Value="#80808080"></Setter>
|
||||
<Setter Property="BorderThickness" Value="1"></Setter>
|
||||
</Style>
|
||||
</DataGrid.CellStyle>
|
||||
<DataGrid.RowStyle>
|
||||
<Style TargetType="{x:Type DataGridRow}">
|
||||
<Setter Property="Background" Value="Transparent"></Setter>
|
||||
<Setter Property="Foreground" Value="White"></Setter>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn IsReadOnly="True" Header="DateTime" Binding="{Binding LogTime}" ElementStyle="{StaticResource WrapText}" Width="auto"/>
|
||||
<DataGridTextColumn IsReadOnly="True" Header="CV" Binding="{Binding CorrelationVector}" ElementStyle="{StaticResource WrapText}" Width="auto"/>
|
||||
<DataGridTextColumn IsReadOnly="True" Header="Category" Binding="{Binding Category}" ElementStyle="{StaticResource WrapText}" Width="auto"/>
|
||||
<DataGridTextColumn IsReadOnly="True" Header="LogLevel" Binding="{Binding LogLevel}" ElementStyle="{StaticResource WrapText}" Width="auto"/>
|
||||
<DataGridTextColumn IsReadOnly="True" Header="EventId" Binding="{Binding EventId}" ElementStyle="{StaticResource WrapText}" Width="auto"/>
|
||||
<DataGridTemplateColumn IsReadOnly="True" Header="Message" Width="*">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<controls:LogMessageTemplate Message="{Binding Message}" Foreground="White"></controls:LogMessageTemplate>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,79 @@
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Daybreak.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Extensions;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Daybreak.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LogsView.xaml
|
||||
/// </summary>
|
||||
public partial class LogsView : UserControl
|
||||
{
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly ILogsManager logManager;
|
||||
private readonly ILogger<LogsView> logger;
|
||||
|
||||
public ObservableCollection<Log> Logs { get; } = new ObservableCollection<Log>();
|
||||
|
||||
public LogsView(
|
||||
IViewManager viewManager,
|
||||
ILogsManager logManager,
|
||||
ILogger<LogsView> logger)
|
||||
{
|
||||
this.logManager = logManager.ThrowIfNull(nameof(logManager));
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
this.InitializeComponent();
|
||||
this.UpdateLogs();
|
||||
}
|
||||
|
||||
private void UpdateLogs()
|
||||
{
|
||||
this.Logs.ClearAnd().AddRange(this.logManager.GetLogs(l => l.LogLevel < Microsoft.Extensions.Logging.LogLevel.Trace));
|
||||
}
|
||||
private async void ExportButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
this.logger.LogInformation("Exporting logs");
|
||||
var saveFileDialog = new SaveFileDialog
|
||||
{
|
||||
DefaultExt = "json",
|
||||
Filter = "Json files (*.json)|*.json",
|
||||
Title = "Export logs",
|
||||
ValidateNames = true,
|
||||
CreatePrompt = true
|
||||
};
|
||||
if (saveFileDialog.ShowDialog() is true)
|
||||
{
|
||||
var fileName = saveFileDialog.FileName;
|
||||
this.logger.LogInformation($"Exporting to {fileName}");
|
||||
await File.WriteAllTextAsync(fileName, this.logManager.GetLogs().ToList().Serialize());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.logger.LogInformation("Exporting canceled");
|
||||
}
|
||||
}
|
||||
private void BackButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
this.viewManager.ShowView<SettingsCategoryView>();
|
||||
}
|
||||
private void BinButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
this.logManager.DeleteLogs();
|
||||
this.UpdateLogs();
|
||||
}
|
||||
private void RefreshGlyph_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
this.UpdateLogs();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,8 @@
|
||||
Clicked="LaunchTexmodButton_Clicked" Grid.Row="1" Grid.ColumnSpan="2" Grid.Column="1"
|
||||
Visibility="{Binding ElementName=_this, Path=ButtonsVisible, Mode=OneWay, Converter={StaticResource BooleanToVisibility}}"></controls:OpaqueButton>
|
||||
<Grid Grid.Column="2" Margin="10" Visibility="{Binding ElementName=_this, Path=BrowsersEnabled, Mode=OneWay, Converter={StaticResource BooleanToVisibility}}">
|
||||
<controls:ChromiumBrowserWrapper Address="{Binding ElementName=_this, Path=RightBrowserAddress, Mode=OneWay}"
|
||||
<controls:ChromiumBrowserWrapper x:Name="RightWebBrowser"
|
||||
Address="{Binding ElementName=_this, Path=RightBrowserAddress, Mode=OneWay}"
|
||||
Foreground="White" FavoriteUriChanged="RightBrowser_FavoriteUriChanged"
|
||||
FavoriteAddress="{Binding ElementName=_this, Path=RightBrowserFavoriteAddress, Mode=OneWay}"
|
||||
MaximizeClicked="RightChromiumBrowserWrapper_MaximizeClicked"
|
||||
@@ -48,7 +49,8 @@
|
||||
CanDownloadBuild="True"/>
|
||||
</Grid>
|
||||
<Grid Grid.Column="0" Margin="10" Visibility="{Binding ElementName=_this, Path=BrowsersEnabled, Mode=OneWay, Converter={StaticResource BooleanToVisibility}}">
|
||||
<controls:ChromiumBrowserWrapper Address="{Binding ElementName=_this, Path=LeftBrowserAddress, Mode=OneWay}"
|
||||
<controls:ChromiumBrowserWrapper x:Name="LeftWebBrowser"
|
||||
Address="{Binding ElementName=_this, Path=LeftBrowserAddress, Mode=OneWay}"
|
||||
Foreground="White" FavoriteUriChanged="LeftBrowser_FavoriteUriChanged"
|
||||
FavoriteAddress="{Binding ElementName=_this, Path=LeftBrowserFavoriteAddress, Mode=OneWay}"
|
||||
MaximizeClicked="LeftChromiumBrowserWrapper_MaximizeClicked"
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
using Daybreak.Exceptions;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Controls;
|
||||
using Daybreak.Exceptions;
|
||||
using Daybreak.Models.Builds;
|
||||
using Daybreak.Services.ApplicationLauncher;
|
||||
using Daybreak.Services.Configuration;
|
||||
using Daybreak.Services.BuildTemplates;
|
||||
using Daybreak.Services.Screens;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Extensions;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -24,8 +28,10 @@ namespace Daybreak.Views
|
||||
{
|
||||
private readonly IApplicationLauncher applicationDetector;
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
private readonly ILiveUpdateableOptions<ApplicationConfiguration> liveOptions;
|
||||
private readonly IScreenManager screenManager;
|
||||
private readonly IBuildTemplateManager buildTemplateManager;
|
||||
private readonly ILogger<ChromiumBrowserWrapper> browserLogger;
|
||||
private readonly CancellationTokenSource cancellationTokenSource = new();
|
||||
|
||||
private bool leftBrowserMaximized = false;
|
||||
@@ -53,21 +59,32 @@ namespace Daybreak.Views
|
||||
public MainView(
|
||||
IApplicationLauncher applicationDetector,
|
||||
IViewManager viewManager,
|
||||
IConfigurationManager configurationManager,
|
||||
IScreenManager screenManager)
|
||||
ILiveUpdateableOptions<ApplicationConfiguration> liveOptions,
|
||||
IScreenManager screenManager,
|
||||
IBuildTemplateManager buildTemplateManager,
|
||||
ILogger<ChromiumBrowserWrapper> browserLogger)
|
||||
{
|
||||
this.browserLogger = browserLogger;
|
||||
this.buildTemplateManager = buildTemplateManager.ThrowIfNull(nameof(buildTemplateManager));
|
||||
this.screenManager = screenManager.ThrowIfNull(nameof(screenManager));
|
||||
this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager));
|
||||
this.liveOptions = liveOptions.ThrowIfNull(nameof(liveOptions));
|
||||
this.applicationDetector = applicationDetector.ThrowIfNull(nameof(applicationDetector));
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
this.InitializeComponent();
|
||||
this.PeriodicallyCheckGameState();
|
||||
this.InitializeBrowsers();
|
||||
this.NavigateToDefaults();
|
||||
}
|
||||
|
||||
private void InitializeBrowsers()
|
||||
{
|
||||
this.LeftWebBrowser.InitializeBrowser(this.liveOptions, this.buildTemplateManager, this.browserLogger);
|
||||
this.RightWebBrowser.InitializeBrowser(this.liveOptions, this.buildTemplateManager, this.browserLogger);
|
||||
}
|
||||
|
||||
private void NavigateToDefaults()
|
||||
{
|
||||
var applicationConfiguration = this.configurationManager.GetConfiguration();
|
||||
var applicationConfiguration = this.liveOptions.Value;
|
||||
if (applicationConfiguration.BrowsersEnabled)
|
||||
{
|
||||
this.LeftBrowserFavoriteAddress = applicationConfiguration.LeftBrowserDefault;
|
||||
@@ -111,21 +128,22 @@ namespace Daybreak.Views
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.configurationManager.GetConfiguration().SetGuildwarsWindowSizeOnLaunch)
|
||||
if (this.liveOptions.Value.SetGuildwarsWindowSizeOnLaunch)
|
||||
{
|
||||
var id = this.configurationManager.GetConfiguration().DesiredGuildwarsScreen;
|
||||
var id = this.liveOptions.Value.DesiredGuildwarsScreen;
|
||||
var desiredScreen = this.screenManager.Screens.Skip(id).FirstOrDefault();
|
||||
if (desiredScreen is null)
|
||||
{
|
||||
throw new InvalidOperationException($"Unable to set guildwars on desired screen. No screen with id {id}");
|
||||
}
|
||||
|
||||
await Task.Delay(1000);
|
||||
this.screenManager.MoveGuildwarsToScreen(desiredScreen);
|
||||
}
|
||||
|
||||
if (this.configurationManager.GetConfiguration().ToolboxAutoLaunch is true)
|
||||
if (this.liveOptions.Value.ToolboxAutoLaunch is true)
|
||||
{
|
||||
var delay = this.configurationManager.GetConfiguration().ExperimentalFeatures.ToolboxAutoLaunchDelay;
|
||||
var delay = this.liveOptions.Value.ExperimentalFeatures.ToolboxAutoLaunchDelay;
|
||||
await Task.Delay(delay);
|
||||
await this.applicationDetector.LaunchGuildwarsToolbox();
|
||||
}
|
||||
@@ -164,23 +182,23 @@ namespace Daybreak.Views
|
||||
}
|
||||
}
|
||||
|
||||
private void ChromiumBrowserWrapper_BuildDecoded(object sender, Models.Builds.Build e)
|
||||
private void ChromiumBrowserWrapper_BuildDecoded(object sender, Build e)
|
||||
{
|
||||
this.viewManager.ShowView<BuildTemplateView>(new BuildEntry { Build = e, Name = string.Empty });
|
||||
}
|
||||
|
||||
private void LeftBrowser_FavoriteUriChanged(object sender, string e)
|
||||
{
|
||||
var config = this.configurationManager.GetConfiguration();
|
||||
var config = this.liveOptions.Value;
|
||||
config.LeftBrowserDefault = e;
|
||||
this.configurationManager.SaveConfiguration(config);
|
||||
this.liveOptions.UpdateOption();
|
||||
}
|
||||
|
||||
private void RightBrowser_FavoriteUriChanged(object sender, string e)
|
||||
{
|
||||
var config = this.configurationManager.GetConfiguration();
|
||||
var config = this.liveOptions.Value;
|
||||
config.RightBrowserDefault = e;
|
||||
this.configurationManager.SaveConfiguration(config);
|
||||
this.liveOptions.UpdateOption();
|
||||
}
|
||||
|
||||
private void LeftChromiumBrowserWrapper_MaximizeClicked(object sender, EventArgs e)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.ApplicationLauncher;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Daybreak.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Extensions;
|
||||
using System.Windows.Controls;
|
||||
|
||||
@@ -15,12 +14,12 @@ namespace Daybreak.Views
|
||||
{
|
||||
private readonly IApplicationLauncher applicationLauncher;
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly ILogger logger;
|
||||
private readonly ILogger<RequestElevationView> logger;
|
||||
|
||||
public RequestElevationView(
|
||||
IApplicationLauncher applicationLauncher,
|
||||
IViewManager viewManager,
|
||||
ILogger logger)
|
||||
ILogger<RequestElevationView> logger)
|
||||
{
|
||||
this.applicationLauncher = applicationLauncher.ThrowIfNull(nameof(applicationLauncher));
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using Daybreak.Controls.Templates;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Controls.Templates;
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.ApplicationLauncher;
|
||||
using Daybreak.Services.Configuration;
|
||||
using Daybreak.Services.Screens;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Extensions;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Extensions;
|
||||
using System.Windows.Media;
|
||||
@@ -23,7 +23,7 @@ namespace Daybreak.Views
|
||||
{
|
||||
private readonly IScreenManager screenManager;
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
private readonly ILiveOptions<ApplicationConfiguration> liveOptions;
|
||||
private readonly IApplicationLauncher applicationLauncher;
|
||||
private int selectedId;
|
||||
|
||||
@@ -33,15 +33,15 @@ namespace Daybreak.Views
|
||||
public ScreenChoiceView(
|
||||
IViewManager viewManager,
|
||||
IScreenManager screenManager,
|
||||
IConfigurationManager configurationManager,
|
||||
ILiveOptions<ApplicationConfiguration> liveOptions,
|
||||
IApplicationLauncher applicationLauncher)
|
||||
{
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
this.screenManager = screenManager.ThrowIfNull(nameof(screenManager));
|
||||
this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager));
|
||||
this.liveOptions = liveOptions.ThrowIfNull(nameof(liveOptions));
|
||||
this.applicationLauncher = applicationLauncher.ThrowIfNull(nameof(applicationLauncher));
|
||||
this.InitializeComponent();
|
||||
this.selectedId = configurationManager.GetConfiguration().DesiredGuildwarsScreen;
|
||||
this.selectedId = this.liveOptions.Value.DesiredGuildwarsScreen;
|
||||
this.CanTest = applicationLauncher.IsGuildwarsRunning;
|
||||
this.SetupView();
|
||||
}
|
||||
@@ -59,8 +59,8 @@ namespace Daybreak.Views
|
||||
VerticalAlignment = System.Windows.VerticalAlignment.Top,
|
||||
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
|
||||
Foreground = screen.Id == this.selectedId ? Brushes.LightGreen : Brushes.White
|
||||
};
|
||||
screenTemplate.Clicked += ScreenTemplate_Clicked;
|
||||
};
|
||||
screenTemplate.Clicked += this.ScreenTemplate_Clicked;
|
||||
this.ScreenContainer.Children.Add(screenTemplate);
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ namespace Daybreak.Views
|
||||
|
||||
private void SaveButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
this.configurationManager.GetConfiguration().DesiredGuildwarsScreen = this.selectedId;
|
||||
this.liveOptions.Value.DesiredGuildwarsScreen = this.selectedId;
|
||||
this.viewManager.ShowView<SettingsCategoryView>();
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,12 @@
|
||||
<controls:StaticGlyph></controls:StaticGlyph>
|
||||
</controls:TileButton.InnerContent>
|
||||
</controls:TileButton>
|
||||
<controls:TileButton Title="Logs" Foreground="White" BorderBrush="White" BorderThickness="2"
|
||||
HighlightColor="White" Clicked="LogsButton_Clicked" Height="150" Width="150">
|
||||
<controls:TileButton.InnerContent>
|
||||
<controls:LogsGlyph></controls:LogsGlyph>
|
||||
</controls:TileButton.InnerContent>
|
||||
</controls:TileButton>
|
||||
</WrapPanel>
|
||||
</WrapPanel>
|
||||
</Grid>
|
||||
|
||||
@@ -43,6 +43,11 @@ namespace Daybreak.Views
|
||||
this.viewManager.ShowView<VersionManagementView>(this);
|
||||
}
|
||||
|
||||
private void LogsButton_Clicked(object sender, System.EventArgs e)
|
||||
{
|
||||
this.viewManager.ShowView<LogsView>();
|
||||
}
|
||||
|
||||
private void FileButton_Clicked(object sender, System.EventArgs e)
|
||||
{
|
||||
this.viewManager.ShowView<ExecutablesView>();
|
||||
|
||||
@@ -94,6 +94,7 @@
|
||||
<TextBlock Text="Desired screen id: " FontSize="22" Foreground="White" Height="30"></TextBlock>
|
||||
<TextBlock Text="Place Shortcut: " FontSize="22" Foreground="White" Height="30"></TextBlock>
|
||||
<TextBlock Text="Shortcut folder: " FontSize="22" Foreground="White" Height="30"></TextBlock>
|
||||
<TextBlock Text="Keep local cache of icons: " FontSize="22" Foreground="White" Height="30"></TextBlock>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Vertical" Grid.Row="1" Grid.Column="1">
|
||||
<ToggleButton HorizontalAlignment="Center" HorizontalContentAlignment="Stretch" Style="{StaticResource AnimatedSwitch}" Height="30" Width="40"
|
||||
@@ -148,6 +149,8 @@
|
||||
Foreground="White" BorderBrush="Gray" BorderThickness="0"
|
||||
Clicked="ShortcutFolderPickerGlyph_Clicked"></controls:FilePickerGlyph>
|
||||
</Grid>
|
||||
<ToggleButton HorizontalAlignment="Center" HorizontalContentAlignment="Stretch" Style="{StaticResource AnimatedSwitch}" Height="30" Width="40"
|
||||
FontSize="22" Foreground="White" IsChecked="{Binding ElementName=_this, Path=KeepLocalIconCache, Mode=TwoWay}"></ToggleButton>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
using Daybreak.Services.Configuration;
|
||||
using Daybreak.Services.Shortcuts;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Extensions;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Extensions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
@@ -18,7 +15,7 @@ namespace Daybreak.Views
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0052:Remove unread private members", Justification = "Used by source generators")]
|
||||
public partial class SettingsView : System.Windows.Controls.UserControl
|
||||
{
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
private readonly ILiveUpdateableOptions<ApplicationConfiguration> liveUpdateableOptions;
|
||||
private readonly IViewManager viewManager;
|
||||
|
||||
[GenerateDependencyProperty]
|
||||
@@ -45,12 +42,14 @@ namespace Daybreak.Views
|
||||
private bool shortcutPlaced;
|
||||
[GenerateDependencyProperty]
|
||||
private bool autoCheckUpdate;
|
||||
[GenerateDependencyProperty]
|
||||
private bool keepLocalIconCache;
|
||||
|
||||
public SettingsView(
|
||||
IConfigurationManager configurationManager,
|
||||
ILiveUpdateableOptions<ApplicationConfiguration> liveUpdateableOptions,
|
||||
IViewManager viewManager)
|
||||
{
|
||||
this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager));
|
||||
this.liveUpdateableOptions = liveUpdateableOptions.ThrowIfNull(nameof(liveUpdateableOptions));
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
this.InitializeComponent();
|
||||
this.LoadSettings();
|
||||
@@ -58,7 +57,7 @@ namespace Daybreak.Views
|
||||
|
||||
private void LoadSettings()
|
||||
{
|
||||
var config = this.configurationManager.GetConfiguration();
|
||||
var config = this.liveUpdateableOptions.Value;
|
||||
this.AddressBarReadonly = config.AddressBarReadonly;
|
||||
this.ToolboxPath = config.ToolboxPath;
|
||||
this.LeftBrowserUrl = config.LeftBrowserDefault;
|
||||
@@ -71,11 +70,12 @@ namespace Daybreak.Views
|
||||
this.ShortcutFolder = config.ShortcutLocation;
|
||||
this.ShortcutPlaced = config.PlaceShortcut;
|
||||
this.AutoCheckUpdate = config.AutoCheckUpdate;
|
||||
this.KeepLocalIconCache = config.KeepLocalIconCache;
|
||||
}
|
||||
|
||||
private void SaveButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
var currentConfig = this.configurationManager.GetConfiguration();
|
||||
var currentConfig = this.liveUpdateableOptions.Value;
|
||||
currentConfig.ToolboxPath = this.ToolboxPath;
|
||||
currentConfig.AddressBarReadonly = this.AddressBarReadonly;
|
||||
currentConfig.LeftBrowserDefault = this.LeftBrowserUrl;
|
||||
@@ -88,7 +88,8 @@ namespace Daybreak.Views
|
||||
currentConfig.ShortcutLocation = this.ShortcutFolder;
|
||||
currentConfig.PlaceShortcut = this.ShortcutPlaced;
|
||||
currentConfig.AutoCheckUpdate = this.AutoCheckUpdate;
|
||||
this.configurationManager.SaveConfiguration(currentConfig);
|
||||
currentConfig.KeepLocalIconCache = this.KeepLocalIconCache;
|
||||
this.liveUpdateableOptions.UpdateOption();
|
||||
this.viewManager.ShowView<SettingsCategoryView>();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.Logging;
|
||||
using Daybreak.Services.Updater;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Daybreak.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -18,7 +17,7 @@ namespace Daybreak.Views
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0052:Remove unread private members", Justification = "Used by source generators")]
|
||||
public partial class UpdateView : UserControl
|
||||
{
|
||||
private readonly ILogger logger;
|
||||
private readonly ILogger<UpdateView> logger;
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly IApplicationUpdater applicationUpdater;
|
||||
private readonly UpdateStatus updateStatus = new();
|
||||
@@ -33,7 +32,7 @@ namespace Daybreak.Views
|
||||
|
||||
public UpdateView(
|
||||
IApplicationUpdater applicationUpdater,
|
||||
ILogger logger,
|
||||
ILogger<UpdateView> logger,
|
||||
IViewManager viewManager)
|
||||
{
|
||||
this.applicationUpdater = applicationUpdater;
|
||||
|
||||
Reference in New Issue
Block a user