VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHostVersion.cpp@ 23069

Last change on this file since 23069 was 23069, checked in by vboxsync, 15 years ago

fix OSE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1
2/* $Id: VBoxHostVersion.cpp 23069 2009-09-16 13:03:17Z vboxsync $ */
3/** @file
4 * VBoxHostVersion - Checks the host's VirtualBox version and notifies
5 * the user in case of an update.
6 */
7
8/*
9 * Copyright (C) 2009 Sun Microsystems, Inc.
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#include "VBoxHostVersion.h"
25#include "VBoxTray.h"
26#include "helpers.h"
27
28#include <VBox/VBoxGuestLib.h>
29
30/* Returns 0 if equal, 1 if Ver1 is greater, 2 if Ver2 is greater
31 * Requires strings in form of "majorVer.minorVer.build" */
32int VBoxCompareVersion (const char* pszVer1, const char* pszVer2)
33{
34 int rc = 0;
35 int iVer1Major, iVer1Minor, iVer1Build;
36 sscanf(pszVer1, "%d.%d.%d", &iVer1Major, &iVer1Minor, &iVer1Build);
37 int iVer2Major, iVer2Minor, iVer2Build;
38 sscanf(pszVer2, "%d.%d.%d", &iVer2Major, &iVer2Minor, &iVer2Build);
39
40 int iVer1Final = (iVer1Major * 10000) + (iVer1Minor * 100) + iVer1Build;
41 int iVer2Final = (iVer2Major * 10000) + (iVer2Minor * 100) + iVer2Build;
42
43 if (iVer1Final > iVer2Final)
44 rc = 1;
45 else if (iVer2Final > iVer1Final)
46 rc = 2;
47 return rc;
48}
49
50int VBoxCheckHostVersion ()
51{
52 int rc;
53 uint32_t uGuestPropSvcClientID;
54
55 rc = VbglR3GuestPropConnect(&uGuestPropSvcClientID);
56 if (RT_SUCCESS(rc))
57 Log(("VBoxTray: Property Service Client ID: %ld\n", uGuestPropSvcClientID));
58 else
59 Log(("VBoxTray: Failed to connect to the guest property service! Error: %d\n", rc));
60
61 char szMsg[256] = "\0"; /* Sizes according to MSDN. */
62 char szTitle[64] = "\0";
63
64 if (RT_SUCCESS(rc))
65 {
66 /* Look up host version (revision) */
67 char *pszVBoxHostVer; // , *pszVBoxHostRev;
68 rc = VbglR3GuestPropReadValueAlloc(uGuestPropSvcClientID, "/VirtualBox/HostInfo/VBoxVer", &pszVBoxHostVer);
69 if(RT_FAILURE(rc))
70 Log(("VBoxTray: Could not read VBox host version! rc = %d\n", rc));
71
72 /*rc = VbglR3GuestPropReadValueAlloc(uGuestPropSvcClientID, "/VirtualBox/HostInfo/VBoxRev", &pszVBoxHostRev);
73 if(RT_FAILURE(rc))
74 Log(("VBoxTray: Could not read VBox host revision! rc = %d\n", rc));*/
75
76 if (RT_SUCCESS(rc))
77 {
78 Log(("VBoxTray: Host version: %s\n", pszVBoxHostVer));
79
80 /* Look up guest version */
81 char szVBoxGuestVer[32];
82 char szVBoxGuestRev[32];
83
84 rc = getAdditionsVersion(szVBoxGuestVer, sizeof(szVBoxGuestVer), szVBoxGuestRev, sizeof(szVBoxGuestRev));
85 if (RT_SUCCESS(rc))
86 {
87 Log(("VBoxTray: Additions version: %s\n", szVBoxGuestVer));
88
89 /* Look up last informed host version */
90 char szVBoxHostVerLastChecked[32];
91 HKEY hKey;
92 LONG lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions\\VBoxTray", 0, KEY_READ, &hKey);
93 if (lRet == ERROR_SUCCESS)
94 {
95 DWORD dwType;
96 DWORD dwSize = sizeof(szVBoxHostVerLastChecked);
97 lRet = RegQueryValueEx(hKey, "HostVerLastChecked", NULL, &dwType, (BYTE*)szVBoxHostVerLastChecked, &dwSize);
98 if (lRet != ERROR_SUCCESS && lRet != ERROR_FILE_NOT_FOUND)
99 Log(("VBoxTray: Could not read HostVerLastChecked! Error = %ld\n", lRet));
100 RegCloseKey(hKey);
101 }
102 else if (lRet != ERROR_FILE_NOT_FOUND)
103 {
104 Log(("VBoxTray: Could not open VBoxTray registry key! Error = %ld\n", lRet));
105 rc = RTErrConvertFromWin32(lRet);
106 }
107
108 /** @todo implement a special value of last informed host version (or a new flag) to disable this service. */
109
110 /* Compare both versions and prepare message */
111 if ( RT_SUCCESS(rc)
112 && strcmp(pszVBoxHostVer, szVBoxHostVerLastChecked) != 0 /* Make sure we did not process this host version already */
113 && VBoxCompareVersion(pszVBoxHostVer, szVBoxGuestVer) == 1) /* Is host version greater than guest add version? */
114 {
115 /** @todo add some translation macros here */
116 _snprintf(szTitle, sizeof(szTitle), "New VirtualBox Guest Additions %s available!", pszVBoxHostVer);
117 _snprintf(szMsg, sizeof(szMsg), "A new version %s of VirtualBox has been installed on the host. "
118 "To ensure that this guest can take advantage of the host's version, "
119 "please also update the Guest Additions (current: %s) of this machine.",
120 pszVBoxHostVer, szVBoxGuestVer);
121
122 /* Save the version to just do a balloon once per new version */
123 if (RT_SUCCESS(rc))
124 {
125 lRet = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
126 "SOFTWARE\\Sun\\VirtualBox Guest Additions\\VBoxTray",
127 0, /* Reserved */
128 NULL, /* lpClass [in, optional] */
129 0, /* dwOptions [in] */
130 KEY_WRITE,
131 NULL, /* lpSecurityAttributes [in, optional] */
132 &hKey,
133 NULL); /* lpdwDisposition [out, optional] */
134 if (lRet == ERROR_SUCCESS)
135 {
136 lRet = RegSetValueEx(hKey, "HostVerLastChecked", 0, REG_SZ, (BYTE*)pszVBoxHostVer, strlen(pszVBoxHostVer)*sizeof(char));
137 if (lRet != ERROR_SUCCESS)
138 Log(("VBoxTray: Could not write HostVerLastChecked! Error = %ld\n", lRet));
139 RegCloseKey(hKey);
140 }
141 else
142 Log(("VBoxTray: Could not open VBoxTray registry key! Error = %ld\n", lRet));
143
144 if(lRet != ERROR_SUCCESS)
145 rc = RTErrConvertFromWin32(lRet);
146 }
147 }
148 }
149 }
150 VbglR3GuestPropReadValueFree(pszVBoxHostVer);
151 //VbglR3GuestPropReadValueFree(pszVBoxHostRev);
152 }
153
154 if(RT_SUCCESS(rc) && strlen(szMsg))
155 {
156 rc = showBalloonTip(gInstance, gToolWindow, ID_TRAYICON, szMsg, szTitle, 5000, 0);
157 if(RT_FAILURE(rc))
158 Log(("VBoxTray: Could not show version notifier balloon tooltip! rc = %d\n", rc));
159 }
160
161 VbglR3GuestPropDisconnect(uGuestPropSvcClientID);
162 return rc;
163}
164
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette