2using System.Collections.Generic;
5using System.Threading.Tasks;
7using Microsoft.Extensions.Logging;
8using Microsoft.Extensions.Options;
112 IOptions<GeneralConfiguration> generalConfigurationOptions,
113 IOptions<SessionConfiguration> sessionConfigurationOptions,
114 ILogger<WindowsByondInstaller> logger)
118 generalConfiguration = generalConfigurationOptions?.Value ??
throw new ArgumentNullException(nameof(generalConfigurationOptions));
119 sessionConfiguration = sessionConfigurationOptions?.Value ??
throw new ArgumentNullException(nameof(sessionConfigurationOptions));
121 var useServiceSpecialTactics = Environment.Is64BitProcess && Environment.UserName == $
"{Environment.MachineName}$";
123 var documentsDirectory = useServiceSpecialTactics
124 ? Environment.ExpandEnvironmentVariables(
"%SystemRoot%\\SysWOW64\\config\\systemprofile\\Documents")
125 : Environment.GetFolderPath(
126 Environment.SpecialFolder.MyDocuments,
127 Environment.SpecialFolderOption.DoNotVerify);
140 public override ValueTask
Install(
EngineVersion version,
string path,
bool deploymentPipelineProcesses, CancellationToken cancellationToken)
143 ArgumentNullException.ThrowIfNull(path);
147 var tasks =
new List<ValueTask>(3)
156 tasks.Add(firewallTask);
166 ArgumentNullException.ThrowIfNull(path);
177 Logger.LogInformation(
"BYOND Version {version} needs dd.exe added to firewall", version);
184 ArgumentNullException.ThrowIfNull(version);
185 ArgumentNullException.ThrowIfNull(fullDmbPath);
195 Logger.LogDebug(
"Adding .dmb ({dmbPath}) to {trustedFilePath}", fullDmbPath, trustedFilePath);
199 string trustedFileText;
200 var filePreviouslyExisted = await
IOManager.
FileExists(trustedFilePath, cancellationToken);
201 if (filePreviouslyExisted)
204 trustedFileText = Encoding.UTF8.GetString(trustedFileBytes);
205 trustedFileText = $
"{trustedFileText.Trim()}{Environment.NewLine}";
208 trustedFileText = String.Empty;
210 if (trustedFileText.Contains(fullDmbPath, StringComparison.Ordinal))
213 trustedFileText = $
"{trustedFileText}{fullDmbPath}{Environment.NewLine}";
215 var newTrustedFileBytes = Encoding.UTF8.GetBytes(trustedFileText);
217 if (!filePreviouslyExisted)
228 return supportsCli ?
"dd.exe" :
"dreamdaemon.exe";
235 var trustedFilePath =
240 Logger.LogTrace(
"Deleting trusted .dmbs file {trustedFilePath}", trustedFilePath);
241 yield
return trustedFilePath;
256 Logger.LogTrace(
"Disabling trusted prompts in {configFilePath}...", configFilePath);
274 Logger.LogTrace(
"DirectX already installed.");
278 Logger.LogTrace(
"Installing DirectX redistributable...");
291 noShellExecute:
true);
294 using (cancellationToken.Register(() => directXInstaller.Terminate()))
295 exitCode = (await directXInstaller.Lifetime).Value;
296 cancellationToken.ThrowIfCancellationRequested();
332 var ruleName = $
"TGS DreamDaemon {version}";
Information about an engine installation.
Version? Version
The System.Version of the engine. Currently only valid when Engine is EngineType.Byond.
Extension methods for the ValueTask and ValueTask<TResult> classes.
static async ValueTask WhenAll(IEnumerable< ValueTask > tasks)
Fully await a given list of tasks .
Base implementation of IEngineInstaller for EngineType.Byond.
readonly IFileDownloader fileDownloader
The IFileDownloader for the ByondInstallerBase.
const string CfgDirectoryName
The path to the cfg directory.
const string ByondBinPath
The path to the BYOND bin folder.
void CheckVersionValidity(EngineVersion version)
Check that a given version is of type EngineType.Byond.
IIOManager IOManager
Gets the IIOManager for the EngineInstallerBase.
ILogger< EngineInstallerBase > Logger
Gets the ILogger for the EngineInstallerBase.
IEngineInstaller for windows systems.
const string ByondNoPromptTrustedMode
Setting to add to ByondDreamDaemonConfigFilename to suppress an invisible user prompt for running a t...
readonly GeneralConfiguration generalConfiguration
The GeneralConfiguration for the WindowsByondInstaller.
override string GetDreamDaemonName(Version byondVersion, out bool supportsCli)
readonly IProcessExecutor processExecutor
The IProcessExecutor for the WindowsByondInstaller.
override ValueTask Install(EngineVersion version, string path, bool deploymentPipelineProcesses, CancellationToken cancellationToken)
Does actions necessary to get an extracted installation working.A ValueTask representing the running ...
const string ByondDreamDaemonConfigFilename
BYOND's DreamDaemon config file.
const string TgsFirewalledDDFile
The file TGS uses to determine if dd.exe has been firewalled.
async ValueTask AddDreamDaemonToFirewall(EngineVersion version, string path, bool deploymentPipelineProcesses, CancellationToken cancellationToken)
Attempt to add the DreamDaemon executable as an exception to the Windows firewall.
bool installedDirectX
If DirectX was installed.
override string DreamMakerName
override string PathToUserFolder
const string ByondConfigDirectory
Directory to byond installation configuration.
const string ByondDXDir
The directory that contains the BYOND directx redistributable.
static Version DDExeVersion
The first version of BYOND to ship with dd.exe on the Windows build.
const string TrustedDmbFileName
The name of the list of trusted .dmb files in the user's BYOND cfg directory.
override string ByondRevisionsUrlTemplate
override IEnumerable< string > AdditionalCacheCleanFilePaths(string configDirectory)
List off additional file paths in the configDirectory to delete.An IEnumerable<T> of paths in config...
override async ValueTask UpgradeInstallation(EngineVersion version, string path, CancellationToken cancellationToken)
Does actions necessary to get upgrade a version installed by a previous version of TGS....
async ValueTask SetNoPromptTrusted(string path, CancellationToken cancellationToken)
Creates the BYOND cfg file that prevents the trusted mode dialog from appearing when launching DreamD...
async ValueTask InstallDirectX(string path, CancellationToken cancellationToken)
Attempt to install the DirectX redistributable included with BYOND.
readonly SessionConfiguration sessionConfiguration
The SessionConfiguration for the WindowsByondInstaller.
readonly SemaphoreSlim semaphore
The SemaphoreSlim for the WindowsByondInstaller.
override async ValueTask TrustDmbPath(EngineVersion version, string fullDmbPath, CancellationToken cancellationToken)
Add a given fullDmbPath to the trusted DMBs list in BYOND's config.A ValueTask representing the runn...
WindowsByondInstaller(IProcessExecutor processExecutor, IIOManager ioManager, IFileDownloader fileDownloader, IOptions< GeneralConfiguration > generalConfigurationOptions, IOptions< SessionConfiguration > sessionConfigurationOptions, ILogger< WindowsByondInstaller > logger)
Initializes a new instance of the WindowsByondInstaller class.
static readonly SemaphoreSlim UserFilesSemaphore
SemaphoreSlim for writing to files in the user's BYOND directory.
General configuration options.
bool SkipAddingByondFirewallException
If the netsh.exe execution to exempt DreamDaemon from Windows firewall should be skipped.
Configuration options for the game sessions.
bool ForceUseDreamDaemonExe
If set dd.exe will not be used on Windows systems in versions where it is present....
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.
Async lock context helper.
static async ValueTask< SemaphoreSlimContext > Lock(SemaphoreSlim semaphore, CancellationToken cancellationToken, ILogger? logger=null)
Asyncronously locks a semaphore .
Interface for using filesystems.
string ResolvePath()
Retrieve the full path of the current working directory.
ValueTask< byte[]> ReadAllBytes(string path, CancellationToken cancellationToken)
Returns all the contents of a file at path as a byte array.
string ConcatPath(params string[] paths)
Combines an array of strings into a path.
Task CreateDirectory(string path, CancellationToken cancellationToken)
Create a directory at path .
ValueTask WriteAllBytes(string path, byte[] contents, CancellationToken cancellationToken)
Writes some contents to a file at path overwriting previous content.
Task< bool > FileExists(string path, CancellationToken cancellationToken)
Check that the file at path exists.
ValueTask< IProcess > LaunchProcess(string fileName, string workingDirectory, string arguments, CancellationToken cancellationToken, IReadOnlyDictionary< string, string >? environment=null, string? fileRedirect=null, bool readStandardHandles=false, bool noShellExecute=false)
Launch a IProcess.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.