コード例 #1
0
static void CreateDir(const char *pPath)
{
	if(!pPath || *pPath == 0)
		return;

	// strip trailing '/'
	((char*)pPath)[MFString_Length(pPath)-1] = 0;

	// the path is empty
	if(*pPath == 0)
		return;

	CreateDir(MFStr_GetFilePath(pPath));

	CreateDirectory(pPath, NULL);
}
コード例 #2
0
bool MFFileNative_CreateDirectory(const char *pPath)
{
	if(!pPath || *pPath == 0)
		return false;

	// strip trailing '/'
	((char*)pPath)[MFString_Length(pPath)-1] = 0;

	// the path is empty
	if(*pPath == 0)
		return false;

	MFFileNative_CreateDirectory(MFStr_GetFilePath(pPath));

	return CreateDirectory(MFString_UFT8AsWChar(pPath), NULL) != 0;
}
コード例 #3
0
int MFFileNative_Open(MFFile *pFile, MFOpenData *pOpenData)
{
	MFCALLSTACK;

	MFDebug_Assert(pOpenData->cbSize == sizeof(MFOpenDataNative), "Incorrect size for MFOpenDataNative structure. Invalid pOpenData.");
	MFOpenDataNative *pNative = (MFOpenDataNative*)pOpenData;

	DWORD access = ((pOpenData->openFlags&MFOF_Read) ? GENERIC_READ : NULL) | ((pOpenData->openFlags&MFOF_Write) ? GENERIC_WRITE : NULL);
	MFDebug_Assert(access, "Neither MFOF_Read nor MFOF_Write specified.");

	const char *pFilename = pNative->pFilename;
#if defined(MF_XBOX) || defined(MF_X360)
	pFilename = FixXBoxFilename(pFilename);
#endif

	if(pOpenData->openFlags & MFOF_CreateDirectory)
		CreateDir(MFStr_GetFilePath(pFilename));

	DWORD create = (pOpenData->openFlags & MFOF_Read) ? ((pOpenData->openFlags & MFOF_Write) ? OPEN_ALWAYS : OPEN_EXISTING) : CREATE_ALWAYS;

	pFile->pFilesysData = CreateFile(pFilename, access, FILE_SHARE_READ, NULL, create, NULL, NULL);

	if(pFile->pFilesysData == INVALID_HANDLE_VALUE)
	{
//		MFDebug_Warn(3, MFStr("Failed to open file '%s'.", pNative->pFilename));
		pFile->pFilesysData = 0;
		return -1;
	}

	pFile->createFlags = pOpenData->openFlags;
	pFile->offset = 0;

	DWORD excess;
	uint32 fileSize = GetFileSize(pFile->pFilesysData, &excess);

	MFDebug_Assert(excess == 0, "Fuji does not support files larger than 4,294,967,295 bytes.");

	pFile->length = fileSize;

#if defined(_DEBUG)
	MFString_Copy(pFile->fileIdentifier, pNative->pFilename);
#endif

	return 0;
}
コード例 #4
0
int MFFileNative_Open(MFFile *pFile, MFOpenData *pOpenData)
{
	MFCALLSTACK;

	MFDebug_Assert(pOpenData->cbSize == sizeof(MFOpenDataNative), "Incorrect size for MFOpenDataNative structure. Invalid pOpenData.");
	MFOpenDataNative *pNative = (MFOpenDataNative*)pOpenData;

	MFDebug_Assert(pOpenData->openFlags & (MFOF_Read|MFOF_Write), "Neither MFOF_Read nor MFOF_Write specified.");
	MFDebug_Assert((pNative->openFlags & (MFOF_Text|MFOF_Binary)) != (MFOF_Text|MFOF_Binary), "MFOF_Text and MFOF_Binary are mutually exclusive.");

	const char *pFilename = pNative->pFilename;
#if defined(MF_XBOX) || defined(MF_X360)
	pFilename = FixXBoxFilename(pFilename);
#endif

	if(pOpenData->openFlags & MFOF_CreateDirectory)
		MFFileNative_CreateDirectory(MFStr_GetFilePath(pFilename));

	DWORD access = 0, create = 0;

	// set the access flags and create mode
	if(pOpenData->openFlags & MFOF_Read)
		access |= GENERIC_READ;
	if(pOpenData->openFlags & (MFOF_Write|MFOF_Append))
	{
		if(pNative->openFlags & MFOF_Append)
			access |= FILE_APPEND_DATA;
		else
			access |= GENERIC_WRITE;

		if(pNative->openFlags & MFOF_Truncate)
			create = CREATE_ALWAYS;
		else
			create = OPEN_ALWAYS;
	}
	else
		create = OPEN_EXISTING;

	pFile->pFilesysData = CreateFile(MFString_UFT8AsWChar(pFilename), access, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, create, FILE_ATTRIBUTE_NORMAL, NULL);

	if(pFile->pFilesysData == INVALID_HANDLE_VALUE)
	{
		pFile->pFilesysData = 0;
		return -1;
	}

	LARGE_INTEGER size;
	if(!GetFileSizeEx(pFile->pFilesysData, &size))
	{
		MFDebug_Warn(2, MFStr("Call: MFFileNative_Open() - Error: Couldn't get size for file '%s'.", pNative->pFilename));
		CloseHandle(pFile->pFilesysData);
		pFile->pFilesysData = 0;
		return -1;
	}

	pFile->createFlags = pOpenData->openFlags;
	pFile->offset = 0;
	pFile->length = size.QuadPart;

	MFString_Copy(pFile->fileIdentifier, pNative->pFilename);

	return 0;
}