Changeset 79409 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Jun 28, 2019 11:45:54 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpInstall.cpp
r76553 r79409 25 25 */ 26 26 27 28 /********************************************************************************************************************************* 29 * Header Files * 30 *********************************************************************************************************************************/ 27 31 #include <VBox/VBoxNetCfg-win.h> 28 32 #include <VBox/VBoxDrvCfg-win.h> … … 30 34 #include <devguid.h> 31 35 36 37 /********************************************************************************************************************************* 38 * Defined Constants And Macros * 39 *********************************************************************************************************************************/ 32 40 #define VBOX_NETADP_APP_NAME L"NetAdpInstall" 33 41 34 42 #define VBOX_NETADP_HWID L"sun_VBoxNetAdp" 35 43 #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 40 49 41 50 static VOID winNetCfgLogger(LPCSTR szString) … … 44 53 } 45 54 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 */ 62 static 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 46 99 static int VBoxNetAdpInstall(void) 47 100 { … … 53 106 wprintf(L"adding host-only interface..\n"); 54 107 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) 62 111 { 63 112 INetCfg *pnc; … … 67 116 { 68 117 69 hr = VBoxNetCfgWinNetAdpInstall(pnc, MpInf);118 hr = VBoxNetCfgWinNetAdpInstall(pnc, wszInfFile); 70 119 71 120 if (hr == S_OK) … … 117 166 else 118 167 { 168 DWORD dwErr = GetLastError(); 119 169 wprintf(L"GetFullPathNameW failed: winEr = %d\n", dwErr); 120 170 hr = HRESULT_FROM_WIN32(dwErr); 121 122 171 } 123 172 CoUninitialize();
Note:
See TracChangeset
for help on using the changeset viewer.