Changeset 24331 in vbox for trunk/src/VBox
- Timestamp:
- Nov 4, 2009 1:59:31 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibHostVersion.cpp
r24306 r24331 36 36 #include "VBGLR3Internal.h" 37 37 38 /** Compares two VirtualBox version strings and returns the result. 39 * Requires strings in form of "majorVer.minorVer.build". 38 /** 39 * Compares two VirtualBox version strings and returns the result. 40 * 41 * Requires strings in form of "majorVer.minorVer.build". 40 42 * 41 43 * @returns 0 if equal, 1 if Ver1 is greater, 2 if Ver2 is greater. … … 44 46 * @param pszVer2 First version string to compare. 45 47 * 48 * @todo Move this to IPRT and add support for more dots, suffixes and whatnot. 46 49 */ 47 50 VBGLR3DECL(int) VbglR3HostVersionCompare(const char *pszVer1, const char *pszVer2) 48 51 { 49 int rc = 0;50 52 int iVer1Major, iVer1Minor, iVer1Build; 51 53 sscanf(pszVer1, "%d.%d.%d", &iVer1Major, &iVer1Minor, &iVer1Build); … … 56 58 int iVer2Final = (iVer2Major * 10000) + (iVer2Minor * 100) + iVer2Build; 57 59 60 int rc = 0; 58 61 if (iVer1Final > iVer2Final) 59 62 rc = 1; … … 64 67 65 68 66 /** Checks for a Guest Additions update by comparing the installed version on 67 * the guest and the reported host version. 69 /** 70 * Checks for a Guest Additions update by comparing the installed version on the 71 * guest and the reported host version. 68 72 * 69 73 * @returns VBox status code 70 74 * 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) 80 { 81 int rc; 82 75 * @param u32ClientId The client id returned by 76 * VbglR3InfoSvcConnect(). 77 * @param pfUpdate Receives pointer to boolean flag indicating 78 * whether an update was found or not. 79 * @param ppszHostVersion Receives pointer of allocated version string. 80 * The returned pointer must be freed using 81 * RTStrFree(). 82 * @param ppszGuestVersion Receives pointer of allocated revision string. 83 * The returned pointer must be freed using 84 * RTStrFree(). Always set to zero. 85 */ 86 VBGLR3DECL(int) VbglR3HostVersionCheckForUpdate(uint32_t u32ClientId, bool *pfUpdate, char **ppszHostVersion, char **ppszGuestVersion) 87 { 83 88 Assert(u32ClientId > 0); 84 89 Assert(bUpdate); … … 91 96 /* We assume we have an update initially. 92 97 Every block down below is allowed to veto */ 93 * bUpdate = true;98 *pfUpdate = true; 94 99 95 100 /* Do we need to do all this stuff? */ 96 101 char *pszCheckHostVersion; 97 rc = VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/CheckHostVersion", &pszCheckHostVersion);102 int rc = VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/CheckHostVersion", &pszCheckHostVersion); 98 103 if (RT_FAILURE(rc)) 99 104 { … … 101 106 rc = VINF_SUCCESS; /* If we don't find the value above we do the check by default */ 102 107 else 103 LogFlow(("Could not read check host version flag! rc = % d\n", rc));108 LogFlow(("Could not read check host version flag! rc = %Rrc\n", rc)); 104 109 } 105 110 else 106 111 { 107 112 /* Only don't do the check if we have a valid "0" in it */ 108 if ( atoi(pszCheckHostVersion) == 0109 && strlen(pszCheckHostVersion))113 if ( *pszCheckHostVersion 114 && atoi(pszCheckHostVersion) == 0) /** @todo r=bird: don't use atoi, use RTStrToXX. avoid std*.h! */ 110 115 { 111 116 LogRel(("No host version update check performed (disabled).")); 112 * bUpdate = false;117 *pfUpdate = false; 113 118 } 114 119 VbglR3GuestPropReadValueFree(pszCheckHostVersion); … … 118 123 /* Make sure we only notify the user once by comparing the host version with 119 124 * the last checked host version (if any) */ 120 if (RT_SUCCESS(rc) && * bUpdate)125 if (RT_SUCCESS(rc) && *pfUpdate) 121 126 { 122 127 /* Look up host version */ … … 124 129 if (RT_FAILURE(rc)) 125 130 { 126 LogFlow(("Could not read VBox host version! rc = % d\n", rc));131 LogFlow(("Could not read VBox host version! rc = %Rrc\n", rc)); 127 132 } 128 133 else … … 137 142 LogFlow(("Last checked host version: %s\n", pszLastCheckedHostVersion)); 138 143 if (strcmp(*ppszHostVersion, pszLastCheckedHostVersion) == 0) 139 * bUpdate = false; /* We already notified this version, skip */144 *pfUpdate = false; /* We already notified this version, skip */ 140 145 VbglR3GuestPropReadValueFree(pszLastCheckedHostVersion); 141 146 } … … 152 157 rc = VbglR3GetAdditionsVersion(ppszGuestVersion, NULL /* Revision not needed here */); 153 158 if (RT_FAILURE(rc)) 154 LogFlow(("Could not read VBox guest version! rc = % d\n", rc));159 LogFlow(("Could not read VBox guest version! rc = %Rrc\n", rc)); 155 160 } 156 161 } 157 162 158 163 /* Do the actual version comparison (if needed, see block(s) above) */ 159 if (RT_SUCCESS(rc) && * bUpdate)164 if (RT_SUCCESS(rc) && *pfUpdate) 160 165 { 161 166 if (VbglR3HostVersionCompare(*ppszHostVersion, *ppszGuestVersion) == 1) /* Is host version greater than guest add version? */ … … 167 172 { 168 173 /* How sad ... */ 169 * bUpdate = false;174 *pfUpdate = false; 170 175 } 171 176 } … … 175 180 { 176 181 if (*ppszHostVersion) 182 { 177 183 VbglR3GuestPropReadValueFree(*ppszHostVersion); 184 *ppszHostVersion = NULL; 185 } 178 186 if (*ppszGuestVersion) 187 { 179 188 VbglR3GuestPropReadValueFree(*ppszGuestVersion); 189 *ppszGuestVersion = NULL; 190 } 180 191 } 181 192 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.