public async Task <bool> DownloadEngineIfNecessary( string engineVersion, Helpers.DownloadProgressCallback?progress = null, CancellationToken cancel = default) { if (_cfg.EngineInstallations.Lookup(engineVersion).HasValue) { // Already have the engine version, we're good. return(false); } Log.Information("Installing engine version {version}...", engineVersion); Log.Debug("Loading manifest from {manifestUrl}...", ConfigConstants.RobustBuildsManifest); var manifest = await _http.GetFromJsonAsync <Dictionary <string, VersionInfo> >( ConfigConstants.RobustBuildsManifest, cancellationToken : cancel); if (!manifest !.TryGetValue(engineVersion, out var versionInfo)) { throw new UpdateException("Unable to find engine version in manifest!"); } if (versionInfo.Insecure) { throw new UpdateException("Specified engine version is insecure!"); } var bestRid = RidUtility.FindBestRid(versionInfo.Platforms.Keys); if (bestRid == null) { throw new UpdateException("No engine version available for our platform!"); } Log.Debug("Selecting RID {rid}", bestRid); var buildInfo = versionInfo.Platforms[bestRid]; Helpers.EnsureDirectoryExists(LauncherPaths.DirEngineInstallations); var downloadTarget = Path.Combine(LauncherPaths.DirEngineInstallations, $"{engineVersion}.zip"); await using var file = File.Create(downloadTarget, 4096, FileOptions.Asynchronous); try { await _http.DownloadToStream(buildInfo.Url, file, progress, cancel : cancel); } catch (OperationCanceledException) { // Don't leave behind garbage. await file.DisposeAsync(); File.Delete(downloadTarget); throw; } _cfg.AddEngineInstallation(new InstalledEngineVersion(engineVersion, buildInfo.Signature)); return(true); }
public void TestFindBestRid(string[] rids, string start, string expected) { Assert.That(RidUtility.FindBestRid(rids, start), Is.EqualTo(expected)); }