Skip to content
Permalink
Browse files

[Setup] PackageInstall: Check VS Installer update if any workload nee…

…ds to be installed (two UAC, but probably better than an error and extra step)
  • Loading branch information
xen2 committed Oct 4, 2019
1 parent 46bcd06 commit fb99c6a35de199b32b5cd999e64b05740054a7d2
Showing with 15 additions and 20 deletions.
  1. +15 −20 sources/tools/Xenko.PackageInstall/Program.cs
@@ -93,22 +93,6 @@ 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);
@@ -131,15 +115,26 @@ private static void CheckVisualStudioAndBuildTools()
var vsInstallerPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Microsoft Visual Studio\Installer\vs_installer.exe");
if (AllowVisualStudioOnly && existingVisualStudio2019Install != null && File.Exists(vsInstallerPath))
{
// First, check if a Visual Studio update is needed
// First, make sure installer is up to date
{
var vsInstallerExitCode = RunProgramAndAskUntilSuccess("Visual Studio Installer", "vs_Setup.exe", "--update --wait --passive", DialogBoxTryAgain);
if (vsInstallerExitCode != 0)
{
var errorMessage = $"Visual Studio Installer update failed with error {vsInstallerExitCode}";
MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw new InvalidOperationException(errorMessage);
}
}

// Second, check if a Visual Studio update is needed
// Note: not necessary since VS2019, still keeping code for when we'll need a specific VS2019 version
if (existingVisualStudio2019Install.Version.Major == 16 && existingVisualStudio2019Install.Version.Minor < 0)
{
// Not sure why, but it seems VS Update is sometimes sending Ctrl+C to our process...
try
{
Console.CancelKeyPress += Console_IgnoreControlC;
var vsInstallerExitCode = RunProgramAndAskUntilSuccess("Visual Studio", vsInstallerPath, $"update --passive --norestart --installPath \"{existingVisualStudio2019Install.InstallationPath}\"", DialogBoxTryAgainVisualStudioInstaller);
var vsInstallerExitCode = RunProgramAndAskUntilSuccess("Visual Studio", vsInstallerPath, $"update --passive --norestart --installPath \"{existingVisualStudio2019Install.InstallationPath}\"", DialogBoxTryAgain);
if (vsInstallerExitCode != 0)
{
var errorMessage = $"Visual Studio 2019 update failed with error {vsInstallerExitCode}";
@@ -153,9 +148,9 @@ private static void CheckVisualStudioAndBuildTools()
}
}

// Check workloads
// Third, check workloads
{
var vsInstallerExitCode = RunProgramAndAskUntilSuccess("Visual Studio", vsInstallerPath, $"modify --passive --norestart --installPath \"{existingVisualStudio2019Install.InstallationPath}\" {string.Join(" ", NecessaryVS2019Workloads.Select(x => $"--add {x}"))}", DialogBoxTryAgainVisualStudioInstaller);
var vsInstallerExitCode = RunProgramAndAskUntilSuccess("Visual Studio", vsInstallerPath, $"modify --passive --norestart --installPath \"{existingVisualStudio2019Install.InstallationPath}\" {string.Join(" ", NecessaryVS2019Workloads.Select(x => $"--add {x}"))}", DialogBoxTryAgain);
if (vsInstallerExitCode != 0)
{
var errorMessage = $"Visual Studio 2019 install failed with error {vsInstallerExitCode}";

0 comments on commit fb99c6a

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