source: oup/releases/0.13a/Unit4_Exporters.pas@ 219

Last change on this file since 219 was 21, checked in by alloc, 18 years ago
File size: 6.2 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 ExportTXMB(fileid:LongWord; convert:Boolean):Integer;
12FUNCTION ExportTXMP(fileid:LongWord; convert:Boolean):Integer;
13VAR
14 ExportHandlers:Array[1..5] OF TExportHandlers=(
15 (Ext:'ABNA'; needed:False),
16 //(Ext:'AGDB'; needed:False),
17 (Ext:'TRAC'; needed:True; Handler:ExportTRAC),
18 (Ext:'TXAN'; needed:True; Handler:ExportTXAN),
19 (Ext:'TXMB'; needed:True; Handler:ExportTXMB),
20 (Ext:'TXMP'; needed:True; Handler:ExportTXMP)
21 );
22
23
24
25IMPLEMENTATION
26USES Unit2_functions;
27
28PROCEDURE ExportDefLine(fileid:LongWord; line:String; create:Boolean);
29 VAR
30 filestream:TFileStream;
31 data:Tdata;
32 i:LongWord;
33 BEGIN
34 SetLength(data,Length(line)+2);
35 FOR i:=1 TO Length(line) DO
36 data[i-1]:=Ord(line[i]);
37 data[Length(line)]:=13;
38 data[Length(line)+1]:=10;
39
40 IF create THEN
41 filestream:=TFileStream.Create(GetExtractPath+'\'+GetWinFileName(fileid,'_DEF_'),fmCreate)
42 ELSE BEGIN
43 filestream:=TFileStream.Create(GetExtractPath+'\'+GetWinFileName(fileid,'_DEF_'),fmOpenWrite);
44 filestream.Seek(0,soFromEnd);
45 END;
46 filestream.Write(data[0],Length(data));
47 filestream.Free;
48 END;
49
50PROCEDURE ExportDefFileHeader(fileid:LongWord);
51 BEGIN
52 IF NOT DirectoryExists(GetExtractPath) THEN
53 CreateDir(GetExtractPath);
54 WITH dat_files[fileid] DO
55 ExportDefLine(fileid,FormatNumber(fileid,5,'0')+':'+Name+':'+Extension+':'+IntToHex(Size,8)+':'+IntToHex(FileType,8),True);
56 END;
57
58PROCEDURE ExportDatFile(fileid:LongWord);
59 VAR
60 filestream:TFileStream;
61 data:Tdata;
62 BEGIN
63 data:=LoadDatFile(fileid);
64 filestream:=TFileStream.Create(GetExtractPath+'\'+GetWinFileName(fileid,'_DAT_'),fmCreate);
65 filestream.Write(data[0],Length(data));
66 filestream.Free;
67 END;
68
69
70FUNCTION ExportTRAC;
71 VAR
72 link:LongWord;
73 linkcount:Word;
74 i:LongWord;
75 BEGIN
76 Result:=export_noerror;
77
78 LoadDatFilePart(fileid,$18,SizeOf(link),@link);
79 link:=link DIV 256;
80 ExportDefLine(fileid,FormatNumber(0,4,'0')+':LINKtoTRAC:'+FormatNumber(link,5,'0')+':'+dat_files[link].Name+':'+dat_files[link].Extension,False);
81
82 LoadDatFilePart(fileid,$1E,SizeOf(linkcount),@linkcount);
83 ExportDefLine(fileid,'TRAMLINKS:'+FormatNumber(linkcount,4,'0'),False);
84 FOR i:=1 TO linkcount DO BEGIN
85 LoadDatFilePart(fileid,$20+(i-1)*12+8,SizeOf(link),@link);
86 link:=link DIV 256;
87 ExportDefLine(fileid,FormatNumber(i,4,'0')+':LINKtoTRAM:'+FormatNumber(link,5,'0')+':'+dat_files[link].Name+':'+dat_files[link].Extension,False);
88 END;
89 END;
90
91FUNCTION ExportTXAN;
92 VAR
93 loop_speed,unknown:Word;
94 linkcount:LongWord;
95 link:LongWord;
96 i:Byte;
97 BEGIN
98 Result:=export_noerror;
99
100 LoadDatFilePart(fileid,$14,SizeOf(loop_speed),@loop_speed);
101 LoadDatFilePart(fileid,$16,SizeOf(unknown),@unknown);
102 ExportDefLine(fileid,'LOOPSPEED:'+FormatNumber(loop_speed,2,'0'),False);
103 ExportDefLine(fileid,'UNKNOWN:'+FormatNumber(unknown,2,'0'),False);
104
105 LoadDatFilePart(fileid,$1C,SizeOf(linkcount),@linkcount);
106 ExportDefLine(fileid,'TXMPLINKS:'+FormatNumber(linkcount,4,'0'),False);
107 FOR i:=0 TO linkcount-1 DO BEGIN
108 LoadDatFilePart(fileid,$20+i*4,SizeOf(link),@link);
109 link:=link DIV 256;
110 IF link=0 THEN link:=fileid-1;
111 ExportDefLine(fileid,FormatNumber(i,4,'0')+':LINKtoTXMP:'+FormatNumber(link,5,'0')+':'+dat_files[link].Name+':'+dat_files[link].Extension,False);
112 END;
113 END;
114
115FUNCTION ExportTXMB;
116 VAR
117 filestream:TFileStream;
118 subfile:Byte;
119 linkcount:LongWord;
120 link:LongWord;
121 width,height:Word;
122 cols,rows:Word;
123 i:Byte;
124 img:TImgPackage;
125 data:Tdata;
126 BEGIN
127 Result:=export_noerror;
128 subfile:=1;
129
130 LoadDatFilePart(fileid,$10,SizeOf(width),@width);
131 LoadDatFilePart(fileid,$12,SizeOf(height),@height);
132 LoadDatFilePart(fileid,$18,SizeOf(cols),@cols);
133 LoadDatFilePart(fileid,$1A,SizeOf(rows),@rows);
134 ExportDefLine(fileid,'WIDTH:'+FormatNumber(width,4,'0'),False);
135 ExportDefLine(fileid,'HEIGHT:'+FormatNumber(height,4,'0'),False);
136 ExportDefLine(fileid,'COLS:'+FormatNumber(cols,2,'0'),False);
137 ExportDefLine(fileid,'ROWS:'+FormatNumber(rows,2,'0'),False);
138
139 LoadDatFilePart(fileid,$1C,SizeOf(linkcount),@linkcount);
140 ExportDefLine(fileid,'TXMPLINKS:'+FormatNumber(linkcount,4,'0'),False);
141 FOR i:=0 TO linkcount-1 DO BEGIN
142 LoadDatFilePart(fileid,$20+i*4,SizeOf(link),@link);
143 link:=link DIV 256;
144 IF link=0 THEN link:=fileid-1;
145 ExportDefLine(fileid,FormatNumber(i,4,'0')+':LINKtoTXMP:'+FormatNumber(link,5,'0')+':'+dat_files[link].Name+':'+dat_files[link].Extension,False);
146 END;
147
148 IF convert THEN BEGIN
149 img:=LoadTXMBconnected(fileid);
150 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
151 filestream:=TFileStream.Create(GetExtractPath+'\'+GetWinFileName(fileid,FormatNumber(subfile,2,'0')+'-ImgData')+'.bmp',fmCreate);
152 filestream.Write(data[0],Length(data));
153 filestream.Free;
154 END;
155 END;
156
157FUNCTION ExportTXMP;
158 VAR
159 filestream:TFileStream;
160 subfile:Byte;
161 img:TImgPackage;
162 BEGIN
163 Result:=export_noerror;
164 subfile:=1;
165
166 img:=LoadImgData(fileid);
167
168 filestream:=TFileStream.Create(GetExtractPath+'\'+GetWinFileName(fileid,FormatNumber(subfile,2,'0')+'-ImgData'),fmCreate);
169 filestream.Write(img.imgdata[0],Length(img.imgdata));
170 filestream.Free;
171
172 IF convert THEN BEGIN
173 img.imgdata:=ImgdataToBMP(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
174 filestream:=TFileStream.Create(GetExtractPath+'\'+GetWinFileName(fileid,FormatNumber(subfile,2,'0')+'-ImgData')+'.bmp',fmCreate);
175 filestream.Write(img.imgdata[0],Length(img.imgdata));
176 filestream.Free;
177 END;
178 END;
179
180END.
Note: See TracBrowser for help on using the repository browser.