WindowsByondInstaller stuff

This commit is contained in:
Cyberboss
2018-07-23 16:32:34 -04:00
parent e98dde5089
commit a56c8b20f9
5 changed files with 71 additions and 6 deletions
@@ -8,6 +8,8 @@ using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Host.IO;
using MemoryStream = System.IO.MemoryStream;
namespace Tgstation.Server.Host.Components
{
/// <inheritdoc />
@@ -83,7 +85,7 @@ namespace Tgstation.Server.Host.Components
await ioManager.CreateDirectory(versionKey, cancellationToken).ConfigureAwait(false);
var resolvedPath = ioManager.ResolvePath(versionKey);
using (var zipBytes = await downloadTask.ConfigureAwait(false))
using (var zipBytes = new MemoryStream(await downloadTask.ConfigureAwait(false)))
using (var archive = new ZipArchive(zipBytes))
await Task.Factory.StartNew(() => archive.ExtractToDirectory(resolvedPath), cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false);
@@ -2,8 +2,6 @@
using System.Threading;
using System.Threading.Tasks;
using Stream = System.IO.Stream;
namespace Tgstation.Server.Host.Components
{
/// <summary>
@@ -26,8 +24,8 @@ namespace Tgstation.Server.Host.Components
/// </summary>
/// <param name="version">The <see cref="Version"/> of BYOND to download</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="Stream"/> of the zipfile</returns>
Task<Stream> DownloadVersion(Version version, CancellationToken cancellationToken);
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="byte"/>s of the zipfile</returns>
Task<byte[]> DownloadVersion(Version version, CancellationToken cancellationToken);
/// <summary>
/// Does actions necessary to get an extracted BYOND installation working
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Host.IO;
namespace Tgstation.Server.Host.Components
{
/// <summary>
/// <see cref="IByondInstaller"/> for windows systems
/// </summary>
sealed class WindowsByondInstaller : IByondInstaller
{
/// <summary>
/// The URL format string for getting BYOND windows version {0}.{1} zipfile
/// </summary>
const string ByondRevisionsURL = "https://secure.byond.com/download/build/{0}/{0}.{1}_byond.zip";
/// <inheritdoc />
public string DreamDaemonName => "dreamdaemon.exe";
/// <inheritdoc />
public string DreamMakerName => "dm.exe";
/// <summary>
/// The <see cref="IIOManager"/> for the <see cref="WindowsByondInstaller"/>
/// </summary>
readonly IIOManager ioManager;
public Task CleanCache(CancellationToken cancellationToken) => ioManager.DeleteDirectory(ioManager.ConcatPath(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "byond/cache"), cancellationToken);
public Task<byte[]> DownloadVersion(Version version, CancellationToken cancellationToken)
{
var url = String.Format(CultureInfo.InvariantCulture, ByondRevisionsURL, version.Major, version.Major);
return ioManager.DownloadFile(new Uri(url), cancellationToken);
}
public Task InstallByond(string path, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -243,5 +244,13 @@ namespace Tgstation.Server.Host.IO
link = ResolvePath(link);
}, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
/// <inheritdoc />
public async Task<byte[]> DownloadFile(Uri url, CancellationToken cancellationToken)
{
using (var wc = new WebClient())
using (cancellationToken.Register(() => wc.CancelAsync()))
return await wc.DownloadDataTaskAsync(url).ConfigureAwait(false);
}
}
}
+10 -1
View File
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -153,5 +154,13 @@ namespace Tgstation.Server.Host.IO
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task MoveFile(string source, string destination, CancellationToken cancellationToken);
/// <summary>
/// Downloads a file from <paramref name="url"/>
/// </summary>
/// <param name="url">The URL to download</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="byte"/>s of the downloaded file</returns>
Task<byte[]> DownloadFile(Uri url, CancellationToken cancellationToken);
}
}