Added included snapshot and tzx option with roms

This commit is contained in:
2026-04-30 16:58:37 +01:00
parent 2f498d00be
commit 5c7ccc02ff
6 changed files with 77 additions and 35 deletions

View File

@@ -344,6 +344,22 @@ namespace Desktop
item.Click += IncludedTapMenuItem_Click;
tAPToolStripMenuItem1.DropDownItems.Add(item);
}
if (resourceName.Contains("Desktop.ROMS.Snapshot.") && resourceName.EndsWith(".sna", StringComparison.OrdinalIgnoreCase))
{
string[] parts = resourceName.Split('.');
string displayName = parts[parts.Length - 2];
ToolStripMenuItem item = new ToolStripMenuItem(displayName) { Tag = resourceName };
item.Click += IncludedTapMenuItem_Click;
SNAPToolStripMenuItem1.DropDownItems.Add(item);
}
if (resourceName.Contains("Desktop.ROMS.TZX.") && resourceName.EndsWith(".tzx", StringComparison.OrdinalIgnoreCase))
{
string[] parts = resourceName.Split('.');
string displayName = parts[parts.Length - 2];
ToolStripMenuItem item = new ToolStripMenuItem(displayName) { Tag = resourceName };
item.Click += IncludedTapMenuItem_Click;
TZXToolStripMenuItem1.DropDownItems.Add(item);
}
}
}
@@ -355,19 +371,33 @@ namespace Desktop
try
{
Assembly assembly = Assembly.GetExecutingAssembly();
// Open the embedded resource stream once
using (Stream? stream = assembly.GetManifestResourceStream(resourceName))
{
if (stream == null) throw new Exception("Could not find embedded resource.");
if (stream == null) throw new Exception($"Could not find embedded resource: {resourceName}");
// Copy the stream into a memory stream to extract the raw byte array
using (MemoryStream ms = new MemoryStream())
{
stream.CopyTo(ms);
_machine.TapeDeck.LoadTapData(ms.ToArray());
byte[] fileBytes = ms.ToArray();
// Route the byte array to the correct emulator component
if (resourceName.EndsWith(".tap", StringComparison.OrdinalIgnoreCase))
{
_machine.TapeDeck.LoadTapData(fileBytes);
}
else if (resourceName.EndsWith(".sna", StringComparison.OrdinalIgnoreCase))
{
_machine.LoadSnapshot(fileBytes);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show($"Failed to load built-in TAP:\n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show($"Failed to load built-in resource:\n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{