[Scummvm-cvs-logs] SF.net SVN: scummvm:[46633] tools/branches/gsoc2009-gui

sev at users.sourceforge.net sev at users.sourceforge.net
Sun Dec 27 13:43:27 CET 2009


Revision: 46633
          http://scummvm.svn.sourceforge.net/scummvm/?rev=46633&view=rev
Author:   sev
Date:     2009-12-27 12:43:26 +0000 (Sun, 27 Dec 2009)

Log Message:
-----------
Port extract_cruise_pc to new framework. This completes syncing with tools trunk

Modified Paths:
--------------
    tools/branches/gsoc2009-gui/Makefile.common
    tools/branches/gsoc2009-gui/engines/cruise/extract_cruise_pc.cpp

Added Paths:
-----------
    tools/branches/gsoc2009-gui/engines/cruise/extract_cruise_pc.h

Modified: tools/branches/gsoc2009-gui/Makefile.common
===================================================================
--- tools/branches/gsoc2009-gui/Makefile.common	2009-12-27 12:38:19 UTC (rev 46632)
+++ tools/branches/gsoc2009-gui/Makefile.common	2009-12-27 12:43:26 UTC (rev 46633)
@@ -25,6 +25,7 @@
 MODULE_DIRS += \
 	engines/agos/ \
 	engines/cine/ \
+	engines/cruise/ \
 	engines/gob/ \
 	engines/groovie/ \
 	engines/kyra/ \
@@ -164,6 +165,7 @@
 	engines/tinsel/compress_tinsel.o \
 	engines/agos/extract_agos.o \
 	engines/cine/extract_cine.o \
+	engines/cruise/extract_cruise_pc.o \
 	engines/gob/extract_gob_stk.o \
 	engines/kyra/extract_kyra.o \
 	engines/scumm/extract_loom_tg16.o \

Modified: tools/branches/gsoc2009-gui/engines/cruise/extract_cruise_pc.cpp
===================================================================
--- tools/branches/gsoc2009-gui/engines/cruise/extract_cruise_pc.cpp	2009-12-27 12:38:19 UTC (rev 46632)
+++ tools/branches/gsoc2009-gui/engines/cruise/extract_cruise_pc.cpp	2009-12-27 12:43:26 UTC (rev 46633)
@@ -1,4 +1,4 @@
-/* extract_cruise_pc
+/* extract_cruise_pc - Extract data from PC version of Cruise for a Corpse
  * Copyright (C) 2009  The ScummVM Team
  *
  * This program is free software; you can redistribute it and/or
@@ -19,8 +19,11 @@
  * $Id$
  *
  */
-#include "util.h"
 
