VirtualBox

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


Ignore:
Timestamp:
Nov 28, 2009 8:14:17 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
55425
Message:

NetFltInstall.cpp: proposal for making it work when the current directory != executable directory.

File:
1 edited

Legend:

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

    r24518 r25072  
    3636}
    3737
     38/** Wrapper aroung GetfullPathNameW that will try an alternative INF location.
     39 * 
     40 * The default location is the current directory.  If not found there, the
     41 * alternative locatoin is the executable directory.  If not found there either,
     42 * the first alternative is present to the caller.
     43 */
     44static DWORD MyGetfullPathNameW(LPCWSTR pwszName, size_t cchFull, LPWSTR pwszFull)
     45{
     46#ifdef DEBUG_bird  /** @todo make this default behavior after 3.1. */
     47    LPWSTR pwszFilePart;
     48    DWORD dwSize = GetFullPathNameW(pwszName, cchFull, pwszFull, &pwszFilePart);
     49    if(dwSize <= 0)
     50        return dwSize;
     51
     52    /* if it doesn't exist, see if the file exists in the same directory as the executable. */
     53    if (GetFileAttributesW(pwszFull) == INVALID_FILE_ATTRIBUTES)
     54    {
     55        WCHAR wsz[512];
     56        DWORD cch = GetModuleFileNameW(GetModuleHandle(NULL), &wsz[0], sizeof(wsz) / sizeof(wsz[0]));
     57        if(cch > 0)
     58        {
     59            while(cch > 0 && wsz[cch - 1] != '/' && wsz[cch - 1] != '\\' && wsz[cch - 1] != ':')
     60                cch--;
     61            unsigned i = 0;
     62            while(cch < sizeof(wsz) / sizeof(wsz[0]))
     63            {
     64                wsz[cch] = pwszFilePart[i++];
     65                if(!wsz[cch])
     66                {
     67                    dwSize = GetFullPathNameW(wsz, cchFull, pwszFull, NULL);
     68                    if(   dwSize > 0
     69                       && GetFileAttributesW(pwszFull) != INVALID_FILE_ATTRIBUTES)
     70                        return dwSize;
     71                    break;
     72                }
     73                cch++;
     74            }
     75        }
     76    }
     77
     78    /* fallback */
     79#endif
     80    return GetFullPathNameW(pwszName, cchFull, pwszFull, NULL);
     81}
     82
    3883static int InstallNetFlt()
    3984{
     
    56101            {
    57102                DWORD dwSize;
    58                 dwSize = GetFullPathNameW(VBOX_NETFLT_PT_INF, sizeof(PtInf)/sizeof(PtInf[0]), PtInf, NULL);
     103                dwSize = MyGetfullPathNameW(VBOX_NETFLT_PT_INF, sizeof(PtInf)/sizeof(PtInf[0]), PtInf);
    59104                if(dwSize > 0)
    60105                {
    61106                    /** @todo add size check for (sizeof(PtInf)/sizeof(PtInf[0])) == dwSize (string length in sizeof(PtInf[0])) */
    62107
    63                     dwSize = GetFullPathNameW(VBOX_NETFLT_MP_INF, sizeof(MpInf)/sizeof(MpInf[0]), MpInf, NULL);
     108                    dwSize = MyGetfullPathNameW(VBOX_NETFLT_MP_INF, sizeof(MpInf)/sizeof(MpInf[0]), MpInf);
    64109                    if(dwSize > 0)
    65110                    {
Note: See TracChangeset for help on using the changeset viewer.

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