From 65a775aefbf2193a70d972c21e8aacb7334a13ae Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Sat, 11 Apr 2026 07:56:10 -0300 Subject: [PATCH] Remove ini watcher code (M1 fix) --- Knossos.NET/Models/GlobalSettings.cs | 63 ------------------- .../ViewModels/Windows/MainWindowViewModel.cs | 5 -- 2 files changed, 68 deletions(-) diff --git a/Knossos.NET/Models/GlobalSettings.cs b/Knossos.NET/Models/GlobalSettings.cs index c2209df2..b060e058 100644 --- a/Knossos.NET/Models/GlobalSettings.cs +++ b/Knossos.NET/Models/GlobalSettings.cs @@ -331,9 +331,6 @@ public ModSortType sortType public string envVars { get; set; } = string.Empty; [JsonPropertyName("show_dev_options")] public bool showDevOptions { get; set; } = false; - - [JsonIgnore] - private FileSystemWatcher? iniWatcher = null; /// /// Call this when the app is closing to save settings if we have pending changes @@ -347,57 +344,6 @@ public void SaveSettingsOnAppClose() } } - /// - /// When the User is on the settings tab we must watch the fs2_open.ini for external changes - /// This is the initial call that must be called once, then we start or stop raising of events - /// - private void StartWatchingDirectory() - { - iniWatcher = new FileSystemWatcher(KnUtils.GetFSODataFolderPath()); - iniWatcher.NotifyFilter = NotifyFilters.LastWrite; - iniWatcher.Changed += OnIniChanged; - iniWatcher.Filter = "fs2_open.ini"; - } - - /// - /// If the fs2_open.ini is changed externally, reload the data - /// - private void OnIniChanged(object sender, FileSystemEventArgs e) - { - iniWatcher!.EnableRaisingEvents = false; - Dispatcher.UIThread.InvokeAsync(() => - { - Log.Add(Log.LogSeverity.Information, "GlobalSettings.OnIniChanged()", "fs2_open.ini was changed externally, loading data."); - Load(); - MainWindowViewModel.Instance?.GlobalSettingsLoadData(); - }); - Task.Delay(1000); - iniWatcher!.EnableRaisingEvents = true; - } - - /// - /// Start watching for changes on the ini file - /// - public void EnableIniWatch() - { - if (iniWatcher != null) - iniWatcher.EnableRaisingEvents = true; - else - { - StartWatchingDirectory(); - EnableIniWatch(); - } - } - - /// - /// Stop watching for changes on the ini file - /// - public void DisableIniWatch() - { - if(iniWatcher != null) - iniWatcher.EnableRaisingEvents = false; - } - /// /// Load setting data that saves on the fs2_open.ini /// On the ini we save all data that is used by both FSO and KNET @@ -944,12 +890,6 @@ public void WriteFS2IniValues(string? customFullPath = null) data["PXO"]["Login"] = pxoLogin; data["PXO"]["Password"] = pxoPassword; - bool wasWatchingIni = false; - if (iniWatcher != null) - { - wasWatchingIni = iniWatcher.EnableRaisingEvents; - iniWatcher.EnableRaisingEvents = false; - } if (customFullPath == null) { parser.WriteFile(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "fs2_open.ini", data, new UTF8Encoding(false)); @@ -961,9 +901,6 @@ public void WriteFS2IniValues(string? customFullPath = null) parser.WriteFile(customFullPath, data, new UTF8Encoding(false)); Log.Add(Log.LogSeverity.Information, "GlobalSettings.WriteFS2IniValues", "Writen ini: " + customFullPath); } - - if (iniWatcher!= null && wasWatchingIni) - iniWatcher.EnableRaisingEvents = true; } catch (Exception ex) { diff --git a/Knossos.NET/ViewModels/Windows/MainWindowViewModel.cs b/Knossos.NET/ViewModels/Windows/MainWindowViewModel.cs index 60c73d36..59ccac34 100644 --- a/Knossos.NET/ViewModels/Windows/MainWindowViewModel.cs +++ b/Knossos.NET/ViewModels/Windows/MainWindowViewModel.cs @@ -355,13 +355,8 @@ partial void OnSelectedMenuItemChanged(MainViewMenuItem? value) } Knossos.globalSettings.Load(); GlobalSettingsView?.LoadData(); - //Knossos.globalSettings.EnableIniWatch(); GlobalSettingsView?.UpdateImgCacheSize(); } - else - { - //Knossos.globalSettings.DisableIniWatch(); - } //Custom Views if (CurrentViewModel != null && CustomLauncher.IsCustomMode)