tgstation-server 5.12.7
The /tg/station 13 server suite
Loading...
Searching...
No Matches
ByondInstallerBase.cs
Go to the documentation of this file.
1using System;
2using System.Globalization;
3using System.IO;
4using System.Threading;
5using System.Threading.Tasks;
6
7using Microsoft.Extensions.Logging;
8
10
12{
15 {
19 const string CacheDirectoryName = "cache";
20
22 public abstract string DreamMakerName { get; }
23
25 public abstract string PathToUserByondFolder { get; }
26
30 protected abstract string ByondRevisionsUrlTemplate { get; }
31
35 protected IIOManager IOManager { get; }
36
40 protected ILogger<ByondInstallerBase> Logger { get; }
41
46
53 protected ByondInstallerBase(IIOManager ioManager, IFileDownloader fileDownloader, ILogger<ByondInstallerBase> logger)
54 {
55 IOManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
56 this.fileDownloader = fileDownloader ?? throw new ArgumentNullException(nameof(fileDownloader));
57 Logger = logger ?? throw new ArgumentNullException(nameof(logger));
58 }
59
61 public abstract string GetDreamDaemonName(Version version, out bool supportsCli);
62
64 public async Task CleanCache(CancellationToken cancellationToken)
65 {
66 try
67 {
68 Logger.LogDebug("Cleaning BYOND cache...");
73 cancellationToken);
74 }
75 catch (OperationCanceledException)
76 {
77 throw;
78 }
79 catch (Exception e)
80 {
81 Logger.LogWarning(e, "Error deleting BYOND cache!");
82 }
83 }
84
86 public abstract Task InstallByond(Version version, string path, CancellationToken cancellationToken);
87
89 public abstract Task UpgradeInstallation(Version version, string path, CancellationToken cancellationToken);
90
92 public async Task<MemoryStream> DownloadVersion(Version version, CancellationToken cancellationToken)
93 {
94 ArgumentNullException.ThrowIfNull(version);
95
96 Logger.LogTrace("Downloading BYOND version {major}.{minor}...", version.Major, version.Minor);
97 var url = String.Format(CultureInfo.InvariantCulture, ByondRevisionsUrlTemplate, version.Major, version.Minor);
98
99 await using var download = fileDownloader.DownloadFile(new Uri(url), null);
100 await using var buffer = new BufferedFileStreamProvider(
101 await download.GetResult(cancellationToken));
102 return await buffer.GetOwnedResult(cancellationToken);
103 }
104 }
105}
async Task CleanCache(CancellationToken cancellationToken)
Attempts to cleans the BYOND cache folder for the system. A Task representing the running operation.
IIOManager IOManager
Gets the IIOManager for the ByondInstallerBase.
async Task< MemoryStream > DownloadVersion(Version version, CancellationToken cancellationToken)
Download a given BYOND version . A Task<TResult> resulting in a MemoryStream of the zipfile.
abstract string GetDreamDaemonName(Version version, out bool supportsCli)
Get the file name of the DreamDaemon executable. The file name of the DreamDaemon executable.
const string CacheDirectoryName
The name of BYOND's cache directory.
readonly IFileDownloader fileDownloader
The IFileDownloader for the ByondInstallerBase.
abstract string DreamMakerName
Get the file name of the DreamMaker executable.
abstract string PathToUserByondFolder
The path to the BYOND folder for the user.
ILogger< ByondInstallerBase > Logger
Gets the ILogger for the ByondInstallerBase.
abstract Task InstallByond(Version version, string path, CancellationToken cancellationToken)
Does actions necessary to get an extracted BYOND installation working. A Task representing the runnin...
ByondInstallerBase(IIOManager ioManager, IFileDownloader fileDownloader, ILogger< ByondInstallerBase > logger)
Initializes a new instance of the ByondInstallerBase class.
abstract string ByondRevisionsUrlTemplate
Gets the URL formatter string for downloading a byond version of {0:Major} {1:Minor}.
abstract Task UpgradeInstallation(Version version, string path, CancellationToken cancellationToken)
Does actions necessary to get upgrade a BYOND version installed by a previous version of TGS....
IFileStreamProvider that provides a ISeekableFileStreamProvider from an input Stream.
For downloading and installing BYOND extractions for a given system.
IFileStreamProvider DownloadFile(Uri url, string bearerToken)
Downloads a file from a given url .
Interface for using filesystems.
Definition: IIOManager.cs:13
string ConcatPath(params string[] paths)
Combines an array of strings into a path.
Task DeleteDirectory(string path, CancellationToken cancellationToken)
Recursively delete a directory, removes and does not enter any symlinks encounterd.