1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25  *
26  */
27 
28 #include "engines/icb/common/px_common.h"
29 #include "engines/icb/p4.h"
30 #include "engines/icb/zsupport.h"
31 #include "engines/icb/res_man_pc.h"
32 
33 namespace ICB {
34 
35 #define BUFLEN 65536
36 
37 //static char buf[BUFLEN];
38 
fileGetZipLength(const char * inFn)39 uint32 fileGetZipLength(const char *inFn) {
40 	Common::SeekableReadStream *fileStream = openDiskFileForBinaryStreamRead(inFn);
41 	uint32 len = fileGetZipLength2(fileStream);
42 	delete fileStream;
43 	return len;
44 }
45 
fileGetZipLength2(Common::SeekableReadStream * fileStream)46 uint32 fileGetZipLength2(Common::SeekableReadStream *fileStream) {
47 	error("TODO: Fix compression");
48 #if 0
49 	gzFile in;
50 	uint32 t = 0;
51 
52 	int32 noOfFile = fileno(file);
53 	in = gzdopen(noOfFile , "rb");
54 
55 	if (in == NULL)
56 		return 0;
57 
58 	gzread(in, &t, sizeof(int32));
59 
60 	return t;
61 #endif
62 }
63 
memUncompress(uint8 * outMem,const char * inFn)64 uint32 memUncompress(uint8 *outMem, const char *inFn) {
65 	Common::SeekableReadStream *fileStream = openDiskFileForBinaryStreamRead(inFn);
66 
67 	uint32 retVal = memUncompress(outMem, inFn, fileStream);
68 
69 	delete fileStream;
70 
71 	return retVal;
72 }
73 
memUncompress(uint8 * outMem,const char * inFn,Common::SeekableReadStream * file)74 uint32 memUncompress(uint8 *outMem, const char *inFn, Common::SeekableReadStream *file) {
75 	error("TODO: Fix compression");
76 #if 0
77 	gzFile in;
78 	uint8 *myp;
79 	uint32 uncompressedLen;
80 
81 
82 	int32 noOfFile = fileno(file);
83 	in = gzdopen(noOfFile , "rb");
84 
85 	if (in == NULL) {
86 		fprintf(stderr, "error opening zipped file %s\n", inFn);
87 		return 0;
88 	}
89 	// Read the length
90 	if (gzread(in, &uncompressedLen, 4) != 4) {
91 		fprintf(stderr, "error in zipped file %s\n", inFn);
92 		return 0;
93 	}
94 
95 	uint32 bytesRead = 0;
96 	uint32 bytesToRead = uncompressedLen;
97 
98 	myp = outMem;
99 
100 	while (bytesToRead) {
101 		// Work out how much to read this go
102 		uint32 bytesToReadThisPass = bytesToRead;
103 		// Only fill a buffer
104 		if (bytesToReadThisPass > BUFLEN)
105 			bytesToReadThisPass = BUFLEN;
106 
107 		// Read in those bytes
108 		uint32 bytesReadThisPass = gzread(in, buf, bytesToReadThisPass);
109 		if (bytesReadThisPass == 0)
110 			break;
111 
112 		// Uypdate the counters and pointers
113 		bytesRead += bytesReadThisPass;
114 		bytesToRead -= bytesReadThisPass;
115 
116 		// And copy the data over
117 		memcpy(myp, buf, bytesReadThisPass);
118 		myp += bytesReadThisPass;
119 	}
120 #endif
121 	return 1;
122 }
123 
124 } // End of namespace ICB
125