Changed some assembly settings

This commit is contained in:
2026-05-02 00:22:05 +01:00
parent b1e7210e95
commit 679d950e46
7 changed files with 71 additions and 33 deletions

View File

@@ -1,26 +1,33 @@
using System;
using System.IO;
using System.Reflection;
namespace Desktop
public static class RomLoader
{
public static class RomLoader
public static byte[] Load(string filename)
{
public static byte[] Load(string filePath)
// Construct the embedded resource path.
// Assuming your project's default namespace is "Desktop" and the folder is "ROMS"
string resourceName = $"Desktop.{filename}";
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
if (!File.Exists(filePath))
if (stream == null)
{
throw new FileNotFoundException($"Could not find the ROM file at: {filePath}");
// BULLETPROOFING: If the string is slightly wrong, this will print out
// exactly what the compiler actually named your embedded files!
string[] availableResources = assembly.GetManifestResourceNames();
string list = string.Join("\n", availableResources);
throw new FileNotFoundException($"Could not find embedded ROM: {resourceName}\n\nAvailable embedded files are:\n{list}");
}
byte[] romData = File.ReadAllBytes(filePath);
// The standard ZX Spectrum 48k ROM is exactly 16384 bytes (16KB)
if (romData.Length != 16384)
using (MemoryStream memoryStream = new MemoryStream())
{
throw new InvalidDataException($"Invalid ROM size. Expected 16384 bytes, got {romData.Length} bytes.");
stream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
return romData;
}
}
}