1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[net] switch to INetworkListManager::GetConnectivity to detect connectivity

* InternetGetConnectedState() is next to useless and doesn't provide
  coherent outcome on the ARM64 platform I'm testing with. This results
  in Rufus declaring that Internet is unavailable on platforms that do
  have actual Internet connectivity.
* Swicth to using INetworkListManager::GetConnectivity(), which actually
  reports a dependable result.
* Closes #1691
* Also remove the mutex for uprintf(), which may produce thread lockout
  and remove an unwanted double GetSignatureName() call on startup.
This commit is contained in:
Pete Batard 2021-02-06 18:58:42 +00:00
parent e4372a9f57
commit b2492908be
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
6 changed files with 36 additions and 29 deletions

View file

@ -10,7 +10,7 @@
<Identity <Identity
Name="19453.net.Rufus" Name="19453.net.Rufus"
Publisher="CN=7AC86D13-3E5A-491A-ADD5-80095C212740" Publisher="CN=7AC86D13-3E5A-491A-ADD5-80095C212740"
Version="3.13.1738.0" /> Version="3.13.1739.0" />
<Properties> <Properties>
<DisplayName>Rufus</DisplayName> <DisplayName>Rufus</DisplayName>
@ -36,7 +36,13 @@
BackgroundColor="transparent" BackgroundColor="transparent"
Square150x150Logo="Images\Square150x150Logo.png" Square150x150Logo="Images\Square150x150Logo.png"
Square44x44Logo="Images\Square44x44Logo.png"> Square44x44Logo="Images\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Images\Wide310x150Logo.png" Square71x71Logo="Images\SmallTile.png" Square310x310Logo="Images\LargeTile.png"/> <uap:DefaultTile Wide310x150Logo="Images\Wide310x150Logo.png" Square71x71Logo="Images\SmallTile.png" Square310x310Logo="Images\LargeTile.png">
<uap:ShowNameOnTiles>
<uap:ShowOn Tile="square150x150Logo"/>
<uap:ShowOn Tile="wide310x150Logo"/>
<uap:ShowOn Tile="square310x310Logo"/>
</uap:ShowNameOnTiles>
</uap:DefaultTile >
</uap:VisualElements> </uap:VisualElements>
</Application> </Application>
</Applications> </Applications>

View file

@ -2181,6 +2181,7 @@ DWORD WINAPI FormatThread(void* param)
} }
out: out:
// TODO: Use a thread or only issue this on DD write
VdsRescan(VDS_RESCAN_REFRESH, 0, TRUE); VdsRescan(VDS_RESCAN_REFRESH, 0, TRUE);
safe_free(volume_name); safe_free(volume_name);
safe_free(buffer); safe_free(buffer);

View file

