1 | unit Main;
|
---|
2 | interface
|
---|
3 | uses
|
---|
4 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
5 | Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus, Grids,
|
---|
6 | MPHexEditor, ToolWin, ImgList, Tabs,
|
---|
7 | MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst,
|
---|
8 | Data, TypeDefs, ConnectionManager,
|
---|
9 | // Functions, Exporters, DataStructures,
|
---|
10 | Functions,
|
---|
11 | Settings, {Helper_LevelDB, }
|
---|
12 | Template,
|
---|
13 | RawEdit, BinEdit, Extractor, Preview, TxmpReplace;
|
---|
14 |
|
---|
15 | type
|
---|
16 | TForm_Main = class(TForm)
|
---|
17 | saved: TSaveDialog;
|
---|
18 | opend: TOpenDialog;
|
---|
19 | statbar: TStatusBar;
|
---|
20 | MenuImages: TImageList;
|
---|
21 | DockTop: TTBDock;
|
---|
22 | MainMenu: TTBToolbar;
|
---|
23 | menu_main: TTBSubmenuItem;
|
---|
24 | menu_loadfile: TTBItem;
|
---|
25 | menu_sep1: TTBSeparatorItem;
|
---|
26 | menu_settings: TTBItem;
|
---|
27 | menu_sep4: TTBSeparatorItem;
|
---|
28 | menu_exit: TTBItem;
|
---|
29 | menu_convert: TTBSubmenuItem;
|
---|
30 | menu_createdb: TTBItem;
|
---|
31 | menu_createlvl: TTBItem;
|
---|
32 | menu_tools: TTBSubmenuItem;
|
---|
33 | menu_preview: TTBItem;
|
---|
34 | menu_binedit: TTBItem;
|
---|
35 | menu_rawedit: TTBItem;
|
---|
36 | menu_txmpreplace: TTBItem;
|
---|
37 | menu_extractor: TTBItem;
|
---|
38 | menu_filecompare: TTBItem;
|
---|
39 | menu_levelstructedit: TTBItem;
|
---|
40 | menu_view: TTBSubmenuItem;
|
---|
41 | menu_windows_cascade: TTBItem;
|
---|
42 | menu_windows_tile: TTBItem;
|
---|
43 | menu_windows_closeall: TTBItem;
|
---|
44 | menu_sep3: TTBSeparatorItem;
|
---|
45 | menu_windows_next: TTBItem;
|
---|
46 | menu_windows_previous: TTBItem;
|
---|
47 | menu_sep2: TTBSeparatorItem;
|
---|
48 | menu_About: TTBItem;
|
---|
49 | Toolbar: TTBToolbar;
|
---|
50 | tbOpen: TTBItem;
|
---|
51 | DockLeft: TTBDock;
|
---|
52 | DockRight: TTBDock;
|
---|
53 | DockBottom: TTBDock;
|
---|
54 | MDIToolbar: TTBToolbar;
|
---|
55 | TBControlItem1: TTBControlItem;
|
---|
56 | MDITab: TMDITab;
|
---|
57 | menu_toolbars: TTBSubmenuItem;
|
---|
58 | menu_view_mdibar: TTBItem;
|
---|
59 | menu_view_statusbar: TTBItem;
|
---|
60 | menu_view_toolbar: TTBItem;
|
---|
61 | tb_separator1: TTBSeparatorItem;
|
---|
62 | tb_preview: TTBItem;
|
---|
63 | tb_structure: TTBItem;
|
---|
64 | tb_compare: TTBItem;
|
---|
65 | tb_extractor: TTBItem;
|
---|
66 | tb_txmpreplacer: TTBItem;
|
---|
67 | tb_rawedit: TTBItem;
|
---|
68 | tb_datedit: TTBItem;
|
---|
69 | menu_windows_tilevert: TTBItem;
|
---|
70 | tb_meta: TTBItem;
|
---|
71 | menu_meta: TTBItem;
|
---|
72 | TBSeparatorItem1: TTBSeparatorItem;
|
---|
73 | tb_db2dat: TTBItem;
|
---|
74 | tb_dat2db: TTBItem;
|
---|
75 | menu_loaddb: TTBItem;
|
---|
76 | tb_opendb: TTBItem;
|
---|
77 | Images_Close: TImageList;
|
---|
78 | menu_conns: TTBSubmenuItem;
|
---|
79 | menu_windows: TTBSubmenuItem;
|
---|
80 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
81 | procedure FormResize(Sender: TObject);
|
---|
82 | procedure FormCreate(Sender: TObject);
|
---|
83 | procedure ActivateTools(active: Boolean);
|
---|
84 | procedure UpdateStatBar;
|
---|
85 | procedure UpdateConLists;
|
---|
86 | procedure LoadFile(typedb: Boolean);
|
---|
87 | function TryCloseAll: Boolean;
|
---|
88 | procedure MDITabDrawTab(Control: TCustomTabControl; TabIndex: Integer;
|
---|
89 | const Rect: TRect; Active: Boolean);
|
---|
90 | procedure MDITabMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
91 | Shift: TShiftState; X, Y: Integer);
|
---|
92 | procedure MDITabMouseMove(Sender: TObject; Shift: TShiftState; X,
|
---|
93 | Y: Integer);
|
---|
94 | procedure ToolbarDockChanged(Sender: TObject);
|
---|
95 | procedure CreateConnection(filename: String);
|
---|
96 | function CheckConnectionCloseable(index: Integer): Boolean;
|
---|
97 |
|
---|
98 | procedure menu_loadfileClick(Sender: TObject);
|
---|
99 | procedure menu_loaddbClick(Sender: TObject);
|
---|
100 | procedure menu_settingsClick(Sender: TObject);
|
---|
101 | procedure menu_exitClick(Sender: TObject);
|
---|
102 |
|
---|
103 | procedure menu_createlvlClick(Sender: TObject);
|
---|
104 | procedure menu_createdbClick(Sender: TObject);
|
---|
105 |
|
---|
106 | procedure menu_bineditClick(Sender: TObject);
|
---|
107 | procedure menu_filecompareClick(Sender: TObject);
|
---|
108 | procedure menu_raweditClick(Sender: TObject);
|
---|
109 | procedure menu_extractorClick(Sender: TObject);
|
---|
110 | procedure menu_txmpreplaceClick(Sender: TObject);
|
---|
111 | procedure menu_previewClick(Sender: TObject);
|
---|
112 | procedure menu_metaClick(Sender: TObject);
|
---|
113 | function open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate;
|
---|
114 |
|
---|
115 | procedure menu_windows_cascadeClick(Sender: TObject);
|
---|
116 | procedure menu_windows_tilevertClick(Sender: TObject);
|
---|
117 | procedure menu_windows_tileClick(Sender: TObject);
|
---|
118 | procedure menu_windows_closeallClick(Sender: TObject);
|
---|
119 | procedure menu_windows_previousClick(Sender: TObject);
|
---|
120 | procedure menu_windows_nextClick(Sender: TObject);
|
---|
121 | procedure menu_conns_itemClick(Sender: TObject);
|
---|
122 | procedure menu_windows_itemClick(Sender: TObject);
|
---|
123 | procedure menu_view_mdibarClick(Sender: TObject);
|
---|
124 | procedure menu_view_statusbarClick(Sender: TObject);
|
---|
125 | procedure menu_view_toolbarClick(Sender: TObject);
|
---|
126 |
|
---|
127 | procedure menu_AboutClick(Sender: TObject);
|
---|
128 |
|
---|
129 | procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
|
---|
130 | private
|
---|
131 | public
|
---|
132 | procedure DefaultHandler(var Message); override;
|
---|
133 | end;
|
---|
134 |
|
---|
135 | var
|
---|
136 | Form_Main: TForm_Main;
|
---|
137 |
|
---|
138 | implementation
|
---|
139 |
|
---|
140 | {$R *.dfm}
|
---|
141 |
|
---|
142 |
|
---|
143 | procedure ShowOpenMsg(msg: TStatusMessages);
|
---|
144 | begin
|
---|
145 | case msg of
|
---|
146 | SM_AlreadyOpened: ShowMessage('File already opened.');
|
---|
147 | SM_FileNotFound: ShowMessage('File not found.');
|
---|
148 | SM_UnknownExtension: ShowMessage('Unknown extension.');
|
---|
149 | SM_IncompatibleFile: ShowMessage('Incompatible file format.');
|
---|
150 | SM_UnknownError: ShowMessage('Unknown error.');
|
---|
151 | end;
|
---|
152 | end;
|
---|
153 |
|
---|
154 | procedure TForm_Main.CreateConnection(filename: String);
|
---|
155 | var
|
---|
156 | RepMsg: TStatusMessages;
|
---|
157 | begin
|
---|
158 | ConManager.OpenConnection(filename, RepMsg);
|
---|
159 | ShowOpenMsg(RepMsg);
|
---|
160 | if RepMsg = SM_OK then
|
---|
161 | begin
|
---|
162 | UpdateStatBar;
|
---|
163 | UpdateConLists;
|
---|
164 | end;
|
---|
165 | end;
|
---|
166 |
|
---|
167 | function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean;
|
---|
168 | var
|
---|
169 | i: Integer;
|
---|
170 | toolform: TForm_ToolTemplate;
|
---|
171 | begin
|
---|
172 | if MDITab.MDIChildCount > 0 then
|
---|
173 | begin
|
---|
174 | for i := 0 to MDITab.MDIChildCount - 1 do
|
---|
175 | begin
|
---|
176 | if MDITab.MDIChildren[i] is TForm_ToolTemplate then
|
---|
177 | begin
|
---|
178 | toolform := TForm_ToolTemplate(MDITab.MDIChildren[i]);
|
---|
179 | if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then
|
---|
180 | begin
|
---|
181 | if not toolform.Closeable then
|
---|
182 | ShowMessage('Can not close toolwindow: ' + toolform.Caption);
|
---|
183 | end;
|
---|
184 | end;
|
---|
185 | end;
|
---|
186 | end;
|
---|
187 | end;
|
---|
188 |
|
---|
189 |
|
---|
190 | { Eine zweite Instanz hat uns ihre Kommandozeilenparameter geschickt }
|
---|
191 | procedure TForm_Main.WMCopyData(var Msg: TWMCopyData);
|
---|
192 | var
|
---|
193 | strings: TStringList;
|
---|
194 | begin
|
---|
195 | if (Msg.CopyDataStruct.dwData = SecondInstMsgId) and (SecondInstMsgId <> 0) then
|
---|
196 | begin
|
---|
197 | Application.BringToFront;
|
---|
198 |
|
---|
199 | strings := TStringList.Create;
|
---|
200 | strings.Text := ParamBlobToStr(Msg.CopyDataStruct.lpData);
|
---|
201 | if strings.Count = 2 then
|
---|
202 | begin
|
---|
203 | if strings.Strings[0] = 'opf' then
|
---|
204 | begin
|
---|
205 | ShowMessage('Load OPF-File: ' + ParamStr(2));
|
---|
206 | end
|
---|
207 | else if (strings.Strings[0] = 'oldb') or (strings.Strings[0] = 'dat') then
|
---|
208 | begin
|
---|
209 | CreateConnection(strings.Strings[1]);
|
---|
210 | end;
|
---|
211 | end;
|
---|
212 | end
|
---|
213 | else
|
---|
214 | inherited;
|
---|
215 | end;
|
---|
216 |
|
---|
217 | {----------------------------------------------------------------------------}
|
---|
218 | { Wir überschreiben den DefaultHandler, der alle Nachrichten zuerst bekommt, }
|
---|
219 | { damit wir auf die Nachricht mit der ID SecondInstMsgId reagieren können. }
|
---|
220 | { (Dies ist notwendig, da wir jetzt noch nicht wissen welchen Wert }
|
---|
221 | { die ID haben wird, weswegen wir keine statische Message-Prozedure, }
|
---|
222 | { so wie bei WM_COPYDATA, schreiben können.) }
|
---|
223 | {----------------------------------------------------------------------------}
|
---|
224 | procedure TForm_Main.DefaultHandler(var Message);
|
---|
225 | begin
|
---|
226 | if TMessage(Message).Msg = SecondInstMsgId then
|
---|
227 | { Eine zweite Instanz hat uns nach dem Handle gefragt }
|
---|
228 | { Es wird in die Message-Queue des Threads gepostet. }
|
---|
229 | PostThreadMessage(TMessage(Message).WParam, SecondInstMsgId, Handle, 0)
|
---|
230 | else
|
---|
231 | inherited;
|
---|
232 | end;
|
---|
233 |
|
---|
234 |
|
---|
235 |
|
---|
236 | procedure TForm_Main.FormCreate(Sender: TObject);
|
---|
237 | var
|
---|
238 | RepMsg: TStatusMessages;
|
---|
239 | begin
|
---|
240 | Self.Caption := 'Oni Un/Packer ' + version;
|
---|
241 | Self.FormResize(Self);
|
---|
242 |
|
---|
243 | ConManager.OnCoonnectionListChanged := UpdateConLists;
|
---|
244 |
|
---|
245 | if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
|
---|
246 | begin
|
---|
247 | AssignFile(AppSettingsFile, ExtractFilepath(Application.EXEname) +
|
---|
248 | '\oniunpacker.ini');
|
---|
249 | Reset(AppSettingsFile);
|
---|
250 | Read(AppSettingsFile, AppSettings);
|
---|
251 | CloseFile(AppSettingsFile);
|
---|
252 | end
|
---|
253 | else
|
---|
254 | begin
|
---|
255 | AppSettings.DatPath := ExtractFilepath(Application.EXEname);
|
---|
256 | AppSettings.ExtractPath := ExtractFilepath(Application.EXEname) + '\extract';
|
---|
257 | AppSettings.FilenumbersAsHex := False;
|
---|
258 | AppSettings.CharSet := DEFAULT_CHARSET;
|
---|
259 | AppSettings.HideUnusedData := False;
|
---|
260 | end;
|
---|
261 |
|
---|
262 | if MidStr(ParamStr(1), 1, 3) = 'opf' then
|
---|
263 | begin
|
---|
264 | ShowMessage('Load OPF-File: ' + ParamStr(2));
|
---|
265 | end
|
---|
266 | else if (MidStr(ParamStr(1), 1, 4) = 'oldb') or (MidStr(ParamStr(1), 1, 3) = 'dat') then
|
---|
267 | begin
|
---|
268 | CreateConnection(ParamStr(2));
|
---|
269 | end;
|
---|
270 | UpdateStatBar;
|
---|
271 | end;
|
---|
272 |
|
---|
273 |
|
---|
274 |
|
---|
275 |
|
---|
276 | procedure TForm_Main.FormResize(Sender: TObject);
|
---|
277 | begin
|
---|
278 | statbar.Panels.Items[0].Width := Self.Width - 200;
|
---|
279 | MDITab.Width := Self.Width - 20;
|
---|
280 | end;
|
---|
281 |
|
---|
282 |
|
---|
283 |
|
---|
284 |
|
---|
285 | procedure TForm_Main.MDITabDrawTab(Control: TCustomTabControl;
|
---|
286 | TabIndex: Integer; const Rect: TRect; Active: Boolean);
|
---|
287 | var
|
---|
288 | x, y: Integer;
|
---|
289 | iconindex: Integer;
|
---|
290 | caption: String;
|
---|
291 | begin
|
---|
292 | iconindex := TMDITab(Control).Glyphs[TabIndex];
|
---|
293 | caption := TMDITab(Control).Captions[TabIndex];
|
---|
294 | if active then
|
---|
295 | begin
|
---|
296 | Control.Canvas.Font.Style := Control.Canvas.Font.Style + [fsItalic];
|
---|
297 | y := Rect.Top + 1;
|
---|
298 | end else
|
---|
299 | y := Rect.Top;
|
---|
300 | if iconindex >= 0 then
|
---|
301 | begin
|
---|
302 | TMDITab(Control).Images.Draw(Control.Canvas, Rect.Left + 4, y, iconindex);
|
---|
303 | x := Rect.Left + 26;
|
---|
304 | end else
|
---|
305 | x := Rect.Left + 4;
|
---|
306 | Control.Canvas.TextOut(x, y + 2, caption);
|
---|
307 | if active then
|
---|
308 | Images_Close.Draw(Control.Canvas, Rect.Right - 18, y, 0)
|
---|
309 | else
|
---|
310 | Images_Close.Draw(Control.Canvas, Rect.Right - 18, y, 1);
|
---|
311 | end;
|
---|
312 |
|
---|
313 |
|
---|
314 | procedure TForm_Main.MDITabMouseMove(Sender: TObject; Shift: TShiftState; X,
|
---|
315 | Y: Integer);
|
---|
316 | var
|
---|
317 | pt: TPoint;
|
---|
318 | tabIndex: Integer;
|
---|
319 | hint: String;
|
---|
320 | tool: TForm_ToolTemplate;
|
---|
321 | begin
|
---|
322 | pt.X := X;
|
---|
323 | pt.Y := Y;
|
---|
324 | tabIndex := MDITab.GetTabAtPos(pt);
|
---|
325 | hint := '';
|
---|
326 |
|
---|
327 | if tabIndex >= 0 then
|
---|
328 | begin
|
---|
329 | if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then
|
---|
330 | begin
|
---|
331 | tool := TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]);
|
---|
332 | if tool.ConnectionID > -1 then
|
---|
333 | hint := 'Connection: ' +
|
---|
334 | ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) + #13+#10
|
---|
335 | else
|
---|
336 | hint := 'Connection: none' + #13+#10;
|
---|
337 | if tool.SelectedFile.ID > -1 then
|
---|
338 | hint := hint + 'Selected File: ' +
|
---|
339 | FormatNumber(tool.SelectedFile.ID, 5, '0') + '-' +
|
---|
340 | tool.SelectedFile.Name + '.' +
|
---|
341 | tool.SelectedFile.Extension
|
---|
342 | else
|
---|
343 | hint := hint + 'Selected File: none';
|
---|
344 | end
|
---|
345 | else
|
---|
346 | hint := 'Window: ' + MDITab.MDIChildren[tabIndex].Caption;
|
---|
347 | if hint <> MDITab.Hint then
|
---|
348 | begin
|
---|
349 | MDITab.Hint := hint;
|
---|
350 | MDITab.ShowHint := True;
|
---|
351 | end;
|
---|
352 | end
|
---|
353 | else
|
---|
354 | begin
|
---|
355 | MDITab.ShowHint := False;
|
---|
356 | MDITab.Hint := '';
|
---|
357 | end;
|
---|
358 | end;
|
---|
359 |
|
---|
360 | procedure TForm_Main.MDITabMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
361 | Shift: TShiftState; X, Y: Integer);
|
---|
362 | var
|
---|
363 | pt: TPoint;
|
---|
364 | tabIndex: Integer;
|
---|
365 | tabRect: TRect;
|
---|
366 | tabX, tabY, tabWidth: Integer;
|
---|
367 | begin
|
---|
368 | pt.X := X;
|
---|
369 | pt.Y := Y;
|
---|
370 | tabIndex := MDITab.GetTabAtPos(pt);
|
---|
371 |
|
---|
372 | // if (Button = mbRight) and (tabIndex >= 0) then
|
---|
373 | // MDITab.MDIChildren[tabIndex].Close;
|
---|
374 |
|
---|
375 | if (Button = mbLeft) and (tabIndex >= 0) then
|
---|
376 | begin
|
---|
377 | tabrect := MDITab.TabRect(tabIndex);
|
---|
378 | tabX := X - tabrect.Left;
|
---|
379 | tabY := Y - tabrect.Top;
|
---|
380 | tabwidth := tabrect.Right - tabrect.Left;
|
---|
381 | if (tabY >= 4) and (tabY <= 17) then
|
---|
382 | if (tabX >= tabwidth - 19) and (tabX <= tabwidth - 7) then
|
---|
383 | MDITab.MDIChildren[tabIndex].Close;
|
---|
384 | end;
|
---|
385 | end;
|
---|
386 |
|
---|
387 |
|
---|
388 |
|
---|
389 |
|
---|
390 | procedure TForm_Main.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
391 | begin
|
---|
392 | AssignFile(AppSettingsFile, ExtractFilepath(Application.EXEname) + '\oniunpacker.ini');
|
---|
393 | if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
|
---|
394 | Reset(AppSettingsFile)
|
---|
395 | else
|
---|
396 | Rewrite(AppSettingsFile);
|
---|
397 | Write(AppSettingsFile, AppSettings);
|
---|
398 | CloseFile(AppSettingsFile);
|
---|
399 | Action := caFree;
|
---|
400 | end;
|
---|
401 |
|
---|
402 |
|
---|
403 |
|
---|
404 | procedure TForm_Main.ActivateTools(active: Boolean);
|
---|
405 | begin
|
---|
406 | menu_tools.Enabled := active;
|
---|
407 | tb_preview.Enabled := active;
|
---|
408 | tb_datedit.Enabled := active;
|
---|
409 | tb_rawedit.Enabled := active;
|
---|
410 | tb_txmpreplacer.Enabled := active;
|
---|
411 | tb_extractor.Enabled := active;
|
---|
412 | // tb_compare.Enabled := active;
|
---|
413 | // tb_structure.Enabled := active;
|
---|
414 | end;
|
---|
415 |
|
---|
416 | procedure TForm_Main.UpdateStatBar;
|
---|
417 | begin
|
---|
418 | if ConManager.Count > 0 then
|
---|
419 | begin
|
---|
420 | Self.Caption := 'Oni Un/Packer ' + version;
|
---|
421 | ActivateTools(True);
|
---|
422 | statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count);
|
---|
423 | end
|
---|
424 | else
|
---|
425 | begin
|
---|
426 | Self.Caption := 'Oni Un/Packer ' + version;
|
---|
427 | statbar.Panels.Items[0].Text := '';
|
---|
428 | statbar.Panels.Items[1].Text := 'Connections: -';
|
---|
429 | statbar.Panels.Items[2].Text := '';
|
---|
430 | ActivateTools(False);
|
---|
431 | end;
|
---|
432 | menu_conns.Enabled := ConManager.Count > 0;
|
---|
433 | end;
|
---|
434 |
|
---|
435 |
|
---|
436 |
|
---|
437 |
|
---|
438 | procedure TForm_Main.ToolbarDockChanged(Sender: TObject);
|
---|
439 | var
|
---|
440 | toolbar: TTBToolbar;
|
---|
441 | position: TTBDockPosition;
|
---|
442 | mode: TTBItemDisplayMode;
|
---|
443 | i: Integer;
|
---|
444 | isEnabled: Boolean;
|
---|
445 | begin
|
---|
446 | toolbar := TTBToolbar(Sender);
|
---|
447 | if toolbar.Floating then
|
---|
448 | mode := nbdmImageAndText
|
---|
449 | else begin
|
---|
450 | position := toolbar.CurrentDock.Position;
|
---|
451 | if position in [dpLeft, dpRight] then
|
---|
452 | mode := nbdmDefault
|
---|
453 | else
|
---|
454 | mode := nbdmImageAndText;
|
---|
455 | end;
|
---|
456 | for i := 0 to toolbar.Items.Count - 1 do
|
---|
457 | toolbar.Items.Items[i].DisplayMode := mode;
|
---|
458 | end;
|
---|
459 |
|
---|
460 | function TForm_Main.TryCloseAll: Boolean;
|
---|
461 | begin
|
---|
462 | menu_windows_closeallClick(Self);
|
---|
463 | Application.ProcessMessages;
|
---|
464 | if MDITab.MDIChildCount = 0 then
|
---|
465 | Result := True
|
---|
466 | else
|
---|
467 | Result := False;
|
---|
468 | end;
|
---|
469 |
|
---|
470 |
|
---|
471 | procedure TForm_Main.UpdateConLists;
|
---|
472 | var
|
---|
473 | i: Integer;
|
---|
474 | entry: TTBItem;
|
---|
475 | begin
|
---|
476 | if MDITab.MDIChildCount > 0 then
|
---|
477 | for i := 0 to MDITab.MDIChildCount - 1 do
|
---|
478 | if MDITab.MDIChildren[i] is TForm_ToolTemplate then
|
---|
479 | TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList;
|
---|
480 |
|
---|
481 | menu_conns.Clear;
|
---|
482 | if ConManager.Count > 0 then
|
---|
483 | begin
|
---|
484 | for i := 0 to ConManager.Count - 1 do
|
---|
485 | begin
|
---|
486 | entry := TTBItem.Create(menu_conns);
|
---|
487 | entry.Caption := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
|
---|
488 | entry.Name := 'menu_conn_' + IntToStr(i);
|
---|
489 | entry.OnClick := menu_conns_itemClick;
|
---|
490 | menu_conns.Add(entry);
|
---|
491 | entry := nil;
|
---|
492 | end;
|
---|
493 | end;
|
---|
494 | end;
|
---|
495 |
|
---|
496 |
|
---|
497 | procedure TForm_Main.LoadFile(typedb: Boolean);
|
---|
498 | var
|
---|
499 | i: Integer;
|
---|
500 | begin
|
---|
501 | opend.InitialDir := AppSettings.DatPath;
|
---|
502 | opend.Filter := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
|
---|
503 | if typedb then
|
---|
504 | opend.FilterIndex := 3
|
---|
505 | else
|
---|
506 | opend.FilterIndex := 2;
|
---|
507 | if opend.Execute then
|
---|
508 | begin
|
---|
509 | if opend.Files.Count > 0 then
|
---|
510 | for i := 0 to opend.Files.Count - 1 do
|
---|
511 | CreateConnection(opend.Files.Strings[i]);
|
---|
512 | AppSettings.DatPath := ExtractFilepath(opend.FileName);
|
---|
513 | end;
|
---|
514 | UpdateStatBar;
|
---|
515 | end;
|
---|
516 |
|
---|
517 |
|
---|
518 | {#################################}
|
---|
519 | {##### Main-Menu-Handlers #####}
|
---|
520 | {#################################}
|
---|
521 | procedure TForm_Main.menu_loaddbClick(Sender: TObject);
|
---|
522 | begin
|
---|
523 | LoadFile(True);
|
---|
524 | end;
|
---|
525 |
|
---|
526 | procedure TForm_Main.menu_loadfileClick(Sender: TObject);
|
---|
527 | begin
|
---|
528 | LoadFile(False);
|
---|
529 | end;
|
---|
530 |
|
---|
531 |
|
---|
532 | procedure TForm_Main.menu_settingsClick(Sender: TObject);
|
---|
533 | begin
|
---|
534 | Form_Settings.Visible := True;
|
---|
535 | Self.Enabled := False;
|
---|
536 | end;
|
---|
537 |
|
---|
538 |
|
---|
539 | procedure TForm_Main.menu_exitClick(Sender: TObject);
|
---|
540 | begin
|
---|
541 | Self.Close;
|
---|
542 | end;
|
---|
543 |
|
---|
544 |
|
---|
545 | {####################################}
|
---|
546 | {##### Converters-Menu-Handlers #####}
|
---|
547 | {####################################}
|
---|
548 | procedure TForm_Main.menu_createdbClick(Sender: TObject);
|
---|
549 | begin
|
---|
550 | ShowMessage('Not yet usable');
|
---|
551 | {
|
---|
552 | opend.Filter := 'Oni-Dat-Files|*.dat';
|
---|
553 | saved.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
|
---|
554 | saved.DefaultExt := 'oldb';
|
---|
555 | if opend.Execute then
|
---|
556 | if saved.Execute then
|
---|
557 | Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
|
---|
558 | }
|
---|
559 | end;
|
---|
560 |
|
---|
561 |
|
---|
562 | procedure TForm_Main.menu_createlvlClick(Sender: TObject);
|
---|
563 | begin
|
---|
564 | ShowMessage('Not yet usable');
|
---|
565 | {
|
---|
566 | opend.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
|
---|
567 | saved.Filter := 'Oni-Dat-Files|*.dat';
|
---|
568 | saved.DefaultExt := 'dat';
|
---|
569 | if opend.Execute then
|
---|
570 | if saved.Execute then
|
---|
571 | Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
|
---|
572 | }
|
---|
573 | end;
|
---|
574 |
|
---|
575 |
|
---|
576 | {#################################}
|
---|
577 | {##### Tools-Menu-Handlers #####}
|
---|
578 | {#################################}
|
---|
579 | procedure TForm_Main.menu_previewClick(Sender: TObject);
|
---|
580 | begin
|
---|
581 | open_child('preview', -1, -1);
|
---|
582 | end;
|
---|
583 |
|
---|
584 | procedure TForm_Main.menu_bineditClick(Sender: TObject);
|
---|
585 | begin
|
---|
586 | open_child('binedit', -1, -1);
|
---|
587 | end;
|
---|
588 |
|
---|
589 | procedure TForm_Main.menu_raweditClick(Sender: TObject);
|
---|
590 | begin
|
---|
591 | open_child('rawedit', -1, -1);
|
---|
592 | end;
|
---|
593 |
|
---|
594 | procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
|
---|
595 | begin
|
---|
596 | open_child('txmpreplace', -1, -1);
|
---|
597 | end;
|
---|
598 |
|
---|
599 | procedure TForm_Main.menu_extractorClick(Sender: TObject);
|
---|
600 | begin
|
---|
601 | open_child('extractor', -1, -1);
|
---|
602 | end;
|
---|
603 |
|
---|
604 | procedure TForm_Main.menu_metaClick(Sender: TObject);
|
---|
605 | begin
|
---|
606 | ShowMessage('TBD');
|
---|
607 | end;
|
---|
608 |
|
---|
609 | procedure TForm_Main.menu_filecompareClick(Sender: TObject);
|
---|
610 | begin
|
---|
611 | open_child('compare', -1, -1);
|
---|
612 | end;
|
---|
613 |
|
---|
614 |
|
---|
615 | {#################################}
|
---|
616 | {##### View-Menu-Handlers #####}
|
---|
617 | {#################################}
|
---|
618 | procedure TForm_Main.menu_windows_cascadeClick(Sender: TObject);
|
---|
619 | begin
|
---|
620 | Self.Cascade;
|
---|
621 | end;
|
---|
622 |
|
---|
623 | procedure TForm_Main.menu_windows_tilevertClick(Sender: TObject);
|
---|
624 | begin
|
---|
625 | Self.TileMode := tbVertical;
|
---|
626 | Self.Tile;
|
---|
627 | end;
|
---|
628 |
|
---|
629 | procedure TForm_Main.menu_windows_tileClick(Sender: TObject);
|
---|
630 | begin
|
---|
631 | Self.TileMode := tbHorizontal;
|
---|
632 | Self.Tile;
|
---|
633 | end;
|
---|
634 |
|
---|
635 | procedure TForm_Main.menu_windows_closeallClick(Sender: TObject);
|
---|
636 | begin
|
---|
637 | MDITab.CloseAll;
|
---|
638 | end;
|
---|
639 |
|
---|
640 | procedure TForm_Main.menu_windows_nextClick(Sender: TObject);
|
---|
641 | begin
|
---|
642 | if MDIChildCount > 1 then
|
---|
643 | if MDITab.TabIndex = MDITab.MDIChildCount - 1 then
|
---|
644 | MDITab.MDIChildren[0].BringToFront
|
---|
645 | else
|
---|
646 | MDITab.MDIChildren[MDITab.TabIndex + 1].BringToFront;
|
---|
647 | end;
|
---|
648 |
|
---|
649 | procedure TForm_Main.menu_windows_previousClick(Sender: TObject);
|
---|
650 | begin
|
---|
651 | if MDIChildCount > 1 then
|
---|
652 | if MDITab.TabIndex = 0 then
|
---|
653 | MDITab.MDIChildren[MDITab.MDIChildCount - 1].BringToFront
|
---|
654 | else
|
---|
655 | MDITab.MDIChildren[MDITab.TabIndex - 1].BringToFront;
|
---|
656 | end;
|
---|
657 |
|
---|
658 |
|
---|
659 | {##################################}
|
---|
660 | {##### Windows-Menu-Handlers #####}
|
---|
661 | {##################################}
|
---|
662 | procedure TForm_Main.menu_windows_itemClick(Sender: TObject);
|
---|
663 | var
|
---|
664 | name: String;
|
---|
665 | begin
|
---|
666 | name := TTBItem(Sender).Name;
|
---|
667 | end;
|
---|
668 |
|
---|
669 |
|
---|
670 |
|
---|
671 | {######################################}
|
---|
672 | {##### Connections-Menu-Handlers #####}
|
---|
673 | {######################################}
|
---|
674 | procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
|
---|
675 | var
|
---|
676 | name: String;
|
---|
677 | i: Integer;
|
---|
678 | index: Integer;
|
---|
679 | RepMsg: TStatusMessages;
|
---|
680 | begin
|
---|
681 | // name := TTBItem(Sender).Caption;
|
---|
682 | index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender));
|
---|
683 | name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName);
|
---|
684 | if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
|
---|
685 | name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then
|
---|
686 | begin
|
---|
687 | CheckConnectionCloseable(index);
|
---|
688 | ConManager.CloseConnectionByIndex(index, RepMsg);
|
---|
689 | ShowOpenMsg(RepMsg);
|
---|
690 | UpdateConLists;
|
---|
691 | end;
|
---|
692 | UpdateStatBar;
|
---|
693 | end;
|
---|
694 |
|
---|
695 |
|
---|
696 | {###################################}
|
---|
697 | {##### Toolbars-Menu-Handlers #####}
|
---|
698 | {###################################}
|
---|
699 | procedure TForm_Main.menu_view_toolbarClick(Sender: TObject);
|
---|
700 | begin
|
---|
701 | menu_view_toolbar.Checked := not menu_view_toolbar.Checked;
|
---|
702 | Toolbar.Visible := menu_view_toolbar.Checked;
|
---|
703 | end;
|
---|
704 |
|
---|
705 | procedure TForm_Main.menu_view_statusbarClick(Sender: TObject);
|
---|
706 | begin
|
---|
707 | menu_view_statusbar.Checked := not menu_view_statusbar.Checked;
|
---|
708 | statbar.Visible := menu_view_statusbar.Checked;
|
---|
709 | end;
|
---|
710 |
|
---|
711 | procedure TForm_Main.menu_view_mdibarClick(Sender: TObject);
|
---|
712 | begin
|
---|
713 | menu_view_mdibar.Checked := not menu_view_mdibar.Checked;
|
---|
714 | mditoolbar.Visible := menu_view_mdibar.Checked;
|
---|
715 | end;
|
---|
716 |
|
---|
717 |
|
---|
718 |
|
---|
719 | procedure TForm_Main.menu_AboutClick(Sender: TObject);
|
---|
720 | begin
|
---|
721 | ShowMessage('Will be implemented later ;)');
|
---|
722 | end;
|
---|
723 |
|
---|
724 |
|
---|
725 |
|
---|
726 |
|
---|
727 |
|
---|
728 | function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate;
|
---|
729 | var
|
---|
730 | toolform: TForm_ToolTemplate;
|
---|
731 | i: Integer;
|
---|
732 | tag: Integer;
|
---|
733 | caption_end: String;
|
---|
734 | iconindex: Integer;
|
---|
735 | begin
|
---|
736 | Result := nil;
|
---|
737 |
|
---|
738 | tag := 1;
|
---|
739 | if MDIChildCount > 0 then
|
---|
740 | for i := 0 to MDIChildCount - 1 do
|
---|
741 | if MDIChildren[i].Tag >= tag then
|
---|
742 | tag := MDIChildren[i].Tag + 1;
|
---|
743 |
|
---|
744 | iconindex := -1;
|
---|
745 | caption_end := IntToStr(tag) + ' ';
|
---|
746 |
|
---|
747 | if window_context = 'binedit' then
|
---|
748 | begin
|
---|
749 | toolform := TForm_BinEdit.Create(Self);
|
---|
750 | toolform.Caption := 'Binary .dat-Editor ' + caption_end;
|
---|
751 | iconindex := 5;
|
---|
752 | end;
|
---|
753 | if window_context = 'extractor' then
|
---|
754 | begin
|
---|
755 | toolform := TForm_Extractor.Create(Self);
|
---|
756 | toolform.Caption := 'Extractor ' + caption_end;
|
---|
757 | iconindex := 8;
|
---|
758 | end;
|
---|
759 | if window_context = 'preview' then
|
---|
760 | begin
|
---|
761 | toolform := TForm_Preview.Create(Self);
|
---|
762 | toolform.Caption := 'Preview-Window ' + caption_end;
|
---|
763 | iconindex := 4;
|
---|
764 | end;
|
---|
765 | if window_context = 'rawedit' then
|
---|
766 | begin
|
---|
767 | toolform := TForm_RawEdit.Create(Self);
|
---|
768 | toolform.Caption := 'Binary .raw-Editor ' + caption_end;
|
---|
769 | iconindex := 6;
|
---|
770 | end;
|
---|
771 | if window_context = 'txmpreplace' then
|
---|
772 | begin
|
---|
773 | toolform := TForm_TxmpReplace.Create(Self);
|
---|
774 | toolform.Caption := 'TXMP Replacer ' + caption_end;
|
---|
775 | iconindex := 7;
|
---|
776 | end;
|
---|
777 |
|
---|
778 | if Assigned(toolform) then
|
---|
779 | begin
|
---|
780 | toolform.Name := window_context + IntToStr(tag);
|
---|
781 | toolform.Tag := tag;
|
---|
782 | MDITab.AddTab(TForm(toolform), iconindex);
|
---|
783 | toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', '');
|
---|
784 | if connection > -1 then
|
---|
785 | begin
|
---|
786 | toolform.SelectConnection(connection);
|
---|
787 | if fileid > -1 then
|
---|
788 | toolform.SelectFileID(connection, fileid);
|
---|
789 | end;
|
---|
790 | Result := toolform;
|
---|
791 | end;
|
---|
792 | end;
|
---|
793 |
|
---|
794 | end.
|
---|