forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatchfile.h
More file actions
176 lines (138 loc) · 5.61 KB
/
patchfile.h
File metadata and controls
176 lines (138 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file patchfile.h
* @author darren, mike
* @date 1997-01-09
*/
#ifndef PATCHFILE_H
#define PATCHFILE_H
#include "pandabase.h"
#ifdef HAVE_OPENSSL
#include "typedef.h"
#include "pnotify.h"
#include "filename.h"
#include "plist.h"
#include "datagram.h"
#include "datagramIterator.h"
#include "buffer.h"
#include "pointerTo.h"
#include "hashVal.h" // MD5 stuff
#include "ordered_vector.h"
#include "streamWrapper.h"
#include <algorithm>
/**
*
*/
class EXPCL_PANDA_EXPRESS Patchfile {
PUBLISHED:
Patchfile();
explicit Patchfile(PT(Buffer) buffer);
~Patchfile();
bool build(Filename file_orig, Filename file_new, Filename patch_name);
int read_header(const Filename &patch_file);
int initiate(const Filename &patch_file, const Filename &file);
int initiate(const Filename &patch_file, const Filename &orig_file,
const Filename &target_file);
int run();
bool apply(Filename &patch_file, Filename &file);
bool apply(Filename &patch_file, Filename &orig_file,
const Filename &target_file);
INLINE PN_stdfloat get_progress() const;
MAKE_PROPERTY(progress, get_progress);
INLINE void set_allow_multifile(bool allow_multifile);
INLINE bool get_allow_multifile();
MAKE_PROPERTY(allow_multifile, get_allow_multifile, set_allow_multifile);
INLINE void set_footprint_length(int length);
INLINE int get_footprint_length();
INLINE void reset_footprint_length();
MAKE_PROPERTY(footprint_length, get_footprint_length, set_footprint_length);
INLINE bool has_source_hash() const;
INLINE const HashVal &get_source_hash() const;
INLINE const HashVal &get_result_hash() const;
MAKE_PROPERTY2(source_hash, has_source_hash, get_source_hash);
MAKE_PROPERTY(result_hash, get_result_hash);
private:
int internal_read_header(const Filename &patch_file);
void init(PT(Buffer) buffer);
void cleanup();
private:
// stuff for the build operation
void build_hash_link_tables(const char *buffer_orig, uint32_t length_orig,
uint32_t *hash_table, uint32_t *link_table);
uint32_t calc_hash(const char *buffer);
void find_longest_match(uint32_t new_pos, uint32_t ©_pos, uint16_t ©_length,
uint32_t *hash_table, uint32_t *link_table, const char* buffer_orig,
uint32_t length_orig, const char* buffer_new, uint32_t length_new);
uint32_t calc_match_length(const char* buf1, const char* buf2, uint32_t max_length,
uint32_t min_length);
void emit_ADD(std::ostream &write_stream, uint32_t length, const char* buffer);
void emit_COPY(std::ostream &write_stream, uint32_t length, uint32_t COPY_pos);
void emit_add_and_copy(std::ostream &write_stream,
uint32_t add_length, const char *add_buffer,
uint32_t copy_length, uint32_t copy_pos);
void cache_add_and_copy(std::ostream &write_stream,
uint32_t add_length, const char *add_buffer,
uint32_t copy_length, uint32_t copy_pos);
void cache_flush(std::ostream &write_stream);
void write_header(std::ostream &write_stream,
std::istream &stream_orig, std::istream &stream_new);
void write_terminator(std::ostream &write_stream);
bool compute_file_patches(std::ostream &write_stream,
uint32_t offset_orig, uint32_t offset_new,
std::istream &stream_orig, std::istream &stream_new);
bool compute_mf_patches(std::ostream &write_stream,
uint32_t offset_orig, uint32_t offset_new,
std::istream &stream_orig, std::istream &stream_new);
bool do_compute_patches(const Filename &file_orig, const Filename &file_new,
std::ostream &write_stream,
uint32_t offset_orig, uint32_t offset_new,
std::istream &stream_orig, std::istream &stream_new);
bool patch_subfile(std::ostream &write_stream,
uint32_t offset_orig, uint32_t offset_new,
const Filename &filename,
IStreamWrapper &stream_orig, std::streampos orig_start, std::streampos orig_end,
IStreamWrapper &stream_new, std::streampos new_start, std::streampos new_end);
static const uint32_t _HASH_BITS;
static const uint32_t _HASHTABLESIZE;
static const uint32_t _DEFAULT_FOOTPRINT_LENGTH;
static const uint32_t _NULL_VALUE;
static const uint32_t _MAX_RUN_LENGTH;
static const uint32_t _HASH_MASK;
bool _allow_multifile;
uint32_t _footprint_length;
uint32_t *_hash_table;
uint32_t _add_pos;
uint32_t _last_copy_pos;
std::string _cache_add_data;
uint32_t _cache_copy_start;
uint32_t _cache_copy_length;
private:
PT(Buffer) _buffer; // this is the work buffer for apply -- used to prevent virtual memory swapping
// async patch apply state variables
bool _initiated;
uint16_t _version_number;
HashVal _MD5_ofSource;
HashVal _MD5_ofResult;
uint32_t _total_bytes_to_process;
uint32_t _total_bytes_processed;
std::istream *_patch_stream;
pofstream _write_stream;
std::istream *_origfile_stream;
Filename _patch_file;
Filename _orig_file;
Filename _output_file;
bool _rename_output_to_orig;
bool _delete_patchfile;
static const uint32_t _v0_magic_number;
static const uint32_t _magic_number;
static const uint16_t _current_version;
};
#include "patchfile.I"
#endif // HAVE_OPENSSL
#endif