Commit 1473be0e authored by longpanda's avatar longpanda
Browse files

Improve the success rate of Ventoy2Disk.exe installation and upgrade

parent cd9aa16b
No preview for this file type
......@@ -133,6 +133,8 @@ function vt_check_compatible_pe {
#set compatible if ISO file is less than 80MB
if [ $vt_chosen_size -gt 33554432 -a $vt_chosen_size -le 83886080 ]; then
set ventoy_compatible=YES
elif [ -e $1/WEPE/WEPE.INI ]; then
set ventoy_compatible=YES
fi
return
......@@ -328,6 +330,8 @@ function distro_specify_initrd_file_phase2 {
vt_linux_specify_initrd_file /360Disk/initrd.gz
elif [ -f (loop)/porteus/initrd.xz ]; then
vt_linux_specify_initrd_file /porteus/initrd.xz
elif [ -f (loop)/pyabr/boot/initrfs.img ]; then
vt_linux_specify_initrd_file /pyabr/boot/initrfs.img
fi
}
......
/******************************************************************************
* DiskService.h
*
* Copyright (c) 2021, longpanda <admin@ventoy.net>
*
* 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 the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __DISKSERVICE_H__
#define __DISKSERVICE_H__
typedef struct VDS_PARA
{
UINT64 Attr;
GUID Type;
GUID Id;
WCHAR Name[36];
ULONG NameLen;
ULONGLONG Offset;
}VDS_PARA;
//VDS com
int VDS_Init(void);
BOOL VDS_CleanDisk(int DriveIndex);
BOOL VDS_DeleteAllPartitions(int DriveIndex);
BOOL VDS_DeleteVtoyEFIPartition(int DriveIndex);
BOOL VDS_ChangeVtoyEFIAttr(int DriveIndex, UINT64 Attr);
BOOL VDS_CreateVtoyEFIPart(int DriveIndex, UINT64 Offset);
BOOL VDS_ChangeVtoyEFI2ESP(int DriveIndex, UINT64 Offset);
BOOL VDS_ChangeVtoyEFI2Basic(int DriveIndex, UINT64 Offset);
//diskpart.exe
BOOL DSPT_CleanDisk(int DriveIndex);
//
// Internel define
//
#endif
/******************************************************************************
* DiskService_diskpart.c
*
* Copyright (c) 2021, longpanda <admin@ventoy.net>
*
* 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 the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include <Windows.h>
#include <winternl.h>
#include <commctrl.h>
#include <initguid.h>
#include <vds.h>
#include "Ventoy2Disk.h"
#include "DiskService.h"
STATIC BOOL IsDiskpartExist(void)
{
BOOL ret;
ret = IsFileExist("C:\\Windows\\system32\\diskpart.exe");
if (!ret)
{
Log("diskpart.exe not exist");
}
return ret;
}
STATIC BOOL DSPT_CommProc(const char *Cmd)
{
CHAR CmdBuf[MAX_PATH];
CHAR CmdFile[MAX_PATH];
STARTUPINFOA Si;
PROCESS_INFORMATION Pi;
GetCurrentDirectoryA(sizeof(CmdBuf), CmdBuf);
sprintf_s(CmdFile, sizeof(CmdFile), "%s\\ventoy\\diskpart_%u.txt", CmdBuf, GetCurrentProcessId());
SaveBufToFile(CmdFile, Cmd, strlen(Cmd));
GetStartupInfoA(&Si);
Si.dwFlags |= STARTF_USESHOWWINDOW;
Si.wShowWindow = SW_HIDE;
sprintf_s(CmdBuf, sizeof(CmdBuf), "C:\\Windows\\system32\\diskpart.exe /s \"%s\"", CmdFile);
Log("CreateProcess <%s>", CmdBuf);
CreateProcessA(NULL, CmdBuf, NULL, NULL, FALSE, 0, NULL, NULL, &Si, &Pi);
Log("Wair process ...");
WaitForSingleObject(Pi.hProcess, INFINITE);
Log("Process finished...");
DeleteFileA(CmdFile);
return TRUE;
}
BOOL DSPT_CleanDisk(int DriveIndex)
{
CHAR CmdBuf[128];
Log("CleanDiskByDiskpart <%d>", DriveIndex);
if (!IsDiskpartExist())
{
return FALSE;
}
sprintf_s(CmdBuf, sizeof(CmdBuf), "select disk %d\r\nclean\r\n", DriveIndex);
return DSPT_CommProc(CmdBuf);
}
This diff is collapsed.
/******************************************************************************
* DiskService_wsma.c
*
* Copyright (c) 2021, longpanda <admin@ventoy.net>
*
* 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 the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include <Windows.h>
#include <winternl.h>
#include <commctrl.h>
#include <initguid.h>
#include <vds.h>
#include "Ventoy2Disk.h"
#include "DiskService.h"
This diff is collapsed.
/******************************************************************************
* Utility.c
*
* Copyright (c) 2020, longpanda <admin@ventoy.net>
* Copyright (c) 2021, longpanda <admin@ventoy.net>
* Copyright (c) 2011-2020, Pete Batard <pete@akeo.ie>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -20,6 +21,25 @@
#include <Windows.h>
#include "Ventoy2Disk.h"
void TraceOut(const char *Fmt, ...)
{
va_list Arg;
int Len = 0;
FILE *File = NULL;
char szBuf[1024];
va_start(Arg, Fmt);
Len += vsnprintf_s(szBuf + Len, sizeof(szBuf)-Len, sizeof(szBuf)-Len, Fmt, Arg);
va_end(Arg);
fopen_s(&File, VENTOY_FILE_LOG, "a+");
if (File)
{
fwrite(szBuf, 1, Len, File);
fclose(File);
}
}
void Log(const char *Fmt, ...)
{
va_list Arg;
......@@ -92,6 +112,22 @@ BOOL IsPathExist(BOOL Dir, const char *Fmt, ...)
return TRUE;
}
int SaveBufToFile(const CHAR *FileName, const void *Buffer, int BufLen)
{
FILE *File = NULL;
void *Data = NULL;
fopen_s(&File, FileName, "wb");
if (File == NULL)
{
Log("Failed to open file %s", FileName);
return 1;
}
fwrite(Buffer, 1, BufLen, File);
fclose(File);
return 0;
}
int ReadWholeFileToBuf(const CHAR *FileName, int ExtLen, void **Bufer, int *BufLen)
{
......@@ -205,73 +241,239 @@ BOOL IsWow64(void)
return bIsWow64;
}
void DumpWindowsVersion(void)
/*
* Some code and functions in the file are copied from rufus.
* https://github.com/pbatard/rufus
*/
/* Windows versions */
enum WindowsVersion {
WINDOWS_UNDEFINED = -1,
WINDOWS_UNSUPPORTED = 0,
WINDOWS_XP = 0x51,
WINDOWS_2003 = 0x52, // Also XP_64
WINDOWS_VISTA = 0x60, // Also Server 2008
WINDOWS_7 = 0x61, // Also Server 2008_R2
WINDOWS_8 = 0x62, // Also Server 2012
WINDOWS_8_1 = 0x63, // Also Server 2012_R2
WINDOWS_10_PREVIEW1 = 0x64,
WINDOWS_10 = 0xA0, // Also Server 2016, also Server 2019
WINDOWS_11 = 0xB0, // Also Server 2022
WINDOWS_MAX
};
static const char* GetEdition(DWORD ProductType)
{
int Bit;
BOOL WsVer;
DWORD Major, Minor;
ULONGLONG MajorEqual, MinorEqual;
OSVERSIONINFOEXA Ver1, Ver2;
const CHAR *Ver = NULL;
CHAR WinVer[256] = { 0 };
memset(&Ver1, 0, sizeof(Ver1));
memset(&Ver2, 0, sizeof(Ver2));
Ver1.dwOSVersionInfoSize = sizeof(Ver1);
// From: https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getproductinfo
// These values can be found in the winnt.h header.
switch (ProductType) {
case 0x00000000: return ""; // Undefined
case 0x00000001: return "Ultimate";
case 0x00000002: return "Home Basic";
case 0x00000003: return "Home Premium";
case 0x00000004: return "Enterprise";
case 0x00000005: return "Home Basic N";
case 0x00000006: return "Business";
case 0x00000007: return "Standard Server";
case 0x00000008: return "Datacenter Server";
case 0x00000009: return "Smallbusiness Server";
case 0x0000000A: return "Enterprise Server";
case 0x0000000B: return "Starter";
case 0x00000010: return "Business N";
case 0x00000011: return "Web Server";
case 0x00000012: return "Cluster Server";
case 0x00000013: return "Home Server";
case 0x0000001A: return "Home Premium N";
case 0x0000001B: return "Enterprise N";
case 0x0000001C: return "Ultimate N";
case 0x00000022: return "Home Premium Server";
case 0x0000002F: return "Starter N";
case 0x00000030: return "Pro";
case 0x00000031: return "Pro N";
case 0x00000042: return "Starter E";
case 0x00000043: return "Home Basic E";
case 0x00000044: return "Premium E";
case 0x00000045: return "Pro E";
case 0x00000046: return "Enterprise E";
case 0x00000047: return "Ultimate E";
case 0x00000048: return "Enterprise Eval";
case 0x00000054: return "Enterprise N Eval";
case 0x00000057: return "Thin PC";
case 0x0000006F: return "Core Connected";
case 0x00000070: return "Pro Student";
case 0x00000071: return "Core Connected N";
case 0x00000072: return "Pro Student N";
case 0x00000073: return "Core Connected Single Language";
case 0x00000074: return "Core Connected China";
case 0x00000079: return "Edu";
case 0x0000007A: return "Edu N";
case 0x0000007D: return "Enterprise S";
case 0x0000007E: return "Enterprise S N";
case 0x0000007F: return "Pro S";
case 0x00000080: return "Pro S N";
case 0x00000081: return "Enterprise S Eval";
case 0x00000082: return "Enterprise S N Eval";
case 0x0000008A: return "Pro Single Language";
case 0x0000008B: return "Pro China";
case 0x0000008C: return "Enterprise Subscription";
case 0x0000008D: return "Enterprise Subscription N";
case 0x00000095: return "Utility VM";
case 0x000000A1: return "Pro Workstation";
case 0x000000A2: return "Pro Workstation N";
case 0x000000A4: return "Pro for Education";
case 0x000000A5: return "Pro for Education N";
case 0x000000AB: return "Enterprise G"; // I swear Microsoft are just making up editions...
case 0x000000AC: return "Enterprise G N";
case 0x000000B6: return "Core OS";
case 0x000000B7: return "Cloud E";
case 0x000000B8: return "Cloud E N";
case 0x000000BD: return "Lite";
case 0xABCDABCD: return "(Unlicensed)";
default: return "(Unknown Edition)";
}
}
#define is_x64 IsWow64
#define static_strcpy safe_strcpy
#define REGKEY_HKCU HKEY_CURRENT_USER
#define REGKEY_HKLM HKEY_LOCAL_MACHINE
static int nWindowsVersion = WINDOWS_UNDEFINED;
static int nWindowsBuildNumber = -1;
static char WindowsVersionStr[128] = "";
/* Helpers for 32 bit registry operations */
/*
* Read a generic registry key value. If a short key_name is used, assume that
* it belongs to the application and create the app subkey if required
*/
static __inline BOOL _GetRegistryKey(HKEY key_root, const char* key_name, DWORD reg_type,
LPBYTE dest, DWORD dest_size)
{
const char software_prefix[] = "SOFTWARE\\";
char long_key_name[MAX_PATH] = { 0 };
BOOL r = FALSE;
size_t i;
LONG s;
HKEY hSoftware = NULL, hApp = NULL;
DWORD dwType = -1, dwSize = dest_size;
memset(dest, 0, dest_size);
if (key_name == NULL)
return FALSE;
for (i = strlen(key_name); i>0; i--) {
if (key_name[i] == '\\')
break;
}
if (i > 0) {
// Prefix with "SOFTWARE" if needed
if (_strnicmp(key_name, software_prefix, sizeof(software_prefix)-1) != 0) {
if (i + sizeof(software_prefix) >= sizeof(long_key_name))
return FALSE;
strcpy_s(long_key_name, sizeof(long_key_name), software_prefix);
strcat_s(long_key_name, sizeof(long_key_name), key_name);
long_key_name[sizeof(software_prefix)+i - 1] = 0;
}
else {
if (i >= sizeof(long_key_name))
return FALSE;
static_strcpy(long_key_name, key_name);
long_key_name[i] = 0;
}
i++;
if (RegOpenKeyExA(key_root, long_key_name, 0, KEY_READ, &hApp) != ERROR_SUCCESS) {
hApp = NULL;
goto out;
}
}
else {
if (RegOpenKeyExA(key_root, "SOFTWARE", 0, KEY_READ | KEY_CREATE_SUB_KEY, &hSoftware) != ERROR_SUCCESS) {
hSoftware = NULL;
goto out;
}
}
s = RegQueryValueExA(hApp, &key_name[i], NULL, &dwType, (LPBYTE)dest, &dwSize);
// No key means default value of 0 or empty string
if ((s == ERROR_FILE_NOT_FOUND) || ((s == ERROR_SUCCESS) && (dwType == reg_type) && (dwSize > 0))) {
r = TRUE;
}
out:
if (hSoftware != NULL)
RegCloseKey(hSoftware);
if (hApp != NULL)
RegCloseKey(hApp);
return r;
}
#define GetRegistryKey32(root, key, pval) _GetRegistryKey(root, key, REG_DWORD, (LPBYTE)pval, sizeof(DWORD))
static __inline INT32 ReadRegistryKey32(HKEY root, const char* key) {
DWORD val;
GetRegistryKey32(root, key, &val);
return (INT32)val;
}
/*
* Modified from smartmontools' os_win32.cpp
*/
void GetWindowsVersion(void)
{
OSVERSIONINFOEXA vi, vi2;
DWORD dwProductType;
const char* w = 0;
const char* w64 = "32 bit";
char *vptr;
size_t vlen;
unsigned major, minor;
ULONGLONG major_equal, minor_equal;
BOOL ws;
nWindowsVersion = WINDOWS_UNDEFINED;
static_strcpy(WindowsVersionStr, "Windows Undefined");
// suppress the C4996 warning for GetVersionExA
#pragma warning(push)
#pragma warning(disable:4996)
if (!GetVersionExA((OSVERSIONINFOA *)&Ver1))
{
memset(&Ver1, 0, sizeof(Ver1));
Ver1.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
if (!GetVersionExA((OSVERSIONINFOA *)&Ver1))
{
memset(&vi, 0, sizeof(vi));
vi.dwOSVersionInfoSize = sizeof(vi);
if (!GetVersionExA((OSVERSIONINFOA *)&vi)) {
memset(&vi, 0, sizeof(vi));
vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
if (!GetVersionExA((OSVERSIONINFOA *)&vi))
return;
}
}
#pragma warning(pop)
if (Ver1.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
if (Ver1.dwMajorVersion > 6 || (Ver1.dwMajorVersion == 6 && Ver1.dwMinorVersion >= 2))
{
// GetVersionEx() has problem on some Windows version
if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
MajorEqual = VerSetConditionMask(0, VER_MAJORVERSION, VER_EQUAL);
for (Major = Ver1.dwMajorVersion; Major <= 9; Major++)
{
memset(&Ver2, 0, sizeof(Ver2));
Ver2.dwOSVersionInfoSize = sizeof(Ver2);
Ver2.dwMajorVersion = Major;
if (vi.dwMajorVersion > 6 || (vi.dwMajorVersion == 6 && vi.dwMinorVersion >= 2)) {
// Starting with Windows 8.1 Preview, GetVersionEx() does no longer report the actual OS version
// See: http://msdn.microsoft.com/en-us/library/windows/desktop/dn302074.aspx
// And starting with Windows 10 Preview 2, Windows enforces the use of the application/supportedOS
// manifest in order for VerSetConditionMask() to report the ACTUAL OS major and minor...
if (!VerifyVersionInfoA(&Ver2, VER_MAJORVERSION, MajorEqual))
{
major_equal = VerSetConditionMask(0, VER_MAJORVERSION, VER_EQUAL);
for (major = vi.dwMajorVersion; major <= 9; major++) {
memset(&vi2, 0, sizeof(vi2));
vi2.dwOSVersionInfoSize = sizeof(vi2); vi2.dwMajorVersion = major;
if (!VerifyVersionInfoA(&vi2, VER_MAJORVERSION, major_equal))
continue;
if (vi.dwMajorVersion < major) {
vi.dwMajorVersion = major; vi.dwMinorVersion = 0;
}
if (Ver1.dwMajorVersion < Major)
{
Ver1.dwMajorVersion = Major;
Ver1.dwMinorVersion = 0;
}
MinorEqual = VerSetConditionMask(0, VER_MINORVERSION, VER_EQUAL);
for (Minor = Ver1.dwMinorVersion; Minor <= 9; Minor++)
{
memset(&Ver2, 0, sizeof(Ver2));
Ver2.dwOSVersionInfoSize = sizeof(Ver2);
Ver2.dwMinorVersion = Minor;
if (!VerifyVersionInfoA(&Ver2, VER_MINORVERSION, MinorEqual))
{
minor_equal = VerSetConditionMask(0, VER_MINORVERSION, VER_EQUAL);
for (minor = vi.dwMinorVersion; minor <= 9; minor++) {
memset(&vi2, 0, sizeof(vi2)); vi2.dwOSVersionInfoSize = sizeof(vi2);
vi2.dwMinorVersion = minor;
if (!VerifyVersionInfoA(&vi2, VER_MINORVERSION, minor_equal))
continue;
}
Ver1.dwMinorVersion = Minor;
vi.dwMinorVersion = minor;
break;
}
......@@ -279,84 +481,81 @@ void DumpWindowsVersion(void)
}
}
if (Ver1.dwMajorVersion <= 0xF && Ver1.dwMinorVersion <= 0xF)
{
WsVer = (Ver1.wProductType <= VER_NT_WORKSTATION);
switch ((Ver1.dwMajorVersion << 4) | Ver2.dwMinorVersion)
{
case 0x51:
{
Ver = "XP";
break;
}
case 0x52:
{
Ver = GetSystemMetrics(89) ? "Server 2003 R2" : "Server 2003";
break;
}
case 0x60:
{
Ver = WsVer ? "Vista" : "Server 2008";
break;
}
case 0x61:
{
Ver = WsVer ? "7" : "Server 2008 R2";
break;
}
case 0x62:
{
Ver = WsVer ? "8" : "Server 2012";
break;
}
case 0x63:
{
Ver = WsVer ? "8.1" : "Server 2012 R2";
break;
}
case 0x64:
{
Ver = WsVer ? "10 (Preview 1)" : "Server 10 (Preview 1)";
break;
}
case 0xA0:
{
Ver = WsVer ? "10" : ((Ver1.dwBuildNumber > 15000) ? "Server 2019" : "Server 2016");
break;
}
default:
{
Ver = "10 or later";
if (vi.dwMajorVersion <= 0xf && vi.dwMinorVersion <= 0xf) {
ws = (vi.wProductType <= VER_NT_WORKSTATION);
nWindowsVersion = vi.dwMajorVersion << 4 | vi.dwMinorVersion;
switch (nWindowsVersion) {
case WINDOWS_XP: w = "XP";
break;
case WINDOWS_2003: w = (ws ? "XP_64" : (!GetSystemMetrics(89) ? "Server 2003" : "Server 2003_R2"));
break;
case WINDOWS_VISTA: w = (ws ? "Vista" : "Server 2008");
break;
case WINDOWS_7: w = (ws ? "7" : "Server 2008_R2");
break;
case WINDOWS_8: w = (ws ? "8" : "Server 2012");
break;
case WINDOWS_8_1: w = (ws ? "8.1" : "Server 2012_R2");
break;
case WINDOWS_10_PREVIEW1: w = (ws ? "10 (Preview 1)" : "Server 10 (Preview 1)");
break;
// Starting with Windows 10 Preview 2, the major is the same as the public-facing version
case WINDOWS_10:
if (vi.dwBuildNumber < 20000) {
w = (ws ? "10" : ((vi.dwBuildNumber < 17763) ? "Server 2016" : "Server 2019"));
break;
}
nWindowsVersion = WINDOWS_11;
// Fall through
case WINDOWS_11: w = (ws ? "11" : "Server 2022");
break;
default:
if (nWindowsVersion < WINDOWS_XP)
nWindowsVersion = WINDOWS_UNSUPPORTED;
else
w = "12 or later";
break;
}
}
}
Bit = IsWow64() ? 64 : 32;
if (is_x64())
w64 = "64-bit";
if (Ver1.wServicePackMinor)
{
safe_sprintf(WinVer, "Windows %s SP%u.%u %d-bit", Ver, Ver1.wServicePackMajor, Ver1.wServicePackMinor, Bit);
}
else if (Ver1.wServicePackMajor)
{
safe_sprintf(WinVer, "Windows %s SP%u %d-bit", Ver, Ver1.wServicePackMajor, Bit);
}
else
{
safe_sprintf(WinVer, "Windows %s %d-bit", Ver, Bit);
}
GetProductInfo(vi.dwMajorVersion, vi.dwMinorVersion, vi.wServicePackMajor, vi.wServicePackMinor, &dwProductType);
vptr = WindowsVersionStr;
vlen = sizeof(WindowsVersionStr) - 1;
if (((Ver1.dwMajorVersion << 4) | Ver2.dwMinorVersion) >= 0x62)
{
Log("Windows Version : %s (Build %u)", WinVer, Ver1.dwBuildNumber);
}
if (!w)
sprintf_s(vptr, vlen, "%s %u.%u %s", (vi.dwPlatformId == VER_PLATFORM_WIN32_NT ? "NT" : "??"),
(unsigned)vi.dwMajorVersion, (unsigned)vi.dwMinorVersion, w64);
else if (vi.wServicePackMinor)
sprintf_s(vptr, vlen, "%s SP%u.%u %s", w, vi.wServicePackMajor, vi.wServicePackMinor, w64);
else if (vi.wServicePackMajor)
sprintf_s(vptr, vlen, "%s SP%u %s", w, vi.wServicePackMajor, w64);
else
{
Log("Windows Version : %s", WinVer);
sprintf_s(vptr, vlen, "%s%s%s, %s",
w, (dwProductType != PRODUCT_UNDEFINED) ? " " : "", GetEdition(dwProductType), w64);
// Add the build number (including UBR if available) for Windows 8.0 and later
nWindowsBuildNumber = vi.dwBuildNumber;
if (nWindowsVersion >= 0x62) {
int nUbr = ReadRegistryKey32(REGKEY_HKLM, "Software\\Microsoft\\Windows NT\\CurrentVersion\\UBR");
vptr = WindowsVersionStr + strlen(WindowsVersionStr);
vlen = sizeof(WindowsVersionStr) - strlen(WindowsVersionStr) - 1;
if (nUbr > 0)
sprintf_s(vptr, vlen, " (Build %d.%d)", nWindowsBuildNumber, nUbr);
else
sprintf_s(vptr, vlen, " (Build %d)", nWindowsBuildNumber);
}
}
void DumpWindowsVersion(void)
{
GetWindowsVersion();
Log("Windows Version: <<Windows %s>>", WindowsVersionStr);
return;
}
......
......@@ -71,7 +71,7 @@ int ParseCmdLineOption(LPSTR lpCmdLine)
return 0;
}
static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD *pMBR, UINT64 *Part2StartSector)
static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD *pMBR, UINT64 *Part2StartSector, UINT64 *GptPart2Attr)
{
int i;
BOOL bRet;
......@@ -149,7 +149,15 @@ static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD *pMBR, UIN
if (memcmp(pGpt->PartTbl[1].Name, L"VTOYEFI", 7 * 2))
{
Log("Invalid ventoy efi part name");
if (pGpt->PartTbl[1].Name[0])
{
Log("Invalid ventoy efi part name <%S>", pGpt->PartTbl[1].Name);
}
else
{
Log("Invalid ventoy efi part name <null>");
}
return FALSE;
}
......@@ -170,6 +178,7 @@ static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD *pMBR, UIN
return FALSE;
}
*GptPart2Attr = pGpt->PartTbl[1].Attr;
*Part2StartSector = pGpt->PartTbl[1].StartLBA;
memcpy(pMBR, &(pGpt->MBR), sizeof(MBR_HEAD));
......@@ -225,6 +234,7 @@ static int FilterPhysicalDrive(PHY_DRIVE_INFO *pDriveList, DWORD DriveCount)
int Letter = 'A';
int Id = 0;
int LetterCount = 0;
UINT64 Part2GPTAttr = 0;
UINT64 Part2StartSector = 0;
PHY_DRIVE_INFO *CurDrive;
MBR_HEAD MBR;
......@@ -247,6 +257,7 @@ static int FilterPhysicalDrive(PHY_DRIVE_INFO *pDriveList, DWORD DriveCount)
for (i = 0; i < DriveCount; i++)
{
Part2GPTAttr = 0;
CurDrive = pDriveList + i;
CurDrive->Id = -1;
......@@ -278,10 +289,11 @@ static int FilterPhysicalDrive(PHY_DRIVE_INFO *pDriveList, DWORD DriveCount)
}
}
if (IsVentoyPhyDrive(CurDrive->PhyDrive, CurDrive->SizeInBytes, &MBR, &Part2StartSector))
if (IsVentoyPhyDrive(CurDrive->PhyDrive, CurDrive->SizeInBytes, &MBR, &Part2StartSector, &Part2GPTAttr))
{
memcpy(&(CurDrive->MBR), &MBR, sizeof(MBR));
CurDrive->PartStyle = (MBR.PartTbl[0].FsFlag == 0xEE) ? 1 : 0;
CurDrive->Part2GPTAttr = Part2GPTAttr;
GetVentoyVerInPhyDrive(CurDrive, Part2StartSector, CurDrive->VentoyVersion, sizeof(CurDrive->VentoyVersion), &(CurDrive->SecureBootSupport));
Log("PhyDrive %d is Ventoy Disk ver:%s SecureBoot:%u", CurDrive->PhyDrive, CurDrive->VentoyVersion, CurDrive->SecureBootSupport);
......
......@@ -53,6 +53,7 @@
}
#define LASTERR GetLastError()
#define RET_LASTERR (ret ? 0 : LASTERR)
#pragma pack(1)
typedef struct PART_TABLE
......@@ -153,12 +154,13 @@ typedef struct PHY_DRIVE_INFO
BOOL SecureBootSupport;
MBR_HEAD MBR;
UINT64 Part2GPTAttr;
}PHY_DRIVE_INFO;
typedef enum PROGRESS_POINT
{
PT_START = 0,
PT_LOCK_FOR_CLEAN,
PT_LOCK_FOR_CLEAN = 8,
PT_DEL_ALL_PART,
PT_LOCK_FOR_WRITE,
PT_FORMAT_PART1,
......@@ -185,6 +187,7 @@ extern HFONT g_language_normal_font;
extern HFONT g_language_bold_font;
extern int g_FilterUSB;
void TraceOut(const char *Fmt, ...);
void Log(const char *Fmt, ...);
BOOL IsPathExist(BOOL Dir, const char *Fmt, ...);
void DumpWindowsVersion(void);
......@@ -207,11 +210,12 @@ int Ventoy2DiskInit(void);
int Ventoy2DiskDestroy(void);
PHY_DRIVE_INFO * GetPhyDriveInfoById(int Id);
int ParseCmdLineOption(LPSTR lpCmdLine);
int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int PartStyle);
int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive);
int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int PartStyle, int TryId);
int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int TryId);
int VentoyFillBackupGptHead(VTOY_GPT_INFO *pInfo, VTOY_GPT_HDR *pHead);
int VentoyFillWholeGpt(UINT64 DiskSizeBytes, VTOY_GPT_INFO *pInfo);
void SetProgressBarPos(int Pos);
int SaveBufToFile(const CHAR *FileName, const void *Buffer, int BufLen);
int ReadWholeFileToBuf(const CHAR *FileName, int ExtLen, void **Bufer, int *BufLen);
int INIT unxz(unsigned char *in, int in_size,
int(*fill)(void *dest, unsigned int size),
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -92,6 +92,9 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="crc32.c" />
<ClCompile Include="DiskService_diskpart.c" />
<ClCompile Include="DiskService_vds.c" />
<ClCompile Include="DiskService_wmsa.c" />
<ClCompile Include="fat_io_lib\fat_access.c" />
<ClCompile Include="fat_io_lib\fat_cache.c" />
<ClCompile Include="fat_io_lib\fat_filelib.c" />
......@@ -115,6 +118,7 @@
<ClCompile Include="xz-embedded-20130513\linux\lib\decompress_unxz.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="DiskService.h" />
<ClInclude Include="fat_io_lib\fat_access.h" />
<ClInclude Include="fat_io_lib\fat_cache.h" />
<ClInclude Include="fat_io_lib\fat_defs.h" />
......
......@@ -81,6 +81,15 @@
<ClCompile Include="VentoyJson.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="DiskService_diskpart.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="DiskService_vds.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="DiskService_wmsa.c">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Ventoy2Disk.h">
......@@ -143,6 +152,9 @@
<ClInclude Include="VentoyJson.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="DiskService.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Ventoy2Disk.rc">
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment