//****************************************************************************
//**
//**    VFS_MAIN.H
//**    Header - Virtual File System
//**
//**	Project:	WSFLib
//**	Component:	VFS
//**    Author:		Michael Walter
//**
//**	History:
//**		18.06.2001		Created (Michael Walter)
//****************************************************************************
#ifndef __VFS_MAIN_H__
#define __VFS_MAIN_H__

//============================================================================
//    INTERFACE REQUIRED HEADERS
//============================================================================
#include <wsf.h>

//============================================================================
//    INTERFACE DEFINITIONS / ENUMERATIONS / SIMPLE TYPEDEFS
//============================================================================
// The current Version.
#define VFS_VERSION				0x0100
#define VFS_PATH_SEPARATOR		'\\'

// Invalid Handle.
#define VFS_INVALID_HANDLE		( ( DWORD ) -1 )

// A Filter Procedure.
typedef BOOL ( *VFS_FilterProc )( LPCBYTE pIn, DWORD dwInCount, LPBYTE* ppOut, DWORD* pOutCount );

// The VFS_File_Open/Create() Flags.
#define VFS_READ				0x01
#define VFS_WRITE				0x02

// The VFS_File_Seek() Flags.
#define VFS_SET					0x00
#define VFS_CURRENT				0x01
#define VFS_END					0x02

// A List of Filter Names.
typedef vector< struct VFS_Filter* > VFS_FilterList;
typedef vector< string > VFS_FilterNameList;
typedef vector< string > VFS_RootPathList;

//============================================================================
//    INTERFACE COMPONENT HEADERS
//============================================================================
//============================================================================
//    INTERFACE CLASS PROTOTYPES / EXTERNAL CLASS REFERENCES
//============================================================================
//============================================================================
//    INTERFACE STRUCTURES / UTILITY CLASSES
//============================================================================
// A Filter for the VFS.
struct VFS_Filter
{
	// The Filter's Name.
	string strName;

	// The Filter's Description.
	string strDescription;

	// The Filter's Procedures.
	VFS_FilterProc pfnEncodeProc;
	VFS_FilterProc pfnDecodeProc;
};

// Information about a VFS Entity.
struct VFS_EntityInfo
{
	// Is the Entity a Directory ?
	BOOL bIsDir;

	// Is the Entity archived ?
	BOOL bArchived;

	// The complete Path and the Name.
	string strPath;
	string strName;

	// The Size ( 0 for Directories ).
	DWORD dwSize;
};

//============================================================================
//    INTERFACE DATA DECLARATIONS
//============================================================================
//============================================================================
//    INTERFACE FUNCTION PROTOTYPES
//============================================================================
// Basic VFS Interface.
// Initialize / Shutdown the VFS.
BOOL VFS_Init();
BOOL VFS_Shutdown();

// Register / Unregister a Filter.
BOOL VFS_RegisterFilter( VFS_Filter* pFilter );
BOOL VFS_UnregisterFilter( VFS_Filter* pFilter );
BOOL VFS_UnregisterFilter( DWORD dwIndex );
DWORD VFS_GetNumFilters();
const VFS_Filter* VFS_GetFilter( DWORD dwIndex );
VFS_FilterList VFS_GetFilters();
VFS_FilterNameList VFS_GetFilterNames();

// Root Path Handling.
BOOL VFS_AddRootPath( LPCTSTR pszRootPath );
BOOL VFS_RemoveRootPath( LPCTSTR pszRootPath );
BOOL VFS_RemoveRootPath( DWORD dwIndex );
DWORD VFS_GetNumRootPaths();
LPCTSTR VFS_GetRootPath( DWORD dwIndex );
VFS_RootPathList VFS_GetRootPaths();

// Flush the VFS (close all unused Archives etc).
BOOL VFS_Flush();

// Information.
BOOL VFS_Exists( LPCTSTR pszPath );
BOOL VFS_GetEntityInfo( LPCTSTR pszPath, VFS_EntityInfo* pInfo );
DWORD VFS_GetVersion();

// The File Interface.
// Create / Open / Close a File.
DWORD VFS_File_Create( LPCTSTR pszFile, DWORD dwFlags );
DWORD VFS_File_Open( LPCTSTR pszFile, DWORD dwFlags );
BOOL VFS_File_Close( DWORD dwHandle );

// Read / Write from / to the File.
BOOL VFS_File_Read( DWORD dwHandle, LPBYTE pBuffer, DWORD dwToRead, DWORD* pRead = NULL );
BOOL VFS_File_Write( DWORD dwHandle, LPCBYTE pBuffer, DWORD dwToWrite, DWORD* pWritten = NULL );

// Direct Data Access.
LPCBYTE VFS_File_GetData( DWORD dwHandle );

// Positioning.
BOOL VFS_File_Seek( DWORD dwHandle, LONG dwPos, DWORD dwOrigin = VFS_SET );
LONG VFS_File_Tell( DWORD dwHandle );
DWORD VFS_File_GetSize( DWORD dwHandle );

// Information.
BOOL VFS_File_Exists( LPCTSTR pszFile );
BOOL VFS_File_GetInfo( LPCTSTR pszFile, VFS_EntityInfo* pInfo );
BOOL VFS_File_GetInfo( DWORD dwHandle, VFS_EntityInfo* pInfo );

// The Archive Interface.
// Create / Open / Close an Archive.
DWORD VFS_Archive_Create( LPCTSTR pszArchive, const VFS_FilterNameList& Filters, DWORD dwFlags );
DWORD VFS_Archive_CreateFromDirectory( LPCTSTR pszArchive, LPCTSTR pszSrcDir,
									   const VFS_FilterNameList& Filters, DWORD dwFlags );
DWORD VFS_Archive_Open( LPCTSTR pszArchive, DWORD dwFlags );
BOOL VFS_Archive_Close( DWORD dwHandle );

// Set the Filters used by this Archive.
BOOL VFS_Archive_SetUsedFilters( DWORD dwHandle, const VFS_FilterNameList& Filters );
BOOL VFS_Archive_GetUsedFilters( DWORD dwHandle, VFS_FilterNameList& Filters );

// Add / Remove Files to / from the Archive.
BOOL VFS_Archive_AddFile( DWORD dwHandle, LPCTSTR pszFile );
BOOL VFS_Archive_RemoveFile( DWORD dwHandle, LPCTSTR pszFile );

// Extract the Archive.
BOOL VFS_Archive_Extract( DWORD dwHandle, LPCTSTR pszTarget );

// Information.
BOOL VFS_Archive_GetInfo( DWORD dwHandle, VFS_EntityInfo* pInfo );
BOOL VFS_Archive_GetInfo( LPCTSTR pszArchive, VFS_EntityInfo* pInfo );

// Flush the Archive System.
BOOL VFS_Archive_Flush();

// The Directory Interface.
// Information.
BOOL VFS_Dir_Exists( LPCTSTR pszDir );
BOOL VFS_Dir_GetInfo( LPCTSTR pszDir, VFS_EntityInfo* pInfo );

// Get the Contents of a Directory.
vector< VFS_EntityInfo > VFS_Dir_GetContents( LPCTSTR pszDir, BOOL bRecursive = FALSE );

//============================================================================
//    INTERFACE OBJECT CLASS DEFINITIONS
//============================================================================
//============================================================================
//    INTERFACE TRAILING HEADERS
//============================================================================

#endif // __VFS_MAIN_H__
