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

panda/src/downloader/download_utils.cxx

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

Generated on Fri May 2 00:36:44 2003 for Panda by doxygen1.3