Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions ShinRyuModManager-CE/ModLoadOrder/Dependency/CPKGen/Endian.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,21 @@ public EndianWriter(Stream input, bool isLittleEndian)
public bool IsLittleEndian { get; set; } = isLittleEndian;

public void Write<T>(T value) {
dynamic input = value;
byte[] someBytes = BitConverter.GetBytes(input);
// A bit gross, but AOT and Trimming compatible
var someBytes = value switch {
bool b => BitConverter.GetBytes(b),
char c => BitConverter.GetBytes(c),
double d => BitConverter.GetBytes(d),
Half h => BitConverter.GetBytes(h),
short s => BitConverter.GetBytes(s),
int i => BitConverter.GetBytes(i),
long l => BitConverter.GetBytes(l),
float f => BitConverter.GetBytes(f),
ushort us => BitConverter.GetBytes(us),
uint ui => BitConverter.GetBytes(ui),
ulong ul => BitConverter.GetBytes(ul),
_ => throw new NotSupportedException($"Type {typeof(T)} is not supported.")
};

if (!IsLittleEndian)
someBytes = someBytes.Reverse().ToArray();
Expand Down
2 changes: 2 additions & 0 deletions ShinRyuModManager-CE/ShinRyuModManager-CE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<IsPackable>false</IsPackable>
<ApplicationIcon>UserInterface\Assets\Icons\SRMM_icon.ico</ApplicationIcon>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>

<!-- Versioning -->
<AssemblyVersion>1.1.11</AssemblyVersion>
Expand All @@ -25,6 +26,7 @@

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<VersionSuffix>$(BuildSuffix)</VersionSuffix>
<PublishTrimmed Condition="'$(SelfContained)' == 'true'">true</PublishTrimmed>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions ShinRyuModManager-CE/UserInterface/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
Expand Down Expand Up @@ -42,6 +43,7 @@ private static void DesktopOnExit(object sender, ControlledApplicationLifetimeEx
Log.CloseAndFlush();
}

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Only removing validation plugins; no reflection or property access used.")]
private static void DisableAvaloniaDataAnnotationValidation() {
// Get an array of plugins to remove
var dataValidationPluginsToRemove =
Expand Down
26 changes: 13 additions & 13 deletions ShinRyuModManager-CE/UserInterface/ViewLocator.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using ShinRyuModManager.UserInterface.UserControls;
using ShinRyuModManager.UserInterface.ViewModels;
using ShinRyuModManager.UserInterface.Views;

namespace ShinRyuModManager.UserInterface;

public class ViewLocator : IDataTemplate {
public Control Build(object param) {
var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
var type = Type.GetType(name);

if (type != null) {
return (Control)Activator.CreateInstance(type)!;
}

return new TextBox {
Text = $"Not Found: {name}"
public Control Build(object data) {
return data switch {
MainWindowViewModel vm => new MainWindow { DataContext = vm },
AboutWindowViewModel vm => new AboutWindow { DataContext = vm },
ChangeLogWindowViewModel vm => new ChangeLogWindow { DataContext = vm },
LibraryDisplayControlViewModel vm => new LibraryDisplayControl { DataContext = vm },
LibraryManagerViewModel vm => new LibraryManagerWindow { DataContext = vm },
MessageBoxWindowViewModel vm => new MessageBoxWindow { DataContext = vm },
ProgressWindowViewModel vm => new ProgressWindow { DataContext = vm },
_ => new TextBlock { Text = $"View not found for {data.GetType().Name}" }
};
}

public bool Match(object data) {
return data is ViewModelBase;
}
public bool Match(object data) => data is ViewModelBase;
}
4 changes: 2 additions & 2 deletions ShinRyuModManager-CE/UserInterface/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,12 @@ private void RefreshModList() {
viewModel.LoadModList();
}

private void CreateOrActivateWindow<T>() where T : Window {
private void CreateOrActivateWindow<T>() where T : Window, new() {
if (_childWindow is { IsVisible: true }) {
// Window visible
_childWindow.Activate();
} else {
_childWindow = Activator.CreateInstance<T>();
_childWindow = new T();
_childWindow.Closed += (_, _) => _childWindow = null;
_childWindow.Show(this);
}
Expand Down