// 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 ); }
static VFS_Handle TryToOpen( const VFS_String& strFileName, VFS_DWORD dwFlags ) { // Absolute? if( VFS_Util_IsAbsoluteFileName( strFileName ) ) { // Already open? if( GetOpenFiles().find( ToLower( strFileName ) ) != GetOpenFiles().end() ) { IFile* pFile = GetOpenFiles()[ ToLower( strFileName ) ]; pFile->Add(); return ( VFS_Handle )( VFS_DWORD )pFile; } // Exists a Standard File? if( CStdIOFile::Exists( strFileName ) ) return AddAndConvert( CStdIOFile::Open( strFileName, dwFlags ), strFileName ); // Try to open an Archive File. return AddAndConvert( CArchiveFile::Open( strFileName, dwFlags ), strFileName ); } // For each Root Path... for( VFS_RootPathList::iterator iter = GetRootPaths().begin(); iter != GetRootPaths().end(); iter++ ) { VFS_String strAbsoluteFileName = ToLower( WithoutTrailingSeparator( *iter, VFS_TRUE ) + VFS_PATH_SEPARATOR + strFileName ); // Already open? if( GetOpenFiles().find( strAbsoluteFileName ) != GetOpenFiles().end() ) { IFile* pFile = GetOpenFiles()[ strAbsoluteFileName ]; pFile->Add(); return ( VFS_Handle )( VFS_DWORD )pFile; } // Exists a Standard File? if( CStdIOFile::Exists( strAbsoluteFileName ) ) return AddAndConvert( CStdIOFile::Open( strAbsoluteFileName, dwFlags ), strAbsoluteFileName ); // Try to open an Archive File. if( CArchiveFile::Exists( strAbsoluteFileName ) ) return AddAndConvert( CArchiveFile::Open( strAbsoluteFileName, dwFlags ), strAbsoluteFileName ); } SetLastError( VFS_ERROR_NOT_FOUND ); return VFS_INVALID_HANDLE_VALUE; }