]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - vtoyjump/vtoyjump/vtoyjump.c
1.0.16 release
[Ventoy.git] / vtoyjump / vtoyjump / vtoyjump.c
index 66efff6ab802472bcc31f3ad3541051e0e493d0f..e4abc4f9095bb286a6c5b1f85ad855fc4eee0d81 100644 (file)
@@ -704,31 +704,76 @@ static int DeleteVentoyPart2MountPoint(DWORD PhyDrive)
     return 1;
 }
 
+static BOOL check_tar_archive(const char *archive, CHAR *tarName)
+{
+    int len;
+    int nameLen;
+    const char *pos = archive;
+    const char *slash = archive;
+
+    while (*pos)
+    {
+        if (*pos == '\\' || *pos == '/')
+        {
+            slash = pos;
+        }
+        pos++;
+    }
+
+    len = (int)strlen(slash);
+
+    if (len > 7 && (strncmp(slash + len - 7, ".tar.gz", 7) == 0 || strncmp(slash + len - 7, ".tar.xz", 7) == 0))
+    {
+        nameLen = (int)sprintf_s(tarName, MAX_PATH, "X:%s", slash);
+        tarName[nameLen - 3] = 0;
+        return TRUE;
+    }
+    else if (len > 8 && strncmp(slash + len - 8, ".tar.bz2", 8) == 0)
+    {
+        nameLen = (int)sprintf_s(tarName, MAX_PATH, "X:%s", slash);
+        tarName[nameLen - 4] = 0;
+        return TRUE;
+    }
+    else if (len > 9 && strncmp(slash + len - 9, ".tar.lzma", 9) == 0)
+    {
+        nameLen = (int)sprintf_s(tarName, MAX_PATH, "X:%s", slash);
+        tarName[nameLen - 5] = 0;
+        return TRUE;
+    }
+
+    return FALSE;
+}
+
 static int DecompressInjectionArchive(const char *archive, DWORD PhyDrive)
 {
     int rc = 1;
     BOOL bRet;
     DWORD dwBytes;
     HANDLE hDrive;
-    CHAR PhyPath[MAX_PATH];
+    HANDLE hOut;
+    DWORD flags = CREATE_NO_WINDOW;
+    CHAR StrBuf[MAX_PATH];
+    CHAR tarName[MAX_PATH];
     STARTUPINFOA Si;
     PROCESS_INFORMATION Pi;
+    PROCESS_INFORMATION NewPi;
     GET_LENGTH_INFORMATION LengthInfo;
+    SECURITY_ATTRIBUTES Sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
 
     Log("DecompressInjectionArchive %s", archive);
 
-    sprintf_s(PhyPath, sizeof(PhyPath), "\\\\.\\PhysicalDrive%d", PhyDrive);
-    hDrive = CreateFileA(PhyPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
+    sprintf_s(StrBuf, sizeof(StrBuf), "\\\\.\\PhysicalDrive%d", PhyDrive);
+    hDrive = CreateFileA(StrBuf, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
     if (hDrive == INVALID_HANDLE_VALUE)
     {
-        Log("Could not open the disk<%s>, error:%u", PhyPath, GetLastError());
+        Log("Could not open the disk<%s>, error:%u", StrBuf, GetLastError());
         goto End;
     }
 
     bRet = DeviceIoControl(hDrive, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &LengthInfo, sizeof(LengthInfo), &dwBytes, NULL);
     if (!bRet)
     {
-        Log("Could not get phy disk %s size, error:%u", PhyPath, GetLastError());
+        Log("Could not get phy disk %s size, error:%u", StrBuf, GetLastError());
         goto End;
     }
 
@@ -750,17 +795,49 @@ static int DecompressInjectionArchive(const char *archive, DWORD PhyDrive)
             CopyFileFromFatDisk("/ventoy/7z/32/7za.exe", "ventoy\\7za.exe");
         }
 
-        sprintf_s(PhyPath, sizeof(PhyPath), "ventoy\\7za.exe x -y -aoa -oX:\\ %s", archive);
+        sprintf_s(StrBuf, sizeof(StrBuf), "ventoy\\7za.exe x -y -aoa -oX:\\ %s", archive);
 
         Log("extract inject to X:");
+        Log("cmdline:<%s>", StrBuf);
 
         GetStartupInfoA(&Si);
 
-        Si.dwFlags |= STARTF_USESHOWWINDOW;
-        Si.wShowWindow = SW_HIDE;
+        hOut = CreateFileA("ventoy\\7z.log",
+            FILE_APPEND_DATA,
+            FILE_SHARE_WRITE | FILE_SHARE_READ,
+            &Sa,
+            OPEN_ALWAYS,
+            FILE_ATTRIBUTE_NORMAL,
+            NULL);
+
+        Si.dwFlags |= STARTF_USESTDHANDLES;
+
+        if (hOut != INVALID_HANDLE_VALUE)
+        {
+            Si.hStdError = hOut;
+            Si.hStdOutput = hOut;
+        }
 
-        CreateProcessA(NULL, PhyPath, NULL, NULL, FALSE, 0, NULL, NULL, &Si, &Pi);
+        CreateProcessA(NULL, StrBuf, NULL, NULL, TRUE, flags, NULL, NULL, &Si, &Pi);
         WaitForSingleObject(Pi.hProcess, INFINITE);
+
+        //
+        // decompress tar archive, for tar.gz/tar.xz/tar.bz2
+        //
+        if (check_tar_archive(archive, tarName))
+        {
+            Log("Decompress tar archive...<%s>", tarName);
+
+            sprintf_s(StrBuf, sizeof(StrBuf), "ventoy\\7za.exe x -y -aoa -oX:\\ %s", tarName);
+
+            CreateProcessA(NULL, StrBuf, NULL, NULL, TRUE, flags, NULL, NULL, &Si, &NewPi);
+            WaitForSingleObject(NewPi.hProcess, INFINITE);
+
+            Log("Now delete %s", tarName);
+            DeleteFileA(tarName);
+        }
+
+        SAFE_CLOSE_HANDLE(hOut);
     }
     fl_shutdown();