diff --git a/Torch.Server/Managers/InstanceManager.cs b/Torch.Server/Managers/InstanceManager.cs index 4e0fae6..82ad278 100644 --- a/Torch.Server/Managers/InstanceManager.cs +++ b/Torch.Server/Managers/InstanceManager.cs @@ -71,8 +71,16 @@ namespace Torch.Server.Managers foreach (var f in worldFolders) { - if (!string.IsNullOrEmpty(f) && File.Exists(Path.Combine(f, "Sandbox.sbc"))) - DedicatedConfig.Worlds.Add(new WorldViewModel(f)); + try + { + if (!string.IsNullOrEmpty(f) && File.Exists(Path.Combine(f, "Sandbox.sbc"))) + DedicatedConfig.Worlds.Add(new WorldViewModel(f)); + } + catch (Exception ex) + { + Log.Error("Failed to load world at path: " + f); + continue; + } } if (DedicatedConfig.Worlds.Count == 0) @@ -91,10 +99,19 @@ namespace Torch.Server.Managers DedicatedConfig.LoadWorld = worldPath; var worldInfo = DedicatedConfig.Worlds.FirstOrDefault(x => x.WorldPath == worldPath); - if (worldInfo?.Checkpoint == null) + try { - worldInfo = new WorldViewModel(worldPath); - DedicatedConfig.Worlds.Add(worldInfo); + if (worldInfo?.Checkpoint == null) + { + worldInfo = new WorldViewModel(worldPath); + DedicatedConfig.Worlds.Add(worldInfo); + } + } + catch (Exception ex) + { + Log.Error("Failed to load world at path: " + worldPath); + DedicatedConfig.LoadWorld = null; + return; } DedicatedConfig.SelectedWorld = worldInfo; @@ -256,11 +273,19 @@ namespace Torch.Server.Managers public WorldViewModel(string worldPath) { - WorldPath = worldPath; - WorldSizeKB = new DirectoryInfo(worldPath).GetFiles().Sum(x => x.Length) / 1024; - _checkpointPath = Path.Combine(WorldPath, "Sandbox.sbc"); - FolderName = Path.GetFileName(worldPath); - BeginLoadCheckpoint(); + try + { + WorldPath = worldPath; + WorldSizeKB = new DirectoryInfo(worldPath).GetFiles().Sum(x => x.Length) / 1024; + _checkpointPath = Path.Combine(WorldPath, "Sandbox.sbc"); + FolderName = Path.GetFileName(worldPath); + 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() diff --git a/Torch/Managers/FilesystemManager.cs b/Torch/Managers/FilesystemManager.cs index b51992e..8963bc7 100644 --- a/Torch/Managers/FilesystemManager.cs +++ b/Torch/Managers/FilesystemManager.cs @@ -24,20 +24,12 @@ namespace Torch.Managers public FilesystemManager(ITorchBase torchInstance) : base(torchInstance) { - var tmp = Path.Combine(Path.GetTempPath(), "Torch"); var torch = new FileInfo(typeof(FilesystemManager).Assembly.Location).Directory.FullName; - if (Path.GetPathRoot(tmp) == Path.GetPathRoot(torch)) - { - TempDirectory = tmp; - } - else - { - TempDirectory = Directory.CreateDirectory(Path.Combine(torch, "tmp")).FullName; - TorchDirectory = torch; + TempDirectory = Directory.CreateDirectory(Path.Combine(torch, "tmp")).FullName; + TorchDirectory = torch; - _log.Info($"Clearing tmp directory at {TempDirectory}"); - ClearTemp(); - } + _log.Debug($"Clearing tmp directory at {TempDirectory}"); + ClearTemp(); } private void ClearTemp() diff --git a/Torch/Managers/KeenLogPatch.cs b/Torch/Managers/KeenLogPatch.cs index dfa9c2a..ce9d8a9 100644 --- a/Torch/Managers/KeenLogPatch.cs +++ b/Torch/Managers/KeenLogPatch.cs @@ -76,7 +76,21 @@ namespace Torch.Managers private static StringBuilder PrepareLog(MyLog log) { - return _tmpStringBuilder.Value.Clear().Append(' ', _getIndentByThread(log, _getThreadId(log)) * 3); + try + { + var v = _tmpStringBuilder.Value; + v.Clear(); + var i = _getThreadId(log); + var t = _getIndentByThread(log, i); + v.Append(' ', t * 3); + return v; + } + catch (Exception e) + { + _log.Error(e); + return _tmpStringBuilder.Value.Clear(); + } + //return _tmpStringBuilder.Value.Clear().Append(' ', _getIndentByThread(log, _getThreadId(log)) * 3); } private static bool PrefixWriteLine(MyLog __instance, string msg) diff --git a/Torch/Plugins/PluginManager.cs b/Torch/Plugins/PluginManager.cs index fb2ce18..613354d 100644 --- a/Torch/Plugins/PluginManager.cs +++ b/Torch/Plugins/PluginManager.cs @@ -438,6 +438,9 @@ namespace Torch.Managers if (!type.GetInterfaces().Contains(typeof(ITorchPlugin))) continue; + if (type.IsAbstract) + continue; + _log.Info($"Loading plugin at {type.FullName}"); if (pluginType != null)