2using System.Collections.Generic;
3using System.Globalization;
6using System.Threading.Tasks;
8using Microsoft.Extensions.Logging;
9using Microsoft.Extensions.Options;
79 internal static Uri GetDownloadZipUrl(Version semver,
string byondZipDownloadTemplate,
string osMarkerTemplate)
82 var guardGuid = Guid.NewGuid();
84 var url = byondZipDownloadTemplate
85 .Replace(
"$$", guardGuid.ToString(), StringComparison.Ordinal)
86 .Replace(
"${Major}", semver.Major.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal)
87 .Replace(
"${Minor}", semver.Minor.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal);
89 var osMarkerPrefix = $
"${{{osMarkerTemplate}:";
90 var osMarkerIndex = url.IndexOf(osMarkerPrefix);
91 while (osMarkerIndex != -1)
93 var start = osMarkerIndex + osMarkerPrefix.Length;
94 var end = url.IndexOf(
'}', start);
98 var substitution = url.Substring(start, end - start);
99 url = url.Replace($
"{osMarkerPrefix}{substitution}}}", substitution, StringComparison.Ordinal);
101 osMarkerIndex = url.IndexOf(osMarkerPrefix);
105 var otherMarkerPrefix =
"${";
106 var otherMarkerIndex = url.IndexOf(otherMarkerPrefix);
107 while (otherMarkerIndex != -1)
109 var start = otherMarkerIndex + otherMarkerPrefix.Length;
110 var end = url.IndexOf(
'}', start);
114 var substitution = url.Substring(start, end - start);
115 url = url.Replace($
"{otherMarkerPrefix}{substitution}}}", String.Empty, StringComparison.Ordinal);
117 otherMarkerIndex = url.IndexOf(otherMarkerPrefix);
120 url = url.Replace(guardGuid.ToString(),
"$", StringComparison.Ordinal);
134 ILogger<ByondInstallerBase> logger,
136 IOptionsMonitor<GeneralConfiguration> generalConfigurationOptions)
137 : base(ioManager, logger)
144 public sealed override ValueTask<IEngineInstallation>
GetInstallation(
EngineVersion version,
string path, Task installationTask, CancellationToken cancellationToken)
153 out var supportsCli);
154 var dreamDaemonPath = installationIOManager.ResolvePath(
155 installationIOManager.ConcatPath(
158 var dreamMakerPath = installationIOManager.ResolvePath(
159 installationIOManager.ConcatPath(
165 installationIOManager,
171 supportsMapThreads));
175 public sealed override async Task
CleanCache(CancellationToken cancellationToken)
181 Logger.LogDebug(
"Cleaning BYOND cache...");
182 async Task CleanDirectorySafe()
194 Logger.LogWarning(ex,
"Failed to clean BYOND cache!");
198 var cacheCleanTask = CleanDirectorySafe();
212 await Task.WhenAll(cacheCleanTask, cfgCreateTask, Task.WhenAll(additionalCleanTasks));
214 catch (
Exception ex) when (ex is not OperationCanceledException)
216 Logger.LogWarning(ex,
"Error cleaning BYOND cache!");
225 var url = GetDownloadZipUrl(version);
226 Logger.LogTrace(
"Downloading {engineType} version {version} from {url}...",
TargetEngineType, version, url);
230 await download.GetResult(cancellationToken));
232 var stream = await buffer.GetOwnedResult(cancellationToken);
241 await stream.DisposeAsync();
270 var guardGuid = Guid.NewGuid();
Information about an engine installation.
Version? Version
The System.Version of the engine. Currently only valid when Engine is EngineType.Byond.
Implementation of IEngineInstallation for EngineType.Byond.
Base implementation of IEngineInstaller for EngineType.Byond.
readonly IFileDownloader fileDownloader
The IFileDownloader for the ByondInstallerBase.
string GetDreamDaemonName(Version byondVersion, out bool supportsCli)
Get the file name of the DreamDaemon executable.
const string CacheDirectoryName
The name of BYOND's cache directory.
const string CfgDirectoryName
The path to the cfg directory.
string OSMarkerTemplate
Template to do ${Marker:xxx} replacements in GeneralConfiguration.ByondZipDownloadTemplate.
static readonly Version MapThreadsVersion
The first Version of BYOND that supports the '-map-threads' parameter on DreamDaemon.
const string ByondBinPath
The path to the BYOND bin folder.
override ValueTask< IEngineInstallation > GetInstallation(EngineVersion version, string path, Task installationTask, CancellationToken cancellationToken)
Creates an IEngineInstallation for a given version .A ValueTask<TResult> resulting in a new IEngineIn...
virtual IEnumerable< string > AdditionalCacheCleanFilePaths(string configDirectory)
List off additional file paths in the configDirectory to delete.
ByondInstallerBase(IIOManager ioManager, ILogger< ByondInstallerBase > logger, IFileDownloader fileDownloader, IOptionsMonitor< GeneralConfiguration > generalConfigurationOptions)
Initializes a new instance of the ByondInstallerBase class.
override async Task CleanCache(CancellationToken cancellationToken)
Attempts to cleans the engine's cache folder for the system.A Task representing the running operation...
Uri GetDownloadZipUrl(EngineVersion version)
Create a Uri pointing to the location of the download for a given version .
override EngineType TargetEngineType
string PathToUserFolder
Path to the system user's local BYOND folder.
override async ValueTask< IEngineInstallationData > DownloadVersion(EngineVersion version, JobProgressReporter progressReporter, CancellationToken cancellationToken)
Download a given engine version .A ValueTask<TResult> resulting in the IEngineInstallationData for th...
string DreamMakerName
Path to the DreamMaker executable.
IOptionsMonitor< GeneralConfiguration > GeneralConfigurationOptions
The GeneralConfiguration IOptionsMonitor<TOptions> for the ByondInstallerBase.
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.
Implementation of IEngineInstallationData for a zip file in a Stream.
IFileStreamProvider that provides a ISeekableFileStreamProvider from an input Stream.
Progress reporter for a Job.
Represents a BYOND installation.
IFileStreamProvider DownloadFile(Uri url, string? bearerToken)
Downloads a file from a given url .
Interface for using filesystems.
string ConcatPath(params string[] paths)
Combines an array of strings into a path.
Task CreateDirectory(string path, CancellationToken cancellationToken)
Create a directory at path .
Task DeleteFile(string path, CancellationToken cancellationToken)
Deletes a file at path .
IIOManager CreateResolverForSubdirectory(string subdirectoryPath)
Create a new IIOManager that resolves paths to the specified subdirectoryPath .
Task DeleteDirectory(string path, CancellationToken cancellationToken)
Recursively delete a directory, removes and does not enter any symlinks encounterd.
EngineType
The type of engine the codebase is using.