VBoxHostVersion.cpp revision 412dfa8e1e3cd467ac99730ccee92326982d7eb8
/* $Id$ */
/** @file
* VBoxHostVersion - Checks the host's VirtualBox version and notifies
* the user in case of an update.
*/
/*
* 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.
*/
#include "VBoxHostVersion.h"
#include "VBoxTray.h"
#include "helpers.h"
#include <VBox/VBoxGuestLib.h>
/* Returns 0 if equal, 1 if Ver1 is greater, 2 if Ver2 is greater
* Requires strings in form of "majorVer.minorVer.build" */
/** @todo should be common code in the guest lib / headers */
{
int rc = 0;
if (iVer1Final > iVer2Final)
rc = 1;
else if (iVer2Final > iVer1Final)
rc = 2;
return rc;
}
int VBoxCheckHostVersion ()
{
int rc;
if (RT_SUCCESS(rc))
else
if (RT_SUCCESS(rc))
{
/* Look up host version (revision) */
char *pszVBoxHostVer;
rc = VbglR3GuestPropReadValueAlloc(uGuestPropSvcClientID, "/VirtualBox/HostInfo/VBoxVer", &pszVBoxHostVer);
if (RT_FAILURE(rc))
if (RT_SUCCESS(rc))
{
/* Look up guest version */
char szVBoxGuestVer[32];
char szVBoxGuestRev[32];
rc = getAdditionsVersion(szVBoxGuestVer, sizeof(szVBoxGuestVer), szVBoxGuestRev, sizeof(szVBoxGuestRev));
if (RT_SUCCESS(rc))
{
/* Look up last informed host version */
char szVBoxHostVerLastChecked[32];
LONG lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions\\VBoxTray", 0, KEY_READ, &hKey);
if (lRet == ERROR_SUCCESS)
{
lRet = RegQueryValueEx(hKey, "HostVerLastChecked", NULL, &dwType, (BYTE*)szVBoxHostVerLastChecked, &dwSize);
}
else if (lRet != ERROR_FILE_NOT_FOUND)
{
}
/** @todo implement a special value of last informed host version (or a new flag) to disable this service. */
/* Compare both versions and prepare message */
if ( RT_SUCCESS(rc)
&& strcmp(pszVBoxHostVer, szVBoxHostVerLastChecked) != 0 /* Make sure we did not process this host version already */
&& VBoxCompareVersion(pszVBoxHostVer, szVBoxGuestVer) == 1) /* Is host version greater than guest add version? */
{
/** @todo add some translation macros here */
"We recommend updating to the latest version (%s) by choosing the "
/* Save the version to just do a balloon once per new version */
if (RT_SUCCESS(rc))
{
"SOFTWARE\\Sun\\VirtualBox Guest Additions\\VBoxTray",
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*)pszVBoxHostVer, strlen(pszVBoxHostVer)*sizeof(char));
if (lRet != ERROR_SUCCESS)
}
else
if (lRet != ERROR_SUCCESS)
}
}
}
}
}
{
if (RT_FAILURE(rc))
}
return rc;
}