Skip to content
Permalink
Browse files

[Setup] PackageInstall: check if VS Installer needs an update, and if…

… yes try to do it automatically
  • Loading branch information
xen2 committed Sep 27, 2019
1 parent 3f31587 commit aa48bc6479c39f8732d11bb84b2960ff1a1cd593
@@ -38,7 +38,7 @@ static int Main(string[] args)
var prerequisitesInstallerPath = @"install-prerequisites.exe";
if (File.Exists(prerequisitesInstallerPath))
{
RunProgramAndAskUntilSuccess("prerequisites", prerequisitesInstallerPath, string.Empty);
RunProgramAndAskUntilSuccess("prerequisites", prerequisitesInstallerPath, string.Empty, DialogBoxTryAgain);
}

// Make sure we have the proper VS2019/BuildTools prerequisites
@@ -57,7 +57,7 @@ static int Main(string[] args)
}
}

private static int RunProgramAndAskUntilSuccess(string programName, string fileName, string arguments)
private static int RunProgramAndAskUntilSuccess(string programName, string fileName, string arguments, Func<string, Process, bool> processError)
{
TryAgain:
try
@@ -71,10 +71,7 @@ private static int RunProgramAndAskUntilSuccess(string programName, string fileN
prerequisitesInstallerProcess.WaitForExit();
if (prerequisitesInstallerProcess.ExitCode != 0)
{
// We'll enter this if UAC has been declined, but also if it timed out (which is a frequent case)
// if you don't stay in front of your computer during the installation.
var result = MessageBox.Show($"The installation of {programName} returned with code {prerequisitesInstallerProcess.ExitCode}.\r\nDo you want to try it again?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result != DialogResult.Yes)
if (!processError(programName, prerequisitesInstallerProcess))
return prerequisitesInstallerProcess.ExitCode;
goto TryAgain;
}
@@ -96,6 +93,28 @@ private static int RunProgramAndAskUntilSuccess(string programName, string fileN
}
}

private static bool DialogBoxTryAgainVisualStudioInstaller(string programName, Process process)
{
if (process.ExitCode == 1)
{
var resultUpdate = MessageBox.Show($"The installation of {programName} returned with code {process.ExitCode}.\r\n\r\nThis is likely due to Visual Studio Installer needs a self-update.\r\n\r\nPlease click Yes to start the self-update process.", "Visual Studio Installer udpate needed", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (RunProgramAndAskUntilSuccess("Visual Studio Installer", "vs_Setup.exe", "--update --wait --passive", DialogBoxTryAgain) == 0)
{
// Then allow update
return true;
}
}

return DialogBoxTryAgain(programName, process);
}


private static bool DialogBoxTryAgain(string programName, Process process)
{
var result = MessageBox.Show($"The installation of {programName} returned with code {process.ExitCode}.\r\nDo you want to try it again?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
return result == DialogResult.Yes;
}

private static void CheckVisualStudioAndBuildTools()
{
// Check if there is any VS2019 installed with necessary workloads
@@ -120,7 +139,7 @@ private static void CheckVisualStudioAndBuildTools()
try
{
Console.CancelKeyPress += Console_IgnoreControlC;
var vsInstallerExitCode = RunProgramAndAskUntilSuccess("Visual Studio", vsInstallerPath, $"update --passive --norestart --installPath \"{existingVisualStudio2019Install.InstallationPath}\"");
var vsInstallerExitCode = RunProgramAndAskUntilSuccess("Visual Studio", vsInstallerPath, $"update --passive --norestart --installPath \"{existingVisualStudio2019Install.InstallationPath}\"", DialogBoxTryAgainVisualStudioInstaller);
if (vsInstallerExitCode != 0)
{
var errorMessage = $"Visual Studio 2019 update failed with error {vsInstallerExitCode}";
@@ -136,7 +155,7 @@ private static void CheckVisualStudioAndBuildTools()

// Check workloads
{
var vsInstallerExitCode = RunProgramAndAskUntilSuccess("Visual Studio", vsInstallerPath, $"modify --passive --norestart --installPath \"{existingVisualStudio2019Install.InstallationPath}\" {string.Join(" ", NecessaryVS2019Workloads.Select(x => $"--add {x}"))}");
var vsInstallerExitCode = RunProgramAndAskUntilSuccess("Visual Studio", vsInstallerPath, $"modify --passive --norestart --installPath \"{existingVisualStudio2019Install.InstallationPath}\" {string.Join(" ", NecessaryVS2019Workloads.Select(x => $"--add {x}"))}", DialogBoxTryAgainVisualStudioInstaller);
if (vsInstallerExitCode != 0)
{
var errorMessage = $"Visual Studio 2019 install failed with error {vsInstallerExitCode}";
@@ -175,7 +194,7 @@ private static void CheckVisualStudioAndBuildTools()
if (buildToolsCommandLine != null)
{
// Run vs_buildtools again
RunProgramAndAskUntilSuccess("Build Tools", "vs_buildtools.exe", buildToolsCommandLine);
RunProgramAndAskUntilSuccess("Build Tools", "vs_buildtools.exe", buildToolsCommandLine, DialogBoxTryAgain);
}
}
}
@@ -43,5 +43,10 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Update="vs_Setup.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="..\..\targets\Xenko.Core.Sign.targets" />
</Project>
Git LFS file not shown

0 comments on commit aa48bc6

Please sign in to comment.
You can’t perform that action at this time.