forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp3dPackage.h
More file actions
executable file
·314 lines (258 loc) · 8.67 KB
/
p3dPackage.h
File metadata and controls
executable file
·314 lines (258 loc) · 8.67 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
// Filename: p3dPackage.h
// Created by: drose (12Jun09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
#ifndef P3DPACKAGE_H
#define P3DPACKAGE_H
#include "p3d_plugin_common.h"
#include "p3dFileDownload.h"
#include "p3dPatchfileReader.h"
#include "fileSpec.h"
#include "get_tinyxml.h"
#include <deque>
class P3DHost;
class P3DInstance;
class P3DTemporaryFile;
////////////////////////////////////////////////////////////////////
// Class : P3DPackage
// Description : This corresponds to a downloadable, patchable
// package, and all its constituent files. For
// instance, a particular version of the Panda3D
// runtime, which consists of a bunch of dll's
// downloaded in a single tar file, is a package.
//
// The core API is responsible for managing these
// packages on disk, downloading new versions when
// needed, and removing stale versions to limit disk
// space waste.
////////////////////////////////////////////////////////////////////
class P3DPackage {
private:
P3DPackage(P3DHost *host,
const string &package_name,
const string &package_version,
const string &package_platform,
const string &alt_host);
~P3DPackage();
public:
inline bool get_info_ready() const;
inline size_t get_download_size() const;
void activate_download();
inline bool get_ready() const;
inline bool get_failed() const;
inline P3DHost *get_host() const;
inline const string &get_package_dir() const;
inline const string &get_package_name() const;
inline const string &get_package_version() const;
inline const string &get_package_platform() const;
inline const string &get_package_display_name() const;
string get_formatted_name() const;
inline const TiXmlElement *get_xconfig() const;
inline const string &get_desc_file_pathname() const;
inline const string &get_desc_file_dirname() const;
inline string get_archive_file_pathname() const;
void add_instance(P3DInstance *inst);
void remove_instance(P3DInstance *inst);
void mark_used();
void uninstall();
TiXmlElement *make_xml();
private:
typedef vector<FileSpec> Extracts;
enum DownloadType {
DT_contents_file,
DT_redownload_contents_file,
DT_desc_file,
DT_install_step,
};
typedef vector<string> TryUrls;
class Download : public P3DFileDownload {
public:
Download(P3DPackage *package, DownloadType dtype,
const FileSpec &file_spec);
Download(const Download ©);
protected:
virtual void download_progress();
virtual void download_finished(bool success);
public:
void resume_download_finished(bool success);
public:
// URL's to try downloading from, in reverse order.
TryUrls _try_urls;
private:
P3DPackage *_package;
DownloadType _dtype;
// FileSpec to validate the download against.
FileSpec _file_spec;
};
enum InstallToken {
IT_step_complete,
IT_step_failed,
IT_continue,
IT_needs_callback,
IT_terminate,
};
class InstallStep {
public:
InstallStep(P3DPackage *package, size_t bytes, double factor);
virtual ~InstallStep();
virtual InstallToken do_step(bool download_finished) = 0;
virtual void output(ostream &out) = 0;
inline double get_effort() const;
inline double get_progress() const;
inline void report_step_progress();
P3DPackage *_package;
size_t _bytes_needed;
size_t _bytes_done;
double _bytes_factor;
};
class InstallStepDownloadFile : public InstallStep {
public:
InstallStepDownloadFile(P3DPackage *package, const FileSpec &file);
virtual ~InstallStepDownloadFile();
virtual InstallToken do_step(bool download_finished);
virtual void output(ostream &out);
string _urlbase;
string _pathname;
FileSpec _file;
Download *_download;
};
class InstallStepThreaded : public InstallStep {
public:
InstallStepThreaded(P3DPackage *package, size_t bytes, double factor);
virtual ~InstallStepThreaded();
virtual InstallToken do_step(bool download_finished);
THREAD_CALLBACK_DECLARATION(InstallStepThreaded, thread_main);
void thread_main();
virtual InstallToken thread_step()=0;
void thread_set_bytes_done(size_t bytes_done);
void thread_add_bytes_done(size_t bytes_done);
THREAD _thread;
LOCK _thread_lock;
bool _thread_started;
InstallToken _thread_token;
size_t _thread_bytes_done;
};
class InstallStepUncompressFile : public InstallStepThreaded {
public:
InstallStepUncompressFile(P3DPackage *package, const FileSpec &source,
const FileSpec &target, bool verify_target);
virtual InstallToken thread_step();
virtual void output(ostream &out);
FileSpec _source;
FileSpec _target;
bool _verify_target;
};
class InstallStepUnpackArchive : public InstallStepThreaded {
public:
InstallStepUnpackArchive(P3DPackage *package, size_t unpack_size);
virtual InstallToken thread_step();
virtual void output(ostream &out);
};
class InstallStepApplyPatch : public InstallStepThreaded {
public:
InstallStepApplyPatch(P3DPackage *package,
const FileSpec &patchfile,
const FileSpec &source,
const FileSpec &target);
virtual InstallToken thread_step();
virtual void output(ostream &out);
P3DPatchfileReader _reader;
};
typedef deque<InstallStep *> InstallPlan;
typedef deque<InstallPlan> InstallPlans;
InstallPlans _install_plans;
bool _computed_plan_size;
double _total_plan_size;
double _total_plan_completed;
double _download_progress;
double _current_step_effort;
void begin_info_download();
void download_contents_file();
void contents_file_download_finished(bool success);
void redownload_contents_file(Download *download);
void contents_file_redownload_finished(bool success);
void host_got_contents_file();
void download_desc_file();
void desc_file_download_finished(bool success);
void got_desc_file(TiXmlDocument *doc, bool freshly_downloaded);
void clear_install_plans();
void build_install_plans(TiXmlDocument *doc);
void follow_install_plans(bool download_finished, bool plan_failed);
static void st_callback(void *self);
void request_callback();
void report_progress(InstallStep *step);
void report_info_ready();
void report_done(bool success);
Download *start_download(DownloadType dtype, const string &urlbase,
const string &pathname, const FileSpec &file_spec);
void set_active_download(Download *download);
void set_saved_download(Download *download);
bool is_extractable(FileSpec &file, const string &filename) const;
bool instance_terminating(P3DInstance *instance);
void set_fullname();
public:
class RequiredPackage {
public:
inline RequiredPackage(const string &package_name,
const string &package_version,
const string &package_seq,
P3DHost *host);
string _package_name;
string _package_version;
string _package_seq;
P3DHost *_host;
};
typedef vector<RequiredPackage> Requires;
Requires _requires;
private:
P3DHost *_host;
int _host_contents_iseq;
string _package_name;
string _package_version;
string _package_platform;
bool _per_platform;
int _patch_version;
string _alt_host;
bool _package_solo;
string _package_display_name;
string _package_fullname;
string _package_dir;
TiXmlElement *_xconfig;
P3DTemporaryFile *_temp_contents_file;
FileSpec _desc_file;
string _desc_file_dirname;
string _desc_file_basename;
string _desc_file_pathname;
bool _info_ready;
bool _allow_data_download;
bool _ready;
bool _failed;
Download *_active_download;
Download *_saved_download;
typedef vector<P3DInstance *> Instances;
Instances _instances;
FileSpec _compressed_archive;
FileSpec _uncompressed_archive;
size_t _unpack_size;
Extracts _extracts;
bool _updated;
static const double _download_factor;
static const double _uncompress_factor;
static const double _unpack_factor;
static const double _patch_factor;
friend class Download;
friend class InstallStep;
friend class P3DMultifileReader;
friend class P3DHost;
};
#include "p3dPackage.I"
#endif