source: oup/releases/0.16a/Unit1_main.pas@ 619

Last change on this file since 619 was 21, checked in by alloc, 18 years ago
File size: 14.5 KB
Line 
1UNIT Unit1_main;
2INTERFACE
3USES
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus,
6 Unit2_functions, Unit3_data, Unit5_preview, Unit7_txmpreplace, Unit8_binedit,
7 Grids, MPHexEditor;
8
9TYPE
10 TForm1 = Class(TForm)
11 panel_all: TPanel;
12 panel_left: TPanel;
13 Splitter1: TSplitter;
14 panel_files: TPanel;
15 btn_extractconvert: TButton;
16 list_files: TListBox;
17 list_extensions: TListBox;
18 Splitter2: TSplitter;
19 fopen: TOpenDialog;
20 group_progress: TGroupBox;
21 progress: TProgressBar;
22 lbl_progress: TLabel;
23 menu: TMainMenu;
24 menu_main: TMenuItem;
25 menu_exit: TMenuItem;
26 menu_preview: TMenuItem;
27 btn_extractcancel: TButton;
28 menu_tools: TMenuItem;
29 menu_txmpreplace: TMenuItem;
30 menu_extract: TMenuItem;
31 menu_extractfile: TMenuItem;
32 menu_extractlist: TMenuItem;
33 menu_extractall: TMenuItem;
34 menu_loaddat: TMenuItem;
35 menu_sep1: TMenuItem;
36 menu_binedit: TMenuItem;
37 statbar: TStatusBar;
38 panel_file: TPanel;
39 lbl_fileinfo: TLabel;
40 hex: TMPHexEditor;
41 lbl_zerobyte: TLabel;
42 PROCEDURE menu_extractallClick(Sender: TObject);
43 PROCEDURE menu_extractlistClick(Sender: TObject);
44 PROCEDURE menu_extractfileClick(Sender: TObject);
45 PROCEDURE menu_bineditClick(Sender: TObject);
46 PROCEDURE menu_loaddatClick(Sender: TObject);
47 PROCEDURE menu_txmpreplaceClick(Sender: TObject);
48 PROCEDURE menu_exitClick(Sender: TObject);
49 PROCEDURE btn_extractcancelClick(Sender: TObject);
50 PROCEDURE menu_previewClick(Sender: TObject);
51 PROCEDURE Splitter1Moved(Sender: TObject);
52 PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
53 PROCEDURE btn_hexcopyClick(Sender: TObject);
54 PROCEDURE list_extensionsClick(Sender: TObject);
55 PROCEDURE FormResize(Sender: TObject);
56 PROCEDURE btn_extractconvertClick(Sender: TObject);
57 PROCEDURE FormCreate(Sender: TObject);
58 PROCEDURE list_filesDblClick(Sender: TObject);
59 PROCEDURE btn_loadClick(Sender: TObject);
60 PRIVATE
61 PUBLIC
62 END;
63
64VAR
65 Form1: TForm1;
66
67IMPLEMENTATION
68{$R *.dfm}
69
70PROCEDURE DoAfterLoadOfADat;
71 VAR
72 i:LongWord;
73 txt:Text;
74 temp4:LongWord;
75 temp2:Word;
76 temp1:Byte;
77 BEGIN
78 IF NOT DirectoryExists(GetExtractPath) THEN
79 CreateDir(GetExtractPath);
80 AssignFile(txt,GetExtractPath+'\___TXMP-FILES___.TXT');
81 ReWrite(txt);
82 FOR i:=0 TO dat_header.Extensions-1 DO BEGIN
83 IF (dat_extensionsmap[i].Extension[3]='T') AND
84 (dat_extensionsmap[i].Extension[2]='X') AND
85 (dat_extensionsmap[i].Extension[1]='M') AND
86 (dat_extensionsmap[i].Extension[0]='P') THEN BEGIN
87 WriteLn(txt, FormatNumber(dat_extensionsmap[i].ExtCount,4,'0')+' TXMP-Files');
88 Break;
89 END;
90 END;
91 WriteLn(txt,'FileName'+#9+'MipMap'+#9+'Depth'+#9+'ImgX'+#9+'ImgY'+#9+'StoreT');
92 FOR i:=0 TO dat_header.Files-1 DO BEGIN
93 IF dat_files[i].Extension='TXMP' THEN BEGIN
94 Write(txt,dat_files[i].FileName+#9);
95 LoadDatFilePart(i,$88,1,@temp1);
96 Write(txt,IntToHex(temp1,2)+#9);
97 LoadDatFilePart(i,$89,1,@temp1);
98 Write(txt,IntToHex(temp1,2)+#9);
99 LoadDatFilePart(i,$8C,2,@temp2);
100 Write(txt,IntToHex(temp2,4)+#9);
101 LoadDatFilePart(i,$8E,2,@temp2);
102 Write(txt,IntToHex(temp2,4)+#9);
103 LoadDatFilePart(i,$90,1,@temp1);
104 Write(txt,IntToHex(temp1,2)+#9);
105 WriteLn(txt,'');
106 END;
107 END;
108 CloseFile(txt);
109
110 IF NOT DirectoryExists(GetExtractPath) THEN
111 CreateDir(GetExtractPath);
112 AssignFile(txt,GetExtractPath+'\___TXAN-FILES___.TXT');
113 ReWrite(txt);
114 FOR i:=0 TO dat_header.Extensions-1 DO BEGIN
115 IF (dat_extensionsmap[i].Extension[3]='T') AND
116 (dat_extensionsmap[i].Extension[2]='X') AND
117 (dat_extensionsmap[i].Extension[1]='A') AND
118 (dat_extensionsmap[i].Extension[0]='N') THEN BEGIN
119 WriteLn(txt, FormatNumber(dat_extensionsmap[i].ExtCount,4,'0')+' TXAN-Files');
120 Break;
121 END;
122 END;
123 WriteLn(txt,'FileName'+#9+'Loopspeed'+#9+'Unknown'+#9+'Links');
124 FOR i:=0 TO dat_header.Files-1 DO BEGIN
125 IF dat_files[i].Extension='TXAN' THEN BEGIN
126 Write(txt,dat_files[i].FileName+#9);
127 LoadDatFilePart(i,$14,2,@temp2);
128 Write(txt,IntToHex(temp2,4)+#9);
129 LoadDatFilePart(i,$16,2,@temp2);
130 Write(txt,IntToHex(temp2,4)+#9);
131 LoadDatFilePart(i,$1C,4,@temp4);
132 Write(txt,IntToHex(temp4,8)+#9);
133 WriteLn(txt,'');
134 END;
135 END;
136 CloseFile(txt);
137 END;
138
139PROCEDURE LoadDat;
140 VAR i:LongWord;
141 BEGIN
142 Form1.fopen.InitialDir:=AppSettings.DatPath;
143 IF Form1.fopen.Execute THEN BEGIN
144 Form1.Caption:='Oni Un/Packer '+version+' ('+ExtractFileName(Form1.fopen.FileName)+')';
145 AppSettings.DatPath:=ExtractFilepath(Form1.fopen.FileName);
146 Form1.list_files.Items.Clear;
147 Form1.list_extensions.Items.Clear;
148 IF LoadDatInfos(Form1.fopen.FileName) THEN BEGIN
149 Form1.list_extensions.Items.Add('_All files: '+FormatNumber(dat_header.Files,4,' '));
150 FOR i:=0 TO dat_header.Extensions-1 DO BEGIN
151 WITH dat_extensionsmap[i] DO BEGIN
152 Form1.list_extensions.Items.Add(
153 Extension[3]+Extension[2]+Extension[1]+Extension[0]+': '+
154 FormatNumber(ExtCount,4,' '));{+' (Ident: 0x'+
155 IntToHex(Ident[7],2)+IntToHex(Ident[6],2)+IntToHex(Ident[5],2)+IntToHex(Ident[4],2)+IntToHex(Ident[3],2)+IntToHex(Ident[2],2)+IntToHex(Ident[1],2)+IntToHex(Ident[0],2)+')');}
156 END;
157 END;
158 Form1.list_extensions.ItemIndex:=0;
159 Form1.list_extensionsClick(Form1);
160 Form1.list_files.ItemIndex:=0;
161 Form1.list_filesDblClick(Form1);
162 Form1.statbar.Panels.Items[0].Text:='Current .dat: '+dat_FileName;
163 Form1.statbar.Panels.Items[1].Text:='Files: '+IntToStr(dat_header.Files);
164 Form1.statbar.Panels.Items[2].Text:='Extensions: '+IntToStr(dat_header.Extensions);
165 Form1.menu_tools.Enabled:=True;
166 Form1.menu_extract.Enabled:=True;
167 Form1.btn_extractconvert.Enabled:=True;
168
169 Form7.RecreateTXMPlist;
170 Form8.Recreatelist;
171
172 DoAfterLoadOfADat;
173
174 END ELSE BEGIN
175 ShowMessage('Error while loading the file:'+CrLf+Form1.fopen.FileName+CrLf+'Perhaps not an Oni-.dat-file?');
176 END;
177 END;
178 END;
179
180PROCEDURE TForm1.btn_loadClick(Sender: TObject);
181 BEGIN
182 LoadDat;
183 END;
184
185PROCEDURE TForm1.list_filesDblClick(Sender: TObject);
186 VAR
187 id:LongWord;
188 temp:Tdata;
189 mem:TMemoryStream;
190 BEGIN
191 id:=StrToInt(MidStr(list_files.Items.Strings[list_files.ItemIndex],1,5));
192 IF (dat_files[id].FileType AND $02)=0 THEN BEGIN
193 lbl_fileinfo.Caption:=
194 'Filename: '+dat_files[id].FileName+CrLf+
195 'Size: '+FormatFileSize(dat_files[id].Size)+' ('+IntToStr(dat_files[id].Size)+' Bytes)'+CrLf+
196 'Address in .dat: 0x'+IntTohex(dat_files[id].DatAddr,8);
197 temp:=LoadDatFile(id);
198 mem:=TMemoryStream.Create;
199 mem.Write(temp[0],Length(temp));
200 hex.LoadFromStream(mem);
201 mem.Free;
202 Form5.ShowPreview(id);
203 lbl_zerobyte.Visible:=False;
204 hex.Visible:=True;
205 END ELSE BEGIN
206 lbl_fileinfo.Caption:=
207 'Filename: '+dat_files[id].FileName;
208 lbl_zerobyte.Visible:=True;
209 hex.Visible:=False;
210 END;
211 END;
212
213PROCEDURE TForm1.FormCreate(Sender: TObject);
214 BEGIN
215 Form1.Caption:='Oni Un/Packer '+version;
216 Form1.FormResize(Form1);
217
218 panel_all.Align:=alClient;
219
220 IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN BEGIN
221 AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini');
222 Reset(AppSettingsFile);
223 Read(AppSettingsFile,AppSettings);
224 CloseFile(AppSettingsFile);
225 END ELSE BEGIN
226 AppSettings.DatPath:='D:\Spiele\Oni\GameDataFolder';
227 AppSettings.ExtractPath:='C:\Dokumente und Einstellungen\Administrator\Desktop';
228 END;
229 END;
230
231PROCEDURE TForm1.btn_extractconvertClick(Sender: TObject);
232 BEGIN
233 Form1.menu_extractfileClick(Form1);
234 END;
235
236PROCEDURE TForm1.FormResize(Sender: TObject);
237 CONST
238 MinWidth:Integer=750;
239 MinHeight:Integer=500;
240 BEGIN
241 IF NOT group_progress.Visible THEN BEGIN
242 IF Form1.Width<MinWidth THEN Form1.Width:=MinWidth;
243 IF Form1.Height<MinHeight THEN Form1.Height:=MinHeight;
244 Form1.statbar.Panels.Items[0].Width:=Form1.Width-200;
245 END ELSE BEGIN
246 Form1.Width:=400;
247 Form1.Height:=120;
248 END;
249 END;
250
251PROCEDURE TForm1.list_extensionsClick(Sender: TObject);
252 VAR
253 Extension:String[4];
254 i:LongWord;
255 BEGIN
256 Extension:=MidStr(list_extensions.Items.Strings[list_extensions.ItemIndex],1,4);
257 list_files.Items.Clear;
258 IF Extension='_All' THEN BEGIN
259 FOR i:=0 TO dat_header.Files-1 DO
260 list_files.Items.Add(dat_files[i].FileName);
261 END ELSE BEGIN
262 FOR i:=0 TO dat_header.Files-1 DO
263 IF dat_files[i].Extension=Extension THEN
264 list_files.Items.Add(dat_files[i].FileName);
265 END;
266 END;
267
268PROCEDURE TForm1.btn_hexcopyClick(Sender: TObject);
269 VAR
270 temp:Tdata;
271 BEGIN
272 temp:=LoadDatFile(StrToInt(MidStr(list_files.Items.Strings[list_files.ItemIndex],1,5)));
273 Clipboard.SetTextBuf(PChar(CreateHexString(temp,True)));
274 END;
275
276PROCEDURE TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
277 BEGIN
278 AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini');
279 IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN
280 Reset(AppSettingsFile)
281 ELSE
282 Rewrite(AppSettingsFile);
283 Write(AppSettingsFile,AppSettings);
284 CloseFile(AppSettingsFile);
285 END;
286
287PROCEDURE TForm1.Splitter1Moved(Sender: TObject);
288 BEGIN
289 Form1.list_files.Height:=Form1.Splitter1.Top-23;
290 Form1.btn_extractconvert.Top:=Form1.Splitter1.Top-21;
291 END;
292
293PROCEDURE TForm1.menu_previewClick(Sender: TObject);
294 BEGIN
295 Form5.Visible:=NOT Form5.Visible;
296 END;
297
298PROCEDURE TForm1.btn_extractcancelClick(Sender: TObject);
299 BEGIN
300 btn_extractcancel.Caption:='Cancel_';
301 END;
302
303PROCEDURE TForm1.menu_exitClick(Sender: TObject);
304 BEGIN
305 Form1.Close;
306 END;
307
308PROCEDURE TForm1.menu_txmpreplaceClick(Sender: TObject);
309 BEGIN
310 Form7.Visible:=NOT Form7.Visible;
311 END;
312
313PROCEDURE TForm1.menu_loaddatClick(Sender: TObject);
314 BEGIN
315 LoadDat;
316 END;
317
318PROCEDURE TForm1.menu_bineditClick(Sender: TObject);
319 BEGIN
320 Form8.Visible:=NOT Form8.Visible;
321 END;
322
323PROCEDURE TForm1.menu_extractfileClick(Sender: TObject);
324 VAR
325 result:Integer;
326 id:LongWord;
327 BEGIN
328 id:=StrToInt(MidStr(list_files.Items.Strings[list_files.ItemIndex],1,5));
329 result:=ExportFile(id,True);
330 CASE result OF
331 0{export_noerror}: BEGIN END;
332 1{export_nohandler}: ShowMessage('No export-handler for files with extension '+dat_files[id].Extension+'.');
333 2{export_handlererror}: ShowMessage('Error while running data-handler for '+CrLf+dat_files[id].FileName);
334 3{export_error}: ShowMessage('Error while exporting file '+CrLf+dat_files[id].FileName);
335 ELSE
336 ShowMessage('Couldn''t export file '+FormatNumber(id,5,'0')+CrLf+'(Unknown error)');
337 END;
338 Form1.list_files.SetFocus;
339 END;
340
341PROCEDURE TForm1.menu_extractlistClick(Sender: TObject);
342 VAR
343 i:LongWord;
344 errors:LongWord;
345 oldwidth,oldheight:Integer;
346 oldstate:TWindowState;
347 BEGIN
348 panel_all.Visible:=False;
349 group_progress.Visible:=True;
350 //FOR i:=0 TO menu.ComponentCount DO menu.Items.Items[i].Enabled:=False;
351 oldwidth:=Form1.Width;
352 oldheight:=Form1.Height;
353 oldstate:=Form1.WindowState;
354 Form1.WindowState:=wsNormal;
355 Form1.Width:=400;
356 Form1.Height:=120;
357 group_progress.Left:=0;
358 group_progress.Top:=0;
359 group_progress.Width:=Form1.Width-8;
360 progress.Width:=group_progress.Width-80;
361 progress.Max:=list_files.Items.Count;
362 btn_extractcancel.Left:=group_progress.Width-65;
363 btn_extractcancel.Caption:='Cancel';
364 btn_extractcancel.SetFocus;
365
366 errors:=0;
367 FOR i:=0 TO progress.Max-1 DO BEGIN
368 IF ExportFile(StrToInt(MidStr(list_files.Items.Strings[i],1,5)),True)>0 THEN Inc(errors);
369 IF (i MOD 25)=0 THEN BEGIN
370 lbl_progress.Caption:=IntToStr(i)+'/'+IntToStr(progress.Max);
371 progress.Position:=i;
372 Application.ProcessMessages;
373 IF btn_extractcancel.Caption='Cancel_' THEN BEGIN
374 btn_extractcancel.Caption:='Cancel';
375 Break;
376 END;
377 END;
378 END;
379 IF errors>0 THEN
380 ShowMessage(IntToStr(errors)+' errors encountered.');
381
382 group_progress.Visible:=False;
383 Form1.Width:=oldwidth;
384 Form1.Height:=oldheight;
385 Form1.WindowState:=oldstate;
386 //FOR i:=0 TO menu.ComponentCount DO menu.Items.Items[i].Enabled:=True;
387 panel_all.Visible:=True;
388 END;
389
390PROCEDURE TForm1.menu_extractallClick(Sender: TObject);
391 VAR
392 i:LongWord;
393 errors:LongWord;
394 oldwidth,oldheight:Integer;
395 oldstate:TWindowState;
396 BEGIN
397 panel_all.Visible:=False;
398 group_progress.Visible:=True;
399 //FOR i:=0 TO menu.ComponentCount DO menu.Items.Items[i].Enabled:=False;
400 oldwidth:=Form1.Width;
401 oldheight:=Form1.Height;
402 oldstate:=Form1.WindowState;
403 Form1.WindowState:=wsNormal;
404 Form1.Width:=400;
405 Form1.Height:=120;
406 group_progress.Left:=0;
407 group_progress.Top:=0;
408 group_progress.Width:=Form1.Width-8;
409 progress.Width:=group_progress.Width-80;
410 progress.Max:=dat_header.files;
411 btn_extractcancel.Left:=group_progress.Width-65;
412 btn_extractcancel.Caption:='Cancel';
413 btn_extractcancel.SetFocus;
414
415 errors:=0;
416 FOR i:=0 TO High(dat_files) DO BEGIN
417 IF ExportFile(i,True)>0 THEN Inc(errors);
418 IF (i MOD 25)=0 THEN BEGIN
419 lbl_progress.Caption:=IntToStr(i)+'/'+IntToStr(dat_header.Files);
420 progress.Position:=i;
421 Application.ProcessMessages;
422 IF btn_extractcancel.Caption='Cancel_' THEN BEGIN
423 btn_extractcancel.Caption:='Cancel';
424 Break;
425 END;
426 END;
427 END;
428 IF errors>0 THEN
429 ShowMessage(IntToStr(errors)+' errors encountered.');
430
431 group_progress.Visible:=False;
432 Form1.Width:=oldwidth;
433 Form1.Height:=oldheight;
434 Form1.WindowState:=oldstate;
435 //FOR i:=0 TO menu.ComponentCount DO menu.Items.Items[i].Enabled:=True;
436 panel_all.Visible:=True;
437 END;
438
439END.
Note: See TracBrowser for help on using the repository browser.