Add error handling to world view loading
This commit is contained in:
@@ -70,10 +70,18 @@ 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)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(f) && File.Exists(Path.Combine(f, "Sandbox.sbc")))
|
if (!string.IsNullOrEmpty(f) && File.Exists(Path.Combine(f, "Sandbox.sbc")))
|
||||||
DedicatedConfig.Worlds.Add(new WorldViewModel(f));
|
DedicatedConfig.Worlds.Add(new WorldViewModel(f));
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error("Failed to load world at path: " + f);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (DedicatedConfig.Worlds.Count == 0)
|
if (DedicatedConfig.Worlds.Count == 0)
|
||||||
{
|
{
|
||||||
@@ -91,11 +99,20 @@ namespace Torch.Server.Managers
|
|||||||
DedicatedConfig.LoadWorld = worldPath;
|
DedicatedConfig.LoadWorld = worldPath;
|
||||||
|
|
||||||
var worldInfo = DedicatedConfig.Worlds.FirstOrDefault(x => x.WorldPath == worldPath);
|
var worldInfo = DedicatedConfig.Worlds.FirstOrDefault(x => x.WorldPath == worldPath);
|
||||||
|
try
|
||||||
|
{
|
||||||
if (worldInfo?.Checkpoint == null)
|
if (worldInfo?.Checkpoint == null)
|
||||||
{
|
{
|
||||||
worldInfo = new WorldViewModel(worldPath);
|
worldInfo = new WorldViewModel(worldPath);
|
||||||
DedicatedConfig.Worlds.Add(worldInfo);
|
DedicatedConfig.Worlds.Add(worldInfo);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error("Failed to load world at path: " + worldPath);
|
||||||
|
DedicatedConfig.LoadWorld = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DedicatedConfig.SelectedWorld = worldInfo;
|
DedicatedConfig.SelectedWorld = worldInfo;
|
||||||
if (DedicatedConfig.SelectedWorld?.Checkpoint != null)
|
if (DedicatedConfig.SelectedWorld?.Checkpoint != null)
|
||||||
@@ -255,6 +272,8 @@ namespace Torch.Server.Managers
|
|||||||
public CheckpointViewModel Checkpoint { get; private set; }
|
public CheckpointViewModel Checkpoint { get; private set; }
|
||||||
|
|
||||||
public WorldViewModel(string worldPath)
|
public WorldViewModel(string worldPath)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
WorldPath = worldPath;
|
WorldPath = worldPath;
|
||||||
WorldSizeKB = new DirectoryInfo(worldPath).GetFiles().Sum(x => x.Length) / 1024;
|
WorldSizeKB = new DirectoryInfo(worldPath).GetFiles().Sum(x => x.Length) / 1024;
|
||||||
@@ -262,6 +281,12 @@ namespace Torch.Server.Managers
|
|||||||
FolderName = Path.GetFileName(worldPath);
|
FolderName = Path.GetFileName(worldPath);
|
||||||
BeginLoadCheckpoint();
|
BeginLoadCheckpoint();
|
||||||
}
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
Log.Error($"World view model failed to load the path: {worldPath} Please ensure this is a valid path.");
|
||||||
|
throw; //rethrow to be handled further up the stack
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task SaveCheckpointAsync()
|
public async Task SaveCheckpointAsync()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user