00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef PATCHFILE_H
00019 #define PATCHFILE_H
00020
00021
00022
00023
00024 #include <pandabase.h>
00025
00026 #include "typedef.h"
00027 #include <notify.h>
00028 #include <filename.h>
00029 #include "plist.h"
00030 #include "datagram.h"
00031 #include "datagramIterator.h"
00032 #include "buffer.h"
00033 #include "pointerTo.h"
00034 #include "hashVal.h"
00035
00036 #include <algorithm>
00037
00038
00039
00040
00041
00042 class EXPCL_PANDAEXPRESS Patchfile {
00043 PUBLISHED:
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 Patchfile(void);
00057 Patchfile(PT(Buffer) buffer);
00058 ~Patchfile(void);
00059
00060 bool build(Filename file_orig, Filename file_new, Filename patch_name);
00061 int read_header(const Filename &patch_file);
00062
00063 int initiate(const Filename &patch_file, const Filename &file);
00064 int run(void);
00065
00066 bool apply(Filename &patch_file, Filename &file);
00067
00068 INLINE float get_progress(void) const;
00069
00070 INLINE void set_footprint_length(int length);
00071 INLINE int get_footprint_length();
00072 INLINE void reset_footprint_length();
00073
00074 INLINE bool has_source_hash() const;
00075 INLINE const HashVal &get_source_hash() const;
00076 INLINE const HashVal &get_result_hash() const;
00077
00078 private:
00079 int internal_read_header(const Filename &patch_file);
00080 void init(PT(Buffer) buffer);
00081 void cleanup(void);
00082
00083 private:
00084
00085 void build_hash_link_tables(const char *buffer_orig, PN_uint32 length_orig,
00086 PN_uint32 *hash_table, PN_uint32 *link_table);
00087 PN_uint16 calc_hash(const char *buffer);
00088 void find_longest_match(PN_uint32 new_pos, PN_uint32 ©_pos, PN_uint16 ©_length,
00089 PN_uint32 *hash_table, PN_uint32 *link_table, const char* buffer_orig,
00090 PN_uint32 length_orig, const char* buffer_new, PN_uint32 length_new);
00091 PN_uint32 calc_match_length(const char* buf1, const char* buf2, PN_uint32 max_length);
00092
00093 void emit_ADD(ofstream &write_stream, PN_uint16 length, const char* buffer,
00094 PN_uint32 ADD_pos);
00095 void emit_COPY(ofstream &write_stream, PN_uint16 length,
00096 PN_uint32 COPY_pos, PN_uint32 last_copy_pos,
00097 PN_uint32 ADD_pos);
00098
00099 static const PN_uint32 _HASHTABLESIZE;
00100 static const PN_uint32 _DEFAULT_FOOTPRINT_LENGTH;
00101 static const PN_uint32 _NULL_VALUE;
00102 static const PN_uint32 _MAX_RUN_LENGTH;
00103
00104 PN_uint32 _footprint_length;
00105
00106 protected:
00107 PT(Buffer) _buffer;
00108
00109
00110 bool _initiated;
00111
00112 PN_uint16 _version_number;
00113
00114 HashVal _MD5_ofSource;
00115 PN_uint32 _source_file_length;
00116
00117 HashVal _MD5_ofResult;
00118 PN_uint32 _result_file_length;
00119 int _total_bytes_processed;
00120
00121 ifstream _patch_stream;
00122 ofstream _write_stream;
00123 ifstream _origfile_stream;
00124
00125 Filename _patch_file;
00126 Filename _orig_file;
00127 Filename _temp_file;
00128
00129 static const PN_uint32 _v0_magic_number;
00130 static const PN_uint32 _magic_number;
00131 static const PN_uint16 _current_version;
00132 };
00133
00134 #include "patchfile.I"
00135
00136 #endif