diff --git a/UET/Redpoint.Uet.SdkManagement/7z.exe b/UET/Redpoint.Uet.SdkManagement/7z.exe deleted file mode 100644 index 6a34fc63..00000000 Binary files a/UET/Redpoint.Uet.SdkManagement/7z.exe and /dev/null differ diff --git a/UET/Redpoint.Uet.SdkManagement/Redpoint.Uet.SdkManagement.csproj b/UET/Redpoint.Uet.SdkManagement/Redpoint.Uet.SdkManagement.csproj index acde00a7..d23d2d9f 100644 --- a/UET/Redpoint.Uet.SdkManagement/Redpoint.Uet.SdkManagement.csproj +++ b/UET/Redpoint.Uet.SdkManagement/Redpoint.Uet.SdkManagement.csproj @@ -3,10 +3,7 @@ - - - - + diff --git a/UET/Redpoint.Uet.SdkManagement/Sdk/LinuxSdkSetup.cs b/UET/Redpoint.Uet.SdkManagement/Sdk/LinuxSdkSetup.cs index 46ca8cbc..17dbe097 100644 --- a/UET/Redpoint.Uet.SdkManagement/Sdk/LinuxSdkSetup.cs +++ b/UET/Redpoint.Uet.SdkManagement/Sdk/LinuxSdkSetup.cs @@ -12,6 +12,8 @@ using System.Text.RegularExpressions; using Redpoint.Uet.SdkManagement.Sdk.VersionNumbers; using Redpoint.ProgressMonitor.Utils; + using Redpoint.PackageManagement; + using Redpoint.PathResolution; [SupportedOSPlatform("windows")] public class LinuxSdkSetup : ISdkSetup @@ -20,17 +22,23 @@ public class LinuxSdkSetup : ISdkSetup private readonly IProcessExecutor _processExecutor; private readonly ISimpleDownloadProgress _simpleDownloadProgress; private readonly IVersionNumberResolver _versionNumberResolver; + private readonly IPackageManager _packageManager; + private readonly IPathResolver _pathResolver; public LinuxSdkSetup( ILogger logger, IProcessExecutor processExecutor, ISimpleDownloadProgress simpleDownloadProgress, - IVersionNumberResolver versionNumberResolver) + IVersionNumberResolver versionNumberResolver, + IPackageManager packageManager, + IPathResolver pathResolver) { _logger = logger; _processExecutor = processExecutor; _simpleDownloadProgress = simpleDownloadProgress; _versionNumberResolver = versionNumberResolver; + _packageManager = packageManager; + _pathResolver = pathResolver; } public IReadOnlyList PlatformNames => new[] { "Linux" }; @@ -46,33 +54,39 @@ public async Task GenerateSdkPackage(string unrealEnginePath, string sdkPackageP { var clangToolchain = await _versionNumberResolver.For(unrealEnginePath).GetClangToolchainVersion(unrealEnginePath).ConfigureAwait(false); + _logger.LogInformation("Ensuring 7-zip is installed for fast extraction..."); + await _packageManager.InstallOrUpgradePackageToLatestAsync("7zip.7zip", cancellationToken); + + _logger.LogInformation("Locating 7-zip..."); + var _7z = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), + "7-Zip", + "7z.exe"); + if (!File.Exists(_7z)) + { + _logger.LogWarning("7-zip is not installed under Program Files (where we expect it to be). Attempting to find it on the PATH environment variable, but this may fail..."); + _7z = await _pathResolver.ResolveBinaryPath("7z"); + } + _logger.LogInformation($"Downloading Linux cross-compile toolchain {clangToolchain}..."); using (var client = new HttpClient()) { - using (var target = new FileStream(Path.Combine(sdkPackagePath, "toolchainextract.exe"), FileMode.Create, FileAccess.Write, FileShare.None)) - { - var downloadUrl = $"https://cdn.unrealengine.com/CrossToolchain_Linux/{clangToolchain.Trim()}.exe"; - await _simpleDownloadProgress.DownloadAndCopyToStreamAsync( - client, - new Uri(downloadUrl), - async stream => await stream.CopyToAsync(target, cancellationToken).ConfigureAwait(false), - cancellationToken).ConfigureAwait(false); - } + using var target = new FileStream(Path.Combine(sdkPackagePath, "toolchainextract.exe"), FileMode.Create, FileAccess.Write, FileShare.None); + + var downloadUrl = $"https://cdn.unrealengine.com/CrossToolchain_Linux/{clangToolchain.Trim()}.exe"; + await _simpleDownloadProgress.DownloadAndCopyToStreamAsync( + client, + new Uri(downloadUrl), + async stream => await stream.CopyToAsync(target, cancellationToken).ConfigureAwait(false), + cancellationToken).ConfigureAwait(false); } _logger.LogInformation($"Extracting Linux cross-compile toolchain {clangToolchain}..."); - using (var zstream = new FileStream(Path.Combine(sdkPackagePath, "7z.exe"), FileMode.Create, FileAccess.Write, FileShare.None)) - { - using (var sstream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Redpoint.Uet.SdkManagement.7z.exe")) - { - await sstream!.CopyToAsync(zstream, cancellationToken).ConfigureAwait(false); - } - } Directory.CreateDirectory(Path.Combine(sdkPackagePath, "SDK")); var exitCode = await _processExecutor.ExecuteAsync( new ProcessSpecification { - FilePath = Path.Combine(sdkPackagePath, "7z.exe"), + FilePath = _7z, Arguments = new LogicalProcessArgument[] { "x", "..\\toolchainextract.exe" }, WorkingDirectory = Path.Combine(sdkPackagePath, "SDK") }, @@ -83,7 +97,6 @@ await _simpleDownloadProgress.DownloadAndCopyToStreamAsync( throw new SdkSetupPackageGenerationFailedException("Failed to extract NSIS installer with 7-Zip."); } - File.Delete(Path.Combine(sdkPackagePath, "7z.exe")); File.Delete(Path.Combine(sdkPackagePath, "toolchainextract.exe")); }