source: oup/releases/0.29a/Unit1_main.pas@ 262

Last change on this file since 262 was 28, checked in by alloc, 18 years ago
File size: 16.9 KB
Line 
1UNIT Unit1_main;
2INTERFACE
3USES
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus, Grids,
6 MPHexEditor, ToolWin, ImgList, Tabs,
7 Unit2_functions, Unit3_data, Unit9_data_structures,
8 Unit10_leveldb, Unit4_exporters, Unit14_settings,
9 Unit5_preview, Unit7_txmpreplace, Unit8_binedit, Unit11_extractor, Unit13_rawedit;
10
11TYPE
12 TForm1 = Class(TForm)
13 tabs: TTabSet;
14 saved: TSaveDialog;
15 opend: TOpenDialog;
16 statbar: TStatusBar;
17 menu: TMainMenu;
18 menu_main: TMenuItem;
19 menu_loaddat: TMenuItem;
20 menu_lvldb: TMenuItem;
21 menu_exit: TMenuItem;
22 menu_convert: TMenuItem;
23 menu_createdb: TMenuItem;
24 menu_createlvl: TMenuItem;
25 menu_tools: TMenuItem;
26 menu_preview: TMenuItem;
27 menu_txmpreplace: TMenuItem;
28 menu_binedit: TMenuItem;
29 menu_extractor: TMenuItem;
30 menu_windows: TMenuItem;
31 menu_windows_cascade: TMenuItem;
32 menu_windows_tile: TMenuItem;
33 menu_windows_closeall: TMenuItem;
34 menu_windows_next: TMenuItem;
35 menu_windows_previous: TMenuItem;
36 menu_sep1: TMenuItem;
37 menu_sep2: TMenuItem;
38 menu_sep3: TMenuItem;
39 menu_levelstructedit: TMenuItem;
40 menu_rawedit: TMenuItem;
41 menu_filecompare: TMenuItem;
42 ClosefileDB1: TMenuItem;
43 menu_sep4: TMenuItem;
44 menu_settings: TMenuItem;
45 PROCEDURE menu_settingsClick(Sender: TObject);
46 PROCEDURE ClosefileDB1Click(Sender: TObject);
47 PROCEDURE menu_filecompareClick(Sender: TObject);
48 PROCEDURE menu_raweditClick(Sender: TObject);
49 PROCEDURE menu_createlvlClick(Sender: TObject);
50 PROCEDURE menu_extractorClick(Sender: TObject);
51 PROCEDURE menu_lvldbClick(Sender: TObject);
52 PROCEDURE menu_createdbClick(Sender: TObject);
53 PROCEDURE SetActiveWindow(window_name:String);
54 PROCEDURE tabsChange(Sender: TObject; NewTab: Integer; var AllowChange: Boolean);
55 PROCEDURE close_window(window_name:String);
56 PROCEDURE menu_windows_previousClick(Sender: TObject);
57 PROCEDURE menu_windows_nextClick(Sender: TObject);
58 PROCEDURE menu_windows_tileClick(Sender: TObject);
59 FUNCTION open_child(window_context:String):Boolean;
60 PROCEDURE menu_windows_closeallClick(Sender: TObject);
61 PROCEDURE menu_windows_cascadeClick(Sender: TObject);
62 PROCEDURE menu_window_entryClick(Sender: TObject);
63 PROCEDURE menu_bineditClick(Sender: TObject);
64 PROCEDURE menu_loaddatClick(Sender: TObject);
65 PROCEDURE menu_txmpreplaceClick(Sender: TObject);
66 PROCEDURE menu_exitClick(Sender: TObject);
67 PROCEDURE menu_previewClick(Sender: TObject);
68 PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
69 PROCEDURE FormResize(Sender: TObject);
70 PROCEDURE FormCreate(Sender: TObject);
71 PRIVATE
72 PUBLIC
73 END;
74
75VAR
76 Form1: TForm1;
77
78IMPLEMENTATION
79{$R *.dfm}
80VAR
81 tablist:Array OF String;
82
83PROCEDURE TForm1.FormCreate(Sender: TObject);
84 BEGIN
85 Form1.Caption:='Oni Un/Packer '+version;
86 Form1.FormResize(Form1);
87
88 IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN BEGIN
89 AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini');
90 Reset(AppSettingsFile);
91 Read(AppSettingsFile,AppSettings);
92 CloseFile(AppSettingsFile);
93 END ELSE BEGIN
94 AppSettings.DatPath:='D:\Spiele\Oni\GameDataFolder';
95 AppSettings.ExtractPath:='C:\Dokumente und Einstellungen\Administrator\Desktop';
96 END;
97// LoadStructureDefinitions(ExtractFilepath(Application.EXEname)+'\StructDefs');
98
99 IF MidStr(ParamStr(1),1,3)='opf' THEN BEGIN
100 ShowMessage('Load OPF-File: '+ParamStr(2));
101 END ELSE IF MidStr(ParamStr(1),1,4)='oldb' THEN BEGIN
102 OpenDatabase(ParamStr(2));
103 IF opened_state=opened_db THEN BEGIN
104 menu_tools.Enabled:=True;
105 menu_convert.Enabled:=False;
106 statbar.Panels.Items[0].Text:='OLDB loaded: '+ParamStr(2);
107 statbar.Panels.Items[1].Text:='Files: '+IntToStr(GetFilesCount);
108 statbar.Panels.Items[2].Text:='Extensions: '+IntToStr(Length(GetExtensionsList));
109 END ELSE BEGIN
110 menu_tools.Enabled:=False;
111 menu_convert.Enabled:=True;
112 END;
113 END ELSE IF MidStr(ParamStr(1),1,3)='dat' THEN BEGIN
114 IF LoadDatInfos(ParamStr(2)) THEN BEGIN
115 Form1.Caption:='Oni Un/Packer '+version+' ('+ExtractFileName(ParamStr(2))+')';
116 statbar.Panels.Items[0].Text:='.dat loaded: '+ParamStr(2);
117 statbar.Panels.Items[1].Text:='Files: '+IntToStr(dat_header.Files);
118 statbar.Panels.Items[2].Text:='Extensions: '+IntToStr(dat_header.Extensions);
119 menu_tools.Enabled:=True;
120 menu_convert.Enabled:=False;
121 END ELSE BEGIN
122 menu_convert.Enabled:=True;
123 ShowMessage('Error while loading the file:'+CrLf+ParamStr(2)+CrLf+'Perhaps not an Oni-.dat-file?');
124 END;
125 END;
126 END;
127
128PROCEDURE TForm1.FormResize(Sender: TObject);
129 CONST
130 MinWidth:Integer=750;
131 MinHeight:Integer=500;
132 BEGIN
133 IF Form1.Width<MinWidth THEN Form1.Width:=MinWidth;
134 IF Form1.Height<MinHeight THEN Form1.Height:=MinHeight;
135 Form1.statbar.Panels.Items[0].Width:=Form1.Width-200;
136 END;
137
138PROCEDURE TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
139 BEGIN
140 AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini');
141 IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN
142 Reset(AppSettingsFile)
143 ELSE
144 Rewrite(AppSettingsFile);
145 Write(AppSettingsFile,AppSettings);
146 CloseFile(AppSettingsFile);
147 Action:=caFree;
148 END;
149
150
151{#################################}
152{##### Main-Menu-Handlers #####}
153{#################################}
154PROCEDURE TForm1.menu_loaddatClick(Sender: TObject);
155 VAR i:LongWord;
156 BEGIN
157 opend.InitialDir:=AppSettings.DatPath;
158 opend.Filter:='Oni-Dat-Files|*.dat';
159 IF opend.Execute THEN BEGIN
160 menu_windows_closeallClick(Form1);
161 IF Length(tablist)=0 THEN BEGIN
162 IF opened_state=opened_db THEN CloseDatabase;
163 Caption:='Oni Un/Packer '+version;
164 statbar.Panels.Items[0].Text:='Nothing loaded';
165 statbar.Panels.Items[1].Text:='Files: -';
166 statbar.Panels.Items[2].Text:='Extensions: -';
167 AppSettings.DatPath:=ExtractFilepath(opend.FileName);
168 IF LoadDatInfos(opend.FileName) THEN BEGIN
169 Form1.Caption:='Oni Un/Packer '+version+' ('+ExtractFileName(opend.FileName)+')';
170 statbar.Panels.Items[0].Text:='.dat loaded: '+dat_FileName;
171 statbar.Panels.Items[1].Text:='Files: '+IntToStr(dat_header.Files);
172 statbar.Panels.Items[2].Text:='Extensions: '+IntToStr(dat_header.Extensions);
173 menu_tools.Enabled:=True;
174 menu_convert.Enabled:=False;
175 END ELSE BEGIN
176 menu_convert.Enabled:=True;
177 ShowMessage('Error while loading the file:'+CrLf+opend.FileName+CrLf+'Perhaps not an Oni-.dat-file?');
178 END;
179 END;
180 END;
181 END;
182PROCEDURE TForm1.menu_lvldbClick(Sender: TObject);
183 BEGIN
184 opend.InitialDir:=AppSettings.DatPath;
185 opend.Filter:='OUP-Level-DB (*.oldb)|*.oldb';
186 IF opend.Execute THEN BEGIN
187 menu_windows_closeallClick(Form1);
188 IF Length(tablist)=0 THEN BEGIN
189 IF opened_state=opened_db THEN CloseDatabase;
190 Form1.Caption:='Oni Un/Packer '+version;
191 opened_state:=opened_nothing;
192 statbar.Panels.Items[0].Text:='Nothing loaded';
193 statbar.Panels.Items[1].Text:='Files: -';
194 statbar.Panels.Items[2].Text:='Extensions: -';
195 OpenDatabase(opend.FileName);
196 IF opened_state=opened_db THEN BEGIN
197 menu_tools.Enabled:=True;
198 menu_convert.Enabled:=False;
199 statbar.Panels.Items[0].Text:='OLDB loaded: '+opend.FileName;
200 statbar.Panels.Items[1].Text:='Files: '+IntToStr(GetFilesCount);
201 statbar.Panels.Items[2].Text:='Extensions: '+IntToStr(Length(GetExtensionsList));
202 END ELSE BEGIN
203 menu_tools.Enabled:=False;
204 menu_convert.Enabled:=True;
205 END;
206 END;
207 END;
208 END;
209PROCEDURE TForm1.ClosefileDB1Click(Sender: TObject);
210 BEGIN
211 menu_windows_closeallClick(Form1);
212 IF Length(tablist)=0 THEN BEGIN
213 IF opened_state=opened_db THEN CloseDatabase;
214 Form1.Caption:='Oni Un/Packer '+version;
215 opened_state:=opened_nothing;
216 statbar.Panels.Items[0].Text:='Nothing loaded';
217 statbar.Panels.Items[1].Text:='Files: -';
218 statbar.Panels.Items[2].Text:='Extensions: -';
219 menu_tools.Enabled:=False;
220 menu_convert.Enabled:=True;
221 END;
222 END;
223PROCEDURE TForm1.menu_settingsClick(Sender: TObject);
224 BEGIN
225 Form14.Visible:=True;
226 Self.Enabled:=False;
227 END;
228PROCEDURE TForm1.menu_exitClick(Sender: TObject);
229 BEGIN
230 Form1.Close;
231 END;
232
233{####################################}
234{##### Converters-Menu-Handlers #####}
235{####################################}
236PROCEDURE TForm1.menu_createdbClick(Sender: TObject);
237 BEGIN
238 opend.Filter:='Oni-Dat-Files|*.dat';
239 saved.Filter:='OUP-Level-DB (*.oldb)|*.oldb';
240 saved.DefaultExt:='oldb';
241 IF opend.Execute THEN BEGIN
242 IF saved.Execute THEN BEGIN
243 Form10.CreateDatabase(opend.FileName,saved.FileName);
244 END;
245 END;
246 END;
247PROCEDURE TForm1.menu_createlvlClick(Sender: TObject);
248 BEGIN
249 opend.Filter:='OUP-Level-DB (*.oldb)|*.oldb';
250 saved.Filter:='Oni-Dat-Files|*.dat';
251 saved.DefaultExt:='dat';
252 IF opend.Execute THEN BEGIN
253 IF saved.Execute THEN BEGIN
254 Form10.CreateLevel(opend.FileName,saved.FileName);
255 END;
256 END;
257 END;
258
259{#################################}
260{##### Tools-Menu-Handlers #####}
261{#################################}
262PROCEDURE TForm1.menu_previewClick(Sender: TObject);
263 BEGIN
264 open_child('preview');
265 END;
266PROCEDURE TForm1.menu_txmpreplaceClick(Sender: TObject);
267 BEGIN
268 open_child('txmpreplace');
269 END;
270PROCEDURE TForm1.menu_bineditClick(Sender: TObject);
271 BEGIN
272 open_child('binedit');
273 END;
274PROCEDURE TForm1.menu_raweditClick(Sender: TObject);
275 BEGIN
276 open_child('rawedit');
277 END;
278
279PROCEDURE TForm1.menu_extractorClick(Sender: TObject);
280 BEGIN
281 open_child('extractor');
282 END;
283PROCEDURE TForm1.menu_filecompareClick(Sender: TObject);
284 BEGIN
285 open_child('compare');
286 END;
287
288
289{#################################}
290{##### Window-Menu-Handlers #####}
291{#################################}
292PROCEDURE TForm1.menu_windows_cascadeClick(Sender: TObject);
293 BEGIN
294 Form1.Cascade;
295 END;
296PROCEDURE TForm1.menu_windows_tileClick(Sender: TObject);
297 BEGIN
298 Form1.TileMode:=tbHorizontal;
299 Form1.Tile;
300 END;
301PROCEDURE TForm1.menu_windows_closeallClick(Sender: TObject);
302 VAR
303 i:Byte;
304 BEGIN
305 IF MDIChildCount>0 THEN BEGIN
306 FOR i:=0 TO MDIChildCount-1 DO BEGIN
307 MDIChildren[i].Close;
308 END;
309 END;
310 tabs.Tabs.Clear;
311 END;
312PROCEDURE TForm1.menu_windows_nextClick(Sender: TObject);
313 VAR i:Byte;
314 first_window:Byte;
315 current_focus:String;
316 BEGIN
317 IF MDIChildCount>1 THEN BEGIN
318 FOR i:=0 TO menu_windows.Count-1 DO BEGIN
319 IF Pos('menu_window_',menu_windows.Items[i].Name)=1 THEN BEGIN
320 first_window:=i;
321 Break;
322 END;
323 END;
324 current_focus:=ActiveMDIChild.Name;
325 FOR i:=first_window TO menu_windows.Count-1 DO
326 IF Pos(current_focus,menu_windows.Items[i].Name)>0 THEN
327 Break;
328 IF i=menu_windows.Count-1 THEN
329 menu_windows.Items[first_window].Click
330 ELSE
331 menu_windows.Items[i+1].Click;
332 FOR i:=0 TO High(tablist) DO BEGIN
333 IF tablist[i]=ActiveMDIChild.Name THEN BEGIN
334 tabs.TabIndex:=i;
335 END;
336 END;
337 END;
338 END;
339PROCEDURE TForm1.menu_windows_previousClick(Sender: TObject);
340 VAR i:Byte;
341 first_window:Byte;
342 current_focus:String;
343 BEGIN
344 IF MDIChildCount>1 THEN BEGIN
345 FOR i:=0 TO menu_windows.Count-1 DO BEGIN
346 IF Pos('menu_window_',menu_windows.Items[i].Name)=1 THEN BEGIN
347 first_window:=i;
348 Break;
349 END;
350 END;
351 current_focus:=ActiveMDIChild.Name;
352 FOR i:=first_window TO menu_windows.Count-1 DO
353 IF Pos(current_focus,menu_windows.Items[i].Name)>0 THEN
354 Break;
355 IF i=first_window THEN
356 menu_windows.Items[menu_windows.Count-1].Click
357 ELSE
358 menu_windows.Items[i-1].Click;
359 FOR i:=0 TO High(tablist) DO BEGIN
360 IF tablist[i]=ActiveMDIChild.Name THEN BEGIN
361 tabs.TabIndex:=i;
362 END;
363 END;
364 END;
365 END;
366
367PROCEDURE TForm1.menu_window_entryClick(Sender: TObject);
368 VAR
369 i:Byte;
370 window_name:String;
371 BEGIN
372 window_name:=MidStr(TComponent(Sender).Name,Pos('window_',TComponent(Sender).Name)+7,Length(TComponent(Sender).Name)-Pos('window_',TComponent(Sender).Name)+7+1);
373 FOR i:=0 TO MDIChildCount-1 DO BEGIN
374 IF MDIChildren[i].Name=window_name THEN BEGIN
375 MDIChildren[i].BringToFront;
376 END;
377 END;
378 FOR i:=0 TO High(tablist) DO BEGIN
379 IF tablist[i]=ActiveMDIChild.Name THEN BEGIN
380 tabs.TabIndex:=i;
381 END;
382 END;
383 END;
384
385
386
387FUNCTION TForm1.open_child(window_context:String):Boolean;
388 VAR
389 rawEdit:TForm13;
390 binEdit:TForm8;
391 preview:TForm5;
392 txmpreplacer:TForm7;
393 extractor:TForm11;
394 menu_button:TMenuItem;
395 used:Array[1..9] OF Boolean;
396 i:Byte;
397 caption:String;
398 name:String;
399 BEGIN
400 Result:=True;
401 FOR i:=1 TO 9 DO used[i]:=False;
402 IF MDIChildCount>0 THEN
403 FOR i:=0 TO MDIChildCount-1 DO
404 IF Pos(window_context,Form1.MDIChildren[i].Name)=1 THEN
405 used[StrToInt(RightStr(Form1.MDIChildren[i].Caption,1))]:=True;
406 FOR i:=1 TO 10 DO
407 IF i=10 THEN
408 Break
409 ELSE
410 IF NOT used[i] THEN Break;
411
412 IF i<10 THEN BEGIN
413 name:=window_context+IntToStr(i);
414 IF window_context='binedit' THEN
415 caption:='Binary .dat-Editor '+IntToStr(i);
416 IF window_context='rawedit' THEN
417 caption:='Binary .raw-Editor '+IntToStr(i);
418 IF window_context='preview' THEN
419 caption:='Preview-Window '+IntToStr(i);
420 IF window_context='txmpreplace' THEN
421 caption:='TXMP Replacer '+IntToStr(i);
422 IF window_context='extractor' THEN
423 caption:='Extractor '+IntToStr(i);
424
425 menu_button:=TMenuItem.Create(menu_windows);
426 menu_button.Caption:=caption;
427 menu_button.Name:='menu_window_'+name;
428 menu_button.OnClick:=Form1.menu_window_entryClick;
429 menu_windows.Add(menu_button);
430
431 SetLength(tablist,Length(tablist)+1);
432 tablist[High(tablist)]:=name;
433 tabs.Tabs.Add(caption);
434
435 IF window_context='binedit' THEN BEGIN
436 binEdit:=TForm8.Create(Application);
437 binEdit.Name:=name;
438 binEdit.Caption:=caption;
439 binEdit.Recreatelist;
440 END;
441 IF window_context='rawedit' THEN BEGIN
442 rawEdit:=TForm13.Create(Application);
443 rawEdit.Name:=name;
444 rawEdit.Caption:=caption;
445 rawEdit.Recreatelist;
446 END;
447 IF window_context='preview' THEN BEGIN
448 preview:=TForm5.Create(Application);
449 preview.Name:=name;
450 preview.Caption:=caption;
451 preview.Recreatelist;
452 END;
453 IF window_context='txmpreplace' THEN BEGIN
454 txmpreplacer:=TForm7.Create(Application);
455 txmpreplacer.Name:=name;
456 txmpreplacer.Caption:=caption;
457 txmpreplacer.Recreatelist;
458 END;
459 IF window_context='extractor' THEN BEGIN
460 extractor:=TForm11.Create(Application);
461 extractor.Name:=name;
462 extractor.Caption:=caption;
463 extractor.Recreatelist;
464 END;
465
466 tabs.TabIndex:=High(tablist);
467 IF MDIChildCount=9 THEN menu_tools.Enabled:=False;
468 END ELSE BEGIN
469 Result:=False;
470 END;
471 END;
472
473
474PROCEDURE TForm1.close_window(window_name:String);
475 VAR
476 i,j:Byte;
477 BEGIN
478 FOR i:=0 TO menu_windows.Count-1 DO BEGIN
479 IF menu_windows.Items[i].Name='menu_window_'+window_name THEN BEGIN
480 menu_windows.Items[i].Free;
481 Break;
482 END;
483 END;
484 FOR i:=0 TO High(tablist) DO BEGIN
485 IF tablist[i]=window_name THEN BEGIN
486 tabs.Tabs.Delete(i);
487 IF High(tablist)>0 THEN
488 FOR j:=i TO High(tablist)-1 DO
489 tablist[j]:=tablist[j+1];
490 SetLength(tablist,Length(tablist)-1);
491 Break;
492 END;
493 END;
494 menu_tools.Enabled:=True;
495 END;
496
497
498PROCEDURE TForm1.tabsChange(Sender: TObject; NewTab: Integer; var AllowChange: Boolean);
499 VAR
500 i:Byte;
501 BEGIN
502 FOR i:=0 TO MDIChildCount-1 DO BEGIN
503 IF MDIChildren[i].Name=tablist[NewTab] THEN
504 MDIChildren[i].BringToFront;
505 END;
506 END;
507
508PROCEDURE TForm1.SetActiveWindow(window_name:String);
509 VAR
510 i:Byte;
511 BEGIN
512 IF Length(tablist)>0 THEN
513 FOR i:=0 TO High(tablist) DO
514 IF tablist[i]=window_name THEN
515 tabs.TabIndex:=i;
516 END;
517
518
519END.
Note: See TracBrowser for help on using the repository browser.