Panda3D

download_utils.cxx

00001 // Filename: download_utils.cxx
00002 // Created by:  mike (18Jan99)
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 
00015 #include "pandabase.h"
00016 
00017 #ifdef HAVE_ZLIB
00018 
00019 #include "download_utils.h"
00020 #include "config_downloader.h"
00021 #include <zlib.h>
00022 
00023 unsigned long
00024 check_crc(Filename name) {
00025   pifstream read_stream;
00026   name.set_binary();
00027   if (!name.open_read(read_stream)) {
00028     downloader_cat.error()
00029       << "check_crc() - Failed to open input file: " << name << endl;
00030     return 0;
00031   }
00032 
00033   // Determine the length of the file and read it into the buffer
00034   read_stream.seekg(0, ios::end);
00035   int buffer_length = read_stream.tellg();
00036   char *buffer = new char[buffer_length];
00037   read_stream.seekg(0, ios::beg);
00038   read_stream.read(buffer, buffer_length);
00039 
00040   // Compute the crc
00041   unsigned long crc = crc32(0L, Z_NULL, 0);
00042   crc = crc32(crc, (unsigned char *)buffer, buffer_length);
00043 
00044   delete buffer;
00045 
00046   return crc;
00047 }
00048 
00049 unsigned long
00050 check_adler(Filename name) {
00051   pifstream read_stream;
00052   name.set_binary();
00053   if (!name.open_read(read_stream)) {
00054     downloader_cat.error()
00055       << "check_adler() - Failed to open input file: " << name << endl;
00056     return 0;
00057   }
00058 
00059   // Determine the length of the file and read it into the buffer
00060   read_stream.seekg(0, ios::end);
00061   int buffer_length = read_stream.tellg();
00062   char *buffer = new char[buffer_length];
00063   read_stream.seekg(0, ios::beg);
00064   read_stream.read(buffer, buffer_length);
00065 
00066   // Compute the adler checksum
00067   unsigned long adler = adler32(0L, Z_NULL, 0);
00068   adler = adler32(adler, (unsigned char *)buffer, buffer_length);
00069 
00070   delete buffer;
00071 
00072   return adler;
00073 }
00074 
00075 #endif  // HAVE_ZLIB
 All Classes Functions Variables Enumerations