diff options
| -rw-r--r-- | dist-assets/windows/installer.nsh | 20 | ||||
| -rw-r--r-- | windows/driverlogic/src/driverlogic.cpp | 21 |
2 files changed, 40 insertions, 1 deletions
diff --git a/dist-assets/windows/installer.nsh b/dist-assets/windows/installer.nsh index de95747cdf..9369a19f62 100644 --- a/dist-assets/windows/installer.nsh +++ b/dist-assets/windows/installer.nsh @@ -24,6 +24,7 @@ !define MULLVAD_SUCCESS 1 # Return codes from driverlogic +!define DL_ADAPTER_NOT_FOUND -2 !define DL_GENERAL_ERROR -1 !define DL_GENERAL_SUCCESS 0 @@ -140,6 +141,23 @@ Goto InstallWintun_return ${EndIf} + nsExec::ExecToStack '"$TEMP\driverlogic.exe" device-exists ${TUN_HARDWARE_ID} Mullvad' + + Pop $0 + Pop $1 + + ${If} $0 == ${DL_GENERAL_ERROR} + IntFmt $0 "0x%X" $0 + StrCpy $R0 "Failed to identify virtual adapter: error $0" + log::LogWithDetails $R0 $1 + Goto InstallWintun_return + ${EndIf} + + ${If} $0 != ${DL_ADAPTER_NOT_FOUND} + log::Log "Found existing virtual adapter" + Goto InstallWintun_return_success + ${EndIf} + log::Log "Creating new virtual adapter" nsExec::ExecToStack '"$TEMP\driverlogic.exe" new-device ${TUN_HARDWARE_ID} Mullvad' @@ -153,6 +171,8 @@ Goto InstallWintun_return ${EndIf} + InstallWintun_return_success: + log::Log "InstallWintun() completed successfully" Push 0 diff --git a/windows/driverlogic/src/driverlogic.cpp b/windows/driverlogic/src/driverlogic.cpp index 25487d8481..08f0e97883 100644 --- a/windows/driverlogic/src/driverlogic.cpp +++ b/windows/driverlogic/src/driverlogic.cpp @@ -34,7 +34,8 @@ constexpr std::chrono::milliseconds REGISTRY_GET_TIMEOUT_MS{ 10000 }; enum ReturnCodes { GENERAL_SUCCESS = 0, - GENERAL_ERROR = -1 + GENERAL_ERROR = -1, + ADAPTER_NOT_FOUND = -2 }; struct NetworkAdapter @@ -917,6 +918,24 @@ int wmain(int argc, const wchar_t * argv[], const wchar_t * []) RemoveNetAdapterByAlias(hardwareId, baseName); } + else if (0 == _wcsicmp(argv[1], L"device-exists")) + { + if (4 != argc) + { + goto INVALID_ARGUMENTS; + } + + const wchar_t *hardwareId = argv[2]; + const wchar_t *baseName = argv[3]; + + const auto tapAdapters = GetNetworkAdapters(hardwareId); + const auto adapter = FindAdapterByAlias(tapAdapters, baseName); + + if (!adapter.has_value()) + { + return ADAPTER_NOT_FOUND; + } + } else if (0 == _wcsicmp(argv[1], L"remove")) { if (3 != argc) |
