Skip to content

Settings files: keep madeira.cfg lines that are not UTF-8, and UTF-16 .ini files as UTF-16 - #629

Open
spenstars1 wants to merge 1 commit into
willfaust:mainfrom
spenstars1:fix/cfg-ini-encodings
Open

spenstars1 wants to merge 1 commit into
willfaust:mainfrom
spenstars1:fix/cfg-ini-encodings

Conversation

@spenstars1

Copy link
Copy Markdown

Fixes #617, fixes #618.

madeira.cfg (#617)

A single byte that is not UTF-8 (for example a comment saved as Windows-1252 by a PC editor) made the strict UTF-8 decode fail, so the app treated the file as empty, and the next Settings change rewrote it with only that key.

  • MadeiraConfig.all() decodes the file lossily (String(decoding:as: UTF8.self)), so Settings sees the same keys build/madeira_cfg.h applies.
  • MadeiraConfig.set() works on bytes, as the native reader does. Every other line, including the non-UTF-8 comment, is kept byte for byte. A file that exists but cannot be read returns false and is not rewritten. Line endings are written as LF, as before.
  • WineProcessBridge.m read the env.* lines with NSUTF8StringEncoding, so such a file exported none of them. It now falls back to Latin 1. Limitation (noted in the code): a non-ASCII env value in such a file is re-encoded rather than passed byte for byte.
  • Get Help from Claude (ClaudeHelp.swift) left such a madeira.cfg out of its files. It now reads the file lossily too.

Settings files (#618)

  • IniFileText opens a file that starts with FF FE as UTF-16 LE and saves it as UTF-16 LE with its byte order mark. A broken UTF-16 file (odd length) does not open, so it is never saved damaged.

Checks

  • tests/host/check-runtime-settings.py: a madeira.cfg with a Windows-1252 byte and CRLF lines reads its keys, and set() keeps the comment bytes and every other key.
  • tests/host/check-ini-editor.py: a UTF-16 LE file opens with its section and values, round-trips unchanged, saves an edited value as UTF-16 LE, and a broken UTF-16 file does not open.

Not run yet: I wrote this on Windows without a Swift toolchain, so only the Python source checks ran (they pass). The Swift parts of the two checks and the Objective-C change still need a run on macOS (python3 tests/host/check-ini-editor.py --require-swift, python3 tests/host/check-runtime-settings.py). Not tested on a device.

The branch merges cleanly with the open PRs that touch these files (#594, #615). #463, #480 and #506 already conflict with main, and this change adds no new conflicts with them.

Written with the help of Claude Code (AI).

🤖 Generated with Claude Code

… .ini files as UTF-16

madeira.cfg (willfaust#617): a byte that is not UTF-8 no longer hides the whole file
from the app. MadeiraConfig.all() decodes it lossily, set() works on bytes
like build/madeira_cfg.h and keeps every other line unchanged, and a file
that exists but cannot be read is no longer rewritten with only the new key.
WineProcessBridge exports the env.* lines of such a file, and Get Help from
Claude includes it.

Settings files (willfaust#618): a .ini starting with FF FE opens as UTF-16 LE and is
saved as UTF-16 LE; a broken UTF-16 file does not open, so it is never saved
damaged.

Fixes willfaust#617, fixes willfaust#618.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: spenstars1 <356334520+spenstars1@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant