Annotation of /linden_release/linden/indra/win_updater/updater.cpp
Parent Directory
|
Revision Log
Revision 57 - (view) (download)
| 1 : | mjm | 57 | /** |
| 2 : | * @file updater.cpp | ||
| 3 : | * @brief Windows auto-updater | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2002&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | * Copyright (c) 2002-2008, Linden Research, Inc. | ||
| 8 : | * | ||
| 9 : | * Second Life Viewer Source Code | ||
| 10 : | * The source code in this file ("Source Code") is provided by Linden Lab | ||
| 11 : | * to you under the terms of the GNU General Public License, version 2.0 | ||
| 12 : | * ("GPL"), unless you have obtained a separate licensing agreement | ||
| 13 : | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
| 14 : | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
| 15 : | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
| 16 : | * | ||
| 17 : | * There are special exceptions to the terms and conditions of the GPL as | ||
| 18 : | * it is applied to this Source Code. View the full text of the exception | ||
| 19 : | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
| 20 : | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 21 : | * | ||
| 22 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 23 : | * that you have read and understood your obligations described above, | ||
| 24 : | * and agree to abide by those obligations. | ||
| 25 : | * | ||
| 26 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 27 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 28 : | * COMPLETENESS OR PERFORMANCE. | ||
| 29 : | * $/LicenseInfo$ | ||
| 30 : | */ | ||
| 31 : | |||
| 32 : | // | ||
| 33 : | // Usage: updater -url <url> [-name <window_title>] [-program <program_name>] [-silent] | ||
| 34 : | // | ||
| 35 : | |||
| 36 : | #include "linden_common.h" | ||
| 37 : | |||
| 38 : | #include <windows.h> | ||
| 39 : | #include <wininet.h> | ||
| 40 : | |||
| 41 : | #define BUFSIZE 8192 | ||
| 42 : | |||
| 43 : | int gTotalBytesRead = 0; | ||
| 44 : | DWORD gTotalBytes = -1; | ||
| 45 : | HWND gWindow = NULL; | ||
| 46 : | WCHAR gProgress[256]; | ||
| 47 : | char* gUpdateURL; | ||
| 48 : | char* gProgramName; | ||
| 49 : | char* gProductName; | ||
| 50 : | bool gIsSilent; | ||
| 51 : | |||
| 52 : | #if _DEBUG | ||
| 53 : | FILE* logfile = 0; | ||
| 54 : | #endif | ||
| 55 : | |||
| 56 : | char* wchars_to_utf8chars(WCHAR* in_chars) | ||
| 57 : | { | ||
| 58 : | int tlen = 0; | ||
| 59 : | WCHAR* twc = in_chars; | ||
| 60 : | while (*twc++ != 0) | ||
| 61 : | { | ||
| 62 : | tlen++; | ||
| 63 : | } | ||
| 64 : | char* outchars = new char[tlen]; | ||
| 65 : | char* res = outchars; | ||
| 66 : | for (int i=0; i<tlen; i++) | ||
| 67 : | { | ||
| 68 : | int cur_char = (int)(*in_chars++); | ||
| 69 : | if (cur_char < 0x80) | ||
| 70 : | { | ||
| 71 : | *outchars++ = (char)cur_char; | ||
| 72 : | } | ||
| 73 : | else | ||
| 74 : | { | ||
| 75 : | *outchars++ = '?'; | ||
| 76 : | } | ||
| 77 : | } | ||
| 78 : | *outchars = 0; | ||
| 79 : | return res; | ||
| 80 : | } | ||
| 81 : | |||
| 82 : | int WINAPI get_url_into_file(WCHAR *uri, char *path, int *cancelled) | ||
| 83 : | { | ||
| 84 : | int success = FALSE; | ||
| 85 : | *cancelled = FALSE; | ||
| 86 : | |||
| 87 : | HINTERNET hinet, hdownload; | ||
| 88 : | char data[BUFSIZE]; /* Flawfinder: ignore */ | ||
| 89 : | unsigned long bytes_read; | ||
| 90 : | |||
| 91 : | #if _DEBUG | ||
| 92 : | fprintf(logfile,"Opening '%s'\n",path); | ||
| 93 : | fflush(logfile); | ||
| 94 : | #endif | ||
| 95 : | |||
| 96 : | FILE* fp = fopen(path, "wb"); /* Flawfinder: ignore */ | ||
| 97 : | |||
| 98 : | if (!fp) | ||
| 99 : | { | ||
| 100 : | #if _DEBUG | ||
| 101 : | fprintf(logfile,"Failed to open '%s'\n",path); | ||
| 102 : | fflush(logfile); | ||
| 103 : | #endif | ||
| 104 : | return success; | ||
| 105 : | } | ||
| 106 : | |||
| 107 : | #if _DEBUG | ||
| 108 : | fprintf(logfile,"Calling InternetOpen\n"); | ||
| 109 : | fflush(logfile); | ||
| 110 : | #endif | ||
| 111 : | // Init wininet subsystem | ||
| 112 : | hinet = InternetOpen(L"LindenUpdater", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); | ||
| 113 : | if (hinet == NULL) | ||
| 114 : | { | ||
| 115 : | return success; | ||
| 116 : | } | ||
| 117 : | |||
| 118 : | #if _DEBUG | ||
| 119 : | fprintf(logfile,"Calling InternetOpenUrl: %s\n",wchars_to_utf8chars(uri)); | ||
| 120 : | fflush(logfile); | ||
| 121 : | #endif | ||
| 122 : | hdownload = InternetOpenUrl(hinet, uri, NULL, 0, INTERNET_FLAG_NEED_FILE, NULL); | ||
| 123 : | if (hdownload == NULL) | ||
| 124 : | { | ||
| 125 : | #if _DEBUG | ||
| 126 : | DWORD err = GetLastError(); | ||
| 127 : | fprintf(logfile,"InternetOpenUrl Failed: %d\n",err); | ||
| 128 : | fflush(logfile); | ||
| 129 : | #endif | ||
| 130 : | return success; | ||
| 131 : | } | ||
| 132 : | |||
| 133 : | DWORD sizeof_total_bytes = sizeof(gTotalBytes); | ||
| 134 : | HttpQueryInfo(hdownload, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &gTotalBytes, &sizeof_total_bytes, NULL); | ||
| 135 : | |||
| 136 : | DWORD total_bytes = 0; | ||
| 137 : | success = InternetQueryDataAvailable(hdownload, &total_bytes, 0, 0); | ||
| 138 : | if (success == FALSE) | ||
| 139 : | { | ||
| 140 : | #if _DEBUG | ||
| 141 : | DWORD err = GetLastError(); | ||
| 142 : | fprintf(logfile,"InternetQueryDataAvailable Failed: %d bytes Err:%d\n",total_bytes,err); | ||
| 143 : | fflush(logfile); | ||
| 144 : | #endif | ||
| 145 : | return success; | ||
| 146 : | } | ||
| 147 : | |||
| 148 : | success = FALSE; | ||
| 149 : | while(!success && !(*cancelled)) | ||
| 150 : | { | ||
| 151 : | MSG msg; | ||
| 152 : | |||
| 153 : | #if _DEBUG | ||
| 154 : | fprintf(logfile,"Calling InternetReadFile\n"); | ||
| 155 : | fflush(logfile); | ||
| 156 : | #endif | ||
| 157 : | if (!InternetReadFile(hdownload, data, BUFSIZE, &bytes_read)) | ||
| 158 : | { | ||
| 159 : | #if _DEBUG | ||
| 160 : | fprintf(logfile,"InternetReadFile Failed.\n"); | ||
| 161 : | fflush(logfile); | ||
| 162 : | #endif | ||
| 163 : | // ...an error occurred | ||
| 164 : | return FALSE; | ||
| 165 : | } | ||
| 166 : | |||
| 167 : | #if _DEBUG | ||
| 168 : | if (!bytes_read) | ||
| 169 : | { | ||
| 170 : | fprintf(logfile,"InternetReadFile Read 0 bytes.\n"); | ||
| 171 : | fflush(logfile); | ||
| 172 : | } | ||
| 173 : | #endif | ||
| 174 : | |||
| 175 : | #if _DEBUG | ||
| 176 : | fprintf(logfile,"Reading Data, bytes_read = %d\n",bytes_read); | ||
| 177 : | fflush(logfile); | ||
| 178 : | #endif | ||
| 179 : | |||
| 180 : | if (bytes_read == 0) | ||
| 181 : | { | ||
| 182 : | // If InternetFileRead returns TRUE AND bytes_read == 0 | ||
| 183 : | // we've successfully downloaded the entire file | ||
| 184 : | wsprintf(gProgress, L"Download complete."); | ||
| 185 : | success = TRUE; | ||
| 186 : | } | ||
| 187 : | else | ||
| 188 : | { | ||
| 189 : | // write what we've got, then continue | ||
| 190 : | fwrite(data, sizeof(char), bytes_read, fp); | ||
| 191 : | |||
| 192 : | gTotalBytesRead += int(bytes_read); | ||
| 193 : | |||
| 194 : | if (gTotalBytes != -1) | ||
| 195 : | wsprintf(gProgress, L"Downloaded: %d%%", 100 * gTotalBytesRead / gTotalBytes); | ||
| 196 : | else | ||
| 197 : | wsprintf(gProgress, L"Downloaded: %dK", gTotalBytesRead / 1024); | ||
| 198 : | |||
| 199 : | } | ||
| 200 : | |||
| 201 : | #if _DEBUG | ||
| 202 : | fprintf(logfile,"Calling InvalidateRect\n"); | ||
| 203 : | fflush(logfile); | ||
| 204 : | #endif | ||
| 205 : | |||
| 206 : | // Mark the window as needing redraw (of the whole thing) | ||
| 207 : | InvalidateRect(gWindow, NULL, TRUE); | ||
| 208 : | |||
| 209 : | // Do the redraw | ||
| 210 : | #if _DEBUG | ||
| 211 : | fprintf(logfile,"Calling UpdateWindow\n"); | ||
| 212 : | fflush(logfile); | ||
| 213 : | #endif | ||
| 214 : | UpdateWindow(gWindow); | ||
| 215 : | |||
| 216 : | #if _DEBUG | ||
| 217 : | fprintf(logfile,"Calling PeekMessage\n"); | ||
| 218 : | fflush(logfile); | ||
| 219 : | #endif | ||
| 220 : | if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) | ||
| 221 : | { | ||
| 222 : | TranslateMessage(&msg); | ||
| 223 : | DispatchMessage(&msg); | ||
| 224 : | |||
| 225 : | if (msg.message == WM_QUIT) | ||
| 226 : | { | ||
| 227 : | // bail out, user cancelled | ||
| 228 : | *cancelled = TRUE; | ||
| 229 : | } | ||
| 230 : | } | ||
| 231 : | } | ||
| 232 : | |||
| 233 : | #if _DEBUG | ||
| 234 : | fprintf(logfile,"Calling InternetCloseHandle\n"); | ||
| 235 : | fclose(logfile); | ||
| 236 : | #endif | ||
| 237 : | |||
| 238 : | fclose(fp); | ||
| 239 : | InternetCloseHandle(hdownload); | ||
| 240 : | InternetCloseHandle(hinet); | ||
| 241 : | |||
| 242 : | return success; | ||
| 243 : | } | ||
| 244 : | |||
| 245 : | LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) | ||
| 246 : | { | ||
| 247 : | HDC hdc; // Drawing context | ||
| 248 : | PAINTSTRUCT ps; | ||
| 249 : | |||
| 250 : | switch(message) | ||
| 251 : | { | ||
| 252 : | case WM_PAINT: | ||
| 253 : | { | ||
| 254 : | hdc = BeginPaint(hwnd, &ps); | ||
| 255 : | |||
| 256 : | RECT rect; | ||
| 257 : | GetClientRect(hwnd, &rect); | ||
| 258 : | DrawText(hdc, gProgress, -1, &rect, | ||
| 259 : | DT_SINGLELINE | DT_CENTER | DT_VCENTER); | ||
| 260 : | |||
| 261 : | EndPaint(hwnd, &ps); | ||
| 262 : | return 0; | ||
| 263 : | } | ||
| 264 : | case WM_CLOSE: | ||
| 265 : | case WM_DESTROY: | ||
| 266 : | // Get out of full screen | ||
| 267 : | // full_screen_mode(false); | ||
| 268 : | PostQuitMessage(0); | ||
| 269 : | return 0; | ||
| 270 : | } | ||
| 271 : | return DefWindowProc(hwnd, message, wparam, lparam); | ||
| 272 : | } | ||
| 273 : | |||
| 274 : | #define win_class_name L"FullScreen" | ||
| 275 : | |||
| 276 : | int parse_args(int argc, char **argv) | ||
| 277 : | { | ||
| 278 : | int j; | ||
| 279 : | |||
| 280 : | for (j = 1; j < argc; j++) | ||
| 281 : | { | ||
| 282 : | if ((!strcmp(argv[j], "-name")) && (++j < argc)) | ||
| 283 : | { | ||
| 284 : | gProductName = argv[j]; | ||
| 285 : | } | ||
| 286 : | else if ((!strcmp(argv[j], "-url")) && (++j < argc)) | ||
| 287 : | { | ||
| 288 : | gUpdateURL = argv[j]; | ||
| 289 : | } | ||
| 290 : | else if ((!strcmp(argv[j], "-program")) && (++j < argc)) | ||
| 291 : | { | ||
| 292 : | gProgramName = argv[j]; | ||
| 293 : | } | ||
| 294 : | else if (!strcmp(argv[j], "-silent")) | ||
| 295 : | { | ||
| 296 : | gIsSilent = true; | ||
| 297 : | } | ||
| 298 : | } | ||
| 299 : | |||
| 300 : | // If nothing was set, let the caller know. | ||
| 301 : | if (!gProductName && !gProgramName && !gIsSilent && !gUpdateURL) | ||
| 302 : | { | ||
| 303 : | return 1; | ||
| 304 : | } | ||
| 305 : | return 0; | ||
| 306 : | } | ||
| 307 : | |||
| 308 : | int WINAPI | ||
| 309 : | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) | ||
| 310 : | { | ||
| 311 : | // Parse the command line. | ||
| 312 : | LPSTR cmd_line_including_exe_name = GetCommandLineA(); | ||
| 313 : | |||
| 314 : | const int MAX_ARGS = 100; | ||
| 315 : | int argc = 0; | ||
| 316 : | char* argv[MAX_ARGS]; /* Flawfinder: ignore */ | ||
| 317 : | |||
| 318 : | #if _DEBUG | ||
| 319 : | logfile = _wfopen(TEXT("updater.log"),TEXT("wt")); | ||
| 320 : | fprintf(logfile,"Parsing command arguments\n"); | ||
| 321 : | fflush(logfile); | ||
| 322 : | #endif | ||
| 323 : | |||
| 324 : | char *token = NULL; | ||
| 325 : | if( cmd_line_including_exe_name[0] == '\"' ) | ||
| 326 : | { | ||
| 327 : | // Exe name is enclosed in quotes | ||
| 328 : | token = strtok( cmd_line_including_exe_name, "\"" ); | ||
| 329 : | argv[argc++] = token; | ||
| 330 : | token = strtok( NULL, " \t," ); | ||
| 331 : | } | ||
| 332 : | else | ||
| 333 : | { | ||
| 334 : | // Exe name is not enclosed in quotes | ||
| 335 : | token = strtok( cmd_line_including_exe_name, " \t," ); | ||
| 336 : | } | ||
| 337 : | |||
| 338 : | while( (token != NULL) && (argc < MAX_ARGS) ) | ||
| 339 : | { | ||
| 340 : | argv[argc++] = token; | ||
| 341 : | /* Get next token: */ | ||
| 342 : | if (*(token + strlen(token) + 1) == '\"') /* Flawfinder: ignore */ | ||
| 343 : | { | ||
| 344 : | token = strtok( NULL, "\""); | ||
| 345 : | } | ||
| 346 : | else | ||
| 347 : | { | ||
| 348 : | token = strtok( NULL, " \t," ); | ||
| 349 : | } | ||
| 350 : | } | ||
| 351 : | |||
| 352 : | gUpdateURL = NULL; | ||
| 353 : | gProgramName = NULL; | ||
| 354 : | gProductName = NULL; | ||
| 355 : | gIsSilent = false; | ||
| 356 : | |||
| 357 : | ///////////////////////////////////////// | ||
| 358 : | // | ||
| 359 : | // Process command line arguments | ||
| 360 : | // | ||
| 361 : | |||
| 362 : | #if _DEBUG | ||
| 363 : | fprintf(logfile,"Processing command arguments\n"); | ||
| 364 : | fflush(logfile); | ||
| 365 : | #endif | ||
| 366 : | |||
| 367 : | // | ||
| 368 : | // Parse the command line arguments | ||
| 369 : | // | ||
| 370 : | int parse_args_result = parse_args(argc, argv); | ||
| 371 : | WCHAR window_title[2048]; | ||
| 372 : | if (gProductName) | ||
| 373 : | { | ||
| 374 : | mbstowcs(window_title, gProductName, 2048); | ||
| 375 : | wcscat(window_title, L" Updater"); /* Flawfinder: ignore */ | ||
| 376 : | } | ||
| 377 : | else | ||
| 378 : | { | ||
| 379 : | mbstowcs(window_title, "Second Life Updater", 2048); | ||
| 380 : | } | ||
| 381 : | |||
| 382 : | WNDCLASSEX wndclassex = { 0 }; | ||
| 383 : | DEVMODE dev_mode = { 0 }; | ||
| 384 : | char update_exec_path[MAX_PATH]; /* Flawfinder: ignore */ | ||
| 385 : | char *ptr; | ||
| 386 : | |||
| 387 : | const int WINDOW_WIDTH = 250; | ||
| 388 : | const int WINDOW_HEIGHT = 100; | ||
| 389 : | |||
| 390 : | wsprintf(gProgress, L"Connecting..."); | ||
| 391 : | |||
| 392 : | /* Init the WNDCLASSEX */ | ||
| 393 : | wndclassex.cbSize = sizeof(WNDCLASSEX); | ||
| 394 : | wndclassex.style = CS_HREDRAW | CS_VREDRAW; | ||
| 395 : | wndclassex.hInstance = hInstance; | ||
| 396 : | wndclassex.lpfnWndProc = WinProc; | ||
| 397 : | wndclassex.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); | ||
| 398 : | wndclassex.lpszClassName = win_class_name; | ||
| 399 : | |||
| 400 : | RegisterClassEx(&wndclassex); | ||
| 401 : | |||
| 402 : | // Get the size of the screen | ||
| 403 : | EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dev_mode); | ||
| 404 : | |||
| 405 : | gWindow = CreateWindowEx(NULL, win_class_name, | ||
| 406 : | window_title, | ||
| 407 : | WS_OVERLAPPEDWINDOW, | ||
| 408 : | CW_USEDEFAULT, | ||
| 409 : | CW_USEDEFAULT, | ||
| 410 : | WINDOW_WIDTH, | ||
| 411 : | WINDOW_HEIGHT, | ||
| 412 : | NULL, NULL, hInstance, NULL); | ||
| 413 : | |||
| 414 : | ShowWindow(gWindow, nShowCmd); | ||
| 415 : | UpdateWindow(gWindow); | ||
| 416 : | |||
| 417 : | if (parse_args_result) | ||
| 418 : | { | ||
| 419 : | MessageBox(gWindow, | ||
| 420 : | L"Usage: updater -url <url> [-name <window_title>] [-program <program_name>] [-silent]", | ||
| 421 : | L"Usage", MB_OK); | ||
| 422 : | return parse_args_result; | ||
| 423 : | } | ||
| 424 : | |||
| 425 : | // Did we get a userserver to work with? | ||
| 426 : | if (!gUpdateURL) | ||
| 427 : | { | ||
| 428 : | MessageBox(gWindow, L"Please specify the download url from the command line", | ||
| 429 : | L"Error", MB_OK); | ||
| 430 : | return 1; | ||
| 431 : | } | ||
| 432 : | |||
| 433 : | // Can't feed GetTempPath into GetTempFile directly | ||
| 434 : | if (0 == GetTempPathA(MAX_PATH - 14, update_exec_path)) | ||
| 435 : | { | ||
| 436 : | MessageBox(gWindow, L"Problem with GetTempPath()", | ||
| 437 : | L"Error", MB_OK); | ||
| 438 : | return 1; | ||
| 439 : | } | ||
| 440 : | if (0 == GetTempFileNameA(update_exec_path, NULL, 0, update_exec_path)) | ||
| 441 : | { | ||
| 442 : | MessageBox(gWindow, L"Problem with GetTempFileName()", | ||
| 443 : | L"Error", MB_OK); | ||
| 444 : | return 1; | ||
| 445 : | } | ||
| 446 : | // Hack hack hack | ||
| 447 : | ptr = strrchr(update_exec_path, '.'); | ||
| 448 : | *(ptr + 1) = 'e'; | ||
| 449 : | *(ptr + 2) = 'x'; | ||
| 450 : | *(ptr + 3) = 'e'; | ||
| 451 : | *(ptr + 4) = 0; | ||
| 452 : | |||
| 453 : | WCHAR update_uri[4096]; | ||
| 454 : | mbstowcs(update_uri, gUpdateURL, 4096); | ||
| 455 : | |||
| 456 : | int success; | ||
| 457 : | int cancelled; | ||
| 458 : | |||
| 459 : | // Actually do the download | ||
| 460 : | #if _DEBUG | ||
| 461 : | fprintf(logfile,"Calling get_url_into_file\n"); | ||
| 462 : | fflush(logfile); | ||
| 463 : | #endif | ||
| 464 : | success = get_url_into_file(update_uri, update_exec_path, &cancelled); | ||
| 465 : | |||
| 466 : | // WinInet can't tell us if we got a 404 or not. Therefor, we check | ||
| 467 : | // for the size of the downloaded file, and assume that our installer | ||
| 468 : | // will always be greater than 1MB. | ||
| 469 : | if (gTotalBytesRead < (1024 * 1024) && ! cancelled) | ||
| 470 : | { | ||
| 471 : | MessageBox(gWindow, | ||
| 472 : | L"The Second Life auto-update has failed.\n" | ||
| 473 : | L"The problem may be caused by other software installed \n" | ||
| 474 : | L"on your computer, such as a firewall.\n" | ||
| 475 : | L"Please visit http://secondlife.com/download/ \n" | ||
| 476 : | L"to download the latest version of Second Life.\n", | ||
| 477 : | NULL, MB_OK); | ||
| 478 : | return 1; | ||
| 479 : | } | ||
| 480 : | |||
| 481 : | if (cancelled) | ||
| 482 : | { | ||
| 483 : | // silently exit | ||
| 484 : | return 0; | ||
| 485 : | } | ||
| 486 : | |||
| 487 : | if (!success) | ||
| 488 : | { | ||
| 489 : | MessageBox(gWindow, | ||
| 490 : | L"Second Life download failed.\n" | ||
| 491 : | L"Please try again later.", | ||
| 492 : | NULL, MB_OK); | ||
| 493 : | return 1; | ||
| 494 : | } | ||
| 495 : | |||
| 496 : | // Construct some parameters. | ||
| 497 : | char params[2048]; /* Flawfinder: ignore */ | ||
| 498 : | if (gIsSilent && gProgramName) | ||
| 499 : | { | ||
| 500 : | _snprintf(params, sizeof(params), "/S /P=\"%s\"", gProgramName); /* Flawfinder: ignore */ | ||
| 501 : | params[2047] = '\0'; | ||
| 502 : | } | ||
| 503 : | else if (gProgramName) | ||
| 504 : | { | ||
| 505 : | _snprintf(params, sizeof(params), "/P=\"%s\"", gProgramName); /* Flawfinder: ignore */ | ||
| 506 : | params[2047] = '\0'; | ||
| 507 : | } | ||
| 508 : | else if (gIsSilent) | ||
| 509 : | { | ||
| 510 : | sprintf(params, "/S"); /* Flawfinder: ignore */ | ||
| 511 : | } | ||
| 512 : | else | ||
| 513 : | { | ||
| 514 : | params[0] = '\0'; | ||
| 515 : | } | ||
| 516 : | |||
| 517 : | if (32 >= (int) ShellExecuteA(gWindow, "open", update_exec_path, params, | ||
| 518 : | "C:\\", SW_SHOWDEFAULT)) | ||
| 519 : | { | ||
| 520 : | // No shit: less than or equal to 32 means failure | ||
| 521 : | MessageBox(gWindow, L"ShellExecute failed. Please try again later.", NULL, MB_OK); | ||
| 522 : | return 1; | ||
| 523 : | } | ||
| 524 : | |||
| 525 : | if (gIsSilent && gProductName) | ||
| 526 : | { | ||
| 527 : | WCHAR message[2048]; | ||
| 528 : | WCHAR wproduct[2048]; | ||
| 529 : | mbstowcs(wproduct, gProductName, 2048); | ||
| 530 : | |||
| 531 : | wsprintf(message, | ||
| 532 : | L"Updating %s. %s will automatically start once the update is complete. This may take a minute...", | ||
| 533 : | wproduct, wproduct); | ||
| 534 : | |||
| 535 : | MessageBox(gWindow, message, L"Download Complete", MB_OK); | ||
| 536 : | } | ||
| 537 : | |||
| 538 : | return 0; | ||
| 539 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

