Panda3D

extractor.h

00001 // Filename: extractor.h
00002 // Created by:  mike (09Jan97)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 #ifndef EXTRACTOR_H
00015 #define EXTRACTOR_H
00016 
00017 #include "pandabase.h"
00018 #include "filename.h"
00019 #include "buffer.h"
00020 #include "multifile.h"
00021 #include "pointerTo.h"
00022 #include "vector_int.h"
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //       Class : Extractor
00026 // Description : This class automatically extracts the contents of a
00027 //               Multifile to the current directory (or to a specified
00028 //               directory) in the background.
00029 //
00030 //               It is designed to limit its use of system resources
00031 //               and run unobtrusively in the background.  After
00032 //               specifying the files you wish to extract via repeated
00033 //               calls to request_subfile(), begin the process by
00034 //               calling run() repeatedly.  Each call to run()
00035 //               extracts another small portion of the Multifile.
00036 //               Call run() whenever you have spare cycles until run()
00037 //               returns EU_success.
00038 ////////////////////////////////////////////////////////////////////
00039 class EXPCL_PANDAEXPRESS Extractor {
00040 PUBLISHED:
00041   Extractor();
00042   ~Extractor();
00043 
00044   bool set_multifile(const Filename &multifile_name);
00045   void set_extract_dir(const Filename &extract_dir);
00046 
00047   void reset();
00048 
00049   bool request_subfile(const Filename &subfile_name);
00050   int request_all_subfiles();
00051 
00052   int step();
00053   PN_stdfloat get_progress() const;
00054 
00055   bool run();
00056 
00057 private:
00058   Filename _multifile_name;
00059   PT(Multifile) _multifile;
00060 
00061   Filename _extract_dir;
00062 
00063   typedef vector_int Requests;
00064   Requests _requests;
00065   size_t _requests_total_length;
00066   
00067   bool _initiated;
00068 
00069   // These are used only while processing.
00070   int _request_index;
00071   int _subfile_index;
00072   size_t _subfile_pos;
00073   size_t _subfile_length;
00074   size_t _total_bytes_extracted;
00075   istream *_read;
00076   pofstream _write;
00077   Filename _subfile_filename;
00078 };
00079 
00080 #include "extractor.I"
00081 
00082 #endif
 All Classes Functions Variables Enumerations