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