Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/express/patchfile.h

Go to the documentation of this file.
00001 // Filename: patchfile.h
00002 // Created by:  darren, mike (09Jan97)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 #ifndef PATCHFILE_H
00019 #define PATCHFILE_H
00020 //
00021 ////////////////////////////////////////////////////////////////////
00022 // Includes
00023 ////////////////////////////////////////////////////////////////////
00024 #include <pandabase.h>
00025 
00026 #include "typedef.h"
00027 #include <notify.h>
00028 #include <filename.h>
00029 #include "plist.h"
00030 #include "datagram.h"
00031 #include "datagramIterator.h"
00032 #include "buffer.h"
00033 #include "pointerTo.h"
00034 #include "hashVal.h" // MD5 stuff
00035 
00036 #include <algorithm>
00037 
00038 ////////////////////////////////////////////////////////////////////
00039 //       Class : Patchfile
00040 // Description :
00041 ////////////////////////////////////////////////////////////////////
00042 class EXPCL_PANDAEXPRESS Patchfile {
00043 PUBLISHED:
00044   /*
00045   enum PatchfileStatus {
00046     PF_ok = 2,
00047     PF_success = 1,
00048     PF_error = -1,
00049     PF_error_filenotfound = -2,
00050     PF_error_invalidpatchfile = -3,
00051     PF_error_wrongpatchfile = -4,
00052     PF_error_renamingtempfile = -5,
00053   };
00054   */
00055 
00056   Patchfile(void);
00057   Patchfile(PT(Buffer) buffer);
00058   ~Patchfile(void);
00059 
00060   bool build(Filename file_orig, Filename file_new, Filename patch_name);
00061   int read_header(const Filename &patch_file);
00062 
00063   int initiate(const Filename &patch_file, const Filename &file);
00064   int run(void);
00065 
00066   bool apply(Filename &patch_file, Filename &file);
00067 
00068   INLINE float get_progress(void) const;
00069 
00070   INLINE void set_footprint_length(int length);
00071   INLINE int get_footprint_length();
00072   INLINE void reset_footprint_length();
00073 
00074   INLINE bool has_source_hash() const;
00075   INLINE const HashVal &get_source_hash() const;
00076   INLINE const HashVal &get_result_hash() const;
00077 
00078 private:
00079   int internal_read_header(const Filename &patch_file);
00080   void init(PT(Buffer) buffer);
00081   void cleanup(void);
00082 
00083 private:
00084   // stuff for the build operation
00085   void build_hash_link_tables(const char *buffer_orig, PN_uint32 length_orig,
00086     PN_uint32 *hash_table, PN_uint32 *link_table);
00087   PN_uint16 calc_hash(const char *buffer);
00088   void find_longest_match(PN_uint32 new_pos, PN_uint32 &copy_pos, PN_uint16 &copy_length,
00089     PN_uint32 *hash_table, PN_uint32 *link_table, const char* buffer_orig,
00090     PN_uint32 length_orig, const char* buffer_new, PN_uint32 length_new);
00091   PN_uint32 calc_match_length(const char* buf1, const char* buf2, PN_uint32 max_length);
00092 
00093   void emit_ADD(ofstream &write_stream, PN_uint16 length, const char* buffer,
00094                 PN_uint32 ADD_pos);
00095   void emit_COPY(ofstream &write_stream, PN_uint16 length, 
00096                  PN_uint32 COPY_pos, PN_uint32 last_copy_pos,
00097                  PN_uint32 ADD_pos);
00098 
00099   static const PN_uint32 _HASHTABLESIZE;
00100   static const PN_uint32 _DEFAULT_FOOTPRINT_LENGTH;
00101   static const PN_uint32 _NULL_VALUE;
00102   static const PN_uint32 _MAX_RUN_LENGTH;
00103 
00104   PN_uint32 _footprint_length;
00105 
00106 protected:
00107   PT(Buffer) _buffer; // this is the work buffer for apply -- used to prevent virtual memory swapping
00108 
00109   // async patch apply state variables
00110   bool _initiated;
00111 
00112   PN_uint16 _version_number;
00113 
00114   HashVal _MD5_ofSource;  
00115   PN_uint32 _source_file_length;
00116 
00117   HashVal _MD5_ofResult;  
00118   PN_uint32 _result_file_length;
00119   int _total_bytes_processed;
00120 
00121   ifstream _patch_stream;
00122   ofstream _write_stream;
00123   ifstream _origfile_stream;
00124 
00125   Filename _patch_file;
00126   Filename _orig_file;
00127   Filename _temp_file;
00128 
00129   static const PN_uint32 _v0_magic_number;
00130   static const PN_uint32 _magic_number;
00131   static const PN_uint16 _current_version;
00132 };
00133 
00134 #include "patchfile.I"
00135 
00136 #endif

Generated on Fri May 2 00:38:29 2003 for Panda by doxygen1.3