Ejemplo n.º 1
0
//
//	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;
}
Ejemplo n.º 2
0
//
//	protect button is clicked
//
void OnProtectClicked(HWND hDlg, HWND hButton)
{
	HANDLE	hDevice;
	DWORD	ret;

	hDevice = VfdOpenDevice(
		GetWindowLong(hDlg, GWL_USERDATA));

	if (hDevice != INVALID_HANDLE_VALUE) {

		if (SendMessage(hButton, BM_GETCHECK, 0, 0) == BST_CHECKED) {
			ret = VfdWriteProtect(hDevice, TRUE);
		}
		else {
			ret = VfdWriteProtect(hDevice, FALSE);
		}

		CloseHandle(hDevice);
	}
	else {
		ret = GetLastError();
	}

	if (ret != ERROR_SUCCESS) {
		AppendLogMessage(ret, MSG_ERR_CHANGE_PROTECT);
	}
}
Ejemplo n.º 3
0
//
//	Close the current image and open the new image
//
void CommandLine()
{
	ULONG			target		= '0';
	PSTR			file_name	= NULL;
	VFD_DISKTYPE	disk_type	= VFD_DISKTYPE_FILE;
	VFD_MEDIA		media_type	= VFD_MEDIA_NONE;
	VFD_FLAGS		image_flags	= 0;
	VFD_FILETYPE	file_type;
	BOOL			five_inch	= FALSE;
	CHAR			protect		= 0;
	BOOL			open_folder	= TRUE;
	BOOL			close_only	= FALSE;
	HANDLE			hDevice;
	CHAR			letter;
	DWORD			driver_state;
	DWORD			ret;

	//
	//	process command line parameters
	//
	while (*(++__argv)) {

		//	Open switch
		if (_stricmp(*__argv, VFD_OPEN_SWITCH) == 0) {
			close_only = FALSE;
		}

		//	Close switch
		else if (_stricmp(*__argv, "/close") == 0) {
			close_only = TRUE;
		}

		//	Quiet mode switch
		else if (stricmp(*__argv, "/q") == 0) {
			open_folder = FALSE;
		}

		//	Disk type options
		else if (_stricmp(*__argv, "/ram") == 0) {
			disk_type = VFD_DISKTYPE_RAM;
		}

		//	Protect options
		else if (_stricmp(*__argv, "/p") == 0 ||
			_stricmp(*__argv, "/w") == 0) {

			protect = (CHAR)toupper(*(*__argv + 1));
		}

		//	media type options
		/*else if (strcmp(*__argv, "/160") == 0) {
			media_type = VFD_MEDIA_F5_160;
		}
		else if (strcmp(*__argv, "/180") == 0) {
			media_type = VFD_MEDIA_F5_180;
		}
		else if (strcmp(*__argv, "/320") == 0) {
			media_type = VFD_MEDIA_F5_320;
		}
		else if (strcmp(*__argv, "/360") == 0) {
			media_type = VFD_MEDIA_F5_360;
		}
		else if (strcmp(*__argv, "/640") == 0) {
			media_type = VFD_MEDIA_F3_640;
		}*/
		else if (strcmp(*__argv, "/720") == 0) {
			media_type = VFD_MEDIA_F3_720;
		}
		/*else if (strcmp(*__argv, "/820") == 0) {
			media_type = VFD_MEDIA_F3_820;
		}
		else if (strcmp(*__argv, "/120") == 0 ||
			strcmp(*__argv, "/1.20") == 0) {
			media_type = VFD_MEDIA_F3_1P2;
		}*/
		else if (strcmp(*__argv, "/144") == 0 ||
			strcmp(*__argv, "/1.44") == 0) {
			media_type = VFD_MEDIA_F3_1P4;
		}
		/*else if (strcmp(*__argv, "/168") == 0 ||
			strcmp(*__argv, "/1.68") == 0) {
			media_type = VFD_MEDIA_F3_1P6;
		}
		else if (strcmp(*__argv, "/172") == 0 ||
			strcmp(*__argv, "/1.72") == 0) {
			media_type = VFD_MEDIA_F3_1P7;
		}
		else if (strcmp(*__argv, "/288") == 0 ||
			strcmp(*__argv, "/2.88") == 0) {
			media_type = VFD_MEDIA_F3_2P8;
		}*/

		//	5.25 inch
		else if (strcmp(*__argv, "/5") == 0 ||
			strcmp(*__argv, "/525") == 0 ||
			strcmp(*__argv, "/5.25") == 0) {
			five_inch = TRUE;
		}

		//	target drive
		else if (isalnum(**__argv) &&
			*(*__argv + 1) == ':' &&
			*(*__argv + 2) == '\0') {

			target = toupper(**__argv);
		}
		else if (**__argv == '*' &&
			*(*__argv + 1) == ':' &&
			*(*__argv + 2) == '\0') {

			target = (ULONG)-1;
		}

		//	image filename
		else if (**__argv != '/') {
			file_name = *__argv;

			if (*file_name == '\"' && *(file_name + strlen(file_name) - 1) == '\"') {

				// remove quote characters if the path is quoted

				*(file_name + strlen(file_name) - 1) = '\0';
				file_name++;
			}
		}

		//	unknown options
		else {
			ShowErrorMessage(0, MSG_ERR_INVALID_PARAM, *__argv);
			return;
		}
	}

	//	check parameter consistency

	if (target == (ULONG)-1 && !close_only) {
		ShowErrorMessage(0, MSG_ERR_INVALID_PARAM, "*:");
		return;
	}

	//	Get the current driver state

	ret = VfdGetDriverState(&driver_state);

	if (ret != ERROR_SUCCESS) {
		ShowErrorMessage(ret, MSG_ERR_APP_INTERNAL);
		return;
	}

	if (close_only && driver_state != SERVICE_RUNNING) {
		//	nothing to do...
		return;
	}

	//	ensure that the driver is running

	if (driver_state == VFD_NOT_INSTALLED) {
		ret = VfdInstallDriver(NULL, SERVICE_DEMAND_START);

		if (ret != ERROR_SUCCESS) {
			ShowErrorMessage(ret, MSG_ERR_DRIVER_INSTALL);
			return;
		}
	}

	//	ensure that the driver is started

	if (driver_state != SERVICE_RUNNING) {
		ret = VfdStartDriver(&driver_state);

		if (ret != ERROR_SUCCESS ||
			driver_state != SERVICE_RUNNING) {
			ShowErrorMessage(ret, MSG_ERR_DRIVER_START);
			return;
		}
	}

	//
	//	close the current image (if any)
	//
	if (target == (ULONG)-1) {
		int i;
		for (i = 0; i < VFD_MAXIMUM_DEVICES; i++) {
			ret = VfdGuiClose(NULL, i);

			if (ret != ERROR_SUCCESS && ret != ERROR_NOT_READY) {
				ShowErrorMessage(ret, MSG_ERR_IMAGE_CLOSE, i + '0');
			}
		}
		return;
	}

	ret = VfdGuiClose(NULL, target);

	if (ret != ERROR_SUCCESS && ret != ERROR_NOT_READY) {
		ShowErrorMessage(ret, MSG_ERR_IMAGE_CLOSE, target);
		return;
	}

	if (close_only) {
		return;
	}

	//
	//	check target image file
	//
	if (file_name) {
		DWORD			file_attr;
		ULONG			image_size;

		ret = VfdCheckImageFile(
			file_name, &file_attr, &file_type, &image_size);

		if (ret == ERROR_FILE_NOT_FOUND) {

			//	If file does not exist, create a new image file

			if (media_type == VFD_MEDIA_NONE) {
				media_type = VFD_MEDIA_F3_1P4;
			}

			ret = VfdCreateImageFile(
				file_name, media_type, VFD_FILETYPE_RAW, FALSE);

			if (ret != ERROR_SUCCESS) {
				ShowErrorMessage(ret, MSG_ERR_FILE_CREATE, file_name);
				return;
			}

			ret = VfdCheckImageFile(
				file_name, &file_attr, &file_type, &image_size);

			if (ret != ERROR_SUCCESS) {
				ShowErrorMessage(ret, MSG_ERR_FILE_OPEN, file_name);
				return;
			}
		}
		else if (ret == ERROR_SUCCESS) {

			//	check file size / media size

			ULONG		media_size;
			VFD_MEDIA	def_media;

			media_size = VfdGetMediaSize(media_type);

			if (media_size > image_size) {

				ShowErrorMessage(0, MSG_ERR_IMAGE_TOO_SMALL);
				return;
			}

			def_media = VfdLookupMedia(image_size);

			if (def_media == VFD_MEDIA_NONE) {

				ShowErrorMessage(0, MSG_ERR_IMAGE_TOO_SMALL);
				return;
			}

			if (media_type == VFD_MEDIA_NONE) {
				media_type = def_media;
			}

			//	check file type

			if (file_type == VFD_FILETYPE_ZIP ||
				(file_attr & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_COMPRESSED | FILE_ATTRIBUTE_ENCRYPTED))) {
				disk_type = VFD_DISKTYPE_RAM;
			}
		}
		else {
			ShowErrorMessage(ret, MSG_ERR_FILE_OPEN, file_name);
			return;
		}

		if (disk_type != VFD_DISKTYPE_FILE) {
			if (protect != 'W') {
				protect = 'P';
			}
		}
	}
	else {
		disk_type = VFD_DISKTYPE_RAM;

		if (media_type == VFD_MEDIA_NONE) {
			media_type = VFD_MEDIA_F3_1P4;
		}
	}

	if (protect == 'P') {
		image_flags |= VFD_FLAG_WRITE_PROTECTED;
	}

	if (five_inch &&
		VfdGetMediaSize(media_type) == VfdGetMediaSize((VFD_MEDIA)(media_type + 1))) {
		media_type = (VFD_MEDIA)(media_type + 1);
	}

	//	Open the target device

	hDevice = VfdOpenDevice(target);

	if (hDevice == INVALID_HANDLE_VALUE) {
		ShowErrorMessage(GetLastError(), MSG_ERR_DEVICE_OPEN, target);
		return;
	}

	//	assign a drive letter if the drive has none

	VfdGetGlobalLink(hDevice, &letter);

	if (!isalpha(letter)) {
		VfdGetLocalLink(hDevice, &letter);
	}

	if (!isalpha(letter)) {
		letter = VfdChooseLetter();
		VfdSetLocalLink(hDevice, letter);
	}

	//	Open the image file

	ret = VfdOpenImage(hDevice, file_name,
		disk_type, media_type, image_flags);

	CloseHandle(hDevice);

	if (ret != ERROR_SUCCESS) {
		ShowErrorMessage(ret, MSG_ERR_FILE_OPEN,
			file_name ? file_name : "<RAM>");
		return;
	}

	//
	//	Unless otherwise specified, open the drive
	//
	if (open_folder && isalpha(letter)) {
		CHAR drive[] = "A:\\";
		CHAR verb[20] = {0};
		LONG size = sizeof(verb);

		drive[0] = (CHAR)toupper(letter);

		//	get the default verb for folder object from the registry
		RegQueryValue(HKEY_CLASSES_ROOT, "Folder\\shell", verb, &size);

		ret = (DWORD)ShellExecute(
			NULL, verb[0] ? verb : NULL, drive, NULL, NULL, SW_SHOWNORMAL);

		if (ret <= 32) {
			VFDTRACE(0, ("OpenImage : ShellExecute - %s",
				GetSystemMessage(GetLastError())));
		}
	}

	return;
}
Ejemplo n.º 4
0
//
//	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);
}
Ejemplo n.º 5
0
//
//	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;
}
Ejemplo n.º 6
0
//
//	OK button is clicked
//
void OnLetterOK(HWND hDlg)
{
	HANDLE	hDevice;
	ULONG	letter;
	BOOL	persistent;
	CHAR	buf[10];
	DWORD	ret = ERROR_SUCCESS;

	//	Get combo box selection

	if (!GetDlgItemText(hDlg, IDC_DRIVE_LETTER, buf, sizeof(buf))) {
		ShowErrorMessage(GetLastError(), MSG_ERR_APP_INTERNAL);
		return;
	}

	//	Get persistent button state

	persistent = (IsDlgButtonChecked(hDlg, IDC_PERSISTENT) == BST_CHECKED);

	//	Get the original drive letter

	letter = GetWindowLong(hDlg, DWL_USER);

	//	Open the VFD drive

	hDevice = VfdOpenDevice(
		GetWindowLong(hDlg, GWL_USERDATA));

	if (hDevice == INVALID_HANDLE_VALUE) {
		ShowErrorMessage(GetLastError(), MSG_ERR_APP_INTERNAL);
		return;
	}

	if (isalpha(LOWORD(letter))) {

		// delete the original drive letter

		if (HIWORD(letter)) {
			ret = VfdSetGlobalLink(hDevice, 0);
		}
		else {
			ret = VfdSetLocalLink(hDevice, 0);
		}
	}

	if (ret == ERROR_SUCCESS && isalpha(buf[0])) {

		//	create a new drive letter

		if (persistent) {
			ret = VfdSetGlobalLink(hDevice, buf[0]);
		}
		else {
			ret = VfdSetLocalLink(hDevice, buf[0]);
		}
	}

	CloseHandle(hDevice);

	if (ret != ERROR_SUCCESS) {
		ShowErrorMessage(GetLastError(), MSG_ERR_APP_INTERNAL);
		return;
	}
}
Ejemplo n.º 7
0
//
//	initialize the drive letter dialog
//
BOOL OnLetterInit(HWND hDlg, ULONG nDevice)
{
	HANDLE	hDevice;
	CHAR	buf[20];
	HWND	hCombo;
	DWORD	logical;
	BOOL	persistent;

	//
	//	setup controls text
	//
	SetControlText(hDlg, 0,					MSG_LETTER_TITLE);
	SetControlText(hDlg, IDC_LETTER_LABEL,	MSG_LETTER_LABEL);
	SetControlText(hDlg, IDC_PERSISTENT,	MSG_PERSISTENT);
	SetControlText(hDlg, IDOK,				MSG_OK_BUTTON);
	SetControlText(hDlg, IDCANCEL,			MSG_CANCEL_BUTTON);

	//
	//	setup the drive letter combo box
	//
	hCombo = GetDlgItem(hDlg, IDC_DRIVE_LETTER);

	if (hCombo == NULL) {
		ShowErrorMessage(GetLastError(), 0);
		return FALSE;
	}

	//	initialize the list

	SendMessage(hCombo, CB_RESETCONTENT, 0, 0);

	//	add <none>

	if (!GetLocalMessage(MSG_GENERIC_NONE, buf, sizeof(buf))) {
		strcpy(buf, "(none)");
	}

	SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)buf);

	//	add unused drive letters

	logical = GetLogicalDrives();

	if (logical == 0) {
		ShowErrorMessage(GetLastError(), 0);
		return FALSE;
	}

	strcpy(buf, "A:");

	while (buf[0] <= 'Z') {
		if (!(logical & 0x01)) {
			SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)buf);
		}

		logical >>= 1;
		buf[0]++;
	}

	SendMessage(hCombo, CB_SETCURSEL, 0, 0);

	//	Get the drive letter of the VFD drive

	hDevice = VfdOpenDevice(nDevice);

	if (hDevice == INVALID_HANDLE_VALUE) {
		ShowErrorMessage(GetLastError(), MSG_ERR_APP_INTERNAL);
		return FALSE;
	}

	persistent = TRUE;

	VfdGetGlobalLink(hDevice, &buf[0]);

	if (!isalpha(buf[0])) {
		if (VfdGetLocalLink(hDevice, &buf[0]) == ERROR_SUCCESS &&
			isalpha(buf[0])) {
			persistent = FALSE;
		}
	}

	CloseHandle(hDevice);

	if (isalpha(buf[0])) {
		SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)buf);
		SendMessage(hCombo, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)buf);
	}

	//	set the persistent button state
	CheckDlgButton(hDlg, IDC_PERSISTENT,
		persistent ? BST_CHECKED : BST_UNCHECKED);

	//	store the device number
	SetWindowLong(hDlg, GWL_USERDATA, nDevice);

	//	store the current drive letter
	SetWindowLong(hDlg, DWL_USER, MAKELONG(buf[0], persistent));

	return TRUE;
}
Ejemplo n.º 8
0
//
//	Refresh the Drive dialog
//
void OnRefreshDialog(HWND hDlg)
{
	DWORD			state;
	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;
	CHAR			letter;
	DWORD			attrib;
	DWORD			ret;

	//	get the driver state

	ret = VfdGetDriverState(&state);

	if (ret != ERROR_SUCCESS) {
		return;
	}

	if (state != SERVICE_RUNNING) {

		//	the driver is not running
		//	clear all information and disable controls

		SetDlgItemText(hDlg, IDC_DRIVE_LETTER, NULL);
		SetDlgItemText(hDlg, IDC_IMAGEFILE, NULL);
		SetDlgItemText(hDlg, IDC_MEDIATYPE, NULL);

		EnableWindow(GetDlgItem(hDlg, IDC_CHANGE),	FALSE);
		EnableWindow(GetDlgItem(hDlg, IDC_OPEN),	FALSE);
		EnableWindow(GetDlgItem(hDlg, IDC_SAVE),	FALSE);
		EnableWindow(GetDlgItem(hDlg, IDC_CLOSE),	FALSE);

		return;
	}

	//	open the device

	hDevice = VfdOpenDevice(GetWindowLong(hDlg, GWL_USERDATA));

	if (hDevice == INVALID_HANDLE_VALUE) {
		AppendLogMessage(GetLastError(), 0);
		return;
	}

	//	get the current drive letter

	VfdGetGlobalLink(hDevice, &letter);

	buf[0] = '\0';

	if (isalpha(letter)) {
		sprintf(buf, "%c (", letter);
		GetLocalMessage(MSG_PERSISTENT, &buf[3], sizeof(buf) - 3);
		strcat(buf, ")");
	}
	else {
		VfdGetLocalLink(hDevice, &letter);

		if (isalpha(letter)) {
			sprintf(buf, "%c (", letter);
			GetLocalMessage(MSG_EPHEMERAL, &buf[3], sizeof(buf) - 3);
			strcat(buf, ")");
		}
	}

	SetDlgItemText(hDlg, IDC_DRIVE_LETTER, buf);
	EnableWindow(GetDlgItem(hDlg, IDC_CHANGE),	TRUE);

	//	get the current image information

	ret = VfdGetImageInfo(hDevice, buf, &disk_type,
		&media_type, &media_flags, &file_type, &image_size);

	CloseHandle(hDevice);

	if (ret != ERROR_SUCCESS) {
		AppendLogMessage(ret, 0);
		return;
	}

	if (media_type == VFD_MEDIA_NONE) {

		//	no media

		SetDlgItemText(hDlg, IDC_IMAGEFILE, NULL);
		SetDlgItemText(hDlg, IDC_DESCRIPTION, NULL);
		SetDlgItemText(hDlg, IDC_MEDIATYPE, NULL);

		EnableWindow(GetDlgItem(hDlg, IDC_OPEN),	TRUE);
		EnableWindow(GetDlgItem(hDlg, IDC_SAVE),	FALSE);
		EnableWindow(GetDlgItem(hDlg, IDC_CLOSE),	FALSE);

		SendMessage(GetDlgItem(hDlg, IDC_OPEN),
			BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);

		return;
	}

	//	set 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>");
		}
		file_type = VFD_FILETYPE_NONE;
		attrib = 0;
	}

	SetDlgItemText(hDlg, IDC_IMAGEFILE, buf);

	//	set description

	VfdMakeFileDesc(buf, sizeof(buf),
		file_type, image_size, attrib);

	SetDlgItemText(hDlg, IDC_DESCRIPTION, buf);

	//	set disk type text

	//	set media type text

	SetDlgItemText(hDlg, IDC_MEDIATYPE,
		VfdMediaTypeName(media_type));

	//	set write protected state

	//
	//	enable / disable appropriate buttons
	//
	EnableWindow(GetDlgItem(hDlg, IDC_OPEN),	FALSE);
	EnableWindow(GetDlgItem(hDlg, IDC_SAVE),	TRUE);
	EnableWindow(GetDlgItem(hDlg, IDC_CLOSE),	TRUE);

	SendMessage(GetDlgItem(hDlg, IDC_CLOSE),
		BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
}