| 142 | } |
| 143 | |
| 144 | int 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 |
nothing calls this directly
no test coverage detected