Update NLog, change init order, fix block delete in UI, change config to JSON

This commit is contained in:
John Gross
2017-07-18 17:31:08 -07:00
parent 17ee96038c
commit 96d1faddbe
13 changed files with 70 additions and 66 deletions

View File

@@ -30,5 +30,10 @@ namespace Torch.API.Managers
/// Disposes all loaded plugins.
/// </summary>
void DisposePlugins();
/// <summary>
/// Load plugins.
/// </summary>
void LoadPlugins();
}
}

View File

@@ -56,6 +56,8 @@ namespace Torch.Server.Managers
Directory.CreateDirectory(savesPath);
var modsPath = Path.Combine(path, "Mods");
Directory.CreateDirectory(modsPath);
var configPath = Path.Combine(path, "SpaceEngineers-Dedicated.cfg");
new MyConfigDedicated<MyObjectBuilder_SessionSettings>(configPath).Save();
LoadInstance(path);
}
}

View File

@@ -23,6 +23,7 @@ using Torch.Server.Views;
using VRage.Game.ModAPI;
using System.IO.Compression;
using System.Net;
using System.Security.Policy;
using Torch.Server.Managers;
using VRage.FileSystem;
using VRageRender;
@@ -61,37 +62,22 @@ namespace Torch.Server
return;
}
var configName = "TorchConfig.xml";
var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);
if (File.Exists(configName))
//CommandLine reflection triggers assembly loading, so DS update must be completely separated.
if (!args.Contains("-noupdate"))
{
_log.Info($"Loading config {configPath}");
_config = TorchConfig.LoadFrom(configPath);
}
else
{
_log.Info($"Generating default config at {configPath}");
_config = new TorchConfig {InstancePath = Path.GetFullPath("Instance")};
_log.Warn("Would you like to enable automatic updates? (Y/n):");
var input = Console.ReadLine() ?? "";
var autoUpdate = string.IsNullOrEmpty(input) || input.Equals("y", StringComparison.InvariantCultureIgnoreCase);
_config.GetTorchUpdates = _config.GetPluginUpdates = autoUpdate;
if (autoUpdate)
if (!Directory.Exists("DedicatedServer64"))
{
_log.Info("Automatic updates enabled.");
RunSteamCmd();
_log.Error("Game libraries not found. Press the Enter key to install the dedicated server.");
Console.ReadLine();
}
_config.Save(configPath);
RunSteamCmd();
}
InitConfig();
if (!_config.Parse(args))
return;
_log.Debug(_config.ToString());
if (!string.IsNullOrEmpty(_config.WaitForPID))
{
try
@@ -110,14 +96,26 @@ namespace Torch.Server
}
_restartOnCrash = _config.RestartOnCrash;
if (_config.GetTorchUpdates || _config.Update)
{
RunSteamCmd();
}
RunServer(_config);
}
public static void InitConfig()
{
var configName = "Torch.cfg";
var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);
if (File.Exists(configName))
{
_log.Info($"Loading config {configPath}");
_config = TorchConfig.LoadFrom(configPath);
}
else
{
_log.Info($"Generating default config at {configPath}");
_config = new TorchConfig { InstancePath = Path.GetFullPath("Instance") };
_config.Save(configPath);
}
}
private const string STEAMCMD_DIR = "steamcmd";
private const string STEAMCMD_ZIP = "temp.zip";
private static readonly string STEAMCMD_PATH = $"{STEAMCMD_DIR}\\steamcmd.exe";

View File

