Pārlūkot izejas kodu

*** empty log message ***

Mike Goslin 25 gadi atpakaļ
vecāks
revīzija
24c6a482ca

+ 1 - 0
panda/src/downloader/extractor.cxx

@@ -71,6 +71,7 @@ init(PT(Buffer) buffer) {
   _frequency = extractor_frequency;
   _token_board = new ExtractorTokenBoard;
   _buffer = buffer;
+  _threads_enabled = false;
 }
 
 ////////////////////////////////////////////////////////////////////

+ 9 - 0
panda/src/downloadertools/multify.cxx

@@ -6,6 +6,9 @@
 #endif
 #include <multifile.h>
 #include <filename.h>
+#ifndef OLD_WAY
+  #include <extractor.h>
+#endif
 
 int
 main(int argc, char *argv[]) {
@@ -70,8 +73,14 @@ main(int argc, char *argv[]) {
     if (mfile.write(dest_file) == false)
       cerr << "Failed to write: " << dest_file << endl;
   } else {
+#ifdef OLD_WAY
     mfile.read(dest_file);
     mfile.extract_all(rel_path);
+#else
+    Extractor extor;
+    extor.set_frequency(0);
+    extor.extract(dest_file, rel_path);
+#endif
   }
 
   return 1;

+ 2 - 0
panda/src/express/datagram.I

@@ -308,6 +308,7 @@ add_fixed_string(const string &str, size_t size) {
 ////////////////////////////////////////////////////////////////////
 INLINE void Datagram::
 pad_bytes(size_t size) {
+  nassertv((int)size >= 0);
   _message += string(size, '\0');
 }
 
@@ -319,6 +320,7 @@ pad_bytes(size_t size) {
 ////////////////////////////////////////////////////////////////////
 INLINE void Datagram::
 append_data(const void *data, size_t size) {
+  nassertv((int)size >= 0);
   _message += string((const char *)data, size);
 }
 

+ 13 - 0
panda/src/express/datagramIterator.cxx

@@ -466,6 +466,7 @@ get_fixed_string(size_t size) {
 ////////////////////////////////////////////////////////////////////
 void DatagramIterator::
 skip_bytes(size_t size) {
+  nassertv((int)size >= 0);
   nassertv(_current_index + size <= _datagram.get_length());
   _current_index += size;
 }
@@ -478,6 +479,7 @@ skip_bytes(size_t size) {
 ////////////////////////////////////////////////////////////////////
 string DatagramIterator::
 extract_bytes(size_t size) {
+  nassertr((int)size >= 0, "");
   nassertr(_current_index + size <= _datagram.get_length(), "");
   int start = _current_index;
 
@@ -516,3 +518,14 @@ const Datagram &DatagramIterator::
 get_datagram() const {
   return _datagram;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: DatagramIterator::get_current_index
+//       Access: Public
+//  Description: Returns the current position within the datagram of the
+//               next piece of data to extract.
+////////////////////////////////////////////////////////////////////
+size_t DatagramIterator::
+get_current_index() const {
+  return _current_index;
+}

+ 1 - 0
panda/src/express/datagramIterator.h

@@ -53,6 +53,7 @@ public:
   int get_remaining_size() const;
 
   const Datagram &get_datagram() const;
+  size_t get_current_index() const;
  
 private:
   const Datagram &_datagram;

+ 29 - 3
panda/src/express/multifile.cxx

@@ -82,6 +82,8 @@ parse_header_length(char *&start, int &size) {
   int bytes_so_far = _datagram.get_length();
   if (bytes_so_far + size < _header_length_buf_length) {
     _datagram.append_data(start, size);
+    start += size;
+    size = 0;
     return false;
   }
 
@@ -89,13 +91,18 @@ parse_header_length(char *&start, int &size) {
   nassertr((int)_datagram.get_length() == _header_length_buf_length, false);
 
   // Advance start and adjust size
-  start += _header_length_buf_length;
+  nassertr(_header_length_buf_length >= bytes_so_far, false);
+  start += (_header_length_buf_length - bytes_so_far);
   nassertr(size >= _header_length_buf_length, false);
-  size -= _header_length_buf_length;
+  size -= (_header_length_buf_length - bytes_so_far);
 
   DatagramIterator di(_datagram);
   _header_length = di.get_int32(); 
 
+  express_cat.debug()
+    << "Multifile::Memfile::parse_header_length() - header length: "
+    << _header_length << endl;
+
   nassertr(_header_length > _header_length_buf_length + (int)sizeof(_buffer_length), false);
 
   _header_length_parsed = true;
@@ -140,6 +147,12 @@ parse_header(char *&start, int& size) {
     _name = di.extract_bytes(_header_length - _header_length_buf_length -
 			     sizeof(_buffer_length));
     _buffer_length = di.get_int32();
+    nassertr(_buffer_length >= 0, false);
+
+    express_cat.debug()
+      << "Multifile::Memfile::parse_header() - Got a header for mem "
+      << "file: " << _name << " header length: " << _header_length
+      << " buffer length: " << _buffer_length << endl;
 
     // Advance start pointer to the end of the header
     start += tsize;
@@ -291,6 +304,9 @@ write(char *&start, int &size, const Filename &rel_path) {
     Filename name = rel_path.get_fullpath() + _name.get_fullpath();
     name.set_binary();
     name.make_dir();
+    express_cat.debug()
+      << "Multifile::Memfile::write() - Opening mem file: " << name
+      << " for writing" << endl;
     if ((_file_open = name.open_write(_write_stream)) == false) {
       express_cat.error()
         << "Multfile::Memfile::write() - Couldn't open file: "
@@ -303,6 +319,7 @@ write(char *&start, int &size, const Filename &rel_path) {
   // Don't write more than the buffer length
   bool done = false;
   int tsize = size;
+  nassertr(_buffer_length >= _bytes_written, false);
   int missing_bytes = _buffer_length - _bytes_written;
   if (size >= missing_bytes) {
     tsize = missing_bytes;
@@ -312,10 +329,14 @@ write(char *&start, int &size, const Filename &rel_path) {
   _write_stream.write(start, tsize);
   start += tsize;
   _bytes_written += tsize;
+  nassertr(size >= tsize, false);
   size -= tsize;
 
-  if (done == true)
+  if (done == true) {
     _write_stream.close();
+    express_cat.debug()
+      << "Multifile::Memfile::write() - Closing mem file" << endl;
+  }
 
   return done;
 }
@@ -406,6 +427,11 @@ parse_header(char *&start, int &size) {
       return false;
     }
     _num_mfiles = di.get_int32();
+    if (_num_mfiles <= 0) {
+      express_cat.debug()
+	<< "Multifile::parse_header() - No memfiles in multifile"
+	<< endl;
+    }
 
     // Advance start pointer to the end of the header
     start += tsize;