source: oup/releases/0.18a2/Unit4_Exporters.pas

Last change on this file 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; filename:String);
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 }
49 END;
50
51PROCEDURE ExportDefFileHeader(fileid:LongWord);
52 BEGIN
53 IF NOT DirectoryExists(GetExtractPath) THEN
54 CreateDir(GetExtractPath);
55 WITH dat_files[fileid] DO
56 ExportDefLine(fileid,FormatNumber(fileid,5,'0')+':'+Name+':'+Extension+':'+IntToHex(Size,8)+':'+IntToHex(FileType,8),True);
57 END;
58
59PROCEDURE ExportDatFile(fileid:LongWord; filename:String);
60 VAR
61 filestream:TFileStream;
62 data:Tdata;
63 BEGIN
64 data:=LoadDatFile(fileid);
65 filestream:=TFileStream.Create(filename,fmCreate);
66 filestream.Write(data[0],Length(data));
67 filestream.Free;
68 END;
69
70
71FUNCTION ExportTRAC;
72 VAR
73 link:LongWord;
74 linkcount:Word;
75 i:LongWord;
76 BEGIN
77 Result:=export_noerror;
78
79 LoadDatFilePart(fileid,$18,SizeOf(link),@link);
80 link:=link DIV 256;
81 ExportDefLine(fileid,FormatNumber(0,4,'0')+':LINKtoTRAC:'+FormatNumber(link,5,'0')+':'+dat_files[link].Name+':'+dat_files[link].Extension,False);
82
83 LoadDatFilePart(fileid,$1E,SizeOf(linkcount),@linkcount);
84 ExportDefLine(fileid,'TRAMLINKS:'+FormatNumber(linkcount,4,'0'),False);
85 FOR i:=1 TO linkcount DO BEGIN
86 LoadDatFilePart(fileid,$20+(i-1)*12+8,SizeOf(link),@link);
87 link:=link DIV 256;
88 ExportDefLine(fileid,FormatNumber(i,4,'0')+':LINKtoTRAM:'+FormatNumber(link,5,'0')+':'+dat_files[link].Name+':'+dat_files[link].Extension,False);
89 END;
90 END;
91
92FUNCTION ExportTXAN;
93 VAR
94 loop_speed,unknown:Word;
95 linkcount:LongWord;
96 link:LongWord;
97 i:Byte;
98 BEGIN
99 Result:=export_noerror;
100
101 LoadDatFilePart(fileid,$14,SizeOf(loop_speed),@loop_speed);
102 LoadDatFilePart(fileid,$16,SizeOf(unknown),@unknown);
103 ExportDefLine(fileid,'LOOPSPEED:'+FormatNumber(loop_speed,2,'0'),False);
104 ExportDefLine(fileid,'UNKNOWN:'+FormatNumber(unknown,2,'0'),False);
105
106 LoadDatFilePart(fileid,$1C,SizeOf(linkcount),@linkcount);
107 ExportDefLine(fileid,'TXMPLINKS:'+FormatNumber(linkcount,4,'0'),False);
108 FOR i:=0 TO linkcount-1 DO BEGIN
109 LoadDatFilePart(fileid,$20+i*4,SizeOf(link),@link);
110 link:=link DIV 256;
111 IF link=0 THEN link:=fileid-1;
112 ExportDefLine(fileid,FormatNumber(i,4,'0')+':LINKtoTXMP:'+FormatNumber(link,5,'0')+':'+dat_files[link].Name+':'+dat_files[link].Extension,False);
113 END;
114 END;
115
116FUNCTION ExportTXMB;
117 VAR
118 filestream:TFileStream;
119 subfile:Byte;
120 linkcount:LongWord;
121 link:LongWord;
122 width,height:Word;
123 cols,rows:Word;
124 i:Byte;
125 img:TImgPackage;
126 data:Tdata;
127 BEGIN
128 Result:=export_noerror;
129 subfile:=1;
130
131 LoadDatFilePart(fileid,$10,SizeOf(width),@width);
132 LoadDatFilePart(fileid,$12,SizeOf(height),@height);
133 LoadDatFilePart(fileid,$18,SizeOf(cols),@cols);
134 LoadDatFilePart(fileid,$1A,SizeOf(rows),@rows);
135 ExportDefLine(fileid,'WIDTH:'+FormatNumber(width,4,'0'),False);
136 ExportDefLine(fileid,'HEIGHT:'+FormatNumber(height,4,'0'),False);
137 ExportDefLine(fileid,'COLS:'+FormatNumber(cols,2,'0'),False);
138 ExportDefLine(fileid,'ROWS:'+FormatNumber(rows,2,'0'),False);
139
140 LoadDatFilePart(fileid,$1C,SizeOf(linkcount),@linkcount);
141 ExportDefLine(fileid,'TXMPLINKS:'+FormatNumber(linkcount,4,'0'),False);
142 FOR i:=0 TO linkcount-1 DO BEGIN
143 LoadDatFilePart(fileid,$20+i*4,SizeOf(link),@link);
144 link:=link DIV 256;
145 IF link=0 THEN link:=fileid-1;
146 ExportDefLine(fileid,FormatNumber(i,4,'0')+':LINKtoTXMP:'+FormatNumber(link,5,'0')+':'+dat_files[link].Name+':'+dat_files[link].Extension,False);
147 END;
148
149 IF convert THEN BEGIN
150 img:=LoadTXMBconnected(fileid);
151 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
152 filestream:=TFileStream.Create(GetExtractPath+'\'+GetWinFileName(fileid,FormatNumber(subfile,2,'0')+'-ImgData')+'.bmp',fmCreate);
153 filestream.Write(data[0],Length(data));
154 filestream.Free;
155 END;
156 END;
157
158FUNCTION ExportTXMP;
159 VAR
160 filestream:TFileStream;
161 subfile:Byte;
162 img:TImgPackage;
163 BEGIN
164 Result:=export_noerror;
165 subfile:=1;
166
167 img:=LoadImgData(fileid);
168 {
169 filestream:=TFileStream.Create(GetExtractPath+'\'+GetWinFileName(fileid,FormatNumber(subfile,2,'0')+'-ImgData'),fmCreate);
170 filestream.Write(img.imgdata[0],Length(img.imgdata));
171 filestream.Free;
172 }
173 IF convert THEN BEGIN
174 img.imgdata:=ImgdataToBMP(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
175 filestream:=TFileStream.Create(GetExtractPath+'\'+GetWinFileName(fileid,FormatNumber(subfile,2,'0')+'-ImgData')+'.bmp',fmCreate);
176 filestream.Write(img.imgdata[0],Length(img.imgdata));
177 filestream.Free;
178 END;
179 END;
180
181END.
Note: See TracBrowser for help on using the repository browser.