Changeset 23876 in vbox
- Timestamp:
- Oct 19, 2009 4:24:26 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 53653
- Location:
- trunk/src/VBox/Additions
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHostVersion.cpp
r23858 r23876 28 28 29 29 30 /** @todo Move this part in VbglR3 and just provide a callback for the platform-specific 31 notification stuff, since this is very similar to the VBoxClient code. */ 30 32 int VBoxCheckHostVersion () 31 33 { 32 34 int rc; 33 char *pszHostVersion;34 char *pszGuestVersion; 35 rc = VbglR3 HostVersionCheckForUpdate(&pszHostVersion, &pszGuestVersion);35 uint32_t uGuestPropSvcClientID; 36 37 rc = VbglR3GuestPropConnect(&uGuestPropSvcClientID); 36 38 if (RT_SUCCESS(rc)) 37 39 { 38 char szMsg[256]; /* Sizes according to MSDN. */ 39 char szTitle[64]; 40 char *pszHostVersion; 41 char *pszGuestVersion; 42 bool bUpdate; 43 rc = VbglR3HostVersionCheckForUpdate(uGuestPropSvcClientID, &bUpdate, &pszHostVersion, &pszGuestVersion); 44 if (RT_SUCCESS(rc)) 45 { 46 if (bUpdate) 47 { 48 char szMsg[256]; /* Sizes according to MSDN. */ 49 char szTitle[64]; 50 51 /** @todo add some translation macros here */ 52 _snprintf(szTitle, sizeof(szTitle), "VirtualBox Guest Additions update available!"); 53 _snprintf(szMsg, sizeof(szMsg), "Your guest is currently running the Guest Additions version %s. " 54 "We recommend updating to the latest version (%s) by choosing the " 55 "install option from the Devices menu.", pszGuestVersion, pszHostVersion); 56 57 rc = showBalloonTip(gInstance, gToolWindow, ID_TRAYICON, szMsg, szTitle, 5000, 0); 58 if (RT_FAILURE(rc)) 59 Log(("VBoxTray: Guest Additions update found; however: could not show version notifier balloon tooltip! rc = %d\n", rc)); 60 } 40 61 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); 46 47 rc = showBalloonTip(gInstance, gToolWindow, ID_TRAYICON, szMsg, szTitle, 5000, 0); 48 if (RT_FAILURE(rc)) 49 Log(("VBoxTray: Could not show version notifier balloon tooltip! rc = %d\n", rc)); 50 51 VbglR3GuestPropReadValueFree(pszHostVersion); 52 VbglR3GuestPropReadValueFree(pszGuestVersion); 62 /* Store host version to not notify again */ 63 rc = VbglR3HostVersionLastCheckedStore(uGuestPropSvcClientID, pszHostVersion); 64 65 VbglR3GuestPropReadValueFree(pszHostVersion); 66 VbglR3GuestPropReadValueFree(pszGuestVersion); 67 } 68 VbglR3GuestPropDisconnect(uGuestPropSvcClientID); 53 69 } 54 55 /* If we didn't have to check for the host version then this is not an error */56 if (rc == VERR_NOT_SUPPORTED)57 rc = VINF_SUCCESS;58 70 return rc; 59 71 } -
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibHostVersion.cpp
- Property svn:executable deleted
-
Property svn:keywords
set to
Author Date Id Revision
r23857 r23876 37 37 38 38 /** Compares two VirtualBox version strings and returns the result. 39 * Requires strings in form of "majorVer.minorVer.build" 39 * Requires strings in form of "majorVer.minorVer.build". 40 40 * 41 41 * @returns 0 if equal, 1 if Ver1 is greater, 2 if Ver2 is greater. … … 64 64 65 65 66 /** @todo Docs */ 67 VBGLR3DECL(bool) VbglR3HostVersionCheckForUpdate(char **ppszHostVersion, char **ppszGuestVersion) 66 /** Checks for a Guest Additions update by comparing the installed version on 67 * the guest and the reported host version. 68 * 69 * @returns VBox status code 70 * 71 * @param u32ClientId The client id returned by VbglR3InfoSvcConnect(). 72 * @param bUpdate Receives pointer to boolean flag indicating whether 73 an update was found or not. 74 * @param ppszHostVersion Receives pointer of allocated version string. 75 * The returned pointer must be freed using RTStrFree(). 76 * @param ppszGuestVersion Receives pointer of allocated revision string. 77 * The returned pointer must be freed using RTStrFree(). 78 */ 79 VBGLR3DECL(int) VbglR3HostVersionCheckForUpdate(uint32_t u32ClientId, bool *bUpdate, char **ppszHostVersion, char **ppszGuestVersion) 68 80 { 69 81 int rc; 70 uint32_t uGuestPropSvcClientID; 71 72 rc = VbglR3GuestPropConnect(&uGuestPropSvcClientID); 73 if (RT_SUCCESS(rc)) 74 LogFlow(("Property Service Client ID: %ld\n", uGuestPropSvcClientID)); 75 else 76 LogFlow(("Failed to connect to the guest property service! Error: %d\n", rc)); 82 83 Assert(u32ClientId > 0); 84 Assert(bUpdate); 85 Assert(ppszHostVersion); 86 Assert(ppszGuestVersion); 87 88 /* We assume we have an update initially. 89 Every block down below is allowed to veto */ 90 *bUpdate = true; 77 91 78 92 /* Do we need to do all this stuff? */ 79 93 char *pszCheckHostVersion; 80 rc = VbglR3GuestPropReadValueAlloc(u GuestPropSvcClientID, "/VirtualBox/GuestAdd/CheckHostVersion", &pszCheckHostVersion);94 rc = VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/CheckHostVersion", &pszCheckHostVersion); 81 95 if (RT_FAILURE(rc)) 82 96 { … … 92 106 && strlen(pszCheckHostVersion)) 93 107 { 94 rc = VERR_NOT_SUPPORTED; 108 LogRel(("No host version update check performed (disabled).")); 109 *bUpdate = false; 95 110 } 96 111 VbglR3GuestPropReadValueFree(pszCheckHostVersion); 97 } 98 if (rc == VERR_NOT_SUPPORTED) 99 LogRel(("No host version check performed (disabled)."));100 101 if (RT_SUCCESS(rc) )102 { 103 /* Look up host version (revision)*/104 rc = VbglR3GuestPropReadValueAlloc(u GuestPropSvcClientID, "/VirtualBox/HostInfo/VBoxVer", ppszHostVersion);112 } 113 114 /* Make sure we only notify the user once by comparing the host version with 115 * the last checked host version (if any) */ 116 if (RT_SUCCESS(rc) && *bUpdate) 117 { 118 /* Look up host version */ 119 rc = VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/HostInfo/VBoxVer", ppszHostVersion); 105 120 if (RT_FAILURE(rc)) 106 121 { … … 111 126 LogFlow(("Host version: %s\n", *ppszHostVersion)); 112 127 113 /* Look up guest version */ 114 rc = VbglR3GetAdditionsVersion(ppszGuestVersion, NULL /* Revision */); 128 /* Get last checked host version */ 129 char *pszLastCheckedHostVersion; 130 rc = VbglR3HostVersionLastCheckedLoad(u32ClientId, &pszLastCheckedHostVersion); 115 131 if (RT_SUCCESS(rc)) 116 132 { 117 LogFlow(("Additions version: %s\n", *ppszGuestVersion)); 118 119 /* Look up last informed host version */ 120 char szVBoxHostVerLastChecked[32]; 121 #ifdef RT_OS_WINDOWS 122 HKEY hKey; 123 LONG lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey); 124 if (lRet == ERROR_SUCCESS) 125 { 126 DWORD dwType; 127 DWORD dwSize = sizeof(szVBoxHostVerLastChecked); 128 lRet = RegQueryValueEx(hKey, "HostVerLastChecked", NULL, &dwType, (BYTE*)szVBoxHostVerLastChecked, &dwSize); 129 if (lRet != ERROR_SUCCESS && lRet != ERROR_FILE_NOT_FOUND) 130 LogFlow(("Could not read HostVerLastChecked! Error = %ld\n", lRet)); 131 RegCloseKey(hKey); 132 } 133 else if (lRet != ERROR_FILE_NOT_FOUND) 134 { 135 LogFlow(("Could not open registry key! Error = %ld\n", lRet)); 136 rc = RTErrConvertFromWin32(lRet); 137 } 138 #else 139 140 #endif 141 /* Compare both versions and prepare message */ 142 if ( RT_SUCCESS(rc) 143 && strcmp(*ppszHostVersion, szVBoxHostVerLastChecked) != 0 /* Make sure we did not process this host version already */ 144 && VbglR3HostVersionCompare(*ppszHostVersion, *ppszGuestVersion) == 1) /* Is host version greater than guest add version? */ 145 { 146 LogFlow(("Update found.")); 147 } 148 else rc = VERR_VERSION_MISMATCH; /* No update found */ 133 LogFlow(("Last checked host version: %s\n", pszLastCheckedHostVersion)); 134 if (strcmp(*ppszHostVersion, pszLastCheckedHostVersion) == 0) 135 *bUpdate = false; /* We already notified this version, skip */ 136 VbglR3GuestPropReadValueFree(pszLastCheckedHostVersion); 149 137 } 150 } 151 } 152 138 else if (rc == VERR_NOT_FOUND) /* Never wrote a last checked host version before */ 139 { 140 LogFlow(("Never checked a host version before.")); 141 rc = VINF_SUCCESS; 142 } 143 } 144 145 if (RT_SUCCESS(rc)) 146 { 147 /* Look up guest version */ 148 rc = VbglR3GetAdditionsVersion(ppszGuestVersion, NULL /* Revision not needed here */); 149 } 150 } 151 152 /* Do the actual version comparison (if needed, see block(s) above) */ 153 if (RT_SUCCESS(rc) && *bUpdate) 154 { 155 if (VbglR3HostVersionCompare(*ppszHostVersion, *ppszGuestVersion) == 1) /* Is host version greater than guest add version? */ 156 { 157 /* Yay, we have an update! */ 158 LogRel(("Guest Additions update found! Please upgrade this machine to the latest Guest Additions.")); 159 } 160 else 161 { 162 /* How sad ... */ 163 *bUpdate = false; 164 } 165 } 166 167 /* Cleanup on failure */ 153 168 if (RT_FAILURE(rc)) 154 169 { 155 if (*ppszHostVersion) 156 VbglR3GuestPropReadValueFree(*ppszHostVersion); 157 if (*ppszGuestVersion) 158 VbglR3GuestPropReadValueFree(*ppszGuestVersion); 159 } 160 return rc == VINF_SUCCESS ? true : false; 161 } 162 163 164 /** @todo Docs */ 165 VBGLR3DECL(int) VbglR3HostVersionStore(const char* pszVer) 166 { 167 int rc; 168 uint32_t uGuestPropSvcClientID; 169 170 rc = VbglR3GuestPropConnect(&uGuestPropSvcClientID); 171 if (RT_FAILURE(rc)) 172 { 173 LogFlow(("Failed to connect to the guest property service! Error: %d\n", rc)); 174 } 175 else 176 { 177 #ifdef RT_OS_WINDOWS 178 HKEY hKey; 179 long lRet; 180 lRet = RegCreateKeyEx (HKEY_LOCAL_MACHINE, 181 "SOFTWARE\\Sun\\VirtualBox Guest Additions", 182 0, /* Reserved */ 183 NULL, /* lpClass [in, optional] */ 184 0, /* dwOptions [in] */ 185 KEY_WRITE, 186 NULL, /* lpSecurityAttributes [in, optional] */ 187 &hKey, 188 NULL); /* lpdwDisposition [out, optional] */ 189 if (lRet == ERROR_SUCCESS) 190 { 191 lRet = RegSetValueEx(hKey, "HostVerLastChecked", 0, REG_SZ, (BYTE*)pszVer, (DWORD)(strlen(pszVer)*sizeof(char))); 192 if (lRet != ERROR_SUCCESS) 193 LogFlow(("Could not write HostVerLastChecked! Error = %ld\n", lRet)); 194 RegCloseKey(hKey); 195 } 196 else 197 LogFlow(("Could not open registry key! Error = %ld\n", lRet)); 198 199 if (lRet != ERROR_SUCCESS) 200 rc = RTErrConvertFromWin32(lRet); 201 #else 202 #endif 170 VbglR3GuestPropReadValueFree(*ppszHostVersion); 171 VbglR3GuestPropReadValueFree(*ppszGuestVersion); 203 172 } 204 173 return rc; 205 174 } 175 176 177 /** Retrieves the last checked host version. 178 * 179 * @returns VBox status code. 180 * 181 * @param u32ClientId The client id returned by VbglR3InfoSvcConnect(). 182 * @param ppszVer Receives pointer of allocated version string. 183 * The returned pointer must be freed using RTStrFree() on VINF_SUCCESS. 184 */ 185 VBGLR3DECL(int) VbglR3HostVersionLastCheckedLoad(uint32_t u32ClientId, char **ppszVer) 186 { 187 Assert(u32ClientId > 0); 188 Assert(ppszVer); 189 return VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/HostVerLastChecked", ppszVer); 190 } 191 192 193 /** Stores the last checked host version for later lookup. 194 * Requires strings in form of "majorVer.minorVer.build". 195 * 196 * @returns VBox status code. 197 * 198 * @param u32ClientId The client id returned by VbglR3InfoSvcConnect(). 199 * @param pszVer Pointer to version string to store. 200 */ 201 VBGLR3DECL(int) VbglR3HostVersionLastCheckedStore(uint32_t u32ClientId, const char *pszVer) 202 { 203 Assert(u32ClientId > 0); 204 Assert(pszVer); 205 return VbglR3GuestPropWriteValue(u32ClientId, "/VirtualBox/GuestAdd/HostVerLastChecked", pszVer); 206 } -
trunk/src/VBox/Additions/x11/VBoxClient/hostversion.cpp
r23859 r23876 111 111 } 112 112 113 /** @todo Move this part in VbglR3 and just provide a callback for the platform-specific 114 notification stuff, since this is very similar to the VBoxTray code. */ 113 115 virtual int run() 114 116 { … … 124 126 rc = VERR_NOT_IMPLEMENTED; 125 127 #endif 128 uint32_t uGuestPropSvcClientID; 129 rc = VbglR3GuestPropConnect(&uGuestPropSvcClientID); 126 130 if (RT_SUCCESS(rc)) 127 131 { 128 int rc;129 char *pszHostVersion;130 char *pszGuestVersion;131 rc = VbglR3HostVersionCheckForUpdate(&pszHostVersion, &pszGuestVersion);132 132 if (RT_SUCCESS(rc)) 133 133 { 134 char szMsg[256]; 135 char szTitle[64]; 134 char *pszHostVersion; 135 char *pszGuestVersion; 136 bool bUpdate; 136 137 137 /** @todo add some translation macros here */ 138 RTStrPrintf(szTitle, sizeof(szTitle), "VirtualBox Guest Additions update available!"); 139 RTStrPrintf(szMsg, sizeof(szMsg), "Your guest is currently running the Guest Additions version %s. " 140 "We recommend updating to the latest version (%s) by choosing the " 141 "install option from the Devices menu.", pszGuestVersion, pszHostVersion); 142 rc = showNotify(szTitle, szMsg); 143 if (RT_FAILURE(rc)) 144 Log(("VBoxClient: Could not show version notifier tooltip! rc = %d\n", rc)); 138 rc = VbglR3HostVersionCheckForUpdate(uGuestPropSvcClientID, &bUpdate, &pszHostVersion, &pszGuestVersion); 139 if (RT_SUCCESS(rc)) 140 { 141 if (bUpdate) 142 { 143 char szMsg[256]; 144 char szTitle[64]; 145 146 /** @todo add some translation macros here */ 147 RTStrPrintf(szTitle, sizeof(szTitle), "VirtualBox Guest Additions update available!"); 148 RTStrPrintf(szMsg, sizeof(szMsg), "Your guest is currently running the Guest Additions version %s. " 149 "We recommend updating to the latest version (%s) by choosing the " 150 "install option from the Devices menu.", pszGuestVersion, pszHostVersion); 151 rc = showNotify(szTitle, szMsg); 152 if (RT_FAILURE(rc)) 153 Log(("VBoxClient: Could not show version notifier tooltip! rc = %d\n", rc)); 154 } 145 155 146 VbglR3GuestPropReadValueFree(pszHostVersion); 147 VbglR3GuestPropReadValueFree(pszGuestVersion); 156 /* Store host version to not notify again */ 157 rc = VbglR3HostVersionLastCheckedStore(uGuestPropSvcClientID, pszHostVersion); 158 159 VbglR3GuestPropReadValueFree(pszHostVersion); 160 VbglR3GuestPropReadValueFree(pszGuestVersion); 161 } 148 162 } 149 150 /* If we didn't have to check for the host version then this is not an error */ 151 if (rc == VERR_NOT_SUPPORTED) 152 rc = VINF_SUCCESS; 163 VbglR3GuestPropDisconnect(uGuestPropSvcClientID); 153 164 } 154 165 LogFlowFunc(("returning %Rrc\n", rc));
Note:
See TracChangeset
for help on using the changeset viewer.