Add validation for world load settings
This commit is contained in:
@@ -67,7 +67,10 @@ namespace Torch.Server.Managers
|
|||||||
var worldFolders = Directory.EnumerateDirectories(Path.Combine(Torch.Config.InstancePath, "Saves"));
|
var worldFolders = Directory.EnumerateDirectories(Path.Combine(Torch.Config.InstancePath, "Saves"));
|
||||||
|
|
||||||
foreach (var f in worldFolders)
|
foreach (var f in worldFolders)
|
||||||
DedicatedConfig.Worlds.Add(new WorldViewModel(f));
|
{
|
||||||
|
if (!string.IsNullOrEmpty(f) && File.Exists(Path.Combine(f, "Sandbox.sbc")))
|
||||||
|
DedicatedConfig.Worlds.Add(new WorldViewModel(f));
|
||||||
|
}
|
||||||
|
|
||||||
if (DedicatedConfig.Worlds.Count == 0)
|
if (DedicatedConfig.Worlds.Count == 0)
|
||||||
{
|
{
|
||||||
@@ -196,6 +199,8 @@ namespace Torch.Server.Managers
|
|||||||
|
|
||||||
public class WorldViewModel : ViewModel
|
public class WorldViewModel : ViewModel
|
||||||
{
|
{
|
||||||
|
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public string FolderName { get; set; }
|
public string FolderName { get; set; }
|
||||||
public string WorldPath { get; }
|
public string WorldPath { get; }
|
||||||
public long WorldSizeKB { get; }
|
public long WorldSizeKB { get; }
|
||||||
@@ -224,6 +229,7 @@ namespace Torch.Server.Managers
|
|||||||
{
|
{
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
|
Log.Info($"Preloading checkpoint {_checkpointPath}");
|
||||||
MyObjectBuilderSerializer.DeserializeXML(_checkpointPath, out MyObjectBuilder_Checkpoint checkpoint);
|
MyObjectBuilderSerializer.DeserializeXML(_checkpointPath, out MyObjectBuilder_Checkpoint checkpoint);
|
||||||
Checkpoint = new CheckpointViewModel(checkpoint);
|
Checkpoint = new CheckpointViewModel(checkpoint);
|
||||||
OnPropertyChanged(nameof(Checkpoint));
|
OnPropertyChanged(nameof(Checkpoint));
|
||||||
|
@@ -15,7 +15,7 @@ namespace Torch.Server.ViewModels
|
|||||||
{
|
{
|
||||||
public class ConfigDedicatedViewModel : ViewModel
|
public class ConfigDedicatedViewModel : ViewModel
|
||||||
{
|
{
|
||||||
private static readonly Logger Log = LogManager.GetLogger("Config");
|
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
private MyConfigDedicated<MyObjectBuilder_SessionSettings> _config;
|
private MyConfigDedicated<MyObjectBuilder_SessionSettings> _config;
|
||||||
public MyConfigDedicated<MyObjectBuilder_SessionSettings> Model => _config;
|
public MyConfigDedicated<MyObjectBuilder_SessionSettings> Model => _config;
|
||||||
|
|
||||||
@@ -33,11 +33,30 @@ namespace Torch.Server.ViewModels
|
|||||||
|
|
||||||
public void Save(string path = null)
|
public void Save(string path = null)
|
||||||
{
|
{
|
||||||
|
Validate();
|
||||||
|
|
||||||
// Never ever
|
// Never ever
|
||||||
_config.IgnoreLastSession = true;
|
_config.IgnoreLastSession = true;
|
||||||
_config.Save(path);
|
_config.Save(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Validate()
|
||||||
|
{
|
||||||
|
if (SelectedWorld == null)
|
||||||
|
{
|
||||||
|
Log.Warn($"{nameof(SelectedWorld)} == null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LoadWorld == null)
|
||||||
|
{
|
||||||
|
Log.Warn($"{nameof(LoadWorld)} == null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private SessionSettingsViewModel _sessionSettings;
|
private SessionSettingsViewModel _sessionSettings;
|
||||||
public SessionSettingsViewModel SessionSettings { get => _sessionSettings; set { _sessionSettings = value; OnPropertyChanged(); } }
|
public SessionSettingsViewModel SessionSettings { get => _sessionSettings; set { _sessionSettings = value; OnPropertyChanged(); } }
|
||||||
|
|
||||||
@@ -49,7 +68,7 @@ namespace Torch.Server.ViewModels
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
SetValue(ref _selectedWorld, value);
|
SetValue(ref _selectedWorld, value);
|
||||||
LoadWorld = _selectedWorld.WorldPath;
|
LoadWorld = _selectedWorld?.WorldPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user