Changeset 23845 in vbox for trunk/src/VBox/Additions/WINNT/VBoxTray
- Timestamp:
- Oct 19, 2009 8:49:10 AM (15 years ago)
- Location:
- trunk/src/VBox/Additions/WINNT/VBoxTray
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHostVersion.cpp
r23836 r23845 27 27 #include <VBox/VBoxGuestLib.h> 28 28 29 /* Returns 0 if equal, 1 if Ver1 is greater, 2 if Ver2 is greater 30 * Requires strings in form of "majorVer.minorVer.build" */ 31 /** @todo should be common code in the guest lib / headers */ 32 int 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 } 29 49 30 50 int VBoxCheckHostVersion () 31 51 { 32 52 int rc; 33 char *pszHostVersion; 34 char *pszGuestVersion; 35 rc = VbglR3HostVersionCheckForUpdate(&pszHostVersion, &pszGuestVersion); 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 /* Do we need to do all this stuff? */ 62 char *pszCheckHostVersion; 63 rc = VbglR3GuestPropReadValueAlloc(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/CheckHostVersion", &pszCheckHostVersion); 64 if (RT_FAILURE(rc)) 65 { 66 if (rc == VERR_NOT_FOUND) 67 rc = VINF_SUCCESS; /* If we don't find the value above we do the check by default */ 68 else 69 Log(("VBoxTray: Could not read check host version flag! rc = %d\n", rc)); 70 } 71 else 72 { 73 /* Only don't do the check if we have a valid "0" in it */ 74 if ( atoi(pszCheckHostVersion) == 0 75 && strlen(pszCheckHostVersion)) 76 { 77 rc = VERR_NOT_SUPPORTED; 78 } 79 VbglR3GuestPropReadValueFree(pszCheckHostVersion); 80 } 81 if (rc == VERR_NOT_SUPPORTED) 82 Log(("VBoxTray: No host version check performed.")); 83 84 char szMsg[256] = "\0"; /* Sizes according to MSDN. */ 85 char szTitle[64] = "\0"; 86 36 87 if (RT_SUCCESS(rc)) 37 88 { 38 char szMsg[256]; /* Sizes according to MSDN. */ 39 char szTitle[64]; 89 /* Look up host version (revision) */ 90 char *pszVBoxHostVer; 91 rc = VbglR3GuestPropReadValueAlloc(uGuestPropSvcClientID, "/VirtualBox/HostInfo/VBoxVer", &pszVBoxHostVer); 92 if (RT_FAILURE(rc)) 93 { 94 Log(("VBoxTray: Could not read VBox host version! rc = %d\n", rc)); 95 } 96 else 97 { 98 Log(("VBoxTray: Host version: %s\n", pszVBoxHostVer)); 40 99 41 /** @todo add some translation macros here */ 42 _snprintf(szTitle, sizeof(szTitle), "VirtualBox Guest Additions update available!"); 43 _snprintf(szMsg, sizeof(szMsg), "Your guest is currently running the Guest Additions version %s. " 44 "We recommend updating to the latest version (%s) by choosing the " 45 "install option from the Devices menu.", pszGuestVersion, pszHostVersion); 100 /* Look up guest version */ 101 char szVBoxGuestVer[32]; 102 char szVBoxGuestRev[32]; 46 103 104 rc = getAdditionsVersion(szVBoxGuestVer, sizeof(szVBoxGuestVer), szVBoxGuestRev, sizeof(szVBoxGuestRev)); 105 if (RT_SUCCESS(rc)) 106 { 107 Log(("VBoxTray: Additions version: %s\n", szVBoxGuestVer)); 108 109 /* Look up last informed host version */ 110 char szVBoxHostVerLastChecked[32]; 111 HKEY hKey; 112 LONG lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions\\VBoxTray", 0, KEY_READ, &hKey); 113 if (lRet == ERROR_SUCCESS) 114 { 115 DWORD dwType; 116 DWORD dwSize = sizeof(szVBoxHostVerLastChecked); 117 lRet = RegQueryValueEx(hKey, "HostVerLastChecked", NULL, &dwType, (BYTE*)szVBoxHostVerLastChecked, &dwSize); 118 if (lRet != ERROR_SUCCESS && lRet != ERROR_FILE_NOT_FOUND) 119 Log(("VBoxTray: Could not read HostVerLastChecked! Error = %ld\n", lRet)); 120 RegCloseKey(hKey); 121 } 122 else if (lRet != ERROR_FILE_NOT_FOUND) 123 { 124 Log(("VBoxTray: Could not open VBoxTray registry key! Error = %ld\n", lRet)); 125 rc = RTErrConvertFromWin32(lRet); 126 } 127 128 /* Compare both versions and prepare message */ 129 if ( RT_SUCCESS(rc) 130 && strcmp(pszVBoxHostVer, szVBoxHostVerLastChecked) != 0 /* Make sure we did not process this host version already */ 131 && VBoxCompareVersion(pszVBoxHostVer, szVBoxGuestVer) == 1) /* Is host version greater than guest add version? */ 132 { 133 /** @todo add some translation macros here */ 134 _snprintf(szTitle, sizeof(szTitle), "VirtualBox Guest Additions update available!"); 135 _snprintf(szMsg, sizeof(szMsg), "Your guest is currently running the Guest Additions version %s. " 136 "We recommend updating to the latest version (%s) by choosing the " 137 "install option from the Devices menu.", szVBoxGuestVer, pszVBoxHostVer); 138 139 /* Save the version to just do a balloon once per new version */ 140 if (RT_SUCCESS(rc)) 141 { 142 lRet = RegCreateKeyEx (HKEY_LOCAL_MACHINE, 143 "SOFTWARE\\Sun\\VirtualBox Guest Additions\\VBoxTray", 144 0, /* Reserved */ 145 NULL, /* lpClass [in, optional] */ 146 0, /* dwOptions [in] */ 147 KEY_WRITE, 148 NULL, /* lpSecurityAttributes [in, optional] */ 149 &hKey, 150 NULL); /* lpdwDisposition [out, optional] */ 151 if (lRet == ERROR_SUCCESS) 152 { 153 lRet = RegSetValueEx(hKey, "HostVerLastChecked", 0, REG_SZ, (BYTE*)pszVBoxHostVer, (DWORD)(strlen(pszVBoxHostVer)*sizeof(char))); 154 if (lRet != ERROR_SUCCESS) 155 Log(("VBoxTray: Could not write HostVerLastChecked! Error = %ld\n", lRet)); 156 RegCloseKey(hKey); 157 } 158 else 159 Log(("VBoxTray: Could not open VBoxTray registry key! Error = %ld\n", lRet)); 160 161 if (lRet != ERROR_SUCCESS) 162 rc = RTErrConvertFromWin32(lRet); 163 } 164 } 165 } 166 } 167 VbglR3GuestPropReadValueFree(pszVBoxHostVer); 168 } 169 170 if (RT_SUCCESS(rc) && strlen(szMsg)) 171 { 47 172 rc = showBalloonTip(gInstance, gToolWindow, ID_TRAYICON, szMsg, szTitle, 5000, 0); 48 173 if (RT_FAILURE(rc)) 49 174 Log(("VBoxTray: Could not show version notifier balloon tooltip! rc = %d\n", rc)); 50 51 VbglR3GuestPropReadValueFree(pszHostVersion);52 VbglR3GuestPropReadValueFree(pszGuestVersion);53 175 } 54 176 … … 56 178 if (rc == VERR_NOT_SUPPORTED) 57 179 rc = VINF_SUCCESS; 180 181 VbglR3GuestPropDisconnect(uGuestPropSvcClientID); 58 182 return rc; 59 183 } -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHostVersion.h
r23835 r23845 25 25 26 26 #endif /* !___VBoxHostVersion_h */ 27 -
trunk/src/VBox/Additions/WINNT/VBoxTray/helpers.cpp
r23835 r23845 256 256 return 0; 257 257 } 258 259 /** @todo move this in guest lib, also used in a similar way in VBoxService */ 260 int getAdditionsVersion(char *pszVer, size_t cbSizeVer, char *pszRev, size_t cbSizeRev) 261 { 262 HKEY hKey; 263 int rc; 264 265 /* Check the new path first. */ 266 rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey); 267 #ifdef RT_ARCH_AMD64 268 if (rc != ERROR_SUCCESS) 269 { 270 /* Check Wow6432Node (for new entries). */ 271 rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey); 272 } 273 #endif 274 275 /* Still no luck? Then try the old xVM paths ... */ 276 if (RT_FAILURE(rc)) 277 { 278 rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, &hKey); 279 #ifdef RT_ARCH_AMD64 280 if (rc != ERROR_SUCCESS) 281 { 282 /* Check Wow6432Node (for new entries). */ 283 rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, &hKey); 284 } 285 #endif 286 } 287 288 /* Did we get something worth looking at? */ 289 if (RT_SUCCESS(rc)) 290 { 291 DWORD dwSize; 292 DWORD dwType; 293 294 /* Revision. */ 295 dwSize = cbSizeRev; 296 rc = RegQueryValueEx(hKey, "Revision", NULL, &dwType, (BYTE*)(LPCTSTR)pszRev, &dwSize); 297 /* Version. */ 298 dwSize = cbSizeVer; 299 rc = RegQueryValueEx(hKey, "Version", NULL, &dwType, (BYTE*)(LPCTSTR)pszVer, &dwSize); 300 } 301 302 if (NULL != hKey) 303 RegCloseKey(hKey); 304 305 return rc; 306 } -
trunk/src/VBox/Additions/WINNT/VBoxTray/helpers.h
r23835 r23845 33 33 void resizeRect(RECTL *paRects, unsigned nRects, unsigned iPrimary, unsigned iResized, int NewWidth, int NewHeight); 34 34 int showBalloonTip (HINSTANCE hInst, HWND hWnd, UINT uID, const char *pszMsg, const char *pszTitle, UINT uTimeout, DWORD dwInfoFlags); 35 int getAdditionsVersion(char *pszVer, size_t cbSizeVer, char *pszRev, size_t cbSizeRev); 35 36 36 37 #endif /* !___VBOXTRAY_HELPERS_H */
Note:
See TracChangeset
for help on using the changeset viewer.