Statistics
| Branch: | Tag: | Revision:

root / ResourceBuilder.pas

History | View | Annotate | Download (1.9 kB)

1 162:ac18d757e2cd aksdb
(*
2 162:ac18d757e2cd aksdb
 * CDDL HEADER START
3 162:ac18d757e2cd aksdb
 *
4 162:ac18d757e2cd aksdb
 * The contents of this file are subject to the terms of the
5 162:ac18d757e2cd aksdb
 * Common Development and Distribution License, Version 1.0 only
6 162:ac18d757e2cd aksdb
 * (the "License").  You may not use this file except in compliance
7 162:ac18d757e2cd aksdb
 * with the License.
8 162:ac18d757e2cd aksdb
 *
9 162:ac18d757e2cd aksdb
 * You can obtain a copy of the license at
10 162:ac18d757e2cd aksdb
 * http://www.opensource.org/licenses/cddl1.php.
11 162:ac18d757e2cd aksdb
 * See the License for the specific language governing permissions
12 162:ac18d757e2cd aksdb
 * and limitations under the License.
13 162:ac18d757e2cd aksdb
 *
14 162:ac18d757e2cd aksdb
 * When distributing Covered Code, include this CDDL HEADER in each
15 162:ac18d757e2cd aksdb
 * file and include the License file at
16 162:ac18d757e2cd aksdb
 * http://www.opensource.org/licenses/cddl1.php.  If applicable,
17 162:ac18d757e2cd aksdb
 * add the following below this CDDL HEADER, with the fields enclosed
18 162:ac18d757e2cd aksdb
 * by brackets "[]" replaced with your own identifying * information:
19 162:ac18d757e2cd aksdb
 *      Portions Copyright [yyyy] [name of copyright owner]
20 162:ac18d757e2cd aksdb
 *
21 162:ac18d757e2cd aksdb
 * CDDL HEADER END
22 162:ac18d757e2cd aksdb
 *
23 162:ac18d757e2cd aksdb
 *
24 162:ac18d757e2cd aksdb
 *      Portions Copyright 2007 Andreas Schneider
25 162:ac18d757e2cd aksdb
 *)
26 162:ac18d757e2cd aksdb
program ResourceBuilder;
27 162:ac18d757e2cd aksdb
28 162:ac18d757e2cd aksdb
{$mode objfpc}{$H+}
29 162:ac18d757e2cd aksdb
30 162:ac18d757e2cd aksdb
uses
31 162:ac18d757e2cd aksdb
        SysUtils, Classes;
32 162:ac18d757e2cd aksdb
33 162:ac18d757e2cd aksdb
var
34 162:ac18d757e2cd aksdb
        fileList: TStringList;
35 162:ac18d757e2cd aksdb
        infile, outfile: TFileStream;
36 162:ac18d757e2cd aksdb
        i, count: Integer;
37 162:ac18d757e2cd aksdb
        size: Cardinal;
38 162:ac18d757e2cd aksdb
        lookupTable: array of Cardinal;
39 162:ac18d757e2cd aksdb
40 162:ac18d757e2cd aksdb
begin
41 162:ac18d757e2cd aksdb
        if ParamCount <> 2 then
42 162:ac18d757e2cd aksdb
        begin
43 162:ac18d757e2cd aksdb
          writeln('Usage: ResourceBuilder <FileList> <ResourceFile>');
44 162:ac18d757e2cd aksdb
          halt;
45 162:ac18d757e2cd aksdb
        end;
46 162:ac18d757e2cd aksdb
47 162:ac18d757e2cd aksdb
        fileList := TStringList.Create;
48 162:ac18d757e2cd aksdb
        fileList.LoadFromFile(ParamStr(1));
49 162:ac18d757e2cd aksdb
        outfile := TFileStream.Create(ParamStr(2), fmCreate);
50 162:ac18d757e2cd aksdb
        count := fileList.Count;
51 162:ac18d757e2cd aksdb
        outfile.Write(count, SizeOf(Integer));
52 162:ac18d757e2cd aksdb
        SetLength(lookupTable, count);
53 162:ac18d757e2cd aksdb
        outfile.Write(lookupTable[0], count * SizeOf(Cardinal));
54 162:ac18d757e2cd aksdb
        for i := 0 to count - 1 do
55 162:ac18d757e2cd aksdb
        begin
56 162:ac18d757e2cd aksdb
          lookupTable[i] := outfile.Position;
57 162:ac18d757e2cd aksdb
          writeln(i, ': ', fileList.Strings[i]);
58 162:ac18d757e2cd aksdb
          infile := TFileStream.Create(fileList.Strings[i], fmOpenRead);
59 162:ac18d757e2cd aksdb
          infile.Position := 0;
60 162:ac18d757e2cd aksdb
          size := infile.Size;
61 162:ac18d757e2cd aksdb
          outfile.Write(size, SizeOf(Cardinal));
62 162:ac18d757e2cd aksdb
          outfile.CopyFrom(infile, infile.Size);
63 162:ac18d757e2cd aksdb
          infile.Free;
64 162:ac18d757e2cd aksdb
        end;
65 162:ac18d757e2cd aksdb
        outfile.Position := SizeOf(Integer);
66 162:ac18d757e2cd aksdb
        outfile.Write(lookupTable[0], count * SizeOf(Cardinal));
67 162:ac18d757e2cd aksdb
        outfile.Free;
68 162:ac18d757e2cd aksdb
        fileList.Free;
69 162:ac18d757e2cd aksdb
end.