synfig-core  1.0.3
filecontainerzip.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
21 /* ========================================================================= */
22 
23 /* === S T A R T =========================================================== */
24 
25 #ifndef __SYNFIG_FILECONTAINERZIP_H
26 #define __SYNFIG_FILECONTAINERZIP_H
27 
28 /* === H E A D E R S ======================================================= */
29 
30 #include <map>
31 #include <ctime>
32 #include "filecontainer.h"
33 
34 /* === M A C R O S ========================================================= */
35 
36 /* === T Y P E D E F S ===================================================== */
37 
38 /* === C L A S S E S & S T R U C T S ======================================= */
39 
40 namespace synfig
41 {
42 
44  {
45  public:
47  {
48  protected:
49  friend class FileContainerZip;
51  public:
52  virtual ~WholeZipReadStream();
53  virtual size_t read(void *buffer, size_t size);
54  };
55 
56  typedef long long int file_size_t;
57 
58  struct HistoryRecord {
63  };
64 
65  private:
66  struct FileInfo
67  {
68  std::string name;
69  bool is_directory;
70  bool directory_saved;
71  file_size_t size;
72  file_size_t header_offset;
73  unsigned int crc32;
74  time_t time;
75 
76  std::string name_part_directory;
77  std::string name_part_localname;
78 
79  void split_name();
80 
81  inline FileInfo():
82  is_directory(false), directory_saved(false),
83  size(0), header_offset(0), crc32(0), time(0) { }
84  };
85 
86  typedef std::map< std::string, FileInfo > FileMap;
87 
88  FILE *storage_file_;
89  FileMap files_;
90  file_size_t prev_storage_size_;
91  bool file_reading_whole_container_;
92  bool file_reading_;
93  bool file_writing_;
94  FileMap::iterator file_;
95  file_size_t file_processed_size_;
96  bool changed_;
97 
98  static unsigned int crc32(unsigned int previous_crc, const void *buffer, size_t size);
99  static std::string encode_history(const HistoryRecord &history_record);
100  static HistoryRecord decode_history(const std::string &comment);
101  static void read_history(std::list<HistoryRecord> &list, FILE *f, file_size_t size);
102 
103  public:
105  virtual ~FileContainerZip();
106 
107  virtual bool create(const std::string &container_filename);
108  virtual bool open(const std::string &container_filename);
109  bool open_from_history(const std::string &container_filename, file_size_t truncate_storage_size = 0);
110  virtual void close();
111  virtual bool is_opened();
112  bool save();
113 
114  static std::list<HistoryRecord> read_history(const std::string &container_filename);
115 
116  virtual bool is_file(const std::string &filename);
117  virtual bool is_directory(const std::string &filename);
118 
119  bool directory_check_name(const std::string &dirname);
120  virtual bool directory_create(const std::string &dirname);
121  virtual bool directory_scan(const std::string &dirname, std::list< std::string > &out_files);
122 
123  virtual bool file_remove(const std::string &filename);
124 
125  bool file_check_name(const std::string &filename);
126  virtual bool file_open_read_whole_container();
127  virtual bool file_open_read(const std::string &filename);
128  virtual bool file_open_write(const std::string &filename);
129  virtual void file_close();
130 
131  virtual bool file_is_opened_for_read();
132  virtual bool file_is_opened_for_write();
133 
134  virtual size_t file_read(void *buffer, size_t size);
135  virtual size_t file_write(const void *buffer, size_t size);
136  };
137 
138 }
139 
140 /* === E N D =============================================================== */
141 
142 #endif