janwas
8667ea74c8
- directoryPosix: replace most methods with boost filesystem (but not all: the latter cannot efficiently enumerate files AND query their size/mtime) - AllocatorChecker: better name for member functions - file: move the File class here - trace: bugfix - io: move UnalignedWriter to write_buffer.cpp (basically the same thing) - vfs: remove unnecessary "vfs" warts from variable names - vfs_tree: VfsFile now stores single Name/Size/MTime fields instead of the FileInfo record (less clunky) - vfs_path: use boost filesystem's version of the basename/extension functions - lf_alloc: remove (no longer necessary, won't be finished - not worth the trouble) - path_util: remove path_foreach_component (replaced by better path traversal logic) and PathPackage (obsoleted by fs::path) ! resource loading code now receives VfsPath as its filename. there is also OsPath (native absolute path) and Path (relative to binaries/data) - tex is now independent of file loading code; it just en/decodes in-memory buffers - wdll_ver: clean up, use smart pointer to simplify bailout code - wsdl: remove nonexistent failure path from calc_gamma (cruised by here because SDL_SetGamme is failing once after a cold boot at work) - wsnd: simplify OpenAL DLL search, use boost::filesystem - wutil: Wow64 redirection is now packaged in a (RAII) class This was SVN commit r5525.
107 lines
2.4 KiB
C++
107 lines
2.4 KiB
C++
/**
|
|
* =========================================================================
|
|
* File : vfs_tree.h
|
|
* Project : 0 A.D.
|
|
* Description : 'tree' of VFS directories and files
|
|
* =========================================================================
|
|
*/
|
|
|
|
// license: GPL; see lib/license.txt
|
|
|
|
#ifndef INCLUDED_VFS_TREE
|
|
#define INCLUDED_VFS_TREE
|
|
|
|
#include "lib/file/file_system.h" // FileInfo
|
|
#include "lib/file/common/file_loader.h" // PIFileLoader
|
|
#include "lib/file/common/real_directory.h" // PRealDirectory
|
|
|
|
class VfsFile
|
|
{
|
|
public:
|
|
VfsFile(const std::string& name, off_t size, time_t mtime, unsigned priority, PIFileLoader provider);
|
|
|
|
const std::string& Name() const
|
|
{
|
|
return m_name;
|
|
}
|
|
|
|
off_t Size() const
|
|
{
|
|
return m_size;
|
|
}
|
|
|
|
time_t MTime() const
|
|
{
|
|
return m_mtime;
|
|
}
|
|
|
|
bool IsSupersededBy(const VfsFile& file) const;
|
|
|
|
void GenerateDescription(char* text, size_t maxChars) const;
|
|
|
|
LibError Load(shared_ptr<u8> buf) const;
|
|
|
|
private:
|
|
std::string m_name;
|
|
off_t m_size;
|
|
time_t m_mtime;
|
|
|
|
unsigned m_priority;
|
|
|
|
PIFileLoader m_loader;
|
|
};
|
|
|
|
|
|
class VfsDirectory
|
|
{
|
|
public:
|
|
VfsDirectory();
|
|
|
|
/**
|
|
* @return address of existing or newly inserted file; remains
|
|
* valid until ClearR is called (i.e. VFS is rebuilt).
|
|
**/
|
|
VfsFile* AddFile(const VfsFile& file);
|
|
|
|
/**
|
|
* @return address of existing or newly inserted subdirectory; remains
|
|
* valid until ClearR is called (i.e. VFS is rebuilt).
|
|
**/
|
|
VfsDirectory* AddSubdirectory(const std::string& name);
|
|
|
|
VfsFile* GetFile(const std::string& name);
|
|
VfsDirectory* GetSubdirectory(const std::string& name);
|
|
|
|
void GetEntries(FileInfos* files, DirectoryNames* subdirectories) const;
|
|
|
|
void DisplayR(unsigned depth) const;
|
|
|
|
void ClearR();
|
|
|
|
void Attach(PRealDirectory realDirectory);
|
|
|
|
PRealDirectory AssociatedDirectory() const
|
|
{
|
|
return m_realDirectory;
|
|
}
|
|
|
|
/**
|
|
* @return whether this directory should be populated from its
|
|
* AssociatedDirectory(). note that calling this is a promise to
|
|
* do so if true is returned -- the flag is immediately reset.
|
|
**/
|
|
bool ShouldPopulate();
|
|
|
|
private:
|
|
typedef std::map<std::string, VfsFile> VfsFiles;
|
|
VfsFiles m_files;
|
|
|
|
typedef std::map<std::string, VfsDirectory> VfsSubdirectories;
|
|
VfsSubdirectories m_subdirectories;
|
|
|
|
PRealDirectory m_realDirectory;
|
|
volatile uintptr_t m_shouldPopulate; // (cpu_CAS can't be used on bool)
|
|
};
|
|
|
|
#endif // #ifndef INCLUDED_VFS_TREE
|