Console: remember Enable Custom Bitmaps, ship the art; bump suite to 4.11.4.5

Settings -> Enable Custom Bitmaps was a static bool with no backing store:
it defaulted to off on every launch, so an operator had to re-tick it each
session and any custom plasma art was silently ignored until they did. New
ConsoleSettings persists machine-level menu toggles as XML in
%ProgramData%\Tesla Console\console.settings, alongside RPDefaults.rpd /
BTDefaults.btd / local.siteconfig. It is loaded once from Main and never
from a static initializer: the differential suite drives PlasmaBitmaps
directly and must keep seeing the original defaults rather than whatever
this machine has saved. A missing file is the first-run case; a corrupt one
is ignored and rewritten by the next toggle, because losing a menu setting
must never stop the console starting.

Custom art is now version-controlled and rolls with the release. New
Console\Plasma Images\ is copied into the package, and the lookup searches
%ProgramData%\Tesla Console\Plasma Images first and the exe-relative folder
second, so a release can never clobber a site's own name bitmaps.
install.bat creates the data-dir folder before the icacls grant so an
unelevated operator can write it. Ships with three 128x32 name bitmaps
(Deadmeat, Muerte, Phrogg); Muerte arrived as "Muerte_128x32-2.bmp", a name
the lookup can never build, so it is renamed to match its pilot.

Two fixes fell out of making the flag sticky. Path.Combine ran on the raw
participant name outside the try block, so with the option on a pilot named
"A:B" threw ArgumentException straight out of egg generation; names that
cannot be a Windows file name now just render procedurally. And the art was
loaded with Image.FromFile, which keeps the bitmap backed by the file and
locked for its whole lifetime — it is copied out through a stream now, so
art can be swapped between missions without restarting the console.

Verified against the built net40 exe: all three shipped bitmaps resolve by
pilot name, ProgramData wins over the shipped copy, a wrong-size file is
ignored, an illegal-character name does not throw, the file is not left
locked, and the settings round-trip and corrupt-file tolerance both hold.
Diff suite 106/106.

Version bumped 4.11.4.4 -> 4.11.4.5 across Console, Launcher, vPOD, the
install/build banners, the diff-suite version assertion and the README's
latest-release pointer.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cyd
2026-07-28 13:16:11 -05:00
co-authored by Claude Opus 5
parent 33f734da2d
commit 2a5a387381
18 changed files with 229 additions and 26 deletions
+79
View File
@@ -0,0 +1,79 @@
using System;
using System.IO;
using System.Windows.Forms;
using System.Xml;
namespace TeslaConsole;
/// <summary>
/// Machine-level console settings that belong to no single game — the Settings
/// menu toggles that used to live only in memory and reset on every restart.
/// Stored as XML in %ProgramData%\Tesla Console\console.settings, next to
/// RPDefaults.rpd / BTDefaults.btd / local.siteconfig.
///
/// The values themselves stay where they are used (PlasmaBitmaps owns
/// EnableCustomBitmaps); this class only moves them to and from disk, so the
/// original decompiled classes keep their shape. Load() is called once from
/// Program.Main and never from a static initializer: the differential test suite
/// drives PlasmaBitmaps directly, and must keep seeing the original defaults
/// rather than whatever this operator happens to have saved.
/// </summary>
internal static class ConsoleSettings
{
private static readonly string sSettingsFilePath = Path.Combine(Program.GetCommonAppDataDirectory(), "console.settings");
/// <summary>
/// Applies the saved settings. A missing file is the normal first-run case;
/// a corrupt one is ignored and rewritten by the next Save(), because losing
/// a menu toggle must never stop the console from starting.
/// </summary>
public static void Load()
{
try
{
if (!File.Exists(sSettingsFilePath))
{
return;
}
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(sSettingsFilePath);
foreach (XmlNode childNode in xmlDocument.DocumentElement.ChildNodes)
{
switch (childNode.Name)
{
case "EnableCustomBitmaps":
{
if (bool.TryParse(childNode.InnerText, out var result))
{
PlasmaBitmaps.EnableCustomBitmaps = result;
}
break;
}
}
}
}
catch (Exception)
{
}
}
public static void Save()
{
try
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.AppendChild(xmlDocument.CreateElement("ConsoleSettings"));
xmlDocument.DocumentElement.AppendChild(xmlDocument.CreateElement("EnableCustomBitmaps")).InnerText = PlasmaBitmaps.EnableCustomBitmaps.ToString();
string directoryName = Path.GetDirectoryName(sSettingsFilePath);
if (!Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
}
xmlDocument.Save(sSettingsFilePath);
}
catch (Exception)
{
MessageBox.Show("The console settings file could not be saved. This setting will only be remembered until the application is closed.", "Error Saving Console Settings!", MessageBoxButtons.OK);
}
}
}
+57 -14
View File
@@ -4,6 +4,7 @@ using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace TeslaConsole;
@@ -45,21 +46,10 @@ public class PlasmaBitmaps
{
if (sEnableCustomBitmaps)
{
string text = Path.Combine(Program.GetCommonAppDataDirectory(), $"Plasma Images\\{str}_{width}x{height}.bmp");
if (File.Exists(text))
Bitmap bitmap = LoadCustomBitmap(width, height, str);
if (bitmap != null)
{
try
{
Bitmap bitmap = (Bitmap)Image.FromFile(text);
if (bitmap.Width == width && bitmap.Height == height)
{
return bitmap;
}
bitmap.Dispose();
}
catch
{
}
return bitmap;
}
}
Bitmap bitmap2 = new Bitmap(width, height);
@@ -87,6 +77,59 @@ public class PlasmaBitmaps
}
}
/// <summary>
/// The operator-supplied plasma image for this string at this size, or null
/// when there is none (the caller then renders the text procedurally).
///
/// Two folders are searched, in order:
/// 1. %ProgramData%\Tesla Console\Plasma Images - this machine's own art,
/// which survives reinstalls and wins over anything shipped.
/// 2. Plasma Images\ next to TeslaConsole.exe - the set that rolls with
/// the release, so art can be version-controlled and deployed.
/// The file name is "&lt;text&gt;_&lt;width&gt;x&lt;height&gt;.bmp", e.g. Camera_128x32.bmp.
///
/// Nothing here may throw: participant names come from operator input, and a
/// name containing a character that is illegal in a path used to take out
/// egg generation entirely once this option was switched on.
/// </summary>
private static Bitmap LoadCustomBitmap(int width, int height, string str)
{
string fileName = $"{str}_{width}x{height}.bmp";
if (fileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
{
return null;
}
string[] searchRoots = new string[2]
{
Program.GetCommonAppDataDirectory(),
Path.GetDirectoryName(Application.ExecutablePath)
};
foreach (string searchRoot in searchRoots)
{
try
{
string path = Path.Combine(Path.Combine(searchRoot, "Plasma Images"), fileName);
if (!File.Exists(path))
{
continue;
}
// Copied out of the file rather than Image.FromFile'd: that keeps the
// bitmap backed by the file for its whole lifetime, which locks the art
// against an operator swapping it while the console is running.
using FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
using Image image = Image.FromStream(stream);
if (image.Width == width && image.Height == height)
{
return new Bitmap(image);
}
}
catch
{
}
}
return null;
}
public static void GenerateStrings(out string large, out string small, string str)
{
GenerateStrings(out large, out small, "Microsoft Sans Serif", str);
+2
View File
@@ -59,6 +59,8 @@ internal static class Program
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(defaultValue: false);
// Machine-level Settings-menu toggles, before the form reads them to set its check marks.
ConsoleSettings.Load();
Application.Run(new TeslaConsoleForm());
}
+1
View File
@@ -478,6 +478,7 @@ public class TeslaConsoleForm : Form
private void enableCustomBitmapsToolStripMenuItem_Click(object sender, EventArgs e)
{
enableCustomBitmapsToolStripMenuItem.Checked = (PlasmaBitmaps.EnableCustomBitmaps = !PlasmaBitmaps.EnableCustomBitmaps);
ConsoleSettings.Save();
}
private void mThrowHandledExceptionMenuItem_Click(object sender, EventArgs e)