提交 647d9f18 编写于 作者: P Pete Batard

[misc] refactoring and cleanup - part 2

* add GetResource() function call to handle resource loading and
  revert 98ff7a93
* add separate BootCheck() call
* better handling of passes tooltip
* remove superfluous backslashes
* fix standalone EFI support
* add GPL v3 license file and update README.txt
上级 bba17729
此差异已折叠。
......@@ -3,19 +3,19 @@ Rufus: The Reliable USB Formatting Utility
Features:
- Formats USB flash drives to FAT/FAT32/NTFS/exFAT
- Creates DOS bootable USB drives, with no external files required
- Creates bootable USB drives from bootable ISOs (Windows, Linux, etc.)
- Creates bootable USB drives from bootable ISOs (Windows, Linux, EFI, etc.)
- Twice as fast as Microsoft's USB/DVD tool or UNetbootin, on ISO->USB (1)
- Bad blocks check, with detection for fake capacity
- Modern UI, with UAC elevation for Windows Vista and later
- Modern UI
- Small footprint, no installation required
- 100% Free Source Software (GPL v3)
Compilation:
Use either Visual Studio 2010, WDK (Windows Driver Kit) or MinGW and then
Use either Visual Studio 2012, WDK 7.1 (Windows Driver Kit) or MinGW and then
invoke the .sln, wdk_build.cmd or configure/make respectively.
Additional information:
Rufus provides extensive information about what it is doing through its easily
Rufus provides extensive information about what it is doing, through its easily
accessible log or the Windows debug facility.
More info:
......
......@@ -27,14 +27,15 @@
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rufus.h"
#include "dos.h"
#include "resource.h"
static BYTE* DiskImage;
static size_t DiskImageSize;
static BYTE* DiskImage = NULL;
static DWORD DiskImageSize;
/*
* FAT time conversion, from ReactOS' time.c
......@@ -166,57 +167,37 @@ static void FatDateTimeToSystemTime(PLARGE_INTEGER SystemTime, PFAT_DATETIME Fat
* IO.SYS 000003AA 75 -> EB
* COMMAND.COM 00006510 75 -> EB
*/
static BOOL Patch_COMMAND_COM(HANDLE hFile)
static BOOL Patch_COMMAND_COM(size_t filestart, size_t filesize)
{
const BYTE expected[8] = { 0x15, 0x80, 0xFA, 0x03, 0x75, 0x10, 0xB8, 0x0E };
BYTE data[sizeof(expected)] = { 0x00 };
DWORD size = sizeof(data);
uprintf("Patching COMMAND.COM...\n");
if (GetFileSize(hFile, NULL) != 93040) {
if (filesize != 93040) {
uprintf(" unexpected file size\n");
return FALSE;
}
SetFilePointer(hFile, 0x650c, NULL, FILE_BEGIN);
if (!ReadFile(hFile, data, size, &size, NULL)) {
uprintf(" could not read data\n");
return FALSE;
}
if (memcmp(data, expected, sizeof(expected)) != 0) {
if (memcmp(&DiskImage[filestart+0x650c], expected, sizeof(expected)) != 0) {
uprintf(" unexpected binary data\n");
return FALSE;
}
data[4] = 0xeb;
SetFilePointer(hFile, 0x650c, NULL, FILE_BEGIN);
size = sizeof(data);
WriteFile(hFile, data, size, &size, NULL);
DiskImage[filestart+0x6510] = 0xeb;
return TRUE;
}
static BOOL Patch_IO_SYS(HANDLE hFile)
static BOOL Patch_IO_SYS(size_t filestart, size_t filesize)
{
const BYTE expected[8] = { 0xFA, 0x80, 0x75, 0x09, 0x8D, 0xB6, 0x99, 0x00 };
BYTE data[sizeof(expected)] = { 0x00 };
DWORD size = sizeof(data);
uprintf("Patching IO.SYS...\n");
if (GetFileSize(hFile, NULL) != 116736) {
if (filesize != 116736) {
uprintf(" unexpected file size\n");
return FALSE;
}
SetFilePointer(hFile, 0x3a8, NULL, FILE_BEGIN);
if (!ReadFile(hFile, data, size, &size, NULL)) {
uprintf(" could not read data\n");
return FALSE;
}
if (memcmp(data, expected, sizeof(expected)) != 0) {
if (memcmp(&DiskImage[filestart+0x3a8], expected, sizeof(expected)) != 0) {
uprintf(" unexpected binary data\n");
return FALSE;
}
data[2] = 0xeb;
SetFilePointer(hFile, 0x3a8, NULL, FILE_BEGIN);
size = sizeof(data);
WriteFile(hFile, data, size, &size, NULL);
DiskImage[filestart+0x3aa] = 0xeb;
return TRUE;
}
......@@ -239,7 +220,6 @@ static BOOL ExtractFAT(int entry, const char* path)
}
strcpy(filename, path);
pos = strlen(path);
filename[pos++] = '\\';
fnamepos = pos;
for(i=0; i<8; i++) {
......@@ -262,6 +242,13 @@ static BOOL ExtractFAT(int entry, const char* path)
return FALSE;
}
/* WinME DOS files need to be patched */
if (strcmp(&filename[fnamepos], "COMMAND.COM") == 0) {
Patch_COMMAND_COM(filestart, filesize);
} else if (strcmp(&filename[fnamepos], "IO.SYS") == 0) {
Patch_IO_SYS(filestart, filesize);
}
/* Create a file, using the same attributes as found in the FAT */
hFile = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, CREATE_ALWAYS, dir_entry->Attributes, 0);
......@@ -276,13 +263,6 @@ static BOOL ExtractFAT(int entry, const char* path)
return FALSE;
}
/* WinME DOS files need to be patched */
if (strcmp(&filename[fnamepos], "COMMAND.COM") == 0) {
Patch_COMMAND_COM(hFile);
} else if (strcmp(&filename[fnamepos], "IO.SYS") == 0) {
Patch_IO_SYS(hFile);
}
/* Restore timestamps from FAT */
FatDateTimeToSystemTime(&liCreationTime, &dir_entry->CreationDateTime, dir_entry->CreationTimeTenMs);
ftCreationTime.dwHighDateTime = liCreationTime.HighPart;
......@@ -311,10 +291,8 @@ static BOOL ExtractMSDOS(const char* path)
{
char dllname[MAX_PATH] = "C:\\Windows\\System32";
int i, j;
BOOL r = TRUE;
HMODULE hDLL;
HGLOBAL hRes;
HRSRC hDiskImage;
BOOL r = FALSE;
HMODULE hDLL = NULL;
char locale_path[MAX_PATH];
char* extractlist[] = { "MSDOS SYS", "COMMAND COM", "IO SYS", "MODE COM",
"KEYB COM", "KEYBOARDSYS", "KEYBRD2 SYS", "KEYBRD3 SYS", "KEYBRD4 SYS",
......@@ -322,7 +300,7 @@ static BOOL ExtractMSDOS(const char* path)
// Reduce the visible mess by placing all the locale files into a subdir
safe_strcpy(locale_path, sizeof(locale_path), path);
safe_strcat(locale_path, sizeof(locale_path), "\\LOCALE");
safe_strcat(locale_path, sizeof(locale_path), "LOCALE\\");
CreateDirectoryA(locale_path, NULL);
GetSystemDirectoryA(dllname, sizeof(dllname));
......@@ -330,31 +308,20 @@ static BOOL ExtractMSDOS(const char* path)
hDLL = LoadLibraryA(dllname);
if (hDLL == NULL) {
uprintf("Unable to open %s: %s\n", dllname, WindowsErrorString());
return FALSE;
goto out;
}
hDiskImage = FindResourceA(hDLL, MAKEINTRESOURCEA(1), "BINFILE");
if (hDiskImage == NULL) {
uprintf("Unable to locate disk image in %s: %s\n", dllname, WindowsErrorString());
FreeLibrary(hDLL);
return FALSE;
}
hRes = LoadResource(hDLL, hDiskImage);
if (hRes != NULL)
DiskImage = (BYTE*)LockResource(hRes);
if ((hRes == NULL) || (DiskImage == NULL) ){
uprintf("Unable to access disk image in %s: %s\n", dllname, WindowsErrorString());
FreeLibrary(hDLL);
return FALSE;
}
DiskImageSize = (size_t)SizeofResource(hDLL, hDiskImage);
DiskImage = (BYTE*)GetResource(hDLL, MAKEINTRESOURCEA(1), "BINFILE", "disk image", &DiskImageSize, TRUE);
if (DiskImage == NULL)
goto out;
// Sanity check
if (DiskImageSize < 700*1024) {
uprintf("MS-DOS disk image is too small (%d bytes)\n", dllname, DiskImageSize);
FreeLibrary(hDLL);
return FALSE;
goto out;
}
for (i=0; r && i<FAT_FN_DIR_ENTRY_LAST; i++) {
for (i=0, r=TRUE; r && i<FAT_FN_DIR_ENTRY_LAST; i++) {
if (DiskImage[FAT12_ROOTDIR_OFFSET + i*FAT_BYTES_PER_DIRENT] == FAT_DIRENT_DELETED)
continue;
for (j=0; r && j<ARRAYSIZE(extractlist); j++) {
......@@ -365,10 +332,13 @@ static BOOL ExtractMSDOS(const char* path)
}
}
}
FreeLibrary(hDLL);
if (r)
r = SetDOSLocale(path, FALSE);
out:
if (hDLL != NULL)
FreeLibrary(hDLL);
safe_free(DiskImage);
return r;
}
......@@ -388,8 +358,6 @@ BOOL ExtractFreeDOS(const char* path)
IDR_FD_EGA12_CPX, IDR_FD_EGA13_CPX, IDR_FD_EGA14_CPX, IDR_FD_EGA15_CPX, IDR_FD_EGA16_CPX,
IDR_FD_EGA17_CPX, IDR_FD_EGA18_CPX };
char filename[MAX_PATH], locale_path[MAX_PATH];
HGLOBAL res_handle;
HRSRC res;
BYTE* res_data;
DWORD res_size, Size;
HANDLE hFile;
......@@ -402,25 +370,13 @@ BOOL ExtractFreeDOS(const char* path)
// Reduce the visible mess by placing all the locale files into a subdir
safe_strcpy(locale_path, sizeof(locale_path), path);
safe_strcat(locale_path, sizeof(locale_path), "\\LOCALE");
safe_strcat(locale_path, sizeof(locale_path), "LOCALE\\");
CreateDirectoryA(locale_path, NULL);
for (i=0; i<ARRAYSIZE(res_name); i++) {
res = FindResource(hMainInstance, MAKEINTRESOURCE(res_id[i]), RT_RCDATA);
if (res == NULL) {
uprintf("Unable to locate FreeDOS resource %s: %s\n", res_name[i], WindowsErrorString());
return FALSE;
}
res_handle = LoadResource(NULL, res);
if (res_handle == NULL) {
uprintf("Unable to load FreeDOS resource %s: %s\n", res_name[i], WindowsErrorString());
return FALSE;
}
res_data = (BYTE*)LockResource(res_handle);
res_size = SizeofResource(NULL, res);
res_data = (BYTE*)GetResource(hMainInstance, MAKEINTRESOURCEA(res_id[i]), _RT_RCDATA, res_name[i], &res_size, FALSE);
safe_strcpy(filename, sizeof(filename), ((i<2)?path:locale_path));
safe_strcat(filename, sizeof(filename), "\\");
safe_strcat(filename, sizeof(filename), res_name[i]);
hFile = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
......
......@@ -75,7 +75,7 @@ HANDLE GetDriveHandle(DWORD DriveIndex, char* DriveLetter, BOOL bWriteAccess, BO
goto out;
}
if (bWriteAccess) {
uprintf("Caution: Opened %s drive for write access\n", physical_drive);
uprintf("Caution: Opened %s drive for write access\n", &physical_drive[4]);
}
} else {
*DriveLetter = ' ';
......@@ -130,7 +130,7 @@ HANDLE GetDriveHandle(DWORD DriveIndex, char* DriveLetter, BOOL bWriteAccess, BO
goto out;
}
if (bWriteAccess) {
uprintf("Caution: Opened %s drive for write access\n", logical_drive);
uprintf("Caution: Opened %s drive for write access\n", &logical_drive[4]);
}
*DriveLetter = *drive?*drive:' ';
}
......
......@@ -779,23 +779,12 @@ out:
*/
BOOL WriteRufusMBR(FILE *fp)
{
HGLOBAL res_handle;
HRSRC res;
DWORD size;
unsigned char aucRef[] = {0x55, 0xAA};
unsigned char* rufus_mbr;
// TODO: Will we need to edit the disk ID according to UI selection in the MBR as well?
res = FindResource(hMainInstance, MAKEINTRESOURCE(IDR_BR_MBR_BIN), RT_RCDATA);
if (res == NULL) {
uprintf("Unable to locate mbr.bin resource: %s\n", WindowsErrorString());
return FALSE;
}
res_handle = LoadResource(NULL, res);
if (res_handle == NULL) {
uprintf("Unable to load mbr.bin resource: %s\n", WindowsErrorString());
return FALSE;
}
rufus_mbr = (unsigned char*)LockResource(res_handle);
rufus_mbr = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_BR_MBR_BIN), _RT_RCDATA, "mbr.bin", &size, FALSE);
return
write_data(fp, 0x0, rufus_mbr, 0x1b8) &&
......@@ -1089,9 +1078,9 @@ static BOOL RemountVolume(char drive_letter)
if (DeleteVolumeMountPointA(drive_name)) {
Sleep(200);
if (SetVolumeMountPointA(drive_name, drive_guid)) {
uprintf("Successfully remounted %s on %s\n", drive_guid, drive_name);
uprintf("Successfully remounted %s on %s\n", &drive_guid[4], drive_name);
} else {
uprintf("Failed to remount %s on %s\n", drive_guid, drive_name);
uprintf("Failed to remount %s on %s\n", &drive_guid[4], drive_name);
// This will leave the drive unaccessible and must be flagged as an error
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_REMOUNT_VOLUME);
return FALSE;
......
......@@ -98,17 +98,7 @@ static BOOL SaveIcon(const char* filename)
BOOL r = FALSE;
GRPICONDIR* icondir;
res = FindResource(hMainInstance, MAKEINTRESOURCE(IDI_ICON), RT_GROUP_ICON);
if (res == NULL) {
uprintf("Unable to locate icon resource: %s\n", WindowsErrorString());
goto out;
}
res_handle = LoadResource(NULL, res);
if (res_handle == NULL) {
uprintf("Unable to load icon resource: %s\n", WindowsErrorString());
goto out;
}
icondir = (GRPICONDIR*)LockResource(res_handle);
icondir = (GRPICONDIR*)GetResource(hMainInstance, MAKEINTRESOURCEA(IDI_ICON), _RT_GROUP_ICON, "icon", &res_size, FALSE);
hFile = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, CREATE_NEW, 0, 0);
......@@ -132,7 +122,7 @@ static BOOL SaveIcon(const char* filename)
uprintf("Couldn't write ICONDIRENTRY[%d]: %s.\n", i, WindowsErrorString());
goto out;
}
res = FindResource(hMainInstance, MAKEINTRESOURCE(icondir->idEntries[i].nID), RT_ICON);
res = FindResourceA(hMainInstance, MAKEINTRESOURCEA(icondir->idEntries[i].nID), _RT_ICON);
// Write the DWORD offset
if ( (!WriteFile(hFile, &offset, sizeof(offset), &Size, NULL)) || (Size != sizeof(offset)) ) {
uprintf("Couldn't write ICONDIRENTRY[%d] offset: %s.\n", i, WindowsErrorString());
......@@ -142,7 +132,7 @@ static BOOL SaveIcon(const char* filename)
}
for (i=0; i<icondir->idCount; i++) {
// Write icon data
res = FindResource(hMainInstance, MAKEINTRESOURCE(icondir->idEntries[i].nID), RT_ICON);
res = FindResourceA(hMainInstance, MAKEINTRESOURCEA(icondir->idEntries[i].nID), _RT_ICON);
res_handle = LoadResource(NULL, res);
res_data = (BYTE*)LockResource(res_handle);
res_size = SizeofResource(NULL, res);
......@@ -170,7 +160,7 @@ BOOL SetAutorun(const char* path)
char filename[64];
wchar_t wlabel[128], wRufusVersion[32];
safe_sprintf(filename, sizeof(filename), "%s\\autorun.inf", path);
safe_sprintf(filename, sizeof(filename), "%sautorun.inf", path);
fd = fopen(filename, "r"); // If there's an existing autorun, don't overwrite
if (fd != NULL) {
uprintf("%s already exists - keeping it\n", filename);
......
......@@ -987,9 +987,9 @@ DWORD WINAPI ISOScanThread(LPVOID param)
uprintf(" With an old %s: %s\n", old_c32_name[i], iso_report.has_old_c32[i]?"Yes":"No");
}
}
if ((!iso_report.has_bootmgr) && (!iso_report.has_isolinux) && (!IS_WINPE(iso_report.winpe))) {
if ((!iso_report.has_bootmgr) && (!iso_report.has_isolinux) && (!IS_WINPE(iso_report.winpe)) && (!iso_report.has_efi)) {
MessageBoxU(hMainDialog, "This version of Rufus only supports bootable ISOs\n"
"based on 'bootmgr/WinPE' or 'isolinux'.\n"
"based on 'bootmgr/WinPE', 'isolinux' or EFI boot.\n"
"This ISO image doesn't appear to use either...", "Unsupported ISO", MB_OK|MB_ICONINFORMATION);
safe_free(iso_path);
SetMBRProps();
......@@ -1061,6 +1061,14 @@ void MoveControl(int nID, float vertical_shift)
(rect.right - rect.left), (rect.bottom - rect.top), TRUE);
}
void SetPassesTooltip(void)
{
char passes_tooltip[32];
safe_strcpy(passes_tooltip, sizeof(passes_tooltip), "Pattern: 0x55, 0xAA, 0xFF, 0x00");
passes_tooltip[13 + ComboBox_GetCurSel(hNBPasses)*6] = 0;
CreateTooltip(hNBPasses, passes_tooltip, -1);
}
// Toggle "advanced" mode
void ToggleAdvanced(void)
{
......@@ -1100,6 +1108,61 @@ void ToggleAdvanced(void)
SendMessage(GetDlgItem(hMainDialog, IDC_ADVANCED), BCM_SETIMAGELIST, 0, (LPARAM)(advanced_mode?&bi_up:&bi_down));
}
static BOOL BootCheck(void)
{
int fs, bt;
if (ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType)) == DT_ISO) {
if (iso_path == NULL) {
MessageBoxA(hMainDialog, "Please click on the disc button to select a bootable ISO,\n"
"or uncheck the \"Create a bootable disk...\" checkbox.",
"No ISO image selected...", MB_OK|MB_ICONERROR);
return FALSE;
}
if ((iso_size_check) && (iso_report.projected_size > (uint64_t)SelectedDrive.DiskSize)) {
MessageBoxA(hMainDialog, "This ISO image is too big "
"for the selected target.", "ISO image too big...", MB_OK|MB_ICONERROR);
return FALSE;
}
fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem));
bt = GETBIOSTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme)));
if (bt == BT_UEFI) {
if (!IS_EFI(iso_report)) {
MessageBoxA(hMainDialog, "When using UEFI Target Type, only EFI bootable ISO images are supported. "
"Please select an EFI bootable ISO or set the Target Type to BIOS.", "Unsupported ISO...", MB_OK|MB_ICONERROR);
return FALSE;
} else if (fs > FS_FAT32) {
MessageBoxA(hMainDialog, "When using UEFI Target Type, only FAT/FAT32 is supported. "
"Please select FAT/FAT32 as the File system or set the Target Type to BIOS.", "Unsupported filesystem...", MB_OK|MB_ICONERROR);
return FALSE;
}
} else if ((fs == FS_NTFS) && (!iso_report.has_bootmgr) && (!IS_WINPE(iso_report.winpe))) {
if (iso_report.has_isolinux) {
MessageBoxA(hMainDialog, "Only FAT/FAT32 is supported for this type of ISO. "
"Please select FAT/FAT32 as the File system.", "Unsupported filesystem...", MB_OK|MB_ICONERROR);
} else {
MessageBoxA(hMainDialog, "Only 'bootmgr' or 'WinPE' based ISO "
"images can currently be used with NTFS.", "Unsupported ISO...", MB_OK|MB_ICONERROR);
}
return FALSE;
} else if (((fs == FS_FAT16)||(fs == FS_FAT32)) && (!iso_report.has_isolinux)) {
MessageBoxA(hMainDialog, "FAT/FAT32 can only be used for isolinux based ISO images "
"or when the Target Type is UEFI.", "Unsupported ISO...", MB_OK|MB_ICONERROR);
return FALSE;
}
if ((bt == BT_UEFI) && (iso_report.has_win7_efi) && (!WimExtractCheck())) {
if (MessageBoxA(hMainDialog, "Your platform cannot extract files from WIM archives. WIM extraction "
"is required to create EFI bootable Windows 7 and Windows Vista USB drives. You can fix that "
"by installing a recent version of 7-Zip.\r\nDo you want to visit the 7-zip download page?",
"Missing WIM support...", MB_YESNO|MB_ICONERROR) == IDYES)
ShellExecuteA(hMainDialog, "open", SEVENZIP_URL, NULL, NULL, SW_SHOWNORMAL);
return FALSE;
}
}
return TRUE;
}
void InitDialog(HWND hDlg)
{
HINSTANCE hDllInst;
......@@ -1161,12 +1224,12 @@ void InitDialog(HWND hDlg)
// Use maximum granularity for the progress bar
SendMessage(hProgress, PBM_SETRANGE, 0, (MAX_PROGRESS<<16) & 0xFFFF0000);
// Fill up the passes
IGNORE_RETVAL(ComboBox_AddStringU(hNBPasses, "1 Pass"));
IGNORE_RETVAL(ComboBox_AddStringU(hNBPasses, "2 Passes"));
IGNORE_RETVAL(ComboBox_AddStringU(hNBPasses, "3 Passes"));
IGNORE_RETVAL(ComboBox_AddStringU(hNBPasses, "4 Passes"));
for (i=0; i<4; i++) {
safe_sprintf(tmp, sizeof(tmp), "%d Pass%s", i+1, (i==0)?"":"es");
IGNORE_RETVAL(ComboBox_AddStringU(hNBPasses, tmp));
}
IGNORE_RETVAL(ComboBox_SetCurSel(hNBPasses, 1));
CreateTooltip(hNBPasses, "Pattern: 0x55, 0xAA", -1);
SetPassesTooltip();
// Fill up the DOS type dropdown
IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "MS-DOS"), DT_WINME));
IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "FreeDOS"), DT_FREEDOS));
......@@ -1380,20 +1443,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
case IDC_NBPASSES:
if (HIWORD(wParam) != CBN_SELCHANGE)
break;
switch(ComboBox_GetCurSel(hNBPasses)) {
case 0:
CreateTooltip(hNBPasses, "Pattern: 0x55", -1);
break;
case 1:
CreateTooltip(hNBPasses, "Pattern: 0x55, 0xAA", -1);
break;
case 2:
CreateTooltip(hNBPasses, "Pattern: 0x55, 0xAA, 0xFF", -1);
break;
case 3:
CreateTooltip(hNBPasses, "Pattern: 0x55, 0xAA, 0xFF, 0x00", -1);
break;
}
SetPassesTooltip();
break;
case IDC_PARTITION_SCHEME:
case IDC_FILESYSTEM:
......@@ -1522,55 +1572,8 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
selection_default = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType));
nDeviceIndex = ComboBox_GetCurSel(hDeviceList);
if (nDeviceIndex != CB_ERR) {
if (IsChecked(IDC_BOOT)) {
if (ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType)) == DT_ISO) {
if (iso_path == NULL) {
MessageBoxA(hMainDialog, "Please click on the disc button to select a bootable ISO,\n"
"or uncheck the \"Create a bootable disk...\" checkbox.",
"No ISO image selected...", MB_OK|MB_ICONERROR);
break;
}
if ((iso_size_check) && (iso_report.projected_size > (uint64_t)SelectedDrive.DiskSize)) {
MessageBoxA(hMainDialog, "This ISO image is too big "
"for the selected target.", "ISO image too big...", MB_OK|MB_ICONERROR);
break;
}
fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem));
bt = GETBIOSTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme)));
if (bt == BT_UEFI) {
if (!IS_EFI(iso_report)) {
MessageBoxA(hMainDialog, "When using UEFI Target Type, only EFI bootable ISO images are supported. "
"Please select an EFI bootable ISO or set the Target Type to BIOS.", "Unsupported ISO...", MB_OK|MB_ICONERROR);
break;
} else if (fs > FS_FAT32) {
MessageBoxA(hMainDialog, "When using UEFI Target Type, only FAT/FAT32 is supported. "
"Please select FAT/FAT32 as the File system or set the Target Type to BIOS.", "Unsupported filesystem...", MB_OK|MB_ICONERROR);
break;
}
} else if ((fs == FS_NTFS) && (!iso_report.has_bootmgr) && (!IS_WINPE(iso_report.winpe))) {
if (iso_report.has_isolinux) {
MessageBoxA(hMainDialog, "Only FAT/FAT32 is supported for this type of ISO. "
"Please select FAT/FAT32 as the File system.", "Unsupported filesystem...", MB_OK|MB_ICONERROR);
} else {
MessageBoxA(hMainDialog, "Only 'bootmgr' or 'WinPE' based ISO "
"images can currently be used with NTFS.", "Unsupported ISO...", MB_OK|MB_ICONERROR);
}
break;
} else if (((fs == FS_FAT16)||(fs == FS_FAT32)) && (!iso_report.has_isolinux)) {
MessageBoxA(hMainDialog, "FAT/FAT32 can only be used for isolinux based ISO images "
"or when the Target Type is UEFI.", "Unsupported ISO...", MB_OK|MB_ICONERROR);
break;
}
if ((bt == BT_UEFI) && (iso_report.has_win7_efi) && (!WimExtractCheck())) {
if (MessageBoxA(hMainDialog, "Your platform cannot extract files from WIM archives. WIM extraction "
"is required to create EFI bootable Windows 7 and Windows Vista USB drives. You can fix that "
"by installing a recent version of 7-Zip.\r\nDo you want to visit the 7-zip download page?",
"Missing WIM support...", MB_YESNO|MB_ICONERROR) == IDYES)
ShellExecuteA(hDlg, "open", SEVENZIP_URL, NULL, NULL, SW_SHOWNORMAL);
break;
}
}
}
if ((IsChecked(IDC_BOOT)) && (!BootCheck()))
break;
GetWindowTextW(hDeviceList, wtmp, ARRAYSIZE(wtmp));
_snwprintf(wstr, ARRAYSIZE(wstr), L"WARNING: ALL DATA ON DEVICE %s\r\nWILL BE DESTROYED.\r\n"
L"To continue with this operation, click OK. To quit click CANCEL.", wtmp);
......@@ -1656,6 +1659,11 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
return (INT_PTR)FALSE;
}
static void PrintStatus2000(const char* str, BOOL val)
{
PrintStatus(2000, FALSE, "%s %s.", str, (val)?"enabled":"disabled");
}
/*
* Application Entrypoint
*/
......@@ -1744,7 +1752,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
// the target USB drive. If this is enabled, the size check is disabled.
if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'S')) {
iso_size_check = !iso_size_check;
PrintStatus(2000, FALSE, "ISO size check %s.", iso_size_check?"enabled":"disabled");
PrintStatus2000("ISO size check", iso_size_check);
continue;
}
// Alt-F => Toggle detection of fixed disks
......@@ -1753,7 +1761,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
// drive instead of an USB key. If this is enabled, Rufus will allow fixed disk formatting.
if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'F')) {
enable_fixed_disks = !enable_fixed_disks;
PrintStatus(2000, FALSE, "Fixed disks detection %s.", enable_fixed_disks?"enabled":"disabled");
PrintStatus2000("Fixed disks detection", enable_fixed_disks);
GetUSBDevices(0);
continue;
}
......@@ -1771,7 +1779,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
// it back during the bad block check.
if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'K')) {
detect_fakes = !detect_fakes;
PrintStatus(2000, FALSE, "Fake drive detection %s.", detect_fakes?"enabled":"disabled");
PrintStatus2000("Fake drive detection", detect_fakes);
continue;
}
// Alt-R => Remove all the registry keys created by Rufus
......
......@@ -293,6 +293,7 @@ extern BOOL CreateProgress(void);
extern BOOL SetAutorun(const char* path);
extern char* FileDialog(BOOL save, char* path, char* filename, char* ext, char* ext_desc);
extern BOOL FileIO(BOOL save, char* path, char** buffer, DWORD* size);
extern unsigned char* GetResource(HMODULE module, char* name, char* type, const char* desc, DWORD* len, BOOL duplicate);
extern BOOL SetLGP(BOOL bRestore, BOOL* bExistingKey, const char* szPath, const char* szPolicy, DWORD dwValue);
extern LONG GetEntryWidth(HWND hDropDown, const char* entry);
extern BOOL DownloadFile(const char* url, const char* file, HWND hProgressDialog);
......@@ -393,3 +394,8 @@ typedef struct {
#ifndef PBM_SETMARQUEE
#define PBM_SETMARQUEE (WM_USER+10)
#endif
/* Why oh why does Microsoft has to make everybody suffer with their braindead use of Unicode */
#define _RT_ICON MAKEINTRESOURCEA(3)
#define _RT_RCDATA MAKEINTRESOURCEA(10)
#define _RT_GROUP_ICON MAKEINTRESOURCEA((ULONG_PTR)(MAKEINTRESOURCEA(3) + 11))
......@@ -30,7 +30,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 206, 316
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Rufus v1.3.2.228"
CAPTION "Rufus v1.3.2.229"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,278,50,14
......@@ -274,8 +274,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,3,2,228
PRODUCTVERSION 1,3,2,228
FILEVERSION 1,3,2,229
PRODUCTVERSION 1,3,2,229
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
......@@ -292,13 +292,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "1.3.2.228"
VALUE "FileVersion", "1.3.2.229"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "(c) 2011-2012 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "1.3.2.228"
VALUE "ProductVersion", "1.3.2.229"
END
END
BLOCK "VarFileInfo"
......
......@@ -231,6 +231,40 @@ out:
return ret;
}
unsigned char* GetResource(HMODULE module, char* name, char* type, const char* desc, DWORD* len, BOOL duplicate)
{
HGLOBAL res_handle;
HRSRC res;
unsigned char* p = NULL;
res = FindResourceA(module, name, type);
if (res == NULL) {
uprintf("Unable to locate resource '%s': %s\n", desc, WindowsErrorString());
goto out;
}
res_handle = LoadResource(module, res);
if (res_handle == NULL) {
uprintf("Unable to load resource '%s': %s\n", desc, WindowsErrorString());
goto out;
}
*len = SizeofResource(module, res);
if (duplicate) {
p = (unsigned char*)malloc(*len);
if (p == NULL) {
uprintf("Unable to allocate ldlinux.sys resource\n");
goto out;
}
memcpy(p, LockResource(res_handle), *len);
} else {
p = (unsigned char*)LockResource(res_handle);
}
out:
return p;
}
/*
* Set or restore a Local Group Policy DWORD key indexed by szPath/SzPolicy
*/
......
......@@ -35,9 +35,9 @@
#include "setadv.h"
unsigned char* syslinux_ldlinux = NULL;
unsigned int syslinux_ldlinux_len;
DWORD syslinux_ldlinux_len;
unsigned char* syslinux_bootsect = NULL;
unsigned int syslinux_bootsect_len;
DWORD syslinux_bootsect_len;
/*
* Wrapper for ReadFile suitable for libfat
......@@ -73,8 +73,6 @@ BOOL InstallSyslinux(DWORD num, const char* drive_name)
DWORD bytes_read;
DWORD bytes_written;
BOOL r = FALSE;
HGLOBAL res_handle;
HRSRC res;
static unsigned char sectbuf[SECTOR_SIZE];
static char ldlinux_name[] = "?:\\ldlinux.sys";
......@@ -91,43 +89,14 @@ BOOL InstallSyslinux(DWORD num, const char* drive_name)
/* Initialize the ADV -- this should be smarter */
syslinux_reset_adv(syslinux_adv);
/* Access ldlinux.sys resource */
res = FindResource(hMainInstance, MAKEINTRESOURCE(IDR_SL_LDLINUX_SYS), RT_RCDATA);
if (res == NULL) {
uprintf("Unable to locate ldlinux.sys resource: %s\n", WindowsErrorString());
/* Access a copy of the ldlinux.sys & ldlinux.bss resources */
syslinux_ldlinux = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_SL_LDLINUX_SYS),
_RT_RCDATA, "ldlinux.sys", &syslinux_ldlinux_len, TRUE);
syslinux_bootsect = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_SL_LDLINUX_BSS),
_RT_RCDATA,"ldlinux.bss", &syslinux_bootsect_len, TRUE);
if ((syslinux_ldlinux == NULL) || (syslinux_bootsect == NULL)) {
goto out;
}
res_handle = LoadResource(NULL, res);
if (res_handle == NULL) {
uprintf("Unable to load ldlinux.sys resource: %s\n", WindowsErrorString());
goto out;
}
syslinux_ldlinux_len = SizeofResource(NULL, res);
syslinux_ldlinux = (unsigned char*)malloc(syslinux_ldlinux_len);
if (syslinux_ldlinux == NULL) {
uprintf("Unable to allocate ldlinux.sys resource\n");
goto out;
}
memcpy(syslinux_ldlinux, LockResource(res_handle), syslinux_ldlinux_len);
/* Access ldlinux.bss resource */
res = FindResource(hMainInstance, MAKEINTRESOURCE(IDR_SL_LDLINUX_BSS), RT_RCDATA);
if (res == NULL) {
uprintf("Unable to locate ldlinux.bss resource: %s\n", WindowsErrorString());
goto out;
}
res_handle = LoadResource(NULL, res);
if (res_handle == NULL) {
uprintf("Unable to load ldlinux.bss resource: %s\n", WindowsErrorString());
goto out;
}
syslinux_bootsect_len = SizeofResource(NULL, res);
syslinux_bootsect = (unsigned char*)malloc(syslinux_bootsect_len);
if (syslinux_bootsect == NULL) {
uprintf("Unable to allocate ldlinux.bss resource\n");
goto out;
}
memcpy(syslinux_bootsect, LockResource(res_handle), syslinux_bootsect_len);
/* Create ldlinux.sys file */
f_handle = CreateFileA(ldlinux_name, GENERIC_READ | GENERIC_WRITE,
......
......@@ -13,17 +13,18 @@
#ifndef SYSLINUX_H
#define SYSLINUX_H
#include <windows.h>
#include <inttypes.h>
#include "advconst.h"
#include "setadv.h"
/* The standard boot sector and ldlinux image */
extern unsigned char* syslinux_bootsect;
extern unsigned int syslinux_bootsect_len;
extern DWORD syslinux_bootsect_len;
extern const int syslinux_bootsect_mtime;
extern unsigned char* syslinux_ldlinux;
extern unsigned int syslinux_ldlinux_len;
extern DWORD syslinux_ldlinux_len;
extern const int syslinux_ldlinux_mtime;
#define boot_sector syslinux_bootsect
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册