Newer
Older
EARS-LINUX / program / LEGACY_MODE_FIX.md

Fix: --legacy flag is not reaching the case loader

Symptom

argv = [.../program.exe | --legacy | --debug]
Loaded 98 cases from .../bin/linux/cases.csv

cases.csv has 98 rows — that is the current-mode loader running. The legacy loader prints Loaded N legacy cases from …, so LoadLegacyCasesFromCsv never ran. The map looks unchanged for the same reason: the app is in normal mode end to end.

So this is not a map-drawing bug. Fix the flag first, then re-check the map.

Likely causes, in order

  1. Program.cs sets AppMode.Legacy after the widgets are built, so SoundWindow's constructor already ran with Legacy == false.
  2. Program.cs step was never applied — argv is printed by pre-existing arg-parsing code, which proves an arg parser exists but not that ours was added to it.
  3. SoundWindow still calls CaseDefinition.LoadCasesFromCsv(AppFile("cases.csv")) instead of the AppMode version.
  4. Assets aren't next to the exe. Note the working dir is program/ but files resolve to program/bin/linux/ — cases_old.csv, map_old/, sound_old/ must be in bin/linux/, not the repo root.

Step 1 — diagnose before editing

Report back, don't fix yet:

  • Paste the full Program.cs Main, in order, from the first line to Application.Run(). Mark exactly where AppMode.Legacy is assigned, or state that it is absent.
  • Paste the current SoundWindow constructor lines that load _allCases.
  • Run ls -la bin/linux/ and report whether cases_old.csv, map_old/, sound_old/ exist there.
  • Confirm whether AppMode.cs and RegionSound.cs are in the build command actually used to produce bin/linux/program.exe (check the Makefile / build script, not just the files on disk).

Step 2 — make the flag observable

Add these three log lines so the mode is never ambiguous again.

In Program.cs, immediately after the AppMode.Legacy assignment:

Console.WriteLine("AppMode.Legacy = " + AppMode.Legacy +
                  "  cases=" + AppMode.CasesCsv);

In the SoundWindow constructor, as the first line:

Console.WriteLine("SoundWindow ctor: AppMode.Legacy = " + AppMode.Legacy);

In MapWindow.ShowCase, after _case is assigned:

Logger.Write("map", "ShowCase legacy=" + AppMode.Legacy +
                    " regions=" + _regions.Count);

Step 3 — set the flag before anything reads it

AppMode.Legacy must be assigned before Application.Init() and before any Builder / window / SoundWindow construction. If the existing parser handles --debug, add --legacy to that same parser and move the whole parse block to the top of Main, above Application.Init(). Do not add a second parser.

Target shape:

static void Main(string[] args)
{
    Console.WriteLine("argv = [" + string.Join(" | ", args) + "]");

    // --- flags first, before any UI construction ---
    AppMode.Legacy = Array.IndexOf(args, "--legacy") >= 0;
    // ... existing --debug handling stays here too ...
    Console.WriteLine("AppMode.Legacy = " + AppMode.Legacy +
                      "  cases=" + AppMode.CasesCsv);

    Application.Init();
    // ... existing window construction ...
    Application.Run();
}

If Main already lives in a different file or class than expected, edit that one — find it by searching for the argv = [ line that appears in the log.

Step 4 — verify SoundWindow uses AppMode

The constructor must read:

_allCases = AppMode.Legacy
    ? CaseDefinition.LoadLegacyCasesFromCsv(AppMode.CasesCsv)
    : CaseDefinition.LoadCasesFromCsv(AppMode.CasesCsv);

If a literal "cases.csv" string remains anywhere in SoundWindow, replace it. Then grep the whole repo for "cases.csv" and report every remaining hit — another class may be loading the CSV independently.

Step 5 — assets in the right folder

SoundWindow.AppFile resolves next to the assembly, which is bin/linux/. If the build copies cases.csv, map/, and sound/ there, make it copy cases_old.csv, map_old/, and sound_old/ the same way. Update the Makefile / build script rather than copying by hand, and say which file you changed.

Step 6 — re-verify, then look at the map

Run:

mono ./bin/linux/program.exe --legacy --debug

Expected, in this order:

AppMode.Legacy = True  cases=.../bin/linux/cases_old.csv
SoundWindow ctor: AppMode.Legacy = True
Loaded 28 legacy cases from .../bin/linux/cases_old.csv

Only once you see Loaded 28 legacy cases, select a case and check the log for:

[map] region 心音1: MAP100.png + SND100.wav
[map] ... 
[map] N/7 regions active
[map] ShowCase legacy=True regions=N

Report which of these appear. Then, and only then, we debug the drawing:

  • regions=0 → the region files aren't resolving; paste the region … map missing lines.
  • regions>0 but the map looks identical → the ShowCase branch from Step 9 of the original task wasn't applied, or _map is being overwritten after it by a later LoadMap(MapPathForView()) call. Paste the whole ShowCase method.
  • Colours appear but no bars → DrawRegionMeters isn't being called from OnMapDrawn.

Rules

  • Steps 1 and 6 are report-only. Do not edit files during them.
  • Do not "fix" this by defaulting AppMode.Legacy to true, by hardcoding cases_old.csv, or by calling the legacy loader unconditionally.
  • Do not touch the map-drawing code until the log proves the legacy loader ran.
  • One step per change set, with a diff, and wait for approval.