View Issue Details

IDProjectCategoryView StatusLast Update
0001559OpenMPTGeneralpublic2025-08-16 16:27
ReporterSaga Musix Assigned Tomanx  
PrioritynormalSeverityminorReproducibilityN/A
Status acknowledgedResolutionopen 
Target VersionOpenMPT 1.33 / libopenmpt 0.9 (goals) 
Summary0001559: Don't use WinAPI functions for INI reading/writing
Description

Currently OpenMPT uses ReadPrivateProfile* / WritePrivateProfile*functions provided by Windows for reading and writing its settings files. This has several issues

  • It's relatively slow, which is why we only write setting that we know have changed
  • It requires hacks to enforce writing unicode files

As a consequence of the first point, it's possible that one OpenMPT instance takes a long time to shut down, and a newly launched instance may not see the settings as saved by the previous instance. One particularly worrying example is the following scenario:

  1. Fresh OpenMPT installation, user sees the Welcome dialog and unchecks automatic update checks
  2. User closes OpenMPT. This is the first time the INI file is written, so it takes quite a while to write out all settings.
  3. User immediately reopens OpenMPT. It may now try to search for updates because the old instance might not have finished writing the settings yet.

A custom INI implementation should avoid this scenario. While the file is being written, other OpenMPT instances should wait until the file is no longer locked, rather than reading incomplete settings.

TagsNo tags attached.
Has the bug occurred in previous versions?
Tested code revision (in case you know it)

Activities

manx

manx

2025-08-16 16:27

administrator   ~0006447

A custom INI implementation should avoid this scenario. While the file is being written, other OpenMPT instances should wait until the file is no longer locked, rather than reading incomplete settings.

I do not think this would be necessary. Atomically writing the file is the easier approach, because we do not (and do not want to, and cannot) guarantee settings consistency across different instances running concurrently anyway. Writing the file in 1 go should also be plenty fast enough to avoid the mentioned race condition. If the second instance is started while the first one is still actively running, there is not much we can do anyway, except for maybe flushing the configuration file after the welcome dialog (which would probably be a good idea even with the old implementation).

There are a couple of open questions regarding our own implementation:

  1. Do we want to handle binary data in string data and key names properly? Windows INI parsers do random confusing and undocumented things here, mostly stripping unwanted characters and trimming the result.
  2. Do we want to preserve ordering of the INI file as read from disk, or do we want to canonicalize/sort what we write out?
  3. Should the format be strictly backward compatible with the Windows INI parser, mimicing all its undocumented quirks?
  4. How to handle duplicate entries? (I did not look into how the Windows INI parser handles this)

The INI implementation that I have in an older code base answers these questions as:

  1. escape both key and value data
  2. strictly sorted output, preserving comments to the respective entry on a best effort basis
  3. no, because of 1 and 2
  4. I have not looked into that in detail yet.

In case the answer to 3 is "no", we should use a different file name in order to not break downgrades completely. "OpenMPT.ini" would make sense here.

Issue History

Date Modified Username Field Change
2022-01-30 17:48 Saga Musix New Issue
2022-01-30 17:51 Saga Musix Target Version => OpenMPT 1.31.01.00 / libopenmpt 0.7.0 (upgrade first)
2022-10-22 13:45 manx Assigned To => manx
2022-10-22 13:45 manx Status new => acknowledged
2023-04-10 08:24 manx Target Version OpenMPT 1.31.01.00 / libopenmpt 0.7.0 (upgrade first) => OpenMPT 1.32.01.00 / libopenmpt 0.8.0 (upgrade first)
2024-10-26 18:05 manx Target Version OpenMPT 1.32.01.00 / libopenmpt 0.8.0 (upgrade first) => OpenMPT 1.33 / libopenmpt 0.9 (goals)
2025-08-16 16:27 manx Note Added: 0006447