1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
6 # define NOMINMAX // Undefine min and max defined by windows.h
9 // Published by Visual Studio Setup team
10 #include <cm3p/Setup.Configuration.h>
20 SmartCOMPtr() { ptr = NULL; }
27 SmartCOMPtr(const SmartCOMPtr<T>& sptr)
33 T** operator&() { return &ptr; }
34 T* operator->() { return ptr; }
44 operator T*() const { return ptr; }
46 HRESULT QueryInterface(REFCLSID rclsid, I** pp)
49 return ptr->QueryInterface(rclsid, (void**)pp);
54 HRESULT CoCreateInstance(REFCLSID clsid, IUnknown* pUnknown,
55 REFIID interfaceId, DWORD dwClsContext = CLSCTX_ALL)
57 HRESULT hr = ::CoCreateInstance(clsid, pUnknown, dwClsContext, interfaceId,
74 SmartBSTR() { str = NULL; }
75 SmartBSTR(const SmartBSTR& src) = delete;
76 SmartBSTR& operator=(const SmartBSTR& src) = delete;
77 operator BSTR() const { return str; }
78 BSTR* operator&() throw() { return &str; }
79 ~SmartBSTR() throw() { ::SysFreeString(str); }
87 std::string VSInstallLocation;
89 std::string VCToolsetVersion;
90 bool IsWin10SDKInstalled = false;
91 bool IsWin81SDKInstalled = false;
93 std::string GetInstallLocation() const;
96 class cmVSSetupAPIHelper
99 cmVSSetupAPIHelper(unsigned int version);
100 ~cmVSSetupAPIHelper();
102 bool SetVSInstance(std::string const& vsInstallLocation,
103 std::string const& vsInstallVersion);
105 bool IsVSInstalled();
106 bool GetVSInstanceInfo(std::string& vsInstallLocation);
107 bool GetVSInstanceVersion(std::string& vsInstanceVersion);
108 bool GetVCToolsetVersion(std::string& vsToolsetVersion);
109 bool IsWin10SDKInstalled();
110 bool IsWin81SDKInstalled();
114 bool GetVSInstanceInfo(SmartCOMPtr<ISetupInstance2> instance2,
115 VSInstanceInfo& vsInstanceInfo);
116 bool CheckInstalledComponent(SmartCOMPtr<ISetupPackageReference> package,
117 bool& bWin10SDK, bool& bWin81SDK);
118 int ChooseVSInstance(const std::vector<VSInstanceInfo>& vecVSInstances);
119 bool EnumerateAndChooseVSInstance();
120 bool LoadSpecifiedVSInstanceFromDisk();
121 bool EnumerateVSInstancesWithVswhere(
122 std::vector<VSInstanceInfo>& VSInstances);
123 bool EnumerateVSInstancesWithCOM(std::vector<VSInstanceInfo>& VSInstances);
125 unsigned int Version;
127 // COM ptrs to query about VS instances
128 SmartCOMPtr<ISetupConfiguration> setupConfig;
129 SmartCOMPtr<ISetupConfiguration2> setupConfig2;
130 SmartCOMPtr<ISetupHelper> setupHelper;
131 // used to indicate failure in Initialize(), so we don't have to call again
132 bool initializationFailure;
133 // indicated if COM initialization is successful
134 HRESULT comInitialized;
135 // current best instance of VS selected
136 VSInstanceInfo chosenInstanceInfo;
137 bool IsEWDKEnabled();
139 std::string SpecifiedVSInstallLocation;
140 std::string SpecifiedVSInstallVersion;