| 6 |
|
MPHexEditor, ToolWin, ImgList, Tabs, |
| 7 |
|
MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst, |
| 8 |
|
Data, TypeDefs, ConnectionManager, |
| 9 |
< |
// Functions, Exporters, DataStructures, |
| 10 |
< |
Settings, {Helper_LevelDB, } |
| 11 |
< |
Template, BinEdit, Extractor, Preview, RawEdit, TxmpReplace; |
| 9 |
> |
Functions, Settings, Template, |
| 10 |
> |
RawEdit, BinEdit, Extractor, Preview, TxmpReplace; |
| 11 |
|
|
| 12 |
|
type |
| 13 |
|
TForm_Main = class(TForm) |
| 90 |
|
Y: Integer); |
| 91 |
|
procedure ToolbarDockChanged(Sender: TObject); |
| 92 |
|
procedure CreateConnection(filename: String); |
| 93 |
+ |
function CheckConnectionCloseable(index: Integer): Boolean; |
| 94 |
|
|
| 95 |
|
procedure menu_loadfileClick(Sender: TObject); |
| 96 |
|
procedure menu_loaddbClick(Sender: TObject); |
| 125 |
|
|
| 126 |
|
procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA; |
| 127 |
|
private |
| 128 |
– |
ConnectionManager: TConnectionManager; |
| 128 |
|
public |
| 129 |
|
procedure DefaultHandler(var Message); override; |
| 130 |
|
end; |
| 134 |
|
|
| 135 |
|
implementation |
| 136 |
|
|
| 137 |
+ |
uses |
| 138 |
+ |
LevelDB, MetaEditor; |
| 139 |
+ |
|
| 140 |
|
{$R *.dfm} |
| 141 |
|
|
| 142 |
|
|
| 155 |
|
var |
| 156 |
|
RepMsg: TStatusMessages; |
| 157 |
|
begin |
| 158 |
< |
ConnectionManager.OpenConnection(filename, RepMsg); |
| 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 |
+ |
Result := True; |
| 173 |
+ |
if MDITab.MDIChildCount > 0 then |
| 174 |
+ |
begin |
| 175 |
+ |
for i := 0 to MDITab.MDIChildCount - 1 do |
| 176 |
+ |
begin |
| 177 |
+ |
if MDITab.MDIChildren[i] is TForm_ToolTemplate then |
| 178 |
+ |
begin |
| 179 |
+ |
toolform := TForm_ToolTemplate(MDITab.MDIChildren[i]); |
| 180 |
+ |
if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then |
| 181 |
+ |
begin |
| 182 |
+ |
if not toolform.Closeable then |
| 183 |
+ |
begin |
| 184 |
+ |
ShowMessage('Can not close toolwindow: ' + toolform.Caption); |
| 185 |
+ |
Result := False; |
| 186 |
+ |
end; |
| 187 |
+ |
end; |
| 188 |
+ |
end; |
| 189 |
+ |
end; |
| 190 |
|
end; |
| 191 |
|
end; |
| 192 |
|
|
| 193 |
+ |
|
| 194 |
|
{ Eine zweite Instanz hat uns ihre Kommandozeilenparameter geschickt } |
| 195 |
|
procedure TForm_Main.WMCopyData(var Msg: TWMCopyData); |
| 196 |
|
var |
| 238 |
|
|
| 239 |
|
|
| 240 |
|
procedure TForm_Main.FormCreate(Sender: TObject); |
| 211 |
– |
var |
| 212 |
– |
RepMsg: TStatusMessages; |
| 241 |
|
begin |
| 242 |
|
Self.Caption := 'Oni Un/Packer ' + version; |
| 243 |
|
Self.FormResize(Self); |
| 244 |
|
|
| 245 |
< |
ConnectionManager := TConnectionManager.Create; |
| 218 |
< |
ConnectionManager.OnCoonnectionListChanged := UpdateConLists; |
| 245 |
> |
ConManager.OnCoonnectionListChanged := UpdateConLists; |
| 246 |
|
|
| 247 |
|
if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then |
| 248 |
|
begin |
| 254 |
|
end |
| 255 |
|
else |
| 256 |
|
begin |
| 257 |
+ |
ShowMessage('Warning!' + #13#10 + |
| 258 |
+ |
'It seems like this is the first time you OUP.' + #13#10 + |
| 259 |
+ |
'I do not take any responsibility for messed up data files' + #13+#10 + |
| 260 |
+ |
'Do not forget to make backup copies of your *.dat/*.raw/*.sep files!'); |
| 261 |
|
AppSettings.DatPath := ExtractFilepath(Application.EXEname); |
| 262 |
|
AppSettings.ExtractPath := ExtractFilepath(Application.EXEname) + '\extract'; |
| 232 |
– |
AppSettings.FilenumbersAsHex := False; |
| 263 |
|
AppSettings.CharSet := DEFAULT_CHARSET; |
| 264 |
|
AppSettings.HideUnusedData := False; |
| 265 |
|
end; |
| 322 |
|
pt: TPoint; |
| 323 |
|
tabIndex: Integer; |
| 324 |
|
hint: String; |
| 325 |
+ |
tool: TForm_ToolTemplate; |
| 326 |
|
begin |
| 327 |
|
pt.X := X; |
| 328 |
|
pt.Y := Y; |
| 333 |
|
begin |
| 334 |
|
if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then |
| 335 |
|
begin |
| 336 |
< |
if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection <> nil then |
| 336 |
> |
tool := TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]); |
| 337 |
> |
if tool.ConnectionID > -1 then |
| 338 |
|
hint := 'Connection: ' + |
| 339 |
< |
ExtractFileName(TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection.FileName) + #13+#10 |
| 339 |
> |
ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) + #13+#10 |
| 340 |
|
else |
| 341 |
|
hint := 'Connection: none' + #13+#10; |
| 342 |
< |
if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.ID >= 0 then |
| 342 |
> |
if tool.SelectedFile.ID > -1 then |
| 343 |
|
hint := hint + 'Selected File: ' + |
| 344 |
< |
TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.FileName |
| 344 |
> |
FormatNumber(tool.SelectedFile.ID, 5, '0') + '-' + |
| 345 |
> |
tool.SelectedFile.Name + '.' + |
| 346 |
> |
tool.SelectedFile.Extension |
| 347 |
|
else |
| 348 |
|
hint := hint + 'Selected File: none'; |
| 349 |
|
end |
| 414 |
|
tb_rawedit.Enabled := active; |
| 415 |
|
tb_txmpreplacer.Enabled := active; |
| 416 |
|
tb_extractor.Enabled := active; |
| 417 |
+ |
tb_meta.Enabled := active; |
| 418 |
|
// tb_compare.Enabled := active; |
| 419 |
|
// tb_structure.Enabled := active; |
| 420 |
|
end; |
| 421 |
|
|
| 422 |
|
procedure TForm_Main.UpdateStatBar; |
| 423 |
|
begin |
| 424 |
< |
if Length(DataConnections) > 0 then |
| 424 |
> |
if ConManager.Count > 0 then |
| 425 |
|
begin |
| 426 |
|
Self.Caption := 'Oni Un/Packer ' + version; |
| 427 |
|
ActivateTools(True); |
| 428 |
< |
statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(Length(DataConnections)); |
| 428 |
> |
statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count); |
| 429 |
|
end |
| 430 |
|
else |
| 431 |
|
begin |
| 435 |
|
statbar.Panels.Items[2].Text := ''; |
| 436 |
|
ActivateTools(False); |
| 437 |
|
end; |
| 438 |
< |
menu_conns.Enabled := Length(DataConnections) > 0; |
| 438 |
> |
menu_conns.Enabled := ConManager.Count > 0; |
| 439 |
|
end; |
| 440 |
|
|
| 441 |
|
|
| 447 |
|
position: TTBDockPosition; |
| 448 |
|
mode: TTBItemDisplayMode; |
| 449 |
|
i: Integer; |
| 415 |
– |
isEnabled: Boolean; |
| 450 |
|
begin |
| 451 |
|
toolbar := TTBToolbar(Sender); |
| 452 |
|
if toolbar.Floating then |
| 484 |
|
TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList; |
| 485 |
|
|
| 486 |
|
menu_conns.Clear; |
| 487 |
< |
if ConnectionManager.Count > 0 then |
| 487 |
> |
if ConManager.Count > 0 then |
| 488 |
|
begin |
| 489 |
< |
for i := 0 to ConnectionManager.Count - 1 do |
| 489 |
> |
for i := 0 to ConManager.Count - 1 do |
| 490 |
|
begin |
| 491 |
|
entry := TTBItem.Create(menu_conns); |
| 492 |
< |
entry.Caption := ExtractFileName(DataConnections[i].FileName); |
| 492 |
> |
entry.Caption := ExtractFileName(ConManager.ConnectionByIndex[i].FileName); |
| 493 |
|
entry.Name := 'menu_conn_' + IntToStr(i); |
| 494 |
|
entry.OnClick := menu_conns_itemClick; |
| 495 |
|
menu_conns.Add(entry); |
| 501 |
|
|
| 502 |
|
procedure TForm_Main.LoadFile(typedb: Boolean); |
| 503 |
|
var |
| 504 |
< |
ext: String; |
| 504 |
> |
i: Integer; |
| 505 |
|
begin |
| 506 |
|
opend.InitialDir := AppSettings.DatPath; |
| 507 |
|
opend.Filter := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*'; |
| 511 |
|
opend.FilterIndex := 2; |
| 512 |
|
if opend.Execute then |
| 513 |
|
begin |
| 514 |
< |
ext := ExtractFileExt(opend.FileName); |
| 515 |
< |
if ext = '.dat' then |
| 516 |
< |
begin |
| 483 |
< |
CreateConnection(opend.FileName); |
| 484 |
< |
end else if ext = '.oldb' then |
| 485 |
< |
begin |
| 486 |
< |
CreateConnection(opend.FileName); |
| 487 |
< |
end else |
| 488 |
< |
ShowMessage('Incompatible file'); |
| 514 |
> |
if opend.Files.Count > 0 then |
| 515 |
> |
for i := 0 to opend.Files.Count - 1 do |
| 516 |
> |
CreateConnection(opend.Files.Strings[i]); |
| 517 |
|
AppSettings.DatPath := ExtractFilepath(opend.FileName); |
| 518 |
|
end; |
| 519 |
|
UpdateStatBar; |
| 552 |
|
{####################################} |
| 553 |
|
procedure TForm_Main.menu_createdbClick(Sender: TObject); |
| 554 |
|
begin |
| 555 |
< |
ShowMessage('Not yet usable'); |
| 556 |
< |
{ |
| 555 |
> |
// ShowMessage('Not yet usable'); |
| 556 |
> |
|
| 557 |
|
opend.Filter := 'Oni-Dat-Files|*.dat'; |
| 558 |
|
saved.Filter := 'OUP-Level-DB (*.oldb)|*.oldb'; |
| 559 |
|
saved.DefaultExt := 'oldb'; |
| 560 |
|
if opend.Execute then |
| 561 |
|
if saved.Execute then |
| 562 |
|
Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName); |
| 535 |
– |
} |
| 563 |
|
end; |
| 564 |
|
|
| 565 |
|
|
| 566 |
|
procedure TForm_Main.menu_createlvlClick(Sender: TObject); |
| 567 |
|
begin |
| 568 |
< |
ShowMessage('Not yet usable'); |
| 569 |
< |
{ |
| 568 |
> |
// ShowMessage('Not yet usable'); |
| 569 |
> |
|
| 570 |
|
opend.Filter := 'OUP-Level-DB (*.oldb)|*.oldb'; |
| 571 |
|
saved.Filter := 'Oni-Dat-Files|*.dat'; |
| 572 |
|
saved.DefaultExt := 'dat'; |
| 573 |
|
if opend.Execute then |
| 574 |
|
if saved.Execute then |
| 575 |
|
Form_LevelDB.CreateLevel(opend.FileName, saved.FileName); |
| 549 |
– |
} |
| 576 |
|
end; |
| 577 |
|
|
| 578 |
|
|
| 581 |
|
{#################################} |
| 582 |
|
procedure TForm_Main.menu_previewClick(Sender: TObject); |
| 583 |
|
begin |
| 584 |
< |
open_child('preview', nil, -1); |
| 584 |
> |
open_child('preview', -1, -1); |
| 585 |
|
end; |
| 586 |
|
|
| 587 |
|
procedure TForm_Main.menu_bineditClick(Sender: TObject); |
| 588 |
|
begin |
| 589 |
< |
open_child('binedit', nil, -1); |
| 589 |
> |
open_child('binedit', -1, -1); |
| 590 |
|
end; |
| 591 |
|
|
| 592 |
|
procedure TForm_Main.menu_raweditClick(Sender: TObject); |
| 593 |
|
begin |
| 594 |
< |
open_child('rawedit', nil, -1); |
| 594 |
> |
open_child('rawedit', -1, -1); |
| 595 |
|
end; |
| 596 |
|
|
| 597 |
|
procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject); |
| 598 |
|
begin |
| 599 |
< |
open_child('txmpreplace', nil, -1); |
| 599 |
> |
open_child('txmpreplace', -1, -1); |
| 600 |
|
end; |
| 601 |
|
|
| 602 |
|
procedure TForm_Main.menu_extractorClick(Sender: TObject); |
| 603 |
|
begin |
| 604 |
< |
open_child('extractor', nil, -1); |
| 604 |
> |
open_child('extractor', -1, -1); |
| 605 |
|
end; |
| 606 |
|
|
| 607 |
|
procedure TForm_Main.menu_metaClick(Sender: TObject); |
| 608 |
+ |
var |
| 609 |
+ |
toolform: TForm_Meta; |
| 610 |
+ |
i: Integer; |
| 611 |
+ |
tag: Integer; |
| 612 |
+ |
iconindex: Integer; |
| 613 |
|
begin |
| 614 |
< |
ShowMessage('TBD'); |
| 614 |
> |
tag := 1; |
| 615 |
> |
if MDIChildCount > 0 then |
| 616 |
> |
for i := 0 to MDIChildCount - 1 do |
| 617 |
> |
if MDIChildren[i].Tag >= tag then |
| 618 |
> |
tag := MDIChildren[i].Tag + 1; |
| 619 |
> |
|
| 620 |
> |
iconindex := -1; |
| 621 |
> |
|
| 622 |
> |
toolform := nil; |
| 623 |
> |
|
| 624 |
> |
toolform := TForm_Meta.Create(Self); |
| 625 |
> |
toolform.Caption := 'MetaEditor' + ' ' + IntToStr(tag) + ' '; |
| 626 |
> |
iconindex := 11; |
| 627 |
> |
|
| 628 |
> |
if Assigned(toolform) then |
| 629 |
> |
begin |
| 630 |
> |
toolform.Name := 'meta' + IntToStr(tag); |
| 631 |
> |
toolform.Tag := tag; |
| 632 |
> |
MDITab.AddTab(TForm(toolform), iconindex); |
| 633 |
> |
toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', ''); |
| 634 |
> |
end; |
| 635 |
|
end; |
| 636 |
|
|
| 637 |
|
procedure TForm_Main.menu_filecompareClick(Sender: TObject); |
| 638 |
|
begin |
| 639 |
< |
open_child('compare', nil, -1); |
| 639 |
> |
open_child('compare', -1, -1); |
| 640 |
|
end; |
| 641 |
|
|
| 642 |
|
|
| 702 |
|
procedure TForm_Main.menu_conns_itemClick(Sender: TObject); |
| 703 |
|
var |
| 704 |
|
name: String; |
| 705 |
< |
i: Integer; |
| 705 |
> |
index: Integer; |
| 706 |
> |
RepMsg: TStatusMessages; |
| 707 |
|
begin |
| 708 |
< |
name := TTBItem(Sender).Caption; |
| 708 |
> |
// name := TTBItem(Sender).Caption; |
| 709 |
> |
index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender)); |
| 710 |
> |
name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName); |
| 711 |
|
if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+ |
| 712 |
|
name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then |
| 713 |
|
begin |
| 714 |
< |
for i := 0 to High(DataConnections) do |
| 715 |
< |
if ExtractFileName(DataConnections[i].FileName) = name then |
| 716 |
< |
begin |
| 717 |
< |
CloseDataConnection(DataConnections[i]); |
| 664 |
< |
Break; |
| 665 |
< |
end; |
| 714 |
> |
CheckConnectionCloseable(index); |
| 715 |
> |
ConManager.CloseConnectionByIndex(index, RepMsg); |
| 716 |
> |
ShowOpenMsg(RepMsg); |
| 717 |
> |
UpdateConLists; |
| 718 |
|
end; |
| 719 |
|
UpdateStatBar; |
| 720 |
|
end; |
| 753 |
|
|
| 754 |
|
|
| 755 |
|
function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate; |
| 756 |
+ |
type |
| 757 |
+ |
TTemplate = class of TForm_ToolTemplate; |
| 758 |
+ |
TTool = record |
| 759 |
+ |
name: String; |
| 760 |
+ |
icon: Integer; |
| 761 |
+ |
caption: String; |
| 762 |
+ |
classt: TTemplate; |
| 763 |
+ |
end; |
| 764 |
+ |
const |
| 765 |
+ |
Tools: array[0..4] of TTool = ( |
| 766 |
+ |
(name: 'binedit'; icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit), |
| 767 |
+ |
(name: 'extractor'; icon: 8; caption: 'Extractor'; classt: TForm_Extractor), |
| 768 |
+ |
(name: 'preview'; icon: 4; caption: 'Preview-Window'; classt: TForm_Preview), |
| 769 |
+ |
(name: 'rawedit'; icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit), |
| 770 |
+ |
(name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer'; classt: TForm_TxmpReplace) |
| 771 |
+ |
); |
| 772 |
|
var |
| 773 |
|
toolform: TForm_ToolTemplate; |
| 774 |
|
i: Integer; |
| 775 |
|
tag: Integer; |
| 708 |
– |
caption_end: String; |
| 776 |
|
iconindex: Integer; |
| 777 |
|
begin |
| 778 |
|
Result := nil; |
| 784 |
|
tag := MDIChildren[i].Tag + 1; |
| 785 |
|
|
| 786 |
|
iconindex := -1; |
| 720 |
– |
caption_end := IntToStr(tag) + ' '; |
| 787 |
|
|
| 788 |
< |
if window_context = 'binedit' then |
| 789 |
< |
begin |
| 790 |
< |
toolform := TForm_BinEdit.Create(Self); |
| 791 |
< |
toolform.Caption := 'Binary .dat-Editor ' + caption_end; |
| 792 |
< |
iconindex := 5; |
| 793 |
< |
end; |
| 794 |
< |
if window_context = 'extractor' then |
| 795 |
< |
begin |
| 796 |
< |
toolform := TForm_Extractor.Create(Self); |
| 797 |
< |
toolform.Caption := 'Extractor ' + caption_end; |
| 798 |
< |
iconindex := 8; |
| 799 |
< |
end; |
| 734 |
< |
if window_context = 'preview' then |
| 735 |
< |
begin |
| 736 |
< |
toolform := TForm_Preview.Create(Self); |
| 737 |
< |
toolform.Caption := 'Preview-Window ' + caption_end; |
| 738 |
< |
iconindex := 4; |
| 739 |
< |
end; |
| 740 |
< |
if window_context = 'rawedit' then |
| 741 |
< |
begin |
| 742 |
< |
toolform := TForm_RawEdit.Create(Self); |
| 743 |
< |
toolform.Caption := 'Binary .raw-Editor ' + caption_end; |
| 744 |
< |
iconindex := 6; |
| 745 |
< |
end; |
| 746 |
< |
if window_context = 'txmpreplace' then |
| 747 |
< |
begin |
| 748 |
< |
toolform := TForm_TxmpReplace.Create(Application); |
| 749 |
< |
toolform.Caption := 'TXMP Replacer ' + caption_end; |
| 750 |
< |
iconindex := 7; |
| 788 |
> |
toolform := nil; |
| 789 |
> |
|
| 790 |
> |
for i := 0 to High(Tools) do |
| 791 |
> |
if Tools[i].name = window_context then |
| 792 |
> |
Break; |
| 793 |
> |
if i < Length(Tools) then |
| 794 |
> |
begin |
| 795 |
> |
toolform := TTemplate(Tools[i].classt).Create(Self); |
| 796 |
> |
toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + ' '; |
| 797 |
> |
iconindex := Tools[i].icon; |
| 798 |
> |
end else begin |
| 799 |
> |
ShowMessage('WindowContext not found!'); |
| 800 |
|
end; |
| 801 |
|
|
| 802 |
|
if Assigned(toolform) then |
| 805 |
|
toolform.Tag := tag; |
| 806 |
|
MDITab.AddTab(TForm(toolform), iconindex); |
| 807 |
|
toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', ''); |
| 808 |
< |
if (fileid > -1) and (connection <> nil) then |
| 808 |
> |
if connection > -1 then |
| 809 |
|
begin |
| 810 |
< |
toolform.SelectFileID(connection, fileid); |
| 810 |
> |
toolform.SelectConnection(connection); |
| 811 |
> |
if fileid > -1 then |
| 812 |
> |
toolform.SelectFileID(connection, fileid); |
| 813 |
|
end; |
| 814 |
|
Result := toolform; |
| 815 |
|
end; |