Ventoy2Disk.exe update.

1. Add exFAT/NTFS/FAT32 option when install Ventoy
2. Display Ventoy partition file system in physical disk
3. String "Status x%" is missing for translations (#1667)
This commit is contained in:
longpanda
2022-11-16 20:33:14 +08:00
parent ac65c0fb24
commit fdf4693433
20 changed files with 355 additions and 46 deletions

View File

@@ -109,3 +109,19 @@ BOOL DISK_ShrinkVolume(int DriveIndex, const char* VolumeGuid, CHAR DriveLetter,
return ret;
}
BOOL DISK_FormatVolume(char DriveLetter, int fs)
{
BOOL ret = FALSE;
//ret = VDS_FormatVolume(DriveLetter, fs);
if (!ret)
{
//ret = DSPT_FormatVolume(DriveLetter, fs);
if (!ret)
{
ret = PSHELL_FormatVolume(DriveLetter, fs);
}
}
return ret;
}

View File

@@ -39,7 +39,7 @@ BOOL DISK_ChangeVtoyEFIAttr(int DriveIndex, UINT64 Offset, UINT64 Attr);
BOOL DISK_ChangeVtoyEFI2ESP(int DriveIndex, UINT64 Offset);
BOOL DISK_ChangeVtoyEFI2Basic(int DriveIndex, UINT64 Offset);
BOOL DISK_ShrinkVolume(int DriveIndex, const char* VolumeGuid, CHAR DriveLetter, UINT64 OldBytes, UINT64 ReduceBytes);
BOOL DISK_FormatVolume(char DriveLetter, int fs);
//VDS com
@@ -51,10 +51,11 @@ BOOL VDS_ChangeVtoyEFI2ESP(int DriveIndex, UINT64 Offset);
BOOL VDS_ChangeVtoyEFI2Basic(int DriveIndex, UINT64 Offset);
BOOL VDS_ShrinkVolume(int DriveIndex, const char* VolumeGuid, CHAR DriveLetter, UINT64 OldBytes, UINT64 ReduceBytes);
BOOL VDS_IsLastAvaliable(void);
BOOL VDS_FormatVolume(char DriveLetter, int fs);
//diskpart.exe
BOOL DSPT_CleanDisk(int DriveIndex);
BOOL DSPT_FormatVolume(char DriveLetter, int fs);
//powershell.exe
BOOL PSHELL_CleanDisk(int DriveIndex);
@@ -62,6 +63,7 @@ BOOL PSHELL_DeleteVtoyEFIPartition(int DriveIndex, UINT64 EfiPartOffset);
BOOL PSHELL_ChangeVtoyEFI2ESP(int DriveIndex, UINT64 Offset);
BOOL PSHELL_ChangeVtoyEFI2Basic(int DriveIndex, UINT64 Offset);
BOOL PSHELL_ShrinkVolume(int DriveIndex, const char* VolumeGuid, CHAR DriveLetter, UINT64 OldBytes, UINT64 ReduceBytes);
BOOL PSHELL_FormatVolume(char DriveLetter, int fs);
//
// Internel define

View File

@@ -85,3 +85,28 @@ BOOL DSPT_CleanDisk(int DriveIndex)
sprintf_s(CmdBuf, sizeof(CmdBuf), "select disk %d\r\nclean\r\n", DriveIndex);
return DSPT_CommProc(CmdBuf);
}
BOOL DSPT_FormatVolume(char DriveLetter, int fs)
{
const char* fsname = NULL;
CHAR CmdBuf[256];
Log("FormatVolumeByDiskpart <%C:>", DriveLetter);
if (!IsDiskpartExist())
{
return FALSE;
}
if (fs == 1)
{
fsname = "NTFS";
}
else
{
fsname = "FAT32";
}
sprintf_s(CmdBuf, sizeof(CmdBuf), "select volume %C:\r\nformat FS=%s LABEL=Ventoy QUICK OVERRIDE\r\n", DriveLetter, fsname);
return DSPT_CommProc(CmdBuf);
}

View File

