--- oup/rewrite/Main.pas 2007/01/22 23:05:45 97 +++ oup/current/Main.pas 2009/06/04 12:03:57 330 @@ -6,12 +6,9 @@ uses MPHexEditor, ToolWin, ImgList, Tabs, MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst, Data, TypeDefs, ConnectionManager, -// Functions, Exporters, DataStructures, - Functions, - Settings, {Helper_LevelDB, } - Template, - Preview; -// BinEdit, Extractor, RawEdit, TxmpReplace; + Functions, Settings, + RawEdit, BinEdit, Extractor, Preview, TxmpReplace, + _BaseTemplate, _TemplateFile, _TemplateFileList; type TForm_Main = class(TForm) @@ -47,7 +44,7 @@ type menu_windows_previous: TTBItem; menu_sep2: TTBSeparatorItem; menu_About: TTBItem; - Toolbar: TTBToolbar; + Toolbar_main: TTBToolbar; tbOpen: TTBItem; DockLeft: TTBDock; DockRight: TTBDock; @@ -60,15 +57,7 @@ type menu_view_statusbar: TTBItem; menu_view_toolbar: TTBItem; tb_separator1: TTBSeparatorItem; - tb_preview: TTBItem; - tb_structure: TTBItem; - tb_compare: TTBItem; - tb_extractor: TTBItem; - tb_txmpreplacer: TTBItem; - tb_rawedit: TTBItem; - tb_datedit: TTBItem; menu_windows_tilevert: TTBItem; - tb_meta: TTBItem; menu_meta: TTBItem; TBSeparatorItem1: TTBSeparatorItem; tb_db2dat: TTBItem; @@ -78,6 +67,18 @@ type Images_Close: TImageList; menu_conns: TTBSubmenuItem; menu_windows: TTBSubmenuItem; + menu_filemanager: TTBItem; + Toolbar_tools: TTBToolbar; + tb_preview: TTBItem; + tb_datedit: TTBItem; + tb_rawedit: TTBItem; + tb_txmpreplacer: TTBItem; + tb_extractor: TTBItem; + tb_meta: TTBItem; + tb_filemanager: TTBItem; + tb_compare: TTBItem; + tb_structure: TTBItem; + menu_view_toolbar_tools: TTBItem; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormResize(Sender: TObject); procedure FormCreate(Sender: TObject); @@ -92,7 +93,7 @@ type Shift: TShiftState; X, Y: Integer); procedure MDITabMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); - procedure ToolbarDockChanged(Sender: TObject); + procedure Toolbar_mainDockChanged(Sender: TObject); procedure CreateConnection(filename: String); function CheckConnectionCloseable(index: Integer): Boolean; @@ -111,7 +112,6 @@ type procedure menu_txmpreplaceClick(Sender: TObject); procedure menu_previewClick(Sender: TObject); procedure menu_metaClick(Sender: TObject); - function open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate; procedure menu_windows_cascadeClick(Sender: TObject); procedure menu_windows_tilevertClick(Sender: TObject); @@ -128,8 +128,13 @@ type procedure menu_AboutClick(Sender: TObject); procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA; + procedure menu_filemanagerClick(Sender: TObject); + procedure menu_view_toolbar_toolsClick(Sender: TObject); private public + function open_child(window_context: String; Connection, FileID: Integer): TForm_BaseTemplate; overload; + function open_child(window_context: String; Connection: Integer): TForm_BaseTemplate; overload; + function open_child(window_context: String): TForm_BaseTemplate; overload; procedure DefaultHandler(var Message); override; end; @@ -138,6 +143,9 @@ var implementation +uses + LevelDB, MetaEditor, FileManager; + {$R *.dfm} @@ -161,25 +169,30 @@ begin if RepMsg = SM_OK then begin UpdateStatBar; + UpdateConLists; end; end; function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean; var i: Integer; - toolform: TForm_ToolTemplate; + toolform: TForm_BaseTemplate; begin + Result := True; if MDITab.MDIChildCount > 0 then begin for i := 0 to MDITab.MDIChildCount - 1 do begin - if MDITab.MDIChildren[i] is TForm_ToolTemplate then + if MDITab.MDIChildren[i] is TForm_BaseTemplate then begin - toolform := TForm_ToolTemplate(MDITab.MDIChildren[i]); + toolform := TForm_BaseTemplate(MDITab.MDIChildren[i]); if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then begin if not toolform.Closeable then - ShowMessage('Can not close toolwindow: ' + toolform.Caption); + begin + ShowMessage('Can not close toolwindow: ' + toolform.Caption); + Result := False; + end; end; end; end; @@ -204,7 +217,7 @@ begin begin ShowMessage('Load OPF-File: ' + ParamStr(2)); end - else if (strings.Strings[0] = 'oldb') or (strings.Strings[0] = 'dat') then + else if (strings.Strings[0] = 'oldb') or (strings.Strings[0] = 'dat') or (strings.Strings[0] = 'oni') then begin CreateConnection(strings.Strings[1]); end; @@ -234,14 +247,15 @@ end; procedure TForm_Main.FormCreate(Sender: TObject); -var - RepMsg: TStatusMessages; begin Self.Caption := 'Oni Un/Packer ' + version; Self.FormResize(Self); ConManager.OnCoonnectionListChanged := UpdateConLists; + Application.HintPause := 250; + Application.HintHidePause := 5000; + if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then begin AssignFile(AppSettingsFile, ExtractFilepath(Application.EXEname) + @@ -252,9 +266,12 @@ begin end else begin + ShowMessage('Warning!' + #13#10 + + 'It seems like this is the first time you OUP.' + #13#10 + + 'I do not take any responsibility for messed up data files' + #13+#10 + + 'Do not forget to make backup copies of your *.dat/*.raw/*.sep files!'); AppSettings.DatPath := ExtractFilepath(Application.EXEname); AppSettings.ExtractPath := ExtractFilepath(Application.EXEname) + '\extract'; - AppSettings.FilenumbersAsHex := False; AppSettings.CharSet := DEFAULT_CHARSET; AppSettings.HideUnusedData := False; end; @@ -263,7 +280,7 @@ begin begin ShowMessage('Load OPF-File: ' + ParamStr(2)); end - else if (MidStr(ParamStr(1), 1, 4) = 'oldb') or (MidStr(ParamStr(1), 1, 3) = 'dat') then + else if (MidStr(ParamStr(1), 1, 4) = 'oldb') or (MidStr(ParamStr(1), 1, 3) = 'dat') or (MidStr(ParamStr(1), 1, 3) = 'oni') then begin CreateConnection(ParamStr(2)); end; @@ -317,7 +334,7 @@ var pt: TPoint; tabIndex: Integer; hint: String; - tool: TForm_ToolTemplate; + tool: TForm_BaseTemplate; begin pt.X := X; pt.Y := Y; @@ -326,21 +343,24 @@ begin if tabIndex >= 0 then begin - if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then + if MDITab.MDIChildren[tabIndex] is TForm_BaseTemplate then begin - tool := TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]); + tool := TForm_BaseTemplate(MDITab.MDIChildren[tabIndex]); if tool.ConnectionID > -1 then hint := 'Connection: ' + - ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) + #13+#10 + ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) else - hint := 'Connection: none' + #13+#10; - if tool.SelectedFile.ID > -1 then - hint := hint + 'Selected File: ' + - FormatNumber(tool.SelectedFile.ID, 5, '0') + '-' + - tool.SelectedFile.Name + '.' + - tool.SelectedFile.Extension - else - hint := hint + 'Selected File: none'; + hint := 'Connection: none'; + if tool is TForm_TemplateFile then + begin + if TForm_TemplateFile(tool).SelectedFile.ID > -1 then + hint := hint + #13+#10 + 'Selected File: ' + + FormatNumber(TForm_TemplateFile(tool).SelectedFile.ID, 5, '0') + '-' + + TForm_TemplateFile(tool).SelectedFile.Name + '.' + + TForm_TemplateFile(tool).SelectedFile.Extension + else + hint := hint + #13+#10 + 'Selected File: none'; + end; end else hint := 'Window: ' + MDITab.MDIChildren[tabIndex].Caption; @@ -409,6 +429,7 @@ begin tb_rawedit.Enabled := active; tb_txmpreplacer.Enabled := active; tb_extractor.Enabled := active; + tb_meta.Enabled := active; // tb_compare.Enabled := active; // tb_structure.Enabled := active; end; @@ -435,13 +456,12 @@ end; -procedure TForm_Main.ToolbarDockChanged(Sender: TObject); +procedure TForm_Main.Toolbar_mainDockChanged(Sender: TObject); var toolbar: TTBToolbar; position: TTBDockPosition; mode: TTBItemDisplayMode; i: Integer; - isEnabled: Boolean; begin toolbar := TTBToolbar(Sender); if toolbar.Floating then @@ -475,8 +495,8 @@ var begin if MDITab.MDIChildCount > 0 then for i := 0 to MDITab.MDIChildCount - 1 do - if MDITab.MDIChildren[i] is TForm_ToolTemplate then - TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList; + if MDITab.MDIChildren[i] is TForm_BaseTemplate then + TForm_BaseTemplate(MDITab.MDIChildren[i]).UpdateConList; menu_conns.Clear; if ConManager.Count > 0 then @@ -488,7 +508,6 @@ begin entry.Name := 'menu_conn_' + IntToStr(i); entry.OnClick := menu_conns_itemClick; menu_conns.Add(entry); - entry := nil; end; end; end; @@ -496,25 +515,19 @@ end; procedure TForm_Main.LoadFile(typedb: Boolean); var - ext: String; + i: Integer; begin opend.InitialDir := AppSettings.DatPath; - opend.Filter := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*'; + opend.Filter := 'Compatible level files|*.dat;*.oni;*.oldb|Oni level (*.dat)|*.dat|OniSplit Archive (*.oni)|*.oni|OUP level database (*.oldb)|*.oldb|Any (*.*)|*'; if typedb then - opend.FilterIndex := 3 + opend.FilterIndex := 4 else opend.FilterIndex := 2; if opend.Execute then begin - ext := ExtractFileExt(opend.FileName); - if ext = '.dat' then - begin - CreateConnection(opend.FileName); - end else if ext = '.oldb' then - begin - CreateConnection(opend.FileName); - end else - ShowMessage('Incompatible file'); + if opend.Files.Count > 0 then + for i := 0 to opend.Files.Count - 1 do + CreateConnection(opend.Files.Strings[i]); AppSettings.DatPath := ExtractFilepath(opend.FileName); end; UpdateStatBar; @@ -553,29 +566,23 @@ end; {####################################} procedure TForm_Main.menu_createdbClick(Sender: TObject); begin - ShowMessage('Not yet usable'); -{ opend.Filter := 'Oni-Dat-Files|*.dat'; saved.Filter := 'OUP-Level-DB (*.oldb)|*.oldb'; saved.DefaultExt := 'oldb'; if opend.Execute then if saved.Execute then Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName); -} end; procedure TForm_Main.menu_createlvlClick(Sender: TObject); begin - ShowMessage('Not yet usable'); -{ opend.Filter := 'OUP-Level-DB (*.oldb)|*.oldb'; saved.Filter := 'Oni-Dat-Files|*.dat'; saved.DefaultExt := 'dat'; if opend.Execute then if saved.Execute then Form_LevelDB.CreateLevel(opend.FileName, saved.FileName); -} end; @@ -584,41 +591,46 @@ end; {#################################} procedure TForm_Main.menu_previewClick(Sender: TObject); begin - open_child('preview', -1, -1); + open_child('preview'); end; procedure TForm_Main.menu_bineditClick(Sender: TObject); begin - open_child('binedit', -1, -1); + open_child('binedit'); end; procedure TForm_Main.menu_raweditClick(Sender: TObject); begin - open_child('rawedit', -1, -1); + open_child('rawedit'); end; procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject); begin - open_child('txmpreplace', -1, -1); + open_child('txmpreplace'); end; procedure TForm_Main.menu_extractorClick(Sender: TObject); begin - open_child('extractor', -1, -1); + open_child('extractor'); end; procedure TForm_Main.menu_metaClick(Sender: TObject); begin - ShowMessage('TBD'); + open_child('meta'); end; procedure TForm_Main.menu_filecompareClick(Sender: TObject); begin - open_child('compare', -1, -1); + open_child('compare'); end; - {#################################} + procedure TForm_Main.menu_filemanagerClick(Sender: TObject); +begin + open_child('filemanager'); +end; + +{#################################} {##### View-Menu-Handlers #####} {#################################} procedure TForm_Main.menu_windows_cascadeClick(Sender: TObject); @@ -680,11 +692,9 @@ end; procedure TForm_Main.menu_conns_itemClick(Sender: TObject); var name: String; - i: Integer; index: Integer; RepMsg: TStatusMessages; begin -// name := TTBItem(Sender).Caption; index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender)); name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName); if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+ @@ -692,6 +702,8 @@ begin begin CheckConnectionCloseable(index); ConManager.CloseConnectionByIndex(index, RepMsg); + ShowOpenMsg(RepMsg); + UpdateConLists; end; UpdateStatBar; end; @@ -703,7 +715,13 @@ end; procedure TForm_Main.menu_view_toolbarClick(Sender: TObject); begin menu_view_toolbar.Checked := not menu_view_toolbar.Checked; - Toolbar.Visible := menu_view_toolbar.Checked; + Toolbar_main.Visible := menu_view_toolbar.Checked; +end; + +procedure TForm_Main.menu_view_toolbar_toolsClick(Sender: TObject); +begin + menu_view_toolbar_tools.Checked := not menu_view_toolbar_tools.Checked; + Toolbar_tools.Visible := menu_view_toolbar_tools.Checked; end; procedure TForm_Main.menu_view_statusbarClick(Sender: TObject); @@ -729,12 +747,29 @@ end; -function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate; +function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_BaseTemplate; +type + TTemplate = class of TForm_BaseTemplate; + TTool = record + name: String; + icon: Integer; + caption: String; + classt: TTemplate; + end; +const + Tools: array[0..6] of TTool = ( + (name: 'binedit'; icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit), + (name: 'extractor'; icon: 8; caption: 'Extractor'; classt: TForm_Extractor), + (name: 'preview'; icon: 4; caption: 'Preview-Window'; classt: TForm_Preview), + (name: 'rawedit'; icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit), + (name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer'; classt: TForm_TxmpReplace), + (name: 'filemanager'; icon:-1; caption: 'FileManager'; classt: TForm_FileManager), + (name: 'meta'; icon: 11; caption: 'MetaEditor'; classt: TForm_Meta) + ); var - toolform: TForm_ToolTemplate; + toolform: TForm_BaseTemplate; i: Integer; tag: Integer; - caption_end: String; iconindex: Integer; begin Result := nil; @@ -746,37 +781,19 @@ begin tag := MDIChildren[i].Tag + 1; iconindex := -1; - caption_end := IntToStr(tag) + ' '; - if window_context = 'binedit' then - begin -// toolform := TForm_BinEdit.Create(Self); - toolform.Caption := 'Binary .dat-Editor ' + caption_end; - iconindex := 5; - end; - if window_context = 'extractor' then - begin -// toolform := TForm_Extractor.Create(Self); - toolform.Caption := 'Extractor ' + caption_end; - iconindex := 8; - end; - if window_context = 'preview' then - begin - toolform := TForm_Preview.Create(Self); - toolform.Caption := 'Preview-Window ' + caption_end; - iconindex := 4; - end; - if window_context = 'rawedit' then - begin -// toolform := TForm_RawEdit.Create(Self); - toolform.Caption := 'Binary .raw-Editor ' + caption_end; - iconindex := 6; - end; - if window_context = 'txmpreplace' then - begin -// toolform := TForm_TxmpReplace.Create(Application); - toolform.Caption := 'TXMP Replacer ' + caption_end; - iconindex := 7; + toolform := nil; + + for i := 0 to High(Tools) do + if Tools[i].name = window_context then + Break; + if i < Length(Tools) then + begin + toolform := TTemplate(Tools[i].classt).Create(Self); + toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + ' '; + iconindex := Tools[i].icon; + end else begin + ShowMessage('WindowContext not found!'); end; if Assigned(toolform) then @@ -785,14 +802,25 @@ begin toolform.Tag := tag; MDITab.AddTab(TForm(toolform), iconindex); toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', ''); - if connection > -1 then + if Connection > -1 then begin toolform.SelectConnection(connection); - if fileid > -1 then - toolform.SelectFileID(connection, fileid); + if (FileID > -1) and (toolform is TForm_TemplateFile) then + TForm_TemplateFile(toolform).SelectFileID(Connection, FileID); end; Result := toolform; end; end; +function TForm_Main.open_child(window_context: String; Connection: Integer): TForm_BaseTemplate; +begin + Result := open_child(window_context, Connection, -1); +end; + +function TForm_Main.open_child(window_context: String): TForm_BaseTemplate; +begin + Result := open_child(window_context, -1, -1); +end; + end. +