00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef DOWNLOADDB_H
00019 #define DOWNLOADDB_H
00020
00021 #include "pandabase.h"
00022 #include "notify.h"
00023 #include "filename.h"
00024 #include "multifile.h"
00025 #include "datagram.h"
00026 #include "datagramIterator.h"
00027
00028 #include "pvector.h"
00029 #include "pointerTo.h"
00030 #include "pmap.h"
00031
00032 #include "hashVal.h"
00033 #include "buffer.h"
00034
00035
00036
00037 // Database Format
00038
00039 magic_number
00040 number_of_multifiles
00041 header_length multifile_name phase version size status num_files
00042 header_length file_name version hash
00043 header_length file_name version hash
00044 header_length multifile_name phase version size status num_files
00045 header_length file_name version hash
00046 header_length file_name version hash
00047 ...
00048 ...
00049
00050
00051 A Db is a Vector<MultifileRecord>
00052 MultifileRecord is a Vector<FileRecord>
00053 */
00054
00055 typedef float Phase;
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 class EXPCL_PANDAEXPRESS DownloadDb {
00069 PUBLISHED:
00070
00071
00072
00073
00074 enum Status {
00075 Status_incomplete = 0,
00076 Status_complete = 1,
00077 Status_decompressed = 2,
00078 Status_extracted = 3
00079 };
00080
00081 DownloadDb(void);
00082 DownloadDb(Ramfile &server_file, Filename &client_file);
00083 DownloadDb(Filename &server_file, Filename &client_file);
00084 ~DownloadDb(void);
00085
00086 void output(ostream &out) const;
00087 void write(ostream &out) const;
00088 void write_version_map(ostream &out) const;
00089
00090
00091 bool write_client_db(Filename &file);
00092 bool write_server_db(Filename &file);
00093
00094 INLINE int get_client_num_multifiles(void) const;
00095 INLINE int get_server_num_multifiles(void) const;
00096
00097 INLINE string get_client_multifile_name(int index) const;
00098 INLINE string get_server_multifile_name(int index) const;
00099
00100 INLINE int get_client_multifile_size(string mfname) const;
00101 INLINE void set_client_multifile_size(string mfname, int size);
00102 INLINE int set_client_multifile_delta_size(string mfname, int size);
00103 INLINE int get_server_multifile_size(string mfname) const;
00104 INLINE void set_server_multifile_size(string mfname, int size);
00105
00106 INLINE Phase get_client_multifile_phase(string mfname) const;
00107 INLINE Phase get_server_multifile_phase(string mfname) const;
00108
00109 INLINE void set_client_multifile_incomplete(string mfname);
00110 INLINE void set_client_multifile_complete(string mfname);
00111 INLINE void set_client_multifile_decompressed(string mfname);
00112 INLINE void set_client_multifile_extracted(string mfname);
00113
00114 INLINE int get_server_num_files(string mfname) const;
00115 INLINE string get_server_file_name(string mfname, int index) const;
00116
00117
00118 bool client_multifile_exists(string mfname) const;
00119 bool client_multifile_complete(string mfname) const;
00120 bool client_multifile_decompressed(string mfname) const;
00121 bool client_multifile_extracted(string mfname) const;
00122
00123
00124 HashVal get_client_multifile_hash(string mfname) const;
00125 void set_client_multifile_hash(string mfname, HashVal val);
00126 HashVal get_server_multifile_hash(string mfname) const;
00127 void set_server_multifile_hash(string mfname, HashVal val);
00128
00129
00130 void delete_client_multifile(string mfname);
00131 void add_client_multifile(string server_mfname);
00132 void expand_client_multifile(string mfname);
00133
00134
00135 void create_new_server_db();
00136 void server_add_multifile(string mfname, Phase phase, int size, int status);
00137 void server_add_file(string mfname, string fname);
00138
00139 public:
00140
00141 class EXPCL_PANDAEXPRESS FileRecord : public ReferenceCount {
00142 public:
00143 FileRecord(void);
00144 FileRecord(string name);
00145 void write(ostream &out) const;
00146 string _name;
00147 };
00148
00149 typedef pvector< PT(FileRecord) > FileRecords;
00150
00151 class EXPCL_PANDAEXPRESS MultifileRecord : public ReferenceCount {
00152 public:
00153 MultifileRecord(void);
00154 MultifileRecord(string name, Phase phase, int size, int status);
00155 void write(ostream &out) const;
00156 int get_num_files(void) const;
00157 string get_file_name(int index) const;
00158 bool file_exists(string fname) const;
00159 PT(FileRecord) get_file_record_named(string fname) const;
00160 void add_file_record(PT(FileRecord) fr);
00161 string _name;
00162 Phase _phase;
00163 int _size;
00164 int _status;
00165 HashVal _hash;
00166 PN_int32 _num_files;
00167 FileRecords _file_records;
00168 };
00169
00170 typedef pvector< PT(MultifileRecord) > MultifileRecords;
00171
00172 class EXPCL_PANDAEXPRESS Db {
00173 public:
00174 Db(void);
00175 void write(ostream &out) const;
00176 int get_num_multifiles(void) const;
00177 string get_multifile_name(int index) const;
00178 bool multifile_exists(string mfname) const;
00179 PT(MultifileRecord) get_multifile_record_named(string mfname) const;
00180 void add_multifile_record(PT(MultifileRecord) mfr);
00181 int parse_header(uchar *start, int size);
00182 int parse_record_header(uchar *start, int size);
00183 PT(MultifileRecord) parse_mfr(uchar *start, int size);
00184 PT(FileRecord) parse_fr(uchar *start, int size);
00185 bool read(istream &read_stream, bool want_server_info);
00186 bool write(ofstream &write_stream, bool want_server_info);
00187 Filename _filename;
00188 MultifileRecords _mfile_records;
00189 bool write_header(ofstream &write_stream);
00190 bool write_bogus_header(ofstream &write_stream);
00191 private:
00192 PN_int32 _header_length;
00193
00194
00195 Datagram _datagram;
00196
00197 };
00198
00199 PUBLISHED:
00200 Db read_db(Filename &file, bool want_server_info);
00201 Db read_db(Ramfile &file, bool want_server_info);
00202 bool write_db(Filename &file, Db db, bool want_server_info);
00203
00204 public:
00205
00206
00207 Db _client_db;
00208 Db _server_db;
00209
00210
00211 static PN_uint32 _magic_number;
00212 static PN_uint32 _bogus_magic_number;
00213 typedef pvector<HashVal> VectorHash;
00214 typedef pmap<Filename, VectorHash> VersionMap;
00215
00216 PUBLISHED:
00217 void add_version(const Filename &name, const HashVal &hash, int version);
00218 void insert_new_version(const Filename &name, const HashVal &hash);
00219 bool has_version(const Filename &name) const;
00220 int get_num_versions(const Filename &name) const;
00221 void set_num_versions(const Filename &name, int num_versions);
00222
00223 int get_version(const Filename &name, const HashVal &hash) const;
00224 const HashVal &get_hash(const Filename &name, int version) const;
00225
00226 protected:
00227 void write_version_map(ofstream &write_stream);
00228 bool read_version_map(istream &read_stream);
00229 VersionMap _versions;
00230 Datagram _master_datagram;
00231 };
00232
00233 INLINE ostream &operator << (ostream &out, const DownloadDb &dldb) {
00234 dldb.output(out);
00235 return out;
00236 }
00237
00238
00239 #include "downloadDb.I"
00240
00241 #endif