Skip to content

Replace user.config with a JSON file next to the exe - #26

Closed
danielchalmers wants to merge 1 commit into
masterfrom
v5/settings-file
Closed

danielchalmers wants to merge 1 commit into
masterfrom
v5/settings-file

Conversation

@danielchalmers

@danielchalmers danielchalmers commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner
  • Settings are saved as JSON in a file next to the exe, named after it: Network-Monitor-x64.settings for the portable exe, Network Monitor.settings for the installed one. A portable copy keeps its settings when it's moved, and each copy has its own.
  • The first time a copy runs, it brings in 4.x's settings and position: the installed copy gets its own back, and any other copy gets whatever 4.x saved last. 4.x's files are only read.
  • A bad value only resets that setting, and an out-of-range size is clamped. A file that can't be parsed is kept as .settings.bad before the defaults are saved over it. Saves go through a temp file, and one that finds the file busy, like while OneDrive reads it, is tried again a second later.
  • If the file can't be written, such as in a folder that needs admin rights, it still starts and warns that changes won't be kept.
  • The user.config repair-and-restart is gone. Still a single exe with no libraries.
26

Release notes: settings now live in a .settings file beside the exe and are brought over from 4.x once. Uninstalling leaves Network Monitor.settings in %LOCALAPPDATA%\Network Monitor, and a portable copy doesn't pick up the installed copy's 5.0 settings.

@danielchalmers
danielchalmers marked this pull request as ready for review October 12, 2026 15:41
@danielchalmers danielchalmers changed the title Keep settings in a file next to the app Replace user.config with a JSON file next to the exe Oct 12, 2026
@danielchalmers
danielchalmers added this pull request to stack #33 October 12, 2026 16:28
Base automatically changed from v4.1/outage-clock to master October 12, 2026 18:09
@github-actions github-actions Bot added the enhancement New feature or request label Oct 13, 2026
- Save settings as JSON to <exe name>.settings beside the exe, a second after each change
- First run imports a sibling .settings file, else this copy's or the newest 4.x user.config
- Write through a temp file and MoveFileEx so a killed save can't leave a partial file
- Reset only bad values, allow a trailing comma, keep an unparsable file as .settings.bad
- Warn at startup when settings can't be saved; remove the user.config repair-and-restart
@danielchalmers

Copy link
Copy Markdown
Owner Author

Recommendation: close this and stay on .NET's user.config.

The settings are a handful of menu options that take seconds to set again. They should survive normal use and never stop the app from starting, and nothing more. Master already does that, so this PR gains little next to what it adds:

  • App code comes out about even (+519/−512), plus ~400 lines of tests. But generated code we never touch becomes saving code we maintain: the serializer, atomic writes, the busy-file retry, .bad backups, the can't-save warning, and the Populate/ToJson list every new setting has to join.
  • Every 4.x user's settings would go through new import code once on the upgrade, so a bug there loses everyone's at the same time. On user.config the installed copy upgrades as it always has: the install path doesn't change, and release builds are 5.0.0.0, so Upgrade() finds 4.1's file.
  • It leaves a file behind on uninstall, and warns in folders that need admin rights.

Settings going forward

  • Plain user.config. A new option is a row in Settings.settings plus a menu item, with no hidden settings.
  • Saved a second after each change, as now. WPF doesn't raise Closing when Windows signs out or restarts, and the widget is rarely closed with Exit, so without it a restart drops every change since sign-in.
  • A broken user.config still can't stop the app from starting. Otherwise a file cut short by a power cut means a crash at every sign-in until someone finds and deletes it in a hashed AppData folder.
  • A copy at a new path starts fresh. Revert the part of b5747f5 that brings in another copy's settings: UserConfigImport, the scan for other running copies, and their tests. It's the most intricate part and only saves re-picking a few options. SettingsStartup shrinks to Upgrade() plus the repair.
  • The portable exe is renamed in 5.0 (Network.Monitor.exe to Network-Monitor-x64.exe), so portable copies start on default settings once. One line in the release notes covers it.
  • Hide while an app is fullscreen on the same monitor #29's fullscreen option, and Add option to change the ping address #27's ping address if it stays, become rows in Settings.settings.

@danielchalmers

Copy link
Copy Markdown
Owner Author

Closing in favor of #37, which keeps .NET's user.config and only removes 4.1's import from other copies. The stack now starts at #37.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant