Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Avalonia and other NuGet packages #225

Merged
merged 10 commits into from
Feb 8, 2024
12 changes: 6 additions & 6 deletions UnitystationLauncher.Tests/UnitystationLauncher.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions UnitystationLauncher/App.xaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:UnitystationLauncher"
x:Class="UnitystationLauncher.App">
x:Class="UnitystationLauncher.App"
RequestedThemeVariant="Default">
<Application.DataTemplates>
<local:ViewLocator />
</Application.DataTemplates>

<Application.Styles>
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml" />
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseDark.xaml" />
<FluentTheme />
<StyleInclude Source="/Styles.axaml" />
</Application.Styles>
</Application>
1 change: 1 addition & 0 deletions UnitystationLauncher/Constants/MessageBoxResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public static class MessageBoxResults
public const string Cancel = "Cancel";
public const string Yes = "Yes";
public const string No = "No";
public const string OpenLogFolder = "Open Log Folder";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using ILVerify;
using UnitystationLauncher.Infrastructure;
using UnitystationLauncher.Models.ConfigFile;
using UnitystationLauncher.Models.ContentScanning;
using UnitystationLauncher.Models.ContentScanning.ScanningTypes;

// psst
Expand All @@ -25,7 +26,7 @@ internal static Resolver CreateResolver(DirectoryInfo managedPath)
return new(managedPath);
}

