From 577f721fb70bbf6c29c40d5f10d4319370ccb1f8 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 12 Jan 2017 11:25:14 -0500 Subject: [PATCH 1/2] VS: Fix detection of VS 2017 installation with WindowsStore Fix logic in cmVSSetupAPIHelper::IsVS2017Installed to work correctly on repeat calls. Closes: #16549 --- Source/cmVSSetupHelper.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/cmVSSetupHelper.cxx b/Source/cmVSSetupHelper.cxx index d675a2c4e0..2091b5cd68 100644 --- a/Source/cmVSSetupHelper.cxx +++ b/Source/cmVSSetupHelper.cxx @@ -76,6 +76,8 @@ bool cmVSSetupAPIHelper::IsVS2017Installed() bool ret = false; if (chosenInstanceInfo.VSInstallLocation.compare(L"") == 0) { ret = EnumerateAndChooseVSInstance(); + } else { + ret = true; } return ret; From 0362c60fe5f4e7e4011f14dc2519ffb1bc6c8ce8 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 12 Jan 2017 11:29:06 -0500 Subject: [PATCH 2/2] cmVSSetupHelper: Simplify use of EnumerateAndChooseVSInstance This method short-circuits when an instance has already been chosen, so avoid duplicating this check at call sites. --- Source/cmVSSetupHelper.cxx | 45 ++++++-------------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/Source/cmVSSetupHelper.cxx b/Source/cmVSSetupHelper.cxx index 2091b5cd68..c2ff66453b 100644 --- a/Source/cmVSSetupHelper.cxx +++ b/Source/cmVSSetupHelper.cxx @@ -73,44 +73,19 @@ cmVSSetupAPIHelper::~cmVSSetupAPIHelper() bool cmVSSetupAPIHelper::IsVS2017Installed() { - bool ret = false; - if (chosenInstanceInfo.VSInstallLocation.compare(L"") == 0) { - ret = EnumerateAndChooseVSInstance(); - } else { - ret = true; - } - - return ret; + return this->EnumerateAndChooseVSInstance(); } bool cmVSSetupAPIHelper::IsWin10SDKInstalled() { - bool isWin10SDKInstalled = false; - if (chosenInstanceInfo.VSInstallLocation.compare(L"") == 0) { - if (EnumerateAndChooseVSInstance() && - chosenInstanceInfo.VSInstallLocation.compare(L"") != 0) { - isWin10SDKInstalled = chosenInstanceInfo.IsWin10SDKInstalled; - } - } else { - isWin10SDKInstalled = chosenInstanceInfo.IsWin10SDKInstalled; - } - - return isWin10SDKInstalled; + return (this->EnumerateAndChooseVSInstance() && + chosenInstanceInfo.IsWin10SDKInstalled); } bool cmVSSetupAPIHelper::IsWin81SDKInstalled() { - bool isWin81SDKInstalled = false; - if (chosenInstanceInfo.VSInstallLocation.compare(L"") == 0) { - if (EnumerateAndChooseVSInstance() && - chosenInstanceInfo.VSInstallLocation.compare(L"") != 0) { - isWin81SDKInstalled = chosenInstanceInfo.IsWin81SDKInstalled; - } - } else { - isWin81SDKInstalled = chosenInstanceInfo.IsWin81SDKInstalled; - } - - return isWin81SDKInstalled; + return (this->EnumerateAndChooseVSInstance() && + chosenInstanceInfo.IsWin81SDKInstalled); } bool cmVSSetupAPIHelper::CheckInstalledComponent( @@ -243,18 +218,12 @@ bool cmVSSetupAPIHelper::GetVSInstanceInfo( bool cmVSSetupAPIHelper::GetVSInstanceInfo(std::string& vsInstallLocation) { vsInstallLocation = ""; - bool isInstalled = false; + bool isInstalled = this->EnumerateAndChooseVSInstance(); - if (chosenInstanceInfo.VSInstallLocation.compare(L"") == 0) { - isInstalled = EnumerateAndChooseVSInstance(); - } - - // Enumerate and choose best VS instance - if (chosenInstanceInfo.VSInstallLocation.compare(L"") != 0) { + if (isInstalled) { std::string str(chosenInstanceInfo.VSInstallLocation.begin(), chosenInstanceInfo.VSInstallLocation.end()); vsInstallLocation = str; - isInstalled = true; } return isInstalled;