ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/Main.pas
(Generate patch)

Comparing:
oup/rewrite/Main.pas (file contents), Revision 93 by alloc, Thu Jan 18 17:15:59 2007 UTC vs.
oup/current/Main.pas (file contents), Revision 197 by alloc, Sat May 26 18:42:15 2007 UTC

# Line 6 | Line 6 | uses
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)
# Line 91 | Line 90 | type
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);
# Line 125 | Line 125 | type
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;
# Line 135 | Line 134 | var
134  
135   implementation
136  
137 + uses
138 +  LevelDB;
139 +
140   {$R *.dfm}
141  
142  
# Line 153 | Line 155 | procedure TForm_Main.CreateConnection(fi
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
# Line 208 | Line 238 | end;
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
# Line 227 | Line 254 | 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;
# Line 292 | Line 322 | var
322    pt: TPoint;
323    tabIndex: Integer;
324    hint: String;
325 +  tool: TForm_ToolTemplate;
326   begin
327    pt.X := X;
328    pt.Y := Y;
# Line 302 | Line 333 | begin
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
# Line 386 | Line 420 | end;
420  
421   procedure TForm_Main.UpdateStatBar;
422   begin
423 <  if Length(DataConnections) > 0 then
423 >  if ConManager.Count > 0 then
424    begin
425      Self.Caption      := 'Oni Un/Packer ' + version;
426      ActivateTools(True);
427 <    statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(Length(DataConnections));
427 >    statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count);
428    end
429    else
430    begin
# Line 400 | Line 434 | begin
434      statbar.Panels.Items[2].Text := '';
435      ActivateTools(False);
436    end;
437 <  menu_conns.Enabled := Length(DataConnections) > 0;
437 >  menu_conns.Enabled := ConManager.Count > 0;
438   end;
439  
440  
# Line 412 | Line 446 | var
446    position: TTBDockPosition;
447    mode: TTBItemDisplayMode;
448    i: Integer;
415  isEnabled: Boolean;
449   begin
450    toolbar := TTBToolbar(Sender);
451    if toolbar.Floating then
# Line 450 | Line 483 | begin
483          TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList;
484  
485    menu_conns.Clear;
486 <  if ConnectionManager.Count > 0 then
486 >  if ConManager.Count > 0 then
487    begin
488 <    for i := 0 to ConnectionManager.Count - 1 do
488 >    for i := 0 to ConManager.Count - 1 do
489      begin
490        entry := TTBItem.Create(menu_conns);
491 <      entry.Caption := ExtractFileName(DataConnections[i].FileName);
491 >      entry.Caption := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
492        entry.Name := 'menu_conn_' + IntToStr(i);
493        entry.OnClick := menu_conns_itemClick;
494        menu_conns.Add(entry);
# Line 467 | Line 500 | end;
500  
501   procedure TForm_Main.LoadFile(typedb: Boolean);
502   var
503 <  ext: String;
503 >  i: Integer;
504   begin
505    opend.InitialDir := AppSettings.DatPath;
506    opend.Filter     := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
# Line 477 | Line 510 | begin
510      opend.FilterIndex := 2;
511    if opend.Execute then
512    begin
513 <    ext := ExtractFileExt(opend.FileName);
514 <    if ext = '.dat' then
515 <    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');
513 >    if opend.Files.Count > 0 then
514 >      for i := 0 to opend.Files.Count - 1 do
515 >        CreateConnection(opend.Files.Strings[i]);
516      AppSettings.DatPath := ExtractFilepath(opend.FileName);
517    end;
518    UpdateStatBar;
# Line 524 | Line 551 | end;
551   {####################################}
552   procedure TForm_Main.menu_createdbClick(Sender: TObject);
553   begin
554 <  ShowMessage('Not yet usable');
555 < {
554 > //  ShowMessage('Not yet usable');
555 >
556    opend.Filter     := 'Oni-Dat-Files|*.dat';
557    saved.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb';
558    saved.DefaultExt := 'oldb';
559    if opend.Execute then
560      if saved.Execute then
561        Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
535 }
562   end;
563  
564  
565   procedure TForm_Main.menu_createlvlClick(Sender: TObject);
566   begin
567 <  ShowMessage('Not yet usable');
568 < {
567 > //  ShowMessage('Not yet usable');
568 >
569    opend.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb';
570    saved.Filter     := 'Oni-Dat-Files|*.dat';
571    saved.DefaultExt := 'dat';
572    if opend.Execute then
573      if saved.Execute then
574        Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
549 }
575   end;
576  
577  
# Line 555 | Line 580 | end;
580   {#################################}
581   procedure TForm_Main.menu_previewClick(Sender: TObject);
582   begin
583 <  open_child('preview', nil, -1);
583 >  open_child('preview', -1, -1);
584   end;
585  
586   procedure TForm_Main.menu_bineditClick(Sender: TObject);
587   begin
588 <  open_child('binedit', nil, -1);
588 >  open_child('binedit', -1, -1);
589   end;
590  
591   procedure TForm_Main.menu_raweditClick(Sender: TObject);
592   begin
593 <  open_child('rawedit', nil, -1);
593 >  open_child('rawedit', -1, -1);
594   end;
595  
596   procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
597   begin
598 <  open_child('txmpreplace', nil, -1);
598 >  open_child('txmpreplace', -1, -1);
599   end;
600  
601   procedure TForm_Main.menu_extractorClick(Sender: TObject);
602   begin
603 <  open_child('extractor', nil, -1);
603 >  open_child('extractor', -1, -1);
604   end;
605  
606   procedure TForm_Main.menu_metaClick(Sender: TObject);
# Line 585 | Line 610 | end;
610  
611   procedure TForm_Main.menu_filecompareClick(Sender: TObject);
612   begin
613 <  open_child('compare', nil, -1);
613 >  open_child('compare', -1, -1);
614   end;
615  
616  
# Line 651 | Line 676 | end;
676   procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
677   var
678    name: String;
679 <  i: Integer;
679 >  index: Integer;
680 >  RepMsg: TStatusMessages;
681   begin
682 <  name := TTBItem(Sender).Caption;
682 > //  name := TTBItem(Sender).Caption;
683 >  index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender));
684 >  name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName);
685    if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
686          name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then
687    begin
688 <    for i := 0 to High(DataConnections) do
689 <      if ExtractFileName(DataConnections[i].FileName) = name then
690 <      begin
691 <        CloseDataConnection(DataConnections[i]);
664 <        Break;
665 <      end;
688 >    CheckConnectionCloseable(index);
689 >    ConManager.CloseConnectionByIndex(index, RepMsg);
690 >    ShowOpenMsg(RepMsg);
691 >    UpdateConLists;
692    end;
693    UpdateStatBar;
694   end;
# Line 701 | Line 727 | end;
727  
728  
729   function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate;
730 + type
731 +  TTemplate = class of TForm_ToolTemplate;
732 +  TTool = record
733 +      name: String;
734 +      icon: Integer;
735 +      caption: String;
736 +      classt: TTemplate;
737 +  end;
738 + const
739 +  Tools: array[0..4] of TTool = (
740 +    (name: 'binedit';     icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit),
741 +    (name: 'extractor';   icon: 8; caption: 'Extractor';          classt: TForm_Extractor),
742 +    (name: 'preview';     icon: 4; caption: 'Preview-Window';     classt: TForm_Preview),
743 +    (name: 'rawedit';     icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit),
744 +    (name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer';      classt: TForm_TxmpReplace)
745 +  );
746   var
747    toolform:    TForm_ToolTemplate;
748    i:           Integer;
749    tag:         Integer;
708  caption_end: String;
750    iconindex:   Integer;
751   begin
752    Result := nil;
# Line 717 | Line 758 | begin
758          tag := MDIChildren[i].Tag + 1;
759  
760    iconindex := -1;
720  caption_end := IntToStr(tag) + '       ';
761  
762 <  if window_context = 'binedit' then
763 <  begin
764 <    toolform         := TForm_BinEdit.Create(Self);
765 <    toolform.Caption := 'Binary .dat-Editor ' + caption_end;
766 <    iconindex        := 5;
767 <  end;
768 <  if window_context = 'extractor' then
769 <  begin
770 <    toolform         := TForm_Extractor.Create(Self);
771 <    toolform.Caption := 'Extractor ' + caption_end;
772 <    iconindex        := 8;
773 <  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;
762 >  toolform := nil;
763 >
764 >  for i := 0 to High(Tools) do
765 >    if Tools[i].name = window_context then
766 >      Break;
767 >  if i < Length(Tools) then
768 >  begin
769 >    toolform         := TTemplate(Tools[i].classt).Create(Self);
770 >    toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + '       ';
771 >    iconindex        := Tools[i].icon;
772 >  end else begin
773 >    ShowMessage('WindowContext not found!');
774    end;
775  
776    if Assigned(toolform) then
# Line 756 | Line 779 | begin
779      toolform.Tag     := tag;
780      MDITab.AddTab(TForm(toolform), iconindex);
781      toolform.Caption := AnsiReplaceStr(toolform.Caption, '       ', '');
782 <    if (fileid > -1) and (connection <> nil) then
782 >    if connection > -1 then
783      begin
784 <      toolform.SelectFileID(connection, fileid);
784 >      toolform.SelectConnection(connection);
785 >      if fileid > -1 then
786 >        toolform.SelectFileID(connection, fileid);
787      end;
788      Result := toolform;
789    end;

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)