tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
WindowsOpenDreamInstaller.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4
5using Microsoft.Extensions.Logging;
6using Microsoft.Extensions.Options;
7
17
19{
24 {
29
44 IIOManager ioManager,
45 ILogger<WindowsOpenDreamInstaller> logger,
47 IProcessExecutor processExecutor,
51 IOptions<GeneralConfiguration> generalConfigurationOptions,
52 IOptions<SessionConfiguration> sessionConfigurationOptions,
54 : base(
55 ioManager,
56 logger,
58 processExecutor,
62 generalConfigurationOptions,
63 sessionConfigurationOptions)
64 {
65 this.linkFactory = linkFactory ?? throw new ArgumentNullException(nameof(linkFactory));
66 }
67
69 public override ValueTask Install(EngineVersion version, string installPath, bool deploymentPipelineProcesses, CancellationToken cancellationToken)
70 {
71 var installTask = base.Install(
72 version,
73 installPath,
74 deploymentPipelineProcesses,
75 cancellationToken);
76 var firewallTask = AddServerFirewallException(
77 version,
78 installPath,
79 deploymentPipelineProcesses,
80 cancellationToken);
81
82 return ValueTaskExtensions.WhenAll(installTask, firewallTask);
83 }
84
86 protected override async ValueTask HandleExtremelyLongPathOperation(Func<string, ValueTask> shortenedPathOperation, string originalPath, CancellationToken cancellationToken)
87 {
88 var shortPath = $"C:/{Guid.NewGuid()}";
89 Logger.LogDebug("Shortening path for build from {long} to {short}...", originalPath, shortPath);
90 await linkFactory.CreateSymbolicLink(originalPath, shortPath, cancellationToken);
91 try
92 {
93 await shortenedPathOperation(shortPath);
94 }
95 finally
96 {
97 await IOManager.DeleteDirectory(shortPath, CancellationToken.None); // DCT: Should always run
98 }
99 }
100
109 async ValueTask AddServerFirewallException(EngineVersion version, string path, bool deploymentPipelineProcesses, CancellationToken cancellationToken)
110 {
112 return;
113
114 GetExecutablePaths(path, out var serverExePath, out _);
115
116 int exitCode;
117 try
118 {
119 // I really wish we could add the instance name here but
120 // 1. It'd make IByondInstaller need to be transient per-instance and WindowsByondInstaller relys on being a singleton for its DX installer call
121 // 2. The instance could be renamed, so it'd have to be an unfriendly ID anyway.
122 var ruleName = $"TGS OpenDream {version}";
123
126 Logger,
127 ruleName,
128 serverExePath,
129 deploymentPipelineProcesses && SessionConfiguration.LowPriorityDeploymentProcesses,
130 cancellationToken);
131 }
132 catch (Exception ex)
133 {
134 throw new JobException(ErrorCode.EngineFirewallFail, ex);
135 }
136
137 if (exitCode != 0)
138 throw new JobException(ErrorCode.EngineFirewallFail, new JobException($"Invalid exit code: {exitCode}"));
139 }
140 }
141}
Information about an engine installation.
Extension methods for the ValueTask and ValueTask<TResult> classes.
static async ValueTask WhenAll(IEnumerable< ValueTask > tasks)
Fully await a given list of tasks .
IIOManager IOManager
Gets the IIOManager for the EngineInstallerBase.
ILogger< EngineInstallerBase > Logger
Gets the ILogger for the EngineInstallerBase.
Implementation of IEngineInstaller for EngineType.OpenDream.
void GetExecutablePaths(string installationPath, out string serverExePath, out string compilerExePath)
Gets the paths to the server and client executables.
readonly IAbstractHttpClientFactory httpClientFactory
The IAbstractHttpClientFactory for the OpenDreamInstaller.
readonly IPlatformIdentifier platformIdentifier
The IPlatformIdentifier for the OpenDreamInstaller.
readonly IRepositoryManager repositoryManager
The IRepositoryManager for the OpenDream repository.
readonly IAsyncDelayer asyncDelayer
The IAsyncDelayer for the OpenDreamInstaller.
Implementation of OpenDreamInstaller for Windows systems.
WindowsOpenDreamInstaller(IIOManager ioManager, ILogger< WindowsOpenDreamInstaller > logger, IPlatformIdentifier platformIdentifier, IProcessExecutor processExecutor, IRepositoryManager repositoryManager, IAsyncDelayer asyncDelayer, IAbstractHttpClientFactory httpClientFactory, IOptions< GeneralConfiguration > generalConfigurationOptions, IOptions< SessionConfiguration > sessionConfigurationOptions, IFilesystemLinkFactory linkFactory)
Initializes a new instance of the WindowsOpenDreamInstaller class.
override async ValueTask HandleExtremelyLongPathOperation(Func< string, ValueTask > shortenedPathOperation, string originalPath, CancellationToken cancellationToken)
Perform an operation on a very long path.A ValueTask representing the running operation.
async ValueTask AddServerFirewallException(EngineVersion version, string path, bool deploymentPipelineProcesses, CancellationToken cancellationToken)
Attempt to add the DreamDaemon executable as an exception to the Windows firewall.
override ValueTask Install(EngineVersion version, string installPath, bool deploymentPipelineProcesses, CancellationToken cancellationToken)
Does actions necessary to get an extracted installation working.A ValueTask representing the running ...
readonly IFilesystemLinkFactory linkFactory
The IFilesystemLinkFactory for the WindowsOpenDreamInstaller.
bool SkipAddingByondFirewallException
If the netsh.exe execution to exempt DreamDaemon from Windows firewall should be skipped.
Configuration options for the game sessions.
bool LowPriorityDeploymentProcesses
If the deployment DreamMaker and DreamDaemon instances are set to be below normal priority processes.
Operation exceptions thrown from the context of a Models.Job.
Helper class for interacting with the Windows Firewall.
static async ValueTask< int > AddFirewallException(IProcessExecutor processExecutor, ILogger logger, string exceptionName, string exePath, bool lowPriority, CancellationToken cancellationToken)
Add an executable exception to the Windows firewall.
Interface for using filesystems.
Definition IIOManager.cs:13
Task DeleteDirectory(string path, CancellationToken cancellationToken)
Recursively delete a directory, removes and does not enter any symlinks encounterd.
For identifying the current platform.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
Definition ErrorCode.cs:12