DEADSOFTWARE

added dfwad -> pk3 converter
[d2df-sdl.git] / src / sfs / wadcvt.dpr
1 {$IFDEF WIN32}
2 {$APPTYPE CONSOLE}
3 {$ENDIF}
4 {$MODE DELPHI}
5 program __wadcvt__;
7 uses
8 SysUtils,
9 Classes,
10 SDL2 in '../lib/sdl2/sdl2.pas',
11 sfs,
12 sfsPlainFS,
13 sfsZipFS,
14 sfsMemFS,
15 zipper;
18 var
19 fs: TStream;
20 fl: TSFSFileList;
21 f: Integer;
22 infname: string;
23 outfname: string;
24 zip: TZipper;
25 dvfn: string;
26 ZEntries: TZipFileEntries;
27 begin
28 if ParamCount() < 1 then
29 begin
30 WriteLn('usage: wadcvt file.wad');
31 Halt(1);
32 end;
34 infname := ParamStr(1);
35 if not SFSStrEqu(ExtractFileExt(infname), '.wad') and not SFSStrEqu(ExtractFileExt(infname), '.dfwad') then
36 begin
37 writeln('wtf?!');
38 Halt(1);
39 end;
41 if ParamCount() > 1 then
42 begin
43 outfname := ParamStr(2);
44 end
45 else
46 begin
47 outfname := ChangeFileExt(infname, '.pk3');
48 end;
50 if not SFSAddDataFile(infname) then begin WriteLn('shit!'); Halt(1); end;
51 dvfn := SFSGetLastVirtualName(infname);
53 {
54 tot := 0;
55 fl := SFSFileList(ParamStr(1));
56 if fl <> nil then
57 begin
58 for f := 0 to fl.Count-1 do
59 begin
60 WriteLn(f:4, ': ', fl[f].fSize:10, ' "', fl[f].fPath, fl[f].fName, '"');
61 Inc(tot, fl[f].fSize);
62 end;
63 WriteLn('===================================================');
64 WriteLn(fl.Count, ' files; ', Int64ToStrComma(tot), ' bytes.');
65 fl.Free();
66 end;
67 }
69 zip := TZipper.Create;
70 zip.Filename := outfname;
72 fl := SFSFileList(dvfn);
73 if fl <> nil then
74 begin
75 ZEntries := TZipFileEntries.Create(TZipFileEntry);
76 for f := 0 to fl.Count-1 do
77 begin
78 if length(fl[f].fName) = 0 then continue;
79 fs := SFSFileOpen(dvfn+'::'+fl[f].fPath+fl[f].fName);
80 writeln('[', f+1, '/', fl.Count, ']: ', fl[f].fPath+fl[f].fName, ' ', fs.size);
81 ZEntries.AddFileEntry(fs, fl[f].fPath+fl[f].fName);
82 end;
83 try
84 if ZEntries.Count > 0 then
85 begin
86 writeln('creating ''', outfname, '''');
87 zip.ZipFiles(ZEntries);
88 end;
89 except
90 on E: EZipError do E.CreateFmt('Zipfile could not be created%sReason: %s', [LineEnding, E.Message])
91 end;
92 end
93 else
94 begin
95 writeln('SFSFileList(): faled!');
96 end;
97 end.