// Returns Information about the File associated with the specified File Handle. VFS_BOOL VFS_File_GetInfo( VFS_Handle hFile, VFS_EntityInfo& Info ) { // 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; // Fill the Entity Information Structure. Info.bArchived = pFile->IsArchived(); Info.eType = VFS_FILE; Info.lSize = pFile->GetSize(); Info.strPath = pFile->GetFileName(); return VFS_Util_GetName( Info.strPath, Info.strName ); }
// Close the File. VFS_BOOL VFS_File_Close( VFS_Handle hFile ) { // 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; // Invalid Handle Value? VFS_BOOL bFound = VFS_FALSE; for( FileMap::iterator iter = GetOpenFiles().begin(); iter != GetOpenFiles().end(); iter++ ) { // Found? if( ( *iter ).second == pFile ) { bFound = VFS_TRUE; break; } } if( !bFound ) { SetLastError( VFS_ERROR_INVALID_PARAMETER ); return VFS_FALSE; } // If the File will be deleted afterwards, remove the File from the // Open Files Map. if( pFile->GetRefCount() == 1 ) { FileMap::iterator iter = GetOpenFiles().find( pFile->GetFileName() ); if( iter == GetOpenFiles().end() ) { SetLastError( VFS_ERROR_GENERIC ); return VFS_FALSE; } GetOpenFiles().erase( iter ); } // Release the File. pFile->Release(); return VFS_TRUE; }
// Rename the specified File. VFS_BOOL VFS_File_Rename( const VFS_String& strFrom, const VFS_String& strTo ) // pszTo has to be a single File Name without a Path. { // Not initialized yet? if( !IsInit() ) { SetLastError( VFS_ERROR_NOT_INITIALIZED_YET ); return VFS_FALSE; } // Try to open the file to get the absolute file name and to see if the file is still open // and if it's not in an Archive (VFS_WRITE would fail otherwise). VFS_Handle hFile = VFS_File_Open( strFrom, VFS_READ | VFS_WRITE ); if( hFile == VFS_INVALID_HANDLE_VALUE ) return VFS_FALSE; // Get the File Pointer. IFile* pFile = ( IFile* )( VFS_DWORD )hFile; // Check if there are still references to the File (but count ourself). if( pFile->GetRefCount() > 1 ) { // Close the File. VFS_File_Close( hFile ); SetLastError( VFS_ERROR_IN_USE ); return VFS_FALSE; } // Get the absolute File Name. VFS_String strAbsoluteFileName = pFile->GetFileName(); // Close the File. VFS_File_Close( hFile ); // Make the Target Name absolute. VFS_String strAbsoluteTo; VFS_Util_GetPath( strAbsoluteFileName, strAbsoluteTo ); strAbsoluteTo = WithoutTrailingSeparator( strAbsoluteTo, VFS_TRUE ) + VFS_PATH_SEPARATOR + strTo; // Try to rename the File. if( !VFS_RENAME( strAbsoluteFileName, strAbsoluteTo ) ) { SetLastError( VFS_ERROR_PERMISSION_DENIED ); return VFS_FALSE; } return VFS_TRUE; }
// Delete the File with the specified File Name. VFS_BOOL VFS_File_Delete( const VFS_String& strFileName ) { // Not initialized yet? if( !IsInit() ) { SetLastError( VFS_ERROR_NOT_INITIALIZED_YET ); return VFS_FALSE; } // Try to open the file to get the absolute file name and to see if the file is still open // and if it's not in an Archive (VFS_WRITE would fail otherwise). VFS_Handle hFile = VFS_File_Open( strFileName, VFS_READ | VFS_WRITE ); if( hFile == VFS_INVALID_HANDLE_VALUE ) return VFS_FALSE; // Get the File Pointer. IFile* pFile = ( IFile* )( VFS_DWORD )hFile; // Check if there are still references to the File (but count ourself). if( pFile->GetRefCount() > 1 ) { // Close the File. VFS_File_Close( hFile ); SetLastError( VFS_ERROR_IN_USE ); return VFS_FALSE; } // Get the absolute File Name. VFS_String strAbsoluteFileName = pFile->GetFileName(); // Close the File. VFS_File_Close( hFile ); // Try to delete the File. if( !VFS_UNLINK( strAbsoluteFileName ) ) { SetLastError( VFS_ERROR_PERMISSION_DENIED ); return VFS_FALSE; } return VFS_TRUE; }