MCPcopy Create free account
hub / github.com/Windscribe/Desktop-App / wWinMain

Function wWinMain

src/installer/gui/windows/bootstrap/main.cpp:144–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpszCmdParam, int nCmdShow)
145{
146 if (!IsWindows10OrGreater()) {
147 showMessageBox(NULL, _T("Windscribe Installer"), MB_OK | MB_ICONSTOP,
148 _T("The Windscribe app cannot be installed on this version of Windows. It requires Windows 10 or newer."));
149 return -1;
150 }
151
152 const auto isAdmin = isElevated();
153 if (!isAdmin.has_value()) {
154 showMessageBox(NULL, _T("Windscribe Installer"), MB_OK | MB_ICONSTOP,
155 _T("Couldn't determine if user has administrative rights."));
156 return -1;
157 }
158
159 std::filesystem::path installPath;
160 auto exitGuard = wsl::wsScopeGuard([&] {
161 deleteFolder(installPath);
162 });
163
164 if (!isAdmin.value()) {
165 if (!isOSCompatible()) {
166 auto response = showMessageBox(NULL, _T("Windscribe Installer"), MB_YESNO | MB_ICONWARNING,
167 _T("The Windscribe app may not function correctly on this version of Windows. It requires Windows 10"
168 " build %lu or newer for full functionality.\n\nDo you want to proceed with the install?"), kMinWindowsBuildNumber);
169 if (response != IDYES) {
170 return -1;
171 }
172 }
173
174 // Attempt to run this program as admin
175 TCHAR buf[MAX_PATH];
176 DWORD result = GetModuleFileName(NULL, buf, MAX_PATH);
177 if (result == 0 || result == MAX_PATH) {
178 // 0 == failure; MAX_PATH == truncated (GetLastError() == ERROR_INSUFFICIENT_BUFFER) - reject either.
179 showMessageBox(NULL, _T("Windscribe Installer"), MB_OK | MB_ICONSTOP,
180 _T("Couldn't get own exe path."));
181 return -1;
182 }
183
184 result = executeProgram(buf, lpszCmdParam, false, true, nullptr);
185 if (result == NO_ERROR) {
186 // Elevated process is running, exit this process
187 return 0;
188 } else if (result == ERROR_CANCELLED) {
189 // User declined the UAC prompt; the installer cannot proceed without elevation, and we
190 // intentionally do not extract anything to a Users-writable temp directory in this case.
191 showMessageBox(NULL, _T("Windscribe Installer"), MB_OK | MB_ICONSTOP,
192 _T("The Windscribe installer requires administrator privileges to run."));
193 return -1;
194 } else {
195 // Some other error occurred launching the elevated process
196 showMessageBox(NULL, _T("Windscribe Installer"), MB_OK | MB_ICONSTOP,
197 _T("Couldn't run installer as administrator."));
198 return -1;
199 }
200 }
201

Callers

nothing calls this directly

Calls 12

showMessageBoxFunction · 0.85
wsScopeGuardFunction · 0.85
deleteFolderFunction · 0.85
isOSCompatibleFunction · 0.85
executeProgramFunction · 0.85
generateRandomSuffixFunction · 0.85
createAdminOnlyDirectoryFunction · 0.85
setLogFunctionMethod · 0.80
extractDecompressorMethod · 0.80
extractMethod · 0.80
isElevatedFunction · 0.70
debugMessageFunction · 0.70

Tested by

no test coverage detected