+#include <stdarg.h>
+
+#include "extract_cruise_pc.h"
+
 struct Disk1Header {
 	unsigned char signature[4];
 	int headerSize;
@@ -33,34 +36,29 @@
 
 struct Disk1Stream {
 
-	FILE *_fp;
+	Common::File *_fp;
 
 	unsigned int _bitsBuffer;
 	int _bitsLeft;
 
-	Disk1Stream(FILE *fp) : _fp(fp), _bitsBuffer(0), _bitsLeft(0) {}
+	Disk1Stream(Common::File *fp) : _fp(fp), _bitsBuffer(0), _bitsLeft(0) {}
 
 	bool readHeader(Disk1Header *hdr) {
-		fread(hdr->signature, 4, 1, _fp);
-		hdr->headerSize = getInt(2);
-		hdr->uncompressedSize = getInt(4);
-		hdr->compressedSize = getInt(4);
-		fread(hdr->name, 14, 1, _fp);
-		hdr->creationTime = getInt(2);
-		hdr->creationDate = getInt(2);
+		for (int i = 0; i < 4; i++)
+			hdr->signature[i] = _fp->readByte();
+		hdr->headerSize = _fp->readSint16LE();
+		hdr->uncompressedSize = _fp->readSint32LE();
+		hdr->compressedSize = _fp->readSint32LE();
+		for (int i = 0; i < 14; i++)
+			hdr->name[i] = _fp->readByte();
+		hdr->creationTime = _fp->readSint16LE();
+		hdr->creationDate = _fp->readSint16LE();
 		return memcmp(hdr->signature, "PKD\0", 4) == 0 && hdr->headerSize == 32;
 	}
-	int getInt(int e) {
-		int num = 0;
-		for (int i = 0; i < e; ++i) {
-			num |= fgetc(_fp) << (i * 8);
-		}
-		return num;
-	}
 	int getBits(int count) {
 		while (_bitsLeft <= 24) {
-			int chr = fgetc(_fp);
-			if (feof(_fp)) chr = 0;
+			int chr = _fp->readByte();
+			if (_fp->eos()) chr = 0;
 			_bitsBuffer |= chr << (24 - _bitsLeft);
 			_bitsLeft += 8;
 		}
@@ -86,9 +84,9 @@
 	int _parent[943];
 	unsigned char _historyBuffer[4156];
 	int _uncompressedSize;
-	FILE *_outputFile;
+	Common::File *_outputFile;
 
-	Disk1Decoder(Disk1Stream *stream, FILE *output, int uncompressedSize)
+	Disk1Decoder(Disk1Stream *stream, Common::File *output, int uncompressedSize)
 		: _stream(stream), _outputFile(output), _uncompressedSize(uncompressedSize) {
 		memset(_child, 0, sizeof(_child));
 		memset(_freq, 0, sizeof(_freq));
@@ -200,7 +198,7 @@
 		while (currentSize < _uncompressedSize) {
 			int chr = decodeChar();
 			if (chr < 256) {
-				fputc(chr & 255, _outputFile);
+				_outputFile->writeByte(chr & 255);
 				_historyBuffer[offset++] = chr;
 				offset &= 0xFFF;
 				++currentSize;
@@ -209,7 +207,7 @@
 				const int size = chr - 253;
 				for (int i = 0; i < size; ++i) {
 					chr = _historyBuffer[(baseOffset + i) & 0xFFF];
-					fputc(chr & 255, _outputFile);
+					_outputFile->writeByte(chr & 255);
 					_historyBuffer[offset++] = chr;
 					offset &= 0xFFF;
 					++currentSize;
@@ -220,37 +218,37 @@
 	}
 };
 
-int main(int argc, char *argv[]) {
-	if (argc != 2) {
-		printf("usage: %s FILE\n", argv[0]);
-		exit(2);
-	}
-	FILE *input = fopen(argv[1], "rb");
-	if (!input) {
-		error("Unable to open '%s' for reading", argv[1]);
-	}
-	Disk1Stream stream(input);
+void ExtractCruisePC::execute() {
+	if (_outputPath.empty())
+		_outputPath.setFullPath("./");
+
+	Common::File input(_inputPaths[0].path, "rb");
+
+	Disk1Stream stream(&input);
 	Disk1Header hdr;
 	if (!stream.readHeader(&hdr)) {
 		error("Invalid file signature");
 	}
-	printf("Output filename '%s'\n", hdr.name);
-	printf("Date %02d/%02d/%04d\n", hdr.creationDate & 31, (hdr.creationDate >> 5) & 15, ((hdr.creationDate >> 9) & 127) + 1980);
-	printf("Time %02d:%02d:%02d\n", (hdr.creationTime >> 11) & 31, (hdr.creationTime >> 5) & 63, (hdr.creationTime & 31) << 1);
-	printf("Size %d (uncompressed %d)\n", hdr.compressedSize, hdr.uncompressedSize);
-	FILE *output = fopen(hdr.name, "wb");
-	if (!output) {
-		error("Unable to open '%s' for writing", hdr.name);
-	}
-	Disk1Decoder d(&stream, output, hdr.uncompressedSize);
-	printf("Decompressing...");
+	print("Output filename '%s'\n", hdr.name);
+	print("Date %02d/%02d/%04d\n", hdr.creationDate & 31, (hdr.creationDate >> 5) & 15, ((hdr.creationDate >> 9) & 127) + 1980);
+	print("Time %02d:%02d:%02d\n", (hdr.creationTime >> 11) & 31, (hdr.creationTime >> 5) & 63, (hdr.creationTime & 31) << 1);
+	print("Size %d (uncompressed %d)\n", hdr.compressedSize, hdr.uncompressedSize);
+
+	_outputPath.setFullName(hdr.name);
+	Common::File output(_outputPath, "wb");
+
+	Disk1Decoder d(&stream, &output, hdr.uncompressedSize);
+	print("Decompressing...");
 	if (d.decode()) {
-		printf("Ok\n");
+		print("Ok\n");
 	} else {
-		printf("Error\n");
+		print("Error\n");
 	}
-	fclose(input);
-	fclose(output);
-	return 0;
 }
 
+#ifdef STANDALONE_MAIN
+int main(int argc, char *argv[]) {
+	ExtractCrsuisePC cruise(argv[0]);
+	return cruise.run(argc, argv);
+}
+#endif

Added: tools/branches/gsoc2009-gui/engines/cruise/extract_cruise_pc.h
===================================================================
--- tools/branches/gsoc2009-gui/engines/cruise/extract_cruise_pc.h	                        (rev 0)
+++ tools/branches/gsoc2009-gui/engines/cruise/extract_cruise_pc.h	2009-12-27 12:43:26 UTC (rev 46633)
@@ -0,0 +1,42 @@
+/* extract_cruise_pc - Extract data from PC version of Cruise for a Corpse
+ * Copyright (C) 2009  The ScummVM Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef EXTRACT_CRUISE_PC_H
+#define EXTRACT_CRUISE_PC_H
+
+#include "compress.h"
+
+struct t_resource;
+typedef t_resource * p_resource;
+
+class ExtractCruisePC : public Tool {
+public:
+	ExtractCruisePC(const std::string &name = "extract_cruise_pc");
+
+	virtual void execute();
+
+protected:
+
+	void extract_resource(Common::File &input, Common::File &output, p_resource res);
+};
+
+#endif


Property changes on: tools/branches/gsoc2009-gui/engines/cruise/extract_cruise_pc.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list