Packed MainWindow.xml into assembly to prevent runtime modification

This commit is contained in:
2025-09-17 09:02:22 +02:00
parent f659ea672c
commit e329430d28
2 changed files with 8 additions and 4 deletions

View File

@@ -12,9 +12,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="UI/MainWindow.xml"> <EmbeddedResource Include="UI/MainWindow.xml" />
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -6,7 +6,13 @@ public class MainWindow
public MainWindow() public MainWindow()
{ {
var builder = Gtk.Builder.NewFromFile("UI/MainWindow.xml"); var assembly = typeof(MainWindow).Assembly;
using var stream = assembly.GetManifestResourceStream("App.UI.MainWindow.xml");
if (stream == null)
throw new Exception("Failed to load embedded resource MainWindow.xml");
using var reader = new System.IO.StreamReader(stream);
var xml = reader.ReadToEnd();
var builder = Gtk.Builder.NewFromString(xml, -1);
var window = builder.GetObject("main_window") as Adw.Window; var window = builder.GetObject("main_window") as Adw.Window;
if (window == null) if (window == null)
throw new Exception("Failed to load main_window from MainWindow.ui"); throw new Exception("Failed to load main_window from MainWindow.ui");