Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Torch.Server/Managers/InstanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ private void ImportWorldConfig(bool modsOnly = true)
}
}

public bool SaveConfig()
public void SaveConfig()
{
if (((TorchServer)Torch).HasRun)
{
Log.Warn("Checkpoint cache is stale, not saving dedicated config.");
return false;
return;
}

DedicatedConfig.Save(Path.Combine(Torch.Config.InstancePath, CONFIG_NAME));
Expand Down Expand Up @@ -238,8 +238,6 @@ public bool SaveConfig()
Log.Error("Failed to write sandbox config, changes will not appear on server");
Log.Error(e);
}

return true;
}

/// <summary>
Expand Down
48 changes: 23 additions & 25 deletions Torch.Server/Views/ConfigControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public ConfigControl(TorchServer server)

_server.PropertyChanged += (sender, args) =>
{
if (args.PropertyName == nameof(TorchServer.CanRun) ||
args.PropertyName == nameof(TorchServer.HasRun))
if (args.PropertyName == nameof(TorchServer.CanRun))
{
Dispatcher.Invoke(SetReadOnly);
}
Expand Down Expand Up @@ -167,59 +166,58 @@ 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<TextBox>(this))
{
// 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;
// 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;
}
}

foreach (var button in GetAllChildren<Button>(this))
{
button.IsEnabled = editable;
button.IsEnabled = _server.CanRun;
}

foreach (var comboBox in GetAllChildren<ComboBox>(this))
{
comboBox.IsEnabled = editable;
comboBox.IsEnabled = _server.CanRun;
}

foreach (var slider in GetAllChildren<Slider>(this))
{
slider.IsEnabled = editable;
slider.IsEnabled = _server.CanRun;
}

foreach (var checkbox in GetAllChildren<CheckBox>(this))
{
checkbox.IsEnabled = editable;
checkbox.IsEnabled = _server.CanRun;
}

foreach (var toggleButton in GetAllChildren<ToggleButton>(this))
{
toggleButton.IsEnabled = editable;
toggleButton.IsEnabled = _server.CanRun;
}

foreach (var radioButton in GetAllChildren<RadioButton>(this))
{
radioButton.IsEnabled = editable;
radioButton.IsEnabled = _server.CanRun;
}

foreach (var listBox in GetAllChildren<ListBox>(this))
{
listBox.IsEnabled = editable;
listBox.IsEnabled = _server.CanRun;
}
}
}
Expand Down
Loading