source: oup/releases/0.11a/Unit4_Exporters.pas@ 398

Last change on this file since 398 was 19, checked in by alloc, 18 years ago
File size: 4.5 KB
Line 
1UNIT Unit4_Exporters;
2INTERFACE
3USES Classes, StrUtils, SysUtils, Math, Unit3_data, Unit6_imgfuncs;
4
5PROCEDURE ExportDefLine(fileid:LongWord; line:String; create:Boolean);
6PROCEDURE ExportDefFileHeader(fileid:LongWord);
7PROCEDURE ExportDatFile(fileid:LongWord);
8
9FUNCTION ExportTRAC(fileid:LongWord; convert:Boolean):Integer;
10FUNCTION ExportTXAN(fileid:LongWord; convert:Boolean):Integer;
11FUNCTION ExportTXMP(fileid:LongWord; convert:Boolean):Integer;
12VAR
13 ExportHandlers:Array[1..4] OF TExportHandlers=(
14 (Ext:'ABNA'; needed:False),
15 //(Ext:'AGDB'; needed:False),
16 (Ext:'TRAC'; needed:True; Handler:ExportTRAC),
17 (Ext:'TXAN'; needed:True; Handler:ExportTXAN),
18 (Ext:'TXMP'; needed:True; Handler:ExportTXMP)
19 );
20
21
22
23IMPLEMENTATION
24USES Unit2_functions;
25
26PROCEDURE ExportDefLine(fileid:LongWord; line:String; create:Boolean);
27 VAR
28 filestream:TFileStream;
29 data:Tdata;
30 i:LongWord;
31 BEGIN
32 SetLength(data,Length(line)+2);
33 FOR i:=1 TO Length(line) DO
34 data[i-1]:=Ord(line[i]);
35 data[Length(line)]:=13;
36 data[Length(line)+1]:=10;
37
38 IF create THEN
39 filestream:=TFileStream.Create(GetExtractPath+'\'+GetWinFileName(fileid,'_DEF_'),fmCreate)
40 ELSE BEGIN
41 filestream:=TFileStream.Create(GetExtractPath+'\'+GetWinFileName(fileid,'_DEF_'),fmOpenWrite);
42 filestream.Seek(0,soFromEnd);
43 END;
44 filestream.Write(data[0],Length(data));
45 filestream.Free;
46 END;
47
48PROCEDURE ExportDefFileHeader(fileid:LongWord);
49 BEGIN
50 IF NOT DirectoryExists(GetExtractPath) THEN
51 CreateDir(GetExtractPath);
52 WITH dat_files[fileid] DO
53 ExportDefLine(fileid,FormatNumber(fileid,5,'0')+':'+Name+':'+Extension+':'+IntToHex(Size,8)+':'+IntToHex(FileType,8),True);
54 END;
55
56PROCEDURE ExportDatFile(fileid:LongWord);
57 VAR
58 filestream:TFileStream;
59 data:Tdata;
60 BEGIN
61 data:=LoadDatFile(fileid);
62 filestream:=TFileStream.Create(GetExtractPath+'\'+GetWinFileName(fileid,'_DAT_'),fmCreate);
63 filestream.Write(data[0],Length(data));
64 filestream.Free;
65 END;
66
67
68FUNCTION ExportTRAC;
69 VAR
70 link:LongWord;
71 linkcount:Word;
72 i:LongWord;
73 BEGIN
74 Result:=export_noerror;
75
76 LoadDatFilePart(fileid,$18,SizeOf(link),@link);
77 link:=link DIV 256;
78 ExportDefLine(fileid,FormatNumber(0,4,'0')+':LINKtoTRAC:'+FormatNumber(link,5,'0')+':'+dat_files[link].Name+':'+dat_files[link].Extension,False);
79
80 LoadDatFilePart(fileid,$1E,SizeOf(linkcount),@linkcount);
81 ExportDefLine(fileid,'TRAMLINKS:'+FormatNumber(linkcount,4,'0'),False);
82 FOR i:=1 TO linkcount DO BEGIN
83 LoadDatFilePart(fileid,$20+(i-1)*12+8,SizeOf(link),@link);
84 link:=link DIV 256;
85 ExportDefLine(fileid,FormatNumber(i,4,'0')+':LINKtoTRAM:'+FormatNumber(link,5,'0')+':'+dat_files[link].Name+':'+dat_files[link].Extension,False);
86 END;
87 END;
88
89FUNCTION ExportTXAN;
90 VAR
91 loop_speed,unknown:Word;
92 linkcount:LongWord;
93 link:LongWord;
94 i:Byte;
95 BEGIN
96 Result:=export_noerror;
97
98 LoadDatFilePart(fileid,$14,SizeOf(loop_speed),@loop_speed);
99 LoadDatFilePart(fileid,$16,SizeOf(unknown),@unknown);
100 ExportDefLine(fileid,'LOOPSPEED:'+FormatNumber(loop_speed,2,'0'),False);
101 ExportDefLine(fileid,'UNKNOWN:'+FormatNumber(unknown,2,'0'),False);
102
103 LoadDatFilePart(fileid,$1C,SizeOf(linkcount),@linkcount);
104 ExportDefLine(fileid,'TXMPLINKS:'+FormatNumber(linkcount,4,'0'),False);
105 FOR i:=0 TO linkcount-1 DO BEGIN
106 LoadDatFilePart(fileid,$20+i*4,SizeOf(link),@link);
107 link:=link DIV 256;
108 IF link=0 THEN link:=fileid-1;
109 ExportDefLine(fileid,FormatNumber(i,4,'0')+':LINKtoTXMP:'+FormatNumber(link,5,'0')+':'+dat_files[link].Name+':'+dat_files[link].Extension,False);
110 END;
111 END;
112
113FUNCTION ExportTXMP;
114 VAR
115 filestream:TFileStream;
116 subfile:Byte;
117 img:TImgPackage;
118 BEGIN
119 Result:=export_noerror;
120 subfile:=1;
121
122 img:=LoadImgData(fileid);
123
124 filestream:=TFileStream.Create(GetExtractPath+'\'+GetWinFileName(fileid,FormatNumber(subfile,2,'0')+'-ImgData'),fmCreate);
125 filestream.Write(img.imgdata[0],Length(img.imgdata));
126 filestream.Free;
127
128 IF convert THEN BEGIN
129 img.imgdata:=ImgdataToBMP(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
130 filestream:=TFileStream.Create(GetExtractPath+'\'+GetWinFileName(fileid,FormatNumber(subfile,2,'0')+'-ImgData')+'.bmp',fmCreate);
131 filestream.Write(img.imgdata[0],Length(img.imgdata));
132 filestream.Free;
133 END;
134 END;
135
136END.
Note: See TracBrowser for help on using the repository browser.