--- oup/rewrite/Main.pas 2007/01/18 17:15:59 93 +++ oup/rewrite/Main.pas 2007/01/22 23:05:45 97 @@ -7,8 +7,11 @@ uses MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst, Data, TypeDefs, ConnectionManager, // Functions, Exporters, DataStructures, + Functions, Settings, {Helper_LevelDB, } - Template, BinEdit, Extractor, Preview, RawEdit, TxmpReplace; + Template, + Preview; +// BinEdit, Extractor, RawEdit, TxmpReplace; type TForm_Main = class(TForm) @@ -91,6 +94,7 @@ type Y: Integer); procedure ToolbarDockChanged(Sender: TObject); procedure CreateConnection(filename: String); + function CheckConnectionCloseable(index: Integer): Boolean; procedure menu_loadfileClick(Sender: TObject); procedure menu_loaddbClick(Sender: TObject); @@ -125,7 +129,6 @@ type procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA; private - ConnectionManager: TConnectionManager; public procedure DefaultHandler(var Message); override; end; @@ -153,7 +156,7 @@ procedure TForm_Main.CreateConnection(fi var RepMsg: TStatusMessages; begin - ConnectionManager.OpenConnection(filename, RepMsg); + ConManager.OpenConnection(filename, RepMsg); ShowOpenMsg(RepMsg); if RepMsg = SM_OK then begin @@ -161,6 +164,29 @@ begin end; end; +function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean; +var + i: Integer; + toolform: TForm_ToolTemplate; +begin + if MDITab.MDIChildCount > 0 then + begin + for i := 0 to MDITab.MDIChildCount - 1 do + begin + if MDITab.MDIChildren[i] is TForm_ToolTemplate then + begin + toolform := TForm_ToolTemplate(MDITab.MDIChildren[i]); + if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then + begin + if not toolform.Closeable then + ShowMessage('Can not close toolwindow: ' + toolform.Caption); + end; + end; + end; + end; +end; + + { Eine zweite Instanz hat uns ihre Kommandozeilenparameter geschickt } procedure TForm_Main.WMCopyData(var Msg: TWMCopyData); var @@ -214,8 +240,7 @@ begin Self.Caption := 'Oni Un/Packer ' + version; Self.FormResize(Self); - ConnectionManager := TConnectionManager.Create; - ConnectionManager.OnCoonnectionListChanged := UpdateConLists; + ConManager.OnCoonnectionListChanged := UpdateConLists; if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then begin @@ -292,6 +317,7 @@ var pt: TPoint; tabIndex: Integer; hint: String; + tool: TForm_ToolTemplate; begin pt.X := X; pt.Y := Y; @@ -302,14 +328,17 @@ begin begin if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then begin - if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection <> nil then + tool := TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]); + if tool.ConnectionID > -1 then hint := 'Connection: ' + - ExtractFileName(TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection.FileName) + #13+#10 + ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) + #13+#10 else hint := 'Connection: none' + #13+#10; - if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.ID >= 0 then + if tool.SelectedFile.ID > -1 then hint := hint + 'Selected File: ' + - TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.FileName + FormatNumber(tool.SelectedFile.ID, 5, '0') + '-' + + tool.SelectedFile.Name + '.' + + tool.SelectedFile.Extension else hint := hint + 'Selected File: none'; end @@ -386,11 +415,11 @@ end; procedure TForm_Main.UpdateStatBar; begin - if Length(DataConnections) > 0 then + if ConManager.Count > 0 then begin Self.Caption := 'Oni Un/Packer ' + version; ActivateTools(True); - statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(Length(DataConnections)); + statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count); end else begin @@ -400,7 +429,7 @@ begin statbar.Panels.Items[2].Text := ''; ActivateTools(False); end; - menu_conns.Enabled := Length(DataConnections) > 0; + menu_conns.Enabled := ConManager.Count > 0; end; @@ -450,12 +479,12 @@ begin TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList; menu_conns.Clear; - if ConnectionManager.Count > 0 then + if ConManager.Count > 0 then begin - for i := 0 to ConnectionManager.Count - 1 do + for i := 0 to ConManager.Count - 1 do begin entry := TTBItem.Create(menu_conns); - entry.Caption := ExtractFileName(DataConnections[i].FileName); + entry.Caption := ExtractFileName(ConManager.ConnectionByIndex[i].FileName); entry.Name := 'menu_conn_' + IntToStr(i); entry.OnClick := menu_conns_itemClick; menu_conns.Add(entry); @@ -555,27 +584,27 @@ end; {#################################} procedure TForm_Main.menu_previewClick(Sender: TObject); begin - open_child('preview', nil, -1); + open_child('preview', -1, -1); end; procedure TForm_Main.menu_bineditClick(Sender: TObject); begin - open_child('binedit', nil, -1); + open_child('binedit', -1, -1); end; procedure TForm_Main.menu_raweditClick(Sender: TObject); begin - open_child('rawedit', nil, -1); + open_child('rawedit', -1, -1); end; procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject); begin - open_child('txmpreplace', nil, -1); + open_child('txmpreplace', -1, -1); end; procedure TForm_Main.menu_extractorClick(Sender: TObject); begin - open_child('extractor', nil, -1); + open_child('extractor', -1, -1); end; procedure TForm_Main.menu_metaClick(Sender: TObject); @@ -585,7 +614,7 @@ end; procedure TForm_Main.menu_filecompareClick(Sender: TObject); begin - open_child('compare', nil, -1); + open_child('compare', -1, -1); end; @@ -652,17 +681,17 @@ procedure TForm_Main.menu_conns_itemClic var name: String; i: Integer; + index: Integer; + RepMsg: TStatusMessages; begin - name := TTBItem(Sender).Caption; +// 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+ name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then begin - for i := 0 to High(DataConnections) do - if ExtractFileName(DataConnections[i].FileName) = name then - begin - CloseDataConnection(DataConnections[i]); - Break; - end; + CheckConnectionCloseable(index); + ConManager.CloseConnectionByIndex(index, RepMsg); end; UpdateStatBar; end; @@ -721,13 +750,13 @@ begin if window_context = 'binedit' then begin - toolform := TForm_BinEdit.Create(Self); +// 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 := TForm_Extractor.Create(Self); toolform.Caption := 'Extractor ' + caption_end; iconindex := 8; end; @@ -739,13 +768,13 @@ begin end; if window_context = 'rawedit' then begin - toolform := TForm_RawEdit.Create(Self); +// 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 := TForm_TxmpReplace.Create(Application); toolform.Caption := 'TXMP Replacer ' + caption_end; iconindex := 7; end; @@ -756,9 +785,11 @@ begin toolform.Tag := tag; MDITab.AddTab(TForm(toolform), iconindex); toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', ''); - if (fileid > -1) and (connection <> nil) then + if connection > -1 then begin - toolform.SelectFileID(connection, fileid); + toolform.SelectConnection(connection); + if fileid > -1 then + toolform.SelectFileID(connection, fileid); end; Result := toolform; end;