--- oup/rewrite/Main.pas 2007/01/18 17:15:59 93 +++ oup/current/Main.pas 2007/03/30 00:51:58 139 @@ -7,8 +7,10 @@ uses MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst, Data, TypeDefs, ConnectionManager, // Functions, Exporters, DataStructures, + Functions, Settings, {Helper_LevelDB, } - Template, BinEdit, Extractor, Preview, RawEdit, TxmpReplace; + Template, + RawEdit, BinEdit, Extractor, Preview, TxmpReplace; type TForm_Main = class(TForm) @@ -91,6 +93,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 +128,6 @@ type procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA; private - ConnectionManager: TConnectionManager; public procedure DefaultHandler(var Message); override; end; @@ -135,6 +137,9 @@ var implementation +uses + LevelDB; + {$R *.dfm} @@ -153,14 +158,42 @@ 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 UpdateStatBar; + UpdateConLists; + end; +end; + +function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean; +var + i: Integer; + toolform: TForm_ToolTemplate; +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 + begin + toolform := TForm_ToolTemplate(MDITab.MDIChildren[i]); + if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then + begin + if not toolform.Closeable then + begin + ShowMessage('Can not close toolwindow: ' + toolform.Caption); + Result := False; + end; + end; + end; + end; end; end; + { Eine zweite Instanz hat uns ihre Kommandozeilenparameter geschickt } procedure TForm_Main.WMCopyData(var Msg: TWMCopyData); var @@ -208,14 +241,11 @@ end; procedure TForm_Main.FormCreate(Sender: TObject); -var - RepMsg: TStatusMessages; 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 @@ -229,7 +259,6 @@ begin begin AppSettings.DatPath := ExtractFilepath(Application.EXEname); AppSettings.ExtractPath := ExtractFilepath(Application.EXEname) + '\extract'; - AppSettings.FilenumbersAsHex := False; AppSettings.CharSet := DEFAULT_CHARSET; AppSettings.HideUnusedData := False; end; @@ -292,6 +321,7 @@ var pt: TPoint; tabIndex: Integer; hint: String; + tool: TForm_ToolTemplate; begin pt.X := X; pt.Y := Y; @@ -302,14 +332,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 +419,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 +433,7 @@ begin statbar.Panels.Items[2].Text := ''; ActivateTools(False); end; - menu_conns.Enabled := Length(DataConnections) > 0; + menu_conns.Enabled := ConManager.Count > 0; end; @@ -412,7 +445,6 @@ var position: TTBDockPosition; mode: TTBItemDisplayMode; i: Integer; - isEnabled: Boolean; begin toolbar := TTBToolbar(Sender); if toolbar.Floating then @@ -450,12 +482,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); @@ -467,7 +499,7 @@ 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 (*.*)|*'; @@ -477,15 +509,9 @@ begin 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; @@ -524,29 +550,27 @@ end; {####################################} procedure TForm_Main.menu_createdbClick(Sender: TObject); begin - ShowMessage('Not yet usable'); -{ +// 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'); -{ +// 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; @@ -555,27 +579,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 +609,7 @@ end; procedure TForm_Main.menu_filecompareClick(Sender: TObject); begin - open_child('compare', nil, -1); + open_child('compare', -1, -1); end; @@ -651,18 +675,19 @@ end; procedure TForm_Main.menu_conns_itemClick(Sender: TObject); 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); + ShowOpenMsg(RepMsg); + UpdateConLists; end; UpdateStatBar; end; @@ -719,6 +744,8 @@ begin iconindex := -1; caption_end := IntToStr(tag) + ' '; + toolform := nil; + if window_context = 'binedit' then begin toolform := TForm_BinEdit.Create(Self); @@ -745,7 +772,7 @@ begin end; if window_context = 'txmpreplace' then begin - toolform := TForm_TxmpReplace.Create(Application); + toolform := TForm_TxmpReplace.Create(Self); toolform.Caption := 'TXMP Replacer ' + caption_end; iconindex := 7; end; @@ -756,9 +783,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;