@@ -590,6 +590,7 @@ const char *WindowsErrorString(DWORD error_code)
#define IVdsVolume_QueryInterface(This, riid, ppvObject) (This)->lpVtbl->QueryInterface(This, riid, ppvObject)
#define IVdsVolume_Release(This) (This)->lpVtbl->Release(This)
#define IVdsVolumeMF3_QueryVolumeGuidPathnames(This, pwszPathArray, pulNumberOfPaths) (This)->lpVtbl->QueryVolumeGuidPathnames(This,pwszPathArray,pulNumberOfPaths)
#define IVdsVolumeMF_Format(This, type, pwsszLabel, dwUnitAllocationSize, bForce, bQuickFormat, bEnableCompression, ppAsync) (This)->lpVtbl->Format(This, type, pwsszLabel, dwUnitAllocationSize, bForce, bQuickFormat, bEnableCompression, ppAsync)
#define IVdsVolumeMF3_FormatEx2(This, pwszFileSystemTypeName, usFileSystemRevision, ulDesiredUnitAllocationSize, pwszLabel, Options, ppAsync) (This)->lpVtbl->FormatEx2(This, pwszFileSystemTypeName, usFileSystemRevision, ulDesiredUnitAllocationSize, pwszLabel, Options, ppAsync)
#define IVdsVolumeMF3_Release(This) (This)->lpVtbl->Release(This)
#define IVdsVolume_GetProperties(This, pVolumeProperties) (This)->lpVtbl->GetProperties(This,pVolumeProperties)
@@ -1411,4 +1412,92 @@ BOOL VDS_ShrinkVolume(int DriveIndex, const char* VolumeGuid, CHAR DriveLetter,
ret = VDS_VolumeCommProc(INTF_VOLUME, wGuid, VDS_CallBack_ShrinkVolume, (UINT64)&Para);
Log("VDS_ShrinkVolume %C: ret:%d (%s)", DriveLetter, ret, ret ? "SUCCESS" : "FAIL");
return ret;
}
}
STATIC BOOL VDS_CallBack_FormatVolume(void* pInterface, VDS_DISK_PROP* pDiskProp, UINT64 data)
{
HRESULT hr, hr2;
ULONG completed;
IVdsAsync* pAsync;
IVdsVolumeMF3* pVolume = (IVdsVolumeMF3*)pInterface;
WCHAR* pFs = NULL;
WCHAR FsNTFS[32] = L"NTFS";
WCHAR FsFAT32[32] = L"FAT32";
VDS_PARA* VdsPara = (VDS_PARA*)data;
pFs = (VdsPara->Attr == 1) ? FsNTFS : FsFAT32;
Log("VDS_CallBack_FormatVolume (%C:) (%llu) ...", VdsPara->DriveLetter, (ULONGLONG)VdsPara->Attr);
hr = IVdsVolumeMF3_FormatEx2(pVolume, pFs, 0, 0, L"Ventoy", VDS_FSOF_FORCE | VDS_FSOF_QUICK, &pAsync);
while (SUCCEEDED(hr))
{
hr = IVdsAsync_QueryStatus(pAsync, &hr2, &completed);
if (SUCCEEDED(hr))
{
hr = hr2;
if (hr == S_OK)
{
Log("FormatVolume QueryStatus OK, %lu%%", completed);
break;
}
else if (hr == VDS_E_OPERATION_PENDING)
{
Log("FormatVolume: %lu%%", completed);
hr = S_OK;
}
else
{
Log("FormatVolume invalid status:0x%lx", hr);
}
}
Sleep(1000);
}
if (hr != S_OK)
{
VDS_SET_ERROR(hr);
Log("Could not FormatVolume, 0x%x err:0x%lx (%s)", hr, LASTERR, WindowsErrorString(hr));
VDS_SET_ERROR(hr);
return FALSE;
}
return TRUE;
}
BOOL VDS_FormatVolume(char DriveLetter, int fs)
{
int i;
BOOL ret = FALSE;
const char* guid = NULL;
CHAR Drive[32] = { 0 };
WCHAR wGuid[128] = { 0 };
CHAR VolumeGuid[128] = { 0 };
VDS_PARA Para;
Drive[0] = DriveLetter;
Drive[1] = ':';
Drive[2] = '\\';
GetVolumeNameForVolumeMountPointA(Drive, VolumeGuid, sizeof(VolumeGuid) / 2);
guid = strstr(VolumeGuid, "{");
if (!guid)
{
Log("Can not find volume GUID for %s:", Drive);
return FALSE;
}
for (i = 0; i < 128 && guid[i]; i++)
{
wGuid[i] = guid[i];
}
Log("VDS_FormatVolume find GUID %C: <%s> ", DriveLetter, VolumeGuid);
Para.Attr = fs;
Para.DriveLetter = DriveLetter;
ret = VDS_VolumeCommProc(INTF_VOLUME_MF3, wGuid, VDS_CallBack_FormatVolume, (UINT64)&Para);
Log("VDS_FormatVolume %C: <%s> ret:%d (%s)", DriveLetter, VolumeGuid, ret, ret ? "SUCCESS" : "FAIL");
return ret;
}

