CentrED/ResourceBuilder.pas

76 lines
2.2 KiB
Plaintext
Raw Normal View History

2015-05-01 12:14:15 +02:00
(*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* http://www.opensource.org/licenses/cddl1.php.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* http://www.opensource.org/licenses/cddl1.php. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying * information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Portions Copyright 2007 Andreas Schneider
*)
program ResourceBuilder;
{$mode objfpc}{$H+}
2015-05-01 12:14:15 +02:00
uses
SysUtils, Classes, strutils, Crc32Hash;
2015-05-01 12:14:15 +02:00
var
fileList: TStringList;
infile, outfile: TFileStream;
i, count: Integer;
size: Cardinal;
lookupTable: array of Cardinal;
fnHashTable: array of Cardinal;
2015-05-01 12:14:15 +02:00
begin
if ParamCount <> 2 then
begin
writeln('Usage: ResourceBuilder <FileList> <ResourceFile>');
halt;
end;
fileList := TStringList.Create;
fileList.LoadFromFile(ParamStr(1));
outfile := TFileStream.Create(ParamStr(2), fmCreate);
count := fileList.Count;
outfile.Write(count, SizeOf(Integer));
SetLength(lookupTable, count);
SetLength(fnHashTable, count);
2015-05-01 12:14:15 +02:00
outfile.Write(lookupTable[0], count * SizeOf(Cardinal));
outfile.Write(fnHashTable[0], count * SizeOf(Cardinal));
2015-05-01 12:14:15 +02:00
for i := 0 to count - 1 do
begin
lookupTable[i] := outfile.Position;
CalcStringCRC32(AnsiLowerCase(fileList.Strings[i]), fnHashTable[i]);
writeln(Format('#%.3d 0x%.8x : %s', [i, Int64(fnHashTable[i]), fileList.Strings[i]]));
2015-05-01 12:14:15 +02:00
infile := TFileStream.Create(fileList.Strings[i], fmOpenRead);
infile.Position := 0;
size := infile.Size;
outfile.Write(size, SizeOf(Cardinal));
outfile.CopyFrom(infile, infile.Size);
infile.Free;
end;
outfile.Position := SizeOf(Integer);
outfile.Write(lookupTable[0], count * SizeOf(Cardinal));
outfile.Write(fnHashTable[0], count * SizeOf(Cardinal));
2015-05-01 12:14:15 +02:00
outfile.Free;
fileList.Free;
end.