Panda3D

download_utils.cxx
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file download_utils.cxx
10 * @author mike
11 * @date 1999-01-18
12 */
13
14 #include "pandabase.h"
15
16 #ifdef HAVE_ZLIB
17
18 #include "download_utils.h"
19 #include "config_downloader.h"
20 #include <zlib.h>
21
22 using std::ios;
23
24 unsigned long
25 check_crc(Filename name) {
26 pifstream read_stream;
27 name.set_binary();
28 if (!name.open_read(read_stream)) {
29 downloader_cat.error()
30 << "check_crc() - Failed to open input file: " << name << std::endl;
31 return 0;
32 }
33
34 // Determine the length of the file and read it into the buffer
35 read_stream.seekg(0, ios::end);
36 int buffer_length = read_stream.tellg();
37 char *buffer = new char[buffer_length];
38 read_stream.seekg(0, ios::beg);
39 read_stream.read(buffer, buffer_length);
40
41 // Compute the crc
42 unsigned long crc = crc32(0L, Z_NULL, 0);
43 crc = crc32(crc, (unsigned char *)buffer, buffer_length);
44
45 delete[] buffer;
46
47 return crc;
48 }
49
50 unsigned long
51 check_adler(Filename name) {
52 pifstream read_stream;
53 name.set_binary();
54 if (!name.open_read(read_stream)) {
55 downloader_cat.error()
56 << "check_adler() - Failed to open input file: " << name << std::endl;
57 return 0;
58 }
59
60 // Determine the length of the file and read it into the buffer
61 read_stream.seekg(0, ios::end);
62 int buffer_length = read_stream.tellg();
63 char *buffer = new char[buffer_length];
64 read_stream.seekg(0, ios::beg);
65 read_stream.read(buffer, buffer_length);
66
67 // Compute the adler checksum
68 unsigned long adler = adler32(0L, Z_NULL, 0);
69 adler = adler32(adler, (unsigned char *)buffer, buffer_length);
70
71 delete[] buffer;
72
73 return adler;
74 }
75
76 #endif // HAVE_ZLIB
Filename
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
Filename::open_read
bool open_read(std::ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
Definition: filename.cxx:1863
Filename::set_binary
void set_binary()
Indicates that the filename represents a binary file.
Definition: filename.I:414
config_downloader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
download_utils.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.