Merge branch 'master' into Patron

This commit is contained in:
Brant Martin
2019-06-16 08:31:35 -04:00
4 changed files with 57 additions and 23 deletions

View File

@@ -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()

View File

@@ -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()

View File

@@ -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)

View File

@@ -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)