示例#1
0
文件: vfdwin.c 项目: layerfsd/Work
//
//	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;
}
示例#2
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;
}