mirror of
https://github.com/1dot13/source.git
synced 2026-09-02 14:36:06 +02:00
*** Merged Code from Multiplayer Branch Revision 2960 ***
- Virtual File System (VFS) by birdflu. This is needed for Multiplayer and is also used for Single Player. Very neat system :-) - Multiplayer Version 1.1 + some additional features and bugfixes * INFO: If you compile a new EXE and want to test, be sure to also use the latest SVN GameDir files in your JA2 install directory * git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@2961 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
#ifndef _VFS_H_
|
||||
#define _VFS_H_
|
||||
|
||||
#include "Interface/vfs_file_interface.h"
|
||||
#include "Interface/vfs_location_interface.h"
|
||||
#include "vfs_vloc.h"
|
||||
#include "vfs_vfile.h"
|
||||
#include "vfs_types.h"
|
||||
#include <map>
|
||||
|
||||
#define USE_VFS
|
||||
|
||||
|
||||
class CFileAllocator
|
||||
{
|
||||
public:
|
||||
static void RegisterAllocator(BasicAllocator* allocator);
|
||||
|
||||
static void Clear();
|
||||
private:
|
||||
static std::vector<BasicAllocator*> _valloc;
|
||||
};
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class CProfileStack;
|
||||
|
||||
class CVirtualFileSystem
|
||||
{
|
||||
typedef std::map<vfs::Path,CVirtualLocation*,vfs::Path::Less> tVFS;
|
||||
public:
|
||||
/*****************************************************/
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
//////////////////////////////
|
||||
class IImplemetation
|
||||
{
|
||||
public:
|
||||
virtual ~IImplemetation() {};
|
||||
virtual vfs::tReadableFile* value() = 0;
|
||||
virtual void next() = 0;
|
||||
};
|
||||
//////////////////////////////
|
||||
private:
|
||||
friend class CVirtualFileSystem;
|
||||
Iterator(IImplemetation* impl);
|
||||
public:
|
||||
Iterator();
|
||||
~Iterator();
|
||||
|
||||
vfs::tReadableFile* value();
|
||||
void next();
|
||||
bool end();
|
||||
private:
|
||||
IImplemetation* _iter_impl;
|
||||
vfs::tReadableFile* _file;
|
||||
};
|
||||
/*****************************************************/
|
||||
class CRegularIterator : public vfs::CVirtualFileSystem::Iterator::IImplemetation
|
||||
{
|
||||
public:
|
||||
CRegularIterator(vfs::CVirtualFileSystem& rVFS);
|
||||
virtual ~CRegularIterator();
|
||||
|
||||
virtual vfs::tReadableFile* value();
|
||||
virtual void next();
|
||||
private:
|
||||
vfs::CVirtualFileSystem& m_rVFS;
|
||||
vfs::CVirtualFileSystem::tVFS::iterator _vloc_iter;
|
||||
CVirtualLocation::Iterator _vfile_iter;
|
||||
};
|
||||
/*****************************************************/
|
||||
class CMatchingIterator : public vfs::CVirtualFileSystem::Iterator::IImplemetation
|
||||
{
|
||||
public:
|
||||
CMatchingIterator(vfs::Path const& sPattern, vfs::CVirtualFileSystem& rVFS);
|
||||
virtual ~CMatchingIterator();
|
||||
|
||||
virtual vfs::tReadableFile* value();
|
||||
virtual void next();
|
||||
private:
|
||||
bool nextLocationMatch();
|
||||
bool nextFileMatch();
|
||||
private:
|
||||
vfs::Path m_sLocPattern, m_sFilePattern;
|
||||
vfs::CVirtualFileSystem& m_rVFS;
|
||||
vfs::CVirtualFileSystem::tVFS::iterator _vloc_iter;
|
||||
CVirtualLocation::Iterator _vfile_iter;
|
||||
};
|
||||
/*****************************************************/
|
||||
public:
|
||||
~CVirtualFileSystem();
|
||||
|
||||
static CVirtualFileSystem* GetVFS();
|
||||
static void ShutdownVFS();
|
||||
|
||||
CProfileStack* GetProfileStack();
|
||||
|
||||
vfs::CVirtualLocation* GetVirtualLocation(vfs::Path const& sPath, bool bCreate = false);
|
||||
bool AddLocation(vfs::IBaseLocation* pLocation,
|
||||
utf8string const& sProfileName,
|
||||
bool bIsWriteable = false);
|
||||
|
||||
bool FileExists(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
bool FileExists(vfs::Path const& rLocalFilePath, std::string const& sProfileName);
|
||||
|
||||
vfs::IBaseFile* GetFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
vfs::IBaseFile* GetFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName);
|
||||
|
||||
vfs::tReadableFile* GetRFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
vfs::tReadableFile* GetRFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName);
|
||||
|
||||
vfs::tWriteableFile* GetWFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
vfs::tWriteableFile* GetWFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName);
|
||||
|
||||
bool RemoveFileFromFS(vfs::Path const& sFilePath);
|
||||
bool RemoveDirectoryFromFS(vfs::Path const& sDir);
|
||||
bool CreateNewFile(vfs::Path const& sFileName);
|
||||
|
||||
Iterator begin();
|
||||
Iterator begin(vfs::Path const& sPattern);
|
||||
private:
|
||||
CProfileStack m_oProfileStack;
|
||||
tVFS m_mapFS;
|
||||
private:
|
||||
CVirtualFileSystem();
|
||||
static CVirtualFileSystem* m_pSingleton;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
vfs::CVirtualFileSystem* GetVFS();
|
||||
|
||||
#endif // _VFS_H_
|
||||
Reference in New Issue
Block a user