00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 #ifndef FILESYSTEM_H
00022 #define FILESYSTEM_H
00023 
00024 #include <fstream>
00025 #include <string>
00026 #include <map>
00027 #include <list>
00028 
00029 #include "IDataSource.h"
00030 #include "ODataSource.h"
00031 
00032 class FileSystem
00033 {
00034  public:
00036         FileSystem(bool noforcedvpaths = false);
00037         ~FileSystem();
00038 
00040         void initBuiltinData(bool allowoverride);
00041 
00042         static FileSystem* get_instance() { return filesystem; }
00043 
00048         IDataSource *ReadFile(const std::string &vfn, bool is_text=false);
00049 
00054         ODataSource *WriteFile(const std::string &vfn, bool is_text=false);
00055 
00062         bool AddVirtualPath(const std::string &vpath, const std::string &realpath,
00063                                                 bool create=false);
00064 
00066         bool RemoveVirtualPath(const std::string &vpath);
00067 
00071         int MkDir(const std::string& path); 
00072 
00073         typedef std::list<std::string> FileList;
00074 
00079         int ListFiles(const std::string mask, FileList& files);
00080 
00081  private:
00082         void switch_slashes(std::string &name);
00083         bool base_to_uppercase(std::string& str, int count);
00084 
00085         bool rawopen
00086         (
00087         std::ifstream& in,                      
00088         const std::string &fname,       
00089         bool is_text = false            
00090         );
00091                 
00092         bool rawopen
00093         (
00094         std::ofstream& out,                     
00095         const std::string &fname,       
00096         bool is_text = false            
00097         );
00098         
00099         bool IsDir(const std::string& path);
00100 
00101         static FileSystem* filesystem;
00102 
00103         
00104         
00105         bool    noforcedvpaths;
00106 
00107         
00108         bool    allowdataoverride;
00109 
00110         
00111         
00112         bool rewrite_virtual_path(std::string& vfn);
00113 
00114         std::map<std::string, std::string> virtualpaths;
00115 
00118         IDataSource* checkBuiltinData(const std::string& vfn, bool is_text=false);
00119 
00120         struct MemoryFile
00121         {
00122                 MemoryFile(const uint8* _data, const uint32 _len)
00123                         : data(_data), len(_len) { } 
00124                 const uint8             *data;
00125                 const uint32    len;
00126         };
00127         std::map<std::string, MemoryFile*> memoryfiles; 
00128 
00129 };
00130 
00131 
00132 
00133 #endif