-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
* With thanks to @Wack0
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* Rufus: The Reliable USB Formatting Utility | ||
* Drive access function calls | ||
* Copyright © 2011-2022 Pete Batard <[email protected]> | ||
* Copyright © 2011-2023 Pete Batard <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -57,7 +57,7 @@ | |
#define VDS_RESCAN_REFRESH 0x00000001 | ||
#define VDS_RESCAN_REENUMERATE 0x00000002 | ||
|
||
#define VDS_SET_ERROR(hr) do { if (hr != S_OK) { SetLastError(hr); FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_GEN_FAILURE; } } while(0) | ||
#define VDS_SET_ERROR(hr) do { if (hr != S_OK) { SetLastError((DWORD)hr); FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_GEN_FAILURE; } } while(0) | ||
|
||
#if !defined(__MINGW32__) | ||
typedef enum _FSINFOCLASS { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,15 @@ | |
|
||
#include "settings.h" | ||
|
||
// MinGW doesn't yet know these (from wldp.h) | ||
typedef enum WLDP_WINDOWS_LOCKDOWN_MODE | ||
{ | ||
WLDP_WINDOWS_LOCKDOWN_MODE_UNLOCKED = 0, | ||
WLDP_WINDOWS_LOCKDOWN_MODE_TRIAL, | ||
WLDP_WINDOWS_LOCKDOWN_MODE_LOCKED, | ||
WLDP_WINDOWS_LOCKDOWN_MODE_MAX, | ||
} WLDP_WINDOWS_LOCKDOWN_MODE, * PWLDP_WINDOWS_LOCKDOWN_MODE; | ||
|
||
windows_version_t WindowsVersion = { 0 }; | ||
|
||
/* | ||
|
@@ -304,6 +313,25 @@ static const char* GetEdition(DWORD ProductType) | |
} | ||
} | ||
|
||
PF_TYPE_DECL(WINAPI, HRESULT, WldpQueryWindowsLockdownMode, (PWLDP_WINDOWS_LOCKDOWN_MODE)); | ||
BOOL isSMode(void) | ||
{ | ||
BOOL r = FALSE; | ||
WLDP_WINDOWS_LOCKDOWN_MODE mode; | ||
PF_INIT_OR_OUT(WldpQueryWindowsLockdownMode, Wldp); | ||
|
||
HRESULT hr = pfWldpQueryWindowsLockdownMode(&mode); | ||
if (hr != S_OK) { | ||
SetLastError((DWORD)hr); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pbatard
Author
Owner
|
||
uprintf("Could not detect S Mode: %s", WindowsErrorString()); | ||
} else { | ||
r = (mode != WLDP_WINDOWS_LOCKDOWN_MODE_UNLOCKED); | ||
} | ||
|
||
out: | ||
return r; | ||
} | ||
|
||
/* | ||
* Modified from smartmontools' os_win32.cpp | ||
*/ | ||
|
@@ -451,6 +479,10 @@ void GetWindowsVersion(windows_version_t* windows_version) | |
safe_sprintf(vptr, vlen, " (Build %lu.%lu)", windows_version->BuildNumber, windows_version->Ubr); | ||
else | ||
safe_sprintf(vptr, vlen, " (Build %lu)", windows_version->BuildNumber); | ||
vptr = &windows_version->VersionStr[safe_strlen(windows_version->VersionStr)]; | ||
vlen = sizeof(windows_version->VersionStr) - safe_strlen(windows_version->VersionStr) - 1; | ||
if (isSMode()) | ||
safe_sprintf(vptr, vlen, " in S Mode"); | ||
} | ||
|
||
/* | ||
|
I personally dislike the use of
SetLastError
with an HRESULT here, especially because the function can only return S_OK orHRESULT_FROM_NT(failing_ntstatus)
, but that would require heavy refactor (probably to take an HRESULT, and where it's used after failing Win32 function, to passHRESULT_FROM_WIN32(GetLastError())
)also about
WindowsErrorString
, FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM) should be able to take an HRESULT directly, MS themselves do it, and in their CRT too (in _com_error::ErrorMessage which is one documented way to get error message from HRESULT)