VirtualBox

Changeset 106869 in vbox for trunk/src


Ignore:
Timestamp:
Nov 7, 2024 9:40:41 AM (3 weeks ago)
Author:
vboxsync
Message:

Windows driver installation: Renamed VBoxWinDrvInfQueryModelsSectionName() -> VBoxWinDrvInfQueryModel(), implemented better detection of driver models which have an extended decoration. Added VBoxWinDrvInfQueryInstallSection[Ex](). bugref:10762

Location:
trunk/src/VBox/GuestHost/installation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/installation/VBoxWinDrvCommon.cpp

    r106839 r106869  
    3737#include <iprt/assert.h>
    3838#include <iprt/dir.h>
    39 #include <iprt/errcore.h>
    4039#include <iprt/ldr.h>
    4140#include <iprt/list.h>
     
    4746#include <iprt/utf16.h>
    4847
    49 #ifdef DEBUG
    50 # include <iprt/stream.h>
    51 #endif
     48#include <VBox/err.h> /* For VERR_PLATFORM_ARCH_NOT_SUPPORTED.*/
    5249
    5350#include "VBoxWinDrvCommon.h"
     
    136133
    137134/**
    138  * Queries for the model name in an INF file.
     135 * Queries a model name from an INF file.
    139136 *
    140137 * @returns VBox status code.
    141138 * @retval  VERR_NOT_FOUND if no model has been found.
    142139 * @param   hInf                INF handle to use.
     140 * @param   uIndex              Index of model to query.
     141 *                              Currently only the first model (index 0) is supported.
    143142 * @param   ppwszValue          Where to return the model name on success.
    144143 * @param   pcwcValue           Where to return the number of characters for \a ppwszValue. Optional an can be NULL.
     
    146145 * @note    Only for non-"primitive" drivers.
    147146 */
    148 int VBoxWinDrvInfQueryModelsSectionName(HINF hInf, PRTUTF16 *ppwszValue, PDWORD pcwcValue)
    149 {
     147int VBoxWinDrvInfQueryModel(HINF hInf, unsigned uIndex, PRTUTF16 *ppwszValue, PDWORD pcwcValue)
     148{
     149    AssertReturn(uIndex == 0, VERR_INVALID_PARAMETER);
     150
    150151    *ppwszValue = NULL;
    151152    if (pcwcValue)
     
    176177        return rc;
    177178
    178     LPWSTR pwszModels;
    179     DWORD  cwcModels;
    180     rc = VBoxWinDrvInfQueryKeyValue(&InfCtx, 1, &pwszModels, &cwcModels);
     179    PRTUTF16 pwszModel;
     180    DWORD    cwcModels;
     181    rc = VBoxWinDrvInfQueryKeyValue(&InfCtx, 1, &pwszModel, &cwcModels);
    181182    if (RT_FAILURE(rc))
    182183        return rc;
    183184
    184     LPWSTR pwszPlatform = NULL;
    185     DWORD  cwcPlatform  = 0;
    186     bool   fArch        = false;
    187     bool   fNt          = false;
    188 
    189     LPWSTR pwszPlatformCur;
    190     DWORD  cwcPlatformCur;
    191     for (DWORD i = 2; (rc = VBoxWinDrvInfQueryKeyValue(&InfCtx, i, &pwszPlatformCur, &cwcPlatformCur)) == VINF_SUCCESS; ++i)
    192     {
    193         if (RTUtf16ICmpAscii(pwszPlatformCur, "NT" VBOXWINDRVINF_NATIVE_ARCH_STR) == 0)
    194             fArch = true;
    195         else
     185    PRTUTF16 pwszResult = NULL;
     186    DWORD    cwcResult  = 0;
     187
     188    PRTUTF16 pwszPlatform = NULL;
     189    DWORD    cwcPlatform;
     190    rc = VBoxWinDrvInfQueryKeyValue(&InfCtx, 2, &pwszPlatform, &cwcPlatform);
     191    if (RT_SUCCESS(rc)) /* Platform is optional. */
     192    {
     193        /* Note! The platform can be more specific, e.g. "NTAMD64.6.0". */
     194        if (RTUtf16FindAscii(pwszPlatform, VBOXWINDRVINF_NT_NATIVE_ARCH_STR) == 0)
    196195        {
    197             if (   fNt
    198                 || RTUtf16ICmpAscii(pwszPlatformCur, "NT") != 0)
     196            RTUTF16 wszSection[VBOXWINDRVINF_MAX_INF_SECTION_NAME];
     197            rc = RTUtf16Copy(wszSection, sizeof(wszSection), pwszModel);
     198            if (RT_SUCCESS(rc))
    199199            {
    200                 RTMemFree(pwszPlatformCur);
    201                 pwszPlatformCur = NULL;
    202                 continue;
     200                rc = RTUtf16Cat(wszSection, sizeof(wszSection), VBOXWINDRVINF_DECORATION_SEP_UTF16_STR);
     201                if (RT_SUCCESS(rc))
     202                {
     203                    rc = RTUtf16Cat(wszSection, sizeof(wszSection), pwszPlatform);
     204                    if (RT_SUCCESS(rc))
     205                    {
     206                        pwszResult = RTUtf16Dup(wszSection);
     207                        if (pwszResult)
     208                        {
     209                            cwcResult = (DWORD)RTUtf16Len(wszSection);
     210                        }
     211                        else
     212                            rc = VERR_NO_MEMORY;
     213                    }
     214                }
    203215            }
    204             fNt = true;
    205         }
    206 
    207         cwcPlatform = cwcPlatformCur;
    208         if (pwszPlatform)
    209             RTMemFree(pwszPlatform);
    210         pwszPlatform = pwszPlatformCur;
    211         pwszPlatformCur = NULL;
    212     }
    213 
    214     rc = VINF_SUCCESS;
    215 
    216     LPWSTR pwszResult = NULL;
    217     DWORD  cwcResult = 0;
    218     if (pwszPlatform)
    219     {
    220         pwszResult = (LPWSTR)RTMemAlloc((cwcModels + cwcPlatform) * sizeof(pwszResult[0]));
    221         if (pwszResult)
    222         {
    223             memcpy(pwszResult, pwszModels, (cwcModels - 1) * sizeof(pwszResult[0]));
    224             pwszResult[cwcModels - 1] = L'.';
    225             memcpy(&pwszResult[cwcModels], pwszPlatform, cwcPlatform * sizeof(pwszResult[0]));
    226             cwcResult = cwcModels + cwcPlatform;
    227216        }
    228217        else
    229             rc = VERR_NO_MEMORY;
    230     }
    231     else
    232     {
    233         pwszResult = pwszModels;
     218            rc = VERR_PLATFORM_ARCH_NOT_SUPPORTED;
     219    }
     220    else /* Model w/o platform. */
     221    {
     222        pwszResult = pwszModel;
    234223        cwcResult  = cwcModels;
    235         pwszModels = NULL;
    236     }
    237 
    238     if (pwszModels)
    239         RTMemFree(pwszModels);
    240     if (pwszPlatform)
    241         RTMemFree(pwszPlatform);
     224        pwszModel  = NULL;
     225
     226        rc = VINF_SUCCESS;
     227    }
     228
     229    RTMemFree(pwszModel);
     230    RTMemFree(pwszPlatform);
    242231
    243232    if (RT_SUCCESS(rc))
     
    249238
    250239    return rc;
     240}
     241
     242int VBoxWinDrvInfQueryInstallSectionEx(HINF hInf, PCRTUTF16 pwszModel, PRTUTF16 *ppwszValue, PDWORD pcwcValue)
     243{
     244    INFCONTEXT InfCtx;
     245    int rc = VBoxWinDrvInfQueryContext(hInf, pwszModel, NULL, &InfCtx);
     246    if (RT_FAILURE(rc))
     247        return rc;
     248
     249    return VBoxWinDrvInfQueryKeyValue(&InfCtx, 1, ppwszValue, pcwcValue);
     250}
     251
     252int VBoxWinDrvInfQueryInstallSection(HINF hInf, PCRTUTF16 pwszModel, PRTUTF16 *ppwszValue)
     253{
     254    return VBoxWinDrvInfQueryInstallSectionEx(hInf, pwszModel, ppwszValue, NULL);
    251255}
    252256
     
    430434    *ppwszModel = NULL;
    431435
    432     return VBoxWinDrvInfQueryModelsSectionName(hInf, ppwszModel, NULL);
     436    return VBoxWinDrvInfQueryModel(hInf, 0 /* Index */, ppwszModel, NULL);
    433437}
    434438
  • trunk/src/VBox/GuestHost/installation/VBoxWinDrvCommon.h

    r106397 r106869  
    4646int VBoxWinDrvInfQueryFirstPnPId(HINF hInf, PRTUTF16 pwszModel, PRTUTF16 *ppwszPnPId);
    4747int VBoxWinDrvInfQueryKeyValue(PINFCONTEXT pCtx, DWORD iValue, PRTUTF16 *ppwszValue, PDWORD pcwcValue);
    48 int VBoxWinDrvInfQueryModelsSectionName(HINF hInf, PRTUTF16 *ppwszValue, PDWORD pcwcValue);
     48int VBoxWinDrvInfQueryModel(HINF hInf, PRTUTF16 *ppwszValue, PDWORD pcwcValue);
     49int VBoxWinDrvInfQueryInstallSectionEx(HINF hInf, PCRTUTF16 pwszModel, PRTUTF16 *ppwszValue, PDWORD pcwcValue);
     50int VBoxWinDrvInfQueryInstallSection(HINF hInf, PCRTUTF16 pwszModel, PRTUTF16 *ppwszValue);
    4951int VBoxWinDrvInfQuerySectionVerEx(HINF hInf, UINT uIndex, PVBOXWINDRVINFSEC_VERSION pVer);
    5052int VBoxWinDrvInfQuerySectionVer(HINF hInf, PVBOXWINDRVINFSEC_VERSION pVer);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette