VBoxGuestR3LibHostVersion.cpp revision 5bb7b06e9e2186e1f51700e01cfd58f2b5f70937
/* $Id: */
/** @file
* VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, host version check.
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#ifdef RT_OS_WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include "VBGLR3Internal.h"
/** Compares two VirtualBox version strings and returns the result.
* Requires strings in form of "majorVer.minorVer.build"
*
* @returns 0 if equal, 1 if Ver1 is greater, 2 if Ver2 is greater.
*
* @param pszVer1 First version string to compare.
* @param pszVer2 First version string to compare.
*
*/
{
int rc = 0;
if (iVer1Final > iVer2Final)
rc = 1;
else if (iVer2Final > iVer1Final)
rc = 2;
return rc;
}
/** @todo Docs */
{
int rc;
if (RT_SUCCESS(rc))
else
/* Do we need to do all this stuff? */
char *pszCheckHostVersion;
rc = VbglR3GuestPropReadValueAlloc(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/CheckHostVersion", &pszCheckHostVersion);
if (RT_FAILURE(rc))
{
if (rc == VERR_NOT_FOUND)
else
}
else
{
/* Only don't do the check if we have a valid "0" in it */
if ( atoi(pszCheckHostVersion) == 0
{
}
}
if (rc == VERR_NOT_SUPPORTED)
LogRel(("No host version check performed (disabled)."));
if (RT_SUCCESS(rc))
{
/* Look up host version (revision) */
rc = VbglR3GuestPropReadValueAlloc(uGuestPropSvcClientID, "/VirtualBox/HostInfo/VBoxVer", ppszHostVersion);
if (RT_FAILURE(rc))
{
}
else
{
/* Look up guest version */
if (RT_SUCCESS(rc))
{
/* Look up last informed host version */
char szVBoxHostVerLastChecked[32];
#ifdef RT_OS_WINDOWS
LONG lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey);
if (lRet == ERROR_SUCCESS)
{
lRet = RegQueryValueEx(hKey, "HostVerLastChecked", NULL, &dwType, (BYTE*)szVBoxHostVerLastChecked, &dwSize);
}
else if (lRet != ERROR_FILE_NOT_FOUND)
{
}
#else
#endif
/* Compare both versions and prepare message */
if ( RT_SUCCESS(rc)
&& strcmp(*ppszHostVersion, szVBoxHostVerLastChecked) != 0 /* Make sure we did not process this host version already */
&& VbglR3HostVersionCompare(*ppszHostVersion, *ppszGuestVersion) == 1) /* Is host version greater than guest add version? */
{
LogFlow(("Update found."));
}
}
}
}
if (RT_FAILURE(rc))
{
if (*ppszHostVersion)
if (*ppszGuestVersion)
}
return rc == VINF_SUCCESS ? true : false;
}
/** @todo Docs */
{
int rc;
if (RT_FAILURE(rc))
{
}
else
{
#ifdef RT_OS_WINDOWS
long lRet;
"SOFTWARE\\Sun\\VirtualBox Guest Additions",
0, /* Reserved */
NULL, /* lpClass [in, optional] */
0, /* dwOptions [in] */
NULL, /* lpSecurityAttributes [in, optional] */
&hKey,
NULL); /* lpdwDisposition [out, optional] */
if (lRet == ERROR_SUCCESS)
{
lRet = RegSetValueEx(hKey, "HostVerLastChecked", 0, REG_SZ, (BYTE*)pszVer, (DWORD)(strlen(pszVer)*sizeof(char)));
if (lRet != ERROR_SUCCESS)
}
else
if (lRet != ERROR_SUCCESS)
#else
#endif
}
return rc;
}