|
|
@ -19,8 +19,10 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
private readonly ISettingsManager settingsManager; |
|
|
|
private readonly ISettingsManager settingsManager; |
|
|
|
|
|
|
|
|
|
|
|
private const string VcRedistDownloadUrl = "https://aka.ms/vs/16/release/vc_redist.x64.exe"; |
|
|
|
private const string VcRedistDownloadUrl = "https://aka.ms/vs/16/release/vc_redist.x64.exe"; |
|
|
|
private const string PythonDownloadUrl = "https://www.python.org/ftp/python/3.10.11/python-3.10.11-embed-amd64.zip"; |
|
|
|
private const string PythonDownloadUrl = |
|
|
|
private const string PythonDownloadHashBlake3 = "24923775f2e07392063aaa0c78fbd4ae0a320e1fc9c6cfbab63803402279fe5a"; |
|
|
|
"https://www.python.org/ftp/python/3.10.11/python-3.10.11-embed-amd64.zip"; |
|
|
|
|
|
|
|
private const string PythonDownloadHashBlake3 = |
|
|
|
|
|
|
|
"24923775f2e07392063aaa0c78fbd4ae0a320e1fc9c6cfbab63803402279fe5a"; |
|
|
|
|
|
|
|
|
|
|
|
private string HomeDir => settingsManager.LibraryDir; |
|
|
|
private string HomeDir => settingsManager.LibraryDir; |
|
|
|
|
|
|
|
|
|
|
@ -34,6 +36,7 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
private string PythonDllPath => Path.Combine(PythonDir, "python310.dll"); |
|
|
|
private string PythonDllPath => Path.Combine(PythonDir, "python310.dll"); |
|
|
|
private string PythonLibraryZipPath => Path.Combine(PythonDir, "python310.zip"); |
|
|
|
private string PythonLibraryZipPath => Path.Combine(PythonDir, "python310.zip"); |
|
|
|
private string GetPipPath => Path.Combine(PythonDir, "get-pip.pyc"); |
|
|
|
private string GetPipPath => Path.Combine(PythonDir, "get-pip.pyc"); |
|
|
|
|
|
|
|
|
|
|
|
// Temporary directory to extract venv to during python install |
|
|
|
// Temporary directory to extract venv to during python install |
|
|
|
private string VenvTempDir => Path.Combine(PythonDir, "venv"); |
|
|
|
private string VenvTempDir => Path.Combine(PythonDir, "venv"); |
|
|
|
|
|
|
|
|
|
|
@ -44,8 +47,12 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
|
|
|
|
|
|
|
|
public bool IsPythonInstalled => File.Exists(PythonDllPath); |
|
|
|
public bool IsPythonInstalled => File.Exists(PythonDllPath); |
|
|
|
|
|
|
|
|
|
|
|
public PrerequisiteHelper(ILogger<PrerequisiteHelper> logger, IGitHubClient gitHubClient, |
|
|
|
public PrerequisiteHelper( |
|
|
|
IDownloadService downloadService, ISettingsManager settingsManager) |
|
|
|
ILogger<PrerequisiteHelper> logger, |
|
|
|
|
|
|
|
IGitHubClient gitHubClient, |
|
|
|
|
|
|
|
IDownloadService downloadService, |
|
|
|
|
|
|
|
ISettingsManager settingsManager |
|
|
|
|
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.logger = logger; |
|
|
|
this.logger = logger; |
|
|
|
this.gitHubClient = gitHubClient; |
|
|
|
this.gitHubClient = gitHubClient; |
|
|
@ -53,16 +60,30 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
this.settingsManager = settingsManager; |
|
|
|
this.settingsManager = settingsManager; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task RunGit(string? workingDirectory = null, params string[] args) |
|
|
|
public async Task RunGit( |
|
|
|
|
|
|
|
string? workingDirectory = null, |
|
|
|
|
|
|
|
Action<ProcessOutput>? onProcessOutput = null, |
|
|
|
|
|
|
|
params string[] args |
|
|
|
|
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var process = ProcessRunner.StartAnsiProcess(GitExePath, args, workingDirectory: workingDirectory); |
|
|
|
var process = ProcessRunner.StartAnsiProcess( |
|
|
|
|
|
|
|
GitExePath, |
|
|
|
|
|
|
|
args, |
|
|
|
|
|
|
|
workingDirectory, |
|
|
|
|
|
|
|
onProcessOutput |
|
|
|
|
|
|
|
); |
|
|
|
await ProcessRunner.WaitForExitConditionAsync(process).ConfigureAwait(false); |
|
|
|
await ProcessRunner.WaitForExitConditionAsync(process).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task<string> GetGitOutput(string? workingDirectory = null, params string[] args) |
|
|
|
public async Task<string> GetGitOutput(string? workingDirectory = null, params string[] args) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var output = await ProcessRunner.GetProcessOutputAsync(GitExePath, string.Join(" ", args), |
|
|
|
var output = await ProcessRunner |
|
|
|
workingDirectory: workingDirectory).ConfigureAwait(false); |
|
|
|
.GetProcessOutputAsync( |
|
|
|
|
|
|
|
GitExePath, |
|
|
|
|
|
|
|
string.Join(" ", args), |
|
|
|
|
|
|
|
workingDirectory: workingDirectory |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.ConfigureAwait(false); |
|
|
|
return output; |
|
|
|
return output; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -85,11 +106,14 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
// from "StabilityMatrix.Assets.Python310.libssl-1_1.dll" |
|
|
|
// from "StabilityMatrix.Assets.Python310.libssl-1_1.dll" |
|
|
|
// to "Python310\libssl-1_1.dll" |
|
|
|
// to "Python310\libssl-1_1.dll" |
|
|
|
var fileExt = Path.GetExtension(resourceName); |
|
|
|
var fileExt = Path.GetExtension(resourceName); |
|
|
|
var fileName = resourceName |
|
|
|
var fileName = |
|
|
|
|
|
|
|
resourceName |
|
|
|
.Replace(fileExt, "") |
|
|
|
.Replace(fileExt, "") |
|
|
|
.Replace("StabilityMatrix.Assets.", "") |
|
|
|
.Replace("StabilityMatrix.Assets.", "") |
|
|
|
.Replace(".", Path.DirectorySeparatorChar.ToString()) + fileExt; |
|
|
|
.Replace(".", Path.DirectorySeparatorChar.ToString()) + fileExt; |
|
|
|
await using var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)!; |
|
|
|
await using var resourceStream = Assembly |
|
|
|
|
|
|
|
.GetExecutingAssembly() |
|
|
|
|
|
|
|
.GetManifestResourceStream(resourceName)!; |
|
|
|
if (resourceStream == null) |
|
|
|
if (resourceStream == null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new Exception($"Resource {resourceName} not found"); |
|
|
|
throw new Exception($"Resource {resourceName} not found"); |
|
|
@ -101,7 +125,11 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Extracts all embedded resources starting with resourceDir to outputDirectory |
|
|
|
/// Extracts all embedded resources starting with resourceDir to outputDirectory |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
private async Task ExtractAllEmbeddedResources(string resourceDir, string outputDirectory, string resourceRoot = "StabilityMatrix.Assets.") |
|
|
|
private async Task ExtractAllEmbeddedResources( |
|
|
|
|
|
|
|
string resourceDir, |
|
|
|
|
|
|
|
string outputDirectory, |
|
|
|
|
|
|
|
string resourceRoot = "StabilityMatrix.Assets." |
|
|
|
|
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Directory.CreateDirectory(outputDirectory); |
|
|
|
Directory.CreateDirectory(outputDirectory); |
|
|
|
// Unpack from embedded resources |
|
|
|
// Unpack from embedded resources |
|
|
@ -117,12 +145,15 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
// from "StabilityMatrix.Assets.Python310.libssl-1_1.dll" |
|
|
|
// from "StabilityMatrix.Assets.Python310.libssl-1_1.dll" |
|
|
|
// to "Python310\libssl-1_1.dll" |
|
|
|
// to "Python310\libssl-1_1.dll" |
|
|
|
var fileExt = Path.GetExtension(resourceName); |
|
|
|
var fileExt = Path.GetExtension(resourceName); |
|
|
|
var fileName = resourceName |
|
|
|
var fileName = |
|
|
|
|
|
|
|
resourceName |
|
|
|
.Replace(fileExt, "") |
|
|
|
.Replace(fileExt, "") |
|
|
|
.Replace(resourceRoot, "") |
|
|
|
.Replace(resourceRoot, "") |
|
|
|
.Replace(".", Path.DirectorySeparatorChar.ToString()) + fileExt; |
|
|
|
.Replace(".", Path.DirectorySeparatorChar.ToString()) + fileExt; |
|
|
|
// Unpack resource |
|
|
|
// Unpack resource |
|
|
|
await using var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)!; |
|
|
|
await using var resourceStream = Assembly |
|
|
|
|
|
|
|
.GetExecutingAssembly() |
|
|
|
|
|
|
|
.GetManifestResourceStream(resourceName)!; |
|
|
|
var outputFilePath = Path.Combine(outputDirectory, fileName); |
|
|
|
var outputFilePath = Path.Combine(outputDirectory, fileName); |
|
|
|
// Create missing directories |
|
|
|
// Create missing directories |
|
|
|
var outputDir = Path.GetDirectoryName(outputFilePath); |
|
|
|
var outputDir = Path.GetDirectoryName(outputFilePath); |
|
|
@ -134,13 +165,21 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
await resourceStream.CopyToAsync(fileStream); |
|
|
|
await resourceStream.CopyToAsync(fileStream); |
|
|
|
copied.Add(outputFilePath); |
|
|
|
copied.Add(outputFilePath); |
|
|
|
} |
|
|
|
} |
|
|
|
logger.LogInformation("Successfully unpacked {Num} embedded resources: [{Resources}]", total, string.Join(",", copied)); |
|
|
|
logger.LogInformation( |
|
|
|
|
|
|
|
"Successfully unpacked {Num} embedded resources: [{Resources}]", |
|
|
|
|
|
|
|
total, |
|
|
|
|
|
|
|
string.Join(",", copied) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task UnpackResourcesIfNecessary(IProgress<ProgressReport>? progress = null) |
|
|
|
public async Task UnpackResourcesIfNecessary(IProgress<ProgressReport>? progress = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Skip if all files exist |
|
|
|
// Skip if all files exist |
|
|
|
if (File.Exists(SevenZipPath) && File.Exists(PythonDllPath) && File.Exists(PythonLibraryZipPath)) |
|
|
|
if ( |
|
|
|
|
|
|
|
File.Exists(SevenZipPath) |
|
|
|
|
|
|
|
&& File.Exists(PythonDllPath) |
|
|
|
|
|
|
|
&& File.Exists(PythonLibraryZipPath) |
|
|
|
|
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -180,13 +219,19 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
|
|
|
|
|
|
|
|
logger.LogInformation( |
|
|
|
logger.LogInformation( |
|
|
|
"Downloading Python from {PythonLibraryZipUrl} to {PythonLibraryZipPath}", |
|
|
|
"Downloading Python from {PythonLibraryZipUrl} to {PythonLibraryZipPath}", |
|
|
|
PythonDownloadUrl, PythonLibraryZipPath); |
|
|
|
PythonDownloadUrl, |
|
|
|
|
|
|
|
PythonLibraryZipPath |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// Cleanup to remove zip if download fails |
|
|
|
// Cleanup to remove zip if download fails |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Download python zip |
|
|
|
// Download python zip |
|
|
|
await downloadService.DownloadToFileAsync(PythonDownloadUrl, PythonDownloadPath, progress: progress); |
|
|
|
await downloadService.DownloadToFileAsync( |
|
|
|
|
|
|
|
PythonDownloadUrl, |
|
|
|
|
|
|
|
PythonDownloadPath, |
|
|
|
|
|
|
|
progress: progress |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// Verify python hash |
|
|
|
// Verify python hash |
|
|
|
var downloadHash = await FileHash.GetBlake3Async(PythonDownloadPath, progress); |
|
|
|
var downloadHash = await FileHash.GetBlake3Async(PythonDownloadPath, progress); |
|
|
@ -194,8 +239,9 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
{ |
|
|
|
{ |
|
|
|
var fileExists = File.Exists(PythonDownloadPath); |
|
|
|
var fileExists = File.Exists(PythonDownloadPath); |
|
|
|
var fileSize = new FileInfo(PythonDownloadPath).Length; |
|
|
|
var fileSize = new FileInfo(PythonDownloadPath).Length; |
|
|
|
var msg = $"Python download hash mismatch: {downloadHash} != {PythonDownloadHashBlake3} " + |
|
|
|
var msg = |
|
|
|
$"(file exists: {fileExists}, size: {fileSize})"; |
|
|
|
$"Python download hash mismatch: {downloadHash} != {PythonDownloadHashBlake3} " |
|
|
|
|
|
|
|
+ $"(file exists: {fileExists}, size: {fileSize})"; |
|
|
|
throw new Exception(msg); |
|
|
|
throw new Exception(msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -207,7 +253,10 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
if (!File.Exists(SevenZipPath)) |
|
|
|
if (!File.Exists(SevenZipPath)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
await ExtractEmbeddedResource("StabilityMatrix.Assets.7za.exe", AssetsDir); |
|
|
|
await ExtractEmbeddedResource("StabilityMatrix.Assets.7za.exe", AssetsDir); |
|
|
|
await ExtractEmbeddedResource("StabilityMatrix.Assets.7za - LICENSE.txt", AssetsDir); |
|
|
|
await ExtractEmbeddedResource( |
|
|
|
|
|
|
|
"StabilityMatrix.Assets.7za - LICENSE.txt", |
|
|
|
|
|
|
|
AssetsDir |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Delete existing python dir |
|
|
|
// Delete existing python dir |
|
|
@ -272,7 +321,11 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(PortableGitDownloadPath)) |
|
|
|
if (!File.Exists(PortableGitDownloadPath)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
await downloadService.DownloadToFileAsync(portableGitUrl, PortableGitDownloadPath, progress: progress); |
|
|
|
await downloadService.DownloadToFileAsync( |
|
|
|
|
|
|
|
portableGitUrl, |
|
|
|
|
|
|
|
PortableGitDownloadPath, |
|
|
|
|
|
|
|
progress: progress |
|
|
|
|
|
|
|
); |
|
|
|
progress?.Report(new ProgressReport(progress: 1f, message: "Git download complete")); |
|
|
|
progress?.Report(new ProgressReport(progress: 1f, message: "Git download complete")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -284,7 +337,9 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
{ |
|
|
|
{ |
|
|
|
var registry = Registry.LocalMachine; |
|
|
|
var registry = Registry.LocalMachine; |
|
|
|
var key = registry.OpenSubKey( |
|
|
|
var key = registry.OpenSubKey( |
|
|
|
@"SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\X64", false); |
|
|
|
@"SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\X64", |
|
|
|
|
|
|
|
false |
|
|
|
|
|
|
|
); |
|
|
|
if (key != null) |
|
|
|
if (key != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var buildId = Convert.ToUInt32(key.GetValue("Bld")); |
|
|
|
var buildId = Convert.ToUInt32(key.GetValue("Bld")); |
|
|
@ -296,16 +351,40 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
|
|
|
|
|
|
|
|
logger.LogInformation("Downloading VC Redist"); |
|
|
|
logger.LogInformation("Downloading VC Redist"); |
|
|
|
|
|
|
|
|
|
|
|
await downloadService.DownloadToFileAsync(VcRedistDownloadUrl, VcRedistDownloadPath, progress: progress); |
|
|
|
await downloadService.DownloadToFileAsync( |
|
|
|
progress?.Report(new ProgressReport(progress: 1f, message: "Visual C++ download complete", |
|
|
|
VcRedistDownloadUrl, |
|
|
|
type: ProgressType.Download)); |
|
|
|
VcRedistDownloadPath, |
|
|
|
|
|
|
|
progress: progress |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
progress?.Report( |
|
|
|
|
|
|
|
new ProgressReport( |
|
|
|
|
|
|
|
progress: 1f, |
|
|
|
|
|
|
|
message: "Visual C++ download complete", |
|
|
|
|
|
|
|
type: ProgressType.Download |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
logger.LogInformation("Installing VC Redist"); |
|
|
|
logger.LogInformation("Installing VC Redist"); |
|
|
|
progress?.Report(new ProgressReport(progress: 0.5f, isIndeterminate: true, type: ProgressType.Generic, message: "Installing prerequisites...")); |
|
|
|
progress?.Report( |
|
|
|
var process = ProcessRunner.StartAnsiProcess(VcRedistDownloadPath, "/install /quiet /norestart"); |
|
|
|
new ProgressReport( |
|
|
|
|
|
|
|
progress: 0.5f, |
|
|
|
|
|
|
|
isIndeterminate: true, |
|
|
|
|
|
|
|
type: ProgressType.Generic, |
|
|
|
|
|
|
|
message: "Installing prerequisites..." |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
var process = ProcessRunner.StartAnsiProcess( |
|
|
|
|
|
|
|
VcRedistDownloadPath, |
|
|
|
|
|
|
|
"/install /quiet /norestart" |
|
|
|
|
|
|
|
); |
|
|
|
await process.WaitForExitAsync(); |
|
|
|
await process.WaitForExitAsync(); |
|
|
|
progress?.Report(new ProgressReport(progress: 1f, message: "Visual C++ install complete", |
|
|
|
progress?.Report( |
|
|
|
type: ProgressType.Generic)); |
|
|
|
new ProgressReport( |
|
|
|
|
|
|
|
progress: 1f, |
|
|
|
|
|
|
|
message: "Visual C++ install complete", |
|
|
|
|
|
|
|
type: ProgressType.Generic |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
File.Delete(VcRedistDownloadPath); |
|
|
|
File.Delete(VcRedistDownloadPath); |
|
|
|
} |
|
|
|
} |
|
|
@ -335,5 +414,4 @@ public class PrerequisiteHelper : IPrerequisiteHelper |
|
|
|
settingsManager.AddPathExtension(GitBinPath); |
|
|
|
settingsManager.AddPathExtension(GitBinPath); |
|
|
|
settingsManager.InsertPathExtensions(); |
|
|
|
settingsManager.InsertPathExtensions(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|