VirtualBox

Changeset 79409 in vbox for trunk/src/VBox/HostDrivers


Ignore:
Timestamp:
Jun 28, 2019 11:45:54 AM (5 years ago)
Author:
vboxsync
Message:

VBoxNetAdpInstall.cpp: Use same fallback as the others.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpInstall.cpp

    r76553 r79409  
    2525 */
    2626
     27
     28/*********************************************************************************************************************************
     29*   Header Files                                                                                                                 *
     30*********************************************************************************************************************************/
    2731#include <VBox/VBoxNetCfg-win.h>
    2832#include <VBox/VBoxDrvCfg-win.h>
     
    3034#include <devguid.h>
    3135
     36
     37/*********************************************************************************************************************************
     38*   Defined Constants And Macros                                                                                                 *
     39*********************************************************************************************************************************/
    3240#define VBOX_NETADP_APP_NAME L"NetAdpInstall"
    3341
    3442#define VBOX_NETADP_HWID L"sun_VBoxNetAdp"
    3543#ifdef NDIS60
    36 #define VBOX_NETADP_INF L"VBoxNetAdp6.inf"
    37 #else /* !NDIS60 */
    38 #define VBOX_NETADP_INF L"VBoxNetAdp.inf"
    39 #endif /* !NDIS60 */
     44# define VBOX_NETADP_INF L"VBoxNetAdp6.inf"
     45#else
     46# define VBOX_NETADP_INF L"VBoxNetAdp.inf"
     47#endif
     48
    4049
    4150static VOID winNetCfgLogger(LPCSTR szString)
     
    4453}
    4554
     55
     56/** Wrapper around GetfullPathNameW that will try an alternative INF location.
     57 *
     58 * The default location is the current directory.  If not found there, the
     59 * alternative location is the executable directory.  If not found there either,
     60 * the first alternative is present to the caller.
     61 */
     62static DWORD MyGetfullPathNameW(LPCWSTR pwszName, size_t cchFull, LPWSTR pwszFull)
     63{
     64    LPWSTR pwszFilePart;
     65    DWORD dwSize = GetFullPathNameW(pwszName, (DWORD)cchFull, pwszFull, &pwszFilePart);
     66    if (dwSize <= 0)
     67        return dwSize;
     68
     69    /* if it doesn't exist, see if the file exists in the same directory as the executable. */
     70    if (GetFileAttributesW(pwszFull) == INVALID_FILE_ATTRIBUTES)
     71    {
     72        WCHAR wsz[512];
     73        DWORD cch = GetModuleFileNameW(GetModuleHandle(NULL), &wsz[0], sizeof(wsz) / sizeof(wsz[0]));
     74        if (cch > 0)
     75        {
     76            while (cch > 0 && wsz[cch - 1] != '/' && wsz[cch - 1] != '\\' && wsz[cch - 1] != ':')
     77                cch--;
     78            unsigned i = 0;
     79            while (cch < sizeof(wsz) / sizeof(wsz[0]))
     80            {
     81                wsz[cch] = pwszFilePart[i++];
     82                if (!wsz[cch])
     83                {
     84                    dwSize = GetFullPathNameW(wsz, (DWORD)cchFull, pwszFull, NULL);
     85                    if (dwSize > 0 && GetFileAttributesW(pwszFull) != INVALID_FILE_ATTRIBUTES)
     86                        return dwSize;
     87                    break;
     88                }
     89                cch++;
     90            }
     91        }
     92    }
     93
     94    /* fallback */
     95    return GetFullPathNameW(pwszName, (DWORD)cchFull, pwszFull, NULL);
     96}
     97
     98
    4699static int VBoxNetAdpInstall(void)
    47100{
     
    53106        wprintf(L"adding host-only interface..\n");
    54107
    55         DWORD dwErr = ERROR_SUCCESS;
    56         WCHAR MpInf[MAX_PATH];
    57 
    58         if (!GetFullPathNameW(VBOX_NETADP_INF, sizeof(MpInf)/sizeof(MpInf[0]), MpInf, NULL))
    59             dwErr = GetLastError();
    60 
    61         if (dwErr == ERROR_SUCCESS)
     108        WCHAR wszInfFile[MAX_PATH];
     109        DWORD cwcInfFile = MyGetfullPathNameW(VBOX_NETADP_INF, sizeof(wszInfFile) / sizeof(wszInfFile[0]), wszInfFile);
     110        if (cwcInfFile > 0)
    62111        {
    63112            INetCfg *pnc;
     
    67116            {
    68117
    69                 hr = VBoxNetCfgWinNetAdpInstall(pnc, MpInf);
     118                hr = VBoxNetCfgWinNetAdpInstall(pnc, wszInfFile);
    70119
    71120                if (hr == S_OK)
     
    117166        else
    118167        {
     168            DWORD dwErr = GetLastError();
    119169            wprintf(L"GetFullPathNameW failed: winEr = %d\n", dwErr);
    120170            hr = HRESULT_FROM_WIN32(dwErr);
    121 
    122171        }
    123172        CoUninitialize();
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