synfig-core  1.0.3
filecontainertemporary.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_FILECONTAINERTEMPORARY_H
26 #define __SYNFIG_FILECONTAINERTEMPORARY_H
27 
28 /* === H E A D E R S ======================================================= */
29 
30 #include <map>
31 #include <ctime>
32 #include <libxml++/libxml++.h>
33 
34 #include "filesystemnative.h"
35 #include "filecontainerzip.h"
36 
37 /* === M A C R O S ========================================================= */
38 
39 /* === T Y P E D E F S ===================================================== */
40 
41 /* === C L A S S E S & S T R U C T S ======================================= */
42 
43 namespace synfig
44 {
45 
47  {
48  private:
49  struct FileInfo
50  {
51  std::string name;
52  std::string tmp_filename;
53  bool is_directory;
54  bool is_removed;
55 
56  std::string name_part_directory;
57  std::string name_part_localname;
58 
59  void split_name();
60 
61  inline FileInfo(): is_directory(false), is_removed(false) { }
62  };
63 
64  typedef std::map< std::string, FileInfo > FileMap;
65 
66  bool is_opened_;
67  FileMap files_;
68  std::string container_filename_;
69  etl::handle< FileContainerZip > container_;
70  etl::handle< FileSystemNative > file_system_;
71 
72  std::string file_;
73  std::string file_tmp_name_;
74  FileSystem::ReadStreamHandle file_read_stream_;
75  FileSystem::WriteStreamHandle file_write_stream_;
76 
77  std::string temporary_filename_base_;
78 
79  static std::string get_xml_node_text(xmlpp::Node *node);
80 
81  public:
83  virtual ~FileContainerTemporary();
84 
85  virtual bool create(const std::string &container_filename);
86  virtual bool open(const std::string &container_filename);
87  bool open_from_history(const std::string &container_filename, FileContainerZip::file_size_t truncate_storage_size = 0);
88  virtual void close();
89  virtual bool is_opened();
90 
91  virtual bool is_file(const std::string &filename);
92  virtual bool is_directory(const std::string &filename);
93 
94  virtual bool directory_create(const std::string &dirname);
95  virtual bool directory_scan(const std::string &dirname, std::list< std::string > &out_files);
96 
97  virtual bool file_remove(const std::string &filename);
98 
99  virtual bool file_open_read(const std::string &filename);
100  virtual bool file_open_write(const std::string &filename);
101  virtual void file_close();
102 
103  virtual bool file_is_opened_for_read();
104  virtual bool file_is_opened_for_write();
105 
106  virtual size_t file_read(void *buffer, size_t size);
107  virtual size_t file_write(const void *buffer, size_t size);
108 
112 
113  const std::string& get_container_filename() const { return container_filename_; }
114  const std::string& get_temporary_filename_base() const { return temporary_filename_base_; }
115 
116  bool save_temporary() const;
117  bool open_temporary(const std::string &filename_base);
118 
119  bool save_changes(const std::string &filename = std::string(), bool as_copy = false);
120  void discard_changes();
121  };
122 
123 }
124 
125 /* === E N D =============================================================== */
126 
127 #endif