Skip to content

Commit

Permalink
Use Redpoint.PackageManagement to install 7-Zip on demand (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
hach-que authored Dec 1, 2024
1 parent 94879c5 commit a621684
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
Binary file removed UET/Redpoint.Uet.SdkManagement/7z.exe
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
<Import Project="$(MSBuildThisFileDirectory)../Lib/Common.Build.props" />

<ItemGroup>
<EmbeddedResource Include="7z.exe" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Redpoint.PackageManagement\Redpoint.PackageManagement.csproj" />
<ProjectReference Include="..\Redpoint.ProcessExecution\Redpoint.ProcessExecution.csproj" />
<ProjectReference Include="..\Redpoint.ProgressMonitor\Redpoint.ProgressMonitor.csproj" />
<ProjectReference Include="..\Redpoint.Registry\Redpoint.Registry.csproj" />
Expand Down
51 changes: 32 additions & 19 deletions UET/Redpoint.Uet.SdkManagement/Sdk/LinuxSdkSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<LinuxSdkSetup> 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<string> PlatformNames => new[] { "Linux" };
Expand All @@ -46,33 +54,39 @@ public async Task GenerateSdkPackage(string unrealEnginePath, string sdkPackageP
{
var clangToolchain = await _versionNumberResolver.For<ILinuxVersionNumbers>(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")
},
Expand All @@ -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"));
}

Expand Down

0 comments on commit a621684

Please sign in to comment.