internal static bool CheckVerificationResult(SandboxConfig loadedCfg, VerificationResult res, string name, MetadataReader reader, Action<string> logErrors)
internal static bool CheckVerificationResult(SandboxConfig loadedCfg, VerificationResult res, string name, MetadataReader reader, Action<ScanLog> scanLog)
{
if (loadedCfg.AllowedVerifierErrors.Contains(res.Code))
{
Expand All @@ -49,7 +50,11 @@ internal static bool CheckVerificationResult(SandboxConfig loadedCfg, Verificati
msg = $"{msg}, type: {type}";
}

logErrors.Invoke(msg);
scanLog.Invoke(new()
{
Type = ScanLog.LogType.Error,
LogMessage = msg
});
return true;
}

Expand Down
15 changes: 11 additions & 4 deletions UnitystationLauncher/ContentScanning/Scanners/ILScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
using ILVerify;
using UnitystationLauncher.Constants;
using UnitystationLauncher.Models.ConfigFile;
using UnitystationLauncher.Models.ContentScanning;

namespace UnitystationLauncher.ContentScanning.Scanners;

internal static class ILScanner
{
internal static bool IsILValid(string name, IResolver resolver, PEReader peReader,
MetadataReader reader, Action<string> info, Action<string> logErrors, SandboxConfig loadedCfg)
MetadataReader reader, Action<ScanLog> scanLog, SandboxConfig loadedCfg)
{
info.Invoke($"{name}: Verifying IL...");
scanLog.Invoke(new()
{
LogMessage = $"{name}: Verifying IL..."
});
Stopwatch sw = Stopwatch.StartNew();
ConcurrentBag<VerificationResult> bag = new();

Expand All @@ -24,14 +28,17 @@ internal static bool IsILValid(string name, IResolver resolver, PEReader peReade
bool verifyErrors = false;
foreach (VerificationResult res in bag)
{
bool error = AssemblyTypeCheckerHelpers.CheckVerificationResult(loadedCfg, res, name, reader, logErrors);
bool error = AssemblyTypeCheckerHelpers.CheckVerificationResult(loadedCfg, res, name, reader, scanLog);
if (error)
{
verifyErrors = true;
}
}

info.Invoke($"{name}: Verified IL in {sw.Elapsed.TotalMilliseconds}ms");
scanLog.Invoke(new()
{
LogMessage = $"{name}: Verified IL in {sw.Elapsed.TotalMilliseconds}ms"
});

if (verifyErrors)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.IO.Pipes;
using System.Reactive.Concurrency;
using System.Threading.Tasks;
using MessageBox.Avalonia.BaseWindows.Base;
using MsBox.Avalonia.Base;
using ReactiveUI;
using Serilog;
using UnitystationLauncher.Infrastructure;
Expand Down Expand Up @@ -60,14 +60,14 @@ public async Task StartServerPipe()
{
RxApp.MainThreadScheduler.ScheduleAsync(async (_, _) =>
{
IMsBoxWindow<string> msgBox = MessageBoxBuilder.CreateMessageBox(
IMsBox<string> msgBox = MessageBoxBuilder.CreateMessageBox(
MessageBoxButtons.YesNo,
string.Empty,
$"would you like to add this Domain to The allowed domains to be opened In your browser, {requests[1]} " +
@"
Justification given by the Fork : " + requests[2]);

string response = await msgBox.Show();
string response = await msgBox.ShowAsync();
Log.Information($"response {response}");
await _writer.WriteLineAsync(response == "No" ? false.ToString() : true.ToString());
await _writer.FlushAsync();
Expand All @@ -78,15 +78,15 @@ public async Task StartServerPipe()
{
RxApp.MainThreadScheduler.ScheduleAsync(async (_, _) =>
{
IMsBoxWindow<string> msgBox = MessageBoxBuilder.CreateMessageBox(
IMsBox<string> msgBox = MessageBoxBuilder.CreateMessageBox(
MessageBoxButtons.YesNo,
string.Empty,
$"The build would like to send an API request to, {requests[1]} " + @"
do you allow this fork to now on access this domain
Justification given by the Fork : " + requests[2]);


string response = await msgBox.Show();
string response = await msgBox.ShowAsync();
Log.Information($"response {response}");
await _writer.WriteLineAsync(response == "No" ? false.ToString() : true.ToString());
await _writer.FlushAsync();
Expand All @@ -97,7 +97,7 @@ public async Task StartServerPipe()
{
RxApp.MainThreadScheduler.ScheduleAsync(async (_, _) =>
{
IMsBoxWindow<string> msgBox = MessageBoxBuilder.CreateMessageBox(
IMsBox<string> msgBox = MessageBoxBuilder.CreateMessageBox(
MessageBoxButtons.YesNo,
string.Empty,
@" Trusted mode automatically allows every API and open URL action to happen without prompt, this also enables the
Expand All @@ -106,7 +106,7 @@ The main purpose of this Prompt is to allow the Variable viewer (Variable editin
What follows is given by the build, we do not control what is written in the Following text So treat with caution and use your brain
Justification : " + requests[1]); //TODO Add text

string response = await msgBox.Show();
string response = await msgBox.ShowAsync();
Log.Information($"response {response}");
await _writer.WriteLineAsync(response == "No" ? false.ToString() : true.ToString());
await _writer.FlushAsync();
Expand Down
17 changes: 11 additions & 6 deletions UnitystationLauncher/Infrastructure/MessageBoxBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System.Collections.Generic;
using MessageBox.Avalonia;
using MessageBox.Avalonia.BaseWindows.Base;
using MessageBox.Avalonia.DTO;
using MessageBox.Avalonia.Models;
using MsBox.Avalonia;
using MsBox.Avalonia.Base;
using MsBox.Avalonia.Dto;
using MsBox.Avalonia.Models;
using UnitystationLauncher.Constants;
using UnitystationLauncher.Models.Enums;

namespace UnitystationLauncher.Infrastructure;

public static class MessageBoxBuilder
{
public static IMsBoxWindow<string> CreateMessageBox(MessageBoxButtons buttonLayout, string header, string message)
public static IMsBox<string> CreateMessageBox(MessageBoxButtons buttonLayout, string header, string message)
{
IMsBoxWindow<string> msgBox = MessageBoxManager.GetMessageBoxCustomWindow(new MessageBoxCustomParams
IMsBox<string> msgBox = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
{
SystemDecorations = Avalonia.Controls.SystemDecorations.BorderOnly,
WindowStartupLocation = Avalonia.Controls.WindowStartupLocation.CenterScreen,
Expand Down Expand Up @@ -40,6 +40,11 @@ public static IMsBoxWindow<string> CreateMessageBox(MessageBoxButtons buttonLayo
new() { Name = MessageBoxResults.No },
new() { Name = MessageBoxResults.Cancel }
},
MessageBoxButtons.OpenLogFolderOk => new()
{
new() { Name = MessageBoxResults.OpenLogFolder },
new() { Name = MessageBoxResults.Ok }
},
_ => new List<ButtonDefinition>()
}
});
Expand Down
22 changes: 22 additions & 0 deletions UnitystationLauncher/Models/ContentScanning/ScanLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace UnitystationLauncher.Models.ContentScanning;

public class ScanLog
{
// Not 100% sure we need this, as this could just be replaced with a bool.
// However, I think it makes the code a bit easier to read to have a named thing so I did it anyways.
public enum LogType
{
Info,
Error
}

/// <summary>
/// Used to know which log we need to write this to
/// </summary>
public LogType Type { get; init; } = LogType.Info;

/// <summary>
/// Log message to be written
/// </summary>
public string LogMessage { get; init; } = string.Empty;
}
3 changes: 2 additions & 1 deletion UnitystationLauncher/Models/Enums/MessageBoxButtons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public enum MessageBoxButtons
Ok,
OkCancel,
YesNo,
YesNoCancel
YesNoCancel,
OpenLogFolderOk
}
33 changes: 28 additions & 5 deletions UnitystationLauncher/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using Avalonia;
using Avalonia.ReactiveUI;

Expand All @@ -11,13 +12,35 @@ private static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
// Windows Specific
.With(new Win32PlatformOptions { UseDeferredRendering = false })
.With(new Win32PlatformOptions
{
RenderingMode = new List<Win32RenderingMode>
{
Win32RenderingMode.Wgl
}
})
// MacOS Specific, AvaloniaNativePlatformOptions is "OSX backend options,
// and MacOSPlatformOptions is "OSX front-end options", no idea why they decided to do it that way.
.With(new AvaloniaNativePlatformOptions { UseGpu = true, UseDeferredRendering = false })
.With(new MacOSPlatformOptions { ShowInDock = true })
.With(new AvaloniaNativePlatformOptions
{
RenderingMode = new List<AvaloniaNativeRenderingMode>
{
AvaloniaNativeRenderingMode.OpenGl
}
})
.With(new MacOSPlatformOptions
{
ShowInDock = true
})
// Linux Specific
.With(new X11PlatformOptions { UseGpu = true, UseDeferredRendering = false })
.With(new X11PlatformOptions
{
RenderingMode = new List<X11RenderingMode>
{
X11RenderingMode.Egl
}
})
.LogToTrace()
.UseReactiveUI();
.UseReactiveUI()
.WithInterFont();
}
Loading
Loading