[37422] | 1 | /* $Id: VBoxTray.cpp 100204 2023-06-19 09:11:37Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[8850] | 3 | * VBoxTray - Guest Additions Tray Application
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[1] | 26 | */
|
---|
| 27 |
|
---|
[33966] | 28 |
|
---|
[57358] | 29 | /*********************************************************************************************************************************
|
---|
| 30 | * Header Files *
|
---|
| 31 | *********************************************************************************************************************************/
|
---|
[49891] | 32 | #include <package-generated.h>
|
---|
| 33 | #include "product-generated.h"
|
---|
| 34 |
|
---|
[8850] | 35 | #include "VBoxTray.h"
|
---|
[95965] | 36 | #include "VBoxTrayInternal.h"
|
---|
[34080] | 37 | #include "VBoxTrayMsg.h"
|
---|
[33966] | 38 | #include "VBoxHelpers.h"
|
---|
[3811] | 39 | #include "VBoxSeamless.h"
|
---|
[4266] | 40 | #include "VBoxClipboard.h"
|
---|
| 41 | #include "VBoxDisplay.h"
|
---|
[4540] | 42 | #include "VBoxVRDP.h"
|
---|
[23053] | 43 | #include "VBoxHostVersion.h"
|
---|
[49891] | 44 | #ifdef VBOX_WITH_DRAG_AND_DROP
|
---|
| 45 | # include "VBoxDnD.h"
|
---|
| 46 | #endif
|
---|
[34080] | 47 | #include "VBoxIPC.h"
|
---|
[40498] | 48 | #include "VBoxLA.h"
|
---|
[3881] | 49 | #include <VBoxHook.h>
|
---|
[1] | 50 |
|
---|
[4466] | 51 | #include <sddl.h>
|
---|
| 52 |
|
---|
[57741] | 53 | #include <iprt/asm.h>
|
---|
[24984] | 54 | #include <iprt/buildconfig.h>
|
---|
[95827] | 55 | #include <iprt/getopt.h>
|
---|
[46593] | 56 | #include <iprt/ldr.h>
|
---|
[95827] | 57 | #include <iprt/message.h>
|
---|
[68630] | 58 | #include <iprt/path.h>
|
---|
[49891] | 59 | #include <iprt/process.h>
|
---|
| 60 | #include <iprt/system.h>
|
---|
| 61 | #include <iprt/time.h>
|
---|
[95827] | 62 | #include <iprt/utf16.h>
|
---|
[51469] | 63 |
|
---|
[49891] | 64 | #include <VBox/log.h>
|
---|
[84721] | 65 | #include <VBox/err.h>
|
---|
| 66 |
|
---|
[33966] | 67 |
|
---|
[57358] | 68 | /*********************************************************************************************************************************
|
---|
| 69 | * Internal Functions *
|
---|
| 70 | *********************************************************************************************************************************/
|
---|
[96449] | 71 | static void VBoxGrapicsSetSupported(BOOL fSupported);
|
---|
[37422] | 72 | static int vboxTrayCreateTrayIcon(void);
|
---|
| 73 | static LRESULT CALLBACK vboxToolWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
---|
| 74 |
|
---|
| 75 | /* Global message handler prototypes. */
|
---|
| 76 | static int vboxTrayGlMsgTaskbarCreated(WPARAM lParam, LPARAM wParam);
|
---|
| 77 |
|
---|
| 78 |
|
---|
[57358] | 79 | /*********************************************************************************************************************************
|
---|
| 80 | * Global Variables *
|
---|
| 81 | *********************************************************************************************************************************/
|
---|
[95827] | 82 | int g_cVerbosity = 0;
|
---|
[57741] | 83 | HANDLE g_hStopSem;
|
---|
| 84 | HANDLE g_hSeamlessWtNotifyEvent = 0;
|
---|
| 85 | HANDLE g_hSeamlessKmNotifyEvent = 0;
|
---|
[95877] | 86 | HINSTANCE g_hInstance = NULL;
|
---|
[57741] | 87 | HWND g_hwndToolWindow;
|
---|
| 88 | NOTIFYICONDATA g_NotifyIconData;
|
---|
[1] | 89 |
|
---|
[62865] | 90 | uint32_t g_fGuestDisplaysChanged = 0;
|
---|
| 91 |
|
---|
[90711] | 92 | static PRTLOGGER g_pLoggerRelease = NULL; /**< This is actually the debug logger in DEBUG builds! */
|
---|
| 93 | static uint32_t g_cHistory = 10; /**< Enable log rotation, 10 files. */
|
---|
| 94 | static uint32_t g_uHistoryFileTime = RT_SEC_1DAY; /**< Max 1 day per file. */
|
---|
| 95 | static uint64_t g_uHistoryFileSize = 100 * _1M; /**< Max 100MB per file. */
|
---|
[34025] | 96 |
|
---|
[79036] | 97 | #ifdef DEBUG_andy
|
---|
| 98 | static VBOXSERVICEINFO g_aServices[] =
|
---|
| 99 | {
|
---|
[100204] | 100 | { &g_SvcDescClipboard, NIL_RTTHREAD, NULL, false, false, false, false, true }
|
---|
[79036] | 101 | };
|
---|
| 102 | #else
|
---|
[57741] | 103 | /**
|
---|
| 104 | * The details of the services that has been compiled in.
|
---|
| 105 | */
|
---|
| 106 | static VBOXSERVICEINFO g_aServices[] =
|
---|
[1] | 107 | {
|
---|
[57741] | 108 | { &g_SvcDescDisplay, NIL_RTTHREAD, NULL, false, false, false, false, true },
|
---|
[78809] | 109 | #ifdef VBOX_WITH_SHARED_CLIPBOARD
|
---|
[57741] | 110 | { &g_SvcDescClipboard, NIL_RTTHREAD, NULL, false, false, false, false, true },
|
---|
[78809] | 111 | #endif
|
---|
[57741] | 112 | { &g_SvcDescSeamless, NIL_RTTHREAD, NULL, false, false, false, false, true },
|
---|
| 113 | { &g_SvcDescVRDP, NIL_RTTHREAD, NULL, false, false, false, false, true },
|
---|
| 114 | { &g_SvcDescIPC, NIL_RTTHREAD, NULL, false, false, false, false, true },
|
---|
| 115 | { &g_SvcDescLA, NIL_RTTHREAD, NULL, false, false, false, false, true },
|
---|
[49891] | 116 | #ifdef VBOX_WITH_DRAG_AND_DROP
|
---|
[57741] | 117 | { &g_SvcDescDnD, NIL_RTTHREAD, NULL, false, false, false, false, true }
|
---|
[49891] | 118 | #endif
|
---|
[1] | 119 | };
|
---|
[79036] | 120 | #endif
|
---|
[1] | 121 |
|
---|
[34025] | 122 | /* The global message table. */
|
---|
[63099] | 123 | static VBOXGLOBALMESSAGE g_vboxGlobalMessageTable[] =
|
---|
[1] | 124 | {
|
---|
[34025] | 125 | /* Windows specific stuff. */
|
---|
| 126 | {
|
---|
| 127 | "TaskbarCreated",
|
---|
| 128 | vboxTrayGlMsgTaskbarCreated
|
---|
| 129 | },
|
---|
| 130 |
|
---|
| 131 | /* VBoxTray specific stuff. */
|
---|
[34080] | 132 | /** @todo Add new messages here! */
|
---|
[34025] | 133 |
|
---|
| 134 | {
|
---|
| 135 | NULL
|
---|
| 136 | }
|
---|
| 137 | };
|
---|
| 138 |
|
---|
| 139 | /**
|
---|
| 140 | * Gets called whenever the Windows main taskbar
|
---|
| 141 | * get (re-)created. Nice to install our tray icon.
|
---|
| 142 | *
|
---|
| 143 | * @return IPRT status code.
|
---|
| 144 | * @param wParam
|
---|
| 145 | * @param lParam
|
---|
| 146 | */
|
---|
[34080] | 147 | static int vboxTrayGlMsgTaskbarCreated(WPARAM wParam, LPARAM lParam)
|
---|
[34025] | 148 | {
|
---|
[63099] | 149 | RT_NOREF(wParam, lParam);
|
---|
[34025] | 150 | return vboxTrayCreateTrayIcon();
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | static int vboxTrayCreateTrayIcon(void)
|
---|
| 154 | {
|
---|
[83072] | 155 | HICON hIcon = LoadIcon(g_hInstance, "IDI_ICON1"); /* see Artwork/win/TemplateR3.rc */
|
---|
[30928] | 156 | if (hIcon == NULL)
|
---|
| 157 | {
|
---|
[34025] | 158 | DWORD dwErr = GetLastError();
|
---|
[57741] | 159 | LogFunc(("Could not load tray icon, error %08X\n", dwErr));
|
---|
[34025] | 160 | return RTErrConvertFromWin32(dwErr);
|
---|
[30928] | 161 | }
|
---|
| 162 |
|
---|
| 163 | /* Prepare the system tray icon. */
|
---|
[57741] | 164 | RT_ZERO(g_NotifyIconData);
|
---|
| 165 | g_NotifyIconData.cbSize = NOTIFYICONDATA_V1_SIZE; // sizeof(NOTIFYICONDATA);
|
---|
| 166 | g_NotifyIconData.hWnd = g_hwndToolWindow;
|
---|
| 167 | g_NotifyIconData.uID = ID_TRAYICON;
|
---|
| 168 | g_NotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
---|
| 169 | g_NotifyIconData.uCallbackMessage = WM_VBOXTRAY_TRAY_ICON;
|
---|
| 170 | g_NotifyIconData.hIcon = hIcon;
|
---|
[30928] | 171 |
|
---|
[95863] | 172 | RTStrPrintf(g_NotifyIconData.szTip, sizeof(g_NotifyIconData.szTip), "%s Guest Additions %d.%d.%dr%d",
|
---|
| 173 | VBOX_PRODUCT, VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV);
|
---|
[30928] | 174 |
|
---|
[34025] | 175 | int rc = VINF_SUCCESS;
|
---|
[57741] | 176 | if (!Shell_NotifyIcon(NIM_ADD, &g_NotifyIconData))
|
---|
[30928] | 177 | {
|
---|
[34025] | 178 | DWORD dwErr = GetLastError();
|
---|
[57741] | 179 | LogFunc(("Could not create tray icon, error=%ld\n", dwErr));
|
---|
[34025] | 180 | rc = RTErrConvertFromWin32(dwErr);
|
---|
[57741] | 181 | RT_ZERO(g_NotifyIconData);
|
---|
[30928] | 182 | }
|
---|
| 183 |
|
---|
| 184 | if (hIcon)
|
---|
| 185 | DestroyIcon(hIcon);
|
---|
[34025] | 186 | return rc;
|
---|
[30928] | 187 | }
|
---|
| 188 |
|
---|
[57741] | 189 | static void vboxTrayRemoveTrayIcon(void)
|
---|
[30928] | 190 | {
|
---|
[57741] | 191 | if (g_NotifyIconData.cbSize > 0)
|
---|
[30928] | 192 | {
|
---|
| 193 | /* Remove the system tray icon and refresh system tray. */
|
---|
[57741] | 194 | Shell_NotifyIcon(NIM_DELETE, &g_NotifyIconData);
|
---|
[30928] | 195 | HWND hTrayWnd = FindWindow("Shell_TrayWnd", NULL); /* We assume we only have one tray atm. */
|
---|
| 196 | if (hTrayWnd)
|
---|
| 197 | {
|
---|
| 198 | HWND hTrayNotifyWnd = FindWindowEx(hTrayWnd, 0, "TrayNotifyWnd", NULL);
|
---|
| 199 | if (hTrayNotifyWnd)
|
---|
| 200 | SendMessage(hTrayNotifyWnd, WM_PAINT, 0, NULL);
|
---|
| 201 | }
|
---|
[57741] | 202 | RT_ZERO(g_NotifyIconData);
|
---|
[30928] | 203 | }
|
---|
| 204 | }
|
---|
| 205 |
|
---|
[57741] | 206 | /**
|
---|
| 207 | * The service thread.
|
---|
| 208 | *
|
---|
| 209 | * @returns Whatever the worker function returns.
|
---|
| 210 | * @param ThreadSelf My thread handle.
|
---|
| 211 | * @param pvUser The service index.
|
---|
| 212 | */
|
---|
| 213 | static DECLCALLBACK(int) vboxTrayServiceThread(RTTHREAD ThreadSelf, void *pvUser)
|
---|
[30928] | 214 | {
|
---|
[57741] | 215 | PVBOXSERVICEINFO pSvc = (PVBOXSERVICEINFO)pvUser;
|
---|
| 216 | AssertPtr(pSvc);
|
---|
| 217 |
|
---|
| 218 | #ifndef RT_OS_WINDOWS
|
---|
| 219 | /*
|
---|
| 220 | * Block all signals for this thread. Only the main thread will handle signals.
|
---|
| 221 | */
|
---|
| 222 | sigset_t signalMask;
|
---|
| 223 | sigfillset(&signalMask);
|
---|
| 224 | pthread_sigmask(SIG_BLOCK, &signalMask, NULL);
|
---|
| 225 | #endif
|
---|
| 226 |
|
---|
| 227 | int rc = pSvc->pDesc->pfnWorker(pSvc->pInstance, &pSvc->fShutdown);
|
---|
| 228 | ASMAtomicXchgBool(&pSvc->fShutdown, true);
|
---|
| 229 | RTThreadUserSignal(ThreadSelf);
|
---|
| 230 |
|
---|
| 231 | LogFunc(("Worker for '%s' ended with %Rrc\n", pSvc->pDesc->pszName, rc));
|
---|
| 232 | return rc;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | static int vboxTrayServicesStart(PVBOXSERVICEENV pEnv)
|
---|
| 236 | {
|
---|
[47195] | 237 | AssertPtrReturn(pEnv, VERR_INVALID_POINTER);
|
---|
| 238 |
|
---|
[57741] | 239 | LogRel(("Starting services ...\n"));
|
---|
[6360] | 240 |
|
---|
[57741] | 241 | int rc = VINF_SUCCESS;
|
---|
[2980] | 242 |
|
---|
[57741] | 243 | for (unsigned i = 0; i < RT_ELEMENTS(g_aServices); i++)
|
---|
[1] | 244 | {
|
---|
[57741] | 245 | PVBOXSERVICEINFO pSvc = &g_aServices[i];
|
---|
| 246 | LogRel(("Starting service '%s' ...\n", pSvc->pDesc->pszName));
|
---|
[2980] | 247 |
|
---|
[57741] | 248 | pSvc->hThread = NIL_RTTHREAD;
|
---|
| 249 | pSvc->pInstance = NULL;
|
---|
| 250 | pSvc->fStarted = false;
|
---|
| 251 | pSvc->fShutdown = false;
|
---|
[2980] | 252 |
|
---|
[57741] | 253 | int rc2 = VINF_SUCCESS;
|
---|
[2980] | 254 |
|
---|
[57741] | 255 | if (pSvc->pDesc->pfnInit)
|
---|
| 256 | rc2 = pSvc->pDesc->pfnInit(pEnv, &pSvc->pInstance);
|
---|
[2980] | 257 |
|
---|
[57741] | 258 | if (RT_FAILURE(rc2))
|
---|
[1] | 259 | {
|
---|
[84720] | 260 | switch (rc2)
|
---|
[64291] | 261 | {
|
---|
[84720] | 262 | case VERR_NOT_SUPPORTED:
|
---|
| 263 | LogRel(("Service '%s' is not supported on this system\n", pSvc->pDesc->pszName));
|
---|
| 264 | rc2 = VINF_SUCCESS; /* Keep going. */
|
---|
| 265 | break;
|
---|
| 266 |
|
---|
| 267 | case VERR_HGCM_SERVICE_NOT_FOUND:
|
---|
| 268 | LogRel(("Service '%s' is not available on the host\n", pSvc->pDesc->pszName));
|
---|
| 269 | rc2 = VINF_SUCCESS; /* Keep going. */
|
---|
| 270 | break;
|
---|
| 271 |
|
---|
| 272 | default:
|
---|
| 273 | LogRel(("Failed to initialize service '%s', rc=%Rrc\n", pSvc->pDesc->pszName, rc2));
|
---|
| 274 | break;
|
---|
[64291] | 275 | }
|
---|
[1] | 276 | }
|
---|
| 277 | else
|
---|
| 278 | {
|
---|
[57741] | 279 | if (pSvc->pDesc->pfnWorker)
|
---|
[1] | 280 | {
|
---|
[57741] | 281 | rc2 = RTThreadCreate(&pSvc->hThread, vboxTrayServiceThread, pSvc /* pvUser */,
|
---|
| 282 | 0 /* Default stack size */, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, pSvc->pDesc->pszName);
|
---|
| 283 | if (RT_SUCCESS(rc2))
|
---|
| 284 | {
|
---|
| 285 | pSvc->fStarted = true;
|
---|
[2980] | 286 |
|
---|
[57741] | 287 | RTThreadUserWait(pSvc->hThread, 30 * 1000 /* Timeout in ms */);
|
---|
| 288 | if (pSvc->fShutdown)
|
---|
| 289 | {
|
---|
| 290 | LogRel(("Service '%s' failed to start!\n", pSvc->pDesc->pszName));
|
---|
| 291 | rc = VERR_GENERAL_FAILURE;
|
---|
| 292 | }
|
---|
| 293 | else
|
---|
| 294 | LogRel(("Service '%s' started\n", pSvc->pDesc->pszName));
|
---|
| 295 | }
|
---|
| 296 | else
|
---|
| 297 | {
|
---|
| 298 | LogRel(("Failed to start thread for service '%s': %Rrc\n", rc2));
|
---|
| 299 | if (pSvc->pDesc->pfnDestroy)
|
---|
| 300 | pSvc->pDesc->pfnDestroy(pSvc->pInstance);
|
---|
| 301 | }
|
---|
[1] | 302 | }
|
---|
| 303 | }
|
---|
[2980] | 304 |
|
---|
[57741] | 305 | if (RT_SUCCESS(rc))
|
---|
| 306 | rc = rc2;
|
---|
[1] | 307 | }
|
---|
[2980] | 308 |
|
---|
[57741] | 309 | if (RT_SUCCESS(rc))
|
---|
| 310 | LogRel(("All services started\n"));
|
---|
| 311 | else
|
---|
| 312 | LogRel(("Services started, but some with errors\n"));
|
---|
| 313 |
|
---|
| 314 | LogFlowFuncLeaveRC(rc);
|
---|
| 315 | return rc;
|
---|
[1] | 316 | }
|
---|
| 317 |
|
---|
[57741] | 318 | static int vboxTrayServicesStop(VBOXSERVICEENV *pEnv)
|
---|
[1] | 319 | {
|
---|
[57741] | 320 | AssertPtrReturn(pEnv, VERR_INVALID_POINTER);
|
---|
[2980] | 321 |
|
---|
[57741] | 322 | LogRel2(("Stopping all services ...\n"));
|
---|
[2980] | 323 |
|
---|
[57741] | 324 | /*
|
---|
| 325 | * Signal all the services.
|
---|
| 326 | */
|
---|
| 327 | for (unsigned i = 0; i < RT_ELEMENTS(g_aServices); i++)
|
---|
| 328 | ASMAtomicWriteBool(&g_aServices[i].fShutdown, true);
|
---|
| 329 |
|
---|
| 330 | /*
|
---|
| 331 | * Do the pfnStop callback on all running services.
|
---|
| 332 | */
|
---|
| 333 | for (unsigned i = 0; i < RT_ELEMENTS(g_aServices); i++)
|
---|
[1] | 334 | {
|
---|
[57741] | 335 | PVBOXSERVICEINFO pSvc = &g_aServices[i];
|
---|
| 336 | if ( pSvc->fStarted
|
---|
| 337 | && pSvc->pDesc->pfnStop)
|
---|
| 338 | {
|
---|
| 339 | LogRel2(("Calling stop function for service '%s' ...\n", pSvc->pDesc->pszName));
|
---|
| 340 | int rc2 = pSvc->pDesc->pfnStop(pSvc->pInstance);
|
---|
| 341 | if (RT_FAILURE(rc2))
|
---|
| 342 | LogRel(("Failed to stop service '%s': %Rrc\n", pSvc->pDesc->pszName, rc2));
|
---|
| 343 | }
|
---|
[47195] | 344 | }
|
---|
| 345 |
|
---|
[57741] | 346 | LogRel2(("All stop functions for services called\n"));
|
---|
| 347 |
|
---|
| 348 | int rc = VINF_SUCCESS;
|
---|
| 349 |
|
---|
| 350 | /*
|
---|
| 351 | * Wait for all the service threads to complete.
|
---|
| 352 | */
|
---|
| 353 | for (unsigned i = 0; i < RT_ELEMENTS(g_aServices); i++)
|
---|
[47195] | 354 | {
|
---|
[57741] | 355 | PVBOXSERVICEINFO pSvc = &g_aServices[i];
|
---|
| 356 | if (!pSvc->fEnabled) /* Only stop services which were started before. */
|
---|
| 357 | continue;
|
---|
| 358 |
|
---|
| 359 | if (pSvc->hThread != NIL_RTTHREAD)
|
---|
[1] | 360 | {
|
---|
[57741] | 361 | LogRel2(("Waiting for service '%s' to stop ...\n", pSvc->pDesc->pszName));
|
---|
| 362 | int rc2 = VINF_SUCCESS;
|
---|
| 363 | for (int j = 0; j < 30; j++) /* Wait 30 seconds in total */
|
---|
[1] | 364 | {
|
---|
[57741] | 365 | rc2 = RTThreadWait(pSvc->hThread, 1000 /* Wait 1 second */, NULL);
|
---|
| 366 | if (RT_SUCCESS(rc2))
|
---|
| 367 | break;
|
---|
[1] | 368 | }
|
---|
[57741] | 369 | if (RT_FAILURE(rc2))
|
---|
| 370 | {
|
---|
| 371 | LogRel(("Service '%s' failed to stop (%Rrc)\n", pSvc->pDesc->pszName, rc2));
|
---|
| 372 | if (RT_SUCCESS(rc))
|
---|
| 373 | rc = rc2;
|
---|
| 374 | }
|
---|
| 375 | }
|
---|
[2980] | 376 |
|
---|
[81188] | 377 | if ( pSvc->pDesc->pfnDestroy
|
---|
| 378 | && pSvc->pInstance) /* pInstance might be NULL if initialization of a service failed. */
|
---|
[57741] | 379 | {
|
---|
| 380 | LogRel2(("Terminating service '%s' ...\n", pSvc->pDesc->pszName));
|
---|
| 381 | pSvc->pDesc->pfnDestroy(pSvc->pInstance);
|
---|
[1] | 382 | }
|
---|
| 383 | }
|
---|
[2980] | 384 |
|
---|
[57741] | 385 | if (RT_SUCCESS(rc))
|
---|
| 386 | LogRel(("All services stopped\n"));
|
---|
| 387 |
|
---|
| 388 | LogFlowFuncLeaveRC(rc);
|
---|
| 389 | return rc;
|
---|
[1] | 390 | }
|
---|
| 391 |
|
---|
[35863] | 392 | static int vboxTrayRegisterGlobalMessages(PVBOXGLOBALMESSAGE pTable)
|
---|
[34025] | 393 | {
|
---|
| 394 | int rc = VINF_SUCCESS;
|
---|
| 395 | if (pTable == NULL) /* No table to register? Skip. */
|
---|
| 396 | return rc;
|
---|
| 397 | while ( pTable->pszName
|
---|
| 398 | && RT_SUCCESS(rc))
|
---|
| 399 | {
|
---|
| 400 | /* Register global accessible window messages. */
|
---|
| 401 | pTable->uMsgID = RegisterWindowMessage(TEXT(pTable->pszName));
|
---|
| 402 | if (!pTable->uMsgID)
|
---|
| 403 | {
|
---|
| 404 | DWORD dwErr = GetLastError();
|
---|
[51469] | 405 | Log(("Registering global message \"%s\" failed, error = %08X\n", dwErr));
|
---|
[34025] | 406 | rc = RTErrConvertFromWin32(dwErr);
|
---|
| 407 | }
|
---|
[1] | 408 |
|
---|
[34025] | 409 | /* Advance to next table element. */
|
---|
| 410 | pTable++;
|
---|
| 411 | }
|
---|
| 412 | return rc;
|
---|
| 413 | }
|
---|
| 414 |
|
---|
[35863] | 415 | static bool vboxTrayHandleGlobalMessages(PVBOXGLOBALMESSAGE pTable, UINT uMsg,
|
---|
| 416 | WPARAM wParam, LPARAM lParam)
|
---|
[21888] | 417 | {
|
---|
[34025] | 418 | if (pTable == NULL)
|
---|
| 419 | return false;
|
---|
[35863] | 420 | while (pTable && pTable->pszName)
|
---|
[34025] | 421 | {
|
---|
| 422 | if (pTable->uMsgID == uMsg)
|
---|
| 423 | {
|
---|
| 424 | if (pTable->pfnHandler)
|
---|
| 425 | pTable->pfnHandler(wParam, lParam);
|
---|
| 426 | return true;
|
---|
| 427 | }
|
---|
[23055] | 428 |
|
---|
[34025] | 429 | /* Advance to next table element. */
|
---|
| 430 | pTable++;
|
---|
[21888] | 431 | }
|
---|
[34025] | 432 | return false;
|
---|
[21888] | 433 | }
|
---|
| 434 |
|
---|
[49891] | 435 | /**
|
---|
[99739] | 436 | * Header/footer callback for the release logger.
|
---|
[49891] | 437 | *
|
---|
| 438 | * @param pLoggerRelease
|
---|
| 439 | * @param enmPhase
|
---|
| 440 | * @param pfnLog
|
---|
| 441 | */
|
---|
[85121] | 442 | static DECLCALLBACK(void) vboxTrayLogHeaderFooter(PRTLOGGER pLoggerRelease, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog)
|
---|
[49891] | 443 | {
|
---|
| 444 | /* Some introductory information. */
|
---|
| 445 | static RTTIMESPEC s_TimeSpec;
|
---|
| 446 | char szTmp[256];
|
---|
| 447 | if (enmPhase == RTLOGPHASE_BEGIN)
|
---|
| 448 | RTTimeNow(&s_TimeSpec);
|
---|
| 449 | RTTimeSpecToString(&s_TimeSpec, szTmp, sizeof(szTmp));
|
---|
| 450 |
|
---|
| 451 | switch (enmPhase)
|
---|
| 452 | {
|
---|
| 453 | case RTLOGPHASE_BEGIN:
|
---|
| 454 | {
|
---|
| 455 | pfnLog(pLoggerRelease,
|
---|
| 456 | "VBoxTray %s r%s %s (%s %s) release log\n"
|
---|
| 457 | "Log opened %s\n",
|
---|
| 458 | RTBldCfgVersion(), RTBldCfgRevisionStr(), VBOX_BUILD_TARGET,
|
---|
| 459 | __DATE__, __TIME__, szTmp);
|
---|
| 460 |
|
---|
| 461 | int vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp));
|
---|
| 462 | if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
|
---|
| 463 | pfnLog(pLoggerRelease, "OS Product: %s\n", szTmp);
|
---|
| 464 | vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp));
|
---|
| 465 | if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
|
---|
| 466 | pfnLog(pLoggerRelease, "OS Release: %s\n", szTmp);
|
---|
| 467 | vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp));
|
---|
| 468 | if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
|
---|
| 469 | pfnLog(pLoggerRelease, "OS Version: %s\n", szTmp);
|
---|
| 470 | if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
|
---|
| 471 | pfnLog(pLoggerRelease, "OS Service Pack: %s\n", szTmp);
|
---|
| 472 |
|
---|
| 473 | /* the package type is interesting for Linux distributions */
|
---|
| 474 | char szExecName[RTPATH_MAX];
|
---|
| 475 | char *pszExecName = RTProcGetExecutablePath(szExecName, sizeof(szExecName));
|
---|
| 476 | pfnLog(pLoggerRelease,
|
---|
| 477 | "Executable: %s\n"
|
---|
| 478 | "Process ID: %u\n"
|
---|
| 479 | "Package type: %s"
|
---|
| 480 | #ifdef VBOX_OSE
|
---|
| 481 | " (OSE)"
|
---|
| 482 | #endif
|
---|
| 483 | "\n",
|
---|
| 484 | pszExecName ? pszExecName : "unknown",
|
---|
| 485 | RTProcSelf(),
|
---|
| 486 | VBOX_PACKAGE_STRING);
|
---|
| 487 | break;
|
---|
| 488 | }
|
---|
| 489 |
|
---|
| 490 | case RTLOGPHASE_PREROTATE:
|
---|
| 491 | pfnLog(pLoggerRelease, "Log rotated - Log started %s\n", szTmp);
|
---|
| 492 | break;
|
---|
| 493 |
|
---|
| 494 | case RTLOGPHASE_POSTROTATE:
|
---|
| 495 | pfnLog(pLoggerRelease, "Log continuation - Log started %s\n", szTmp);
|
---|
| 496 | break;
|
---|
| 497 |
|
---|
| 498 | case RTLOGPHASE_END:
|
---|
| 499 | pfnLog(pLoggerRelease, "End of log file - Log started %s\n", szTmp);
|
---|
| 500 | break;
|
---|
| 501 |
|
---|
| 502 | default:
|
---|
| 503 | /* nothing */;
|
---|
| 504 | }
|
---|
| 505 | }
|
---|
| 506 |
|
---|
| 507 | /**
|
---|
| 508 | * Creates the default release logger outputting to the specified file.
|
---|
| 509 | *
|
---|
| 510 | * @return IPRT status code.
|
---|
[95827] | 511 | * @param pszLogFile Path to log file to use.
|
---|
[49891] | 512 | */
|
---|
[95827] | 513 | static int vboxTrayLogCreate(const char *pszLogFile)
|
---|
[49891] | 514 | {
|
---|
[90711] | 515 | /* Create release (or debug) logger (stdout + file). */
|
---|
[49891] | 516 | static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
|
---|
[90829] | 517 | static const char s_szEnvVarPfx[] = "VBOXTRAY_RELEASE_LOG";
|
---|
[95827] | 518 |
|
---|
[90829] | 519 | RTERRINFOSTATIC ErrInfo;
|
---|
| 520 | int rc = RTLogCreateEx(&g_pLoggerRelease, s_szEnvVarPfx,
|
---|
| 521 | RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME_PROG | RTLOGFLAGS_USECRLF,
|
---|
[95827] | 522 | "all.e", RT_ELEMENTS(s_apszGroups), s_apszGroups, UINT32_MAX,
|
---|
[90862] | 523 | 0 /*cBufDescs*/, NULL /*paBufDescs*/, RTLOGDEST_STDOUT,
|
---|
[49891] | 524 | vboxTrayLogHeaderFooter, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime,
|
---|
[94629] | 525 | NULL /*pOutputIf*/, NULL /*pvOutputIfUser*/,
|
---|
[95827] | 526 | RTErrInfoInitStatic(&ErrInfo), "%s", pszLogFile ? pszLogFile : "");
|
---|
[49891] | 527 | if (RT_SUCCESS(rc))
|
---|
| 528 | {
|
---|
| 529 | /* Register this logger as the release logger. */
|
---|
| 530 | RTLogRelSetDefaultInstance(g_pLoggerRelease);
|
---|
[95827] | 531 |
|
---|
| 532 | /* Register this logger as the _debug_ logger. */
|
---|
| 533 | RTLogSetDefaultInstance(g_pLoggerRelease);
|
---|
| 534 |
|
---|
[100204] | 535 | /* All groups we want to enable logging for VBoxTray. */
|
---|
| 536 | const char *apszGroups[] = { "guest_dnd", "shared_clipboard" };
|
---|
[95959] | 537 | char szGroupSettings[_1K];
|
---|
| 538 |
|
---|
| 539 | szGroupSettings[0] = '\0';
|
---|
| 540 |
|
---|
| 541 | for (size_t i = 0; i < RT_ELEMENTS(apszGroups); i++)
|
---|
[95827] | 542 | {
|
---|
[95959] | 543 | if (i > 0)
|
---|
| 544 | rc = RTStrCat(szGroupSettings, sizeof(szGroupSettings), "+");
|
---|
| 545 | if (RT_SUCCESS(rc))
|
---|
| 546 | rc = RTStrCat(szGroupSettings, sizeof(szGroupSettings), apszGroups[i]);
|
---|
| 547 | if (RT_FAILURE(rc))
|
---|
[95827] | 548 | break;
|
---|
| 549 |
|
---|
[95959] | 550 | switch (g_cVerbosity)
|
---|
| 551 | {
|
---|
| 552 | case 1:
|
---|
| 553 | rc = RTStrCat(szGroupSettings, sizeof(szGroupSettings), ".e.l");
|
---|
| 554 | break;
|
---|
[95827] | 555 |
|
---|
[95959] | 556 | case 2:
|
---|
| 557 | rc = RTStrCat(szGroupSettings, sizeof(szGroupSettings), ".e.l.l2");
|
---|
| 558 | break;
|
---|
[95827] | 559 |
|
---|
[95959] | 560 | case 3:
|
---|
| 561 | rc = RTStrCat(szGroupSettings, sizeof(szGroupSettings), ".e.l.l2.l3");
|
---|
| 562 | break;
|
---|
| 563 |
|
---|
| 564 | case 4:
|
---|
| 565 | RT_FALL_THROUGH();
|
---|
| 566 | default:
|
---|
| 567 | rc = RTStrCat(szGroupSettings, sizeof(szGroupSettings), ".e.l.l2.l3.f");
|
---|
| 568 | break;
|
---|
| 569 | }
|
---|
| 570 |
|
---|
| 571 | if (RT_FAILURE(rc))
|
---|
[95827] | 572 | break;
|
---|
| 573 | }
|
---|
[95959] | 574 |
|
---|
| 575 | LogRel(("Verbose log settings are: %s\n", szGroupSettings));
|
---|
| 576 |
|
---|
| 577 | if (RT_SUCCESS(rc))
|
---|
| 578 | rc = RTLogGroupSettings(g_pLoggerRelease, szGroupSettings);
|
---|
[95827] | 579 | if (RT_FAILURE(rc))
|
---|
[95959] | 580 | RTMsgError("Setting log group settings failed, rc=%Rrc\n", rc);
|
---|
[95827] | 581 |
|
---|
[49891] | 582 | /* Explicitly flush the log in case of VBOXTRAY_RELEASE_LOG=buffered. */
|
---|
| 583 | RTLogFlush(g_pLoggerRelease);
|
---|
| 584 | }
|
---|
| 585 | else
|
---|
[76098] | 586 | VBoxTrayShowError(ErrInfo.szMsg);
|
---|
[49891] | 587 |
|
---|
| 588 | return rc;
|
---|
| 589 | }
|
---|
| 590 |
|
---|
| 591 | static void vboxTrayLogDestroy(void)
|
---|
| 592 | {
|
---|
[90711] | 593 | /* Only want to destroy the release logger before calling exit(). The debug
|
---|
| 594 | logger can be useful after that point... */
|
---|
[49891] | 595 | RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
|
---|
| 596 | }
|
---|
| 597 |
|
---|
[76098] | 598 | /**
|
---|
| 599 | * Displays an error message.
|
---|
| 600 | *
|
---|
| 601 | * @returns RTEXITCODE_FAILURE.
|
---|
| 602 | * @param pszFormat The message text.
|
---|
| 603 | * @param ... Format arguments.
|
---|
| 604 | */
|
---|
| 605 | RTEXITCODE VBoxTrayShowError(const char *pszFormat, ...)
|
---|
| 606 | {
|
---|
| 607 | va_list args;
|
---|
| 608 | va_start(args, pszFormat);
|
---|
| 609 | char *psz = NULL;
|
---|
| 610 | RTStrAPrintfV(&psz, pszFormat, args);
|
---|
| 611 | va_end(args);
|
---|
| 612 |
|
---|
| 613 | AssertPtr(psz);
|
---|
| 614 | LogRel(("Error: %s", psz));
|
---|
| 615 |
|
---|
| 616 | MessageBox(GetDesktopWindow(), psz, "VBoxTray - Error", MB_OK | MB_ICONERROR);
|
---|
| 617 |
|
---|
| 618 | RTStrFree(psz);
|
---|
| 619 |
|
---|
| 620 | return RTEXITCODE_FAILURE;
|
---|
| 621 | }
|
---|
| 622 |
|
---|
[37422] | 623 | static void vboxTrayDestroyToolWindow(void)
|
---|
[35863] | 624 | {
|
---|
[57741] | 625 | if (g_hwndToolWindow)
|
---|
[1] | 626 | {
|
---|
[51469] | 627 | Log(("Destroying tool window ...\n"));
|
---|
[35863] | 628 |
|
---|
| 629 | /* Destroy the tool window. */
|
---|
[57741] | 630 | DestroyWindow(g_hwndToolWindow);
|
---|
| 631 | g_hwndToolWindow = NULL;
|
---|
[35863] | 632 |
|
---|
[57741] | 633 | UnregisterClass("VBoxTrayToolWndClass", g_hInstance);
|
---|
[35863] | 634 | }
|
---|
| 635 | }
|
---|
| 636 |
|
---|
[37422] | 637 | static int vboxTrayCreateToolWindow(void)
|
---|
[35863] | 638 | {
|
---|
| 639 | DWORD dwErr = ERROR_SUCCESS;
|
---|
| 640 |
|
---|
| 641 | /* Create a custom window class. */
|
---|
[57741] | 642 | WNDCLASSEX wc = { 0 };
|
---|
| 643 | wc.cbSize = sizeof(WNDCLASSEX);
|
---|
| 644 | wc.style = CS_NOCLOSE;
|
---|
| 645 | wc.lpfnWndProc = (WNDPROC)vboxToolWndProc;
|
---|
| 646 | wc.hInstance = g_hInstance;
|
---|
| 647 | wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
---|
| 648 | wc.lpszClassName = "VBoxTrayToolWndClass";
|
---|
| 649 |
|
---|
| 650 | if (!RegisterClassEx(&wc))
|
---|
[35863] | 651 | {
|
---|
| 652 | dwErr = GetLastError();
|
---|
[51469] | 653 | Log(("Registering invisible tool window failed, error = %08X\n", dwErr));
|
---|
[35863] | 654 | }
|
---|
| 655 | else
|
---|
| 656 | {
|
---|
| 657 | /*
|
---|
| 658 | * Create our (invisible) tool window.
|
---|
| 659 | * Note: The window name ("VBoxTrayToolWnd") and class ("VBoxTrayToolWndClass") is
|
---|
[34025] | 660 | * needed for posting globally registered messages to VBoxTray and must not be
|
---|
[35863] | 661 | * changed! Otherwise things get broken!
|
---|
| 662 | *
|
---|
| 663 | */
|
---|
[57741] | 664 | g_hwndToolWindow = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST,
|
---|
[35863] | 665 | "VBoxTrayToolWndClass", "VBoxTrayToolWnd",
|
---|
| 666 | WS_POPUPWINDOW,
|
---|
[57741] | 667 | -200, -200, 100, 100, NULL, NULL, g_hInstance, NULL);
|
---|
| 668 | if (!g_hwndToolWindow)
|
---|
[34025] | 669 | {
|
---|
| 670 | dwErr = GetLastError();
|
---|
[51469] | 671 | Log(("Creating invisible tool window failed, error = %08X\n", dwErr));
|
---|
[34025] | 672 | }
|
---|
[1] | 673 | else
|
---|
[34025] | 674 | {
|
---|
[35863] | 675 | /* Reload the cursor(s). */
|
---|
[34025] | 676 | hlpReloadCursor();
|
---|
[35863] | 677 |
|
---|
[57741] | 678 | Log(("Invisible tool window handle = %p\n", g_hwndToolWindow));
|
---|
[34025] | 679 | }
|
---|
[1] | 680 | }
|
---|
[2980] | 681 |
|
---|
[35863] | 682 | if (dwErr != ERROR_SUCCESS)
|
---|
| 683 | vboxTrayDestroyToolWindow();
|
---|
| 684 | return RTErrConvertFromWin32(dwErr);
|
---|
| 685 | }
|
---|
[1] | 686 |
|
---|
[37422] | 687 | static int vboxTraySetupSeamless(void)
|
---|
[35863] | 688 | {
|
---|
| 689 | /* We need to setup a security descriptor to allow other processes modify access to the seamless notification event semaphore. */
|
---|
| 690 | SECURITY_ATTRIBUTES SecAttr;
|
---|
| 691 | DWORD dwErr = ERROR_SUCCESS;
|
---|
| 692 | char secDesc[SECURITY_DESCRIPTOR_MIN_LENGTH];
|
---|
| 693 | BOOL fRC;
|
---|
| 694 |
|
---|
| 695 | SecAttr.nLength = sizeof(SecAttr);
|
---|
| 696 | SecAttr.bInheritHandle = FALSE;
|
---|
| 697 | SecAttr.lpSecurityDescriptor = &secDesc;
|
---|
| 698 | InitializeSecurityDescriptor(SecAttr.lpSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION);
|
---|
| 699 | fRC = SetSecurityDescriptorDacl(SecAttr.lpSecurityDescriptor, TRUE, 0, FALSE);
|
---|
| 700 | if (!fRC)
|
---|
[1] | 701 | {
|
---|
[35863] | 702 | dwErr = GetLastError();
|
---|
[51469] | 703 | Log(("SetSecurityDescriptorDacl failed with last error = %08X\n", dwErr));
|
---|
[35863] | 704 | }
|
---|
| 705 | else
|
---|
| 706 | {
|
---|
| 707 | /* For Vista and up we need to change the integrity of the security descriptor, too. */
|
---|
[78937] | 708 | uint64_t const uNtVersion = RTSystemGetNtVersion();
|
---|
| 709 | if (uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(6, 0, 0))
|
---|
[4466] | 710 | {
|
---|
| 711 | BOOL (WINAPI * pfnConvertStringSecurityDescriptorToSecurityDescriptorA)(LPCSTR StringSecurityDescriptor, DWORD StringSDRevision, PSECURITY_DESCRIPTOR *SecurityDescriptor, PULONG SecurityDescriptorSize);
|
---|
[46593] | 712 | *(void **)&pfnConvertStringSecurityDescriptorToSecurityDescriptorA =
|
---|
[46625] | 713 | RTLdrGetSystemSymbol("advapi32.dll", "ConvertStringSecurityDescriptorToSecurityDescriptorA");
|
---|
[85121] | 714 | Log(("pfnConvertStringSecurityDescriptorToSecurityDescriptorA = %p\n",
|
---|
| 715 | RT_CB_LOG_CAST(pfnConvertStringSecurityDescriptorToSecurityDescriptorA)));
|
---|
[46593] | 716 | if (pfnConvertStringSecurityDescriptorToSecurityDescriptorA)
|
---|
[4466] | 717 | {
|
---|
[4467] | 718 | PSECURITY_DESCRIPTOR pSD;
|
---|
| 719 | PACL pSacl = NULL;
|
---|
| 720 | BOOL fSaclPresent = FALSE;
|
---|
| 721 | BOOL fSaclDefaulted = FALSE;
|
---|
| 722 |
|
---|
[46593] | 723 | fRC = pfnConvertStringSecurityDescriptorToSecurityDescriptorA("S:(ML;;NW;;;LW)", /* this means "low integrity" */
|
---|
| 724 | SDDL_REVISION_1, &pSD, NULL);
|
---|
| 725 | if (!fRC)
|
---|
[4466] | 726 | {
|
---|
[46593] | 727 | dwErr = GetLastError();
|
---|
[51469] | 728 | Log(("ConvertStringSecurityDescriptorToSecurityDescriptorA failed with last error = %08X\n", dwErr));
|
---|
[46593] | 729 | }
|
---|
| 730 | else
|
---|
| 731 | {
|
---|
| 732 | fRC = GetSecurityDescriptorSacl(pSD, &fSaclPresent, &pSacl, &fSaclDefaulted);
|
---|
[35863] | 733 | if (!fRC)
|
---|
| 734 | {
|
---|
| 735 | dwErr = GetLastError();
|
---|
[51469] | 736 | Log(("GetSecurityDescriptorSacl failed with last error = %08X\n", dwErr));
|
---|
[35863] | 737 | }
|
---|
| 738 | else
|
---|
| 739 | {
|
---|
[46593] | 740 | fRC = SetSecurityDescriptorSacl(SecAttr.lpSecurityDescriptor, TRUE, pSacl, FALSE);
|
---|
[35863] | 741 | if (!fRC)
|
---|
| 742 | {
|
---|
| 743 | dwErr = GetLastError();
|
---|
[51469] | 744 | Log(("SetSecurityDescriptorSacl failed with last error = %08X\n", dwErr));
|
---|
[35863] | 745 | }
|
---|
| 746 | }
|
---|
[4466] | 747 | }
|
---|
| 748 | }
|
---|
| 749 | }
|
---|
| 750 |
|
---|
[35863] | 751 | if ( dwErr == ERROR_SUCCESS
|
---|
[78937] | 752 | && uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(5, 0, 0)) /* Only for W2K and up ... */
|
---|
[4461] | 753 | {
|
---|
[57741] | 754 | g_hSeamlessWtNotifyEvent = CreateEvent(&SecAttr, FALSE, FALSE, VBOXHOOK_GLOBAL_WT_EVENT_NAME);
|
---|
| 755 | if (g_hSeamlessWtNotifyEvent == NULL)
|
---|
[6360] | 756 | {
|
---|
[35863] | 757 | dwErr = GetLastError();
|
---|
[51469] | 758 | Log(("CreateEvent for Seamless failed, last error = %08X\n", dwErr));
|
---|
[6360] | 759 | }
|
---|
[48070] | 760 |
|
---|
[57741] | 761 | g_hSeamlessKmNotifyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
---|
| 762 | if (g_hSeamlessKmNotifyEvent == NULL)
|
---|
[48070] | 763 | {
|
---|
| 764 | dwErr = GetLastError();
|
---|
[51469] | 765 | Log(("CreateEvent for Seamless failed, last error = %08X\n", dwErr));
|
---|
[48070] | 766 | }
|
---|
[4461] | 767 | }
|
---|
[1] | 768 | }
|
---|
[35863] | 769 | return RTErrConvertFromWin32(dwErr);
|
---|
| 770 | }
|
---|
[1] | 771 |
|
---|
[35863] | 772 | static void vboxTrayShutdownSeamless(void)
|
---|
| 773 | {
|
---|
[57741] | 774 | if (g_hSeamlessWtNotifyEvent)
|
---|
[37422] | 775 | {
|
---|
[57741] | 776 | CloseHandle(g_hSeamlessWtNotifyEvent);
|
---|
| 777 | g_hSeamlessWtNotifyEvent = NULL;
|
---|
[37422] | 778 | }
|
---|
[48070] | 779 |
|
---|
[57741] | 780 | if (g_hSeamlessKmNotifyEvent)
|
---|
[48070] | 781 | {
|
---|
[57741] | 782 | CloseHandle(g_hSeamlessKmNotifyEvent);
|
---|
| 783 | g_hSeamlessKmNotifyEvent = NULL;
|
---|
[48070] | 784 | }
|
---|
[35863] | 785 | }
|
---|
[2980] | 786 |
|
---|
[35863] | 787 | static int vboxTrayServiceMain(void)
|
---|
| 788 | {
|
---|
| 789 | int rc = VINF_SUCCESS;
|
---|
[57741] | 790 | LogFunc(("Entering vboxTrayServiceMain\n"));
|
---|
[27955] | 791 |
|
---|
[57741] | 792 | g_hStopSem = CreateEvent(NULL, TRUE, FALSE, NULL);
|
---|
| 793 | if (g_hStopSem == NULL)
|
---|
[1] | 794 | {
|
---|
[35863] | 795 | rc = RTErrConvertFromWin32(GetLastError());
|
---|
[57741] | 796 | LogFunc(("CreateEvent for stopping VBoxTray failed, rc=%Rrc\n", rc));
|
---|
[1] | 797 | }
|
---|
[35863] | 798 | else
|
---|
[1] | 799 | {
|
---|
[35863] | 800 | /*
|
---|
| 801 | * Start services listed in the vboxServiceTable.
|
---|
| 802 | */
|
---|
| 803 | VBOXSERVICEENV svcEnv;
|
---|
[57741] | 804 | svcEnv.hInstance = g_hInstance;
|
---|
[1] | 805 |
|
---|
[35863] | 806 | /* Initializes disp-if to default (XPDM) mode. */
|
---|
| 807 | VBoxDispIfInit(&svcEnv.dispIf); /* Cannot fail atm. */
|
---|
| 808 | #ifdef VBOX_WITH_WDDM
|
---|
| 809 | /*
|
---|
| 810 | * For now the display mode will be adjusted to WDDM mode if needed
|
---|
| 811 | * on display service initialization when it detects the display driver type.
|
---|
| 812 | */
|
---|
| 813 | #endif
|
---|
[1] | 814 |
|
---|
[35863] | 815 | /* Finally start all the built-in services! */
|
---|
[57741] | 816 | rc = vboxTrayServicesStart(&svcEnv);
|
---|
[35863] | 817 | if (RT_FAILURE(rc))
|
---|
[1] | 818 | {
|
---|
[35863] | 819 | /* Terminate service if something went wrong. */
|
---|
[57741] | 820 | vboxTrayServicesStop(&svcEnv);
|
---|
[1] | 821 | }
|
---|
[4461] | 822 | else
|
---|
| 823 | {
|
---|
[78937] | 824 | uint64_t const uNtVersion = RTSystemGetNtVersion();
|
---|
[35863] | 825 | rc = vboxTrayCreateTrayIcon();
|
---|
| 826 | if ( RT_SUCCESS(rc)
|
---|
[78937] | 827 | && uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(5, 0, 0)) /* Only for W2K and up ... */
|
---|
[1] | 828 | {
|
---|
[35863] | 829 | /* We're ready to create the tooltip balloon.
|
---|
| 830 | Check in 10 seconds (@todo make seconds configurable) ... */
|
---|
[57741] | 831 | SetTimer(g_hwndToolWindow,
|
---|
[35863] | 832 | TIMERID_VBOXTRAY_CHECK_HOSTVERSION,
|
---|
| 833 | 10 * 1000, /* 10 seconds */
|
---|
| 834 | NULL /* No timerproc */);
|
---|
| 835 | }
|
---|
| 836 |
|
---|
| 837 | if (RT_SUCCESS(rc))
|
---|
| 838 | {
|
---|
[78466] | 839 | /* Report the host that we're up and running! */
|
---|
| 840 | hlpReportStatus(VBoxGuestFacilityStatus_Active);
|
---|
[1] | 841 | }
|
---|
| 842 |
|
---|
[35863] | 843 | if (RT_SUCCESS(rc))
|
---|
| 844 | {
|
---|
| 845 | /* Boost thread priority to make sure we wake up early for seamless window notifications
|
---|
| 846 | * (not sure if it actually makes any difference though). */
|
---|
| 847 | SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
|
---|
[1] | 848 |
|
---|
[35863] | 849 | /*
|
---|
| 850 | * Main execution loop
|
---|
| 851 | * Wait for the stop semaphore to be posted or a window event to arrive
|
---|
| 852 | */
|
---|
[1] | 853 |
|
---|
[48070] | 854 | HANDLE hWaitEvent[4] = {0};
|
---|
[45763] | 855 | DWORD dwEventCount = 0;
|
---|
[1] | 856 |
|
---|
[57741] | 857 | hWaitEvent[dwEventCount++] = g_hStopSem;
|
---|
[2980] | 858 |
|
---|
[45763] | 859 | /* Check if seamless mode is not active and add seamless event to the list */
|
---|
[57741] | 860 | if (0 != g_hSeamlessWtNotifyEvent)
|
---|
[45763] | 861 | {
|
---|
[57741] | 862 | hWaitEvent[dwEventCount++] = g_hSeamlessWtNotifyEvent;
|
---|
[45763] | 863 | }
|
---|
| 864 |
|
---|
[57741] | 865 | if (0 != g_hSeamlessKmNotifyEvent)
|
---|
[48070] | 866 | {
|
---|
[57741] | 867 | hWaitEvent[dwEventCount++] = g_hSeamlessKmNotifyEvent;
|
---|
[48070] | 868 | }
|
---|
| 869 |
|
---|
[45763] | 870 | if (0 != vboxDtGetNotifyEvent())
|
---|
| 871 | {
|
---|
| 872 | hWaitEvent[dwEventCount++] = vboxDtGetNotifyEvent();
|
---|
| 873 | }
|
---|
| 874 |
|
---|
[57741] | 875 | LogFlowFunc(("Number of events to wait in main loop: %ld\n", dwEventCount));
|
---|
[35863] | 876 | while (true)
|
---|
| 877 | {
|
---|
| 878 | DWORD waitResult = MsgWaitForMultipleObjectsEx(dwEventCount, hWaitEvent, 500, QS_ALLINPUT, 0);
|
---|
| 879 | waitResult = waitResult - WAIT_OBJECT_0;
|
---|
[1] | 880 |
|
---|
[35863] | 881 | /* Only enable for message debugging, lots of traffic! */
|
---|
[51469] | 882 | //Log(("Wait result = %ld\n", waitResult));
|
---|
[1] | 883 |
|
---|
[35863] | 884 | if (waitResult == 0)
|
---|
| 885 | {
|
---|
[57741] | 886 | LogFunc(("Event 'Exit' triggered\n"));
|
---|
[35863] | 887 | /* exit */
|
---|
| 888 | break;
|
---|
| 889 | }
|
---|
[45763] | 890 | else
|
---|
[35863] | 891 | {
|
---|
[45763] | 892 | BOOL fHandled = FALSE;
|
---|
| 893 | if (waitResult < RT_ELEMENTS(hWaitEvent))
|
---|
[45703] | 894 | {
|
---|
[45763] | 895 | if (hWaitEvent[waitResult])
|
---|
[45703] | 896 | {
|
---|
[57741] | 897 | if (hWaitEvent[waitResult] == g_hSeamlessWtNotifyEvent)
|
---|
[45763] | 898 | {
|
---|
[57741] | 899 | LogFunc(("Event 'Seamless' triggered\n"));
|
---|
[45763] | 900 |
|
---|
| 901 | /* seamless window notification */
|
---|
[48070] | 902 | VBoxSeamlessCheckWindows(false);
|
---|
[45763] | 903 | fHandled = TRUE;
|
---|
| 904 | }
|
---|
[57741] | 905 | else if (hWaitEvent[waitResult] == g_hSeamlessKmNotifyEvent)
|
---|
[48070] | 906 | {
|
---|
[57741] | 907 | LogFunc(("Event 'Km Seamless' triggered\n"));
|
---|
[48070] | 908 |
|
---|
| 909 | /* seamless window notification */
|
---|
| 910 | VBoxSeamlessCheckWindows(true);
|
---|
| 911 | fHandled = TRUE;
|
---|
| 912 | }
|
---|
[45763] | 913 | else if (hWaitEvent[waitResult] == vboxDtGetNotifyEvent())
|
---|
| 914 | {
|
---|
[57741] | 915 | LogFunc(("Event 'Dt' triggered\n"));
|
---|
[95967] | 916 | vboxDtDoCheck();
|
---|
[45763] | 917 | fHandled = TRUE;
|
---|
| 918 | }
|
---|
[45703] | 919 | }
|
---|
| 920 | }
|
---|
[45763] | 921 |
|
---|
| 922 | if (!fHandled)
|
---|
[35863] | 923 | {
|
---|
[45763] | 924 | /* timeout or a window message, handle it */
|
---|
| 925 | MSG msg;
|
---|
| 926 | while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
---|
[35863] | 927 | {
|
---|
[57741] | 928 | #ifdef DEBUG_andy
|
---|
| 929 | LogFlowFunc(("PeekMessage %u\n", msg.message));
|
---|
[49891] | 930 | #endif
|
---|
[45763] | 931 | if (msg.message == WM_QUIT)
|
---|
| 932 | {
|
---|
[57741] | 933 | LogFunc(("Terminating ...\n"));
|
---|
| 934 | SetEvent(g_hStopSem);
|
---|
[45763] | 935 | }
|
---|
| 936 | TranslateMessage(&msg);
|
---|
| 937 | DispatchMessage(&msg);
|
---|
[35863] | 938 | }
|
---|
| 939 | }
|
---|
| 940 | }
|
---|
| 941 | }
|
---|
[57741] | 942 | LogFunc(("Returned from main loop, exiting ...\n"));
|
---|
[35863] | 943 | }
|
---|
[57741] | 944 | LogFunc(("Waiting for services to stop ...\n"));
|
---|
| 945 | vboxTrayServicesStop(&svcEnv);
|
---|
[35863] | 946 | } /* Services started */
|
---|
[57741] | 947 | CloseHandle(g_hStopSem);
|
---|
[35863] | 948 | } /* Stop event created */
|
---|
[1] | 949 |
|
---|
[35863] | 950 | vboxTrayRemoveTrayIcon();
|
---|
[1] | 951 |
|
---|
[57741] | 952 | LogFunc(("Leaving with rc=%Rrc\n", rc));
|
---|
[35863] | 953 | return rc;
|
---|
[1] | 954 | }
|
---|
| 955 |
|
---|
| 956 | /**
|
---|
| 957 | * Main function
|
---|
| 958 | */
|
---|
[95863] | 959 | int main(int cArgs, char **papszArgs)
|
---|
[1] | 960 | {
|
---|
[95863] | 961 | int rc = RTR3InitExe(cArgs, &papszArgs, RTR3INIT_FLAGS_STANDALONE_APP);
|
---|
| 962 | if (RT_FAILURE(rc))
|
---|
| 963 | return RTMsgInitFailure(rc);
|
---|
[63099] | 964 |
|
---|
[95877] | 965 | /*
|
---|
| 966 | * Parse the top level arguments until we find a command.
|
---|
| 967 | */
|
---|
| 968 | static const RTGETOPTDEF s_aOptions[] =
|
---|
| 969 | {
|
---|
| 970 | { "--help", 'h', RTGETOPT_REQ_NOTHING },
|
---|
| 971 | { "-help", 'h', RTGETOPT_REQ_NOTHING },
|
---|
| 972 | { "/help", 'h', RTGETOPT_REQ_NOTHING },
|
---|
| 973 | { "/?", 'h', RTGETOPT_REQ_NOTHING },
|
---|
| 974 | { "--logfile", 'l', RTGETOPT_REQ_STRING },
|
---|
| 975 | { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
|
---|
| 976 | { "--version", 'V', RTGETOPT_REQ_NOTHING },
|
---|
| 977 | };
|
---|
[95827] | 978 |
|
---|
[95877] | 979 | char szLogFile[RTPATH_MAX] = {0};
|
---|
| 980 |
|
---|
| 981 | RTGETOPTSTATE GetState;
|
---|
| 982 | rc = RTGetOptInit(&GetState, cArgs, papszArgs, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0 /*fFlags*/);
|
---|
[95827] | 983 | if (RT_FAILURE(rc))
|
---|
[95877] | 984 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTGetOptInit failed: %Rrc\n", rc);
|
---|
[95827] | 985 |
|
---|
[95877] | 986 | int ch;
|
---|
| 987 | RTGETOPTUNION ValueUnion;
|
---|
| 988 | while ((ch = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
[95827] | 989 | {
|
---|
[95877] | 990 | switch (ch)
|
---|
[95827] | 991 | {
|
---|
[95877] | 992 | case 'h':
|
---|
| 993 | hlpShowMessageBox(VBOX_PRODUCT " - " VBOX_VBOXTRAY_TITLE,
|
---|
| 994 | MB_ICONINFORMATION,
|
---|
| 995 | "-- " VBOX_PRODUCT " %s v%u.%u.%ur%u --\n\n"
|
---|
[96399] | 996 | "Copyright (C) 2009-" VBOX_C_YEAR " " VBOX_VENDOR "\n\n"
|
---|
[95877] | 997 | "Command Line Parameters:\n\n"
|
---|
| 998 | "-l, --logfile <file>\n"
|
---|
| 999 | " Enables logging to a file\n"
|
---|
| 1000 | "-v, --verbose\n"
|
---|
| 1001 | " Increases verbosity\n"
|
---|
| 1002 | "-V, --version\n"
|
---|
| 1003 | " Displays version number and exit\n"
|
---|
| 1004 | "-?, -h, --help\n"
|
---|
| 1005 | " Displays this help text and exit\n"
|
---|
| 1006 | "\n"
|
---|
| 1007 | "Examples:\n"
|
---|
| 1008 | " %s -vvv\n",
|
---|
| 1009 | VBOX_VBOXTRAY_TITLE, VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV,
|
---|
| 1010 | papszArgs[0], papszArgs[0]);
|
---|
| 1011 | return RTEXITCODE_SUCCESS;
|
---|
[95827] | 1012 |
|
---|
[95877] | 1013 | case 'l':
|
---|
| 1014 | if (*ValueUnion.psz == '\0')
|
---|
| 1015 | szLogFile[0] = '\0';
|
---|
| 1016 | else
|
---|
| 1017 | {
|
---|
| 1018 | rc = RTPathAbs(ValueUnion.psz, szLogFile, sizeof(szLogFile));
|
---|
| 1019 | if (RT_FAILURE(rc))
|
---|
| 1020 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathAbs failed on log file path: %Rrc (%s)",
|
---|
| 1021 | rc, ValueUnion.psz);
|
---|
| 1022 | }
|
---|
| 1023 | break;
|
---|
[95827] | 1024 |
|
---|
[95877] | 1025 | case 'v':
|
---|
| 1026 | g_cVerbosity++;
|
---|
| 1027 | break;
|
---|
[95827] | 1028 |
|
---|
[95877] | 1029 | case 'V':
|
---|
| 1030 | hlpShowMessageBox(VBOX_VBOXTRAY_TITLE, MB_ICONINFORMATION,
|
---|
| 1031 | "Version: %u.%u.%ur%u",
|
---|
| 1032 | VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV);
|
---|
| 1033 | return RTEXITCODE_SUCCESS;
|
---|
[95827] | 1034 |
|
---|
[95877] | 1035 | default:
|
---|
| 1036 | rc = RTGetOptPrintError(ch, &ValueUnion);
|
---|
| 1037 | break;
|
---|
[95827] | 1038 | }
|
---|
| 1039 | }
|
---|
| 1040 |
|
---|
[49891] | 1041 | /* Note: Do not use a global namespace ("Global\\") for mutex name here,
|
---|
| 1042 | * will blow up NT4 compatibility! */
|
---|
[95827] | 1043 | HANDLE hMutexAppRunning = CreateMutex(NULL, FALSE, VBOX_VBOXTRAY_TITLE);
|
---|
[34025] | 1044 | if ( hMutexAppRunning != NULL
|
---|
| 1045 | && GetLastError() == ERROR_ALREADY_EXISTS)
|
---|
[10777] | 1046 | {
|
---|
[49891] | 1047 | /* VBoxTray already running? Bail out. */
|
---|
[34025] | 1048 | CloseHandle (hMutexAppRunning);
|
---|
| 1049 | hMutexAppRunning = NULL;
|
---|
[95827] | 1050 | return RTEXITCODE_SUCCESS;
|
---|
[10777] | 1051 | }
|
---|
[8897] | 1052 |
|
---|
[95827] | 1053 | rc = vboxTrayLogCreate(szLogFile[0] ? szLogFile : NULL);
|
---|
[35863] | 1054 | if (RT_SUCCESS(rc))
|
---|
[68559] | 1055 | {
|
---|
[95827] | 1056 | LogRel(("Verbosity level: %d\n", g_cVerbosity));
|
---|
| 1057 |
|
---|
[35863] | 1058 | rc = VbglR3Init();
|
---|
| 1059 | if (RT_SUCCESS(rc))
|
---|
| 1060 | {
|
---|
[78937] | 1061 | /* Log the major windows NT version: */
|
---|
| 1062 | uint64_t const uNtVersion = RTSystemGetNtVersion();
|
---|
| 1063 | LogRel(("Windows version %u.%u build %u (uNtVersion=%#RX64)\n", RTSYSTEM_NT_VERSION_GET_MAJOR(uNtVersion),
|
---|
| 1064 | RTSYSTEM_NT_VERSION_GET_MINOR(uNtVersion), RTSYSTEM_NT_VERSION_GET_BUILD(uNtVersion), uNtVersion ));
|
---|
| 1065 |
|
---|
[95863] | 1066 | /* Set the instance handle. */
|
---|
| 1067 | #ifdef IPRT_NO_CRT
|
---|
[95877] | 1068 | Assert(g_hInstance == NULL); /* Make sure this isn't set before by WinMain(). */
|
---|
[95863] | 1069 | g_hInstance = GetModuleHandleW(NULL);
|
---|
| 1070 | #endif
|
---|
[68559] | 1071 | hlpReportStatus(VBoxGuestFacilityStatus_Init);
|
---|
| 1072 | rc = vboxTrayCreateToolWindow();
|
---|
| 1073 | if (RT_SUCCESS(rc))
|
---|
[45703] | 1074 | {
|
---|
[68559] | 1075 | VBoxCapsInit();
|
---|
[45703] | 1076 |
|
---|
[68559] | 1077 | rc = vboxStInit(g_hwndToolWindow);
|
---|
| 1078 | if (!RT_SUCCESS(rc))
|
---|
| 1079 | {
|
---|
| 1080 | LogFlowFunc(("vboxStInit failed, rc=%Rrc\n", rc));
|
---|
| 1081 | /* ignore the St Init failure. this can happen for < XP win that do not support WTS API
|
---|
| 1082 | * in that case the session is treated as active connected to the physical console
|
---|
| 1083 | * (i.e. fallback to the old behavior that was before introduction of VBoxSt) */
|
---|
| 1084 | Assert(vboxStIsActiveConsole());
|
---|
| 1085 | }
|
---|
[45703] | 1086 |
|
---|
[68559] | 1087 | rc = vboxDtInit();
|
---|
| 1088 | if (!RT_SUCCESS(rc))
|
---|
| 1089 | {
|
---|
| 1090 | LogFlowFunc(("vboxDtInit failed, rc=%Rrc\n", rc));
|
---|
| 1091 | /* ignore the Dt Init failure. this can happen for < XP win that do not support WTS API
|
---|
| 1092 | * in that case the session is treated as active connected to the physical console
|
---|
| 1093 | * (i.e. fallback to the old behavior that was before introduction of VBoxSt) */
|
---|
| 1094 | Assert(vboxDtIsInputDesktop());
|
---|
| 1095 | }
|
---|
[46196] | 1096 |
|
---|
[68559] | 1097 | rc = VBoxAcquireGuestCaps(VMMDEV_GUEST_SUPPORTS_SEAMLESS | VMMDEV_GUEST_SUPPORTS_GRAPHICS, 0, true);
|
---|
| 1098 | if (!RT_SUCCESS(rc))
|
---|
| 1099 | LogFlowFunc(("VBoxAcquireGuestCaps failed with rc=%Rrc, ignoring ...\n", rc));
|
---|
| 1100 |
|
---|
| 1101 | rc = vboxTraySetupSeamless(); /** @todo r=andy Do we really want to be this critical for the whole application? */
|
---|
[35863] | 1102 | if (RT_SUCCESS(rc))
|
---|
[68559] | 1103 | {
|
---|
| 1104 | rc = vboxTrayServiceMain();
|
---|
| 1105 | if (RT_SUCCESS(rc))
|
---|
| 1106 | hlpReportStatus(VBoxGuestFacilityStatus_Terminating);
|
---|
| 1107 | vboxTrayShutdownSeamless();
|
---|
| 1108 | }
|
---|
[45703] | 1109 |
|
---|
[68559] | 1110 | /* it should be safe to call vboxDtTerm even if vboxStInit above failed */
|
---|
| 1111 | vboxDtTerm();
|
---|
[45703] | 1112 |
|
---|
[68559] | 1113 | /* it should be safe to call vboxStTerm even if vboxStInit above failed */
|
---|
| 1114 | vboxStTerm();
|
---|
[45703] | 1115 |
|
---|
[68559] | 1116 | VBoxCapsTerm();
|
---|
[45763] | 1117 |
|
---|
[68559] | 1118 | vboxTrayDestroyToolWindow();
|
---|
| 1119 | }
|
---|
| 1120 | if (RT_SUCCESS(rc))
|
---|
| 1121 | hlpReportStatus(VBoxGuestFacilityStatus_Terminated);
|
---|
| 1122 | else
|
---|
| 1123 | {
|
---|
| 1124 | LogRel(("Error while starting, rc=%Rrc\n", rc));
|
---|
| 1125 | hlpReportStatus(VBoxGuestFacilityStatus_Failed);
|
---|
| 1126 | }
|
---|
| 1127 |
|
---|
| 1128 | LogRel(("Ended\n"));
|
---|
| 1129 | VbglR3Term();
|
---|
[35863] | 1130 | }
|
---|
[68559] | 1131 | else
|
---|
| 1132 | LogRel(("VbglR3Init failed: %Rrc\n", rc));
|
---|
[35863] | 1133 | }
|
---|
[35907] | 1134 |
|
---|
[8897] | 1135 | /* Release instance mutex. */
|
---|
[34025] | 1136 | if (hMutexAppRunning != NULL)
|
---|
| 1137 | {
|
---|
[23053] | 1138 | CloseHandle(hMutexAppRunning);
|
---|
[8897] | 1139 | hMutexAppRunning = NULL;
|
---|
| 1140 | }
|
---|
| 1141 |
|
---|
[49891] | 1142 | vboxTrayLogDestroy();
|
---|
| 1143 |
|
---|
[95877] | 1144 | return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
|
---|
[1] | 1145 | }
|
---|
| 1146 |
|
---|
[95877] | 1147 | #ifndef IPRT_NO_CRT
|
---|
| 1148 | int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
---|
| 1149 | {
|
---|
| 1150 | RT_NOREF(hPrevInstance, lpCmdLine, nCmdShow);
|
---|
| 1151 |
|
---|
| 1152 | g_hInstance = hInstance;
|
---|
| 1153 |
|
---|
| 1154 | return main(__argc, __argv);
|
---|
| 1155 | }
|
---|
| 1156 | #endif /* IPRT_NO_CRT */
|
---|
| 1157 |
|
---|
[1] | 1158 | /**
|
---|
[57741] | 1159 | * Window procedure for our main tool window.
|
---|
[1] | 1160 | */
|
---|
[37422] | 1161 | static LRESULT CALLBACK vboxToolWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
[1] | 1162 | {
|
---|
[57741] | 1163 | LogFlowFunc(("hWnd=%p, uMsg=%u\n", hWnd, uMsg));
|
---|
| 1164 |
|
---|
[34025] | 1165 | switch (uMsg)
|
---|
[1] | 1166 | {
|
---|
[30928] | 1167 | case WM_CREATE:
|
---|
[34025] | 1168 | {
|
---|
[57741] | 1169 | LogFunc(("Tool window created\n"));
|
---|
[30928] | 1170 |
|
---|
[63099] | 1171 | int rc = vboxTrayRegisterGlobalMessages(&g_vboxGlobalMessageTable[0]);
|
---|
[34025] | 1172 | if (RT_FAILURE(rc))
|
---|
[57741] | 1173 | LogFunc(("Error registering global window messages, rc=%Rrc\n", rc));
|
---|
[34025] | 1174 | return 0;
|
---|
| 1175 | }
|
---|
| 1176 |
|
---|
[1] | 1177 | case WM_CLOSE:
|
---|
[34025] | 1178 | return 0;
|
---|
[1] | 1179 |
|
---|
| 1180 | case WM_DESTROY:
|
---|
[57741] | 1181 | {
|
---|
| 1182 | LogFunc(("Tool window destroyed\n"));
|
---|
| 1183 | KillTimer(g_hwndToolWindow, TIMERID_VBOXTRAY_CHECK_HOSTVERSION);
|
---|
[34025] | 1184 | return 0;
|
---|
[57741] | 1185 | }
|
---|
[1] | 1186 |
|
---|
[23053] | 1187 | case WM_TIMER:
|
---|
[57741] | 1188 | {
|
---|
[45763] | 1189 | if (VBoxCapsCheckTimer(wParam))
|
---|
| 1190 | return 0;
|
---|
[45837] | 1191 | if (vboxDtCheckTimer(wParam))
|
---|
[45802] | 1192 | return 0;
|
---|
[45837] | 1193 | if (vboxStCheckTimer(wParam))
|
---|
| 1194 | return 0;
|
---|
[45763] | 1195 |
|
---|
[23055] | 1196 | switch (wParam)
|
---|
| 1197 | {
|
---|
[34025] | 1198 | case TIMERID_VBOXTRAY_CHECK_HOSTVERSION:
|
---|
[23053] | 1199 | if (RT_SUCCESS(VBoxCheckHostVersion()))
|
---|
| 1200 | {
|
---|
| 1201 | /* After successful run we don't need to check again. */
|
---|
[57741] | 1202 | KillTimer(g_hwndToolWindow, TIMERID_VBOXTRAY_CHECK_HOSTVERSION);
|
---|
[23053] | 1203 | }
|
---|
| 1204 | return 0;
|
---|
| 1205 |
|
---|
| 1206 | default:
|
---|
| 1207 | break;
|
---|
| 1208 | }
|
---|
[57741] | 1209 |
|
---|
[34025] | 1210 | break; /* Make sure other timers get processed the usual way! */
|
---|
[57741] | 1211 | }
|
---|
[23053] | 1212 |
|
---|
[33966] | 1213 | case WM_VBOXTRAY_TRAY_ICON:
|
---|
[57741] | 1214 | {
|
---|
[81132] | 1215 | switch (LOWORD(lParam))
|
---|
[23055] | 1216 | {
|
---|
| 1217 | case WM_LBUTTONDBLCLK:
|
---|
| 1218 | break;
|
---|
[81132] | 1219 | case WM_RBUTTONDOWN:
|
---|
| 1220 | {
|
---|
[95827] | 1221 | if (!g_cVerbosity) /* Don't show menu when running in non-verbose mode. */
|
---|
| 1222 | break;
|
---|
| 1223 |
|
---|
[81132] | 1224 | POINT lpCursor;
|
---|
| 1225 | if (GetCursorPos(&lpCursor))
|
---|
| 1226 | {
|
---|
| 1227 | HMENU hContextMenu = CreatePopupMenu();
|
---|
| 1228 | if (hContextMenu)
|
---|
| 1229 | {
|
---|
| 1230 | UINT_PTR uMenuItem = 9999;
|
---|
| 1231 | UINT fMenuItem = MF_BYPOSITION | MF_STRING;
|
---|
| 1232 | if (InsertMenuW(hContextMenu, UINT_MAX, fMenuItem, uMenuItem, L"Exit"))
|
---|
| 1233 | {
|
---|
| 1234 | SetForegroundWindow(hWnd);
|
---|
[23055] | 1235 |
|
---|
[81132] | 1236 | const bool fBlockWhileTracking = true;
|
---|
| 1237 |
|
---|
| 1238 | UINT fTrack = TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_BOTTOMALIGN;
|
---|
| 1239 |
|
---|
| 1240 | if (fBlockWhileTracking)
|
---|
| 1241 | fTrack |= TPM_RETURNCMD | TPM_NONOTIFY;
|
---|
| 1242 |
|
---|
[83823] | 1243 | uMsg = TrackPopupMenu(hContextMenu, fTrack, lpCursor.x, lpCursor.y, 0, hWnd, NULL);
|
---|
[81132] | 1244 | if ( uMsg
|
---|
| 1245 | && fBlockWhileTracking)
|
---|
| 1246 | {
|
---|
| 1247 | if (uMsg == uMenuItem)
|
---|
| 1248 | PostMessage(g_hwndToolWindow, WM_QUIT, 0, 0);
|
---|
| 1249 | }
|
---|
| 1250 | else if (!uMsg)
|
---|
| 1251 | LogFlowFunc(("Tracking popup menu failed with %ld\n", GetLastError()));
|
---|
| 1252 | }
|
---|
[81145] | 1253 |
|
---|
| 1254 | DestroyMenu(hContextMenu);
|
---|
[81132] | 1255 | }
|
---|
| 1256 | }
|
---|
[23055] | 1257 | break;
|
---|
[81132] | 1258 | }
|
---|
[23055] | 1259 | }
|
---|
[34025] | 1260 | return 0;
|
---|
[57741] | 1261 | }
|
---|
[23055] | 1262 |
|
---|
[45703] | 1263 | case WM_VBOX_SEAMLESS_ENABLE:
|
---|
[57741] | 1264 | {
|
---|
[45763] | 1265 | VBoxCapsEntryFuncStateSet(VBOXCAPS_ENTRY_IDX_SEAMLESS, VBOXCAPS_ENTRY_FUNCSTATE_STARTED);
|
---|
[65442] | 1266 | if (VBoxCapsEntryIsEnabled(VBOXCAPS_ENTRY_IDX_SEAMLESS))
|
---|
| 1267 | VBoxSeamlessCheckWindows(true);
|
---|
[34025] | 1268 | return 0;
|
---|
[57741] | 1269 | }
|
---|
[3811] | 1270 |
|
---|
[45703] | 1271 | case WM_VBOX_SEAMLESS_DISABLE:
|
---|
[57741] | 1272 | {
|
---|
[45763] | 1273 | VBoxCapsEntryFuncStateSet(VBOXCAPS_ENTRY_IDX_SEAMLESS, VBOXCAPS_ENTRY_FUNCSTATE_SUPPORTED);
|
---|
[34025] | 1274 | return 0;
|
---|
[57741] | 1275 | }
|
---|
[3811] | 1276 |
|
---|
[45853] | 1277 | case WM_DISPLAYCHANGE:
|
---|
[62865] | 1278 | ASMAtomicUoWriteU32(&g_fGuestDisplaysChanged, 1);
|
---|
| 1279 | // No break or return is intentional here.
|
---|
[3881] | 1280 | case WM_VBOX_SEAMLESS_UPDATE:
|
---|
[57741] | 1281 | {
|
---|
[45763] | 1282 | if (VBoxCapsEntryIsEnabled(VBOXCAPS_ENTRY_IDX_SEAMLESS))
|
---|
[48070] | 1283 | VBoxSeamlessCheckWindows(true);
|
---|
[34025] | 1284 | return 0;
|
---|
[57741] | 1285 | }
|
---|
[3881] | 1286 |
|
---|
[45763] | 1287 | case WM_VBOX_GRAPHICS_SUPPORTED:
|
---|
[57741] | 1288 | {
|
---|
[45763] | 1289 | VBoxGrapicsSetSupported(TRUE);
|
---|
| 1290 | return 0;
|
---|
[57741] | 1291 | }
|
---|
[45763] | 1292 |
|
---|
| 1293 | case WM_VBOX_GRAPHICS_UNSUPPORTED:
|
---|
[57741] | 1294 | {
|
---|
[45763] | 1295 | VBoxGrapicsSetSupported(FALSE);
|
---|
| 1296 | return 0;
|
---|
[57741] | 1297 | }
|
---|
[45763] | 1298 |
|
---|
[45703] | 1299 | case WM_WTSSESSION_CHANGE:
|
---|
| 1300 | {
|
---|
[45763] | 1301 | BOOL fOldAllowedState = VBoxConsoleIsAllowed();
|
---|
[63099] | 1302 | if (vboxStHandleEvent(wParam))
|
---|
[45703] | 1303 | {
|
---|
[45763] | 1304 | if (!VBoxConsoleIsAllowed() != !fOldAllowedState)
|
---|
| 1305 | VBoxConsoleEnable(!fOldAllowedState);
|
---|
[45703] | 1306 | }
|
---|
| 1307 | return 0;
|
---|
| 1308 | }
|
---|
[57741] | 1309 |
|
---|
[1] | 1310 | default:
|
---|
[57741] | 1311 | {
|
---|
[34025] | 1312 | /* Handle all globally registered window messages. */
|
---|
[63099] | 1313 | if (vboxTrayHandleGlobalMessages(&g_vboxGlobalMessageTable[0], uMsg,
|
---|
[34025] | 1314 | wParam, lParam))
|
---|
[30928] | 1315 | {
|
---|
[34025] | 1316 | return 0; /* We handled the message. @todo Add return value!*/
|
---|
[30928] | 1317 | }
|
---|
[34025] | 1318 | break; /* We did not handle the message, dispatch to DefWndProc. */
|
---|
[57741] | 1319 | }
|
---|
[1] | 1320 | }
|
---|
[34025] | 1321 |
|
---|
[57741] | 1322 | /* Only if message was *not* handled by our switch above, dispatch to DefWindowProc. */
|
---|
[34025] | 1323 | return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
---|
[1] | 1324 | }
|
---|
[37422] | 1325 |
|
---|
[45763] | 1326 | static void VBoxGrapicsSetSupported(BOOL fSupported)
|
---|
| 1327 | {
|
---|
| 1328 | VBoxConsoleCapSetSupported(VBOXCAPS_ENTRY_IDX_GRAPHICS, fSupported);
|
---|
| 1329 | }
|
---|
[95966] | 1330 |
|
---|