mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
Compare commits
2 commits
8449accb55
...
21ac145a4b
Author | SHA1 | Date | |
---|---|---|---|
|
21ac145a4b | ||
|
ed80d696f4 |
5 changed files with 130 additions and 49 deletions
27
src/drive.c
27
src/drive.c
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Rufus: The Reliable USB Formatting Utility
|
* Rufus: The Reliable USB Formatting Utility
|
||||||
* Drive access function calls
|
* Drive access function calls
|
||||||
* Copyright © 2011-2022 Pete Batard <pete@akeo.ie>
|
* Copyright © 2011-2023 Pete Batard <pete@akeo.ie>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -203,7 +203,9 @@ static HANDLE GetHandle(char* Path, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWr
|
||||||
uprintf("Could not lock access to %s: %s", Path, WindowsErrorString());
|
uprintf("Could not lock access to %s: %s", Path, WindowsErrorString());
|
||||||
// See if we can report the processes are accessing the drive
|
// See if we can report the processes are accessing the drive
|
||||||
if (!IS_ERROR(FormatStatus) && (access_mask == 0))
|
if (!IS_ERROR(FormatStatus) && (access_mask == 0))
|
||||||
access_mask = SearchProcess(DevPath, SEARCH_PROCESS_TIMEOUT, TRUE, TRUE, FALSE);
|
// Double the search process timeout here, as Windows is so bloated with processes
|
||||||
|
// that 10 seconds has become way too small to get much of any results these days...
|
||||||
|
access_mask = SearchProcess(DevPath, 2 * SEARCH_PROCESS_TIMEOUT, TRUE, TRUE, FALSE);
|
||||||
// Try to continue if the only access rights we saw were for read-only
|
// Try to continue if the only access rights we saw were for read-only
|
||||||
if ((access_mask & 0x07) != 0x01)
|
if ((access_mask & 0x07) != 0x01)
|
||||||
safe_closehandle(hDrive);
|
safe_closehandle(hDrive);
|
||||||
|
@ -252,10 +254,10 @@ char* GetLogicalName(DWORD DriveIndex, uint64_t PartitionOffset, BOOL bKeepTrail
|
||||||
static const char* ignore_device[] = { "\\Device\\CdRom", "\\Device\\Floppy" };
|
static const char* ignore_device[] = { "\\Device\\CdRom", "\\Device\\Floppy" };
|
||||||
static const char* volume_start = "\\\\?\\";
|
static const char* volume_start = "\\\\?\\";
|
||||||
char *ret = NULL, volume_name[MAX_PATH], path[MAX_PATH];
|
char *ret = NULL, volume_name[MAX_PATH], path[MAX_PATH];
|
||||||
BOOL bPrintHeader = TRUE;
|
BOOL r, bPrintHeader = TRUE;
|
||||||
HANDLE hDrive = INVALID_HANDLE_VALUE, hVolume = INVALID_HANDLE_VALUE;
|
HANDLE hDrive = INVALID_HANDLE_VALUE, hVolume = INVALID_HANDLE_VALUE;
|
||||||
VOLUME_DISK_EXTENTS_REDEF DiskExtents;
|
VOLUME_DISK_EXTENTS_REDEF DiskExtents;
|
||||||
DWORD size;
|
DWORD size = 0;
|
||||||
UINT drive_type;
|
UINT drive_type;
|
||||||
StrArray found_name;
|
StrArray found_name;
|
||||||
uint64_t found_offset[MAX_PARTITIONS] = { 0 };
|
uint64_t found_offset[MAX_PARTITIONS] = { 0 };
|
||||||
|
@ -312,9 +314,10 @@ char* GetLogicalName(DWORD DriveIndex, uint64_t PartitionOffset, BOOL bKeepTrail
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!DeviceIoControl(hDrive, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0,
|
r = DeviceIoControl(hDrive, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0,
|
||||||
&DiskExtents, sizeof(DiskExtents), &size, NULL)) || (size <= 0)) {
|
&DiskExtents, sizeof(DiskExtents), &size, NULL);
|
||||||
suprintf("Could not get Disk Extents: %s", WindowsErrorString());
|
if ((!r) || (size == 0)) {
|
||||||
|
suprintf("Could not get Disk Extents: %s", r ? "(empty data)" : WindowsErrorString());
|
||||||
safe_closehandle(hDrive);
|
safe_closehandle(hDrive);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1059,15 +1062,17 @@ int GetDriveNumber(HANDLE hDrive, char* path)
|
||||||
{
|
{
|
||||||
STORAGE_DEVICE_NUMBER_REDEF DeviceNumber;
|
STORAGE_DEVICE_NUMBER_REDEF DeviceNumber;
|
||||||
VOLUME_DISK_EXTENTS_REDEF DiskExtents;
|
VOLUME_DISK_EXTENTS_REDEF DiskExtents;
|
||||||
DWORD size;
|
DWORD size = 0;
|
||||||
|
BOOL s;
|
||||||
int r = -1;
|
int r = -1;
|
||||||
|
|
||||||
if (!DeviceIoControl(hDrive, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0,
|
if (!DeviceIoControl(hDrive, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0,
|
||||||
&DiskExtents, sizeof(DiskExtents), &size, NULL) || (size <= 0) || (DiskExtents.NumberOfDiskExtents < 1) ) {
|
&DiskExtents, sizeof(DiskExtents), &size, NULL) || (size <= 0) || (DiskExtents.NumberOfDiskExtents < 1) ) {
|
||||||
// DiskExtents are NO_GO (which is the case for external USB HDDs...)
|
// DiskExtents are NO_GO (which is the case for external USB HDDs...)
|
||||||
if(!DeviceIoControl(hDrive, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0,
|
s = DeviceIoControl(hDrive, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &DeviceNumber, sizeof(DeviceNumber),
|
||||||
&DeviceNumber, sizeof(DeviceNumber), &size, NULL ) || (size <= 0)) {
|
&size, NULL);
|
||||||
uprintf("Could not get device number for device %s: %s", path, WindowsErrorString());
|
if ((!s) || (size == 0)) {
|
||||||
|
uprintf("Could not get device number for device %s %s", path, s ? "(empty data)" : WindowsErrorString());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
r = (int)DeviceNumber.DeviceNumber;
|
r = (int)DeviceNumber.DeviceNumber;
|
||||||
|
|
10
src/rufus.rc
10
src/rufus.rc
|
@ -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.22.1988"
|
CAPTION "Rufus 3.22.1990"
|
||||||
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
|
||||||
|
@ -392,8 +392,8 @@ END
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 3,22,1988,0
|
FILEVERSION 3,22,1990,0
|
||||||
PRODUCTVERSION 3,22,1988,0
|
PRODUCTVERSION 3,22,1990,0
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -411,13 +411,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.22.1988"
|
VALUE "FileVersion", "3.22.1990"
|
||||||
VALUE "InternalName", "Rufus"
|
VALUE "InternalName", "Rufus"
|
||||||
VALUE "LegalCopyright", "© 2011-2023 Pete Batard (GPL v3)"
|
VALUE "LegalCopyright", "© 2011-2023 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.22.exe"
|
VALUE "OriginalFilename", "rufus-3.22.exe"
|
||||||
VALUE "ProductName", "Rufus"
|
VALUE "ProductName", "Rufus"
|
||||||
VALUE "ProductVersion", "3.22.1988"
|
VALUE "ProductVersion", "3.22.1990"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
137
src/vhd.c
137
src/vhd.c
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Rufus: The Reliable USB Formatting Utility
|
* Rufus: The Reliable USB Formatting Utility
|
||||||
* Virtual Disk Handling functions
|
* Virtual Disk Handling functions
|
||||||
* Copyright © 2013-2022 Pete Batard <pete@akeo.ie>
|
* Copyright © 2013-2023 Pete Batard <pete@akeo.ie>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -47,6 +47,13 @@ PF_TYPE_DECL(WINAPI, DWORD, WIMRegisterMessageCallback, (HANDLE, FARPROC, PVOID)
|
||||||
PF_TYPE_DECL(WINAPI, DWORD, WIMUnregisterMessageCallback, (HANDLE, FARPROC));
|
PF_TYPE_DECL(WINAPI, DWORD, WIMUnregisterMessageCallback, (HANDLE, FARPROC));
|
||||||
PF_TYPE_DECL(RPC_ENTRY, RPC_STATUS, UuidCreate, (UUID __RPC_FAR*));
|
PF_TYPE_DECL(RPC_ENTRY, RPC_STATUS, UuidCreate, (UUID __RPC_FAR*));
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int index;
|
||||||
|
BOOL commit;
|
||||||
|
const char* image;
|
||||||
|
const char* dst;
|
||||||
|
} mount_params_t;
|
||||||
|
|
||||||
uint32_t wim_nb_files, wim_proc_files, wim_extra_files;
|
uint32_t wim_nb_files, wim_proc_files, wim_extra_files;
|
||||||
HANDLE wim_thread = NULL;
|
HANDLE wim_thread = NULL;
|
||||||
extern int default_thread_priority;
|
extern int default_thread_priority;
|
||||||
|
@ -59,9 +66,7 @@ static wchar_t wmount_path[MAX_PATH] = { 0 }, wmount_track[MAX_PATH] = { 0 };
|
||||||
static char sevenzip_path[MAX_PATH];
|
static char sevenzip_path[MAX_PATH];
|
||||||
static const char conectix_str[] = VHD_FOOTER_COOKIE;
|
static const char conectix_str[] = VHD_FOOTER_COOKIE;
|
||||||
static BOOL count_files;
|
static BOOL count_files;
|
||||||
// Apply/Mount image functionality
|
static int progress_op = OP_FILE_COPY, progress_msg = MSG_267;
|
||||||
static const char *_image, *_dst;
|
|
||||||
static int _index, progress_op = OP_FILE_COPY, progress_msg = MSG_267;
|
|
||||||
|
|
||||||
static BOOL Get7ZipPath(void)
|
static BOOL Get7ZipPath(void)
|
||||||
{
|
{
|
||||||
|
@ -414,7 +419,8 @@ static DWORD WINAPI WimMountImageThread(LPVOID param)
|
||||||
{
|
{
|
||||||
BOOL r = FALSE;
|
BOOL r = FALSE;
|
||||||
wconvert(temp_dir);
|
wconvert(temp_dir);
|
||||||
wchar_t* wimage = utf8_to_wchar(_image);
|
mount_params_t* mp = (mount_params_t*)param;
|
||||||
|
wchar_t* wimage = utf8_to_wchar(mp->image);
|
||||||
|
|
||||||
PF_INIT_OR_OUT(WIMRegisterMessageCallback, Wimgapi);
|
PF_INIT_OR_OUT(WIMRegisterMessageCallback, Wimgapi);
|
||||||
PF_INIT_OR_OUT(WIMMountImage, Wimgapi);
|
PF_INIT_OR_OUT(WIMMountImage, Wimgapi);
|
||||||
|
@ -423,7 +429,7 @@ static DWORD WINAPI WimMountImageThread(LPVOID param)
|
||||||
|
|
||||||
if (wmount_path[0] != 0) {
|
if (wmount_path[0] != 0) {
|
||||||
uprintf("WimMountImage: An image is already mounted. Trying to unmount it...");
|
uprintf("WimMountImage: An image is already mounted. Trying to unmount it...");
|
||||||
if (pfWIMUnmountImage(wmount_path, wimage, _index, FALSE))
|
if (pfWIMUnmountImage(wmount_path, wimage, mp->index, FALSE))
|
||||||
uprintf("WimMountImage: Successfully unmounted existing image..");
|
uprintf("WimMountImage: Successfully unmounted existing image..");
|
||||||
else
|
else
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -457,13 +463,13 @@ static DWORD WINAPI WimMountImageThread(LPVOID param)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = pfWIMMountImage(wmount_path, wimage, _index, wmount_track);
|
r = pfWIMMountImage(wmount_path, wimage, mp->index, wmount_track);
|
||||||
pfWIMUnregisterMessageCallback(NULL, (FARPROC)WimProgressCallback);
|
pfWIMUnregisterMessageCallback(NULL, (FARPROC)WimProgressCallback);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
uprintf("Could not mount '%S [%d]' on '%S': %s", wimage, _index, wmount_path, WindowsErrorString());
|
uprintf("Could not mount '%S [%d]' on '%S': %s", wimage, mp->index, wmount_path, WindowsErrorString());
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
uprintf("Mounted '%S [%d]' on '%S'", wimage, _index, wmount_path);
|
uprintf("Mounted '%S [%d]' on '%S'", wimage, mp->index, wmount_path);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (!r) {
|
if (!r) {
|
||||||
|
@ -485,11 +491,23 @@ out:
|
||||||
// Returned path must be freed by the caller.
|
// Returned path must be freed by the caller.
|
||||||
char* WimMountImage(const char* image, int index)
|
char* WimMountImage(const char* image, int index)
|
||||||
{
|
{
|
||||||
|
char* mount_path = NULL;
|
||||||
DWORD dw = 0;
|
DWORD dw = 0;
|
||||||
_image = image;
|
mount_params_t mp = { 0 };
|
||||||
_index = index;
|
mp.image = image;
|
||||||
|
mp.index = index;
|
||||||
|
|
||||||
wim_thread = CreateThread(NULL, 0, WimMountImageThread, NULL, 0, NULL);
|
// Try to unmount an existing stale image, if there is any
|
||||||
|
mount_path = GetExistingMountPoint(image, index);
|
||||||
|
if (mount_path != NULL) {
|
||||||
|
uprintf("WARNING: Found stale '%s [%d]' image mounted on '%s' - Attempting to unmount it...",
|
||||||
|
image, index, mount_path);
|
||||||
|
utf8_to_wchar_no_alloc(mount_path, wmount_path, ARRAYSIZE(wmount_path));
|
||||||
|
wmount_track[0] = 0;
|
||||||
|
WimUnmountImage(image, index, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
wim_thread = CreateThread(NULL, 0, WimMountImageThread, &mp, 0, NULL);
|
||||||
if (wim_thread == NULL) {
|
if (wim_thread == NULL) {
|
||||||
uprintf("Unable to start mount-image thread");
|
uprintf("Unable to start mount-image thread");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -505,7 +523,8 @@ char* WimMountImage(const char* image, int index)
|
||||||
static DWORD WINAPI WimUnmountImageThread(LPVOID param)
|
static DWORD WINAPI WimUnmountImageThread(LPVOID param)
|
||||||
{
|
{
|
||||||
BOOL r = FALSE;
|
BOOL r = FALSE;
|
||||||
wchar_t* wimage = utf8_to_wchar(_image);
|
mount_params_t* mp = (mount_params_t*)param;
|
||||||
|
wchar_t* wimage = utf8_to_wchar(mp->image);
|
||||||
|
|
||||||
PF_INIT_OR_OUT(WIMRegisterMessageCallback, Wimgapi);
|
PF_INIT_OR_OUT(WIMRegisterMessageCallback, Wimgapi);
|
||||||
PF_INIT_OR_OUT(WIMUnmountImage, Wimgapi);
|
PF_INIT_OR_OUT(WIMUnmountImage, Wimgapi);
|
||||||
|
@ -526,17 +545,17 @@ static DWORD WINAPI WimUnmountImageThread(LPVOID param)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = pfWIMUnmountImage(wmount_path, wimage, _index, TRUE);
|
r = pfWIMUnmountImage(wmount_path, wimage, mp->index, mp->commit);
|
||||||
pfWIMUnregisterMessageCallback(NULL, (FARPROC)WimProgressCallback);
|
pfWIMUnregisterMessageCallback(NULL, (FARPROC)WimProgressCallback);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
uprintf("Could not unmount '%S': %s", wmount_path, WindowsErrorString());
|
uprintf("Could not unmount '%S': %s", wmount_path, WindowsErrorString());
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
uprintf("Unmounted '%S [%d]'", wmount_path, _index);
|
uprintf("Unmounted '%S [%d]'", wmount_path, mp->index);
|
||||||
if (!RemoveDirectoryW(wmount_track))
|
if (wmount_track[0] != 0 && !RemoveDirectoryW(wmount_track))
|
||||||
uprintf("Could not delete '%S' : %s", wmount_track, WindowsErrorString());
|
uprintf("Could not delete '%S' : %s", wmount_track, WindowsErrorString());
|
||||||
wmount_track[0] = 0;
|
wmount_track[0] = 0;
|
||||||
if (!RemoveDirectoryW(wmount_path))
|
if (wmount_path[0] != 0 && !RemoveDirectoryW(wmount_path))
|
||||||
uprintf("Could not delete '%S' : %s", wmount_path, WindowsErrorString());
|
uprintf("Could not delete '%S' : %s", wmount_path, WindowsErrorString());
|
||||||
wmount_path[0] = 0;
|
wmount_path[0] = 0;
|
||||||
out:
|
out:
|
||||||
|
@ -544,13 +563,15 @@ out:
|
||||||
ExitThread((DWORD)r);
|
ExitThread((DWORD)r);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL WimUnmountImage(const char* image, int index)
|
BOOL WimUnmountImage(const char* image, int index, BOOL commit)
|
||||||
{
|
{
|
||||||
DWORD dw = 0;
|
DWORD dw = 0;
|
||||||
_image = image;
|
mount_params_t mp = { 0 };
|
||||||
_index = index;
|
mp.image = image;
|
||||||
|
mp.index = index;
|
||||||
|
mp.commit = commit;
|
||||||
|
|
||||||
wim_thread = CreateThread(NULL, 0, WimUnmountImageThread, NULL, 0, NULL);
|
wim_thread = CreateThread(NULL, 0, WimUnmountImageThread, &mp, 0, NULL);
|
||||||
if (wim_thread == NULL) {
|
if (wim_thread == NULL) {
|
||||||
uprintf("Unable to start unmount-image thread");
|
uprintf("Unable to start unmount-image thread");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -563,6 +584,58 @@ BOOL WimUnmountImage(const char* image, int index)
|
||||||
return dw;
|
return dw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the existing mount point (if any) for the image + index passed as parameters.
|
||||||
|
// Needed because Windows refuses to mount two images with the same path/index even
|
||||||
|
// if the previous has become stale or deleted. This situation may occur if the user
|
||||||
|
// force-closed Rufus when 'boot.wim' was mounted, thus leaving them unable to mount
|
||||||
|
// 'boot.wim' for subsequent sessions unless they invoke dism /Unmount-Wim manually.
|
||||||
|
// This basically parses HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WIMMount\Mounted Images
|
||||||
|
// to see if an instance exists with the image/index passed as parameter and returns
|
||||||
|
// the mount point of this image if found, or NULL otherwise.
|
||||||
|
char* GetExistingMountPoint(const char* image, int index)
|
||||||
|
{
|
||||||
|
static char path[MAX_PATH];
|
||||||
|
char class[MAX_PATH] = "", guid[40], key_name[MAX_PATH];
|
||||||
|
HKEY hKey;
|
||||||
|
DWORD dw = 0, i, k, nb_subkeys = 0, class_size;
|
||||||
|
DWORD cbMaxSubKey, cchMaxClass, cValues, cchMaxValue;
|
||||||
|
DWORD cbMaxValueData, cbSecurityDescriptor;
|
||||||
|
FILETIME ftLastWriteTime;
|
||||||
|
|
||||||
|
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\WIMMount\\Mounted Images",
|
||||||
|
0, KEY_READ, &hKey) != ERROR_SUCCESS)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
class_size = sizeof(class);
|
||||||
|
RegQueryInfoKeyA(hKey, class, &class_size, NULL, &nb_subkeys,
|
||||||
|
&cbMaxSubKey, &cchMaxClass, &cValues, &cchMaxValue,
|
||||||
|
&cbMaxValueData, &cbSecurityDescriptor, &ftLastWriteTime);
|
||||||
|
|
||||||
|
for (k = 0; k < nb_subkeys; k++) {
|
||||||
|
dw = sizeof(guid);
|
||||||
|
if (RegEnumKeyExA(hKey, k, guid, &dw, NULL, NULL, NULL,
|
||||||
|
&ftLastWriteTime) == ERROR_SUCCESS) {
|
||||||
|
static_sprintf(key_name, "SOFTWARE\\Microsoft\\WIMMount\\Mounted Images\\%s\\WIM Path", guid);
|
||||||
|
if (GetRegistryKeyStr(HKEY_LOCAL_MACHINE, key_name, path, sizeof(path)) &&
|
||||||
|
(stricmp(path, image) != 0))
|
||||||
|
continue;
|
||||||
|
static_sprintf(key_name, "SOFTWARE\\Microsoft\\WIMMount\\Mounted Images\\%s\\Image Index", guid);
|
||||||
|
if (GetRegistryKey32(HKEY_LOCAL_MACHINE, key_name, &i) && (i != (DWORD)index))
|
||||||
|
continue;
|
||||||
|
path[0] = 0;
|
||||||
|
static_sprintf(key_name, "SOFTWARE\\Microsoft\\WIMMount\\Mounted Images\\%s\\Mount Path", guid);
|
||||||
|
if (GetRegistryKeyStr(HKEY_LOCAL_MACHINE, key_name, path, sizeof(path)))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (k >= nb_subkeys)
|
||||||
|
path[0] = 0;
|
||||||
|
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
|
return (path[0] == 0) ? NULL: path;
|
||||||
|
}
|
||||||
|
|
||||||
// Extract a file from a WIM image using wimgapi.dll (Windows 7 or later)
|
// Extract a file from a WIM image using wimgapi.dll (Windows 7 or later)
|
||||||
// NB: if you want progress from a WIM callback, you must run the WIM API call in its own thread
|
// NB: if you want progress from a WIM callback, you must run the WIM API call in its own thread
|
||||||
// (which we don't do here) as it won't work otherwise. Thanks go to Erwan for figuring this out!
|
// (which we don't do here) as it won't work otherwise. Thanks go to Erwan for figuring this out!
|
||||||
|
@ -792,9 +865,10 @@ static DWORD WINAPI WimApplyImageThread(LPVOID param)
|
||||||
BOOL r = FALSE;
|
BOOL r = FALSE;
|
||||||
HANDLE hWim = NULL;
|
HANDLE hWim = NULL;
|
||||||
HANDLE hImage = NULL;
|
HANDLE hImage = NULL;
|
||||||
wchar_t wtemp[MAX_PATH] = {0};
|
wchar_t wtemp[MAX_PATH] = { 0 };
|
||||||
wchar_t* wimage = utf8_to_wchar(_image);
|
mount_params_t* mp = (mount_params_t*)param;
|
||||||
wchar_t* wdst = utf8_to_wchar(_dst);
|
wchar_t* wimage = utf8_to_wchar(mp->image);
|
||||||
|
wchar_t* wdst = utf8_to_wchar(mp->dst);
|
||||||
|
|
||||||
PF_INIT_OR_OUT(WIMRegisterMessageCallback, Wimgapi);
|
PF_INIT_OR_OUT(WIMRegisterMessageCallback, Wimgapi);
|
||||||
PF_INIT_OR_OUT(WIMCreateFile, Wimgapi);
|
PF_INIT_OR_OUT(WIMCreateFile, Wimgapi);
|
||||||
|
@ -804,7 +878,7 @@ static DWORD WINAPI WimApplyImageThread(LPVOID param)
|
||||||
PF_INIT_OR_OUT(WIMCloseHandle, Wimgapi);
|
PF_INIT_OR_OUT(WIMCloseHandle, Wimgapi);
|
||||||
PF_INIT_OR_OUT(WIMUnregisterMessageCallback, Wimgapi);
|
PF_INIT_OR_OUT(WIMUnregisterMessageCallback, Wimgapi);
|
||||||
|
|
||||||
uprintf("Opening: %s:[%d]", _image, _index);
|
uprintf("Opening: %s:[%d]", mp->image, mp->index);
|
||||||
|
|
||||||
progress_report_mask = WIM_REPORT_PROCESS | WIM_REPORT_FILEINFO;
|
progress_report_mask = WIM_REPORT_PROCESS | WIM_REPORT_FILEINFO;
|
||||||
progress_op = OP_FILE_COPY;
|
progress_op = OP_FILE_COPY;
|
||||||
|
@ -833,7 +907,7 @@ static DWORD WINAPI WimApplyImageThread(LPVOID param)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
hImage = pfWIMLoadImage(hWim, (DWORD)_index);
|
hImage = pfWIMLoadImage(hWim, (DWORD)mp->index);
|
||||||
if (hImage == NULL) {
|
if (hImage == NULL) {
|
||||||
uprintf(" Could not set index: %s", WindowsErrorString());
|
uprintf(" Could not set index: %s", WindowsErrorString());
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -872,7 +946,7 @@ static DWORD WINAPI WimApplyImageThread(LPVOID param)
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if ((hImage != NULL) || (hWim != NULL)) {
|
if ((hImage != NULL) || (hWim != NULL)) {
|
||||||
uprintf("Closing: %s", _image);
|
uprintf("Closing: %s", mp->image);
|
||||||
if (hImage != NULL) pfWIMCloseHandle(hImage);
|
if (hImage != NULL) pfWIMCloseHandle(hImage);
|
||||||
if (hWim != NULL) pfWIMCloseHandle(hWim);
|
if (hWim != NULL) pfWIMCloseHandle(hWim);
|
||||||
}
|
}
|
||||||
|
@ -886,11 +960,12 @@ out:
|
||||||
BOOL WimApplyImage(const char* image, int index, const char* dst)
|
BOOL WimApplyImage(const char* image, int index, const char* dst)
|
||||||
{
|
{
|
||||||
DWORD dw = 0;
|
DWORD dw = 0;
|
||||||
_image = image;
|
mount_params_t mp = { 0 };
|
||||||
_index = index;
|
mp.image = image;
|
||||||
_dst = dst;
|
mp.index = index;
|
||||||
|
mp.dst = dst;
|
||||||
|
|
||||||
wim_thread = CreateThread(NULL, 0, WimApplyImageThread, NULL, 0, NULL);
|
wim_thread = CreateThread(NULL, 0, WimApplyImageThread, &mp, 0, NULL);
|
||||||
if (wim_thread == NULL) {
|
if (wim_thread == NULL) {
|
||||||
uprintf("Unable to start apply-image thread");
|
uprintf("Unable to start apply-image thread");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
@ -135,7 +135,8 @@ extern BOOL WimExtractFile_API(const char* image, int index, const char* src, co
|
||||||
extern BOOL WimExtractFile_7z(const char* image, int index, const char* src, const char* dst, BOOL bSilent);
|
extern BOOL WimExtractFile_7z(const char* image, int index, const char* src, const char* dst, BOOL bSilent);
|
||||||
extern BOOL WimApplyImage(const char* image, int index, const char* dst);
|
extern BOOL WimApplyImage(const char* image, int index, const char* dst);
|
||||||
extern char* WimMountImage(const char* image, int index);
|
extern char* WimMountImage(const char* image, int index);
|
||||||
extern BOOL WimUnmountImage(const char* image, int index);
|
extern BOOL WimUnmountImage(const char* image, int index, BOOL commit);
|
||||||
|
extern char* GetExistingMountPoint(const char* image, int index);
|
||||||
extern BOOL WimIsValidIndex(const char* image, int index);
|
extern BOOL WimIsValidIndex(const char* image, int index);
|
||||||
extern int8_t IsBootableImage(const char* path);
|
extern int8_t IsBootableImage(const char* path);
|
||||||
extern BOOL AppendVHDFooter(const char* vhd_path);
|
extern BOOL AppendVHDFooter(const char* vhd_path);
|
||||||
|
|
|
@ -883,7 +883,7 @@ out:
|
||||||
}
|
}
|
||||||
if (mount_path) {
|
if (mount_path) {
|
||||||
uprintf("Unmounting '%s[%d]'...", boot_wim_path, wim_index);
|
uprintf("Unmounting '%s[%d]'...", boot_wim_path, wim_index);
|
||||||
WimUnmountImage(boot_wim_path, wim_index);
|
WimUnmountImage(boot_wim_path, wim_index, TRUE);
|
||||||
UpdateProgressWithInfo(OP_PATCH, MSG_325, PATCH_PROGRESS_TOTAL, PATCH_PROGRESS_TOTAL);
|
UpdateProgressWithInfo(OP_PATCH, MSG_325, PATCH_PROGRESS_TOTAL, PATCH_PROGRESS_TOTAL);
|
||||||
}
|
}
|
||||||
free(mount_path);
|
free(mount_path);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue