Esempio n. 1
0
// Creates a File in the First Root Path.
VFS_Handle VFS_File_Create( const VFS_String& strFileName, VFS_DWORD dwFlags )
{
	// Not initialized yet?
	if( !IsInit() )
	{
		SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
		return VFS_INVALID_HANDLE_VALUE;
	}

	// No Root Paths specified yet?
	if( GetRootPaths().size() == 0 && !VFS_Util_IsAbsoluteFileName( strFileName ) )
	{
		SetLastError( VFS_ERROR_NO_ROOT_PATHS_DEFINED );
		return VFS_INVALID_HANDLE_VALUE;
	}

	// Make it absolute...
	VFS_String strAbsoluteFileName = ToLower( strFileName );
	if( !VFS_Util_IsAbsoluteFileName( strAbsoluteFileName ) )
		strAbsoluteFileName = ToLower( WithoutTrailingSeparator( GetRootPaths()[ 0 ], VFS_TRUE ) + VFS_PATH_SEPARATOR + strFileName );

	// Is such a File already open? Then just resize it.
	if( GetOpenFiles().find( strAbsoluteFileName ) != GetOpenFiles().end() )
	{
		IFile* pFile = GetOpenFiles()[ strAbsoluteFileName ];
		if( !pFile->Resize( 0 ) )
			return VFS_INVALID_HANDLE_VALUE;
		pFile->Add();
		return ( VFS_Handle )( VFS_DWORD )pFile;
	}

    // Try to create and return a StdIO File.	
	return AddAndConvert( CStdIOFile::Create( strAbsoluteFileName, dwFlags ), strAbsoluteFileName );
}
Esempio n. 2
0
// Resize the File.
VFS_BOOL VFS_File_Resize( VFS_Handle hFile, VFS_LONG lSize )
{
	// Not initialized yet?
	if( !IsInit() )
	{
		SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
		return VFS_FALSE;
	}

	// Invalid Handle Value?
	if( hFile == VFS_INVALID_HANDLE_VALUE )
	{
		SetLastError( VFS_ERROR_INVALID_PARAMETER );
		return VFS_FALSE;
	}

	// Get the File Pointer.
	IFile* pFile = ( IFile* )( VFS_DWORD )hFile;

	return pFile->Resize( lSize );
}