TDME2  1.9.200
ArchiveFileSystem.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <fstream>
4 #include <map>
5 #include <string>
6 #include <vector>
7 
8 #include <tdme/tdme.h>
13 
14 using std::ifstream;
15 using std::map;
16 using std::string;
17 using std::vector;
18 
22 
23 /**
24  * Archive file system implementation
25  * @author Andreas Drewke
26  */
28 {
29 private:
30  struct FileInformation {
31  string name;
32  uint64_t bytes;
33  uint8_t compressed;
34  uint64_t bytesCompressed;
35  uint64_t offset;
36  bool executable;
37  };
38  string fileName;
40  ifstream ifs;
41  map<string, FileInformation> fileInformations;
42 
43  /**
44  * Decompress from archive
45  * @param inContent compressed content
46  * @param outContent uncompressed out content
47  * @throws tdme::os::filesystem::FileSystemException
48  */
49  void decompress(vector<uint8_t>& inContent, vector<uint8_t>& outContent);
50 
51 public:
52  // forbid class copy
54 
55  /**
56  * Public constructor
57  * @param fileName archive file name
58  */
59  ArchiveFileSystem(const string& fileName = "archive.ta");
60 
61  /**
62  * Public destructor
63  */
64  virtual ~ArchiveFileSystem();
65 
66  /**
67  * @return Returns underlying TDME2 archive file name
68  */
69  const string& getArchiveFileName();
70 
71  // overridden methods
72  // overridden methods
73  const string composeURI(const string& pathName, const string& fileName);
74  uint64_t getFileSize(const string& pathName, const string& fileName);
75  const string getContentAsString(const string& pathName, const string& fileName);
76  void setContentFromString(const string& pathName, const string& fileName, const string& content);
77  void getContent(const string& pathName, const string& fileName, vector<uint8_t>& content);
78  void setContent(const string& pathName, const string& fileName, const vector<uint8_t>& content);
79  void getContentAsStringArray(const string& pathName, const string& fileName, vector<string>& content);
80  void setContentFromStringArray(const string& pathName, const string& fileName, const vector<string>& content);
81  void list(const string& pathName, vector<string>& files, FileNameFilter* filter = nullptr, bool addDrives = false);
82  bool isPath(const string& uri);
83  bool isDrive(const string& uri);
84  bool exists(const string& uri);
85  bool isExecutable(const string& pathName, const string& fileName) override;
86  void setExecutable(const string& pathName, const string& fileName) override;
87  const string getCanonicalURI(const string& pathName, const string& fileName);
88  const string getCurrentWorkingPathName();
89  void changePath(const string& pathName);
90  const string getPathName(const string& uri);
91  const string getFileName(const string& uri);
92  const string removeFileExtension(const string& fileName);
93  void createPath(const string& pathName);
94  void removePath(const string& pathName, bool recursive);
95  void removeFile(const string& pathName, const string& fileName);
96  void rename(const string& fileNameFrom, const string& fileNameTo);
97  bool getThumbnailAttachment(const string& pathName, const string& fileName, vector<uint8_t>& thumbnailAttachmentContent);
98  bool getThumbnailAttachment(const vector<uint8_t>& content, vector<uint8_t>& thumbnailAttachmentContent);
99 
100  /**
101  * Compute SHA256 hash
102  */
103  const string computeSHA256Hash();
104 };
Archive file system implementation.
const string removeFileExtension(const string &fileName)
Remove file extension, e.g.
bool isDrive(const string &uri)
Check if file is a drive (applies to Microsoft Windows only)
map< string, FileInformation > fileInformations
void setContentFromString(const string &pathName, const string &fileName, const string &content)
Set content from string.
ArchiveFileSystem(const string &fileName="archive.ta")
Public constructor.
virtual ~ArchiveFileSystem()
Public destructor.
const string composeURI(const string &pathName, const string &fileName)
Compose URI from path name and file name.
const string getPathName(const string &uri)
Get path name.
const string getCanonicalURI(const string &pathName, const string &fileName)
Get canonical URI from given path name and file name.
void createPath(const string &pathName)
Create path.
bool getThumbnailAttachment(const string &pathName, const string &fileName, vector< uint8_t > &thumbnailAttachmentContent)
Reads a thumbnail attachment from binary file.
void decompress(vector< uint8_t > &inContent, vector< uint8_t > &outContent)
Decompress from archive.
void list(const string &pathName, vector< string > &files, FileNameFilter *filter=nullptr, bool addDrives=false)
List files for given path and filter by a file name filter if not null.
void changePath(const string &pathName)
Change path.
void removePath(const string &pathName, bool recursive)
Remove path.
void setExecutable(const string &pathName, const string &fileName) override
Set up file to be an executable file.
void setContent(const string &pathName, const string &fileName, const vector< uint8_t > &content)
Set file content.
void getContent(const string &pathName, const string &fileName, vector< uint8_t > &content)
Get file content.
void setContentFromStringArray(const string &pathName, const string &fileName, const vector< string > &content)
Set file content as string array.
const string computeSHA256Hash()
Compute SHA256 hash.
void removeFile(const string &pathName, const string &fileName)
Remove file.
uint64_t getFileSize(const string &pathName, const string &fileName)
Return file size of given file.
void getContentAsStringArray(const string &pathName, const string &fileName, vector< string > &content)
Get file content as string array.
const string getFileName(const string &uri)
Get file name.
bool isPath(const string &uri)
Check if file is a path.
bool exists(const string &uri)
Check if file exists.
const string getCurrentWorkingPathName()
Get current working path name.
bool isExecutable(const string &pathName, const string &fileName) override
Returns if file is a executable file.
const string getContentAsString(const string &pathName, const string &fileName)
Get content as string.
void rename(const string &fileNameFrom, const string &fileNameTo)
Rename file.
Mutex implementation.
Definition: Mutex.h:19
File system file name filter interface.
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6