Skip to content

Skip a UTF-8 byte order mark at the start of fs2_open.ini - #7884

Open
dustinspace217 wants to merge 1 commit into
scp-fs2open:masterfrom
dustinspace217:osapi/ini-utf8-bom
Open

dustinspace217 wants to merge 1 commit into
scp-fs2open:masterfrom
dustinspace217:osapi/ini-utf8-bom

Conversation

@dustinspace217

Copy link
Copy Markdown
Contributor

Related to #5543 (its fs2_open.ini part; the multi.cfg part is #7881)

What?

Strips a UTF-8 byte order mark from the first line of fs2_open.ini before it is parsed.

Why?

If fs2_open.ini is saved with a byte order mark (Notepad can do this), the game stops seeing the first section, normally [Default], and every setting in it is ignored. The next time the game saves a setting it writes the file back without that section, so those settings are lost for good. This is the "using UTF-8 BOM to encode the fs2_open.ini causes FSO to completely delete..." part of #5543.

How?

profile_read compares each trimmed line with [. With the mark in front, [Default] is not seen as a section header, and the keys after it have no section, so they are dropped. On the first line only, if it starts with EF BB BF, those three bytes are removed before parsing. The same reader handles the per-mod settings file, so that is covered too. The saved file is written without the mark.

Testing?

Linux Release builds, retail FS2 data, master (a1250d7) against this branch, each run with its own preferences folder:

  • Reading: a standalone server with no -port takes its game port from [Default] ForcePort. With the mark (CRLF or LF, and with a second section after it), master opened the default port 7808 and this branch opened ForcePort. Without the mark, with the mark followed by a blank line, with only a mark, with an empty file and with no file, both builds behaved the same.
  • Saving: a test mod sets opt.MultiLogin from $On Game Init, which saves the ini. With the mark, master rewrote the file with only [Sound] and [PXO], and [Default] and both of its keys were gone. This branch kept every key. Without the mark, both kept every key.

The per-mod settings file uses the same reader but was not run separately.

Anything Else?

Written with Claude Code; the investigation, review and testing ran on my machine.

profile_read did not recognize a section header preceded by a byte order
mark, so every key under the first section ([Default]) was dropped. The
next settings save wrote the file back without them. Editors such as
Notepad can save the file with a mark.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant