00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __FS_IndexFile__
00020 #define __FS_IndexFile__
00021
00022 #include "FS_API.h"
00023 #include <UT/UT_String.h>
00024 #include <UT/UT_PtrArray.h>
00025 #include <UT/UT_SymbolTable.h>
00026 #include "FS_Reader.h"
00027
00028 class UT_Options;
00029 class FS_WriteFilterFactory;
00030 class FS_IStreamFilterFactory;
00031 class UT_OStrStream;
00032
00033 #define FS_SECTION_SEPARATOR '?'
00034 #define FS_SECTION_SEPARATOR_STRING "?"
00035
00036
00037
00038 class FS_API FS_IndexFile
00039 {
00040 public:
00041 FS_IndexFile();
00042 FS_IndexFile(FS_Reader *reader);
00043 FS_IndexFile(const char *source);
00044 virtual ~FS_IndexFile();
00045
00046
00047
00048
00049 bool hasSection(const char *section) const;
00050 int getSectionModTime(const char *section) const;
00051 int getSectionDataSize(const char *section) const;
00052 void readSection(const char *section,
00053 char *buffer) const;
00054 bool readOptionsSection(const char *section,
00055 UT_Options &options) const;
00056 void addSection(const char *section,
00057 const char *filename);
00058 void addSection(const char *section,
00059 UT_OStrStream &os,
00060 int modtime = -1);
00061 void addSection(const char *section,
00062 const char *buffer,
00063 int len, int modtime = -1);
00064 void addSection(const char *section, const FS_IndexFile &file);
00065 void modifySection(const char *section,
00066 const char *buffer,
00067 int len, int modtime = -1);
00068 void removeSection(const char *section);
00069 void mergeIndexFile(const FS_IndexFile &file, bool overwrite);
00070
00071
00072
00073 void moveSections(int first, int last, int offset);
00074
00075
00076 int getModTime() const;
00077
00078
00079 int getFileDataSize() const;
00080
00081
00082
00083 void setFilters(FS_WriteFilterFactory *encrypt_factory,
00084 FS_IStreamFilterFactory *decrypt_factory);
00085
00086
00087 FS_WriteFilterFactory *getEncryptionFilter() const;
00088 FS_IStreamFilterFactory *getDecryptionFilter() const;
00089
00090
00091 FS_Reader *getSectionReader(const char *section) const;
00092
00093
00094 FS_ReaderStream *getSectionStream(const char *section) const;
00095 FS_ReaderStream *getStreamCopy() const;
00096
00097
00098 int getNumSections() const;
00099 const char *getSectionName(int index) const;
00100
00101
00102 const UT_String &getSourceFile() const;
00103
00104
00105 const UT_String &getDescription() const;
00106 void setDescription(const char *description);
00107
00108
00109
00110 int guessStreamSize() const;
00111
00112
00113
00114
00115
00116
00117 virtual void writeFile(ostream &os);
00118
00119
00120
00121 virtual bool expandToDirectory(const char *destdir);
00122 virtual bool collapseFromDirectory(const char *srcdir);
00123
00124
00125 static int getCurrentTime();
00126
00127 protected:
00128 void setModified();
00129
00130 private:
00131 class FS_API FS_Section
00132 {
00133 public:
00134 FS_Section()
00135 : myDataSize(0), mySectionSize(0), myOffset(0), myModTime(0),
00136 mySection(0) { }
00137 ~FS_Section() { if( mySection ) delete []mySection; }
00138
00139 const char *getName() const { return myName; }
00140 void setName(const char *name) { myName.harden(name); }
00141 void adoptName(char *name) { myName.adopt(name); }
00142 void adoptName(UT_String &name) { myName.adopt(name); }
00143 int getDataSize() const { return myDataSize; }
00144 void setDataSize(int length) { myDataSize = length; }
00145 int getSectionSize() const { return mySectionSize; }
00146 void setSectionSize(int length) { mySectionSize = length; }
00147
00148 int getOffset() const { return myOffset; }
00149 void setOffset(int offset) { myOffset = offset; }
00150 int getModTime() const { return myModTime; }
00151 void setModTime(int modtime) { myModTime = modtime; }
00152 char *getSectionBytes() const { return mySection; }
00153 void setSectionBytes(const char *data)
00154 {
00155 if( mySection ) delete []mySection;
00156 mySection = new char[mySectionSize];
00157 memcpy(mySection, data, mySectionSize);
00158 }
00159 void stealData(char *data)
00160 {
00161 if( mySection ) delete []mySection;
00162 mySection = data;
00163 }
00164
00165 private:
00166 UT_String myName;
00167 int myOffset;
00168 int myModTime;
00169 int myDataSize;
00170 int mySectionSize;
00171 char *mySection;
00172 };
00173
00174 typedef UT_PtrArray<FS_Section *> FS_SectionArray;
00175
00176
00177 void openStream() const;
00178 void closeStream() const;
00179
00180
00181 void makeValidFileName(UT_String &filename);
00182 bool writeSectionListFile(const char *sectionfile);
00183
00184
00185
00186
00187 void writeSection(int section_idx, ostream &os);
00188
00189
00190 void readIndex();
00191
00192
00193 int getWriteFilteredSectionSize( int index ) const;
00194
00195
00196 void recalculateFilteredSectionSizes();
00197
00198
00199 mutable FS_Reader *myReader;
00200 FS_SectionArray mySections;
00201 UT_SymbolTable mySectionTable;
00202 UT_String myDescription;
00203 UT_String mySourceFile;
00204 FS_WriteFilterFactory *myWriteFilter;
00205 FS_IStreamFilterFactory *myReadFilter;
00206 int myModTime;
00207 int mySize;
00208 int myStreamStart;
00209 bool myModified;
00210 };
00211
00212 #endif
00213