Skip to content

Interactive 2D wave optics simulator. Turn any image into a refractive scene, add sources, watch waves refract, diffract and interfere. Probes, intensity maps, video export.

C#

User settings in one XML file per user; Authors and Company are the product's name

Alexander Graef2957bed1afff
diff --git a/CLAUDE.md b/CLAUDE.md
index 336b02b..6945ea2 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -81,8 +81,11 @@ harnesses run.
`file_header_template` (its warranty sentence ends in a full stop: Roslyn cuts the value at `;`). LICENSE.md is
the FSF's GPL-3.0 Markdown verbatim, nothing else (GitHub's detector rejects additions); the About dialog shows
it as a document built by `Build/LicenseDocument.targets`.
-- The library is compiled optimised in every configuration (flip it locally to step through engine code). Each exe
- path has its own `user.config` under `%LOCALAPPDATA%\WaveDudeNext.WPF`. Close Visual Studio before renaming a
+- The library is compiled optimised in every configuration (flip it locally to step through engine code). The user
+ settings are one sparse XML file, `%LOCALAPPDATA%\WaveDudeNext\Settings.xml` (`Settings.cs`, `XmlSerializer`, 2026-10-26, the
+ user's choice: .NET's `ApplicationSettingsBase` kept a `user.config` per exe path and version under a folder named after
+ the assembly's company, his name by default; Authors and Company are now the product's name, nothing personal in folder
+ names). Folders under `%LOCALAPPDATA%\Alexander_Graef` and `%LOCALAPPDATA%\WaveDudeNext.WPF` are leftovers of that. Close Visual Studio before renaming a
project folder.
## Architecture
diff --git a/WaveDudeNext.WPF/App.xaml.cs b/WaveDudeNext.WPF/App.xaml.cs
index 15beb3c..a43ca26 100644
--- a/WaveDudeNext.WPF/App.xaml.cs
+++ b/WaveDudeNext.WPF/App.xaml.cs
@@ -15,7 +15,6 @@
// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
// <https://www.gnu.org/licenses/>.
-using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Reflection;
@@ -28,7 +27,6 @@ using NLog.Config;
using NLog.Targets;
using WaveDudeNext.WPF.Localization;
using WaveDudeNext.WPF.Logging;
-using WaveDudeNext.WPF.Properties;
using WaveDudeNext.Rendering;
using WaveDudeNext.Runs;
using WaveDudeNext.WPF.Rendering;
@@ -172,34 +170,6 @@ public partial class App : Application
}
}
- /// <summary>
- /// Makes the user settings usable: carries them over from the previous version on the
- /// first start after an update, and resets them when <c>user.config</c> is corrupt.
- /// </summary>
- private static void PrepareSettings()
- {
- try
- {
- if (Settings.Default.UpgradeRequired)
- {
- Settings.Default.Upgrade();
- Settings.Default.UpgradeRequired = false;
- Settings.Default.Save();
- Logger.Info("User settings upgraded from the previous version");
- }
- }
- catch (ConfigurationErrorsException ex)
- {
- string? file = (ex.InnerException as ConfigurationErrorsException)?.Filename ?? ex.Filename;
- Logger.Error(ex, "User settings file '{Path}' is unreadable; resetting to defaults", file);
- if (file != null && File.Exists(file))
- {
- File.Delete(file);
- }
- Settings.Default.Reload();
- }
- }
-
/// <inheritdoc/>
protected override void OnStartup(StartupEventArgs e)
{
@@ -230,7 +200,6 @@ public partial class App : Application
FileAssociation.Register(ColorSchemeStore.XmlExtension, FileAssociation.SchemeProgId, FileAssociation.SchemeDescription, executable);
}
- PrepareSettings();
FrameCache.Sweep();
ColorSchemeCatalog.Instance.Load();
ThemeController.Instance.Current = Settings.Default.Theme;
diff --git a/WaveDudeNext.WPF/Help/AboutWindow.xaml.cs b/WaveDudeNext.WPF/Help/AboutWindow.xaml.cs
index f89644b..86a8b15 100644
--- a/WaveDudeNext.WPF/Help/AboutWindow.xaml.cs
+++ b/WaveDudeNext.WPF/Help/AboutWindow.xaml.cs
@@ -23,7 +23,6 @@ using System.Windows.Input;
using System.Windows.Navigation;
using System.Windows.Threading;
using NLog;
-using WaveDudeNext.WPF.Properties;
using WaveDudeNext.WPF.Theming;
namespace WaveDudeNext.WPF.Help;
diff --git a/WaveDudeNext.WPF/MainWindow.Display.cs b/WaveDudeNext.WPF/MainWindow.Display.cs
index 6fef539..c8c87ba 100644
--- a/WaveDudeNext.WPF/MainWindow.Display.cs
+++ b/WaveDudeNext.WPF/MainWindow.Display.cs
@@ -22,7 +22,6 @@ using WaveDudeNext.Engine;
using WaveDudeNext.Model;
using WaveDudeNext.Rendering;
using WaveDudeNext.Runs;
-using WaveDudeNext.WPF.Properties;
namespace WaveDudeNext.WPF;
diff --git a/WaveDudeNext.WPF/MainWindow.Export.cs b/WaveDudeNext.WPF/MainWindow.Export.cs
index a63f645..6b2ca22 100644
--- a/WaveDudeNext.WPF/MainWindow.Export.cs
+++ b/WaveDudeNext.WPF/MainWindow.Export.cs
@@ -26,7 +26,6 @@ using WaveDudeNext.Probes;
using WaveDudeNext.Rendering;
using WaveDudeNext.Runs;
using WaveDudeNext.WPF.Dialogs;
-using WaveDudeNext.WPF.Properties;
using WaveDudeNext.WPF.Rendering;
namespace WaveDudeNext.WPF;
diff --git a/WaveDudeNext.WPF/MainWindow.Live.cs b/WaveDudeNext.WPF/MainWindow.Live.cs
index 284bc23..d8a1c4e 100644
--- a/WaveDudeNext.WPF/MainWindow.Live.cs
+++ b/WaveDudeNext.WPF/MainWindow.Live.cs
@@ -23,7 +23,6 @@ using WaveDudeNext.Model;
using WaveDudeNext.Parts;
using WaveDudeNext.Rendering;
using WaveDudeNext.Runs;
-using WaveDudeNext.WPF.Properties;
using WaveDudeNext.WPF.Rendering;
namespace WaveDudeNext.WPF;
diff --git a/WaveDudeNext.WPF/MainWindow.Simulation.cs b/WaveDudeNext.WPF/MainWindow.Simulation.cs
index b356419..c48b0b5 100644
--- a/WaveDudeNext.WPF/MainWindow.Simulation.cs
+++ b/WaveDudeNext.WPF/MainWindow.Simulation.cs
@@ -22,7 +22,6 @@ using System.Windows.Threading;
using WaveDudeNext.Engine;
using WaveDudeNext.Model;
using WaveDudeNext.Runs;
-using WaveDudeNext.WPF.Properties;
using WaveDudeNext.WPF.Rendering;
namespace WaveDudeNext.WPF;
diff --git a/WaveDudeNext.WPF/MainWindow.xaml b/WaveDudeNext.WPF/MainWindow.xaml
index f3d9383..93f8f1b 100644
--- a/WaveDudeNext.WPF/MainWindow.xaml
+++ b/WaveDudeNext.WPF/MainWindow.xaml
@@ -29,15 +29,15 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
xmlns:converters="clr-namespace:WaveDudeNext.WPF.Converters"
xmlns:panes="clr-namespace:WaveDudeNext.WPF.Panes"
xmlns:commands="clr-namespace:WaveDudeNext.WPF.Commands"
- xmlns:p="clr-namespace:WaveDudeNext.WPF.Properties"
+ xmlns:p="clr-namespace:WaveDudeNext.WPF"
xmlns:runs="clr-namespace:WaveDudeNext.Runs;assembly=WaveDudeNext"
Icon="App.ico"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
- Width="{Binding Source={x:Static p:Settings.Default}, Path=MainWindow_Width, Mode=TwoWay}"
- Height="{Binding Source={x:Static p:Settings.Default}, Path=MainWindow_Height, Mode=TwoWay}"
- Left="{Binding Source={x:Static p:Settings.Default}, Path=MainWindow_Left, Mode=TwoWay}"
- Top="{Binding Source={x:Static p:Settings.Default}, Path=MainWindow_Top, Mode=TwoWay}"
- WindowState="{Binding Source={x:Static p:Settings.Default}, Path=MainWindow_State, Mode=TwoWay}"
+ Width="{Binding Source={x:Static p:Settings.Default}, Path=WindowWidth, Mode=TwoWay}"
+ Height="{Binding Source={x:Static p:Settings.Default}, Path=WindowHeight, Mode=TwoWay}"
+ Left="{Binding Source={x:Static p:Settings.Default}, Path=WindowLeft, Mode=TwoWay}"
+ Top="{Binding Source={x:Static p:Settings.Default}, Path=WindowTop, Mode=TwoWay}"
+ WindowState="{Binding Source={x:Static p:Settings.Default}, Path=WindowState, Mode=TwoWay}"
MinWidth="800" MinHeight="500"
WindowStartupLocation="CenterScreen"
ResizeMode="CanResizeWithGrip"
diff --git a/WaveDudeNext.WPF/MainWindow.xaml.cs b/WaveDudeNext.WPF/MainWindow.xaml.cs
index 3e10306..b36a66e 100644
--- a/WaveDudeNext.WPF/MainWindow.xaml.cs
+++ b/WaveDudeNext.WPF/MainWindow.xaml.cs
@@ -16,8 +16,6 @@
// <https://www.gnu.org/licenses/>.
using System.Collections.ObjectModel;
-using System.Collections.Specialized;
-using System.Configuration;
using System.IO;
using System.Windows;
using System.Windows.Controls;
@@ -32,7 +30,6 @@ using WaveDudeNext.Rendering;
using WaveDudeNext.WPF.Dialogs;
using WaveDudeNext.WPF.Docking;
using WaveDudeNext.WPF.Localization;
-using WaveDudeNext.WPF.Properties;
using WaveDudeNext.WPF.Theming;
namespace WaveDudeNext.WPF;
@@ -315,11 +312,11 @@ public partial class MainWindow : Window
{
JumpList.AddToRecentCategory(fileName);
- // a fresh collection so the bound menu sees the change (StringCollection does not notify)
- var recent = new StringCollection { fileName };
- foreach (string? entry in Settings.Default.RecentFiles ?? [])
+ // a fresh list so the bound menu sees the change
+ var recent = new List<string> { fileName };
+ foreach (string entry in Settings.Default.RecentFiles)
{
- if (entry != null && !string.Equals(entry, fileName, StringComparison.OrdinalIgnoreCase) && recent.Count < RecentFileCount)
+ if (!string.Equals(entry, fileName, StringComparison.OrdinalIgnoreCase) && recent.Count < RecentFileCount)
{
recent.Add(entry);
}
@@ -559,10 +556,10 @@ public partial class MainWindow : Window
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
- if (Settings.Default.MainWindow_State == WindowState.Minimized)
+ if (Settings.Default.WindowState == WindowState.Minimized)
{
// never start minimized
- Settings.Default.MainWindow_State = WindowState.Normal;
+ Settings.Default.WindowState = WindowState.Normal;
}
SaveSettings();
}
@@ -574,10 +571,10 @@ public partial class MainWindow : Window
Settings.Default.Save();
Logger.Debug("User settings saved");
}
- catch (Exception ex) when (ex is ConfigurationErrorsException or IOException or UnauthorizedAccessException)
+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
// Losing window placement or the recent list is not worth interrupting the user. The file errors: two
- // instances closing at once replace the same user.config, and the second one finds it gone (2026-10-19)
+ // instances closing at once write the same file, and the second one finds it open (2026-10-19)
Logger.Warn(ex, "Could not save the user settings");
}
}
diff --git a/WaveDudeNext.WPF/Properties/Settings.Designer.cs b/WaveDudeNext.WPF/Properties/Settings.Designer.cs
deleted file mode 100644
index 197f10e..0000000
--- a/WaveDudeNext.WPF/Properties/Settings.Designer.cs
+++ /dev/null
@@ -1,264 +0,0 @@
-//------------------------------------------------------------------------------
-// <auto-generated>
-// This code was generated by a tool.
-// Runtime Version:4.0.30319.42000
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-// </auto-generated>
-//------------------------------------------------------------------------------
-
-namespace WaveDudeNext.WPF.Properties {
-
-
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "18.10.0.0")]
- internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
-
- private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
-
- public static Settings Default {
- get {
- return defaultInstance;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("True")]
- public bool UpgradeRequired {
- get {
- return ((bool)(this["UpgradeRequired"]));
- }
- set {
- this["UpgradeRequired"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("1280")]
- public double MainWindow_Width {
- get {
- return ((double)(this["MainWindow_Width"]));
- }
- set {
- this["MainWindow_Width"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("800")]
- public double MainWindow_Height {
- get {
- return ((double)(this["MainWindow_Height"]));
- }
- set {
- this["MainWindow_Height"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("NaN")]
- public double MainWindow_Left {
- get {
- return ((double)(this["MainWindow_Left"]));
- }
- set {
- this["MainWindow_Left"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("NaN")]
- public double MainWindow_Top {
- get {
- return ((double)(this["MainWindow_Top"]));
- }
- set {
- this["MainWindow_Top"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("Normal")]
- public global::System.Windows.WindowState MainWindow_State {
- get {
- return ((global::System.Windows.WindowState)(this["MainWindow_State"]));
- }
- set {
- this["MainWindow_State"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- public global::WaveDudeNext.WPF.Docking.DockLayout Layout {
- get {
- return ((global::WaveDudeNext.WPF.Docking.DockLayout)(this["Layout"]));
- }
- set {
- this["Layout"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("System")]
- public global::WaveDudeNext.WPF.Theming.AppTheme Theme {
- get {
- return ((global::WaveDudeNext.WPF.Theming.AppTheme)(this["Theme"]));
- }
- set {
- this["Theme"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("")]
- public string Language {
- get {
- return ((string)(this["Language"]));
- }
- set {
- this["Language"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- public global::System.Collections.Specialized.StringCollection RecentFiles {
- get {
- return ((global::System.Collections.Specialized.StringCollection)(this["RecentFiles"]));
- }
- set {
- this["RecentFiles"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("Vertical")]
- public global::System.Windows.Controls.Orientation PreviewOrientation {
- get {
- return ((global::System.Windows.Controls.Orientation)(this["PreviewOrientation"]));
- }
- set {
- this["PreviewOrientation"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("True")]
- public bool AutoRerun {
- get {
- return ((bool)(this["AutoRerun"]));
- }
- set {
- this["AutoRerun"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("True")]
- public bool UseGpu {
- get {
- return ((bool)(this["UseGpu"]));
- }
- set {
- this["UseGpu"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("0")]
- public int FrameMemoryPercent {
- get {
- return ((int)(this["FrameMemoryPercent"]));
- }
- set {
- this["FrameMemoryPercent"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("1")]
- public int PreviewResolution {
- get {
- return ((int)(this["PreviewResolution"]));
- }
- set {
- this["PreviewResolution"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("1")]
- public int PreviewFrames {
- get {
- return ((int)(this["PreviewFrames"]));
- }
- set {
- this["PreviewFrames"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("1")]
- public int PreviewSampleBytes {
- get {
- return ((int)(this["PreviewSampleBytes"]));
- }
- set {
- this["PreviewSampleBytes"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("0")]
- public int PreviewDitherBits {
- get {
- return ((int)(this["PreviewDitherBits"]));
- }
- set {
- this["PreviewDitherBits"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("")]
- public string LastExportFolder {
- get {
- return ((string)(this["LastExportFolder"]));
- }
- set {
- this["LastExportFolder"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("0")]
- public int ExportFilterIndex {
- get {
- return ((int)(this["ExportFilterIndex"]));
- }
- set {
- this["ExportFilterIndex"] = value;
- }
- }
- }
-}
diff --git a/WaveDudeNext.WPF/Properties/Settings.settings b/WaveDudeNext.WPF/Properties/Settings.settings
deleted file mode 100644
index 5a73f8e..0000000
--- a/WaveDudeNext.WPF/Properties/Settings.settings
+++ /dev/null
@@ -1,66 +0,0 @@
-<?xml version='1.0' encoding='utf-8'?>
-<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="WaveDudeNext.WPF.Properties" GeneratedClassName="Settings">
- <Profiles />
- <Settings>
- <Setting Name="UpgradeRequired" Type="System.Boolean" Scope="User">
- <Value Profile="(Default)">True</Value>
- </Setting>
- <Setting Name="MainWindow_Width" Type="System.Double" Scope="User">
- <Value Profile="(Default)">1280</Value>
- </Setting>
- <Setting Name="MainWindow_Height" Type="System.Double" Scope="User">
- <Value Profile="(Default)">800</Value>
- </Setting>
- <Setting Name="MainWindow_Left" Type="System.Double" Scope="User">
- <Value Profile="(Default)">NaN</Value>
- </Setting>
- <Setting Name="MainWindow_Top" Type="System.Double" Scope="User">
- <Value Profile="(Default)">NaN</Value>
- </Setting>
- <Setting Name="MainWindow_State" Type="System.Windows.WindowState" Scope="User">
- <Value Profile="(Default)">Normal</Value>
- </Setting>
- <Setting Name="Layout" Type="WaveDudeNext.WPF.Docking.DockLayout" Scope="User">
- <Value Profile="(Default)" />
- </Setting>
- <Setting Name="Theme" Type="WaveDudeNext.WPF.Theming.AppTheme" Scope="User">
- <Value Profile="(Default)">System</Value>
- </Setting>
- <Setting Name="Language" Type="System.String" Scope="User">
- <Value Profile="(Default)" />
- </Setting>
- <Setting Name="RecentFiles" Type="System.Collections.Specialized.StringCollection" Scope="User">
- <Value Profile="(Default)" />
- </Setting>
- <Setting Name="PreviewOrientation" Type="System.Windows.Controls.Orientation" Scope="User">
- <Value Profile="(Default)">Vertical</Value>
- </Setting>
- <Setting Name="AutoRerun" Type="System.Boolean" Scope="User">
- <Value Profile="(Default)">True</Value>
- </Setting>
- <Setting Name="UseGpu" Type="System.Boolean" Scope="User">
- <Value Profile="(Default)">True</Value>
- </Setting>
- <Setting Name="FrameMemoryPercent" Type="System.Int32" Scope="User">
- <Value Profile="(Default)">0</Value>
- </Setting>
- <Setting Name="PreviewResolution" Type="System.Int32" Scope="User">
- <Value Profile="(Default)">1</Value>
- </Setting>
- <Setting Name="PreviewFrames" Type="System.Int32" Scope="User">
- <Value Profile="(Default)">1</Value>
- </Setting>
- <Setting Name="PreviewSampleBytes" Type="System.Int32" Scope="User">
- <Value Profile="(Default)">1</Value>
- </Setting>
- <Setting Name="PreviewDitherBits" Type="System.Int32" Scope="User">
- <Value Profile="(Default)">0</Value>
- </Setting>
- <Setting Name="LastExportFolder" Type="System.String" Scope="User">
- <Value Profile="(Default)" />
- </Setting>
- <Setting Name="ExportFilterIndex" Type="System.Int32" Scope="User">
- <Value Profile="(Default)">0</Value>
- </Setting>
- </Settings>
-</SettingsFile>
diff --git a/WaveDudeNext.WPF/Settings.cs b/WaveDudeNext.WPF/Settings.cs
new file mode 100644
index 0000000..a684ee1
--- /dev/null
+++ b/WaveDudeNext.WPF/Settings.cs
@@ -0,0 +1,288 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 Alexander Graef <[email protected]>
+//
+// This file is part of WaveDude Next, a 2D wave simulator.
+//
+// Based on the work of
+// Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026
+// <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>
+// 0x23 (Diffraction Limited), author of WaveSimulator2D
+// <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>
+//
+// WaveDude Next is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation, either version 3 of the License, or (at your option) any later
+// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
+// <https://www.gnu.org/licenses/>.
+
+using System.ComponentModel;
+using System.IO;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Xml;
+using System.Xml.Serialization;
+using NLog;
+using WaveDudeNext.WPF.Docking;
+using WaveDudeNext.WPF.Theming;
+
+namespace WaveDudeNext.WPF;
+
+/// <summary>
+/// The user settings: one XML file per user, <c>%LocalAppData%\WaveDudeNext\Settings.xml</c>, beside the colour
+/// schemes and the frame cache, written by <see cref="XmlSerializer"/> sparsely (a value at its default is left out).
+/// Replaces <c>ApplicationSettingsBase</c> (2026-10-26, the user's choice): that kept a <c>user.config</c> per exe
+/// path and per version under a folder named after the assembly's company, the author's name by default, so a build
+/// and a publish never shared their settings and the upgrade step had nothing to carry over. Every member is for the
+/// UI thread; a change raises <see cref="PropertyChanged"/>, and nothing is written until <see cref="Save"/>.
+/// </summary>
+[XmlRoot("Settings")]
+public sealed class Settings : INotifyPropertyChanged
+{
+ private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();
+ private static readonly XmlSerializer Serializer = new(typeof(Settings));
+
+ /// <summary>The settings file.</summary>
+ public static string FilePath { get; } = Path.Combine(App.LocalAppDataDirectory, "Settings.xml");
+
+ /// <summary>This user's settings, read from <see cref="FilePath"/> at first use; the defaults when the file is missing or unreadable.</summary>
+ public static Settings Default { get; } = Load();
+
+ /// <inheritdoc/>
+ public event PropertyChangedEventHandler? PropertyChanged;
+
+ private double _windowWidth = 1280;
+
+ /// <summary>Width of the main window in device-independent pixels.</summary>
+ [XmlAttribute, DefaultValue(1280.0)]
+ public double WindowWidth
+ {
+ get => _windowWidth;
+ set => Set(ref _windowWidth, value);
+ }
+
+ private double _windowHeight = 800;
+
+ /// <summary>Height of the main window in device-independent pixels.</summary>
+ [XmlAttribute, DefaultValue(800.0)]
+ public double WindowHeight
+ {
+ get => _windowHeight;
+ set => Set(ref _windowHeight, value);
+ }
+
+ private double _windowLeft = double.NaN;
+
+ /// <summary>Left edge of the main window in device-independent pixels; NaN lets Windows place it.</summary>
+ [XmlAttribute, DefaultValue(double.NaN)]
+ public double WindowLeft
+ {
+ get => _windowLeft;
+ set => Set(ref _windowLeft, value);
+ }
+
+ private double _windowTop = double.NaN;
+
+ /// <summary>Top edge of the main window in device-independent pixels; NaN lets Windows place it.</summary>
+ [XmlAttribute, DefaultValue(double.NaN)]
+ public double WindowTop
+ {
+ get => _windowTop;
+ set => Set(ref _windowTop, value);
+ }
+
+ private WindowState _windowState = WindowState.Normal;
+
+ /// <summary>State of the main window; never saved as minimized.</summary>
+ [XmlAttribute, DefaultValue(WindowState.Normal)]
+ public WindowState WindowState
+ {
+ get => _windowState;
+ set => Set(ref _windowState, value);
+ }
+
+ private DockLayout? _layout = null;
+
+ /// <summary>The dock panes' arrangement at the last close; null for a first start.</summary>
+ [XmlElement("Layout")]
+ public DockLayout? Layout
+ {
+ get => _layout;
+ set => Set(ref _layout, value);
+ }
+
+ private AppTheme _theme = AppTheme.System;
+
+ /// <summary>The colour theme.</summary>
+ [XmlAttribute, DefaultValue(AppTheme.System)]
+ public AppTheme Theme
+ {
+ get => _theme;
+ set => Set(ref _theme, value);
+ }
+
+ private string _language = "";
+
+ /// <summary>The string table's language code; empty for the system's.</summary>
+ [XmlAttribute, DefaultValue("")]
+ public string Language
+ {
+ get => _language;
+ set => Set(ref _language, value);
+ }
+
+ private List<string> _recentFiles = [];
+
+ /// <summary>The recently opened project files, newest first; a fresh list on every change, so the bound menu sees it.</summary>
+ [XmlElement("RecentFile")]
+ public List<string> RecentFiles
+ {
+ get => _recentFiles;
+ set => Set(ref _recentFiles, value);
+ }
+
+ private Orientation _previewOrientation = Orientation.Vertical;
+
+ /// <summary>Whether the preview's pictures sit side by side or one above the other.</summary>
+ [XmlAttribute, DefaultValue(Orientation.Vertical)]
+ public Orientation PreviewOrientation
+ {
+ get => _previewOrientation;
+ set => Set(ref _previewOrientation, value);
+ }
+
+ private bool _autoRerun = true;
+
+ /// <summary>Whether a simulation edit re-runs the simulation after a moment of quiet.</summary>
+ [XmlAttribute, DefaultValue(true)]
+ public bool AutoRerun
+ {
+ get => _autoRerun;
+ set => Set(ref _autoRerun, value);
+ }
+
+ private bool _useGpu = true;
+
+ /// <summary>Whether runs use the OpenCL engine, falling back to the CPU.</summary>
+ [XmlAttribute, DefaultValue(true)]
+ public bool UseGpu
+ {
+ get => _useGpu;
+ set => Set(ref _useGpu, value);
+ }
+
+ private int _frameMemoryPercent = 0;
+
+ /// <summary>The RAM cache's bound as a percentage of the physical memory; 0 or less for automatic.</summary>
+ [XmlAttribute, DefaultValue(0)]
+ public int FrameMemoryPercent
+ {
+ get => _frameMemoryPercent;
+ set => Set(ref _frameMemoryPercent, value);
+ }
+
+ private int _previewResolution = 1;
+
+ /// <summary>The preview's resolution divisor: 1, 2 or 4.</summary>
+ [XmlAttribute, DefaultValue(1)]
+ public int PreviewResolution
+ {
+ get => _previewResolution;
+ set => Set(ref _previewResolution, value);
+ }
+
+ private int _previewFrames = 1;
+
+ /// <summary>The preview's frame divisor: every 1st, 2nd or 4th frame.</summary>
+ [XmlAttribute, DefaultValue(1)]
+ public int PreviewFrames
+ {
+ get => _previewFrames;
+ set => Set(ref _previewFrames, value);
+ }
+
+ private int _previewSampleBytes = 1;
+
+ /// <summary>Bytes per preview sample: 1 for palette indices, 2 for halves.</summary>
+ [XmlAttribute, DefaultValue(1)]
+ public int PreviewSampleBytes
+ {
+ get => _previewSampleBytes;
+ set => Set(ref _previewSampleBytes, value);
+ }
+
+ private int _previewDitherBits = 0;
+
+ /// <summary>Preview dithering: 0 for off, else the bits per channel the colours are reduced from (10, 12, 14 or 16).</summary>
+ [XmlAttribute, DefaultValue(0)]
+ public int PreviewDitherBits
+ {
+ get => _previewDitherBits;
+ set => Set(ref _previewDitherBits, value);
+ }
+
+ private string _lastExportFolder = "";
+
+ /// <summary>The folder of the last export; empty for none.</summary>
+ [XmlAttribute, DefaultValue("")]
+ public string LastExportFolder
+ {
+ get => _lastExportFolder;
+ set => Set(ref _lastExportFolder, value);
+ }
+
+ private int _exportFilterIndex = 0;
+
+ /// <summary>The index of the export format chosen last in the dialog's filter list.</summary>
+ [XmlAttribute, DefaultValue(0)]
+ public int ExportFilterIndex
+ {
+ get => _exportFilterIndex;
+ set => Set(ref _exportFilterIndex, value);
+ }
+
+ /// <summary>Writes the settings to <see cref="FilePath"/>, creating the folder; file errors are the caller's.</summary>
+ public void Save()
+ {
+ Directory.CreateDirectory(Path.GetDirectoryName(FilePath)!);
+ using var writer = XmlWriter.Create(FilePath, new XmlWriterSettings
+ {
+ Indent = true,
+ IndentChars = "\t",
+ Encoding = new UTF8Encoding(false),
+ });
+ Serializer.Serialize(writer, this, new XmlSerializerNamespaces([XmlQualifiedName.Empty]));
+ }
+
+ private static Settings Load()
+ {
+ if (!File.Exists(FilePath))
+ {
+ Logger.Debug("No settings file at '{Path}', using the defaults", FilePath);
+ return new Settings();
+ }
+ try
+ {
+ using var reader = XmlReader.Create(FilePath);
+ if (Serializer.Deserialize(reader) is Settings settings)
+ {
+ return settings;
+ }
+ }
+ catch (Exception ex) when (ex is InvalidOperationException or XmlException or IOException or UnauthorizedAccessException)
+ {
+ Logger.Error(ex, "The settings file '{Path}' is unreadable, using the defaults", FilePath);
+ }
+ return new Settings();
+ }
+
+ private void Set<T>(ref T field, T value, [CallerMemberName] string? name = null)
+ {
+ if (!EqualityComparer<T>.Default.Equals(field, value))
+ {
+ field = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
+ }
+ }
+}
diff --git a/WaveDudeNext.WPF/WaveDudeNext.WPF.csproj b/WaveDudeNext.WPF/WaveDudeNext.WPF.csproj
index bbb2bb6..1cfda47 100644
--- a/WaveDudeNext.WPF/WaveDudeNext.WPF.csproj
+++ b/WaveDudeNext.WPF/WaveDudeNext.WPF.csproj
@@ -10,8 +10,11 @@
<StartupObject>WaveDudeNext.WPF.Program</StartupObject>
<!-- executable icon (Explorer, taskbar); the window icon is the same file as a resource -->
<ApplicationIcon>App.ico</ApplicationIcon>
- <!-- read by About and the file properties; the license text is LICENSE.md, the header of every source file names it -->
- <Authors>Alexander Graef</Authors>
+ <!-- read by About and the file properties; the license text is LICENSE.md, the header of every source file names it.
+ Authors and Company are the product's name (2026-10-26, the user's rule): .NET puts the company into folder names,
+ and the author's name is nobody's business on a user's disk; the Copyright line names him -->
+ <Authors>WaveDudeNext</Authors>
+ <Company>WaveDudeNext</Company>
<Copyright>Copyright (C) 2026 Alexander Graef</Copyright>
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
<!-- the .editorconfig code-style rules are build warnings too: a file without the license header (IDE0073) -->
@@ -34,19 +37,4 @@
<ProjectReference Include="..\WaveDudeNext\WaveDudeNext.csproj" />
</ItemGroup>
- <ItemGroup>
- <Compile Update="Properties\Settings.Designer.cs">
- <DesignTimeSharedInput>True</DesignTimeSharedInput>
- <AutoGen>True</AutoGen>
- <DependentUpon>Settings.settings</DependentUpon>
- </Compile>
- </ItemGroup>
-
- <ItemGroup>
- <None Update="Properties\Settings.settings">
- <Generator>SettingsSingleFileGenerator</Generator>
- <LastGenOutput>Settings.Designer.cs</LastGenOutput>
- </None>
- </ItemGroup>
-
</Project>
diff --git a/WaveDudeNext/WaveDudeNext.csproj b/WaveDudeNext/WaveDudeNext.csproj
index 93d7209..13602e9 100644
--- a/WaveDudeNext/WaveDudeNext.csproj
+++ b/WaveDudeNext/WaveDudeNext.csproj
@@ -11,8 +11,11 @@
<Optimize>true</Optimize>
<!-- the MP4 writer copies a frame into a Media Foundation buffer through its raw pointer -->
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <!-- read by About and the file properties; the license text is LICENSE.md, the header of every source file names it -->
- <Authors>Alexander Graef</Authors>
+ <!-- read by About and the file properties; the license text is LICENSE.md, the header of every source file names it.
+ Authors and Company are the product's name (2026-10-26, the user's rule): .NET puts the company into folder names,
+ and the author's name is nobody's business on a user's disk; the Copyright line names him -->
+ <Authors>WaveDudeNext</Authors>
+ <Company>WaveDudeNext</Company>
<Copyright>Copyright (C) 2026 Alexander Graef</Copyright>
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
<!-- the .editorconfig code-style rules are build warnings too: a file without the license header (IDE0073) -->