Changeset 95827 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Jul 26, 2022 9:55:21 AM (3 years ago)
- Location:
- trunk/src/VBox/Additions/WINNT/VBoxTray
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.cpp
r93115 r95827 21 21 #include <iprt/alloca.h> 22 22 #include <iprt/system.h> 23 #include <iprt/utf16.h> 23 24 #include <VBox/Log.h> 24 25 #include <VBox/VBoxGuestLib.h> … … 331 332 } 332 333 334 /** 335 * Shows a message box with a printf() style formatted string. 336 * 337 * @param pszTitle Title of the message box. 338 * @param uStyle Style of message box to use (see MSDN, MB_ defines). 339 * When 0 is specified, MB_ICONINFORMATION will be used. 340 * @param pszFmt Printf-style format string to show in the message box body. 341 * @param ... Arguments for format string. 342 */ 343 void hlpShowMessageBox(const char *pszTitle, UINT uStyle, const char *pszFmt, ...) 344 { 345 if (!uStyle) 346 uStyle = MB_ICONINFORMATION; 347 348 char *pszMsg; 349 va_list va; 350 va_start(va, pszFmt); 351 int rc = RTStrAPrintfV(&pszMsg, pszFmt, va); 352 va_end(va); 353 if (rc >= 0) 354 { 355 PRTUTF16 pwszTitle; 356 rc = RTStrToUtf16(pszTitle, &pwszTitle); 357 if (RT_SUCCESS(rc)) 358 { 359 PRTUTF16 pwszMsg; 360 rc = RTStrToUtf16(pszMsg, &pwszMsg); 361 if (RT_SUCCESS(rc)) 362 { 363 MessageBoxW(GetDesktopWindow(), pwszMsg, pwszTitle, uStyle); 364 RTUtf16Free(pwszMsg); 365 } 366 else 367 MessageBoxA(GetDesktopWindow(), pszMsg, pszTitle, uStyle); 368 RTUtf16Free(pwszTitle); 369 } 370 } 371 else /* Should never happen! */ 372 AssertMsgFailed(("Failed to format error text of format string: %s!\n", pszFmt)); 373 RTStrFree(pszMsg); 374 } 375 -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.h
r93115 r95827 24 24 // #define DEBUG_DISPLAY_CHANGE 25 25 26 /** @todo r=andy WTF? Remove this!! */ 26 27 #ifdef DEBUG_DISPLAY_CHANGE 27 28 # define DDCLOG(a) Log(a) … … 30 31 #endif /* !DEBUG_DISPLAY_CHANGE */ 31 32 32 extern int hlpReportStatus(VBoxGuestFacilityStatus statusCurrent);33 extern int hlpReportStatus(VBoxGuestFacilityStatus statusCurrent); 33 34 extern void hlpReloadCursor(void); 34 35 extern void hlpResizeRect(RECTL *paRects, unsigned nRects, unsigned uPrimary, unsigned uResized, int iNewWidth, int iNewHeight, int iNewPosX, int iNewPosY); 35 extern int hlpShowBalloonTip(HINSTANCE hInst, HWND hWnd, UINT uID, const char *pszMsg, const char *pszTitle, UINT uTimeout, DWORD dwInfoFlags); 36 extern int hlpShowBalloonTip(HINSTANCE hInst, HWND hWnd, UINT uID, const char *pszMsg, const char *pszTitle, UINT uTimeout, DWORD dwInfoFlags); 37 extern void hlpShowMessageBox(const char *pszTitle, UINT uStyle, const char *pszFmt, ...); 36 38 37 39 #endif /* !GA_INCLUDED_SRC_WINNT_VBoxTray_VBoxHelpers_h */ -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp
r94629 r95827 42 42 #include <iprt/asm.h> 43 43 #include <iprt/buildconfig.h> 44 #include <iprt/getopt.h> 44 45 #include <iprt/ldr.h> 46 #include <iprt/message.h> 45 47 #include <iprt/path.h> 46 48 #include <iprt/process.h> 47 49 #include <iprt/system.h> 48 50 #include <iprt/time.h> 51 #include <iprt/utf16.h> 49 52 50 53 #include <VBox/log.h> … … 132 135 * Global Variables * 133 136 *********************************************************************************************************************************/ 137 int g_cVerbosity = 0; 134 138 HANDLE g_hStopSem; 135 139 HANDLE g_hSeamlessWtNotifyEvent = 0; … … 559 563 /** 560 564 * Creates the default release logger outputting to the specified file. 561 * Pass NULL for disabled logging.562 565 * 563 566 * @return IPRT status code. 567 * @param pszLogFile Path to log file to use. 564 568 */ 565 static int vboxTrayLogCreate( void)569 static int vboxTrayLogCreate(const char *pszLogFile) 566 570 { 567 571 /* Create release (or debug) logger (stdout + file). */ 568 572 static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES; 569 #ifdef DEBUG /* See below, debug logger not release. */570 static const char s_szEnvVarPfx[] = "VBOXTRAY_LOG";571 static const char s_szGroupSettings[] = "all.e.l.f";572 #else573 573 static const char s_szEnvVarPfx[] = "VBOXTRAY_RELEASE_LOG"; 574 static const char s_szGroupSettings[] = "all"; 575 #endif 574 576 575 RTERRINFOSTATIC ErrInfo; 577 576 int rc = RTLogCreateEx(&g_pLoggerRelease, s_szEnvVarPfx, 578 577 RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME_PROG | RTLOGFLAGS_USECRLF, 579 s_szGroupSettings, RT_ELEMENTS(s_apszGroups), s_apszGroups, UINT32_MAX,578 "all.e", RT_ELEMENTS(s_apszGroups), s_apszGroups, UINT32_MAX, 580 579 0 /*cBufDescs*/, NULL /*paBufDescs*/, RTLOGDEST_STDOUT, 581 580 vboxTrayLogHeaderFooter, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime, 582 581 NULL /*pOutputIf*/, NULL /*pvOutputIfUser*/, 583 RTErrInfoInitStatic(&ErrInfo), NULL /*pszFilenameFmt*/);582 RTErrInfoInitStatic(&ErrInfo), "%s", pszLogFile ? pszLogFile : ""); 584 583 if (RT_SUCCESS(rc)) 585 584 { 586 #ifdef DEBUG587 /* Register this logger as the _debug_ logger.588 Note! This means any Log() statement preceeding this may cause a589 20yy-*VBoxTray*.log file to have been created and it will stay590 open till the process quits as we don't destroy it when591 replacing it here. */592 RTLogSetDefaultInstance(g_pLoggerRelease);593 #else594 585 /* Register this logger as the release logger. */ 595 586 RTLogRelSetDefaultInstance(g_pLoggerRelease); 596 #endif 587 588 /* Register this logger as the _debug_ logger. */ 589 RTLogSetDefaultInstance(g_pLoggerRelease); 590 591 switch (g_cVerbosity) /* Not very elegant, but has to do it for now. */ 592 { 593 case 1: 594 rc = RTLogGroupSettings(g_pLoggerRelease, "all.e.l"); 595 break; 596 597 case 2: 598 rc = RTLogGroupSettings(g_pLoggerRelease, "all.e.l.l2"); 599 break; 600 601 case 3: 602 rc = RTLogGroupSettings(g_pLoggerRelease, "all.e.l.l2.l3"); 603 break; 604 605 case 4: 606 RT_FALL_THROUGH(); 607 default: 608 rc = RTLogGroupSettings(g_pLoggerRelease, "all.e.l.l2.l3.f"); 609 break; 610 } 611 if (RT_FAILURE(rc)) 612 RTMsgError("Setting debug logging failed, rc=%Rrc\n", rc); 613 597 614 /* Explicitly flush the log in case of VBOXTRAY_RELEASE_LOG=buffered. */ 598 615 RTLogFlush(g_pLoggerRelease); … … 985 1002 { 986 1003 RT_NOREF(hPrevInstance, lpCmdLine, nCmdShow); 987 int rc = RTR3InitExeNoArguments(0); 1004 1005 int rc = RTR3InitExe(__argc, &__argv, RTR3INIT_FLAGS_STANDALONE_APP); 988 1006 if (RT_FAILURE(rc)) 989 return RTEXITCODE_INIT; 1007 return RTMsgInitFailure(rc); 1008 1009 LPWSTR pwszCmdLine = GetCommandLineW(); 1010 if (!pwszCmdLine) 1011 return RTMsgErrorExit(RTEXITCODE_FAILURE, "GetCommandLineW failed"); 1012 1013 char *pszCmdLine; 1014 rc = RTUtf16ToUtf8(pwszCmdLine, &pszCmdLine); /* leaked */ 1015 if (RT_FAILURE(rc)) 1016 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to convert the command line: %Rrc", rc); 1017 1018 char szLogFile[RTPATH_MAX] = {0}; 1019 1020 int cArgs; 1021 char **papszArgs; 1022 rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszCmdLine, RTGETOPTARGV_CNV_QUOTE_MS_CRT, NULL); 1023 if (RT_SUCCESS(rc)) 1024 { 1025 /* 1026 * Parse the top level arguments until we find a command. 1027 */ 1028 static const RTGETOPTDEF s_aOptions[] = 1029 { 1030 { "--help", 'h', RTGETOPT_REQ_NOTHING }, 1031 { "-help", 'h', RTGETOPT_REQ_NOTHING }, 1032 { "/help", 'h', RTGETOPT_REQ_NOTHING }, 1033 { "/?", 'h', RTGETOPT_REQ_NOTHING }, 1034 { "--logfile", 'l', RTGETOPT_REQ_STRING }, 1035 { "-l", 'l', RTGETOPT_REQ_STRING }, 1036 { "/l", 'l', RTGETOPT_REQ_STRING }, 1037 { "--verbose", 'v', RTGETOPT_REQ_NOTHING }, 1038 { "-v", 'v', RTGETOPT_REQ_NOTHING }, 1039 { "/v", 'v', RTGETOPT_REQ_NOTHING }, 1040 { "--version", 'V', RTGETOPT_REQ_NOTHING }, 1041 { "-version", 'V', RTGETOPT_REQ_NOTHING }, 1042 { "/version", 'V', RTGETOPT_REQ_NOTHING }, 1043 { "/V", 'V', RTGETOPT_REQ_NOTHING } 1044 }; 1045 1046 RTGETOPTSTATE GetState; 1047 rc = RTGetOptInit(&GetState, cArgs, papszArgs, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0 /*fFlags*/); 1048 if (RT_FAILURE(rc)) 1049 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTGetOptInit failed: %Rrc\n", rc); 1050 1051 int ch; 1052 RTGETOPTUNION ValueUnion; 1053 while ((ch = RTGetOpt(&GetState, &ValueUnion)) != 0) 1054 { 1055 switch (ch) 1056 { 1057 case 'h': 1058 hlpShowMessageBox(VBOX_VBOXTRAY_TITLE, MB_ICONINFORMATION, "-- %s v%u.%u.%ur%u --\n" 1059 "\n" 1060 "Command Line Parameters:\n\n" 1061 "-l, --logfile <file>\n" 1062 " Enables logging to a file\n" 1063 "-v, --verbose\n" 1064 " Increases verbosity\n" 1065 "-V, --version\n" 1066 " Displays version number and exit\n" 1067 "-?, -h, --help\n" 1068 " Displays this help text and exit\n" 1069 "\n" 1070 "Examples:\n" 1071 " %s -vvv\n", 1072 VBOX_VBOXTRAY_TITLE, VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV, 1073 papszArgs[0], papszArgs[0]); 1074 return RTEXITCODE_SUCCESS; 1075 1076 case 'l': 1077 if (*ValueUnion.psz == '\0') 1078 szLogFile[0] = '\0'; 1079 else 1080 { 1081 rc = RTPathAbs(ValueUnion.psz, szLogFile, sizeof(szLogFile)); 1082 if (RT_FAILURE(rc)) 1083 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Log file path is too long (%Rrc)", rc); 1084 } 1085 break; 1086 1087 case 'v': 1088 g_cVerbosity++; 1089 break; 1090 1091 case 'V': 1092 hlpShowMessageBox(VBOX_VBOXTRAY_TITLE, MB_ICONINFORMATION, 1093 "Version: %u.%u.%ur%u", 1094 VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV); 1095 return RTEXITCODE_SUCCESS; 1096 1097 default: 1098 rc = RTGetOptPrintError(ch, &ValueUnion); 1099 break; 1100 } 1101 } 1102 1103 RTGetOptArgvFree(papszArgs); 1104 } 1105 else 1106 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTGetOptArgvFromString failed: %Rrc", rc); 990 1107 991 1108 /* Note: Do not use a global namespace ("Global\\") for mutex name here, 992 1109 * will blow up NT4 compatibility! */ 993 HANDLE hMutexAppRunning = CreateMutex(NULL, FALSE, "VBoxTray");1110 HANDLE hMutexAppRunning = CreateMutex(NULL, FALSE, VBOX_VBOXTRAY_TITLE); 994 1111 if ( hMutexAppRunning != NULL 995 1112 && GetLastError() == ERROR_ALREADY_EXISTS) … … 998 1115 CloseHandle (hMutexAppRunning); 999 1116 hMutexAppRunning = NULL; 1000 return 0; 1001 } 1002 1003 LogRel(("%s r%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr())); 1004 1005 rc = vboxTrayLogCreate(); 1117 return RTEXITCODE_SUCCESS; 1118 } 1119 1120 rc = vboxTrayLogCreate(szLogFile[0] ? szLogFile : NULL); 1006 1121 if (RT_SUCCESS(rc)) 1007 1122 { 1123 LogRel(("Verbosity level: %d\n", g_cVerbosity)); 1124 1008 1125 rc = VbglR3Init(); 1009 1126 if (RT_SUCCESS(rc)) … … 1154 1271 case WM_LBUTTONDBLCLK: 1155 1272 break; 1156 #ifdef DEBUG1157 1273 case WM_RBUTTONDOWN: 1158 1274 { 1275 if (!g_cVerbosity) /* Don't show menu when running in non-verbose mode. */ 1276 break; 1277 1159 1278 POINT lpCursor; 1160 1279 if (GetCursorPos(&lpCursor)) … … 1192 1311 break; 1193 1312 } 1194 #endif1195 1313 } 1196 1314 return 0; -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h
r93115 r95827 39 39 #include "VBoxDispIf.h" 40 40 41 42 /********************************************************************************************************************************* 43 * Defined Constants And Macros * 44 *********************************************************************************************************************************/ 45 /** Title of the program to show. 46 * Also shown as part of message boxes. */ 47 #define VBOX_VBOXTRAY_TITLE "VBoxTray" 48 41 49 /* 42 50 * Windows messsages. … … 58 66 #define TIMERID_VBOXTRAY_DT_TIMER 1002 59 67 #define TIMERID_VBOXTRAY_ST_DELAYED_INIT_TIMER 1003 68 69 70 /********************************************************************************************************************************* 71 * Common structures * 72 *********************************************************************************************************************************/ 60 73 61 74 /** … … 123 136 } VBOXSERVICEDESC, *PVBOXSERVICEDESC; 124 137 125 extern VBOXSERVICEDESC g_SvcDescDisplay;126 #ifdef VBOX_WITH_SHARED_CLIPBOARD127 extern VBOXSERVICEDESC g_SvcDescClipboard;128 #endif129 extern VBOXSERVICEDESC g_SvcDescSeamless;130 extern VBOXSERVICEDESC g_SvcDescVRDP;131 extern VBOXSERVICEDESC g_SvcDescIPC;132 extern VBOXSERVICEDESC g_SvcDescLA;133 #ifdef VBOX_WITH_DRAG_AND_DROP134 extern VBOXSERVICEDESC g_SvcDescDnD;135 #endif136 138 137 139 /** … … 174 176 } VBOXGLOBALMESSAGE, *PVBOXGLOBALMESSAGE; 175 177 178 179 /********************************************************************************************************************************* 180 * Externals * 181 *********************************************************************************************************************************/ 182 extern VBOXSERVICEDESC g_SvcDescDisplay; 183 #ifdef VBOX_WITH_SHARED_CLIPBOARD 184 extern VBOXSERVICEDESC g_SvcDescClipboard; 185 #endif 186 extern VBOXSERVICEDESC g_SvcDescSeamless; 187 extern VBOXSERVICEDESC g_SvcDescVRDP; 188 extern VBOXSERVICEDESC g_SvcDescIPC; 189 extern VBOXSERVICEDESC g_SvcDescLA; 190 #ifdef VBOX_WITH_DRAG_AND_DROP 191 extern VBOXSERVICEDESC g_SvcDescDnD; 192 #endif 193 194 extern int g_cVerbosity; 176 195 extern HINSTANCE g_hInstance; 177 196 extern HWND g_hwndToolWindow;
Note:
See TracChangeset
for help on using the changeset viewer.