Re: [PATCH] vbox: Fix version extraction on Windows for newer VirtualBox versions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2011/6/4 Daniel Veillard <veillard@xxxxxxxxxx>:
> On Sat, Jun 04, 2011 at 10:53:06AM +0200, Matthias Bolte wrote:
>> VirtualBox 4.0.8 changed the registry key layout. Before the version
>> number was in a Version key. Now the Version key contains %VER% and
>> the actual version number is in VersionExt now.
>>
>> Move value lookup code into its own function: vboxLookupRegistryValue.
>> ---
>> Âsrc/vbox/vbox_MSCOMGlue.c | Â 87 +++++++++++++++++++++++++++++++--------------
>> Â1 files changed, 60 insertions(+), 27 deletions(-)
>>
>> diff --git a/src/vbox/vbox_MSCOMGlue.c b/src/vbox/vbox_MSCOMGlue.c
>> index e31a763..8aef266 100644
>> --- a/src/vbox/vbox_MSCOMGlue.c
>> +++ b/src/vbox/vbox_MSCOMGlue.c
>> @@ -2,7 +2,7 @@
>> Â/*
>> Â * vbox_MSCOMGlue.c: glue to the MSCOM based VirtualBox API
>> Â *
>> - * Copyright (C) 2010 Matthias Bolte <matthias.bolte@xxxxxxxxxxxxxx>
>> + * Copyright (C) 2010-2011 Matthias Bolte <matthias.bolte@xxxxxxxxxxxxxx>
>> Â *
>> Â * This library is free software; you can redistribute it and/or
>> Â * modify it under the terms of the GNU Lesser General Public
>> @@ -338,45 +338,31 @@ static nsIEventQueue vboxEventQueue = {
>>
>>
>>
>> -static int
>> -vboxLookupVersionInRegistry(void)
>> +static char *
>> +vboxLookupRegistryValue(HKEY key, const char *keyName, const char *valueName)
>> Â{
>> - Â Âint result = -1;
>> - Â Âconst char *keyName = VBOX_REGKEY_ORACLE;
>> Â Â ÂLONG status;
>> - Â ÂHKEY key;
>> Â Â ÂDWORD type;
>> Â Â ÂDWORD length;
>> Â Â Âchar *value = NULL;
>>
>> - Â Âstatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &key);
>> + Â Âstatus = RegQueryValueEx(key, valueName, NULL, &type, NULL, &length);
>>
>> Â Â Âif (status != ERROR_SUCCESS) {
>> - Â Â Â ÂkeyName = VBOX_REGKEY_SUN;
>> - Â Â Â Âstatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &key);
>> -
>> - Â Â Â Âif (status != ERROR_SUCCESS) {
>> - Â Â Â Â Â Â/* Both keys aren't there, or we cannot open them. In general this
>> - Â Â Â Â Â Â * indicates that VirtualBox is not installed, so we just silently
>> - Â Â Â Â Â Â * fail here making vboxRegister() register the dummy driver. */
>> - Â Â Â Â Â Âreturn -1;
>> - Â Â Â Â}
>> - Â Â}
>> -
>> - Â Âstatus = RegQueryValueEx(key, "Version", NULL, &type, NULL, &length);
>> -
>> - Â Âif (status != ERROR_SUCCESS) {
>> - Â Â Â ÂVIR_ERROR(_("Could not query registry value '%s\\Version'"), keyName);
>> + Â Â Â ÂVIR_ERROR(_("Could not query registry value '%s\\%s'"),
>> + Â Â Â Â Â Â Â Â ÂkeyName, valueName);
>> Â Â Â Â Âgoto cleanup;
>> Â Â Â}
>>
>> Â Â Âif (type != REG_SZ) {
>> - Â Â Â ÂVIR_ERROR(_("Registry value '%s\\Version' has unexpected type"), keyName);
>> + Â Â Â ÂVIR_ERROR(_("Registry value '%s\\%s' has unexpected type"),
>> + Â Â Â Â Â Â Â Â ÂkeyName, valueName);
>> Â Â Â Â Âgoto cleanup;
>> Â Â Â}
>>
>> Â Â Âif (length < 2) {
>> - Â Â Â ÂVIR_ERROR(_("Registry value '%s\\Version' is too short"), keyName);
>> + Â Â Â ÂVIR_ERROR(_("Registry value '%s\\%s' is too short"),
>> + Â Â Â Â Â Â Â Â ÂkeyName, valueName);
>> Â Â Â Â Âgoto cleanup;
>> Â Â Â}
>>
>> @@ -386,10 +372,12 @@ vboxLookupVersionInRegistry(void)
>> Â Â Â Â Âgoto cleanup;
>> Â Â Â}
>>
>> - Â Âstatus = RegQueryValueEx(key, "Version", NULL, NULL, (LPBYTE)value, &length);
>> + Â Âstatus = RegQueryValueEx(key, valueName, NULL, NULL, (LPBYTE)value, &length);
>>
>> Â Â Âif (status != ERROR_SUCCESS) {
>> - Â Â Â ÂVIR_ERROR(_("Could not query registry value '%s\\Version'"), keyName);
>> + Â Â Â ÂVIR_FREE(value);
>> + Â Â Â ÂVIR_ERROR(_("Could not query registry value '%s\\%s'"),
>> + Â Â Â Â Â Â Â Â ÂkeyName, valueName);
>> Â Â Â Â Âgoto cleanup;
>> Â Â Â}
>>
>> @@ -397,7 +385,52 @@ vboxLookupVersionInRegistry(void)
>> Â Â Â Â Âvalue[length] = '\0';
>> Â Â Â}
>>
>> - Â Âif (virParseVersionString(value, &vboxVersion)) {
>> + Âcleanup:
>> + Â Âreturn value;
>> +}
>> +
>> +static int
>> +vboxLookupVersionInRegistry(void)
>> +{
>> + Â Âint result = -1;
>> + Â Âconst char *keyName = VBOX_REGKEY_ORACLE;
>> + Â ÂLONG status;
>> + Â ÂHKEY key;
>> + Â Âchar *value = NULL;
>> +
>> + Â Âstatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &key);
>> +
>> + Â Âif (status != ERROR_SUCCESS) {
>> + Â Â Â ÂkeyName = VBOX_REGKEY_SUN;
>> + Â Â Â Âstatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &key);
>> +
>> + Â Â Â Âif (status != ERROR_SUCCESS) {
>> + Â Â Â Â Â Â/* Both keys aren't there, or we cannot open them. In general this
>> + Â Â Â Â Â Â * indicates that VirtualBox is not installed, so we just silently
>> + Â Â Â Â Â Â * fail here making vboxRegister() register the dummy driver. */
>> + Â Â Â Â Â Âreturn -1;
>> + Â Â Â Â}
>> + Â Â}
>> +
>> + Â Â/* The registry key layout changed around version 4.0.8. Before the version
>> + Â Â * number was in the Version key, now the Version key can contain %VER% and
>> + Â Â * the actual version number is in the VersionExt key then. */
>> + Â Âvalue = vboxLookupRegistryValue(key, keyName, "Version");
>> +
>> + Â Âif (value == NULL) {
>> + Â Â Â Âgoto cleanup;
>> + Â Â}
>> +
>> + Â Âif (STREQ(value, "%VER%")) {
>> + Â Â Â ÂVIR_FREE(value);
>> + Â Â Â Âvalue = vboxLookupRegistryValue(key, keyName, "VersionExt");
>> +
>> + Â Â Â Âif (value == NULL) {
>> + Â Â Â Â Â Âgoto cleanup;
>> + Â Â Â Â}
>> + Â Â}
>> +
>> + Â Âif (virParseVersionString(value, &vboxVersion) < 0) {
>> Â Â Â Â ÂVIR_ERROR(_("Could not parse version number from '%s'"), value);
>> Â Â Â Â Âgoto cleanup;
>> Â Â Â}
>
> ÂOkay, looks reasonable, ACK, please push for release :-)
>
> Daniel
>

Thanks, pushed.

Matthias

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]