@@ -59,9 +59,11 @@
<HintPath>..\GameBinaries\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.4.1\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\NLog.4.4.11\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="Sandbox.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Xml.Serialization;
using Newtonsoft.Json;
using NLog;
namespace Torch.Server
@@ -16,11 +17,11 @@ namespace Torch.Server
public string InstancePath { get; set; }
/// <inheritdoc />
[XmlIgnore, Arg("noupdate", "Disable automatically downloading game and plugin updates.")]
[JsonIgnore, Arg("noupdate", "Disable automatically downloading game and plugin updates.")]
public bool NoUpdate { get => false; set => GetTorchUpdates = GetPluginUpdates = !value; }
/// <inheritdoc />
[XmlIgnore, Arg("update", "Manually check for and install updates.")]
[JsonIgnore, Arg("update", "Manually check for and install updates.")]
public bool Update { get; set; }
/// <inheritdoc />
@@ -36,7 +37,7 @@ namespace Torch.Server
public bool NoGui { get; set; }
/// <inheritdoc />
[XmlIgnore, Arg("waitforpid", "Makes Torch wait for another process to exit.")]
[JsonIgnore, Arg("waitforpid", "Makes Torch wait for another process to exit.")]
public string WaitForPID { get; set; }
/// <inheritdoc />
@@ -53,33 +54,26 @@ namespace Torch.Server
public int TickTimeout { get; set; } = 60;
/// <inheritdoc />
public List<string> Plugins { get; set; } = new List<string>();
public List<string> Plugins { get; set; } = new List<string> {"TorchAPI/Concealment", "TorchAPI/Essentials"};
internal Point WindowSize { get; set; } = new Point(800, 600);
internal Point WindowPosition { get; set; } = new Point();
[NonSerialized]
[JsonIgnore]
private string _path;
public TorchConfig() : this("Torch") { }
public TorchConfig(string instanceName = "Torch", string instancePath = null, int autosaveInterval = 5, bool autoRestart = false)
public TorchConfig(string instanceName = "Torch", string instancePath = null)
{
InstanceName = instanceName;
InstancePath = instancePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SpaceEngineersDedicated");
//Autosave = autosaveInterval;
//AutoRestart = autoRestart;
}
public static TorchConfig LoadFrom(string path)
{
try
{
var serializer = new XmlSerializer(typeof(TorchConfig));
TorchConfig config;
using (var f = File.OpenRead(path))
{
config = (TorchConfig)serializer.Deserialize(f);
}
var config = JsonConvert.DeserializeObject<TorchConfig>(File.ReadAllText(path));
config._path = path;
return config;
}
@@ -99,11 +93,8 @@ namespace Torch.Server
try
{
var serializer = new XmlSerializer(typeof(TorchConfig));
using (var f = File.Create(path))
{
serializer.Serialize(f, this);
}
var str = JsonConvert.SerializeObject(this);
File.WriteAllText(path, str);
return true;
}
catch (Exception e)

View File

@@ -18,6 +18,7 @@ using Sandbox.ModAPI;
using SteamSDK;
using Torch.API;
using Torch.Managers;
using Torch.Server.Managers;
using VRage.Dedicated;
using VRage.FileSystem;
using VRage.Game;
@@ -55,6 +56,7 @@ namespace Torch.Server
public TorchServer(TorchConfig config = null)
{
AddManager(new ConfigManager(this));
Config = config ?? new TorchConfig();
MyFakes.ENABLE_INFINARIO = false;
}
@@ -85,7 +87,11 @@ namespace Torch.Server
MyPlugins.RegisterSandboxGameAssemblyFile(MyPerGameSettings.SandboxGameAssembly);
MyPlugins.Load();
MyGlobalTypeMetadata.Static.Init();
RuntimeHelpers.RunClassConstructor(typeof(MyObjectBuilder_Base).TypeHandle);
if (!Directory.Exists(Config.InstancePath))
GetManager<ConfigManager>().CreateInstance(Config.InstancePath);
Plugins.LoadPlugins();
}
private void InvokeBeforeRun()

View File

@@ -50,6 +50,12 @@ namespace Torch.Server.ViewModels.Blocks
public override bool CanStop => false;
/// <inheritdoc />
public override void Delete()
{
Block.CubeGrid.RazeBlock(Block.Position);
}
public BlockViewModel(IMyTerminalBlock block, EntityTreeViewModel tree) : base(block, tree)
{
Block = block;

View File

@@ -37,6 +37,11 @@ namespace Torch.Server.ViewModels.Entities
public virtual bool CanDelete => !(Entity is IMyCharacter);
public virtual void Delete()
{
Entity.Close();
}
public EntityViewModel(IMyEntity entity, EntityTreeViewModel tree)
{
Entity = entity;

View File

@@ -60,7 +60,7 @@ namespace Torch.Server.Views
{
if (Entities.CurrentEntity?.Entity is IMyCharacter)
return;
TorchBase.Instance.Invoke(() => Entities.CurrentEntity?.Entity.Close());
TorchBase.Instance.Invoke(() => Entities.CurrentEntity?.Delete());
}
private void Stop_OnClick(object sender, RoutedEventArgs e)

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Extended.Wpf.Toolkit" version="2.9" targetFramework="net461" />
<package id="NLog" version="4.4.1" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
<package id="NLog" version="4.4.11" targetFramework="net461" />
</packages>

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
@@ -14,7 +13,7 @@ namespace Torch
private readonly string _argPrefix;
private readonly Dictionary<ArgAttribute, PropertyInfo> _args = new Dictionary<ArgAttribute, PropertyInfo>();
public CommandLine(string argPrefix = "-")
protected CommandLine(string argPrefix = "-")
{
_argPrefix = argPrefix;
foreach (var prop in GetType().GetProperties())

View File

@@ -85,7 +85,7 @@ namespace Torch.Managers
}
/// <inheritdoc />
public override void Init()
public void LoadPlugins()
{
_updateManager = Torch.GetManager<UpdateManager>();
var commands = Torch.GetManager<CommandManager>();

View File

@@ -226,16 +226,6 @@ namespace Torch
SpaceEngineersGame.SetupBasicGameInfo();
SpaceEngineersGame.SetupPerGameSettings();
/*
if (Directory.Exists("DedicatedServer64"))
{
Log.Debug("Inserting DedicatedServer64 before MyPerGameSettings assembly paths");
MyPerGameSettings.GameModAssembly = $"DedicatedServer64\\{MyPerGameSettings.GameModAssembly}";
MyPerGameSettings.GameModObjBuildersAssembly = $"DedicatedServer64\\{MyPerGameSettings.GameModObjBuildersAssembly}";
MyPerGameSettings.SandboxAssembly = $"DedicatedServer64\\{MyPerGameSettings.SandboxAssembly}";
MyPerGameSettings.SandboxGameAssembly = $"DedicatedServer64\\{MyPerGameSettings.SandboxGameAssembly}";
}*/
TorchVersion = Assembly.GetEntryAssembly().GetName().Version;
GameVersion = new Version(new MyVersion(MyPerGameSettings.BasicGameInfo.GameVersion.Value).FormattedText.ToString().Replace("_", "."));
var verInfo = $"Torch {TorchVersion}, SE {GameVersion}";