diff --git a/Torch.Server/Managers/InstanceManager.cs b/Torch.Server/Managers/InstanceManager.cs index e08ce0d2..57885062 100644 --- a/Torch.Server/Managers/InstanceManager.cs +++ b/Torch.Server/Managers/InstanceManager.cs @@ -199,12 +199,12 @@ private void ImportWorldConfig(bool modsOnly = true) } } - public void SaveConfig() + public bool SaveConfig() { if (((TorchServer)Torch).HasRun) { Log.Warn("Checkpoint cache is stale, not saving dedicated config."); - return; + return false; } DedicatedConfig.Save(Path.Combine(Torch.Config.InstancePath, CONFIG_NAME)); @@ -238,6 +238,8 @@ public void SaveConfig() Log.Error("Failed to write sandbox config, changes will not appear on server"); Log.Error(e); } + + return true; } /// diff --git a/Torch.Server/Views/ConfigControl.xaml.cs b/Torch.Server/Views/ConfigControl.xaml.cs index 0441683d..41e94bc4 100644 --- a/Torch.Server/Views/ConfigControl.xaml.cs +++ b/Torch.Server/Views/ConfigControl.xaml.cs @@ -41,7 +41,8 @@ public ConfigControl(TorchServer server) _server.PropertyChanged += (sender, args) => { - if (args.PropertyName == nameof(TorchServer.CanRun)) + if (args.PropertyName == nameof(TorchServer.CanRun) || + args.PropertyName == nameof(TorchServer.HasRun)) { Dispatcher.Invoke(SetReadOnly); } @@ -166,58 +167,59 @@ private void RoleEdit_Onlick(object sender, RoutedEventArgs e) private void SetReadOnly() { + // Config is only editable before the first start of the session. After the server + // has run the checkpoint is stale and saving is blocked, so the + // entire panel is locked even after a stop. + bool editable = _server.CanRun && !_server.HasRun; + foreach (var textbox in GetAllChildren(this)) { - // Don't make inherently read-only textboxes editable - // (e.g., AnalyticsToken with ReadOnly=true in DisplayAttribute) - if (!_server.CanRun) - textbox.IsReadOnly = true; - // Only make editable if it wasn't marked as inherently read-only - // We use Tag to track this - PropertyGrid doesn't set Tag on TextBoxes - else if (textbox.Tag as string != "InherentlyReadOnly") - { - // Check if this is the first time and textbox is already read-only - // If so, mark it as inherently read-only - if (textbox.IsReadOnly && textbox.Tag == null) - textbox.Tag = "InherentlyReadOnly"; - else - textbox.IsReadOnly = false; - } + // Track fields that are inherently read-only (Such as AnalyticsToken) + // so they stay read-only even when the panel is editable. + if (textbox.IsReadOnly && textbox.Tag == null) + textbox.Tag = "InherentlyReadOnly"; + + bool inherentlyReadOnly = textbox.Tag as string == "InherentlyReadOnly"; + + // Gray out when the panel is locked, otherwise enable- but keep + // inherently-read-only fields non-editable. + textbox.IsEnabled = editable; + textbox.IsReadOnly = !editable || inherentlyReadOnly; } foreach (var button in GetAllChildren