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
Name="19453.net.Rufus"
Publisher="CN=7AC86D13-3E5A-491A-ADD5-80095C212740"
Version="3.13.1738.0" />
Version="3.13.1739.0" />
<Properties>
<DisplayName>Rufus</DisplayName>
@ -36,7 +36,13 @@
BackgroundColor="transparent"
Square150x150Logo="Images\Square150x150Logo.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>
</Application>
</Applications>

View file

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

View file

@ -25,6 +25,7 @@
#include <windows.h>
#include <wininet.h>
#include <netlistmgr.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>
@ -265,27 +266,32 @@ static HINTERNET GetInternetSession(BOOL bRetry)
{
int i;
char agent[64];
BOOL r, decodingSupport = TRUE;
DWORD dwFlags, dwTimeout = NET_SESSION_TIMEOUT, dwProtocolSupport = HTTP_PROTOCOL_FLAG_HTTP2;
BOOL decodingSupport = TRUE;
DWORD dwTimeout = NET_SESSION_TIMEOUT, dwProtocolSupport = HTTP_PROTOCOL_FLAG_HTTP2;
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, BOOL, InternetSetOptionA, (HINTERNET, DWORD, LPVOID, DWORD));
PF_INIT_OR_OUT(InternetGetConnectedState, WinInet);
PF_INIT_OR_OUT(InternetOpenA, WinInet);
PF_INIT_OR_OUT(InternetSetOptionA, WinInet);
for (i = 0; i <= WRITE_RETRIES; i++) {
r = pfInternetGetConnectedState(&dwFlags, 0);
if (r || !bRetry)
break;
Sleep(1000);
// 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++) {
hr = INetworkListManager_GetConnectivity(pNetworkListManager, &Connectivity);
if (hr == S_OK || !bRetry)
break;
Sleep(1000);
}
}
if (!r) {
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa384702.aspx is wrong...
SetLastError(ERROR_INTERNET_NOT_INITIALIZED);
uprintf("Network is unavailable: %s", WinInetErrorString());
if (Connectivity == NLM_CONNECTIVITY_DISCONNECTED) {
SetLastError(ERROR_INTERNET_DISCONNECTED);
goto out;
}
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
static_sprintf(ini_path, "%s\\rufus.ini", app_dir);
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) {
ini_file = ini_path;
fclose(fd);

View file

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

View file

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