-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathProgram.cs
More file actions
88 lines (81 loc) · 2.86 KB
/
Program.cs
File metadata and controls
88 lines (81 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Reflection;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using Microsoft.VisualBasic.Devices;
using NLog;
using NLog.Fluent;
using NLog.Targets;
using Torch.Utils;
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)
{
Target.Register<FlowDocumentTarget>("FlowDocument");
//Ensures that all the files are downloaded in the Torch directory.
var workingDir = new FileInfo(typeof(Program).Assembly.Location).Directory.ToString();
var binDir = Path.Combine(workingDir, "DedicatedServer64");
Directory.SetCurrentDirectory(workingDir);
//HACK for block skins update
var badDlls = new[]
{
"System.Security.Principal.Windows.dll",
"VRage.Platform.Windows.dll"
};
try
{
foreach (var file in badDlls)
{
if (File.Exists(file))
File.Delete(file);
}
}
catch (Exception e)
{
var log = LogManager.GetCurrentClassLogger();
log.Error($"Error updating. Please delete the following files from the Torch root folder manually:\r\n{string.Join("\r\n", badDlls)}");
log.Error(e);
return;
}
try
{
if (!TorchLauncher.IsTorchWrapped())
{
TorchLauncher.Launch(Assembly.GetEntryAssembly().FullName, args, binDir);
return;
}
// Breaks on Windows Server 2019
if ((!new ComputerInfo().OSFullName.Contains("Server 2019") &&
!new ComputerInfo().OSFullName.Contains("Server 2022") &&
!new ComputerInfo().OSFullName.Contains("Server 2025")) &&
!Environment.UserInteractive)
{
using (var service = new TorchService(args))
ServiceBase.Run(service);
return;
}
var initializer = new Initializer(workingDir);
if (!initializer.Initialize(args))
return;
initializer.Run();
} catch (Exception runException)
{
var log = LogManager.GetCurrentClassLogger();
log.Fatal(runException.ToString());
return;
}
}
}
}