예제 #1
0
HANDLE FILECACHE::openfileat(const char* filename, long position)
{
	if(!validfilename(filename)) return INVALID_HANDLE_VALUE;
	
	char realname[BUFSIZ] = "Data Files\\MWSE\\";
	// 2005-02-12  CDC Create the file storage area if it doesn't already exist
	CreateDirectory("Data Files\\MWSE", NULL);
	// 2005-07-01  CDC Allow connection to named pipes one the local machine
	if ( *filename == '|' ) 
	{
		strcpy(realname, "\\\\.\\pipe\\MWSE");
		filename++;
	}

	strncpy(&realname[strlen(realname)], filename,NELEM(realname)-strlen(realname));
	HANDLE result = CreateFile(
		 realname
		,GENERIC_READ|GENERIC_WRITE
		,FILE_SHARE_READ|FILE_SHARE_WRITE
		,NULL
		,OPEN_ALWAYS
		,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN
		,NULL
		);
	if(result != INVALID_HANDLE_VALUE && SetFilePointer(result, position, 0, FILE_BEGIN) < 0)
	{
		CloseHandle(result);
		result = INVALID_HANDLE_VALUE;
	}
	
	return result;
}
예제 #2
0
ibool MVFileDialog::validFilename(const char *filename)
/****************************************************************************
*
* Function:		MVFileDialog::validFilename
* Parameters:	filename	- Filename to check for validity
* Returns:		True if the filename is valid.
*
* Description:	To determine this, we first check if the directory is
*				valid. If the 'fdMustExist' flag is set, then we also check
*				to ensure that the file selected also exists. If any errors
*				occur, we pop up a dialog box to that effect and return
*				false.
*
****************************************************************************/
{
	char	path[PM_MAX_PATH];
	char	drive[PM_MAX_DRIVE];
	char	dir[PM_MAX_PATH];
	char	name[PM_MAX_PATH];
	char	ext[PM_MAX_PATH];
	ibool	invalid;

	PM_splitpath((char*)filename,drive,dir,name,ext);

	if (drive[0] == 0) {
		strcpy(drive,driveSel->getText());
		if (dir[0] == 0)
			strcpy(dir,directory);
		}

	// Check to see that the drive/directory exists

	strcpy(path,drive);		strcat(path,dir);
	int len = strlen(path);
	if (path[len-1] == '\\' || path[len-1] == '/')
		path[--len] = '\0';
#ifndef __UNIX__
	if (path[len-1] == ':')
		invalid = !PM_driveValid((char)toupper(path[len-2]));
	else
#endif
		invalid = !issubdirectory(path) && !isrootdirectory(path);
	if (invalid) {
		MV_messageBox(dc,invalidDriveText,mfError | mfOKButton | mfOKDefault);
		fileLine->select();
		return false;
		}

	// Check that the file exists if required. If the filename has wildcards,
	// then it is valid.

	if (!hasWildcards(filename)) {
		strcat(path,"/");
		if (MVFileDialog::flags & fdMustExist) {
			// Check that the file exists or is a subdirectory
			strcat(path,name);
			strcat(path,ext);
			if (!validfilename(path) && !issubdirectory(path)) {
				MV_messageBox(dc,invalidFileText,mfError | mfOKButton | mfOKDefault);
				fileLine->select();
				fileLine->setText(fileLine->getText());
				return false;
				}
			}
		else {
			// First check to see that the path to the file exists
			if (!issubdirectory(path)) {
				MV_messageBox(dc,invalidFileText,mfError | mfOKButton | mfOKDefault);
				fileLine->select();
				fileLine->setText(fileLine->getText());
				return false;
				}
			}
		}

	return true;
}