]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Support lenovo product recovery iso file.
authorlongpanda <admin@ventoy.net>
Tue, 3 Jan 2023 03:35:27 +0000 (11:35 +0800)
committerlongpanda <admin@ventoy.net>
Tue, 3 Jan 2023 03:35:27 +0000 (11:35 +0800)
INSTALL/grub/grub.cfg
INSTALL/ventoy/vtoyjump32.exe
INSTALL/ventoy/vtoyjump64.exe
vtoyjump/vtoyjump/vtoyjump.c

index 064542babc87323841bd82df8ae58dd11eb86492..08eb5d1d70f163cee75d9d069116b8fa73acdc5d 100644 (file)
@@ -227,6 +227,8 @@ function distro_specify_wim_patch {
 function distro_specify_wim_patch_phase2 {
     if [ -f (loop)/boot/boot.wim ]; then
         vt_windows_collect_wim_patch wim /boot/boot.wim
+    elif [ -f (loop)/sources/boot.wim ]; then
+        vt_windows_collect_wim_patch wim /sources/boot.wim
     fi
 
     if vt_str_begin "$vt_volume_id" "DLC Boot"; then
index 9a1feef3e60997de1c1111707dff79dc78bd9eaf..d6af4ac7552f4c24163536907aa54fceb8433a82 100644 (file)
Binary files a/INSTALL/ventoy/vtoyjump32.exe and b/INSTALL/ventoy/vtoyjump32.exe differ
index 3772ef36ec501c65bc7d691a730c1a702da01876..544212007aaeff7d3b1de5028fe645c15b39068e 100644 (file)
Binary files a/INSTALL/ventoy/vtoyjump64.exe and b/INSTALL/ventoy/vtoyjump64.exe differ
index ad7c3093cd9aef227e598b220ca4869ca51a9d13..e72754dc1e1402274800225687dfaf5d1ce8c1db 100644 (file)
@@ -60,6 +60,23 @@ static CHAR g_prog_name[MAX_PATH];
 #define MUTEX_LOCK(hmutex)  if (hmutex != NULL) LockStatus = WaitForSingleObject(hmutex, INFINITE)\r
 #define MUTEX_UNLOCK(hmutex)  if (hmutex != NULL && WAIT_OBJECT_0 == LockStatus) ReleaseMutex(hmutex)\r
 \r
+#define BREAK()  BreakAndLaunchCmd(__LINE__)\r
+\r
+static void BreakAndLaunchCmd(int line)\r
+{\r
+    STARTUPINFOA Si;\r
+    PROCESS_INFORMATION Pi;\r
+\r
+    Log("Break at line:%d", line);\r
+    \r
+    GetStartupInfoA(&Si);\r
+    Si.dwFlags |= STARTF_USESHOWWINDOW;\r
+    Si.wShowWindow = SW_NORMAL;\r
+\r
+    CreateProcessA(NULL, "cmd.exe", NULL, NULL, FALSE, 0, NULL, NULL, &Si, &Pi);\r
+    WaitForSingleObject(Pi.hProcess, INFINITE);\r
+}\r
+\r
 static const char * GetFileNameInPath(const char *fullpath)\r
 {\r
     int i;\r
@@ -459,6 +476,16 @@ static int IsUTF8Encode(const char *src)
     return 0;\r
 }\r
 \r
+static int Utf16ToUtf8(const WCHAR *src, char *dst)\r
+{\r
+    int len;\r
+    int size;\r
+\r
+    len = (int)wcslen(src) + 1;\r
+    size = WideCharToMultiByte(CP_UTF8, 0, src, len, NULL, 0, NULL, NULL);\r
+    return WideCharToMultiByte(CP_UTF8, 0, src, len, dst, size, NULL, NULL);\r
+}\r
+\r
 static int Utf8ToUtf16(const char* src, WCHAR * dst)\r
 {\r
     int size = MultiByteToWideChar(CP_UTF8, 0, src, -1, dst, 0);\r
@@ -1046,7 +1073,7 @@ End:
     return rc;\r
 }\r
 \r
-static int VentoyRunImdisk(const char *IsoPath, const char *imdiskexe)\r
+static int VentoyRunImdisk(const char *IsoPath, const char *imdiskexe, const char *ExOpt)\r
 {\r
     CHAR Letter;\r
     CHAR Cmdline[512];\r
@@ -1056,7 +1083,16 @@ static int VentoyRunImdisk(const char *IsoPath, const char *imdiskexe)
     Log("VentoyRunImdisk <%s> <%s>", IsoPath, imdiskexe);\r
 \r
     Letter = GetIMDiskMountLogicalDrive();\r
-    sprintf_s(Cmdline, sizeof(Cmdline), "%s -a -o ro -f \"%s\" -m %C:", imdiskexe, IsoPath, Letter);\r
+\r
+    if (ExOpt)\r
+    {\r
+        sprintf_s(Cmdline, sizeof(Cmdline), "%s -a -o ro,%s -f \"%s\" -m %C:", imdiskexe, ExOpt, IsoPath, Letter);\r
+    }\r
+    else\r
+    {\r
+        sprintf_s(Cmdline, sizeof(Cmdline), "%s -a -o ro -f \"%s\" -m %C:", imdiskexe, IsoPath, Letter);\r
+    }\r
+    \r
     Log("mount iso to %C: use imdisk cmd <%s>", Letter, Cmdline);\r
 \r
     if (IsUTF8Encode(IsoPath))\r
@@ -1099,7 +1135,7 @@ int VentoyMountISOByImdisk(const char *IsoPath, DWORD PhyDrive)
 \r
     if (0 == VentoyCopyImdisk(PhyDrive, ImPath))\r
     {\r
-        VentoyRunImdisk(IsoPath, ImPath);\r
+        VentoyRunImdisk(IsoPath, ImPath, NULL);\r
         rc = 0;\r
     }\r
 \r
@@ -2269,6 +2305,75 @@ static BOOL CheckVentoyDisk(DWORD DiskNum)
     return FALSE;\r
 }\r
 \r
+static BOOL VentoyIsLenovoRecovery(CHAR *IsoPath, CHAR *VTLRIPath)\r
+{\r
+    int n;\r
+    int UTF8 = 0;\r
+    HANDLE hFile;\r
+    DWORD Attr;\r
+    WCHAR FilePathW[MAX_PATH];\r
+\r
+    UTF8 = IsUTF8Encode(IsoPath);\r
+\r
+    if (UTF8)\r
+    {\r
+        Utf8ToUtf16(IsoPath, FilePathW);\r
+\r
+        n = (int)wcslen(FilePathW);\r
+        if (n > 4 && _wcsicmp(FilePathW + n - 4, L".iso") == 0)\r
+        {\r
+            FilePathW[n - 3] = L'V';\r
+            FilePathW[n - 2] = L'T';\r
+            FilePathW[n - 1] = L'L';\r
+            FilePathW[n - 0] = L'R';\r
+            FilePathW[n + 1] = L'I';\r
+            FilePathW[n + 2] = 0;\r
+\r
+            hFile = CreateFileW(FilePathW, FILE_READ_EA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);\r
+            if (hFile != INVALID_HANDLE_VALUE)\r
+            {\r
+                CloseHandle(hFile);\r
+                Attr = GetFileAttributesW(FilePathW);\r
+\r
+                if ((Attr & FILE_ATTRIBUTE_DIRECTORY) == 0)\r
+                {\r
+                    Utf16ToUtf8(FilePathW, VTLRIPath);\r
+                    return TRUE;\r
+                }\r
+            }\r
+        }\r
+    }\r
+    else\r
+    {\r
+        n = (int)strlen(IsoPath);\r
+        if (n > 4 && _stricmp(IsoPath + n - 4, ".iso") == 0)\r
+        {\r
+            IsoPath[n - 4] = 0;\r
+            sprintf_s(VTLRIPath, MAX_PATH, "%s.VTLRI", IsoPath);\r
+            IsoPath[n - 4] = '.';\r
+\r
+            if (IsFileExist(VTLRIPath))\r
+            {\r
+                return TRUE;\r
+            }\r
+        }\r
+    }\r
+    \r
+    return FALSE;\r
+}\r
+\r
+static int MountVTLRI(CHAR *ImgPath, DWORD PhyDrive)\r
+{\r
+    CHAR ImDiskPath[256];\r
+    \r
+    Log("MountVTLRI <%s> %u", ImgPath, PhyDrive);\r
+\r
+    VentoyCopyImdisk(PhyDrive, ImDiskPath);\r
+\r
+    VentoyRunImdisk(ImgPath, ImDiskPath, "rem");\r
+\r
+    return 0;\r
+}\r
 \r
 static int VentoyHook(ventoy_os_param *param)\r
 {\r
@@ -2288,6 +2393,7 @@ static int VentoyHook(ventoy_os_param *param)
     DISK_EXTENT VtoyDiskExtent;\r
     UINT8 UUID[16];\r
     CHAR IsoPath[MAX_PATH];\r
+    CHAR VTLRIPath[MAX_PATH];\r
 \r
     Log("VentoyHook Path:<%s>", param->vtoy_img_path);\r
 \r
@@ -2426,8 +2532,17 @@ static int VentoyHook(ventoy_os_param *param)
 \r
     Drives = GetLogicalDrives();\r
     Log("Drives before mount: 0x%x", Drives);\r
-\r
-    rc = MountIsoFile(IsoPath, VtoyDiskNum);\r
+    \r
+    if (VentoyIsLenovoRecovery(IsoPath, VTLRIPath))\r
+    {\r
+        Log("This is lenovo recovery image, mount VTLRI file.");\r
+        rc = MountVTLRI(VTLRIPath, VtoyDiskNum);\r
+    }\r
+    else\r
+    {\r
+        Log("This is normal image, mount ISO file.");\r
+        rc = MountIsoFile(IsoPath, VtoyDiskNum);\r
+    }\r
 \r
     NewDrives = GetLogicalDrives();\r
     Log("Drives after mount: 0x%x (0x%x)", NewDrives, (NewDrives ^ Drives));\r