mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 06:26:00 +00:00
[VFD] Import the VFD project (Virtual Floppy Drive) which allows creating virtual
floppy drives in ReactOS and mount images on them. Only the cmd got imported. The GUI interface may come later on. Note that, as for vcdrom, the driver is left disabled and you need to explicitely start it through vfd command line interface. CORE-14090
This commit is contained in:
parent
d82796778f
commit
25c7e1a8d0
58 changed files with 21984 additions and 0 deletions
|
@ -1 +1,2 @@
|
|||
add_subdirectory(vfdlib)
|
||||
add_subdirectory(win32err)
|
||||
|
|
33
modules/rosapps/lib/vfdlib/CMakeLists.txt
Normal file
33
modules/rosapps/lib/vfdlib/CMakeLists.txt
Normal file
|
@ -0,0 +1,33 @@
|
|||
set_cpp(WITH_RUNTIME WITH_EXCEPTIONS WITH_STL)
|
||||
|
||||
spec2def(vfd.dll vfdlib.spec ADD_IMPORTLIB)
|
||||
|
||||
add_message_headers(ANSI vfdmsg_lib.mc)
|
||||
|
||||
list(APPEND SOURCE
|
||||
vfdctl.c
|
||||
vfdfat.c
|
||||
vfdguiopen.c
|
||||
vfdguisave.c
|
||||
vfdguitip.c
|
||||
vfdguiut.c
|
||||
vfdlib.c
|
||||
vfdshcfact.cpp
|
||||
vfdshext.cpp
|
||||
vfdshmenu.cpp
|
||||
vfdshprop.cpp
|
||||
vfdshutil.cpp
|
||||
vfdzip.c)
|
||||
|
||||
add_library(vfd SHARED
|
||||
${SOURCE}
|
||||
vfdlib.rc
|
||||
${CMAKE_CURRENT_BINARY_DIR}/vfdlib.def)
|
||||
|
||||
include_directories(${REACTOS_SOURCE_DIR}/modules/rosapps/include/vfd
|
||||
${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/zlib)
|
||||
set_module_type(vfd win32dll ENTRYPOINT DllMain 12)
|
||||
target_link_libraries(vfd zlib_solo uuid)
|
||||
add_importlibs(vfd advapi32 user32 gdi32 shell32 comdlg32 comctl32 ole32 version psapi msvcrt kernel32 ntdll)
|
||||
add_dependencies(vfd vfdmsg_lib)
|
||||
add_cd_file(TARGET vfd DESTINATION reactos/system32 FOR all)
|
BIN
modules/rosapps/lib/vfdlib/res/config.ico
Normal file
BIN
modules/rosapps/lib/vfdlib/res/config.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
modules/rosapps/lib/vfdlib/res/image.ico
Normal file
BIN
modules/rosapps/lib/vfdlib/res/image.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
modules/rosapps/lib/vfdlib/res/vfd.ico
Normal file
BIN
modules/rosapps/lib/vfdlib/res/vfd.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
3272
modules/rosapps/lib/vfdlib/vfdctl.c
Normal file
3272
modules/rosapps/lib/vfdlib/vfdctl.c
Normal file
File diff suppressed because it is too large
Load diff
205
modules/rosapps/lib/vfdlib/vfdfat.c
Normal file
205
modules/rosapps/lib/vfdlib/vfdfat.c
Normal file
|
@ -0,0 +1,205 @@
|
|||
/*
|
||||
vfdfat.c
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
Formats the image with FAT12
|
||||
|
||||
Copyright (C) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#pragma message(__FILE__": Compiled as C++ for testing purpose.")
|
||||
#endif // __cplusplus
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include "vfdtypes.h"
|
||||
#include "vfdio.h"
|
||||
#include "vfdlib.h"
|
||||
#include "vfdver.h"
|
||||
|
||||
#pragma pack(1)
|
||||
//
|
||||
// BIOS parameter block
|
||||
//
|
||||
typedef struct _DOS_BPB
|
||||
{
|
||||
USHORT BytesPerSector;
|
||||
UCHAR SectorsPerCluster;
|
||||
USHORT ReservedSectors;
|
||||
UCHAR NumberOfFATs;
|
||||
USHORT RootEntries;
|
||||
USHORT SmallSectors;
|
||||
UCHAR MediaDescriptor;
|
||||
USHORT SectorsPerFAT;
|
||||
USHORT SectorsPerTrack;
|
||||
USHORT NumberOfHeads;
|
||||
ULONG HiddenSectors;
|
||||
ULONG LargeSectors;
|
||||
}
|
||||
DOS_BPB, *PDOS_BPB;
|
||||
|
||||
//
|
||||
// Extended BIOS parameter block for FAT12/16/HUGE
|
||||
//
|
||||
typedef struct _EXBPB
|
||||
{
|
||||
UCHAR PhysicalDriveNumber;
|
||||
UCHAR Reserved;
|
||||
UCHAR BootSignature;
|
||||
ULONG VolumeSerialNumber;
|
||||
CHAR VolumeLabel[11];
|
||||
CHAR FileSystemType[8];
|
||||
}
|
||||
EXBPB, *PEXBPB;
|
||||
|
||||
//
|
||||
// Partition Boot Record
|
||||
//
|
||||
typedef struct _DOS_PBR { // Partition Boot Record
|
||||
UCHAR jump[3]; // Jump Instruction (E9 or EB, xx, 90)
|
||||
CHAR oemid[8]; // OEM ID (OS type)
|
||||
DOS_BPB bpb; // BIOS parameter block
|
||||
EXBPB exbpb; // Extended BIOS parameter block
|
||||
}
|
||||
DOS_PBR, *PDOS_PBR;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#define FAT_DIR_ENTRY_SIZE 32
|
||||
|
||||
// We need to have the 0xeb and 0x90 in the jump code
|
||||
// because the file system recognizer checks these values
|
||||
#define VFD_JUMP_CODE "\xeb\x3c\x90"
|
||||
#define VFD_OEM_NAME "VFD" VFD_DRIVER_VERSION_STR " "
|
||||
#define VFD_VOLUME_LABEL "NO NAME "
|
||||
#define VFD_FILESYSTEM "FAT12 "
|
||||
|
||||
//
|
||||
// Select DOS BPB parameters from media size
|
||||
//
|
||||
static const DOS_BPB *SelectDosBpb(
|
||||
USHORT nSectors)
|
||||
{
|
||||
static const DOS_BPB bpb_tbl[] = {
|
||||
// b/s s/c r fat root sec desc s/f s/t h
|
||||
{VFD_BYTES_PER_SECTOR, 2, 1, 2, 112, 320, 0xFE, 1, 8, 1, 0, 0}, // 160KB 5.25"
|
||||
{VFD_BYTES_PER_SECTOR, 2, 1, 2, 112, 360, 0xFC, 1, 9, 1, 0, 0}, // 180KB 5.25"
|
||||
{VFD_BYTES_PER_SECTOR, 2, 1, 2, 112, 640, 0xFF, 1, 8, 2, 0, 0}, // 320KB 5.25"
|
||||
{VFD_BYTES_PER_SECTOR, 2, 1, 2, 112, 720, 0xFD, 2, 9, 2, 0, 0}, // 360KB 5.25"
|
||||
{VFD_BYTES_PER_SECTOR, 2, 1, 2, 112, 1280, 0xFB, 2, 8, 2, 0, 0}, // 640KB 5.25" / 3.5"
|
||||
{VFD_BYTES_PER_SECTOR, 2, 1, 2, 112, 1440, 0xF9, 3, 9, 2, 0, 0}, // 720KB 5.25" / 3.5"
|
||||
{VFD_BYTES_PER_SECTOR, 2, 1, 2, 112, 1640, 0xF9, 3, 10, 2, 0, 0}, // 820KB 3.5"
|
||||
{VFD_BYTES_PER_SECTOR, 1, 1, 2, 224, 2400, 0xF9, 7, 15, 2, 0, 0}, // 1.20MB 5.25" / 3.5"
|
||||
{VFD_BYTES_PER_SECTOR, 1, 1, 2, 224, 2880, 0xF0, 9, 18, 2, 0, 0}, // 1.44MB 3.5"
|
||||
{VFD_BYTES_PER_SECTOR, 1, 1, 2, 224, 3360, 0xF0, 10, 21, 2, 0, 0}, // 1.68MB 3.5"
|
||||
{VFD_BYTES_PER_SECTOR, 1, 1, 2, 224, 3444, 0xF0, 10, 21, 2, 0, 0}, // 1.72MB 3.5"
|
||||
{VFD_BYTES_PER_SECTOR, 2, 1, 2, 240, 5760, 0xF0, 9, 36, 2, 0, 0}, // 2.88MB 3.5"
|
||||
};
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(bpb_tbl) / sizeof(bpb_tbl[0]); i++) {
|
||||
if (nSectors == bpb_tbl[i].SmallSectors) {
|
||||
return &bpb_tbl[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Format the buffer with FAT12
|
||||
//
|
||||
DWORD FormatBufferFat(
|
||||
PUCHAR pBuffer,
|
||||
ULONG nSectors)
|
||||
{
|
||||
const DOS_BPB *bpb; // BIOS Parameter Block
|
||||
PDOS_PBR pbr; // Partition Boot Record
|
||||
PUCHAR fat; // File Allocation Table
|
||||
USHORT idx;
|
||||
|
||||
VFDTRACE(0,
|
||||
("[VFD] VfdFormatImage - IN\n"));
|
||||
|
||||
//
|
||||
// Select DOS BPB parameters from media size
|
||||
//
|
||||
bpb = SelectDosBpb((USHORT)nSectors);
|
||||
|
||||
if (!bpb) {
|
||||
VFDTRACE(0,
|
||||
("[VFD] Unsupported media size %lu\n",
|
||||
nSectors));
|
||||
return ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize the whole area with the fill data
|
||||
//
|
||||
FillMemory(pBuffer,
|
||||
VFD_SECTOR_TO_BYTE(nSectors),
|
||||
VFD_FORMAT_FILL_DATA);
|
||||
|
||||
//
|
||||
// Make up the FAT boot record
|
||||
//
|
||||
ZeroMemory(pBuffer, VFD_BYTES_PER_SECTOR);
|
||||
|
||||
pbr = (PDOS_PBR)pBuffer;
|
||||
|
||||
CopyMemory(pbr->jump, VFD_JUMP_CODE, sizeof(pbr->jump));
|
||||
CopyMemory(pbr->oemid, VFD_OEM_NAME, sizeof(pbr->oemid));
|
||||
CopyMemory(&pbr->bpb, bpb, sizeof(pbr->bpb));
|
||||
|
||||
// Make up the extended BPB
|
||||
|
||||
pbr->exbpb.BootSignature = 0x29;
|
||||
|
||||
// use the tick count as the volume serial number
|
||||
pbr->exbpb.VolumeSerialNumber = GetTickCount();
|
||||
|
||||
CopyMemory(pbr->exbpb.VolumeLabel,
|
||||
VFD_VOLUME_LABEL, sizeof(pbr->exbpb.VolumeLabel));
|
||||
|
||||
CopyMemory(pbr->exbpb.FileSystemType,
|
||||
VFD_FILESYSTEM, sizeof(pbr->exbpb.FileSystemType));
|
||||
|
||||
// Set the boot record signature
|
||||
|
||||
*(pBuffer + VFD_BYTES_PER_SECTOR - 2) = 0x55;
|
||||
*(pBuffer + VFD_BYTES_PER_SECTOR - 1) = 0xaa;
|
||||
|
||||
//
|
||||
// Clear FAT areas
|
||||
//
|
||||
fat = pBuffer + VFD_SECTOR_TO_BYTE(bpb->ReservedSectors);
|
||||
|
||||
ZeroMemory(
|
||||
fat,
|
||||
VFD_SECTOR_TO_BYTE(bpb->SectorsPerFAT * bpb->NumberOfFATs));
|
||||
|
||||
//
|
||||
// Make up FAT entries for the root directory
|
||||
//
|
||||
for (idx = 0; idx < bpb->NumberOfFATs; idx++) {
|
||||
*fat = bpb->MediaDescriptor;
|
||||
*(fat + 1) = 0xff;
|
||||
*(fat + 2) = 0xff;
|
||||
|
||||
fat += VFD_SECTOR_TO_BYTE(bpb->SectorsPerFAT);
|
||||
}
|
||||
|
||||
//
|
||||
// Clear root directory entries
|
||||
//
|
||||
ZeroMemory(fat, bpb->RootEntries * FAT_DIR_ENTRY_SIZE);
|
||||
|
||||
VFDTRACE(0,
|
||||
("[VFD] VfdFormatImage - OUT\n"));
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
562
modules/rosapps/lib/vfdlib/vfdguiopen.c
Normal file
562
modules/rosapps/lib/vfdlib/vfdguiopen.c
Normal file
|
@ -0,0 +1,562 @@
|
|||
/*
|
||||
vfdguiopen.c
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
Open image GUI utility function
|
||||
|
||||
Copyright (c) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#pragma message(__FILE__": Compiled as C++ for testing purpose.")
|
||||
#endif // __cplusplus
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push,3)
|
||||
#endif
|
||||
#include <commdlg.h>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#include "vfdtypes.h"
|
||||
#include "vfdapi.h"
|
||||
#include "vfdlib.h"
|
||||
#ifndef __REACTOS__
|
||||
#include "vfdmsg.h"
|
||||
#else
|
||||
#include "vfdmsg_lib.h"
|
||||
#endif
|
||||
#include "vfdguirc.h"
|
||||
|
||||
//
|
||||
// String constants
|
||||
//
|
||||
|
||||
#define FALLBACK_IMAGE_FILTER \
|
||||
"Common image files (bin,dat,fdd,flp,ima,img,vfd)\0" \
|
||||
"*.bin;*.dat;*.fdd;*.flp;*.ima;*.img;*.vfd\0" \
|
||||
"Zip compressed image (imz,zip)\0*.imz;*.zip\0" \
|
||||
"All files (*.*)\0*.*\0"
|
||||
|
||||
#define FALLBACK_IMAGE_TITLE "Open Virtual Floppy Image"
|
||||
|
||||
//
|
||||
// local functions
|
||||
//
|
||||
static INT CALLBACK OpenDialogProc(
|
||||
HWND hDlg,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam);
|
||||
|
||||
static void OnInit(HWND hDlg, ULONG nDevice);
|
||||
static void OnImage(HWND hDlg, HWND hEdit);
|
||||
static void OnBrowse(HWND hDlg);
|
||||
static void OnDiskType(HWND hDlg, HWND hRadio);
|
||||
static void OnMediaType(HWND hDlg, HWND hCombo);
|
||||
static void OnProtect(HWND hDlg, HWND hCheck);
|
||||
static DWORD OnOK(HWND hDlg);
|
||||
|
||||
//
|
||||
// Show Open Image dialog box
|
||||
//
|
||||
DWORD WINAPI VfdGuiOpen(
|
||||
HWND hParent,
|
||||
ULONG nDevice)
|
||||
{
|
||||
switch (DialogBoxParam(
|
||||
g_hDllModule,
|
||||
MAKEINTRESOURCE(IDD_OPENDIALOG),
|
||||
hParent,
|
||||
OpenDialogProc,
|
||||
nDevice))
|
||||
{
|
||||
case IDOK:
|
||||
return ERROR_SUCCESS;
|
||||
|
||||
case IDCANCEL:
|
||||
return ERROR_CANCELLED;
|
||||
|
||||
default:
|
||||
return GetLastError();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Open image dialog procedure
|
||||
//
|
||||
INT CALLBACK OpenDialogProc(
|
||||
HWND hDlg,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
switch (uMsg) {
|
||||
case WM_INITDIALOG:
|
||||
OnInit(hDlg, lParam);
|
||||
return TRUE;
|
||||
|
||||
case WM_COMMAND:
|
||||
switch (wParam) {
|
||||
case MAKELONG(IDC_IMAGEFILE, EN_CHANGE):
|
||||
OnImage(hDlg, (HWND)lParam);
|
||||
return TRUE;
|
||||
|
||||
case IDC_BROWSE:
|
||||
OnBrowse(hDlg);
|
||||
return TRUE;
|
||||
|
||||
case IDC_DISKTYPE_FILE:
|
||||
case IDC_DISKTYPE_RAM:
|
||||
OnDiskType(hDlg, (HWND)lParam);
|
||||
return TRUE;
|
||||
|
||||
case MAKELONG(IDC_MEDIATYPE, CBN_SELCHANGE):
|
||||
OnMediaType(hDlg, (HWND)lParam);
|
||||
return TRUE;
|
||||
|
||||
case IDC_OPEN_PROTECTED:
|
||||
OnProtect(hDlg, (HWND)lParam);
|
||||
return TRUE;
|
||||
|
||||
case IDOK:
|
||||
if (OnOK(hDlg) == ERROR_SUCCESS) {
|
||||
EndDialog(hDlg, IDOK);
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
case IDCANCEL:
|
||||
EndDialog(hDlg, IDCANCEL);
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_CONTEXTMENU:
|
||||
ShowContextMenu(hDlg, (HWND)wParam, lParam);
|
||||
break;
|
||||
|
||||
case WM_HELP:
|
||||
{
|
||||
LPHELPINFO info = (LPHELPINFO)lParam;
|
||||
|
||||
if (info->iContextType == HELPINFO_WINDOW) {
|
||||
ShowHelpWindow(hDlg, info->iCtrlId);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize the Open Image dialog
|
||||
//
|
||||
void OnInit(
|
||||
HWND hDlg,
|
||||
ULONG nDevice)
|
||||
{
|
||||
VFD_MEDIA i;
|
||||
|
||||
// Store the device number
|
||||
|
||||
SetWindowLong(hDlg, GWL_USERDATA, nDevice);
|
||||
|
||||
// Store default file size
|
||||
|
||||
SetWindowLong(hDlg, DWL_USER, INVALID_FILE_SIZE);
|
||||
|
||||
// Set dialog window title
|
||||
|
||||
SetControlText(hDlg, 0, MSG_OPEN_TITLE);
|
||||
|
||||
// Set control captions
|
||||
|
||||
SetControlText(hDlg, IDC_IMAGEFILE_LABEL, MSG_IMAGEFILE_ACCEL);
|
||||
SetControlText(hDlg, IDC_IMAGEDESC_LABEL, MSG_DESCRIPTION_LABEL);
|
||||
SetControlText(hDlg, IDC_BROWSE, MSG_BROWSE_BUTTON);
|
||||
SetControlText(hDlg, IDC_DISKTYPE_LABEL, MSG_DISKTYPE_LABEL);
|
||||
SetControlText(hDlg, IDC_MEDIATYPE_LABEL, MSG_MEDIATYPE_ACCEL);
|
||||
SetControlText(hDlg, IDC_OPEN_PROTECTED, MSG_MENU_PROTECT);
|
||||
SetControlText(hDlg, IDOK, MSG_CREATE_BUTTON);
|
||||
SetControlText(hDlg, IDCANCEL, MSG_CANCEL_BUTTON);
|
||||
|
||||
// select RAM disk as default
|
||||
|
||||
CheckRadioButton(hDlg, IDC_DISKTYPE_FILE,
|
||||
IDC_DISKTYPE_RAM, IDC_DISKTYPE_RAM);
|
||||
|
||||
// setup media type combo list
|
||||
|
||||
for (i = 1; i < VFD_MEDIA_MAX; i++) {
|
||||
SendDlgItemMessage(hDlg, IDC_MEDIATYPE,
|
||||
CB_ADDSTRING, 0, (LPARAM)VfdMediaTypeName(i));
|
||||
}
|
||||
|
||||
// select 1.44MB as the default
|
||||
|
||||
SendDlgItemMessage(hDlg, IDC_MEDIATYPE, CB_SELECTSTRING,
|
||||
(WPARAM)-1, (LPARAM)VfdMediaTypeName(VFD_MEDIA_F3_1P4));
|
||||
|
||||
// set up other controls
|
||||
|
||||
OnImage(hDlg, GetDlgItem(hDlg, IDC_IMAGEFILE));
|
||||
}
|
||||
|
||||
//
|
||||
// Path is changed -- check if the file exists
|
||||
//
|
||||
void OnImage(
|
||||
HWND hDlg,
|
||||
HWND hEdit)
|
||||
{
|
||||
CHAR buf[MAX_PATH];
|
||||
DWORD file_attr;
|
||||
ULONG image_size;
|
||||
VFD_FILETYPE file_type;
|
||||
VFD_MEDIA media_type;
|
||||
|
||||
DWORD ret = ERROR_SUCCESS;
|
||||
|
||||
// Store default file size
|
||||
|
||||
SetWindowLong(hDlg, DWL_USER, INVALID_FILE_SIZE);
|
||||
|
||||
// get currently selected media type
|
||||
|
||||
media_type = (VFD_MEDIA)(SendDlgItemMessage(
|
||||
hDlg, IDC_MEDIATYPE, CB_GETCURSEL, 0, 0) + 1);
|
||||
|
||||
// clear hint and description text
|
||||
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE_DESC, NULL);
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE_HINT, NULL);
|
||||
|
||||
// get file name and file information
|
||||
|
||||
if (GetWindowText(hEdit, buf, sizeof(buf))) {
|
||||
|
||||
ret = VfdCheckImageFile(
|
||||
buf, &file_attr, &file_type, &image_size);
|
||||
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
|
||||
// use media type from image size
|
||||
|
||||
media_type = VfdLookupMedia(image_size);
|
||||
}
|
||||
else if (ret == ERROR_FILE_NOT_FOUND) {
|
||||
|
||||
// new file
|
||||
// use the parent directory attributes
|
||||
|
||||
PSTR p;
|
||||
|
||||
if ((p = strrchr(buf, '\\')) != NULL) {
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
file_attr = GetFileAttributes(buf);
|
||||
|
||||
if (file_attr == INVALID_FILE_ATTRIBUTES) {
|
||||
// directory access error
|
||||
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE_DESC, SystemMessage(ret));
|
||||
return;
|
||||
}
|
||||
|
||||
file_attr &= ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_DIRECTORY);
|
||||
image_size = INVALID_FILE_SIZE;
|
||||
file_type = VFD_FILETYPE_RAW;
|
||||
}
|
||||
else {
|
||||
// file access error
|
||||
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE_DESC, SystemMessage(ret));
|
||||
return;
|
||||
}
|
||||
|
||||
// make file description text
|
||||
|
||||
VfdMakeFileDesc(buf, sizeof(buf),
|
||||
file_type, image_size, file_attr);
|
||||
|
||||
// set file description
|
||||
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE_DESC, buf);
|
||||
}
|
||||
else {
|
||||
|
||||
// filename is empty - RAM disk
|
||||
|
||||
file_attr = 0;
|
||||
image_size = INVALID_FILE_SIZE;
|
||||
file_type = VFD_FILETYPE_NONE;
|
||||
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE_DESC, "RAM");
|
||||
}
|
||||
|
||||
// store the image size
|
||||
|
||||
SetWindowLong(hDlg, DWL_USER, image_size);
|
||||
|
||||
// setup disktype controls
|
||||
|
||||
if (file_type != VFD_FILETYPE_RAW ||
|
||||
(file_attr & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_COMPRESSED | FILE_ATTRIBUTE_ENCRYPTED))) {
|
||||
|
||||
// file cannot be opened directly -- RAM mode is forced
|
||||
|
||||
CheckRadioButton(hDlg, IDC_DISKTYPE_FILE,
|
||||
IDC_DISKTYPE_RAM, IDC_DISKTYPE_RAM);
|
||||
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_DISKTYPE_FILE), FALSE);
|
||||
}
|
||||
else {
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_DISKTYPE_FILE), TRUE);
|
||||
}
|
||||
|
||||
// set OK button text
|
||||
|
||||
if (image_size == INVALID_FILE_SIZE) {
|
||||
// file does not exist - OK button is "Create"
|
||||
|
||||
SetControlText(hDlg, IDOK, MSG_CREATE_BUTTON);
|
||||
}
|
||||
else {
|
||||
// file exists - OK button is "Open"
|
||||
|
||||
SetControlText(hDlg, IDOK, MSG_OPEN_BUTTON);
|
||||
}
|
||||
|
||||
// select media type
|
||||
|
||||
SendDlgItemMessage(hDlg, IDC_MEDIATYPE,
|
||||
CB_SETCURSEL, media_type - 1, 0);
|
||||
|
||||
OnMediaType(hDlg, GetDlgItem(hDlg, IDC_MEDIATYPE));
|
||||
}
|
||||
|
||||
//
|
||||
// Show open file dialog box
|
||||
//
|
||||
void OnBrowse(
|
||||
HWND hDlg)
|
||||
{
|
||||
OPENFILENAME ofn;
|
||||
PSTR title;
|
||||
PSTR filter;
|
||||
CHAR file[MAX_PATH];
|
||||
CHAR dir[MAX_PATH];
|
||||
DWORD len;
|
||||
|
||||
// prepare title and filter text
|
||||
|
||||
title = ModuleMessage(MSG_OPEN_TITLE);
|
||||
|
||||
filter = ModuleMessage(MSG_OPEN_FILTER);
|
||||
|
||||
if (filter) {
|
||||
PSTR p = filter;
|
||||
|
||||
do {
|
||||
if (*p == '|') {
|
||||
*p = '\0';
|
||||
}
|
||||
}
|
||||
while (*(++p));
|
||||
}
|
||||
|
||||
// get current file name from the control
|
||||
|
||||
ZeroMemory(file, sizeof(file));
|
||||
ZeroMemory(dir, sizeof(dir));
|
||||
|
||||
len = GetDlgItemText(hDlg, IDC_IMAGEFILE, file, sizeof(file));
|
||||
|
||||
if (len && file[len - 1] == '\\') {
|
||||
strcpy(dir, file);
|
||||
ZeroMemory(file, sizeof(file));
|
||||
}
|
||||
|
||||
// prepare OPENFILENAME structure
|
||||
|
||||
ZeroMemory(&ofn, sizeof(ofn));
|
||||
|
||||
ofn.lStructSize = IS_WINDOWS_NT() ?
|
||||
OPENFILENAME_SIZE_VERSION_400 : sizeof(ofn);
|
||||
|
||||
ofn.hwndOwner = hDlg;
|
||||
ofn.lpstrFilter = filter ? filter : FALLBACK_IMAGE_FILTER;
|
||||
ofn.lpstrFile = file;
|
||||
ofn.nMaxFile = sizeof(file);
|
||||
ofn.lpstrInitialDir = dir;
|
||||
ofn.lpstrTitle = title ? title : FALLBACK_IMAGE_TITLE;
|
||||
ofn.Flags = OFN_ENABLESIZING | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
|
||||
|
||||
// show the open file dialog box
|
||||
|
||||
if (GetOpenFileName(&ofn)) {
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE, file);
|
||||
SetFocus(GetDlgItem(hDlg, IDC_IMAGEFILE));
|
||||
}
|
||||
|
||||
// release text buffers
|
||||
|
||||
if (filter) {
|
||||
LocalFree(filter);
|
||||
}
|
||||
|
||||
if (title) {
|
||||
LocalFree(title);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Disk type is changed
|
||||
//
|
||||
void OnDiskType(
|
||||
HWND hDlg,
|
||||
HWND hRadio)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hDlg);
|
||||
UNREFERENCED_PARAMETER(hRadio);
|
||||
}
|
||||
|
||||
//
|
||||
// Media type is changed
|
||||
//
|
||||
void OnMediaType(
|
||||
HWND hDlg,
|
||||
HWND hCombo)
|
||||
{
|
||||
VFD_MEDIA media_type;
|
||||
ULONG media_size;
|
||||
ULONG image_size;
|
||||
|
||||
image_size = GetWindowLong(hDlg, DWL_USER);
|
||||
|
||||
if (image_size == INVALID_FILE_SIZE) {
|
||||
return;
|
||||
}
|
||||
|
||||
media_type = (VFD_MEDIA)(SendMessage(
|
||||
hCombo, CB_GETCURSEL, 0, 0) + 1);
|
||||
|
||||
if (media_type == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
media_size = VfdGetMediaSize(media_type);
|
||||
|
||||
if (media_size > image_size) {
|
||||
// selected media is too large
|
||||
SetControlText(hDlg, IDC_IMAGEFILE_HINT, MSG_FILE_TOO_SMALL);
|
||||
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
|
||||
return;
|
||||
}
|
||||
else if (media_size < image_size) {
|
||||
SetControlText(hDlg, IDC_IMAGEFILE_HINT, MSG_SIZE_MISMATCH);
|
||||
}
|
||||
else {
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE_HINT, NULL);
|
||||
}
|
||||
|
||||
EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
|
||||
}
|
||||
|
||||
//
|
||||
// Write Protect check box is clicked
|
||||
//
|
||||
void OnProtect(
|
||||
HWND hDlg,
|
||||
HWND hCheck)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hDlg);
|
||||
UNREFERENCED_PARAMETER(hCheck);
|
||||
}
|
||||
|
||||
//
|
||||
// Create / open an image
|
||||
//
|
||||
DWORD OnOK(
|
||||
HWND hDlg)
|
||||
{
|
||||
CHAR file_name[MAX_PATH];
|
||||
VFD_DISKTYPE disk_type;
|
||||
VFD_MEDIA media_type;
|
||||
VFD_FLAGS image_flags;
|
||||
HANDLE hDevice;
|
||||
DWORD ret;
|
||||
|
||||
// get the disk type
|
||||
|
||||
if (IsDlgButtonChecked(hDlg, IDC_DISKTYPE_FILE) == BST_CHECKED) {
|
||||
disk_type = VFD_DISKTYPE_FILE;
|
||||
}
|
||||
else {
|
||||
disk_type = VFD_DISKTYPE_RAM;
|
||||
}
|
||||
|
||||
// get the media type
|
||||
|
||||
media_type = (VFD_MEDIA)(SendDlgItemMessage(
|
||||
hDlg, IDC_MEDIATYPE, CB_GETCURSEL, 0, 0) + 1);
|
||||
|
||||
// get the protect flag
|
||||
|
||||
if (IsDlgButtonChecked(hDlg, IDC_OPEN_PROTECTED) == BST_CHECKED) {
|
||||
image_flags = VFD_FLAG_WRITE_PROTECTED;
|
||||
}
|
||||
else {
|
||||
image_flags = 0;
|
||||
}
|
||||
|
||||
// get the image name to create
|
||||
|
||||
if (GetDlgItemText(hDlg, IDC_IMAGEFILE, file_name, sizeof(file_name))) {
|
||||
|
||||
// file is specified
|
||||
|
||||
if (GetWindowLong(hDlg, DWL_USER) == INVALID_FILE_SIZE) {
|
||||
|
||||
// create a new image
|
||||
|
||||
ret = VfdCreateImageFile(
|
||||
file_name, media_type, VFD_FILETYPE_RAW, FALSE);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
goto exit_func;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// open the image
|
||||
|
||||
hDevice = VfdOpenDevice(GetWindowLong(hDlg, GWL_USERDATA));
|
||||
|
||||
if (hDevice == INVALID_HANDLE_VALUE) {
|
||||
ret = GetLastError();
|
||||
goto exit_func;
|
||||
}
|
||||
|
||||
ret = VfdOpenImage(
|
||||
hDevice, file_name, disk_type, media_type, image_flags);
|
||||
|
||||
CloseHandle(hDevice);
|
||||
|
||||
exit_func:
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
|
||||
// show error message
|
||||
|
||||
MessageBox(hDlg, SystemMessage(ret),
|
||||
VFD_MSGBOX_TITLE, MB_ICONSTOP);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
47
modules/rosapps/lib/vfdlib/vfdguirc.h
Normal file
47
modules/rosapps/lib/vfdlib/vfdguirc.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by vfdlib.rc
|
||||
//
|
||||
#define IDD_PROPDIALOG 101
|
||||
#define IDD_OPENDIALOG 102
|
||||
#define IDD_SAVEDIALOG 103
|
||||
#define IDI_VFD_ICON 104
|
||||
#define IDI_IMAGE_ICON 105
|
||||
#define IDI_CONFIG_ICON 106
|
||||
#define IDC_PROPERTY_TITLE 1001
|
||||
#define IDC_COPYRIGHT_STR 1002
|
||||
#define IDC_IMAGEFILE_LABEL 1003
|
||||
#define IDC_IMAGEFILE 1004
|
||||
#define IDC_IMAGEDESC_LABEL 1005
|
||||
#define IDC_IMAGEFILE_DESC 1006
|
||||
#define IDC_IMAGEFILE_HINT 1007
|
||||
#define IDC_TARGETFILE_LABEL 1008
|
||||
#define IDC_TARGETFILE 1009
|
||||
#define IDC_DISKTYPE_LABEL 1010
|
||||
#define IDC_DISKTYPE 1011
|
||||
#define IDC_DISKTYPE_FILE 1012
|
||||
#define IDC_DISKTYPE_RAM 1013
|
||||
#define IDC_MEDIATYPE_LABEL 1014
|
||||
#define IDC_MEDIATYPE 1015
|
||||
#define IDC_WRITE_PROTECTED 1016
|
||||
#define IDC_OPEN_PROTECTED 1017
|
||||
#define IDC_BROWSE 1018
|
||||
#define IDC_OPEN 1019
|
||||
#define IDC_SAVE 1020
|
||||
#define IDC_CLOSE 1021
|
||||
#define IDC_FORMAT 1022
|
||||
#define IDC_CONTROL 1023
|
||||
#define IDC_OVERWRITE 1024
|
||||
#define IDC_TRUNCATE 1025
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 107
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1025
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
529
modules/rosapps/lib/vfdlib/vfdguisave.c
Normal file
529
modules/rosapps/lib/vfdlib/vfdguisave.c
Normal file
|
@ -0,0 +1,529 @@
|
|||
/*
|
||||
vfdguisave.c
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
Save image GUI utility function
|
||||
|
||||
Copyright (c) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#pragma message(__FILE__": Compiled as C++ for testing purpose.")
|
||||
#endif // __cplusplus
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push,3)
|
||||
#endif
|
||||
#include <commdlg.h>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#include "vfdtypes.h"
|
||||
#include "vfdapi.h"
|
||||
#include "vfdlib.h"
|
||||
#ifndef __REACTOS__
|
||||
#include "vfdmsg.h"
|
||||
#else
|
||||
#include "vfdmsg_lib.h"
|
||||
#endif
|
||||
#include "vfdguirc.h"
|
||||
|
||||
//
|
||||
// local functions
|
||||
//
|
||||
static INT CALLBACK SaveDialogProc(
|
||||
HWND hDlg,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam);
|
||||
|
||||
static void OnInit(HWND hDlg, PCSAVE_PARAM pParam);
|
||||
static void OnTarget(HWND hDlg, HWND hEdit);
|
||||
static void OnBrowse(HWND hDlg);
|
||||
static void OnOverwrite(HWND hDlg, HWND hCheck);
|
||||
static void OnTruncate(HWND hDlg, HWND hCheck);
|
||||
static DWORD OnOK(HWND hDlg);
|
||||
|
||||
//
|
||||
// Show Save Image dialog box
|
||||
//
|
||||
DWORD WINAPI VfdGuiSave(
|
||||
HWND hParent,
|
||||
ULONG nDevice)
|
||||
{
|
||||
SAVE_PARAM param;
|
||||
CHAR path[MAX_PATH];
|
||||
DWORD ret;
|
||||
|
||||
// open the source device
|
||||
|
||||
param.hDevice = VfdOpenDevice(nDevice);
|
||||
|
||||
if (param.hDevice == INVALID_HANDLE_VALUE) {
|
||||
return GetLastError();
|
||||
}
|
||||
|
||||
// get current image information
|
||||
|
||||
param.ImageName = path;
|
||||
|
||||
ret = VfdGetImageInfo(
|
||||
param.hDevice,
|
||||
param.ImageName,
|
||||
¶m.DiskType,
|
||||
¶m.MediaType,
|
||||
¶m.MediaFlags,
|
||||
¶m.FileType,
|
||||
¶m.ImageSize);
|
||||
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
|
||||
// show dialog box
|
||||
|
||||
ret = GuiSaveParam(hParent, ¶m);
|
||||
}
|
||||
|
||||
// close the source device
|
||||
|
||||
CloseHandle(param.hDevice);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
DWORD GuiSaveParam(
|
||||
HWND hParent,
|
||||
PCSAVE_PARAM pParam)
|
||||
{
|
||||
switch (DialogBoxParam(
|
||||
g_hDllModule,
|
||||
MAKEINTRESOURCE(IDD_SAVEDIALOG),
|
||||
hParent,
|
||||
SaveDialogProc,
|
||||
(LPARAM)pParam))
|
||||
{
|
||||
case IDOK:
|
||||
return ERROR_SUCCESS;
|
||||
|
||||
case IDCANCEL:
|
||||
return ERROR_CANCELLED;
|
||||
|
||||
default:
|
||||
return GetLastError();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// The dialog procedure
|
||||
//
|
||||
INT CALLBACK SaveDialogProc(
|
||||
HWND hDlg,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
switch (uMsg) {
|
||||
case WM_INITDIALOG:
|
||||
OnInit(hDlg, (PCSAVE_PARAM)lParam);
|
||||
return TRUE;
|
||||
|
||||
case WM_COMMAND:
|
||||
switch (wParam) {
|
||||
case MAKELONG(IDC_TARGETFILE, EN_CHANGE):
|
||||
OnTarget(hDlg, (HWND)lParam);
|
||||
return TRUE;
|
||||
|
||||
case IDC_BROWSE:
|
||||
OnBrowse(hDlg);
|
||||
return TRUE;
|
||||
|
||||
case IDC_OVERWRITE:
|
||||
OnOverwrite(hDlg, (HWND)lParam);
|
||||
return TRUE;
|
||||
|
||||
case IDC_TRUNCATE:
|
||||
OnTruncate(hDlg, (HWND)lParam);
|
||||
return TRUE;
|
||||
|
||||
case IDOK:
|
||||
if (OnOK(hDlg) == ERROR_SUCCESS) {
|
||||
EndDialog(hDlg, IDOK);
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
case IDCANCEL:
|
||||
EndDialog(hDlg, IDCANCEL);
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_CONTEXTMENU:
|
||||
ShowContextMenu(hDlg, (HWND)wParam, lParam);
|
||||
break;
|
||||
|
||||
case WM_HELP:
|
||||
{
|
||||
LPHELPINFO info = (LPHELPINFO)lParam;
|
||||
|
||||
if (info->iContextType == HELPINFO_WINDOW) {
|
||||
ShowHelpWindow(hDlg, info->iCtrlId);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize the dialog
|
||||
//
|
||||
void OnInit(
|
||||
HWND hDlg,
|
||||
PCSAVE_PARAM pParam)
|
||||
{
|
||||
// Store parameters
|
||||
|
||||
SetWindowLong(hDlg, GWL_USERDATA, (ULONG)pParam);
|
||||
|
||||
// clear the target existence flag
|
||||
|
||||
SetWindowLong(hDlg, DWL_USER, 0);
|
||||
|
||||
// Set dialog window title
|
||||
|
||||
SetControlText(hDlg, 0, MSG_SAVE_TITLE);
|
||||
|
||||
// Set control captions
|
||||
|
||||
SetControlText(hDlg, IDC_IMAGEFILE_LABEL, MSG_IMAGEFILE_LABEL);
|
||||
SetControlText(hDlg, IDC_DISKTYPE_LABEL, MSG_DISKTYPE_LABEL);
|
||||
SetControlText(hDlg, IDC_MEDIATYPE_LABEL, MSG_MEDIATYPE_LABEL);
|
||||
SetControlText(hDlg, IDC_TARGETFILE_LABEL, MSG_TARGETFILE_LABEL);
|
||||
SetControlText(hDlg, IDC_IMAGEDESC_LABEL, MSG_DESCRIPTION_LABEL);
|
||||
SetControlText(hDlg, IDC_BROWSE, MSG_BROWSE_BUTTON);
|
||||
SetControlText(hDlg, IDC_OVERWRITE, MSG_OVERWRITE_CHECK);
|
||||
SetControlText(hDlg, IDC_TRUNCATE, MSG_TRUNCATE_CHECK);
|
||||
SetControlText(hDlg, IDOK, MSG_SAVE_BUTTON);
|
||||
SetControlText(hDlg, IDCANCEL, MSG_CANCEL_BUTTON);
|
||||
|
||||
// set disk type
|
||||
|
||||
if (pParam->DiskType == VFD_DISKTYPE_FILE) {
|
||||
SetDlgItemText(hDlg, IDC_DISKTYPE, "FILE");
|
||||
}
|
||||
else {
|
||||
SetDlgItemText(hDlg, IDC_DISKTYPE, "RAM");
|
||||
}
|
||||
|
||||
// display media type
|
||||
|
||||
SetDlgItemText(hDlg, IDC_MEDIATYPE,
|
||||
VfdMediaTypeName(pParam->MediaType));
|
||||
|
||||
// set current image and initial target
|
||||
|
||||
if (pParam->ImageName[0]) {
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE, pParam->ImageName);
|
||||
SetDlgItemText(hDlg, IDC_TARGETFILE, pParam->ImageName);
|
||||
}
|
||||
else if (pParam->DiskType != VFD_DISKTYPE_FILE) {
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE, "<RAM>");
|
||||
OnTarget(hDlg, GetDlgItem(hDlg, IDC_TARGETFILE));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Path is changed -- check specified target file
|
||||
//
|
||||
void OnTarget(
|
||||
HWND hDlg,
|
||||
HWND hEdit)
|
||||
{
|
||||
PCSAVE_PARAM param;
|
||||
CHAR buf[MAX_PATH];
|
||||
ULONG file_size;
|
||||
VFD_FILETYPE file_type;
|
||||
DWORD file_attr;
|
||||
DWORD ret;
|
||||
|
||||
// clear the target existence flag
|
||||
|
||||
SetWindowLong(hDlg, DWL_USER, 0);
|
||||
|
||||
// clear the description and hint text
|
||||
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE_DESC, NULL);
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE_HINT, NULL);
|
||||
|
||||
// get the target file name
|
||||
|
||||
if (GetWindowText(hEdit, buf, sizeof(buf)) == 0) {
|
||||
|
||||
// target file is blank
|
||||
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_OVERWRITE), FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_TRUNCATE), FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
CHAR full[MAX_PATH];
|
||||
PSTR file;
|
||||
|
||||
// convert into a full path
|
||||
|
||||
if (GetFullPathName(buf, sizeof(full), full, &file)) {
|
||||
strcpy(buf, full);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// get the current image info
|
||||
//
|
||||
param = (PCSAVE_PARAM)GetWindowLong(hDlg, GWL_USERDATA);
|
||||
|
||||
if (_stricmp(param->ImageName, buf) == 0) {
|
||||
|
||||
// target is the current file
|
||||
|
||||
char desc[MAX_PATH];
|
||||
|
||||
VfdMakeFileDesc(desc, sizeof(desc),
|
||||
param->FileType, param->ImageSize,
|
||||
GetFileAttributes(param->ImageName));
|
||||
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE_DESC, desc);
|
||||
SetControlText(hDlg, IDC_IMAGEFILE_HINT, MSG_CURRENT_FILE);
|
||||
|
||||
if (param->DiskType == VFD_DISKTYPE_FILE) {
|
||||
|
||||
// cannot overwrite the current FILE disk image
|
||||
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_OVERWRITE), FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_TRUNCATE), FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// check target image file
|
||||
//
|
||||
ret = VfdCheckImageFile(
|
||||
buf, &file_attr, &file_type, &file_size);
|
||||
|
||||
if (ret == ERROR_FILE_NOT_FOUND) {
|
||||
// file does not exist
|
||||
SetControlText(hDlg, IDC_IMAGEFILE_DESC, MSG_DESC_NEW_FILE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_OVERWRITE), FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_TRUNCATE), FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
|
||||
return;
|
||||
}
|
||||
else if (ret != ERROR_SUCCESS) {
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE_DESC, SystemMessage(ret));
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_OVERWRITE), FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_TRUNCATE), FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
// set target file description
|
||||
|
||||
VfdMakeFileDesc(buf, sizeof(buf),
|
||||
file_type, file_size, file_attr);
|
||||
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE_DESC, buf);
|
||||
|
||||
// check target file type
|
||||
|
||||
if (file_type == VFD_FILETYPE_ZIP) {
|
||||
SetControlText(hDlg, IDC_IMAGEFILE_HINT, MSG_TARGET_IS_ZIP);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_OVERWRITE), FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_TRUNCATE), FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
// the target is an existing raw file
|
||||
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_OVERWRITE), TRUE);
|
||||
|
||||
// set truncate box
|
||||
|
||||
if (file_size > VfdGetMediaSize(param->MediaType)) {
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_TRUNCATE), TRUE);
|
||||
SetControlText(hDlg, IDC_IMAGEFILE_HINT, MSG_SIZE_MISMATCH);
|
||||
}
|
||||
else {
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_TRUNCATE), FALSE);
|
||||
}
|
||||
|
||||
// check overwrite setting
|
||||
|
||||
if (IsDlgButtonChecked(hDlg, IDC_OVERWRITE) != BST_CHECKED) {
|
||||
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
|
||||
}
|
||||
else {
|
||||
EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
|
||||
}
|
||||
|
||||
// target file exists and overwritable
|
||||
|
||||
SetWindowLong(hDlg, DWL_USER, 1);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Show save file dialog box
|
||||
//
|
||||
void OnBrowse(
|
||||
HWND hDlg)
|
||||
{
|
||||
OPENFILENAME ofn;
|
||||
PSTR title;
|
||||
CHAR file[MAX_PATH];
|
||||
CHAR dir[MAX_PATH];
|
||||
DWORD len;
|
||||
|
||||
title = ModuleMessage(MSG_SAVE_TITLE);
|
||||
|
||||
ZeroMemory(&ofn, sizeof(ofn));
|
||||
ZeroMemory(file, sizeof(file));
|
||||
ZeroMemory(dir, sizeof(dir));
|
||||
|
||||
len = GetDlgItemText(hDlg, IDC_TARGETFILE, file, sizeof(file));
|
||||
|
||||
if (len && file[len - 1] == '\\') {
|
||||
strcpy(dir, file);
|
||||
ZeroMemory(file, sizeof(file));
|
||||
}
|
||||
|
||||
// Different structure sizes must be used for NT and 2K/XP
|
||||
ofn.lStructSize = IS_WINDOWS_NT() ?
|
||||
OPENFILENAME_SIZE_VERSION_400 : sizeof(ofn);
|
||||
|
||||
ofn.hwndOwner = hDlg;
|
||||
ofn.lpstrFile = file;
|
||||
ofn.nMaxFile = sizeof(file);
|
||||
ofn.lpstrInitialDir = dir;
|
||||
ofn.lpstrTitle = title ? title : "Save Image";
|
||||
ofn.lpstrFilter = "*.*\0*.*\0";
|
||||
ofn.Flags = OFN_ENABLESIZING | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
|
||||
|
||||
if (GetSaveFileName(&ofn)) {
|
||||
SetDlgItemText(hDlg, IDC_TARGETFILE, file);
|
||||
SetFocus(GetDlgItem(hDlg, IDC_TARGETFILE));
|
||||
}
|
||||
|
||||
if (title) {
|
||||
LocalFree(title);
|
||||
}
|
||||
}
|
||||
|
||||
void OnOverwrite(
|
||||
HWND hDlg,
|
||||
HWND hCheck)
|
||||
{
|
||||
if (GetWindowLong(hDlg, DWL_USER)) {
|
||||
// the target file exists and overwritable
|
||||
if (SendMessage(hCheck, BM_GETCHECK, 0, 0) != BST_CHECKED) {
|
||||
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
|
||||
}
|
||||
else {
|
||||
EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnTruncate(
|
||||
HWND hDlg,
|
||||
HWND hCheck)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hDlg);
|
||||
UNREFERENCED_PARAMETER(hCheck);
|
||||
}
|
||||
|
||||
//
|
||||
// Save image
|
||||
//
|
||||
DWORD OnOK(
|
||||
HWND hDlg)
|
||||
{
|
||||
PCSAVE_PARAM param;
|
||||
CHAR path[MAX_PATH];
|
||||
BOOL overwrite;
|
||||
BOOL truncate;
|
||||
DWORD ret;
|
||||
|
||||
param = (PCSAVE_PARAM)GetWindowLong(hDlg, GWL_USERDATA);
|
||||
|
||||
if (!param) {
|
||||
return ERROR_INVALID_FUNCTION;
|
||||
}
|
||||
|
||||
// get the target image name
|
||||
|
||||
if (GetDlgItemText(hDlg, IDC_TARGETFILE, path, sizeof(path)) == 0) {
|
||||
return ERROR_INVALID_FUNCTION;
|
||||
}
|
||||
|
||||
if (GetWindowLong(hDlg, DWL_USER)) {
|
||||
// the target file exists and overwritable
|
||||
overwrite = (IsDlgButtonChecked(hDlg, IDC_OVERWRITE) == BST_CHECKED);
|
||||
truncate = (IsDlgButtonChecked(hDlg, IDC_TRUNCATE) == BST_CHECKED);
|
||||
}
|
||||
else {
|
||||
overwrite = FALSE;
|
||||
truncate = TRUE;
|
||||
}
|
||||
|
||||
retry:
|
||||
ret = VfdDismountVolume(param->hDevice, FALSE);
|
||||
|
||||
if (ret == ERROR_ACCESS_DENIED) {
|
||||
PSTR msg = ModuleMessage(MSG_UNMOUNT_CONFIRM);
|
||||
|
||||
int reply = MessageBox(
|
||||
hDlg, msg ? msg : "retry", VFD_MSGBOX_TITLE,
|
||||
MB_ICONEXCLAMATION | MB_CANCELTRYCONTINUE);
|
||||
|
||||
if (msg) {
|
||||
LocalFree(msg);
|
||||
}
|
||||
|
||||
if (reply == IDRETRY) {
|
||||
goto retry;
|
||||
}
|
||||
else if (reply == IDCANCEL) {
|
||||
return ERROR_CANCELLED;
|
||||
}
|
||||
else {
|
||||
VfdDismountVolume(param->hDevice, TRUE);
|
||||
}
|
||||
}
|
||||
else if (ret != ERROR_SUCCESS) {
|
||||
|
||||
MessageBox(hDlg, SystemMessage(ret),
|
||||
VFD_MSGBOX_TITLE, MB_ICONSTOP);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = VfdSaveImage(param->hDevice, path, overwrite, truncate);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
|
||||
// show error message
|
||||
|
||||
MessageBox(hDlg, SystemMessage(ret),
|
||||
VFD_MSGBOX_TITLE, MB_ICONSTOP);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
354
modules/rosapps/lib/vfdlib/vfdguitip.c
Normal file
354
modules/rosapps/lib/vfdlib/vfdguitip.c
Normal file
|
@ -0,0 +1,354 @@
|
|||
/*
|
||||
vfdguitip.c
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
tooltip information GUI utility functions
|
||||
|
||||
Copyright (c) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#pragma message(__FILE__": Compiled as C++ for testing purpose.")
|
||||
#endif // __cplusplus
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include "vfdtypes.h"
|
||||
#include "vfdapi.h"
|
||||
#include "vfdlib.h"
|
||||
#ifndef __REACTOS__
|
||||
#include "vfdmsg.h"
|
||||
#else
|
||||
#include "vfdmsg_lib.h"
|
||||
#endif
|
||||
|
||||
//
|
||||
// tooltip window class name
|
||||
//
|
||||
#define VFD_INFOTIP_WNDCLASS "VfdInfoTip"
|
||||
|
||||
//
|
||||
// the window procedure
|
||||
//
|
||||
static LRESULT CALLBACK ToolTipProc(
|
||||
HWND hWnd,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
switch (uMsg) {
|
||||
case WM_CREATE:
|
||||
// Store Font handle
|
||||
SetWindowLong(hWnd, GWL_USERDATA,
|
||||
(LONG)((LPCREATESTRUCT)lParam)->lpCreateParams);
|
||||
return 0;
|
||||
|
||||
case WM_PAINT:
|
||||
{
|
||||
PAINTSTRUCT paint;
|
||||
HDC hDC = BeginPaint(hWnd, &paint);
|
||||
|
||||
if (hDC) {
|
||||
char text[MAX_PATH];
|
||||
int len;
|
||||
RECT rc;
|
||||
|
||||
|
||||
SelectObject(hDC, (HFONT)GetWindowLong(hWnd, GWL_USERDATA));
|
||||
|
||||
SetTextColor(hDC, GetSysColor(COLOR_INFOTEXT));
|
||||
SetBkMode(hDC, TRANSPARENT);
|
||||
|
||||
len = GetWindowText(hWnd, text, sizeof(text));
|
||||
|
||||
rc.top = 8;
|
||||
rc.left = 8;
|
||||
rc.right = paint.rcPaint.right;
|
||||
rc.bottom = paint.rcPaint.bottom;
|
||||
|
||||
DrawText(hDC, text, len, &rc, DT_LEFT | DT_TOP);
|
||||
|
||||
EndPaint(hWnd, &paint);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_KILLFOCUS:
|
||||
if (!(GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOPMOST)) {
|
||||
// Stick tool tip - Closed on kill focus
|
||||
DestroyWindow(hWnd);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_SETCURSOR:
|
||||
if (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) {
|
||||
// Non-stick tool tip - Closed when cursor leaves
|
||||
TRACKMOUSEEVENT track;
|
||||
|
||||
track.cbSize = sizeof(track);
|
||||
track.dwFlags = TME_LEAVE;
|
||||
track.hwndTrack = hWnd;
|
||||
track.dwHoverTime = 0;
|
||||
|
||||
TrackMouseEvent(&track);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_MOUSELEAVE:
|
||||
// Non-stick tool tip - Closed when cursor leaves
|
||||
DestroyWindow(hWnd);
|
||||
return 0;
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
case WM_MBUTTONDOWN:
|
||||
case WM_RBUTTONDOWN:
|
||||
// Both stick and non-stick tool tip
|
||||
// Closed when clicked
|
||||
SetCapture(hWnd);
|
||||
return 0;
|
||||
|
||||
case WM_LBUTTONUP:
|
||||
case WM_MBUTTONUP:
|
||||
case WM_RBUTTONUP:
|
||||
// Both stick and non-stick tool tip
|
||||
// Closed when clicked
|
||||
if (GetCapture() == hWnd) {
|
||||
DestroyWindow(hWnd);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_DESTROY:
|
||||
// delete font
|
||||
DeleteObject((HFONT)GetWindowLong(hWnd, GWL_USERDATA));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
//
|
||||
// Create and show tooltip window
|
||||
//
|
||||
void WINAPI VfdToolTip(
|
||||
HWND hParent,
|
||||
PCSTR sText,
|
||||
int pos_x,
|
||||
int pos_y,
|
||||
BOOL stick)
|
||||
{
|
||||
#ifndef __REACTOS__
|
||||
HWND hWnd;
|
||||
#endif
|
||||
WNDCLASS wc = {0};
|
||||
LOGFONT lf;
|
||||
HFONT font;
|
||||
HDC dc;
|
||||
int len;
|
||||
SIZE sz;
|
||||
RECT rc;
|
||||
int scr_x;
|
||||
int scr_y;
|
||||
|
||||
//
|
||||
// Register Window Class
|
||||
//
|
||||
|
||||
wc.lpfnWndProc = ToolTipProc;
|
||||
wc.hInstance = g_hDllModule;
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.hbrBackground = (HBRUSH)(COLOR_INFOBK + 1);
|
||||
wc.lpszClassName = VFD_INFOTIP_WNDCLASS;
|
||||
|
||||
RegisterClass(&wc);
|
||||
|
||||
//
|
||||
// Create Tool Tip Font (== Icon title font)
|
||||
//
|
||||
|
||||
SystemParametersInfo(
|
||||
SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
|
||||
|
||||
font = CreateFontIndirect(&lf);
|
||||
|
||||
//
|
||||
// Calculate Tool Tip Window size
|
||||
//
|
||||
|
||||
dc = GetDC(hParent);
|
||||
|
||||
SelectObject(dc, font);
|
||||
|
||||
len = strlen(sText);
|
||||
|
||||
GetTextExtentPoint32(dc, sText, len, &sz);
|
||||
|
||||
rc.left = 0;
|
||||
rc.top = 0;
|
||||
rc.right = sz.cx;
|
||||
rc.bottom = sz.cy;
|
||||
|
||||
DrawText(dc, sText, len, &rc, DT_CALCRECT | DT_LEFT | DT_TOP);
|
||||
|
||||
ReleaseDC(hParent, dc);
|
||||
|
||||
sz.cx = rc.right - rc.left + 16;
|
||||
sz.cy = rc.bottom - rc.top + 16;
|
||||
|
||||
//
|
||||
// Decide the window position
|
||||
//
|
||||
if (pos_x == -1 || pos_y == -1) {
|
||||
//
|
||||
// Use current cursor position
|
||||
//
|
||||
POINT pt;
|
||||
|
||||
GetCursorPos(&pt);
|
||||
|
||||
pos_x = pt.x - (sz.cx / 2);
|
||||
pos_y = pt.y - (sz.cy / 2);
|
||||
}
|
||||
else {
|
||||
pos_x = pos_x - (sz.cx / 2);
|
||||
}
|
||||
|
||||
//
|
||||
// make sure the tip window fits in visible area
|
||||
//
|
||||
scr_x = GetSystemMetrics(SM_CXSCREEN);
|
||||
scr_y = GetSystemMetrics(SM_CYSCREEN);
|
||||
|
||||
if (pos_x < 0) {
|
||||
pos_x = 0;
|
||||
}
|
||||
if (pos_x + sz.cx > scr_x) {
|
||||
pos_x = scr_x - sz.cx;
|
||||
}
|
||||
if (pos_y < 0) {
|
||||
pos_y = 0;
|
||||
}
|
||||
if (pos_y + sz.cy > scr_y) {
|
||||
pos_y = scr_y - sz.cy;
|
||||
}
|
||||
|
||||
//
|
||||
// Create the tool tip window
|
||||
//
|
||||
#ifndef __REACTOS__
|
||||
hWnd = CreateWindowEx(
|
||||
#else
|
||||
CreateWindowEx(
|
||||
#endif
|
||||
stick ? 0 : WS_EX_TOPMOST,
|
||||
VFD_INFOTIP_WNDCLASS,
|
||||
sText,
|
||||
WS_BORDER | WS_POPUP | WS_VISIBLE,
|
||||
pos_x, pos_y,
|
||||
sz.cx, sz.cy,
|
||||
hParent,
|
||||
NULL,
|
||||
NULL,
|
||||
(PVOID)font);
|
||||
|
||||
//
|
||||
// Give focus if it is not a stick tool-tip
|
||||
//
|
||||
if (!stick) {
|
||||
SetFocus(hParent);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Show an image information tooltip
|
||||
//
|
||||
void WINAPI VfdImageTip(
|
||||
HWND hParent,
|
||||
ULONG nDevice)
|
||||
{
|
||||
HANDLE hDevice;
|
||||
PSTR info_str = NULL;
|
||||
PSTR type_str = NULL;
|
||||
PSTR prot_str = NULL;
|
||||
PCSTR media_str = NULL;
|
||||
CHAR path[MAX_PATH];
|
||||
CHAR desc[MAX_PATH];
|
||||
VFD_DISKTYPE disk_type;
|
||||
VFD_MEDIA media_type;
|
||||
VFD_FLAGS media_flags;
|
||||
VFD_FILETYPE file_type;
|
||||
ULONG image_size;
|
||||
DWORD file_attr;
|
||||
ULONG ret;
|
||||
|
||||
hDevice = VfdOpenDevice(nDevice);
|
||||
|
||||
if (hDevice == INVALID_HANDLE_VALUE) {
|
||||
VfdToolTip(hParent,
|
||||
SystemMessage(GetLastError()), -1, -1, FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = VfdGetImageInfo(
|
||||
hDevice,
|
||||
path,
|
||||
&disk_type,
|
||||
&media_type,
|
||||
&media_flags,
|
||||
&file_type,
|
||||
&image_size);
|
||||
|
||||
CloseHandle(hDevice);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
VfdToolTip(hParent, SystemMessage(ret), -1, -1, FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (path[0]) {
|
||||
file_attr = GetFileAttributes(path);
|
||||
}
|
||||
else {
|
||||
if (disk_type != VFD_DISKTYPE_FILE) {
|
||||
strcpy(path, "<RAM>");
|
||||
}
|
||||
file_attr = 0;
|
||||
}
|
||||
|
||||
VfdMakeFileDesc(desc, sizeof(desc),
|
||||
file_type, image_size, file_attr);
|
||||
|
||||
if (disk_type == VFD_DISKTYPE_FILE) {
|
||||
type_str = "FILE";
|
||||
}
|
||||
else {
|
||||
type_str = "RAM";
|
||||
}
|
||||
|
||||
media_str = VfdMediaTypeName(media_type);
|
||||
|
||||
if (media_flags & VFD_FLAG_WRITE_PROTECTED) {
|
||||
prot_str = ModuleMessage(MSG_WRITE_PROTECTED);
|
||||
}
|
||||
else {
|
||||
prot_str = ModuleMessage(MSG_WRITE_ALLOWED);
|
||||
}
|
||||
|
||||
info_str = ModuleMessage(
|
||||
MSG_IMAGE_INFOTIP,
|
||||
path,
|
||||
desc,
|
||||
type_str ? type_str : "",
|
||||
media_str ? media_str : "",
|
||||
prot_str ? prot_str : "");
|
||||
|
||||
if (info_str) {
|
||||
VfdToolTip(hParent, info_str, -1, -1, FALSE);
|
||||
LocalFree(info_str);
|
||||
}
|
||||
|
||||
if (prot_str) {
|
||||
LocalFree(prot_str);
|
||||
}
|
||||
}
|
581
modules/rosapps/lib/vfdlib/vfdguiut.c
Normal file
581
modules/rosapps/lib/vfdlib/vfdguiut.c
Normal file
|
@ -0,0 +1,581 @@
|
|||
/*
|
||||
vfdguiut.c
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
open / close / format GUI utility functions
|
||||
|
||||
Copyright (c) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#pragma message(__FILE__": Compiled as C++ for testing purpose.")
|
||||
#endif // __cplusplus
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "vfdtypes.h"
|
||||
#include "vfdapi.h"
|
||||
#include "vfdlib.h"
|
||||
#ifndef __REACTOS__
|
||||
#include "vfdmsg.h"
|
||||
#else
|
||||
#include "vfdmsg_lib.h"
|
||||
#endif
|
||||
#include "vfdguirc.h"
|
||||
|
||||
//
|
||||
// message box constants added since Win2K
|
||||
//
|
||||
|
||||
#ifndef MB_CANCELTRYCONTINUE
|
||||
#define MB_CANCELTRYCONTINUE 0x00000006L
|
||||
#endif
|
||||
|
||||
#ifndef IDTRYAGAIN
|
||||
#define IDTRYAGAIN 10
|
||||
#endif
|
||||
|
||||
#ifndef IDCONTINUE
|
||||
#define IDCONTINUE 11
|
||||
#endif
|
||||
|
||||
//
|
||||
// local funcitons
|
||||
//
|
||||
static PSTR FormatSizeBytes(ULONG size, PSTR buf)
|
||||
{
|
||||
ULONG comma = 1;
|
||||
int len;
|
||||
|
||||
while ((comma * 1000) < size) {
|
||||
comma *= 1000;
|
||||
}
|
||||
|
||||
len = sprintf(buf, "%lu", size / comma);
|
||||
|
||||
while (comma > 1) {
|
||||
size %= comma;
|
||||
comma /= 1000;
|
||||
len += sprintf(buf + len, ",%03lu", size / comma);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static PSTR FormatSizeUnits(ULONG size, PSTR buf)
|
||||
{
|
||||
static const char *name[3] = {
|
||||
" KB", " MB", " GB"
|
||||
};
|
||||
int unit;
|
||||
double dsize;
|
||||
|
||||
if (size < 1000) {
|
||||
#ifndef __REACTOS__
|
||||
sprintf(buf, "%u", size);
|
||||
#else
|
||||
sprintf(buf, "%lu", size);
|
||||
#endif
|
||||
return buf;
|
||||
}
|
||||
|
||||
dsize = size;
|
||||
dsize /= 1024;
|
||||
unit = 0;
|
||||
|
||||
while (unit < 2 && dsize >= 1000) {
|
||||
dsize /= 1000;
|
||||
unit++;
|
||||
}
|
||||
|
||||
if (dsize < 10) {
|
||||
sprintf(buf, "%3.2f%s", dsize, name[unit]);
|
||||
}
|
||||
else if (dsize < 100) {
|
||||
sprintf(buf, "%3.1f%s", dsize, name[unit]);
|
||||
}
|
||||
else if (dsize < 1000) {
|
||||
sprintf(buf, "%3.0f%s", dsize, name[unit]);
|
||||
}
|
||||
else {
|
||||
FormatSizeBytes((ULONG)dsize, buf);
|
||||
strcat(buf, name[unit]);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
//
|
||||
// Close the current image
|
||||
//
|
||||
DWORD WINAPI VfdGuiClose(
|
||||
HWND hParent, // parent window
|
||||
ULONG nDevice) // device number
|
||||
{
|
||||
HANDLE hDevice;
|
||||
SAVE_PARAM param;
|
||||
CHAR path[MAX_PATH];
|
||||
HCURSOR hourglass;
|
||||
DWORD ret;
|
||||
int reply;
|
||||
|
||||
VFDTRACE(0, ("VfdGuiClose()\n"));
|
||||
|
||||
hDevice = VfdOpenDevice(nDevice);
|
||||
|
||||
if (hDevice == INVALID_HANDLE_VALUE) {
|
||||
return GetLastError();
|
||||
}
|
||||
|
||||
// get current image information
|
||||
|
||||
ret = VfdGetImageInfo(
|
||||
hDevice,
|
||||
path,
|
||||
¶m.DiskType,
|
||||
¶m.MediaType,
|
||||
¶m.MediaFlags,
|
||||
¶m.FileType,
|
||||
¶m.ImageSize);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
CloseHandle(hDevice);
|
||||
return ret;
|
||||
}
|
||||
|
||||
param.hDevice = hDevice;
|
||||
param.ImageName = path;
|
||||
|
||||
// check if RAM image is modified
|
||||
|
||||
if (param.MediaFlags & VFD_FLAG_DATA_MODIFIED) {
|
||||
PSTR msg = ModuleMessage(MSG_MEDIA_MODIFIED);
|
||||
|
||||
for (;;) {
|
||||
reply = MessageBox(hParent, msg ? msg : "save?",
|
||||
VFD_MSGBOX_TITLE, MB_ICONQUESTION | MB_YESNOCANCEL);
|
||||
|
||||
if (reply != IDYES) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (GuiSaveParam(hParent, ¶m) == ERROR_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (msg) {
|
||||
LocalFree(msg);
|
||||
}
|
||||
|
||||
if (reply == IDCANCEL) {
|
||||
CloseHandle(hDevice);
|
||||
return ERROR_CANCELLED;
|
||||
}
|
||||
}
|
||||
|
||||
// close the image
|
||||
|
||||
hourglass = LoadCursor(NULL, IDC_WAIT);
|
||||
|
||||
for (;;) {
|
||||
|
||||
// show the hourglass cursor
|
||||
|
||||
HCURSOR original = SetCursor(hourglass);
|
||||
|
||||
// close the current image
|
||||
|
||||
ret = VfdCloseImage(hDevice, FALSE);
|
||||
|
||||
// restore the original cursor
|
||||
|
||||
SetCursor(original);
|
||||
|
||||
if (ret != ERROR_ACCESS_DENIED) {
|
||||
// success or errors other than access denied
|
||||
break;
|
||||
}
|
||||
|
||||
if (IS_WINDOWS_NT()) {
|
||||
|
||||
// Windows NT -- cannot force close
|
||||
// show retry / cancel message box
|
||||
|
||||
PSTR msg = ModuleMessage(MSG_UNMOUNT_FAILED);
|
||||
|
||||
reply = MessageBox(
|
||||
hParent, msg ? msg : "retry", VFD_MSGBOX_TITLE,
|
||||
MB_ICONEXCLAMATION | MB_RETRYCANCEL);
|
||||
|
||||
if (msg) {
|
||||
LocalFree(msg);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
// Windows 2000 and later -- possible to force
|
||||
// show cancel / retry / continue message box
|
||||
|
||||
PSTR msg = ModuleMessage(MSG_UNMOUNT_CONFIRM);
|
||||
|
||||
reply = MessageBox(
|
||||
hParent, msg ? msg : "retry", VFD_MSGBOX_TITLE,
|
||||
MB_ICONEXCLAMATION | MB_CANCELTRYCONTINUE);
|
||||
|
||||
if (msg) {
|
||||
LocalFree(msg);
|
||||
}
|
||||
|
||||
if (reply == IDCONTINUE) {
|
||||
|
||||
// try forced close
|
||||
|
||||
ret = VfdCloseImage(hDevice, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
if (reply == IDCANCEL) {
|
||||
ret = ERROR_CANCELLED;
|
||||
break;
|
||||
}
|
||||
else if (reply == IDCONTINUE) {
|
||||
|
||||
// try forced close
|
||||
|
||||
ret = VfdCloseImage(hDevice, TRUE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(hDevice);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
// Format the current media
|
||||
//
|
||||
DWORD WINAPI VfdGuiFormat(
|
||||
HWND hParent, // parent window
|
||||
ULONG nDevice) // device number
|
||||
{
|
||||
HANDLE hDevice;
|
||||
ULONG ret;
|
||||
PSTR msg;
|
||||
|
||||
msg = ModuleMessage(MSG_FORMAT_WARNING);
|
||||
|
||||
ret = MessageBox(hParent,
|
||||
msg ? msg : "Format?",
|
||||
VFD_MSGBOX_TITLE,
|
||||
MB_ICONEXCLAMATION | MB_OKCANCEL);
|
||||
|
||||
if (msg) {
|
||||
LocalFree(msg);
|
||||
}
|
||||
|
||||
if (ret == IDCANCEL) {
|
||||
MessageBox(hParent,
|
||||
SystemMessage(ERROR_CANCELLED),
|
||||
VFD_MSGBOX_TITLE, MB_ICONSTOP);
|
||||
|
||||
return ERROR_CANCELLED;
|
||||
}
|
||||
|
||||
hDevice = VfdOpenDevice(nDevice);
|
||||
|
||||
if (hDevice == INVALID_HANDLE_VALUE) {
|
||||
ret = GetLastError();
|
||||
}
|
||||
else {
|
||||
HCURSOR original;
|
||||
|
||||
retry:
|
||||
original = SetCursor(LoadCursor(NULL, IDC_WAIT));
|
||||
|
||||
ret = VfdDismountVolume(hDevice, FALSE);
|
||||
|
||||
if (ret == ERROR_ACCESS_DENIED) {
|
||||
PSTR msg;
|
||||
int reply;
|
||||
|
||||
SetCursor(original);
|
||||
|
||||
msg = ModuleMessage(MSG_UNMOUNT_CONFIRM);
|
||||
|
||||
reply = MessageBox(
|
||||
hParent, msg ? msg : "retry", VFD_MSGBOX_TITLE,
|
||||
MB_ICONEXCLAMATION | MB_CANCELTRYCONTINUE);
|
||||
|
||||
if (msg) {
|
||||
LocalFree(msg);
|
||||
}
|
||||
|
||||
if (reply == IDRETRY) {
|
||||
goto retry;
|
||||
}
|
||||
else if (reply == IDCANCEL) {
|
||||
ret = ERROR_CANCELLED;
|
||||
}
|
||||
else {
|
||||
VfdDismountVolume(hDevice, TRUE);
|
||||
ret = ERROR_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
ret = VfdFormatMedia(hDevice);
|
||||
}
|
||||
|
||||
SetCursor(original);
|
||||
|
||||
CloseHandle(hDevice);
|
||||
}
|
||||
|
||||
MessageBox(hParent,
|
||||
SystemMessage(ret),
|
||||
VFD_MSGBOX_TITLE,
|
||||
ret == ERROR_SUCCESS ? MB_ICONINFORMATION : MB_ICONSTOP);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
// Set a text to a dialog control
|
||||
//
|
||||
void SetControlText(
|
||||
HWND hWnd,
|
||||
UINT nCtrl,
|
||||
DWORD nMsg)
|
||||
{
|
||||
PSTR p = NULL;
|
||||
|
||||
if (nMsg) {
|
||||
p = ModuleMessage(nMsg);
|
||||
}
|
||||
|
||||
if (nCtrl) {
|
||||
SetDlgItemText(hWnd, nCtrl, p);
|
||||
}
|
||||
else {
|
||||
SetWindowText(hWnd, p);
|
||||
}
|
||||
|
||||
if (p) {
|
||||
LocalFree(p);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Make file description text
|
||||
//
|
||||
void WINAPI VfdMakeFileDesc(
|
||||
PSTR pBuffer,
|
||||
ULONG nBufSize,
|
||||
VFD_FILETYPE nFileType,
|
||||
ULONG nFileSize,
|
||||
DWORD nFileAttr)
|
||||
{
|
||||
PSTR type_str;
|
||||
PSTR size_str;
|
||||
PSTR attr_ro;
|
||||
PSTR attr_enc;
|
||||
PSTR attr_cmp;
|
||||
|
||||
ZeroMemory(pBuffer, nBufSize);
|
||||
|
||||
switch (nFileType) {
|
||||
case VFD_FILETYPE_RAW:
|
||||
type_str = ModuleMessage(MSG_FILETYPE_RAW);
|
||||
break;
|
||||
|
||||
case VFD_FILETYPE_ZIP:
|
||||
type_str = ModuleMessage(MSG_FILETYPE_ZIP);
|
||||
break;
|
||||
|
||||
default:
|
||||
type_str = NULL;
|
||||
}
|
||||
|
||||
if (nFileSize == INVALID_FILE_SIZE) {
|
||||
size_str = ModuleMessage(MSG_DESC_NEW_FILE);
|
||||
}
|
||||
else {
|
||||
CHAR buf[20], buf2[20];
|
||||
size_str = ModuleMessage(MSG_DESC_FILESIZE,
|
||||
FormatSizeBytes(nFileSize, buf),
|
||||
FormatSizeUnits(nFileSize, buf2));
|
||||
}
|
||||
|
||||
attr_ro = NULL;
|
||||
attr_cmp = NULL;
|
||||
attr_enc = NULL;
|
||||
|
||||
if (nFileAttr != INVALID_FILE_ATTRIBUTES) {
|
||||
if (nFileAttr & FILE_ATTRIBUTE_READONLY) {
|
||||
attr_ro = ModuleMessage(MSG_ATTR_READONLY);
|
||||
}
|
||||
|
||||
if (nFileAttr & FILE_ATTRIBUTE_COMPRESSED) {
|
||||
attr_cmp = ModuleMessage(MSG_ATTR_COMPRESSED);
|
||||
}
|
||||
|
||||
if (nFileAttr & FILE_ATTRIBUTE_ENCRYPTED) {
|
||||
attr_enc = ModuleMessage(MSG_ATTR_ENCRYPTED);
|
||||
}
|
||||
}
|
||||
|
||||
_snprintf(pBuffer, nBufSize - 1, "%s %s %s %s %s",
|
||||
type_str ? type_str : "",
|
||||
size_str ? size_str : "",
|
||||
attr_ro ? attr_ro : "",
|
||||
attr_cmp ? attr_cmp : "",
|
||||
attr_enc ? attr_enc : "");
|
||||
|
||||
if (type_str) {
|
||||
LocalFree(type_str);
|
||||
}
|
||||
if (size_str) {
|
||||
LocalFree(size_str);
|
||||
}
|
||||
if (attr_ro) {
|
||||
LocalFree(attr_ro);
|
||||
}
|
||||
if (attr_cmp) {
|
||||
LocalFree(attr_cmp);
|
||||
}
|
||||
if (attr_enc) {
|
||||
LocalFree(attr_enc);
|
||||
}
|
||||
}
|
||||
|
||||
void ShowContextMenu(
|
||||
HWND hDlg,
|
||||
HWND hCtl,
|
||||
LPARAM lParam)
|
||||
{
|
||||
POINT pt;
|
||||
UINT id;
|
||||
HMENU hMenu;
|
||||
|
||||
pt.x = ((int)(short)LOWORD(lParam));
|
||||
pt.y = ((int)(short)HIWORD(lParam));
|
||||
|
||||
if (pt.x == -1 || pt.y == -1) {
|
||||
RECT rc;
|
||||
|
||||
GetWindowRect(hCtl, &rc);
|
||||
pt.x = (rc.left + rc.right) / 2;
|
||||
pt.y = (rc.top + rc.bottom) / 2;
|
||||
|
||||
id = GetDlgCtrlID(hCtl);
|
||||
}
|
||||
else {
|
||||
POINT pt2 = pt;
|
||||
|
||||
ScreenToClient(hDlg, &pt2);
|
||||
|
||||
id = GetDlgCtrlID(
|
||||
ChildWindowFromPoint(hDlg, pt2));
|
||||
}
|
||||
|
||||
if (id < IDC_IMAGEFILE_LABEL ||
|
||||
id > IDC_TRUNCATE) {
|
||||
return;
|
||||
}
|
||||
|
||||
hMenu = CreatePopupMenu();
|
||||
|
||||
AppendMenu(hMenu, MF_STRING, 1, "&What's This");
|
||||
|
||||
if (TrackPopupMenu(hMenu, TPM_RETURNCMD,
|
||||
pt.x, pt.y, 0, hDlg, NULL))
|
||||
{
|
||||
ShowHelpWindow(hDlg, id);
|
||||
}
|
||||
|
||||
DestroyMenu(hMenu);
|
||||
}
|
||||
|
||||
//
|
||||
// Show tool tip help
|
||||
//
|
||||
void ShowHelpWindow(
|
||||
HWND hDlg,
|
||||
UINT nCtl)
|
||||
{
|
||||
UINT msg;
|
||||
RECT rc;
|
||||
PSTR help;
|
||||
|
||||
switch (nCtl) {
|
||||
case IDC_IMAGEFILE_LABEL:
|
||||
case IDC_IMAGEFILE:
|
||||
msg = MSG_HELP_IMAGEFILE;
|
||||
break;
|
||||
case IDC_IMAGEDESC_LABEL:
|
||||
case IDC_IMAGEFILE_DESC:
|
||||
msg = MSG_HELP_IMAGEDESC;
|
||||
break;
|
||||
case IDC_TARGETFILE_LABEL:
|
||||
case IDC_TARGETFILE:
|
||||
msg = MSG_HELP_TARGETFILE;
|
||||
break;
|
||||
case IDC_DISKTYPE_LABEL:
|
||||
case IDC_DISKTYPE:
|
||||
case IDC_DISKTYPE_FILE:
|
||||
case IDC_DISKTYPE_RAM:
|
||||
msg = MSG_HELP_DISKTYPE;
|
||||
break;
|
||||
case IDC_MEDIATYPE_LABEL:
|
||||
case IDC_MEDIATYPE:
|
||||
msg = MSG_HELP_MEDIATYPE;
|
||||
break;
|
||||
case IDC_WRITE_PROTECTED:
|
||||
msg = MSG_HELP_PROTECT_NOW;
|
||||
break;
|
||||
case IDC_OPEN_PROTECTED:
|
||||
msg = MSG_HELP_PROTECT_OPEN;
|
||||
break;
|
||||
case IDC_BROWSE:
|
||||
msg = MSG_HELP_BROWSE;
|
||||
break;
|
||||
case IDC_OPEN:
|
||||
msg = MSG_HELP_OPEN;
|
||||
break;
|
||||
case IDC_SAVE:
|
||||
msg = MSG_HELP_SAVE;
|
||||
break;
|
||||
case IDC_CLOSE:
|
||||
msg = MSG_HELP_CLOSE;
|
||||
break;
|
||||
case IDC_FORMAT:
|
||||
msg = MSG_HELP_FORMAT;
|
||||
break;
|
||||
case IDC_CONTROL:
|
||||
msg = MSG_HELP_CONTROL;
|
||||
break;
|
||||
case IDC_OVERWRITE:
|
||||
msg = MSG_HELP_OVERWRITE;
|
||||
break;
|
||||
case IDC_TRUNCATE:
|
||||
msg = MSG_HELP_TRUNCATE;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
GetWindowRect(GetDlgItem(hDlg, nCtl), &rc);
|
||||
|
||||
help = ModuleMessage(msg);
|
||||
|
||||
if (help) {
|
||||
VfdToolTip(hDlg, help, rc.left, (rc.top + rc.bottom) / 2, TRUE);
|
||||
LocalFree(help);
|
||||
}
|
||||
}
|
||||
|
184
modules/rosapps/lib/vfdlib/vfdlib.c
Normal file
184
modules/rosapps/lib/vfdlib/vfdlib.c
Normal file
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
vfdlib.c
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
Miscellaneous functions
|
||||
|
||||
Copyright (C) 2003-2008 Ken Kato
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#pragma message(__FILE__": Compiled as C++ for testing purpose.")
|
||||
#endif // __cplusplus
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include <psapi.h>
|
||||
#endif // _DEBUG
|
||||
|
||||
#include "vfdtypes.h"
|
||||
#include "vfdapi.h"
|
||||
#include "vfdlib.h"
|
||||
|
||||
//
|
||||
// DLL Global variables
|
||||
//
|
||||
|
||||
#ifndef __REACTOS__
|
||||
extern HINSTANCE g_hDllModule = NULL; // Handle to this DLL itself
|
||||
extern UINT g_cDllRefCnt = 0; // Reference count of this DLL
|
||||
extern UINT g_nNotifyMsg = 0; // VFD notification message
|
||||
#else
|
||||
HINSTANCE g_hDllModule = NULL; // Handle to this DLL itself
|
||||
UINT g_cDllRefCnt = 0; // Reference count of this DLL
|
||||
UINT g_nNotifyMsg = 0; // VFD notification message
|
||||
#endif
|
||||
|
||||
//
|
||||
// DllMain
|
||||
//
|
||||
BOOL WINAPI DllMain(
|
||||
HINSTANCE hInstance,
|
||||
DWORD dwReason,
|
||||
LPVOID lpReserved)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
char name[MAX_PATH];
|
||||
HMODULE hMod;
|
||||
DWORD size;
|
||||
|
||||
if (EnumProcessModules(GetCurrentProcess(), &hMod, sizeof(hMod), &size)) {
|
||||
GetModuleBaseName(GetCurrentProcess(), hMod, name, sizeof(name));
|
||||
}
|
||||
else {
|
||||
strcpy(name, "unknown");
|
||||
}
|
||||
#endif // _DEBUG
|
||||
|
||||
UNREFERENCED_PARAMETER(lpReserved);
|
||||
|
||||
if (dwReason == DLL_PROCESS_ATTACH) {
|
||||
VFDTRACE(0, ("DLL_PROCESS_ATTACH - %s\n", name));
|
||||
|
||||
// this DLL doesn't need DLL_THREAD_ATTACH and DLL_THREAD_DETACH
|
||||
DisableThreadLibraryCalls(hInstance);
|
||||
|
||||
// store the DLL instance handle
|
||||
g_hDllModule = hInstance;
|
||||
|
||||
// register the VFD notification message
|
||||
g_nNotifyMsg = RegisterWindowMessage(VFD_NOTIFY_MESSAGE);
|
||||
|
||||
}
|
||||
else if (dwReason == DLL_PROCESS_DETACH) {
|
||||
VFDTRACE(0, ("DLL_PROCESS_DETACH - %s\n", name));
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// Check running platform
|
||||
//
|
||||
BOOL WINAPI VfdIsValidPlatform()
|
||||
{
|
||||
BOOL (WINAPI *pfnIsWow64Process)(HANDLE, PBOOL);
|
||||
BOOL wow64;
|
||||
|
||||
if (GetVersion() & 0x80000000) {
|
||||
return FALSE; // doesn't work on Win9x
|
||||
}
|
||||
|
||||
pfnIsWow64Process = (BOOL (WINAPI *)(HANDLE, PBOOL))
|
||||
GetProcAddress(GetModuleHandle("kernel32.dll"), "IsWow64Process");
|
||||
|
||||
if (pfnIsWow64Process == NULL) {
|
||||
return TRUE; // NT4 or 2000 -- assured to be 32 bit
|
||||
}
|
||||
|
||||
wow64 = FALSE;
|
||||
|
||||
if (!pfnIsWow64Process(GetCurrentProcess(), &wow64)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return !wow64;
|
||||
}
|
||||
|
||||
//
|
||||
// Get VFD notification message value
|
||||
//
|
||||
UINT WINAPI VfdGetNotifyMessage()
|
||||
{
|
||||
return g_nNotifyMsg;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Get message text from this DLL module
|
||||
//
|
||||
PSTR ModuleMessage(
|
||||
DWORD nFormat, ...)
|
||||
{
|
||||
PSTR p;
|
||||
va_list args;
|
||||
|
||||
va_start(args, nFormat);
|
||||
|
||||
if (!FormatMessage(
|
||||
FORMAT_MESSAGE_FROM_HMODULE |
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||
g_hDllModule, nFormat, 0, (LPTSTR)&p, 0, &args)) {
|
||||
p = NULL;
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
//
|
||||
// Get system error message string
|
||||
//
|
||||
PCSTR SystemMessage(
|
||||
DWORD nError)
|
||||
{
|
||||
static CHAR msg[256];
|
||||
|
||||
if (!FormatMessage(
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, nError, 0, msg, sizeof(msg), NULL)) {
|
||||
|
||||
_snprintf(msg, sizeof(msg),
|
||||
"Unknown system error %lu (0x%08x)\n", nError, nError);
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
//
|
||||
// Format and output debug string
|
||||
//
|
||||
void DebugTrace(
|
||||
PCSTR sFormat, ...)
|
||||
{
|
||||
CHAR buf[512];
|
||||
int len;
|
||||
va_list args;
|
||||
|
||||
len = _snprintf(buf, sizeof(buf),
|
||||
"%s(%lu) : ", TraceFile, TraceLine);
|
||||
|
||||
va_start(args, sFormat);
|
||||
|
||||
_vsnprintf(buf + len, sizeof(buf) - len, sFormat, args);
|
||||
|
||||
OutputDebugString(buf);
|
||||
}
|
||||
#endif // _DEBUG
|
185
modules/rosapps/lib/vfdlib/vfdlib.h
Normal file
185
modules/rosapps/lib/vfdlib/vfdlib.h
Normal file
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
vfdlib.h
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library local header
|
||||
|
||||
Copyright (C) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#ifndef _VFDLIB_H_
|
||||
#define _VFDLIB_H_
|
||||
|
||||
#define VFD_LIBRARY_FILENAME "vfd.dll"
|
||||
|
||||
#ifdef VFD_EMBED_DRIVER
|
||||
#define VFD_DRIVER_NAME_ID VFD_DRIVER
|
||||
#define VFD_DRIVER_TYPE_ID BINARY
|
||||
#endif
|
||||
|
||||
#ifndef RC_INVOKED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
//
|
||||
// DLL instance handle
|
||||
//
|
||||
extern HINSTANCE g_hDllModule;
|
||||
|
||||
//
|
||||
// Reference count for the DLL
|
||||
//
|
||||
extern UINT g_cDllRefCnt;
|
||||
|
||||
//
|
||||
// VFD notification message value
|
||||
//
|
||||
extern UINT g_nNotifyMsg;
|
||||
|
||||
//
|
||||
// VFD notification message register string
|
||||
//
|
||||
#define VFD_NOTIFY_MESSAGE "VfdNotifyMessage"
|
||||
|
||||
//
|
||||
// Message box title string
|
||||
//
|
||||
#define VFD_MSGBOX_TITLE "Virtual Floppy Drive"
|
||||
|
||||
//
|
||||
// shell extention string constants
|
||||
//
|
||||
#define VFDEXT_DESCRIPTION "VFD shell extension"
|
||||
#define VFDEXT_MENU_REGKEY "Drive\\shellex\\ContextMenuHandlers\\VFD"
|
||||
#define VFDEXT_DND_REGKEY "Drive\\shellex\\DragDropHandlers\\VFD"
|
||||
#define VFDEXT_PROP_REGKEY "Drive\\shellex\\PropertySheetHandlers\\VFD"
|
||||
#define VFDEXT_INFO_REGKEY "Drive\\shellex\\{00021500-0000-0000-C000-000000000046}"
|
||||
|
||||
//=====================================
|
||||
// Image handling functions
|
||||
//=====================================
|
||||
|
||||
// Format a buffer with FAT12
|
||||
|
||||
DWORD FormatBufferFat(
|
||||
PUCHAR pBuffer,
|
||||
ULONG nSectors);
|
||||
|
||||
// Extract image information from a zip compressed file
|
||||
|
||||
DWORD ExtractZipInfo(
|
||||
HANDLE hFile,
|
||||
ULONG *pSize);
|
||||
|
||||
// Extract original image from a zip compressed file
|
||||
|
||||
DWORD ExtractZipImage(
|
||||
HANDLE hFile,
|
||||
PUCHAR *pBuffer,
|
||||
PULONG pLength);
|
||||
|
||||
//=====================================
|
||||
// GUI utility functions
|
||||
//=====================================
|
||||
|
||||
typedef struct _SAVE_PARAM {
|
||||
HANDLE hDevice;
|
||||
VFD_DISKTYPE DiskType;
|
||||
VFD_MEDIA MediaType;
|
||||
VFD_FLAGS MediaFlags;
|
||||
VFD_FILETYPE FileType;
|
||||
ULONG ImageSize;
|
||||
PSTR ImageName;
|
||||
} SAVE_PARAM, PSAVE_PARAM;
|
||||
|
||||
typedef const SAVE_PARAM CSAVE_PARAM, *PCSAVE_PARAM;
|
||||
|
||||
DWORD GuiSaveParam(
|
||||
HWND hParent,
|
||||
PCSAVE_PARAM pParam);
|
||||
|
||||
void ShowContextMenu(
|
||||
HWND hDlg,
|
||||
HWND hCtl,
|
||||
LPARAM lParam);
|
||||
|
||||
void ShowHelpWindow(
|
||||
HWND hDlg,
|
||||
UINT nCtl);
|
||||
|
||||
//
|
||||
// Set a message to a control window
|
||||
//
|
||||
void SetControlText(
|
||||
HWND hWnd,
|
||||
UINT nCtrl,
|
||||
DWORD nMsg);
|
||||
|
||||
//==============================
|
||||
// Message extract functions
|
||||
//==============================
|
||||
|
||||
// Return a system error message
|
||||
|
||||
PCSTR SystemMessage(
|
||||
DWORD nError);
|
||||
|
||||
// Return a message from this DLL module
|
||||
|
||||
PSTR ModuleMessage(
|
||||
DWORD nFormat, ...);
|
||||
|
||||
//==============================
|
||||
// utility macros
|
||||
//==============================
|
||||
|
||||
#define IS_WINDOWS_NT() ((GetVersion() & 0xff) < 5)
|
||||
|
||||
//==============================
|
||||
// Debug functions
|
||||
//==============================
|
||||
|
||||
#ifdef _DEBUG
|
||||
extern ULONG TraceFlags;
|
||||
#ifndef __REACTOS__
|
||||
extern PCHAR TraceFile;
|
||||
#else
|
||||
extern CHAR const * TraceFile;
|
||||
#endif
|
||||
extern ULONG TraceLine;
|
||||
|
||||
#define VFDTRACE(LEVEL,STRING) \
|
||||
if ((TraceFlags & (LEVEL)) == (LEVEL)) { \
|
||||
TraceFile = __FILE__; \
|
||||
TraceLine = __LINE__; \
|
||||
DebugTrace STRING; \
|
||||
}
|
||||
|
||||
void DebugTrace(PCSTR sFormat, ...);
|
||||
|
||||
#else // _DEBUG
|
||||
#define VFDTRACE(LEVEL,STRING)
|
||||
#endif // _DEBUG
|
||||
|
||||
//
|
||||
// supplement old system headers
|
||||
//
|
||||
#ifndef INVALID_FILE_ATTRIBUTES
|
||||
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
|
||||
#endif // INVALID_FILE_ATTRIBUTES
|
||||
|
||||
#if defined(_INC_COMMDLG) && !defined(OPENFILENAME_SIZE_VERSION_400)
|
||||
// Pre Win2K system header is used
|
||||
// OPENFILENAME is defined without extra fields.
|
||||
#define OPENFILENAME_SIZE_VERSION_400 sizeof(OPENFILENAME)
|
||||
#endif // __INC_COMMDLG && !OPENFILENAME_SIZE_VERSION_400
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // RC_INVOKED
|
||||
|
||||
#endif // _VFDLIB_H_
|
219
modules/rosapps/lib/vfdlib/vfdlib.rc
Normal file
219
modules/rosapps/lib/vfdlib/vfdlib.rc
Normal file
|
@ -0,0 +1,219 @@
|
|||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "vfdguirc.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "winres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// ưÄ×Ù resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
|
||||
#pragma code_page(932)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"vfdguirc.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""winres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog
|
||||
//
|
||||
|
||||
IDD_OPENDIALOG DIALOGEX 0, 0, 250, 150
|
||||
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
EXSTYLE WS_EX_CONTEXTHELP
|
||||
CAPTION "Open Virtual Floppy Image"
|
||||
FONT 9, "MS Shell Dlg"
|
||||
BEGIN
|
||||
LTEXT "&Image File:",IDC_IMAGEFILE_LABEL,7,7,52,12,
|
||||
SS_CENTERIMAGE
|
||||
EDITTEXT IDC_IMAGEFILE,60,7,130,12,ES_AUTOHSCROLL
|
||||
PUSHBUTTON "&Browse...",IDC_BROWSE,193,7,50,14
|
||||
LTEXT "Description:",IDC_IMAGEDESC_LABEL,7,27,52,8
|
||||
EDITTEXT IDC_IMAGEFILE_DESC,60,27,183,12,ES_AUTOHSCROLL |
|
||||
ES_READONLY | NOT WS_BORDER | NOT WS_TABSTOP
|
||||
LTEXT "additional information",IDC_IMAGEFILE_HINT,60,43,183,8
|
||||
LTEXT "Disk Type:",IDC_DISKTYPE_LABEL,7,59,52,10
|
||||
CONTROL "&FILE",IDC_DISKTYPE_FILE,"Button",BS_AUTORADIOBUTTON |
|
||||
WS_GROUP | WS_TABSTOP,60,59,38,10
|
||||
CONTROL "&RAM",IDC_DISKTYPE_RAM,"Button",BS_AUTORADIOBUTTON,99,
|
||||
59,38,10
|
||||
LTEXT "&Media Type:",IDC_MEDIATYPE_LABEL,7,75,52,12,
|
||||
SS_CENTERIMAGE
|
||||
COMBOBOX IDC_MEDIATYPE,59,75,80,84,CBS_DROPDOWNLIST | WS_VSCROLL |
|
||||
WS_TABSTOP
|
||||
DEFPUSHBUTTON "&Open",IDOK,72,129,50,14,WS_GROUP
|
||||
PUSHBUTTON "Cancel",IDCANCEL,127,129,50,14
|
||||
CONTROL "&Write Protect",IDC_OPEN_PROTECTED,"Button",
|
||||
BS_AUTOCHECKBOX | WS_TABSTOP,59,95,184,10
|
||||
END
|
||||
|
||||
IDD_PROPDIALOG DIALOGEX 0, 0, 226, 215
|
||||
STYLE WS_CHILD | WS_VISIBLE
|
||||
EXSTYLE WS_EX_CONTEXTHELP
|
||||
FONT 9, "MS Shell Dlg", 0, 0, 0x1
|
||||
BEGIN
|
||||
ICON IDI_VFD_ICON,IDC_STATIC,7,7,20,20
|
||||
CTEXT "Virtual Floppy Drive for Windows",IDC_PROPERTY_TITLE,29,
|
||||
10,168,8,SS_CENTERIMAGE
|
||||
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,7,32,212,1
|
||||
LTEXT "Image File:",IDC_IMAGEFILE_LABEL,7,40,50,8
|
||||
EDITTEXT IDC_IMAGEFILE,58,40,161,12,ES_AUTOHSCROLL | ES_READONLY |
|
||||
NOT WS_BORDER | NOT WS_TABSTOP
|
||||
LTEXT "Description:",IDC_IMAGEDESC_LABEL,7,58,50,8
|
||||
EDITTEXT IDC_IMAGEFILE_DESC,58,58,161,12,ES_AUTOHSCROLL |
|
||||
ES_READONLY | NOT WS_BORDER | NOT WS_TABSTOP
|
||||
LTEXT "Disk Type:",IDC_DISKTYPE_LABEL,7,76,50,8
|
||||
EDITTEXT IDC_DISKTYPE,58,76,161,12,ES_AUTOHSCROLL | ES_READONLY |
|
||||
NOT WS_BORDER | NOT WS_TABSTOP
|
||||
LTEXT "Media Type:",IDC_MEDIATYPE_LABEL,7,94,50,8
|
||||
EDITTEXT IDC_MEDIATYPE,58,94,161,12,ES_AUTOHSCROLL | ES_READONLY |
|
||||
NOT WS_BORDER | NOT WS_TABSTOP
|
||||
CONTROL "&Write Protect",IDC_WRITE_PROTECTED,"Button",
|
||||
BS_AUTOCHECKBOX | WS_TABSTOP,58,112,161,8
|
||||
PUSHBUTTON "&Open",IDC_OPEN,7,127,50,14
|
||||
PUSHBUTTON "&Save",IDC_SAVE,61,127,50,14
|
||||
PUSHBUTTON "&Close",IDC_CLOSE,115,127,50,14
|
||||
PUSHBUTTON "&Format",IDC_FORMAT,169,127,50,14
|
||||
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,7,148,212,1
|
||||
PUSHBUTTON "&VFD Control Panel",IDC_CONTROL,139,192,80,14
|
||||
CTEXT "Copyright (c) 2003-2008 Ken Kato",IDC_COPYRIGHT_STR,29,
|
||||
20,168,8,SS_CENTERIMAGE
|
||||
END
|
||||
|
||||
IDD_SAVEDIALOG DIALOGEX 0, 0, 250, 150
|
||||
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
EXSTYLE WS_EX_CONTEXTHELP
|
||||
CAPTION "Save Virtual Floppy Image"
|
||||
FONT 9, "MS Shell Dlg", 0, 0, 0x1
|
||||
BEGIN
|
||||
LTEXT "Image File:",IDC_IMAGEFILE_LABEL,7,7,52,12
|
||||
EDITTEXT IDC_IMAGEFILE,60,7,183,12,ES_AUTOHSCROLL | ES_READONLY |
|
||||
NOT WS_BORDER | NOT WS_TABSTOP
|
||||
LTEXT "Disk Type:",IDC_DISKTYPE_LABEL,7,25,52,8,SS_NOPREFIX
|
||||
EDITTEXT IDC_DISKTYPE,60,25,58,12,ES_AUTOHSCROLL | ES_READONLY |
|
||||
NOT WS_BORDER | NOT WS_TABSTOP
|
||||
LTEXT "Media Type:",IDC_MEDIATYPE_LABEL,120,25,52,8,
|
||||
SS_NOPREFIX
|
||||
EDITTEXT IDC_MEDIATYPE,173,25,70,12,ES_AUTOHSCROLL | ES_READONLY |
|
||||
NOT WS_BORDER | NOT WS_TABSTOP
|
||||
LTEXT "Target &File:",IDC_TARGETFILE_LABEL,7,43,52,12,
|
||||
SS_CENTERIMAGE
|
||||
EDITTEXT IDC_TARGETFILE,60,43,131,12,ES_AUTOHSCROLL
|
||||
PUSHBUTTON "&Browse...",IDC_BROWSE,193,43,50,14
|
||||
LTEXT "Description:",IDC_IMAGEDESC_LABEL,7,64,52,8,SS_NOPREFIX
|
||||
EDITTEXT IDC_IMAGEFILE_DESC,60,64,183,12,ES_AUTOHSCROLL |
|
||||
ES_READONLY | NOT WS_BORDER | NOT WS_TABSTOP
|
||||
CONTROL "&Overwrite an existing file",IDC_OVERWRITE,"Button",
|
||||
BS_AUTOCHECKBOX | WS_TABSTOP,60,95,183,10
|
||||
CONTROL "&Truncate an existing file",IDC_TRUNCATE,"Button",
|
||||
BS_AUTOCHECKBOX | WS_TABSTOP,60,111,183,10
|
||||
DEFPUSHBUTTON "&Save",IDOK,72,129,50,14,WS_DISABLED
|
||||
PUSHBUTTON "Cancel",IDCANCEL,127,129,50,14
|
||||
LTEXT "additional information",IDC_IMAGEFILE_HINT,60,80,183,8,
|
||||
SS_NOPREFIX
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DESIGNINFO
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
GUIDELINES DESIGNINFO DISCARDABLE
|
||||
BEGIN
|
||||
IDD_OPENDIALOG, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 243
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 143
|
||||
END
|
||||
|
||||
IDD_PROPDIALOG, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 219
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 206
|
||||
END
|
||||
|
||||
IDD_SAVEDIALOG, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 243
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 143
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
//
|
||||
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
#ifndef __REACTOS__
|
||||
IDI_VFD_ICON ICON DISCARDABLE "res\\vfd.ico"
|
||||
IDI_IMAGE_ICON ICON DISCARDABLE "res\\image.ico"
|
||||
IDI_CONFIG_ICON ICON DISCARDABLE "res\\config.ico"
|
||||
#else
|
||||
IDI_VFD_ICON ICON DISCARDABLE "res/vfd.ico"
|
||||
IDI_IMAGE_ICON ICON DISCARDABLE "res/image.ico"
|
||||
IDI_CONFIG_ICON ICON DISCARDABLE "res/config.ico"
|
||||
#endif
|
||||
#endif // ưÄ×Ù resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
#ifdef __REACTOS__
|
||||
#include <vfdmsg_lib.rc>
|
||||
#endif
|
83
modules/rosapps/lib/vfdlib/vfdlib.rs
Normal file
83
modules/rosapps/lib/vfdlib/vfdlib.rs
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
vfdlib.rc
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
Resource Script
|
||||
|
||||
The non-standard extension ".rs" is intentional, so that
|
||||
Microsoft Visual Studio won't try to open this file with
|
||||
the resource editor
|
||||
|
||||
Copyright (c) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
|
||||
//
|
||||
// version resource constants
|
||||
//
|
||||
#include <winver.h>
|
||||
|
||||
//
|
||||
// VFD common version constants
|
||||
//
|
||||
#include "vfdver.h"
|
||||
|
||||
//
|
||||
// Library specific version constants
|
||||
//
|
||||
#include "vfdlib.h"
|
||||
|
||||
#define VFD_FILEOS VOS_NT_WINDOWS32
|
||||
#define VFD_FILETYPE VFT_DLL
|
||||
#define VFD_FILESUBTYPE VFT2_UNKNOWN
|
||||
|
||||
#define VFD_DESCRIPTION "Virtual Floppy Drive Library"
|
||||
#define VFD_INTERNALNAME VFD_LIBRARY_FILENAME
|
||||
#define VFD_FILE_MAJOR 2
|
||||
#define VFD_FILE_MINOR 1
|
||||
|
||||
//
|
||||
// embedded VFD driver binary
|
||||
//
|
||||
#ifdef VFD_EMBED_DRIVER
|
||||
|
||||
#define VFD_SPECIAL_FLAG VS_FF_SPECIALBUILD
|
||||
#define VFD_SPECIAL_DESC "Driver binary embedded version"
|
||||
#define VFD_SPECIAL_DESC_ALT "ドライババイナリ埋め込み版"
|
||||
|
||||
#ifdef _DEBUG
|
||||
VFD_DRIVER_NAME_ID VFD_DRIVER_TYPE_ID "..\..\sys\objchk\i386\vfd.sys"
|
||||
#else // _DEBUG
|
||||
VFD_DRIVER_NAME_ID VFD_DRIVER_TYPE_ID "..\..\sys\objfre\i386\vfd.sys"
|
||||
#endif // _DEBUG
|
||||
|
||||
#endif // VFD_EMBED_DRIVER
|
||||
|
||||
//
|
||||
// Japanese version resource constants
|
||||
//
|
||||
#define VFD_VERSIONINFO_ALT "041104B0"
|
||||
#undef VFD_VERSIONINFO_TRANS
|
||||
#define VFD_VERSIONINFO_TRANS 0x0409, 0x04B0, 0x0411, 0x04B0
|
||||
|
||||
#define VFD_DESCRIPTION_ALT "Virtual Floppy Drive ライブラリ"
|
||||
#define VFD_PRODUCT_NAME_ALT VFD_PRODUCT_NAME
|
||||
|
||||
//
|
||||
// VFD common version resource
|
||||
//
|
||||
#include "vfdver.rc"
|
||||
|
||||
//
|
||||
// GUI resource
|
||||
//
|
||||
#include "vfdlib.rc"
|
||||
|
||||
//
|
||||
// Module message resource
|
||||
//
|
||||
#include "vfdmsg.rc"
|
||||
|
||||
#endif // !APSTUDIO_INVOKED
|
55
modules/rosapps/lib/vfdlib/vfdlib.spec
Normal file
55
modules/rosapps/lib/vfdlib/vfdlib.spec
Normal file
|
@ -0,0 +1,55 @@
|
|||
@ stdcall -private DllCanUnloadNow()
|
||||
@ stdcall -private DllGetClassObject(ptr ptr ptr)
|
||||
|
||||
@ stdcall VfdRegisterHandlers()
|
||||
@ stdcall VfdUnregisterHandlers()
|
||||
@ stdcall VfdCheckHandlers()
|
||||
|
||||
@ stdcall VfdInstallDriver(str long)
|
||||
@ stdcall VfdConfigDriver(long)
|
||||
@ stdcall VfdRemoveDriver()
|
||||
@ stdcall VfdStartDriver(ptr)
|
||||
@ stdcall VfdStopDriver(ptr)
|
||||
@ stdcall VfdGetDriverConfig(str ptr)
|
||||
@ stdcall VfdGetDriverState(ptr)
|
||||
|
||||
@ stdcall VfdOpenDevice(long)
|
||||
@ stdcall VfdGetDeviceNumber(ptr ptr)
|
||||
@ stdcall VfdGetDeviceName(ptr str long)
|
||||
@ stdcall VfdGetDriverVersion(ptr ptr)
|
||||
|
||||
@ stdcall VfdOpenImage(ptr str long long long)
|
||||
@ stdcall VfdCloseImage(ptr long)
|
||||
@ stdcall VfdGetImageInfo(ptr str ptr ptr ptr ptr ptr)
|
||||
@ stdcall VfdSaveImage(ptr str long long)
|
||||
@ stdcall VfdFormatMedia(ptr)
|
||||
@ stdcall VfdGetMediaState(ptr)
|
||||
@ stdcall VfdWriteProtect(ptr long)
|
||||
@ stdcall VfdDismountVolume(ptr long)
|
||||
|
||||
@ stdcall VfdSetGlobalLink(ptr long)
|
||||
@ stdcall VfdGetGlobalLink(ptr str)
|
||||
@ stdcall VfdSetLocalLink(ptr long)
|
||||
@ stdcall VfdGetLocalLink(ptr str)
|
||||
|
||||
@ stdcall VfdGetNotifyMessage()
|
||||
|
||||
@ stdcall VfdChooseLetter()
|
||||
@ stdcall VfdCheckDriverFile(str ptr)
|
||||
@ stdcall VfdCheckImageFile(str ptr ptr ptr)
|
||||
@ stdcall VfdCreateImageFile(str long long long)
|
||||
|
||||
@ stdcall VfdLookupMedia(long)
|
||||
@ stdcall VfdGetMediaSize(long)
|
||||
@ stdcall VfdMediaTypeName(long)
|
||||
|
||||
@ stdcall VfdMakeFileDesc(str long long long long)
|
||||
|
||||
@ stdcall VfdGuiOpen(ptr long)
|
||||
@ stdcall VfdGuiSave(ptr long)
|
||||
@ stdcall VfdGuiClose(ptr long)
|
||||
@ stdcall VfdGuiFormat(ptr long)
|
||||
@ stdcall VfdToolTip(ptr str long long long)
|
||||
@ stdcall VfdImageTip(ptr long)
|
||||
|
||||
@ stdcall VfdIsValidPlatform()
|
523
modules/rosapps/lib/vfdlib/vfdmsg_lib.mc
Normal file
523
modules/rosapps/lib/vfdlib/vfdmsg_lib.mc
Normal file
|
@ -0,0 +1,523 @@
|
|||
;/*
|
||||
; vfdmsg.h
|
||||
;
|
||||
; Virtual Floppy Drive for Windows
|
||||
; Driver control library
|
||||
; Message definition
|
||||
;
|
||||
; Copyright (c) 2003-2005 Ken Kato
|
||||
;*/
|
||||
;
|
||||
;#ifndef _VFDMSG_H_
|
||||
;#define _VFDMSG_H_
|
||||
;
|
||||
|
||||
MessageIdTypedef=DWORD
|
||||
LanguageNames=(English=0x409:msg0409)
|
||||
|
||||
;
|
||||
;//
|
||||
;// Context menu text
|
||||
;//
|
||||
;
|
||||
MessageId=
|
||||
SymbolicName=MSG_MENU_OPEN
|
||||
Language=English
|
||||
&Open VFD image...%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_OPEN
|
||||
Language=English
|
||||
Open a virtual floppy image.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_MENU_CLOSE
|
||||
Language=English
|
||||
&Close VFD image%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_CLOSE
|
||||
Language=English
|
||||
Close the current virtual floppy image.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_MENU_SAVE
|
||||
Language=English
|
||||
&Save VFD image...%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_SAVE
|
||||
Language=English
|
||||
Save the current image into a file.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_MENU_PROTECT
|
||||
Language=English
|
||||
&Write Protect%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_PROTECT
|
||||
Language=English
|
||||
Enable/disable the media write protection.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_MENU_PROP
|
||||
Language=English
|
||||
VFD &Property%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_PROP
|
||||
Language=English
|
||||
Display the VFD property page.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_MENU_DROP
|
||||
Language=English
|
||||
&Open with VFD%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_DROP
|
||||
Language=English
|
||||
Open the file with VFD.%0
|
||||
.
|
||||
|
||||
|
||||
;
|
||||
;//
|
||||
;// Dialog title text
|
||||
;//
|
||||
;
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_OPEN_TITLE
|
||||
Language=English
|
||||
Open Virtual Floppy Image%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_SAVE_TITLE
|
||||
Language=English
|
||||
Save Virtual Floppy Image%0
|
||||
.
|
||||
|
||||
|
||||
;
|
||||
;//
|
||||
;// Dialog label text
|
||||
;//
|
||||
;
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_IMAGEFILE_LABEL
|
||||
Language=English
|
||||
Image File:%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_IMAGEFILE_ACCEL
|
||||
Language=English
|
||||
&Image File:%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_DESCRIPTION_LABEL
|
||||
Language=English
|
||||
Description:%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_DISKTYPE_LABEL
|
||||
Language=English
|
||||
Disk Type:%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_MEDIATYPE_LABEL
|
||||
Language=English
|
||||
Media Type:%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_MEDIATYPE_ACCEL
|
||||
Language=English
|
||||
&Media Type:%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_TARGETFILE_LABEL
|
||||
Language=English
|
||||
&Target File:%0
|
||||
.
|
||||
|
||||
|
||||
;
|
||||
;//
|
||||
;// button text
|
||||
;//
|
||||
;
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_OPEN_BUTTON
|
||||
Language=English
|
||||
&Open%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_CREATE_BUTTON
|
||||
Language=English
|
||||
&Create%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_SAVE_BUTTON
|
||||
Language=English
|
||||
&Save%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_CLOSE_BUTTON
|
||||
Language=English
|
||||
&Close%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_FORMAT_BUTTON
|
||||
Language=English
|
||||
&Format%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_CONTROL_BUTTON
|
||||
Language=English
|
||||
&VFD Control Panel%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_BROWSE_BUTTON
|
||||
Language=English
|
||||
&Browse...%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_CANCEL_BUTTON
|
||||
Language=English
|
||||
Cancel%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_OVERWRITE_CHECK
|
||||
Language=English
|
||||
Overwrite an existing file.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_TRUNCATE_CHECK
|
||||
Language=English
|
||||
Truncate an existing file.%0
|
||||
.
|
||||
|
||||
|
||||
;
|
||||
;//
|
||||
;// file description text
|
||||
;//
|
||||
;
|
||||
MessageId=
|
||||
SymbolicName=MSG_FILETYPE_RAW
|
||||
Language=English
|
||||
RAW image%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_FILETYPE_ZIP
|
||||
Language=English
|
||||
ZIP image%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_DESC_NEW_FILE
|
||||
Language=English
|
||||
New file%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_DESC_FILESIZE
|
||||
Language=English
|
||||
%1!s! bytes (%2!s!)%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_ATTR_READONLY
|
||||
Language=English
|
||||
ReadOnly%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_ATTR_COMPRESSED
|
||||
Language=English
|
||||
Compressed%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_ATTR_ENCRYPTED
|
||||
Language=English
|
||||
Encrypted%0
|
||||
.
|
||||
|
||||
|
||||
;
|
||||
;//
|
||||
;// ToolTip
|
||||
;//
|
||||
;
|
||||
MessageId=
|
||||
SymbolicName=MSG_WRITE_PROTECTED
|
||||
Language=English
|
||||
&Write Protected%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_WRITE_ALLOWED
|
||||
Language=English
|
||||
Write Allowed%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_IMAGE_INFOTIP
|
||||
Language=English
|
||||
%1!s!
|
||||
%2!s!
|
||||
Type: %3!s! disk
|
||||
Media: %4!s!
|
||||
%5!s!%0
|
||||
.
|
||||
|
||||
|
||||
;
|
||||
;//
|
||||
;// Context help text
|
||||
;//
|
||||
;
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_IMAGEFILE
|
||||
Language=English
|
||||
Image file name.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_IMAGEDESC
|
||||
Language=English
|
||||
Information about the image file.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_TARGETFILE
|
||||
Language=English
|
||||
Save target file name.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_DISKTYPE
|
||||
Language=English
|
||||
Virtual disk type.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_MEDIATYPE
|
||||
Language=English
|
||||
Virtual floppy media type.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_FORMAT
|
||||
Language=English
|
||||
Click to format the
|
||||
current image with FAT.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_CONTROL
|
||||
Language=English
|
||||
Start the VFD Control Panel.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_PROTECT_NOW
|
||||
Language=English
|
||||
Enable/disable the media write protection.
|
||||
The change takes effect immediately.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_PROTECT_OPEN
|
||||
Language=English
|
||||
Open the image as a
|
||||
write protected media.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_BROWSE
|
||||
Language=English
|
||||
Browse for folders to
|
||||
find the target file.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_OVERWRITE
|
||||
Language=English
|
||||
Overwrite the existing file
|
||||
to save the current image.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_HELP_TRUNCATE
|
||||
Language=English
|
||||
Truncate the target file after
|
||||
saving the current image.%0
|
||||
.
|
||||
|
||||
|
||||
;
|
||||
;//
|
||||
;// Hint text
|
||||
;//
|
||||
;
|
||||
MessageId=
|
||||
SymbolicName=MSG_CURRENT_FILE
|
||||
Language=English
|
||||
Current image file.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_FILE_TOO_SMALL
|
||||
Language=English
|
||||
The file is too small for the selected media type.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_SIZE_MISMATCH
|
||||
Language=English
|
||||
The file size does not match the selected media size.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_FILE_ACCESS_ERROR
|
||||
Language=English
|
||||
Cannot access the file.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_TARGET_IS_ZIP
|
||||
Language=English
|
||||
Cannot overwrite a ZIP compressed file.%0
|
||||
.
|
||||
|
||||
|
||||
;
|
||||
;//
|
||||
;// Other text
|
||||
;//
|
||||
;
|
||||
MessageId=
|
||||
SymbolicName=MSG_OPEN_FILTER
|
||||
Language=English
|
||||
Common image files (bin,dat,fdd,flp,ima,img,vfd)|*.bin;*.dat;*.fdd;*.flp;*.ima;*.img;*.vfd|ZIP Compressed Image (imz,zip)|*.imz;*.zip|All files (*.*)|*.*|%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_FORMAT_WARNING
|
||||
Language=English
|
||||
Warning: Formatting will erase all data on this disk.
|
||||
Click [OK] to format the disk, [Cancel] to quit.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_MEDIA_MODIFIED
|
||||
Language=English
|
||||
Data on the RAM disk is modified.
|
||||
Save to a file before closing ?%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_UNMOUNT_CONFIRM
|
||||
Language=English
|
||||
Failed to lock the volume.
|
||||
Make sure that any files are not in use.
|
||||
Continuing forces all files to be closed.%0
|
||||
.
|
||||
|
||||
|
||||
MessageId=
|
||||
SymbolicName=MSG_UNMOUNT_FAILED
|
||||
Language=English
|
||||
Failed to unmount the volume.
|
||||
Make sure that any files are not in use.%0
|
||||
.
|
||||
|
||||
;
|
||||
;#endif // _VFDMSG_H_
|
126
modules/rosapps/lib/vfdlib/vfdshcfact.cpp
Normal file
126
modules/rosapps/lib/vfdlib/vfdshcfact.cpp
Normal file
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
vfdshcfact.cpp
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
shell extension COM class factory class
|
||||
|
||||
Copyright (c) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
|
||||
#include "vfdtypes.h"
|
||||
#include "vfdlib.h"
|
||||
#include "vfdshext.h"
|
||||
|
||||
// class header
|
||||
#include "vfdshcfact.h"
|
||||
|
||||
//
|
||||
// constructor
|
||||
//
|
||||
CVfdFactory::CVfdFactory()
|
||||
{
|
||||
VFDTRACE(0, ("CVfdFactory::CVfdFactory()\n"));
|
||||
|
||||
m_cRefCnt = 0L;
|
||||
|
||||
g_cDllRefCnt++;
|
||||
}
|
||||
|
||||
//
|
||||
// destructor
|
||||
//
|
||||
CVfdFactory::~CVfdFactory()
|
||||
{
|
||||
VFDTRACE(0, ("CVfdFactory::~CVfdFactory()\n"));
|
||||
|
||||
g_cDllRefCnt--;
|
||||
}
|
||||
|
||||
//
|
||||
// IUnknown methods
|
||||
//
|
||||
STDMETHODIMP CVfdFactory::QueryInterface(
|
||||
REFIID riid,
|
||||
LPVOID *ppv)
|
||||
{
|
||||
VFDTRACE(0, ("CVfdFactory::QueryInterface()\n"));
|
||||
|
||||
*ppv = NULL;
|
||||
|
||||
if (IsEqualIID(riid, IID_IUnknown) ||
|
||||
IsEqualIID(riid, IID_IClassFactory)) {
|
||||
*ppv = (LPCLASSFACTORY)this;
|
||||
|
||||
AddRef();
|
||||
|
||||
return NOERROR;
|
||||
}
|
||||
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
STDMETHODIMP_(ULONG) CVfdFactory::AddRef()
|
||||
{
|
||||
VFDTRACE(0, ("CVfdFactory::AddRef()\n"));
|
||||
|
||||
return ++m_cRefCnt;
|
||||
}
|
||||
|
||||
STDMETHODIMP_(ULONG) CVfdFactory::Release()
|
||||
{
|
||||
VFDTRACE(0, ("CVfdFactory::Release()\n"));
|
||||
|
||||
if (--m_cRefCnt) {
|
||||
return m_cRefCnt;
|
||||
}
|
||||
|
||||
#ifndef __REACTOS__
|
||||
delete this;
|
||||
#endif
|
||||
|
||||
return 0L;
|
||||
}
|
||||
|
||||
//
|
||||
// IClassFactory methods
|
||||
//
|
||||
STDMETHODIMP CVfdFactory::CreateInstance(
|
||||
LPUNKNOWN pUnkOuter,
|
||||
REFIID riid,
|
||||
LPVOID *ppvObj)
|
||||
{
|
||||
VFDTRACE(0, ("CVfdFactory::CreateInstance()\n"));
|
||||
|
||||
*ppvObj = NULL;
|
||||
|
||||
// Shell extensions typically don't support
|
||||
// aggregation (inheritance)
|
||||
|
||||
if (pUnkOuter) {
|
||||
return CLASS_E_NOAGGREGATION;
|
||||
}
|
||||
|
||||
// Create the main shell extension object.
|
||||
// The shell will then call QueryInterface with IID_IShellExtInit
|
||||
// -- this is how shell extensions are initialized.
|
||||
|
||||
LPCVFDSHEXT pVfdShExt = new CVfdShExt;
|
||||
|
||||
if (!pVfdShExt) {
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
return pVfdShExt->QueryInterface(riid, ppvObj);
|
||||
}
|
||||
|
||||
STDMETHODIMP CVfdFactory::LockServer(BOOL fLock)
|
||||
{
|
||||
VFDTRACE(0, ("CVfdFactory::LockServer()\n"));
|
||||
UNREFERENCED_PARAMETER(fLock);
|
||||
return NOERROR;
|
||||
}
|
42
modules/rosapps/lib/vfdlib/vfdshcfact.h
Normal file
42
modules/rosapps/lib/vfdlib/vfdshcfact.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
vfdshcfact.h
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
shell extension COM class-factory class header
|
||||
|
||||
Copyright (c) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#ifndef _VFDSHCFACT_H_
|
||||
#define _VFDSHCFACT_H_
|
||||
|
||||
//
|
||||
// CVfdFactory
|
||||
// class factory class to create the COM shell extension object
|
||||
//
|
||||
class CVfdFactory : public IClassFactory
|
||||
{
|
||||
protected:
|
||||
ULONG m_cRefCnt; // Reference count to the object
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
CVfdFactory();
|
||||
|
||||
// Destructor
|
||||
~CVfdFactory();
|
||||
|
||||
// IUnknown inheritance
|
||||
STDMETHODIMP QueryInterface(REFIID, LPVOID *);
|
||||
STDMETHODIMP_(ULONG) AddRef();
|
||||
STDMETHODIMP_(ULONG) Release();
|
||||
|
||||
// IClassFactory inheritance
|
||||
STDMETHODIMP CreateInstance(LPUNKNOWN, REFIID, LPVOID *);
|
||||
STDMETHODIMP LockServer(BOOL);
|
||||
};
|
||||
|
||||
typedef CVfdFactory *LPCVFDFACTORY;
|
||||
|
||||
#endif // _VFDSHCFACT_H_
|
235
modules/rosapps/lib/vfdlib/vfdshext.cpp
Normal file
235
modules/rosapps/lib/vfdlib/vfdshext.cpp
Normal file
|
@ -0,0 +1,235 @@
|
|||
/*
|
||||
vfdshext.cpp
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
shell extension COM shell extension class
|
||||
|
||||
Copyright (c) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
#include <shlobj.h>
|
||||
|
||||
#include "vfdtypes.h"
|
||||
#include "vfdapi.h"
|
||||
#include "vfdlib.h"
|
||||
|
||||
// class header
|
||||
#include "vfdshext.h"
|
||||
|
||||
//
|
||||
// Constructor
|
||||
//
|
||||
CVfdShExt::CVfdShExt()
|
||||
{
|
||||
VFDTRACE(0, ("CVfdShExt::CVfdShExt()\n"));
|
||||
|
||||
m_cRefCnt = 0L;
|
||||
m_pDataObj = NULL;
|
||||
m_nDevice = (ULONG)-1;
|
||||
m_sTarget[0] = '\0';
|
||||
m_bDragDrop = FALSE;
|
||||
|
||||
g_cDllRefCnt++;
|
||||
}
|
||||
|
||||
//
|
||||
// Destructor
|
||||
//
|
||||
CVfdShExt::~CVfdShExt()
|
||||
{
|
||||
VFDTRACE(0, ("CVfdShExt::~CVfdShExt()\n"));
|
||||
|
||||
if (m_pDataObj) {
|
||||
m_pDataObj->Release();
|
||||
}
|
||||
|
||||
g_cDllRefCnt--;
|
||||
}
|
||||
|
||||
// IUnknown members
|
||||
|
||||
STDMETHODIMP CVfdShExt::QueryInterface(
|
||||
REFIID riid,
|
||||
LPVOID *ppv)
|
||||
{
|
||||
*ppv = NULL;
|
||||
|
||||
if (IsEqualIID(riid, IID_IShellExtInit) ||
|
||||
IsEqualIID(riid, IID_IUnknown)) {
|
||||
VFDTRACE(0,
|
||||
("CVfdShExt::QueryInterface()==>IID_IShellExtInit\n"));
|
||||
|
||||
*ppv = (LPSHELLEXTINIT)this;
|
||||
}
|
||||
else if (IsEqualIID(riid, IID_IContextMenu)) {
|
||||
VFDTRACE(0,
|
||||
("CVfdShExt::QueryInterface()==>IID_IContextMenu\n"));
|
||||
|
||||
*ppv = (LPCONTEXTMENU)this;
|
||||
}
|
||||
else if (IsEqualIID(riid, IID_IShellPropSheetExt)) {
|
||||
VFDTRACE(0,
|
||||
("CVfdShExt::QueryInterface()==>IID_IShellPropSheetExt\n"));
|
||||
|
||||
*ppv = (LPSHELLPROPSHEETEXT)this;
|
||||
}
|
||||
|
||||
if (*ppv) {
|
||||
AddRef();
|
||||
|
||||
return NOERROR;
|
||||
}
|
||||
|
||||
VFDTRACE(0,
|
||||
("CVfdShExt::QueryInterface()==>Unknown Interface!\n"));
|
||||
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
STDMETHODIMP_(ULONG) CVfdShExt::AddRef()
|
||||
{
|
||||
VFDTRACE(0, ("CVfdShExt::AddRef()\n"));
|
||||
|
||||
return ++m_cRefCnt;
|
||||
}
|
||||
|
||||
STDMETHODIMP_(ULONG) CVfdShExt::Release()
|
||||
{
|
||||
VFDTRACE(0, ("CVfdShExt::Release()\n"));
|
||||
|
||||
if (--m_cRefCnt) {
|
||||
return m_cRefCnt;
|
||||
}
|
||||
|
||||
#ifndef __REACTOS__
|
||||
delete this;
|
||||
#endif
|
||||
|
||||
return 0L;
|
||||
}
|
||||
|
||||
// IShellExtInit members
|
||||
|
||||
//
|
||||
// Initialize
|
||||
// Called by the shell to initialize the shell extension object
|
||||
//
|
||||
STDMETHODIMP CVfdShExt::Initialize(
|
||||
LPCITEMIDLIST pIDFolder,
|
||||
LPDATAOBJECT pDataObj,
|
||||
HKEY hRegKey)
|
||||
{
|
||||
CHAR drive = '\0';
|
||||
|
||||
VFDTRACE(0, ("CVfdShExt::Initialize()\n"));
|
||||
|
||||
UNREFERENCED_PARAMETER(hRegKey);
|
||||
|
||||
// Initialize can be called more than once
|
||||
|
||||
if (m_pDataObj) {
|
||||
m_pDataObj->Release();
|
||||
m_pDataObj = NULL;
|
||||
}
|
||||
|
||||
m_nDevice = (ULONG)-1;
|
||||
m_sTarget[0] = '\0';
|
||||
|
||||
// Get the folder name
|
||||
if (SHGetPathFromIDList(pIDFolder, m_sTarget)) {
|
||||
|
||||
// act as a Drag-and-Drop Handler
|
||||
|
||||
VFDTRACE(0, ("Drag-Drop: %s\n", m_sTarget));
|
||||
|
||||
if (GetDriveType(m_sTarget) != DRIVE_REMOVABLE) {
|
||||
VFDTRACE(0, ("Not a VFD drive\n"));
|
||||
return NOERROR;
|
||||
}
|
||||
|
||||
drive = m_sTarget[0];
|
||||
m_bDragDrop = TRUE;
|
||||
}
|
||||
else {
|
||||
|
||||
// act as a context menu handler
|
||||
|
||||
VFDTRACE(0, ("Context menu:\n"));
|
||||
m_bDragDrop = FALSE;
|
||||
}
|
||||
|
||||
// Extract the target object name
|
||||
|
||||
if (pDataObj) {
|
||||
|
||||
STGMEDIUM medium;
|
||||
FORMATETC fmt = {
|
||||
CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL
|
||||
};
|
||||
|
||||
if (SUCCEEDED(pDataObj->GetData(&fmt, &medium))) {
|
||||
if (DragQueryFile((HDROP)medium.hGlobal, (UINT)-1, NULL, 0)) {
|
||||
|
||||
DragQueryFile((HDROP)medium.hGlobal,
|
||||
0, m_sTarget, sizeof(m_sTarget));
|
||||
}
|
||||
|
||||
ReleaseStgMedium(&medium);
|
||||
}
|
||||
}
|
||||
|
||||
VFDTRACE(0, ("Target %s\n", m_sTarget));
|
||||
|
||||
if (!drive) {
|
||||
// Contect menu handler
|
||||
// -- Data object is the target drive
|
||||
drive = m_sTarget[0];
|
||||
}
|
||||
|
||||
HANDLE hDevice = VfdOpenDevice(drive);
|
||||
|
||||
if (hDevice == INVALID_HANDLE_VALUE) {
|
||||
VFDTRACE(0, ("Not a VFD drive\n"));
|
||||
return NOERROR;
|
||||
}
|
||||
|
||||
ULONG ret = VfdGetDeviceNumber(hDevice, &m_nDevice);
|
||||
|
||||
CloseHandle(hDevice);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
m_nDevice = (ULONG)-1;
|
||||
return NOERROR;
|
||||
}
|
||||
|
||||
VFDTRACE(0, ("VFD device %d\n", m_nDevice));
|
||||
// Store the data object
|
||||
|
||||
m_pDataObj = pDataObj;
|
||||
m_pDataObj->AddRef();
|
||||
|
||||
return NOERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
STDMETHODIMP CVfdShExt::GetInfoFlags(
|
||||
DWORD *pdwFlags)
|
||||
{
|
||||
VFDTRACE(0, ("CVfdShExt::GetInfoFlags\n"));
|
||||
*pdwFlags = 0;
|
||||
return NOERROR;
|
||||
}
|
||||
|
||||
STDMETHODIMP CVfdShExt::GetInfoTip(
|
||||
DWORD dwFlags,
|
||||
LPWSTR *ppwszTip)
|
||||
{
|
||||
VFDTRACE(0, ("CVfdShExt::GetInfoTip\n"));
|
||||
*ppwszTip = NULL;
|
||||
return NOERROR;
|
||||
}
|
||||
*/
|
99
modules/rosapps/lib/vfdlib/vfdshext.h
Normal file
99
modules/rosapps/lib/vfdlib/vfdshext.h
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
vfdshext.h
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
shell extension COM class header
|
||||
|
||||
Copyright (c) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#ifndef _VFDSHEXT_H_
|
||||
#define _VFDSHEXT_H_
|
||||
|
||||
//
|
||||
// CVfdShExt
|
||||
// COM Shell extension class
|
||||
//
|
||||
class CVfdShExt : public IContextMenu,
|
||||
IShellExtInit,
|
||||
IShellPropSheetExt
|
||||
// IQueryInfo
|
||||
{
|
||||
protected:
|
||||
ULONG m_cRefCnt; // reference count
|
||||
LPDATAOBJECT m_pDataObj; // IDataObject pointer
|
||||
ULONG m_nDevice; // VFD device number
|
||||
CHAR m_sTarget[MAX_PATH]; // target path
|
||||
BOOL m_bDragDrop;
|
||||
|
||||
public:
|
||||
// constructor / destructor
|
||||
CVfdShExt();
|
||||
~CVfdShExt();
|
||||
|
||||
// perform VFD operations
|
||||
DWORD DoVfdOpen(HWND hParent);
|
||||
DWORD DoVfdNew(HWND hParent);
|
||||
DWORD DoVfdClose(HWND hParent);
|
||||
DWORD DoVfdSave(HWND hParent);
|
||||
DWORD DoVfdProtect(HWND hParent);
|
||||
DWORD DoVfdDrop(HWND hParent);
|
||||
|
||||
// get current attributes
|
||||
ULONG GetDevice() { return m_nDevice; }
|
||||
PCSTR GetTarget() { return m_sTarget; }
|
||||
|
||||
// IUnknown inheritance
|
||||
STDMETHODIMP QueryInterface(REFIID, LPVOID *);
|
||||
STDMETHODIMP_(ULONG) AddRef();
|
||||
STDMETHODIMP_(ULONG) Release();
|
||||
|
||||
// IShellExtInit inheritance
|
||||
STDMETHODIMP Initialize(
|
||||
LPCITEMIDLIST pIDFolder,
|
||||
LPDATAOBJECT pDataObj,
|
||||
HKEY hKeyID);
|
||||
|
||||
// IContextMenu inheritance
|
||||
STDMETHODIMP QueryContextMenu(
|
||||
HMENU hMenu,
|
||||
UINT indexMenu,
|
||||
UINT idCmdFirst,
|
||||
UINT idCmdLast,
|
||||
UINT uFlags);
|
||||
|
||||
STDMETHODIMP InvokeCommand(
|
||||
LPCMINVOKECOMMANDINFO lpcmi);
|
||||
|
||||
STDMETHODIMP GetCommandString(
|
||||
UINT idCmd,
|
||||
UINT uFlags,
|
||||
UINT *reserved,
|
||||
LPSTR pszName,
|
||||
UINT cchMax);
|
||||
|
||||
// IShellPropSheetExt inheritance
|
||||
STDMETHODIMP AddPages(
|
||||
LPFNADDPROPSHEETPAGE lpfnAddPage,
|
||||
LPARAM lParam);
|
||||
|
||||
STDMETHODIMP ReplacePage(
|
||||
UINT uPageID,
|
||||
LPFNADDPROPSHEETPAGE lpfnReplaceWith,
|
||||
LPARAM lParam);
|
||||
/*
|
||||
// IQueryInfo inheritance
|
||||
|
||||
STDMETHODIMP GetInfoFlags(
|
||||
DWORD *pdwFlags);
|
||||
|
||||
STDMETHODIMP GetInfoTip(
|
||||
DWORD dwFlags,
|
||||
LPWSTR *ppwszTip);
|
||||
*/
|
||||
};
|
||||
|
||||
typedef CVfdShExt *LPCVFDSHEXT;
|
||||
|
||||
#endif // _VFDSHEXT_H_
|
17
modules/rosapps/lib/vfdlib/vfdshguid.h
Normal file
17
modules/rosapps/lib/vfdlib/vfdshguid.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
vfdshguid.h
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
shell extension GUID header
|
||||
|
||||
Copyright (c) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#ifndef _VFDSHGUID_H_
|
||||
#define _VFDSHGUID_H_
|
||||
|
||||
DEFINE_GUID(CLSID_VfdShellExt, 0x296c1585L, 0x678f, 0x4584,
|
||||
0x8f, 0x02, 0x10, 0x39, 0xc1, 0xd1, 0x86, 0x4c);
|
||||
|
||||
#endif // _VFDSHGUID_H_
|
597
modules/rosapps/lib/vfdlib/vfdshmenu.cpp
Normal file
597
modules/rosapps/lib/vfdlib/vfdshmenu.cpp
Normal file
|
@ -0,0 +1,597 @@
|
|||
/*
|
||||
vfdshmenu.cpp
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
COM shell extension class context menu functions
|
||||
|
||||
Copyright (c) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
#include <shlobj.h>
|
||||
|
||||
#include "vfdtypes.h"
|
||||
#include "vfdapi.h"
|
||||
#include "vfdlib.h"
|
||||
#ifndef __REACTOS__
|
||||
#include "vfdmsg.h"
|
||||
#else
|
||||
#include "vfdmsg_lib.h"
|
||||
#endif
|
||||
|
||||
// class header
|
||||
#include "vfdshext.h"
|
||||
|
||||
//
|
||||
// Undocumented windows API to handle shell property sheets
|
||||
//
|
||||
|
||||
typedef BOOL (WINAPI *SHOBJECTPROPERTIES)(
|
||||
HWND hwnd, DWORD dwType, LPCWSTR lpObject, LPCWSTR lpPage);
|
||||
|
||||
#ifndef SHOP_FILEPATH
|
||||
#define SHOP_FILEPATH 0x00000002
|
||||
#endif
|
||||
|
||||
#define SHOP_EXPORT_ORDINAL 178
|
||||
|
||||
//
|
||||
// Context Menu Items
|
||||
//
|
||||
enum {
|
||||
VFD_CMD_OPEN = 0,
|
||||
VFD_CMD_SAVE,
|
||||
VFD_CMD_CLOSE,
|
||||
VFD_CMD_PROTECT,
|
||||
VFD_CMD_DROP,
|
||||
VFD_CMD_PROP,
|
||||
VFD_CMD_MAX
|
||||
};
|
||||
|
||||
static struct _vfd_menu {
|
||||
UINT textid; // menu item text id
|
||||
UINT helpid; // menu item help id
|
||||
#ifndef __REACTOS__
|
||||
PCHAR verbA; // ansi verb text
|
||||
PWCHAR verbW; // unicode verb text
|
||||
#else
|
||||
LPCSTR verbA; // ansi verb text
|
||||
LPCWSTR verbW; // unicode verb text
|
||||
#endif
|
||||
}
|
||||
g_VfdMenu[VFD_CMD_MAX] = {
|
||||
{ MSG_MENU_OPEN, MSG_HELP_OPEN, "vfdopen", L"vfdopen" },
|
||||
{ MSG_MENU_SAVE, MSG_HELP_SAVE, "vfdsave", L"vfdsave" },
|
||||
{ MSG_MENU_CLOSE, MSG_HELP_CLOSE, "vfdclose", L"vfdclose" },
|
||||
{ MSG_MENU_PROTECT, MSG_HELP_PROTECT, "protect", L"protect" },
|
||||
{ MSG_MENU_DROP, MSG_HELP_DROP, "vfddrop", L"vfddrop" },
|
||||
{ MSG_MENU_PROP, MSG_HELP_PROP, "vfdprop", L"vfdprop" },
|
||||
};
|
||||
|
||||
//
|
||||
// local functions
|
||||
//
|
||||
static void AddMenuItem(
|
||||
HMENU hMenu,
|
||||
UINT uPos,
|
||||
UINT uFlags,
|
||||
UINT uCmd,
|
||||
UINT uText)
|
||||
{
|
||||
PSTR text = ModuleMessage(uText);
|
||||
|
||||
if (text) {
|
||||
InsertMenu(hMenu, uPos, uFlags, uCmd, text);
|
||||
LocalFree(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// FUNCTION: CVfdShExt::QueryContextMenu(HMENU, UINT, UINT, UINT, UINT)
|
||||
//
|
||||
// PURPOSE: Called by the shell just before the context menu is displayed.
|
||||
// This is where you add your specific menu items.
|
||||
//
|
||||
// PARAMETERS:
|
||||
// hMenu - Handle to the context menu
|
||||
// indexMenu - Index of where to begin inserting menu items
|
||||
// idCmdFirst - Lowest value for new menu ID's
|
||||
// idCmtLast - Highest value for new menu ID's
|
||||
// uFlags - Specifies the context of the menu event
|
||||
//
|
||||
STDMETHODIMP CVfdShExt::QueryContextMenu(
|
||||
HMENU hMenu,
|
||||
UINT indexMenu,
|
||||
UINT idCmdFirst,
|
||||
UINT idCmdLast,
|
||||
UINT uFlags)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(idCmdLast);
|
||||
VFDTRACE(0, ("CVfdShExt::QueryContextMenu()\n"));
|
||||
|
||||
//
|
||||
// Check if menu items should be added
|
||||
//
|
||||
if ((CMF_DEFAULTONLY & uFlags) ||
|
||||
!m_pDataObj || m_nDevice == (ULONG)-1) {
|
||||
|
||||
VFDTRACE(0, ("Don't add any items.\n"));
|
||||
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
|
||||
}
|
||||
|
||||
//
|
||||
// Drag & Drop handler?
|
||||
//
|
||||
if (m_bDragDrop) {
|
||||
|
||||
VFDTRACE(0, ("Invoked as the Drop handler.\n"));
|
||||
|
||||
if (GetFileAttributes(m_sTarget) & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
|
||||
// if the dropped item is a directory, nothing to do here
|
||||
VFDTRACE(0, ("Dropped object is a directory.\n"));
|
||||
|
||||
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
|
||||
}
|
||||
|
||||
// Add a drop context menu item
|
||||
AddMenuItem(
|
||||
hMenu,
|
||||
indexMenu,
|
||||
MF_BYPOSITION | MF_STRING,
|
||||
idCmdFirst + VFD_CMD_DROP,
|
||||
g_VfdMenu[VFD_CMD_DROP].textid);
|
||||
|
||||
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, VFD_CMD_DROP + 1);
|
||||
}
|
||||
|
||||
//
|
||||
// Context menu handler
|
||||
//
|
||||
VFDTRACE(0, ("Invoked as the context menu handler.\n"));
|
||||
|
||||
//
|
||||
// Get the VFD media state
|
||||
//
|
||||
HANDLE hDevice = VfdOpenDevice(m_nDevice);
|
||||
|
||||
if (hDevice == INVALID_HANDLE_VALUE) {
|
||||
VFDTRACE(0, ("device open failed.\n"));
|
||||
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
|
||||
}
|
||||
|
||||
DWORD status = VfdGetMediaState(hDevice);
|
||||
|
||||
CloseHandle(hDevice);
|
||||
|
||||
//
|
||||
// Add context menu items
|
||||
//
|
||||
|
||||
InsertMenu(hMenu, indexMenu++,
|
||||
MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
|
||||
|
||||
if (status == ERROR_SUCCESS ||
|
||||
status == ERROR_WRITE_PROTECT) {
|
||||
|
||||
// An image is opened
|
||||
|
||||
// insert the "save" menu item
|
||||
|
||||
AddMenuItem(
|
||||
hMenu,
|
||||
indexMenu++,
|
||||
MF_BYPOSITION | MF_STRING,
|
||||
idCmdFirst + VFD_CMD_SAVE,
|
||||
g_VfdMenu[VFD_CMD_SAVE].textid);
|
||||
|
||||
// insert the "close" menu item
|
||||
|
||||
AddMenuItem(
|
||||
hMenu,
|
||||
indexMenu++,
|
||||
MF_BYPOSITION | MF_STRING,
|
||||
idCmdFirst + VFD_CMD_CLOSE,
|
||||
g_VfdMenu[VFD_CMD_CLOSE].textid);
|
||||
|
||||
// insert the "protect" menu item
|
||||
|
||||
AddMenuItem(
|
||||
hMenu,
|
||||
indexMenu++,
|
||||
MF_BYPOSITION | MF_STRING,
|
||||
idCmdFirst + VFD_CMD_PROTECT,
|
||||
g_VfdMenu[VFD_CMD_PROTECT].textid);
|
||||
|
||||
// check "protect" menu item
|
||||
|
||||
if (status == ERROR_WRITE_PROTECT) {
|
||||
CheckMenuItem(hMenu, indexMenu - 1,
|
||||
MF_BYPOSITION | MF_CHECKED);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// The drive is empty
|
||||
|
||||
// insert the "open" menu item
|
||||
|
||||
AddMenuItem(
|
||||
hMenu,
|
||||
indexMenu++,
|
||||
MF_BYPOSITION | MF_STRING,
|
||||
idCmdFirst + VFD_CMD_OPEN,
|
||||
g_VfdMenu[VFD_CMD_OPEN].textid);
|
||||
}
|
||||
|
||||
// Insert the "proterty" menu item
|
||||
|
||||
AddMenuItem(
|
||||
hMenu,
|
||||
indexMenu++,
|
||||
MF_BYPOSITION | MF_STRING,
|
||||
idCmdFirst + VFD_CMD_PROP,
|
||||
g_VfdMenu[VFD_CMD_PROP].textid);
|
||||
|
||||
// Insert a separator
|
||||
|
||||
InsertMenu(hMenu, indexMenu,
|
||||
MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
|
||||
|
||||
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, VFD_CMD_PROP + 1);
|
||||
}
|
||||
|
||||
//
|
||||
// FUNCTION: CVfdShExt::GetCommandString(LPCMINVOKECOMMANDINFO)
|
||||
//
|
||||
// PURPOSE: Retrieves information about a shortcut menu command,
|
||||
// including the Help string and the language-independent,
|
||||
// or canonical, name for the command.
|
||||
//
|
||||
// PARAMETERS:
|
||||
// idCmd - Menu command identifier offset.
|
||||
// uFlags - Flags specifying the information to return.
|
||||
// This parameter can have one of the following values.
|
||||
// GCS_HELPTEXTA Sets pszName to an ANSI string containing the Help text for the command.
|
||||
// GCS_HELPTEXTW Sets pszName to a Unicode string containing the Help text for the command.
|
||||
// GCS_VALIDATEA Returns S_OK if the menu item exists, or S_FALSE otherwise.
|
||||
// GCS_VALIDATEW Returns S_OK if the menu item exists, or S_FALSE otherwise.
|
||||
// GCS_VERBA Sets pszName to an ANSI string containing the language-independent command name for the menu item.
|
||||
// GCS_VERBW Sets pszName to a Unicode string containing the language-independent command name for the menu item.
|
||||
// pwReserved - Reserved. Applications must specify NULL when calling this method, and handlers must ignore this parameter when called.
|
||||
// pszName - Address of the buffer to receive the null-terminated string being retrieved.
|
||||
// cchMax - Size of the buffer to receive the null-terminated string.
|
||||
//
|
||||
|
||||
STDMETHODIMP CVfdShExt::GetCommandString(
|
||||
UINT idCmd,
|
||||
UINT uFlags,
|
||||
UINT *reserved,
|
||||
LPSTR pszName,
|
||||
UINT cchMax)
|
||||
{
|
||||
VFDTRACE(0,
|
||||
("CVfdShExt::GetCommandString(%u,...)\n", idCmd));
|
||||
|
||||
UNREFERENCED_PARAMETER(reserved);
|
||||
|
||||
if (idCmd >= sizeof(g_VfdMenu) / sizeof(g_VfdMenu[0])) {
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
switch (uFlags) {
|
||||
case GCS_HELPTEXTA:
|
||||
FormatMessageA(
|
||||
FORMAT_MESSAGE_FROM_HMODULE |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
g_hDllModule, g_VfdMenu[idCmd].helpid,
|
||||
0, pszName, cchMax, NULL);
|
||||
|
||||
VFDTRACE(0, ("HELPTEXTA: %s\n", pszName));
|
||||
break;
|
||||
|
||||
case GCS_HELPTEXTW:
|
||||
FormatMessageW(
|
||||
FORMAT_MESSAGE_FROM_HMODULE |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
g_hDllModule, g_VfdMenu[idCmd].helpid,
|
||||
0, (LPWSTR)pszName, cchMax, NULL);
|
||||
|
||||
VFDTRACE(0, ("HELPTEXTW: %ws\n", pszName));
|
||||
break;
|
||||
|
||||
case GCS_VERBA:
|
||||
lstrcpynA(pszName, g_VfdMenu[idCmd].verbA, cchMax);
|
||||
break;
|
||||
|
||||
case GCS_VERBW:
|
||||
lstrcpynW((LPWSTR)pszName, g_VfdMenu[idCmd].verbW, cchMax);
|
||||
break;
|
||||
}
|
||||
|
||||
return NOERROR;
|
||||
}
|
||||
|
||||
//
|
||||
// FUNCTION: CVfdShExt::InvokeCommand(LPCMINVOKECOMMANDINFO)
|
||||
//
|
||||
// PURPOSE: Called by the shell after the user has selected on of the
|
||||
// menu items that was added in QueryContextMenu().
|
||||
//
|
||||
// PARAMETERS:
|
||||
// lpcmi - Pointer to an CMINVOKECOMMANDINFO structure
|
||||
//
|
||||
|
||||
STDMETHODIMP CVfdShExt::InvokeCommand(
|
||||
LPCMINVOKECOMMANDINFO lpcmi)
|
||||
{
|
||||
VFDTRACE(0, ("CVfdShExt::InvokeCommand()\n"));
|
||||
|
||||
BOOL unicode = FALSE;
|
||||
UINT id;
|
||||
DWORD ret;
|
||||
CMINVOKECOMMANDINFOEX *excmi = (CMINVOKECOMMANDINFOEX *)lpcmi;
|
||||
|
||||
if (lpcmi->cbSize >= sizeof(CMINVOKECOMMANDINFOEX) &&
|
||||
(lpcmi->fMask & CMIC_MASK_UNICODE)) {
|
||||
|
||||
unicode = TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (!unicode && HIWORD(lpcmi->lpVerb)) {
|
||||
|
||||
VFDTRACE(0, ("ANSI: %s\n", lpcmi->lpVerb));
|
||||
|
||||
// ANSI verb
|
||||
for (id = 0; id < sizeof(g_VfdMenu) / sizeof(g_VfdMenu[0]); id++) {
|
||||
if (!lstrcmpi(lpcmi->lpVerb, g_VfdMenu[id].verbA)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (unicode && HIWORD(excmi->lpVerbW)) {
|
||||
|
||||
VFDTRACE(0, ("UNICODE: %ws\n", excmi->lpVerbW));
|
||||
|
||||
// UNICODE verb
|
||||
for (id = 0; id < sizeof(g_VfdMenu) / sizeof(g_VfdMenu[0]); id++) {
|
||||
if (!lstrcmpiW(excmi->lpVerbW, g_VfdMenu[id].verbW)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
VFDTRACE(0, ("Command: %u\n", LOWORD(lpcmi->lpVerb)));
|
||||
|
||||
// Command ID
|
||||
id = LOWORD(lpcmi->lpVerb);
|
||||
}
|
||||
|
||||
VFDTRACE(0, ("MenuItem: %u\n", id));
|
||||
|
||||
switch (id) {
|
||||
case VFD_CMD_OPEN:
|
||||
ret = DoVfdOpen(lpcmi->hwnd);
|
||||
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
VfdImageTip(lpcmi->hwnd, m_nDevice);
|
||||
}
|
||||
break;
|
||||
|
||||
case VFD_CMD_SAVE:
|
||||
ret = DoVfdSave(lpcmi->hwnd);
|
||||
break;
|
||||
|
||||
case VFD_CMD_CLOSE:
|
||||
ret = DoVfdClose(lpcmi->hwnd);
|
||||
break;
|
||||
|
||||
case VFD_CMD_PROTECT:
|
||||
ret = DoVfdProtect(lpcmi->hwnd);
|
||||
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
VfdImageTip(lpcmi->hwnd, m_nDevice);
|
||||
}
|
||||
else if (ret == ERROR_WRITE_PROTECT) {
|
||||
VfdImageTip(lpcmi->hwnd, m_nDevice);
|
||||
ret = ERROR_SUCCESS;
|
||||
}
|
||||
break;
|
||||
|
||||
case VFD_CMD_DROP:
|
||||
ret = DoVfdDrop(lpcmi->hwnd);
|
||||
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
VfdImageTip(lpcmi->hwnd, m_nDevice);
|
||||
}
|
||||
break;
|
||||
|
||||
case VFD_CMD_PROP:
|
||||
{
|
||||
SHOBJECTPROPERTIES pSHObjectProperties;
|
||||
WCHAR path[4] = L" :\\";
|
||||
|
||||
pSHObjectProperties = (SHOBJECTPROPERTIES)GetProcAddress(
|
||||
LoadLibrary("shell32"), "SHObjectProperties");
|
||||
|
||||
if (!pSHObjectProperties) {
|
||||
pSHObjectProperties = (SHOBJECTPROPERTIES)GetProcAddress(
|
||||
LoadLibrary("shell32"), (LPCSTR)SHOP_EXPORT_ORDINAL);
|
||||
}
|
||||
|
||||
if (pSHObjectProperties) {
|
||||
path[0] = m_sTarget[0];
|
||||
|
||||
pSHObjectProperties(lpcmi->hwnd,
|
||||
SHOP_FILEPATH, path, L"VFD");
|
||||
}
|
||||
}
|
||||
ret = ERROR_SUCCESS;
|
||||
break;
|
||||
|
||||
default:
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (ret != ERROR_SUCCESS &&
|
||||
ret != ERROR_CANCELLED) {
|
||||
|
||||
MessageBox(lpcmi->hwnd,
|
||||
SystemMessage(ret), VFD_MSGBOX_TITLE, MB_ICONSTOP);
|
||||
}
|
||||
|
||||
return NOERROR;
|
||||
}
|
||||
|
||||
//=====================================
|
||||
// perform VFD menu operation
|
||||
//=====================================
|
||||
|
||||
DWORD CVfdShExt::DoVfdOpen(
|
||||
HWND hParent)
|
||||
{
|
||||
DWORD ret = VfdGuiOpen(hParent, m_nDevice);
|
||||
|
||||
if (ret != ERROR_SUCCESS && ret != ERROR_CANCELLED) {
|
||||
MessageBox(hParent, SystemMessage(ret),
|
||||
VFD_MSGBOX_TITLE, MB_ICONSTOP);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
// Save the VFD image
|
||||
//
|
||||
DWORD CVfdShExt::DoVfdSave(
|
||||
HWND hParent)
|
||||
{
|
||||
return VfdGuiSave(hParent, m_nDevice);
|
||||
}
|
||||
|
||||
//
|
||||
// Close current VFD image
|
||||
//
|
||||
DWORD CVfdShExt::DoVfdClose(
|
||||
HWND hParent)
|
||||
{
|
||||
return VfdGuiClose(hParent, m_nDevice);
|
||||
}
|
||||
|
||||
//
|
||||
// Enable/disable media write protection
|
||||
//
|
||||
DWORD CVfdShExt::DoVfdProtect(
|
||||
HWND hParent)
|
||||
{
|
||||
HANDLE hDevice;
|
||||
DWORD ret;
|
||||
|
||||
UNREFERENCED_PARAMETER(hParent);
|
||||
VFDTRACE(0, ("CVfdShExt::DoVfdProtect()\n"));
|
||||
|
||||
hDevice = VfdOpenDevice(m_nDevice);
|
||||
|
||||
if (hDevice == INVALID_HANDLE_VALUE) {
|
||||
return GetLastError();
|
||||
}
|
||||
|
||||
ret = VfdGetMediaState(hDevice);
|
||||
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
ret = VfdWriteProtect(hDevice, TRUE);
|
||||
}
|
||||
else if (ret == ERROR_WRITE_PROTECT) {
|
||||
ret = VfdWriteProtect(hDevice, FALSE);
|
||||
}
|
||||
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
ret = VfdGetMediaState(hDevice);
|
||||
}
|
||||
|
||||
CloseHandle(hDevice);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
// Open dropped file with VFD
|
||||
//
|
||||
DWORD CVfdShExt::DoVfdDrop(
|
||||
HWND hParent)
|
||||
{
|
||||
HANDLE hDevice;
|
||||
DWORD file_attr;
|
||||
ULONG file_size;
|
||||
VFD_FILETYPE file_type;
|
||||
|
||||
VFD_DISKTYPE disk_type;
|
||||
VFD_MEDIA media_type;
|
||||
|
||||
DWORD ret;
|
||||
|
||||
VFDTRACE(0, ("CVfdShExt::DoVfdDropOpen()\n"));
|
||||
|
||||
// check if dropped file is a valid image
|
||||
|
||||
ret = VfdCheckImageFile(
|
||||
m_sTarget, &file_attr, &file_type, &file_size);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// check file size
|
||||
media_type = VfdLookupMedia(file_size);
|
||||
|
||||
if (!media_type) {
|
||||
PSTR msg = ModuleMessage(MSG_FILE_TOO_SMALL);
|
||||
|
||||
MessageBox(hParent, msg ? msg : "Bad size",
|
||||
VFD_MSGBOX_TITLE, MB_ICONSTOP);
|
||||
|
||||
if (msg) {
|
||||
LocalFree(msg);
|
||||
}
|
||||
|
||||
return ERROR_CANCELLED;
|
||||
}
|
||||
|
||||
if ((file_type == VFD_FILETYPE_ZIP) ||
|
||||
(file_attr & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_COMPRESSED | FILE_ATTRIBUTE_ENCRYPTED))) {
|
||||
|
||||
disk_type = VFD_DISKTYPE_RAM;
|
||||
}
|
||||
else {
|
||||
disk_type = VFD_DISKTYPE_FILE;
|
||||
}
|
||||
|
||||
// close current image (if opened)
|
||||
|
||||
ret = DoVfdClose(hParent);
|
||||
|
||||
if (ret != ERROR_SUCCESS &&
|
||||
ret != ERROR_NOT_READY) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// open dropped file
|
||||
|
||||
hDevice = VfdOpenDevice(m_nDevice);
|
||||
|
||||
if (hDevice == INVALID_HANDLE_VALUE) {
|
||||
return GetLastError();
|
||||
}
|
||||
|
||||
ret = VfdOpenImage(
|
||||
hDevice, m_sTarget, disk_type, media_type, FALSE);
|
||||
|
||||
CloseHandle(hDevice);
|
||||
|
||||
return ret;
|
||||
}
|
434
modules/rosapps/lib/vfdlib/vfdshprop.cpp
Normal file
434
modules/rosapps/lib/vfdlib/vfdshprop.cpp
Normal file
|
@ -0,0 +1,434 @@
|
|||
/*
|
||||
vfdshprop.cpp
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
COM shell extension class property sheet functions
|
||||
|
||||
Copyright (c) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
#include <shlobj.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "vfdtypes.h"
|
||||
#include "vfdapi.h"
|
||||
#include "vfdlib.h"
|
||||
#include "vfdver.h"
|
||||
#ifndef __REACTOS__
|
||||
#include "vfdmsg.h"
|
||||
#else
|
||||
#include "vfdmsg_lib.h"
|
||||
#endif
|
||||
#include "vfdguirc.h"
|
||||
|
||||
// class header
|
||||
#include "vfdshext.h"
|
||||
|
||||
// property sheet property ID
|
||||
|
||||
#define VFD_PROPERTY_ID "VFD"
|
||||
|
||||
//
|
||||
// local functions
|
||||
//
|
||||
static BOOL CALLBACK VfdPageDlgProc(
|
||||
HWND hDlg,
|
||||
UINT uMessage,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam);
|
||||
|
||||
static UINT CALLBACK VfdPageCallback(
|
||||
HWND hWnd,
|
||||
UINT uMessage,
|
||||
LPPROPSHEETPAGE ppsp);
|
||||
|
||||
static void OnPropInit(HWND hDlg);
|
||||
static void OnControl(HWND hDlg);
|
||||
static void UpdateImageInfo(HWND hDlg, ULONG nDevice);
|
||||
|
||||
//
|
||||
// property sheet callback function
|
||||
//
|
||||
UINT CALLBACK VfdPageCallback(
|
||||
HWND hWnd,
|
||||
UINT uMessage,
|
||||
LPPROPSHEETPAGE ppsp)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hWnd);
|
||||
|
||||
switch(uMessage) {
|
||||
case PSPCB_CREATE:
|
||||
return TRUE;
|
||||
|
||||
case PSPCB_RELEASE:
|
||||
if (ppsp->lParam) {
|
||||
((LPCVFDSHEXT)(ppsp->lParam))->Release();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// property page dialog procedure
|
||||
//
|
||||
BOOL CALLBACK VfdPageDlgProc(
|
||||
HWND hDlg,
|
||||
UINT uMessage,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
LPPROPSHEETPAGE psp;
|
||||
LPCVFDSHEXT lpcs;
|
||||
|
||||
switch (uMessage) {
|
||||
case WM_INITDIALOG:
|
||||
SetWindowLong(hDlg, DWL_USER, lParam);
|
||||
|
||||
if (lParam) {
|
||||
lpcs = (LPCVFDSHEXT)((LPPROPSHEETPAGE)lParam)->lParam;
|
||||
|
||||
OnPropInit(hDlg);
|
||||
UpdateImageInfo(hDlg, lpcs->GetDevice());
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
case WM_COMMAND:
|
||||
psp = (LPPROPSHEETPAGE)GetWindowLong(hDlg, DWL_USER);
|
||||
|
||||
if (!psp) {
|
||||
break;
|
||||
}
|
||||
|
||||
lpcs = (LPCVFDSHEXT)psp->lParam;
|
||||
|
||||
if (!lpcs) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (wParam) {
|
||||
case IDC_OPEN:
|
||||
if (lpcs->DoVfdOpen(hDlg) == ERROR_SUCCESS) {
|
||||
SendMessage((HWND)lParam,
|
||||
BM_SETSTYLE, BS_PUSHBUTTON, TRUE);
|
||||
}
|
||||
UpdateImageInfo(hDlg, lpcs->GetDevice());
|
||||
break;
|
||||
|
||||
case IDC_SAVE:
|
||||
if (lpcs->DoVfdSave(hDlg) == ERROR_SUCCESS) {
|
||||
SendMessage((HWND)lParam,
|
||||
BM_SETSTYLE, BS_PUSHBUTTON, TRUE);
|
||||
}
|
||||
UpdateImageInfo(hDlg, lpcs->GetDevice());
|
||||
break;
|
||||
|
||||
case IDC_CLOSE:
|
||||
if (lpcs->DoVfdClose(hDlg) == ERROR_SUCCESS) {
|
||||
SendMessage((HWND)lParam,
|
||||
BM_SETSTYLE, BS_PUSHBUTTON, TRUE);
|
||||
}
|
||||
UpdateImageInfo(hDlg, lpcs->GetDevice());
|
||||
break;
|
||||
|
||||
case IDC_WRITE_PROTECTED:
|
||||
lpcs->DoVfdProtect(hDlg);
|
||||
break;
|
||||
|
||||
case IDC_FORMAT:
|
||||
VfdGuiFormat(hDlg, lpcs->GetDevice());
|
||||
break;
|
||||
|
||||
case IDC_CONTROL:
|
||||
OnControl(hDlg);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_CONTEXTMENU:
|
||||
ShowContextMenu(hDlg, (HWND)wParam, lParam);
|
||||
break;
|
||||
|
||||
case WM_HELP:
|
||||
{
|
||||
LPHELPINFO info = (LPHELPINFO)lParam;
|
||||
|
||||
if (info->iContextType == HELPINFO_WINDOW) {
|
||||
ShowHelpWindow(hDlg, info->iCtrlId);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
default:
|
||||
if (uMessage == g_nNotifyMsg) {
|
||||
psp = (LPPROPSHEETPAGE)GetWindowLong(hDlg, DWL_USER);
|
||||
|
||||
if (!psp) {
|
||||
break;
|
||||
}
|
||||
|
||||
lpcs = (LPCVFDSHEXT)psp->lParam;
|
||||
|
||||
if (!lpcs) {
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateImageInfo(hDlg, lpcs->GetDevice());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// initialize the property page
|
||||
//
|
||||
void OnPropInit(
|
||||
HWND hDlg)
|
||||
{
|
||||
// set up control text
|
||||
|
||||
SetDlgItemText(hDlg, IDC_PROPERTY_TITLE, VFD_PRODUCT_DESC);
|
||||
SetDlgItemText(hDlg, IDC_COPYRIGHT_STR, VFD_COPYRIGHT_STR);
|
||||
|
||||
SetControlText(hDlg, IDC_IMAGEFILE_LABEL, MSG_IMAGEFILE_LABEL);
|
||||
SetControlText(hDlg, IDC_IMAGEDESC_LABEL, MSG_DESCRIPTION_LABEL);
|
||||
SetControlText(hDlg, IDC_DISKTYPE_LABEL, MSG_DISKTYPE_LABEL);
|
||||
SetControlText(hDlg, IDC_MEDIATYPE_LABEL, MSG_MEDIATYPE_LABEL);
|
||||
SetControlText(hDlg, IDC_WRITE_PROTECTED, MSG_MENU_PROTECT);
|
||||
SetControlText(hDlg, IDC_OPEN, MSG_OPEN_BUTTON);
|
||||
SetControlText(hDlg, IDC_SAVE, MSG_SAVE_BUTTON);
|
||||
SetControlText(hDlg, IDC_CLOSE, MSG_CLOSE_BUTTON);
|
||||
SetControlText(hDlg, IDC_FORMAT, MSG_FORMAT_BUTTON);
|
||||
SetControlText(hDlg, IDC_CONTROL, MSG_CONTROL_BUTTON);
|
||||
}
|
||||
|
||||
//
|
||||
// Control Panel button is clicked
|
||||
//
|
||||
void OnControl(
|
||||
HWND hDlg)
|
||||
{
|
||||
CHAR module_path[MAX_PATH];
|
||||
CHAR full_path[MAX_PATH];
|
||||
PSTR file_name;
|
||||
DWORD ret;
|
||||
|
||||
ret = GetModuleFileName(
|
||||
g_hDllModule, module_path, sizeof(module_path));
|
||||
|
||||
if (ret == 0 || ret >= sizeof(module_path)) {
|
||||
file_name = full_path;
|
||||
}
|
||||
else {
|
||||
ret = GetFullPathName(
|
||||
module_path, sizeof(full_path), full_path, &file_name);
|
||||
|
||||
if (ret == 0 || ret >= sizeof(full_path)) {
|
||||
file_name = full_path;
|
||||
}
|
||||
}
|
||||
|
||||
strcpy(file_name, "vfdwin.exe");
|
||||
|
||||
VFDTRACE(0, ("Starting %s\n", full_path));
|
||||
|
||||
ret = (DWORD)ShellExecute(
|
||||
hDlg, NULL, full_path, NULL, NULL, SW_SHOW);
|
||||
|
||||
if (ret > 32) {
|
||||
PropSheet_PressButton(GetParent(hDlg), PSBTN_CANCEL);
|
||||
}
|
||||
else {
|
||||
MessageBox(hDlg, SystemMessage(ret),
|
||||
VFD_MSGBOX_TITLE, MB_ICONSTOP);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Update image information on the property page
|
||||
//
|
||||
void UpdateImageInfo(
|
||||
HWND hDlg,
|
||||
ULONG nDevice)
|
||||
{
|
||||
HANDLE hDevice;
|
||||
CHAR buf[MAX_PATH];
|
||||
VFD_DISKTYPE disk_type;
|
||||
VFD_MEDIA media_type;
|
||||
VFD_FLAGS media_flags;
|
||||
VFD_FILETYPE file_type;
|
||||
ULONG image_size;
|
||||
DWORD attrib;
|
||||
ULONG ret;
|
||||
|
||||
hDevice = VfdOpenDevice(nDevice);
|
||||
|
||||
if (hDevice == INVALID_HANDLE_VALUE) {
|
||||
MessageBox(hDlg,
|
||||
SystemMessage(GetLastError()),
|
||||
VFD_MSGBOX_TITLE, MB_ICONSTOP);
|
||||
return;
|
||||
}
|
||||
|
||||
// get current image information
|
||||
|
||||
ret = VfdGetImageInfo(
|
||||
hDevice,
|
||||
buf,
|
||||
&disk_type,
|
||||
&media_type,
|
||||
&media_flags,
|
||||
&file_type,
|
||||
&image_size);
|
||||
|
||||
CloseHandle(hDevice);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
MessageBox(hDlg,
|
||||
SystemMessage(ret),
|
||||
VFD_MSGBOX_TITLE, MB_ICONSTOP);
|
||||
return;
|
||||
}
|
||||
|
||||
if (media_type == VFD_MEDIA_NONE) {
|
||||
|
||||
// drive is empty
|
||||
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE, NULL);
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE_DESC, NULL);
|
||||
SetDlgItemText(hDlg, IDC_DISKTYPE, NULL);
|
||||
SetDlgItemText(hDlg, IDC_MEDIATYPE, NULL);
|
||||
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WRITE_PROTECTED), FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_OPEN), TRUE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_SAVE), FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_CLOSE), FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_FORMAT), FALSE);
|
||||
|
||||
SendMessage(GetDlgItem(hDlg, IDC_OPEN),
|
||||
BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
|
||||
|
||||
SetFocus(GetDlgItem(hDlg, IDC_OPEN));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// display image file name
|
||||
|
||||
if (buf[0]) {
|
||||
attrib = GetFileAttributes(buf);
|
||||
|
||||
if (attrib == INVALID_FILE_ATTRIBUTES) {
|
||||
attrib = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (disk_type != VFD_DISKTYPE_FILE) {
|
||||
strcpy(buf, "<RAM>");
|
||||
}
|
||||
attrib = 0;
|
||||
}
|
||||
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE, buf);
|
||||
|
||||
// display image description
|
||||
|
||||
VfdMakeFileDesc(buf, sizeof(buf),
|
||||
file_type, image_size, attrib);
|
||||
|
||||
SetDlgItemText(hDlg, IDC_IMAGEFILE_DESC, buf);
|
||||
|
||||
// display disk type
|
||||
|
||||
if (disk_type == VFD_DISKTYPE_FILE) {
|
||||
SetDlgItemText(hDlg, IDC_DISKTYPE, "FILE");
|
||||
}
|
||||
else {
|
||||
SetDlgItemText(hDlg, IDC_DISKTYPE, "RAM");
|
||||
}
|
||||
|
||||
// display media type
|
||||
|
||||
SetDlgItemText(hDlg, IDC_MEDIATYPE,
|
||||
VfdMediaTypeName(media_type));
|
||||
|
||||
// set write protect check box
|
||||
|
||||
if (media_flags & VFD_FLAG_WRITE_PROTECTED) {
|
||||
CheckDlgButton(hDlg, IDC_WRITE_PROTECTED, BST_CHECKED);
|
||||
}
|
||||
else {
|
||||
CheckDlgButton(hDlg, IDC_WRITE_PROTECTED, BST_UNCHECKED);
|
||||
}
|
||||
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WRITE_PROTECTED), TRUE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_OPEN), FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_SAVE), TRUE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_CLOSE), TRUE);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_FORMAT), TRUE);
|
||||
|
||||
SendMessage(GetDlgItem(hDlg, IDC_CLOSE),
|
||||
BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
|
||||
|
||||
SetFocus(GetDlgItem(hDlg, IDC_CLOSE));
|
||||
}
|
||||
|
||||
//
|
||||
// CVfdShExt class members inherited from IShellPropSheetExt
|
||||
//
|
||||
|
||||
// Add property page
|
||||
STDMETHODIMP CVfdShExt::AddPages(
|
||||
LPFNADDPROPSHEETPAGE lpfnAddPage,
|
||||
LPARAM lParam)
|
||||
{
|
||||
PROPSHEETPAGE psp;
|
||||
HPROPSHEETPAGE hpage;
|
||||
|
||||
if (!m_pDataObj || m_nDevice == (ULONG)-1) {
|
||||
// not a VFD drive
|
||||
VFDTRACE(0, ("PropPage: Not a VFD drive\n"));
|
||||
|
||||
return NOERROR;
|
||||
}
|
||||
|
||||
psp.dwSize = sizeof(psp); // no extra data.
|
||||
psp.dwFlags = PSP_USEREFPARENT | PSP_USETITLE | PSP_USECALLBACK;
|
||||
psp.hInstance = g_hDllModule;
|
||||
psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPDIALOG);
|
||||
psp.hIcon = 0;
|
||||
psp.pszTitle = "VFD";
|
||||
psp.pfnDlgProc = VfdPageDlgProc;
|
||||
psp.pcRefParent = &g_cDllRefCnt;
|
||||
psp.pfnCallback = VfdPageCallback;
|
||||
psp.lParam = (LPARAM)this;
|
||||
|
||||
AddRef();
|
||||
hpage = CreatePropertySheetPage(&psp);
|
||||
|
||||
if (hpage) {
|
||||
if (!lpfnAddPage(hpage, lParam)) {
|
||||
DestroyPropertySheetPage(hpage);
|
||||
Release();
|
||||
}
|
||||
}
|
||||
|
||||
return NOERROR;
|
||||
}
|
||||
|
||||
STDMETHODIMP CVfdShExt::ReplacePage(
|
||||
UINT uPageID,
|
||||
LPFNADDPROPSHEETPAGE lpfnReplaceWith,
|
||||
LPARAM lParam)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(uPageID);
|
||||
UNREFERENCED_PARAMETER(lpfnReplaceWith);
|
||||
UNREFERENCED_PARAMETER(lParam);
|
||||
return E_FAIL;
|
||||
}
|
419
modules/rosapps/lib/vfdlib/vfdshutil.cpp
Normal file
419
modules/rosapps/lib/vfdlib/vfdshutil.cpp
Normal file
|
@ -0,0 +1,419 @@
|
|||
/*
|
||||
vfdshutil.cpp
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
shell extension utility functions
|
||||
|
||||
Copyright (c) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <objbase.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "vfdtypes.h"
|
||||
#include "vfdapi.h"
|
||||
#include "vfdlib.h"
|
||||
#include "vfdshcfact.h"
|
||||
|
||||
//=====================================
|
||||
// Initialize the GUID instance
|
||||
//=====================================
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma data_seg(".text")
|
||||
#endif
|
||||
#define INITGUID
|
||||
#include <initguid.h>
|
||||
#include <shlguid.h>
|
||||
#include "vfdshguid.h"
|
||||
#ifdef _MSC_VER
|
||||
#pragma data_seg()
|
||||
#endif
|
||||
|
||||
//
|
||||
// Registry path to the approved shell extensions key
|
||||
//
|
||||
#define REGKEY_APPROVED \
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"
|
||||
|
||||
|
||||
//=====================================
|
||||
// Shell extension library requirements
|
||||
//=====================================
|
||||
|
||||
//
|
||||
// Creates a class factory instance
|
||||
//
|
||||
STDAPI DllGetClassObject(
|
||||
REFCLSID rclsid,
|
||||
REFIID riid,
|
||||
LPVOID *ppvOut)
|
||||
{
|
||||
VFDTRACE(0,
|
||||
("DllGetClassObject\n"));
|
||||
|
||||
*ppvOut = NULL;
|
||||
|
||||
if (IsEqualIID(rclsid, CLSID_VfdShellExt)) {
|
||||
CVfdFactory *pFactory = new CVfdFactory;
|
||||
|
||||
if (!pFactory) {
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
return pFactory->QueryInterface(riid, ppvOut);
|
||||
}
|
||||
|
||||
return CLASS_E_CLASSNOTAVAILABLE;
|
||||
}
|
||||
|
||||
//
|
||||
// DllCanUnloadNow
|
||||
//
|
||||
STDAPI DllCanUnloadNow(void)
|
||||
{
|
||||
VFDTRACE(0,
|
||||
("DllCanUnloadNow - %s\n", (g_cDllRefCnt ? "No" : "Yes")));
|
||||
|
||||
return (g_cDllRefCnt ? S_FALSE : S_OK);
|
||||
}
|
||||
|
||||
//=====================================
|
||||
// Shell extension register functions
|
||||
//=====================================
|
||||
|
||||
static inline void MakeGuidString(LPTSTR str, const GUID &guid)
|
||||
{
|
||||
sprintf(str, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
|
||||
guid.Data1, guid.Data2, guid.Data3,
|
||||
guid.Data4[0], guid.Data4[1],
|
||||
guid.Data4[2], guid.Data4[3], guid.Data4[4],
|
||||
guid.Data4[5], guid.Data4[6], guid.Data4[7]);
|
||||
}
|
||||
|
||||
//
|
||||
// Regster this dll as shell extention handlers
|
||||
//
|
||||
DWORD WINAPI VfdRegisterHandlers()
|
||||
{
|
||||
TCHAR buf[MAX_PATH];
|
||||
TCHAR guid_str[40];
|
||||
HKEY hKey;
|
||||
DWORD temp;
|
||||
DWORD ret;
|
||||
|
||||
MakeGuidString(guid_str, CLSID_VfdShellExt);
|
||||
|
||||
//
|
||||
// Register the GUID in the CLSID subtree
|
||||
//
|
||||
sprintf(buf, "CLSID\\%s", guid_str);
|
||||
|
||||
VFDTRACE(0, ("HKCR\\%s\n", buf));
|
||||
|
||||
ret = RegCreateKeyEx(
|
||||
HKEY_CLASSES_ROOT, buf, 0, NULL,
|
||||
0, KEY_ALL_ACCESS, NULL, &hKey, &temp);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (temp == REG_OPENED_EXISTING_KEY) {
|
||||
temp = sizeof(buf);
|
||||
|
||||
ret = RegQueryValueEx(
|
||||
hKey, NULL, NULL, NULL, (PBYTE)buf, &temp);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
RegCloseKey(hKey);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (_stricmp(buf, VFDEXT_DESCRIPTION)) {
|
||||
RegCloseKey(hKey);
|
||||
return ERROR_FILE_EXISTS;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
VFDTRACE(0, ("@=" VFDEXT_DESCRIPTION "\n"));
|
||||
|
||||
ret = RegSetValueEx(hKey, NULL, NULL, REG_SZ,
|
||||
(PBYTE)VFDEXT_DESCRIPTION, sizeof(VFDEXT_DESCRIPTION));
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Register the executable path
|
||||
//
|
||||
sprintf(buf, "CLSID\\%s\\InProcServer32", guid_str);
|
||||
|
||||
VFDTRACE(0, ("HKCR\\%s\n", buf));
|
||||
|
||||
ret = RegCreateKeyEx(
|
||||
HKEY_CLASSES_ROOT, buf, 0, NULL,
|
||||
0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
temp = GetModuleFileName(g_hDllModule, buf, sizeof(buf));
|
||||
|
||||
VFDTRACE(0, ("@=%s\n", buf));
|
||||
|
||||
ret = RegSetValueEx(
|
||||
hKey, NULL, NULL, REG_SZ, (PBYTE)buf, temp + 1);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
RegCloseKey(hKey);
|
||||
return ret;
|
||||
}
|
||||
|
||||
VFDTRACE(0, ("ThreadingModel=Apartment\n"));
|
||||
|
||||
ret = RegSetValueEx(hKey, "ThreadingModel", NULL, REG_SZ,
|
||||
(PBYTE)"Apartment", sizeof("Apartment"));
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
// Register context menu handler
|
||||
//
|
||||
VFDTRACE(0, ("HKCR\\" VFDEXT_MENU_REGKEY "\n"));
|
||||
|
||||
ret = RegCreateKeyEx(
|
||||
HKEY_CLASSES_ROOT, VFDEXT_MENU_REGKEY, 0, NULL,
|
||||
0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
VFDTRACE(0, ("@=%s\n", guid_str));
|
||||
|
||||
ret = RegSetValueEx(hKey, NULL, NULL, REG_SZ,
|
||||
(PBYTE)guid_str, strlen(guid_str) + 1);
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
// Register Drag&Drop handler
|
||||
//
|
||||
if (!IS_WINDOWS_NT()) {
|
||||
//
|
||||
// Windows NT does not support Drag&Drop handlers ???
|
||||
//
|
||||
VFDTRACE(0, ("HKCR\\" VFDEXT_DND_REGKEY "\n"));
|
||||
|
||||
ret = RegCreateKeyEx(
|
||||
HKEY_CLASSES_ROOT, VFDEXT_DND_REGKEY, 0, NULL,
|
||||
0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
VFDTRACE(0, ("@=%s\n", guid_str));
|
||||
|
||||
ret = RegSetValueEx(hKey, NULL, NULL, REG_SZ,
|
||||
(PBYTE)guid_str, strlen(guid_str) + 1);
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Register property sheet handler
|
||||
//
|
||||
VFDTRACE(0, ("HKCR\\" VFDEXT_PROP_REGKEY "\n"));
|
||||
|
||||
ret = RegCreateKeyEx(
|
||||
HKEY_CLASSES_ROOT, VFDEXT_PROP_REGKEY, 0, NULL,
|
||||
0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
VFDTRACE(0, ("@=%s\n", guid_str));
|
||||
|
||||
ret = RegSetValueEx(hKey, NULL, NULL, REG_SZ,
|
||||
(PBYTE)guid_str, strlen(guid_str) + 1);
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
// Register approved extensions entry
|
||||
//
|
||||
VFDTRACE(0, ("HKLM\\" REGKEY_APPROVED "\n"));
|
||||
|
||||
ret = RegCreateKeyEx(
|
||||
HKEY_LOCAL_MACHINE, REGKEY_APPROVED,
|
||||
0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
VFDTRACE(0,
|
||||
("%s=" VFDEXT_DESCRIPTION "\n", guid_str));
|
||||
|
||||
ret = RegSetValueEx(hKey, guid_str, NULL, REG_SZ,
|
||||
(PBYTE)VFDEXT_DESCRIPTION, sizeof(VFDEXT_DESCRIPTION));
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
// Unregister context menu handler
|
||||
//
|
||||
DWORD WINAPI VfdUnregisterHandlers()
|
||||
{
|
||||
TCHAR buf[MAX_PATH];
|
||||
TCHAR guid_str[40];
|
||||
HKEY hKey;
|
||||
DWORD temp;
|
||||
DWORD ret;
|
||||
|
||||
MakeGuidString(guid_str, CLSID_VfdShellExt);
|
||||
|
||||
sprintf(buf, "CLSID\\%s", guid_str);
|
||||
|
||||
VFDTRACE(0, ("HKCR\\%s\n", buf));
|
||||
|
||||
temp = sizeof(buf);
|
||||
|
||||
ret = RegQueryValue(HKEY_CLASSES_ROOT, buf, buf, (PLONG)&temp);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (_stricmp(buf, VFDEXT_DESCRIPTION)) {
|
||||
return ERROR_PATH_NOT_FOUND;
|
||||
}
|
||||
|
||||
sprintf(buf, "CLSID\\%s\\InProcServer32", guid_str);
|
||||
|
||||
VFDTRACE(0, ("HKCR\\%s\n", buf));
|
||||
|
||||
ret = RegDeleteKey(HKEY_CLASSES_ROOT, buf);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
sprintf(buf, "CLSID\\%s", guid_str);
|
||||
|
||||
VFDTRACE(0, ("HKCR\\%s\n", buf));
|
||||
|
||||
ret = RegDeleteKey(HKEY_CLASSES_ROOT, buf);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
VFDTRACE(0, ("HKCR\\" VFDEXT_MENU_REGKEY "\n"));
|
||||
|
||||
ret = RegDeleteKey(HKEY_CLASSES_ROOT, VFDEXT_MENU_REGKEY);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!IS_WINDOWS_NT()) {
|
||||
|
||||
// Windows NT doesn't support Drag & Drop handlers ???
|
||||
|
||||
VFDTRACE(0, ("HKCR\\" VFDEXT_DND_REGKEY "\n"));
|
||||
|
||||
ret = RegDeleteKey(HKEY_CLASSES_ROOT, VFDEXT_DND_REGKEY);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
VFDTRACE(0, ("HKCR\\" VFDEXT_PROP_REGKEY "\n"));
|
||||
|
||||
ret = RegDeleteKey(HKEY_CLASSES_ROOT, VFDEXT_PROP_REGKEY);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
VFDTRACE(0, ("HKLM\\" REGKEY_APPROVED "\n"));
|
||||
|
||||
ret = RegCreateKeyEx(
|
||||
HKEY_LOCAL_MACHINE,
|
||||
REGKEY_APPROVED,
|
||||
0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = RegDeleteValue(hKey, guid_str);
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
// Check if context menu handler is registered
|
||||
//
|
||||
DWORD WINAPI VfdCheckHandlers()
|
||||
{
|
||||
TCHAR buf[MAX_PATH];
|
||||
TCHAR guid_str[40];
|
||||
DWORD temp;
|
||||
DWORD ret;
|
||||
|
||||
MakeGuidString(guid_str, CLSID_VfdShellExt);
|
||||
|
||||
sprintf(buf, "CLSID\\%s", guid_str);
|
||||
|
||||
VFDTRACE(0, ("HKCR\\%s\n", buf));
|
||||
|
||||
temp = sizeof(buf);
|
||||
|
||||
ret = RegQueryValue(HKEY_CLASSES_ROOT, buf, buf, (PLONG)&temp);
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (_stricmp(buf, VFDEXT_DESCRIPTION)) {
|
||||
return ERROR_PATH_NOT_FOUND;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
422
modules/rosapps/lib/vfdlib/vfdzip.c
Normal file
422
modules/rosapps/lib/vfdlib/vfdzip.c
Normal file
|
@ -0,0 +1,422 @@
|
|||
/*
|
||||
vfdzip.c
|
||||
|
||||
Virtual Floppy Drive for Windows
|
||||
Driver control library
|
||||
Zip compressed floppy image handling
|
||||
|
||||
Copyright (C) 2003-2005 Ken Kato
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#pragma message(__FILE__": Compiled as C++ for testing purpose.")
|
||||
#endif // __cplusplus
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include "vfdtypes.h"
|
||||
#include "vfdio.h"
|
||||
#include "vfdlib.h"
|
||||
|
||||
#ifndef __REACTOS__
|
||||
#define ZLIB_WINAPI
|
||||
#else
|
||||
#define Z_SOLO
|
||||
#define ZLIB_INTERNAL
|
||||
#endif
|
||||
#include "zlib.h"
|
||||
|
||||
#ifdef VFD_NO_ZLIB
|
||||
#pragma message("ZIP image support is disabled.")
|
||||
|
||||
DWORD ExtractZipInfo(
|
||||
HANDLE hFile,
|
||||
ULONG *pSize)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hFile);
|
||||
UNREFERENCED_PARAMETER(pSize);
|
||||
return ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
DWORD ExtractZipImage(
|
||||
HANDLE hFile,
|
||||
PUCHAR *pBuffer,
|
||||
PULONG pLength)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hFile);
|
||||
UNREFERENCED_PARAMETER(pBuffer);
|
||||
UNREFERENCED_PARAMETER(pLength);
|
||||
return ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
#else // VFD_NO_ZLIB
|
||||
|
||||
#ifdef _DEBUG
|
||||
static const char *ZLIB_ERROR(int err)
|
||||
{
|
||||
switch (err) {
|
||||
case Z_OK : return "Z_OK";
|
||||
case Z_STREAM_END : return "Z_STREAM_END";
|
||||
case Z_NEED_DICT : return "Z_NEED_DICT";
|
||||
case Z_ERRNO : return "Z_ERRNO";
|
||||
case Z_STREAM_ERROR : return "Z_STREAM_ERROR";
|
||||
case Z_DATA_ERROR : return "Z_DATA_ERROR";
|
||||
case Z_MEM_ERROR : return "Z_MEM_ERROR";
|
||||
case Z_BUF_ERROR : return "Z_BUF_ERROR";
|
||||
case Z_VERSION_ERROR: return "Z_VERSION_ERROR";
|
||||
default : return "unknown";
|
||||
}
|
||||
}
|
||||
#endif // _DEBUG
|
||||
|
||||
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size))
|
||||
{
|
||||
UNREFERENCED_PARAMETER(opaque);
|
||||
return LocalAlloc(LPTR, items * size);
|
||||
}
|
||||
|
||||
void zcfree OF((voidpf opaque, voidpf ptr))
|
||||
{
|
||||
UNREFERENCED_PARAMETER(opaque);
|
||||
LocalFree(ptr);
|
||||
}
|
||||
|
||||
#define ZIP_LOCAL_SIGNATURE 0x04034b50
|
||||
|
||||
#define ZIP_FLAG_ENCRYPTED 0x01
|
||||
|
||||
#define ZIP_FLAG_DEFLATE_NORMAL 0x00
|
||||
#define ZIP_FLAG_DEFLATE_MAX 0x02
|
||||
#define ZIP_FLAG_DEFLATE_FAST 0x04
|
||||
#define ZIP_FLAG_DEFLATE_SUPER 0x06
|
||||
#define ZIP_FLAG_DEFLATE_MASK 0x06
|
||||
|
||||
#define ZIP_FLAG_SIZE_IN_DESC 0x08
|
||||
|
||||
#define ZIP_METHOD_STORED 0
|
||||
#define ZIP_METHOD_SHRUNK 1
|
||||
#define ZIP_METHOD_REDUCED1 2
|
||||
#define ZIP_METHOD_REDUCED2 3
|
||||
#define ZIP_METHOD_REDUCED3 4
|
||||
#define ZIP_METHOD_REDUCED4 5
|
||||
#define ZIP_METHOD_IMPLODED 6
|
||||
#define ZIP_METHOD_TOKENIZED 7
|
||||
#define ZIP_METHOD_DEFLATED 8
|
||||
#define ZIP_METHOD_DEFLATE64 9
|
||||
#define ZIP_METHOD_PKWARE_IMP 10
|
||||
#define ZIP_METHOD_RESERVED 11
|
||||
#define ZIP_METHOD_BZIP2 12
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct _zip_local_file_header {
|
||||
ULONG header_signature;
|
||||
USHORT required_version;
|
||||
USHORT general_flags;
|
||||
USHORT compression_method;
|
||||
USHORT last_mod_time;
|
||||
USHORT last_mod_date;
|
||||
ULONG crc32;
|
||||
ULONG compressed_size;
|
||||
ULONG uncompressed_size;
|
||||
USHORT file_name_length;
|
||||
USHORT extra_field_length;
|
||||
CHAR file_name[1];
|
||||
// followed by extra field data, then compressed data
|
||||
}
|
||||
ZIP_HEADER, *PZIP_HEADER;
|
||||
|
||||
//
|
||||
// Check if the file is ZIP compressed
|
||||
//
|
||||
DWORD ExtractZipInfo(
|
||||
HANDLE hFile,
|
||||
ULONG *pSize)
|
||||
{
|
||||
ZIP_HEADER zip_hdr;
|
||||
DWORD result;
|
||||
DWORD ret;
|
||||
|
||||
if (SetFilePointer(hFile, 0, NULL, FILE_BEGIN) != 0) {
|
||||
ret = GetLastError();
|
||||
|
||||
VFDTRACE(0,
|
||||
("SetFilePointer() - %s\n",
|
||||
SystemMessage(ret)));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!ReadFile(hFile, &zip_hdr, sizeof(zip_hdr), &result, NULL)) {
|
||||
ret = GetLastError();
|
||||
|
||||
VFDTRACE(0,
|
||||
("ReadFile() - %s\n",
|
||||
SystemMessage(ret)));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (result != sizeof(zip_hdr) ||
|
||||
zip_hdr.header_signature != ZIP_LOCAL_SIGNATURE ||
|
||||
zip_hdr.compression_method != ZIP_METHOD_DEFLATED ||
|
||||
(zip_hdr.general_flags & ZIP_FLAG_ENCRYPTED)) {
|
||||
|
||||
VFDTRACE(0,
|
||||
("[VFD] Invalid ZIP file\n"));
|
||||
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
// correct (and supported) ZIP header detected
|
||||
|
||||
*pSize = zip_hdr.uncompressed_size;
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract original data from IMZ file
|
||||
//
|
||||
DWORD ExtractZipImage(
|
||||
HANDLE hFile,
|
||||
PUCHAR *pBuffer,
|
||||
PULONG pLength)
|
||||
{
|
||||
UCHAR buf[VFD_BYTES_PER_SECTOR];
|
||||
DWORD result;
|
||||
DWORD ret;
|
||||
|
||||
PZIP_HEADER zip_hdr;
|
||||
ULONG compressed;
|
||||
ULONG uncompressed;
|
||||
PUCHAR file_cache;
|
||||
z_stream stream;
|
||||
int zlib_ret;
|
||||
|
||||
VFDTRACE(0,
|
||||
("[VFD] VfdExtractImz - IN\n"));
|
||||
|
||||
*pBuffer = NULL;
|
||||
*pLength = 0;
|
||||
|
||||
//
|
||||
// Read PKZIP local file header of the first file in the file
|
||||
// -- An IMZ file actually is just a ZIP file with a different
|
||||
// extension, which contains a single floppy image file
|
||||
//
|
||||
if (SetFilePointer(hFile, 0, NULL, FILE_BEGIN) != 0) {
|
||||
ret = GetLastError();
|
||||
|
||||
VFDTRACE(0,(
|
||||
"SetFilePointer - %s", SystemMessage(ret)));;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!ReadFile(hFile, buf, VFD_BYTES_PER_SECTOR, &result, NULL) ||
|
||||
result < VFD_BYTES_PER_SECTOR) {
|
||||
|
||||
ret = GetLastError();
|
||||
|
||||
VFDTRACE(0,(
|
||||
"ReadFile - %s", SystemMessage(ret)));;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
zip_hdr = (PZIP_HEADER)buf;
|
||||
|
||||
// check local file header signature
|
||||
|
||||
if (zip_hdr->header_signature != ZIP_LOCAL_SIGNATURE) {
|
||||
|
||||
VFDTRACE(0,
|
||||
("[VFD] PKZIP header signature not found.\n"));
|
||||
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
// check compression method
|
||||
|
||||
if (zip_hdr->compression_method != Z_DEFLATED) {
|
||||
|
||||
VFDTRACE(0,
|
||||
("[VFD] Bad PKZIP compression method.\n"));
|
||||
|
||||
return ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
if (zip_hdr->general_flags & 0x01) {
|
||||
// encrypted zip not supported
|
||||
|
||||
VFDTRACE(0,
|
||||
("[VFD] PKZIP encrypted.\n"));
|
||||
|
||||
return ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
// check uncompressed image size
|
||||
|
||||
compressed = zip_hdr->compressed_size;
|
||||
uncompressed = zip_hdr->uncompressed_size;
|
||||
|
||||
switch (uncompressed) {
|
||||
case VFD_SECTOR_TO_BYTE(320):
|
||||
case VFD_SECTOR_TO_BYTE(360):
|
||||
case VFD_SECTOR_TO_BYTE(640):
|
||||
case VFD_SECTOR_TO_BYTE(720):
|
||||
case VFD_SECTOR_TO_BYTE(1280):
|
||||
case VFD_SECTOR_TO_BYTE(1440):
|
||||
case VFD_SECTOR_TO_BYTE(1640):
|
||||
case VFD_SECTOR_TO_BYTE(2400):
|
||||
case VFD_SECTOR_TO_BYTE(2880):
|
||||
case VFD_SECTOR_TO_BYTE(3360):
|
||||
case VFD_SECTOR_TO_BYTE(3444):
|
||||
case VFD_SECTOR_TO_BYTE(5760):
|
||||
break;
|
||||
|
||||
default:
|
||||
VFDTRACE(0,
|
||||
("[VFD] Unsupported image size %lu.\n",
|
||||
uncompressed));
|
||||
|
||||
return ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
// check local file header length
|
||||
// -- Just for simplicity, the compressed data must start in the
|
||||
// first sector in the file: this is not a problem in most cases.
|
||||
|
||||
if (FIELD_OFFSET(ZIP_HEADER, file_name) +
|
||||
zip_hdr->file_name_length +
|
||||
zip_hdr->extra_field_length >= VFD_BYTES_PER_SECTOR) {
|
||||
|
||||
VFDTRACE(0,
|
||||
("[VFD] PKZIP header too long.\n"));
|
||||
|
||||
return ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
// allocate memory to store uncompressed data
|
||||
|
||||
file_cache = (PUCHAR)LocalAlloc(LPTR, uncompressed);
|
||||
|
||||
if (!file_cache) {
|
||||
|
||||
VFDTRACE(0,
|
||||
("[VFD] Failed to allocate file cache.\n"));
|
||||
|
||||
return ERROR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
// initialize the zlib stream
|
||||
|
||||
ZeroMemory(&stream, sizeof(stream));
|
||||
|
||||
// set initial input data information
|
||||
|
||||
stream.next_in = (PUCHAR)zip_hdr->file_name +
|
||||
zip_hdr->file_name_length + zip_hdr->extra_field_length;
|
||||
|
||||
stream.avail_in = VFD_BYTES_PER_SECTOR -
|
||||
FIELD_OFFSET(ZIP_HEADER, file_name) -
|
||||
zip_hdr->file_name_length - zip_hdr->extra_field_length;
|
||||
|
||||
// set output buffer information
|
||||
|
||||
stream.next_out = file_cache;
|
||||
stream.avail_out = uncompressed;
|
||||
|
||||
zlib_ret = inflateInit2(&stream, -MAX_WBITS);
|
||||
|
||||
// negative MAX_WBITS value passed to the inflateInit2() function
|
||||
// indicates that there is no zlib header.
|
||||
// In this case inflate() function requires an extra "dummy" byte
|
||||
// after the compressed stream in order to complete decompression
|
||||
// and return Z_STREAM_END. However, both compressed and uncompressed
|
||||
// data size are already known from the pkzip header, Z_STREAM_END
|
||||
// is not absolutely necessary to know the completion of the operation.
|
||||
|
||||
if (zlib_ret != Z_OK) {
|
||||
LocalFree(file_cache);
|
||||
|
||||
VFDTRACE(0,
|
||||
("[VFD] inflateInit2() failed - %s.\n",
|
||||
ZLIB_ERROR(zlib_ret)));
|
||||
|
||||
return ERROR_INVALID_FUNCTION;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
|
||||
// uncompress current block
|
||||
|
||||
zlib_ret = inflate(&stream, Z_NO_FLUSH);
|
||||
|
||||
if (zlib_ret != Z_OK) {
|
||||
if (zlib_ret == Z_STREAM_END) {
|
||||
ret = ERROR_SUCCESS;
|
||||
}
|
||||
else {
|
||||
VFDTRACE(0,
|
||||
("[VFD] inflate() failed - %s.\n",
|
||||
ZLIB_ERROR(zlib_ret)));
|
||||
|
||||
ret = ERROR_INVALID_FUNCTION;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (stream.total_out >= uncompressed) {
|
||||
// uncompress completed - no need to wait for Z_STREAM_END
|
||||
// (inflate() would return Z_STREAM_END on the next call)
|
||||
ret = ERROR_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
if (stream.total_in >= compressed) {
|
||||
// somehow there is not enought compressed data
|
||||
ret = ERROR_INVALID_FUNCTION;
|
||||
break;
|
||||
}
|
||||
|
||||
// read next block from file
|
||||
|
||||
if (!ReadFile(hFile, buf, VFD_BYTES_PER_SECTOR, &result, NULL) ||
|
||||
result <= 0) {
|
||||
|
||||
ret = GetLastError();
|
||||
|
||||
VFDTRACE(0,
|
||||
("[VFD] Read compressed data - %s.\n",
|
||||
SystemMessage(ret)));
|
||||
break;
|
||||
}
|
||||
|
||||
stream.avail_in = result;
|
||||
stream.next_in = buf;
|
||||
}
|
||||
|
||||
// cleanup the zlib stream
|
||||
|
||||
inflateEnd(&stream);
|
||||
|
||||
// set the return information
|
||||
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
*pBuffer = file_cache;
|
||||
*pLength = uncompressed;
|
||||
}
|
||||
else {
|
||||
LocalFree(file_cache);
|
||||
}
|
||||
|
||||
VFDTRACE(0,
|
||||
("[VFD] VfdExtractImz - OUT\n"));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif // VFD_NO_ZLIB
|
Loading…
Add table
Add a link
Reference in a new issue