@ -25,6 +25,7 @@
#include <windows.h> #include <windows.h>
#include <wininet.h> #include <wininet.h>
#include <netlistmgr.h>
#include <stdio.h> #include <stdio.h>
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>
@ -265,27 +266,32 @@ static HINTERNET GetInternetSession(BOOL bRetry)
{ {
int i; int i;
char agent[64]; char agent[64];
BOOL r, decodingSupport = TRUE; BOOL decodingSupport = TRUE;
DWORD dwFlags, dwTimeout = NET_SESSION_TIMEOUT, dwProtocolSupport = HTTP_PROTOCOL_FLAG_HTTP2; DWORD dwTimeout = NET_SESSION_TIMEOUT, dwProtocolSupport = HTTP_PROTOCOL_FLAG_HTTP2;
HINTERNET hSession = NULL; HINTERNET hSession = NULL;
HRESULT hr = S_FALSE;
INetworkListManager* pNetworkListManager;
NLM_CONNECTIVITY Connectivity = NLM_CONNECTIVITY_DISCONNECTED;
PF_TYPE_DECL(WINAPI, BOOL, InternetGetConnectedState, (LPDWORD, DWORD));
PF_TYPE_DECL(WINAPI, HINTERNET, InternetOpenA, (LPCSTR, DWORD, LPCSTR, LPCSTR, DWORD)); PF_TYPE_DECL(WINAPI, HINTERNET, InternetOpenA, (LPCSTR, DWORD, LPCSTR, LPCSTR, DWORD));
PF_TYPE_DECL(WINAPI, BOOL, InternetSetOptionA, (HINTERNET, DWORD, LPVOID, DWORD)); PF_TYPE_DECL(WINAPI, BOOL, InternetSetOptionA, (HINTERNET, DWORD, LPVOID, DWORD));
PF_INIT_OR_OUT(InternetGetConnectedState, WinInet);
PF_INIT_OR_OUT(InternetOpenA, WinInet); PF_INIT_OR_OUT(InternetOpenA, WinInet);
PF_INIT_OR_OUT(InternetSetOptionA, WinInet); PF_INIT_OR_OUT(InternetSetOptionA, WinInet);
// Create a NetworkListManager Instance to check the network connection
IGNORE_RETVAL(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED));
hr = CoCreateInstance(&CLSID_NetworkListManager, NULL, CLSCTX_ALL,
&IID_INetworkListManager, (LPVOID*)&pNetworkListManager);
if (hr == S_OK) {
for (i = 0; i <= WRITE_RETRIES; i++) { for (i = 0; i <= WRITE_RETRIES; i++) {
r = pfInternetGetConnectedState(&dwFlags, 0); hr = INetworkListManager_GetConnectivity(pNetworkListManager, &Connectivity);
if (r || !bRetry) if (hr == S_OK || !bRetry)
break; break;
Sleep(1000); Sleep(1000);
} }
if (!r) { }
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa384702.aspx is wrong... if (Connectivity == NLM_CONNECTIVITY_DISCONNECTED) {
SetLastError(ERROR_INTERNET_NOT_INITIALIZED); SetLastError(ERROR_INTERNET_DISCONNECTED);
uprintf("Network is unavailable: %s", WinInetErrorString());
goto out; goto out;
} }
static_sprintf(agent, APPLICATION_NAME "/%d.%d.%d (Windows NT %d.%d%s)", static_sprintf(agent, APPLICATION_NAME "/%d.%d.%d (Windows NT %d.%d%s)",

View file

@ -3290,7 +3290,9 @@ skip_args_processing:
// Look for a .ini file in the current app directory // Look for a .ini file in the current app directory
static_sprintf(ini_path, "%s\\rufus.ini", app_dir); static_sprintf(ini_path, "%s\\rufus.ini", app_dir);
fd = fopenU(ini_path, ini_flags); // Will create the file if portable mode is requested fd = fopenU(ini_path, ini_flags); // Will create the file if portable mode is requested
vc |= (safe_strcmp(GetSignatureName(NULL, NULL), cert_name[0]) == 0); // Using the string directly in safe_strcmp() would call GetSignatureName() twice
tmp = GetSignatureName(NULL, NULL);
vc |= (safe_strcmp(tmp, cert_name[0]) == 0);
if (fd != NULL) { if (fd != NULL) {
ini_file = ini_path; ini_file = ini_path;
fclose(fd); fclose(fd);

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326 IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.14.1738" CAPTION "Rufus 3.14.1739"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0 FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -395,8 +395,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,14,1738,0 FILEVERSION 3,14,1739,0
PRODUCTVERSION 3,14,1738,0 PRODUCTVERSION 3,14,1739,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -414,13 +414,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie" VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting" VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.14.1738" VALUE "FileVersion", "3.14.1739"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2021 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011-2021 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-3.14.exe" VALUE "OriginalFilename", "rufus-3.14.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.14.1738" VALUE "ProductVersion", "3.14.1739"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View file

@ -43,7 +43,6 @@
HWND hStatus; HWND hStatus;
size_t ubuffer_pos = 0; size_t ubuffer_pos = 0;
char ubuffer[UBUFFER_SIZE]; // Buffer for ubpushf() messages we don't log right away char ubuffer[UBUFFER_SIZE]; // Buffer for ubpushf() messages we don't log right away
static HANDLE print_mutex = NULL;
void _uprintf(const char *format, ...) void _uprintf(const char *format, ...)
{ {
@ -53,11 +52,6 @@ void _uprintf(const char *format, ...)
va_list args; va_list args;
int n; int n;
if (print_mutex == NULL)
print_mutex = CreateMutex(NULL, FALSE, NULL);
if (WaitForSingleObject(print_mutex, INFINITE) != WAIT_OBJECT_0)
return;
va_start(args, format); va_start(args, format);
n = safe_vsnprintf(p, sizeof(buf)-3, format, args); // buf-3 is room for CR/LF/NUL n = safe_vsnprintf(p, sizeof(buf)-3, format, args); // buf-3 is room for CR/LF/NUL
va_end(args); va_end(args);
@ -84,8 +78,6 @@ void _uprintf(const char *format, ...)
Edit_Scroll(hLog, Edit_GetLineCount(hLog), 0); Edit_Scroll(hLog, Edit_GetLineCount(hLog), 0);
} }
free(wbuf); free(wbuf);
ReleaseMutex(print_mutex);
} }
void _uprintfs(const char* str) void _uprintfs(const char* str)