aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/win_updater/updater.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/win_updater/updater.cpp103
1 files changed, 20 insertions, 83 deletions
diff --git a/linden/indra/win_updater/updater.cpp b/linden/indra/win_updater/updater.cpp
index 5ea4695..bea45d1 100644
--- a/linden/indra/win_updater/updater.cpp
+++ b/linden/indra/win_updater/updater.cpp
@@ -30,7 +30,7 @@
30 */ 30 */
31 31
32// 32//
33// Usage: updater -url <url> [-name <window_title>] [-program <program_name>] [-silent] 33// Usage: updater -url <url>
34// 34//
35 35
36#include "linden_common.h" 36#include "linden_common.h"
@@ -45,9 +45,6 @@ DWORD gTotalBytes = -1;
45HWND gWindow = NULL; 45HWND gWindow = NULL;
46WCHAR gProgress[256]; 46WCHAR gProgress[256];
47char* gUpdateURL; 47char* gUpdateURL;
48char* gProgramName;
49char* gProductName;
50bool gIsSilent;
51 48
52#if _DEBUG 49#if _DEBUG
53FILE* logfile = 0; 50FILE* logfile = 0;
@@ -217,7 +214,7 @@ int WINAPI get_url_into_file(WCHAR *uri, char *path, int *cancelled)
217 fprintf(logfile,"Calling PeekMessage\n"); 214 fprintf(logfile,"Calling PeekMessage\n");
218 fflush(logfile); 215 fflush(logfile);
219#endif 216#endif
220 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 217 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
221 { 218 {
222 TranslateMessage(&msg); 219 TranslateMessage(&msg);
223 DispatchMessage(&msg); 220 DispatchMessage(&msg);
@@ -279,26 +276,14 @@ int parse_args(int argc, char **argv)
279 276
280 for (j = 1; j < argc; j++) 277 for (j = 1; j < argc; j++)
281 { 278 {
282 if ((!strcmp(argv[j], "-name")) && (++j < argc)) 279 if ((!strcmp(argv[j], "-url")) && (++j < argc))
283 {
284 gProductName = argv[j];
285 }
286 else if ((!strcmp(argv[j], "-url")) && (++j < argc))
287 { 280 {
288 gUpdateURL = argv[j]; 281 gUpdateURL = argv[j];
289 } 282 }
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 } 283 }
299 284
300 // If nothing was set, let the caller know. 285 // If nothing was set, let the caller know.
301 if (!gProductName && !gProgramName && !gIsSilent && !gUpdateURL) 286 if (!gUpdateURL)
302 { 287 {
303 return 1; 288 return 1;
304 } 289 }
@@ -350,9 +335,6 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nSho
350 } 335 }
351 336
352 gUpdateURL = NULL; 337 gUpdateURL = NULL;
353 gProgramName = NULL;
354 gProductName = NULL;
355 gIsSilent = false;
356 338
357 ///////////////////////////////////////// 339 /////////////////////////////////////////
358 // 340 //
@@ -368,21 +350,10 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nSho
368 // Parse the command line arguments 350 // Parse the command line arguments
369 // 351 //
370 int parse_args_result = parse_args(argc, argv); 352 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 353
382 WNDCLASSEX wndclassex = { 0 }; 354 WNDCLASSEX wndclassex = { 0 };
383 DEVMODE dev_mode = { 0 }; 355 DEVMODE dev_mode = { 0 };
384 char update_exec_path[MAX_PATH]; /* Flawfinder: ignore */ 356 char update_exec_path[MAX_PATH]; /* Flawfinder: ignore */
385 char *ptr;
386 357
387 const int WINDOW_WIDTH = 250; 358 const int WINDOW_WIDTH = 250;
388 const int WINDOW_HEIGHT = 100; 359 const int WINDOW_HEIGHT = 100;
@@ -403,7 +374,7 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nSho
403 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dev_mode); 374 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dev_mode);
404 375
405 gWindow = CreateWindowEx(NULL, win_class_name, 376 gWindow = CreateWindowEx(NULL, win_class_name,
406 window_title, 377 L"Second Life Updater",
407 WS_OVERLAPPEDWINDOW, 378 WS_OVERLAPPEDWINDOW,
408 CW_USEDEFAULT, 379 CW_USEDEFAULT,
409 CW_USEDEFAULT, 380 CW_USEDEFAULT,
@@ -437,24 +408,13 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nSho
437 L"Error", MB_OK); 408 L"Error", MB_OK);
438 return 1; 409 return 1;
439 } 410 }
440 if (0 == GetTempFileNameA(update_exec_path, NULL, 0, update_exec_path)) 411 strcat(update_exec_path, "Second_Life_Updater.exe");
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 412
453 WCHAR update_uri[4096]; 413 WCHAR update_uri[4096];
454 mbstowcs(update_uri, gUpdateURL, 4096); 414 mbstowcs(update_uri, gUpdateURL, 4096);
455 415
456 int success; 416 int success = 0;
457 int cancelled; 417 int cancelled = 0;
458 418
459 // Actually do the download 419 // Actually do the download
460#if _DEBUG 420#if _DEBUG
@@ -493,47 +453,24 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nSho
493 return 1; 453 return 1;
494 } 454 }
495 455
496 // Construct some parameters. 456 // TODO: Make updates silent (with /S to NSIS)
497 char params[2048]; /* Flawfinder: ignore */ 457 //char params[256]; /* Flawfinder: ignore */
498 if (gIsSilent && gProgramName) 458 //sprintf(params, "/S"); /* Flawfinder: ignore */
499 { 459 //MessageBox(gWindow,
500 _snprintf(params, sizeof(params), "/S /P=\"%s\"", gProgramName); /* Flawfinder: ignore */ 460 // L"Updating Second Life.\n\nSecond Life will automatically start once the update is complete. This may take a minute...",
501 params[2047] = '\0'; 461 // L"Download Complete",
502 } 462 // MB_OK);
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 463
517 if (32 >= (int) ShellExecuteA(gWindow, "open", update_exec_path, params, 464 if (32 >= (int) ShellExecuteA(gWindow, "open", update_exec_path, NULL,
518 "C:\\", SW_SHOWDEFAULT)) 465 "C:\\", SW_SHOWDEFAULT))
519 { 466 {
520 // No shit: less than or equal to 32 means failure 467 // Less than or equal to 32 means failure
521 MessageBox(gWindow, L"ShellExecute failed. Please try again later.", NULL, MB_OK); 468 MessageBox(gWindow, L"Update failed. Please try again later.", NULL, MB_OK);
522 return 1; 469 return 1;
523 } 470 }
524 471
525 if (gIsSilent && gProductName) 472 // Give installer some time to open a window
526 { 473 Sleep(1000);
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 474
538 return 0; 475 return 0;
539} 476}