From 662b8d1b2fd37cac35c2c48539e846c93ad17f7d Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 26 Sep 2023 01:22:24 +0200 Subject: [PATCH] Windows: during Setup, and if VeraCrypt already installed, open online help only if PC connected to Internet --- src/Common/Dlgcode.c | 42 +++++++++++++++++++++++++++++++++++++++--- src/Common/Dlgcode.h | 1 + 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index d9bb776e..2fede6fe 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -11223,10 +11224,18 @@ void Applink (const char *dest) if (buildUrl) { - // in case of setup, always open the online documentation because existing documentation may be outdated + // in case of setup, open the online documentation if we are connected to Internet because existing documentation may be outdated #ifdef SETUP - StringCbPrintfW (url, sizeof (url), L"https://www.veracrypt.fr/en/%s", page); - buildUrl = FALSE; + if (IsInternetConnected()) + { + StringCbPrintfW (url, sizeof (url), L"https://www.veracrypt.fr/en/%s", page); + buildUrl = FALSE; + } + else + { + StringCbPrintfW (url, sizeof (url), L"file:///%sdocs/html/en/%s", installDir, page); + CorrectURL (url); + } #else StringCbPrintfW (url, sizeof (url), L"file:///%sdocs/html/en/%s", installDir, page); CorrectURL (url); @@ -15233,6 +15242,33 @@ void PasswordEditDropTarget::GotDrop(CLIPFORMAT format) } +// check if the PC is connected to the internet using INetworkListManager interface +BOOL IsInternetConnected() +{ + HRESULT hr; + BOOL isConnected = FALSE; + INetworkListManager* pNetworkListManager = nullptr; + + hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); + if (SUCCEEDED(hr)) + { + hr = CoCreateInstance(CLSID_NetworkListManager, NULL, CLSCTX_ALL, IID_PPV_ARGS(&pNetworkListManager)); + if (SUCCEEDED(hr)) + { + VARIANT_BOOL isConnectedVariant; + hr = pNetworkListManager->get_IsConnectedToInternet(&isConnectedVariant); + if (SUCCEEDED(hr)) + { + isConnected = isConnectedVariant == VARIANT_TRUE; + } + pNetworkListManager->Release(); + } + CoUninitialize(); + } + + return isConnected; +} + /* * Query the status of Hibernate and Fast Startup */ diff --git a/src/Common/Dlgcode.h b/src/Common/Dlgcode.h index 3611371d..750b4dc7 100644 --- a/src/Common/Dlgcode.h +++ b/src/Common/Dlgcode.h @@ -597,6 +597,7 @@ DWORD FastResizeFile (const wchar_t* filePath, __int64 fileSize); #ifdef _WIN64 void GetAppRandomSeed (unsigned char* pbRandSeed, size_t cbRandSeed); #endif +BOOL IsInternetConnected(); #ifdef __cplusplus }