View File

@@ -255,3 +255,27 @@ BOOL PSHELL_ShrinkVolume(int DriveIndex, const char* VolumeGuid, CHAR DriveLette
Log("PSHELL_ShrinkVolume<%d> %C: ret:%d (%s)", DriveIndex, DriveLetter, ret, ret ? "SUCCESS" : "FAIL");
return ret;
}
BOOL PSHELL_FormatVolume(char DriveLetter, int fs)
{
BOOL ret;
const char* fsname = NULL;
CHAR CmdBuf[512];
if (fs == 1)
{
fsname = "NTFS";
}
else
{
fsname = "FAT32";
}
sprintf_s(CmdBuf, sizeof(CmdBuf),
"format-volume -DriveLetter %C -FileSystem %s -Force -NewFileSystemLabel Ventoy",
DriveLetter, fsname);
ret = PSHELL_CommProc(CmdBuf);
Log("PSHELL_FormatVolume %C: ret:%d (%s)", DriveLetter, ret, ret ? "SUCCESS" : "FAIL");
return ret;
}

View File

@@ -1,38 +1,45 @@
/******************************************************************************
* Language.c
*
* Copyright (c) 2020, 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 "Ventoy2Disk.h"
#include "Language.h"
const TCHAR * GetString(enum STR_ID ID)
{
return g_cur_lang_data->MsgString[ID];
};
static const UINT16 g_unicode_icon[UNICODE_BUTT][3] =
{
{ 0xD83D, 0xDD12, 0x0000 },
};
const UINT16 * GetUnicodeIcon(icon)
{
return g_unicode_icon[icon];
}
/******************************************************************************
* Language.c
*
* Copyright (c) 2020, 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 "Ventoy2Disk.h"
#include "Language.h"
const TCHAR * GetString(enum STR_ID ID)
{
if (g_cur_lang_data)
{
return g_cur_lang_data->MsgString[ID];
}
else
{
return NULL;
}
};
static const UINT16 g_unicode_icon[UNICODE_BUTT][3] =
{
{ 0xD83D, 0xDD12, 0x0000 },
};
const UINT16 * GetUnicodeIcon(icon)
{
return g_unicode_icon[icon];
}

View File

@@ -86,6 +86,8 @@ typedef enum STR_ID
STR_INSTALL_YES_TIP1,//48
STR_INSTALL_YES_TIP2,//49
STR_PART_VENTOY_FS, //50
STR_ID_MAX
}STR_ID;

Binary file not shown.

View File

@@ -1337,6 +1337,7 @@ int ClearVentoyFromPhyDrive(HWND hWnd, PHY_DRIVE_INFO *pPhyDrive, char *pDrvLett
End:
PROGRESS_BAR_SET_POS(PT_MOUNT_VOLUME);
PROGRESS_BAR_SET_POS(PT_REFORMAT_FINISH);
if (pTmpBuf)
{
@@ -1608,6 +1609,7 @@ int InstallVentoy2FileImage(PHY_DRIVE_INFO *pPhyDrive, int PartStyle)
End:
PROGRESS_BAR_SET_POS(PT_MOUNT_VOLUME);
PROGRESS_BAR_SET_POS(PT_REFORMAT_FINISH);
Log("retcode:%d\n", rc);
@@ -1839,6 +1841,7 @@ End:
else
{
Log("%s is ventoy part1, already mounted", DriveName);
MountDrive = DriveName[0];
state = 1;
}
}
@@ -1852,12 +1855,35 @@ End:
DriveName[0] = MountDrive;
bRet = SetVolumeMountPointA(DriveName, DriveLetters);
Log("SetVolumeMountPoint <%s> <%s> bRet:%u code:%u", DriveName, DriveLetters, bRet, GetLastError());
if (bRet)
{
state = 1;
}
}
else
{
Log("Failed to find ventoy volume");
}
}
if (GetVentoyFsType() > 0)
{
if (state)
{
Log("Reformat %C:\\ to %s", MountDrive, GetVentoyFsName());
DISK_FormatVolume(MountDrive, GetVentoyFsType());
}
else
{
Log("Can not reformat %s to %s", DriveName, GetVentoyFsName());
}
}
else
{
Log("No need to reformat ventoy partition");
}
Log("OK\n");
}
else

View File

@@ -251,6 +251,64 @@ static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD *pMBR, UIN
return TRUE;
}
static int GetVentoyFsNameInPhyDrive(PHY_DRIVE_INFO* CurDrive)
{
int i = 0;
UINT64 Offset;
CHAR Volume[128] = { 0 };
CHAR FsName[MAX_PATH] = { 0 };
while (CurDrive->DriveLetters[i])
{
if (GetPhyDriveByLogicalDrive(CurDrive->DriveLetters[i], &Offset) >= 0)
{
if (Offset == SIZE_1MB)
{
sprintf_s(Volume, sizeof(Volume), "%C:\\", CurDrive->DriveLetters[i]);
Log("Find the partition 1 logical drive is %s", Volume);
break;
}
}
i++;
}
sprintf_s(CurDrive->VentoyFsType, sizeof(CurDrive->VentoyFsType), "??");
if (Volume[0])
{
if (GetVolumeInformationA(Volume, NULL, 0, NULL, NULL, NULL, FsName, MAX_PATH))
{
if (_stricmp(FsName, "exFAT") == 0)
{
sprintf_s(CurDrive->VentoyFsType, sizeof(CurDrive->VentoyFsType), "exFAT");
}
else if (_stricmp(FsName, "NTFS") == 0)
{
sprintf_s(CurDrive->VentoyFsType, sizeof(CurDrive->VentoyFsType), "NTFS");
}
else if (_stricmp(FsName, "FAT") == 0 || _stricmp(FsName, "FAT32") == 0)
{
sprintf_s(CurDrive->VentoyFsType, sizeof(CurDrive->VentoyFsType), "FAT32");
}
else
{
sprintf_s(CurDrive->VentoyFsType, sizeof(CurDrive->VentoyFsType), "%s", FsName);
}
Log("GetVentoyFsNameInPhyDrive %d %s <%s> <%s>", CurDrive->PhyDrive, Volume, FsName, CurDrive->VentoyFsType);
}
else
{
Log("GetVolumeInformationA %s failed %u", Volume, LASTERR);
}
}
else
{
Log("GetVentoyFsNameInPhyDrive %s not found", Volume);
}
return 0;
}
static int FilterPhysicalDrive(PHY_DRIVE_INFO *pDriveList, DWORD DriveCount)
{
@@ -323,6 +381,8 @@ static int FilterPhysicalDrive(PHY_DRIVE_INFO *pDriveList, DWORD DriveCount)
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);
GetVentoyFsNameInPhyDrive(CurDrive);
if (CurDrive->VentoyVersion[0] == 0)
{
CurDrive->VentoyVersion[0] = '?';

View File

@@ -159,7 +159,8 @@ typedef struct PHY_DRIVE_INFO
STORAGE_BUS_TYPE BusType;
CHAR DriveLetters[64];
CHAR VentoyFsType[16];
CHAR VentoyVersion[32];
BOOL SecureBootSupport;
@@ -193,6 +194,9 @@ typedef enum PROGRESS_POINT
PT_WRITE_PART_TABLE,
PT_MOUNT_VOLUME,
PT_REFORMAT_START,
PT_REFORMAT_FINISH = PT_REFORMAT_START + 2,
PT_FINISH
}PROGRESS_POINT;
@@ -253,6 +257,9 @@ INT_PTR CALLBACK YesDialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lP
INT_PTR CALLBACK PartDialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
int GetReservedSpaceInMB(void);
int IsPartNeed4KBAlign(void);
int GetVentoyFsType(void);
void SetVentoyFsType(int fs);
const char* GetVentoyFsName(void);
int FindProcessOccupyDisk(HANDLE hDrive, PHY_DRIVE_INFO *pPhyDrive);
int VentoyFillMBRLocation(UINT64 DiskSizeInBytes, UINT32 StartSectorId, UINT32 SectorCount, PART_TABLE *Table);
int ClearVentoyFromPhyDrive(HWND hWnd, PHY_DRIVE_INFO *pPhyDrive, char *pDrvLetter);

Binary file not shown.

Binary file not shown.