got it working on docker
fixed log closing exception
This commit is contained in:
@@ -1,17 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
#if TORCH_SERVICE
|
||||
using Microsoft.VisualBasic.Devices;
|
||||
#endif
|
||||
using NLog;
|
||||
using NLog.Fluent;
|
||||
using NLog.Targets;
|
||||
using Torch.Utils;
|
||||
|
||||
@@ -19,19 +7,17 @@ namespace Torch.Server
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <remarks>
|
||||
/// This method must *NOT* load any types/assemblies from the vanilla game, otherwise automatic updates will fail.
|
||||
/// </remarks>
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var isService = Environment.GetEnvironmentVariable("TORCH_SERVICE")
|
||||
?.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase) ?? false;
|
||||
Target.Register<LogViewerTarget>(nameof(LogViewerTarget));
|
||||
//Ensures that all the files are downloaded in the Torch directory.
|
||||
var workingDir = new FileInfo(typeof(Program).Assembly.Location).Directory!.FullName;
|
||||
var binDir = Path.Combine(workingDir, "DedicatedServer64");
|
||||
Directory.SetCurrentDirectory(workingDir);
|
||||
var workingDir = AppContext.BaseDirectory;
|
||||
var binDir = Path.Combine(Environment.GetEnvironmentVariable("TORCH_GAME_PATH") ?? workingDir, "DedicatedServer64");
|
||||
Directory.SetCurrentDirectory(Environment.GetEnvironmentVariable("TORCH_GAME_PATH") ?? workingDir);
|
||||
|
||||
if (Directory.Exists(binDir))
|
||||
if (!isService && Directory.Exists(binDir))
|
||||
foreach (var file in Directory.GetFiles(binDir, "System.*.dll"))
|
||||
{
|
||||
File.Delete(file);
|
||||
@@ -49,11 +35,71 @@ namespace Torch.Server
|
||||
}
|
||||
#endif
|
||||
|
||||
var initializer = new Initializer(workingDir);
|
||||
if (!initializer.Initialize(args))
|
||||
return;
|
||||
var instanceName = Environment.GetEnvironmentVariable("TORCH_INSTANCE") ?? "Instance";
|
||||
string instancePath;
|
||||
|
||||
if (Path.IsPathRooted(instanceName))
|
||||
{
|
||||
instancePath = instanceName;
|
||||
instanceName = Path.GetDirectoryName(instanceName);
|
||||
}
|
||||
else
|
||||
{
|
||||
instancePath = Path.GetFullPath(instanceName);
|
||||
}
|
||||
|
||||
initializer.Run();
|
||||
var oldTorchCfg = Path.Combine(workingDir, "Torch.cfg");
|
||||
var torchCfg = Path.Combine(instancePath, "Torch.cfg");
|
||||
|
||||
if (File.Exists(oldTorchCfg))
|
||||
File.Move(oldTorchCfg, torchCfg, true);
|
||||
|
||||
var config = Persistent<TorchConfig>.Load(torchCfg);
|
||||
config.Data.InstanceName = instanceName;
|
||||
config.Data.InstancePath = instancePath;
|
||||
if (!config.Data.Parse(args))
|
||||
{
|
||||
Console.WriteLine("Invalid arguments");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
var handler = new UnhandledExceptionHandler(config.Data, isService);
|
||||
AppDomain.CurrentDomain.UnhandledException += handler.OnUnhandledException;
|
||||
|
||||
var initializer = new Initializer(workingDir, config);
|
||||
if (!initializer.Initialize(args))
|
||||
Environment.Exit(1);
|
||||
|
||||
CopyNative(binDir);
|
||||
initializer.Run(isService, instanceName, instancePath);
|
||||
}
|
||||
|
||||
private static void CopyNative(string binPath)
|
||||
{
|
||||
var apiSource = Path.Combine(binPath, "steam_api64.dll");
|
||||
var apiTarget = Path.Combine(AppContext.BaseDirectory, "steam_api64.dll");
|
||||
if (!File.Exists(apiTarget))
|
||||
{
|
||||
File.Copy(apiSource, apiTarget);
|
||||
}
|
||||
else if (File.GetLastWriteTime(apiTarget) < File.GetLastWriteTime(binPath))
|
||||
{
|
||||
File.Delete(apiTarget);
|
||||
File.Copy(apiSource, apiTarget);
|
||||
}
|
||||
|
||||
var havokSource = Path.Combine(binPath, "Havok.dll");
|
||||
var havokTarget = Path.Combine(AppContext.BaseDirectory, "Havok.dll");
|
||||
|
||||
if (!File.Exists(havokTarget))
|
||||
{
|
||||
File.Copy(havokSource, havokTarget);
|
||||
}
|
||||
else if (File.GetLastWriteTime(havokTarget) < File.GetLastWriteTime(havokSource))
|
||||
{
|
||||
File.Delete(havokTarget);
|
||||
File.Copy(havokSource, havokTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user