Panda3D
extractor.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file extractor.h
10  * @author mike
11  * @date 1997-01-09
12  */
13 
14 #ifndef EXTRACTOR_H
15 #define EXTRACTOR_H
16 
17 #include "pandabase.h"
18 #include "filename.h"
19 #include "buffer.h"
20 #include "multifile.h"
21 #include "pointerTo.h"
22 #include "vector_int.h"
23 
24 /**
25  * This class automatically extracts the contents of a Multifile to the
26  * current directory (or to a specified directory) in the background.
27  *
28  * It is designed to limit its use of system resources and run unobtrusively
29  * in the background. After specifying the files you wish to extract via
30  * repeated calls to request_subfile(), begin the process by calling run()
31  * repeatedly. Each call to run() extracts another small portion of the
32  * Multifile. Call run() whenever you have spare cycles until run() returns
33  * EU_success.
34  */
35 class EXPCL_PANDA_DOWNLOADER Extractor {
36 PUBLISHED:
37  Extractor();
38  ~Extractor();
39 
40  bool set_multifile(const Filename &multifile_name);
41  void set_extract_dir(const Filename &extract_dir);
42 
43  void reset();
44 
45  bool request_subfile(const Filename &subfile_name);
46  int request_all_subfiles();
47 
48  int step();
49  PN_stdfloat get_progress() const;
50 
51  bool run();
52 
53 PUBLISHED:
54  MAKE_PROPERTY(progress, get_progress);
55 
56 private:
57  Filename _multifile_name;
58  PT(Multifile) _multifile;
59 
60  Filename _extract_dir;
61 
62  typedef vector_int Requests;
63  Requests _requests;
64  size_t _requests_total_length;
65 
66  bool _initiated;
67 
68  // These are used only while processing.
69  int _request_index;
70  int _subfile_index;
71  size_t _subfile_pos;
72  size_t _subfile_length;
73  size_t _total_bytes_extracted;
74  std::istream *_read;
75  pofstream _write;
76  Filename _subfile_filename;
77 };
78 
79 #include "extractor.I"
80 
81 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class automatically extracts the contents of a Multifile to the current directory (or to a speci...
Definition: extractor.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A file that contains a set of files.
Definition: multifile.h:37
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.