[93] | 1 | unit Main;
|
---|
| 2 | interface
|
---|
| 3 | uses
|
---|
| 4 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
| 5 | Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus, Grids,
|
---|
| 6 | MPHexEditor, ToolWin, ImgList, Tabs,
|
---|
| 7 | MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst,
|
---|
| 8 | Data, TypeDefs, ConnectionManager,
|
---|
| 9 | // Functions, Exporters, DataStructures,
|
---|
[97] | 10 | Functions,
|
---|
[93] | 11 | Settings, {Helper_LevelDB, }
|
---|
[97] | 12 | Template,
|
---|
[105] | 13 | RawEdit, BinEdit, Extractor, Preview, TxmpReplace;
|
---|
[93] | 14 |
|
---|
| 15 | type
|
---|
| 16 | TForm_Main = class(TForm)
|
---|
| 17 | saved: TSaveDialog;
|
---|
| 18 | opend: TOpenDialog;
|
---|
| 19 | statbar: TStatusBar;
|
---|
| 20 | MenuImages: TImageList;
|
---|
| 21 | DockTop: TTBDock;
|
---|
| 22 | MainMenu: TTBToolbar;
|
---|
| 23 | menu_main: TTBSubmenuItem;
|
---|
| 24 | menu_loadfile: TTBItem;
|
---|
| 25 | menu_sep1: TTBSeparatorItem;
|
---|
| 26 | menu_settings: TTBItem;
|
---|
| 27 | menu_sep4: TTBSeparatorItem;
|
---|
| 28 | menu_exit: TTBItem;
|
---|
| 29 | menu_convert: TTBSubmenuItem;
|
---|
| 30 | menu_createdb: TTBItem;
|
---|
| 31 | menu_createlvl: TTBItem;
|
---|
| 32 | menu_tools: TTBSubmenuItem;
|
---|
| 33 | menu_preview: TTBItem;
|
---|
| 34 | menu_binedit: TTBItem;
|
---|
| 35 | menu_rawedit: TTBItem;
|
---|
| 36 | menu_txmpreplace: TTBItem;
|
---|
| 37 | menu_extractor: TTBItem;
|
---|
| 38 | menu_filecompare: TTBItem;
|
---|
| 39 | menu_levelstructedit: TTBItem;
|
---|
| 40 | menu_view: TTBSubmenuItem;
|
---|
| 41 | menu_windows_cascade: TTBItem;
|
---|
| 42 | menu_windows_tile: TTBItem;
|
---|
| 43 | menu_windows_closeall: TTBItem;
|
---|
| 44 | menu_sep3: TTBSeparatorItem;
|
---|
| 45 | menu_windows_next: TTBItem;
|
---|
| 46 | menu_windows_previous: TTBItem;
|
---|
| 47 | menu_sep2: TTBSeparatorItem;
|
---|
| 48 | menu_About: TTBItem;
|
---|
| 49 | Toolbar: TTBToolbar;
|
---|
| 50 | tbOpen: TTBItem;
|
---|
| 51 | DockLeft: TTBDock;
|
---|
| 52 | DockRight: TTBDock;
|
---|
| 53 | DockBottom: TTBDock;
|
---|
| 54 | MDIToolbar: TTBToolbar;
|
---|
| 55 | TBControlItem1: TTBControlItem;
|
---|
| 56 | MDITab: TMDITab;
|
---|
| 57 | menu_toolbars: TTBSubmenuItem;
|
---|
| 58 | menu_view_mdibar: TTBItem;
|
---|
| 59 | menu_view_statusbar: TTBItem;
|
---|
| 60 | menu_view_toolbar: TTBItem;
|
---|
| 61 | tb_separator1: TTBSeparatorItem;
|
---|
| 62 | tb_preview: TTBItem;
|
---|
| 63 | tb_structure: TTBItem;
|
---|
| 64 | tb_compare: TTBItem;
|
---|
| 65 | tb_extractor: TTBItem;
|
---|
| 66 | tb_txmpreplacer: TTBItem;
|
---|
| 67 | tb_rawedit: TTBItem;
|
---|
| 68 | tb_datedit: TTBItem;
|
---|
| 69 | menu_windows_tilevert: TTBItem;
|
---|
| 70 | tb_meta: TTBItem;
|
---|
| 71 | menu_meta: TTBItem;
|
---|
| 72 | TBSeparatorItem1: TTBSeparatorItem;
|
---|
| 73 | tb_db2dat: TTBItem;
|
---|
| 74 | tb_dat2db: TTBItem;
|
---|
| 75 | menu_loaddb: TTBItem;
|
---|
| 76 | tb_opendb: TTBItem;
|
---|
| 77 | Images_Close: TImageList;
|
---|
| 78 | menu_conns: TTBSubmenuItem;
|
---|
| 79 | menu_windows: TTBSubmenuItem;
|
---|
| 80 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 81 | procedure FormResize(Sender: TObject);
|
---|
| 82 | procedure FormCreate(Sender: TObject);
|
---|
| 83 | procedure ActivateTools(active: Boolean);
|
---|
| 84 | procedure UpdateStatBar;
|
---|
| 85 | procedure UpdateConLists;
|
---|
| 86 | procedure LoadFile(typedb: Boolean);
|
---|
| 87 | function TryCloseAll: Boolean;
|
---|
| 88 | procedure MDITabDrawTab(Control: TCustomTabControl; TabIndex: Integer;
|
---|
| 89 | const Rect: TRect; Active: Boolean);
|
---|
| 90 | procedure MDITabMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
| 91 | Shift: TShiftState; X, Y: Integer);
|
---|
| 92 | procedure MDITabMouseMove(Sender: TObject; Shift: TShiftState; X,
|
---|
| 93 | Y: Integer);
|
---|
| 94 | procedure ToolbarDockChanged(Sender: TObject);
|
---|
| 95 | procedure CreateConnection(filename: String);
|
---|
[97] | 96 | function CheckConnectionCloseable(index: Integer): Boolean;
|
---|
[93] | 97 |
|
---|
| 98 | procedure menu_loadfileClick(Sender: TObject);
|
---|
| 99 | procedure menu_loaddbClick(Sender: TObject);
|
---|
| 100 | procedure menu_settingsClick(Sender: TObject);
|
---|
| 101 | procedure menu_exitClick(Sender: TObject);
|
---|
| 102 |
|
---|
| 103 | procedure menu_createlvlClick(Sender: TObject);
|
---|
| 104 | procedure menu_createdbClick(Sender: TObject);
|
---|
| 105 |
|
---|
| 106 | procedure menu_bineditClick(Sender: TObject);
|
---|
| 107 | procedure menu_filecompareClick(Sender: TObject);
|
---|
| 108 | procedure menu_raweditClick(Sender: TObject);
|
---|
| 109 | procedure menu_extractorClick(Sender: TObject);
|
---|
| 110 | procedure menu_txmpreplaceClick(Sender: TObject);
|
---|
| 111 | procedure menu_previewClick(Sender: TObject);
|
---|
| 112 | procedure menu_metaClick(Sender: TObject);
|
---|
| 113 | function open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate;
|
---|
| 114 |
|
---|
| 115 | procedure menu_windows_cascadeClick(Sender: TObject);
|
---|
| 116 | procedure menu_windows_tilevertClick(Sender: TObject);
|
---|
| 117 | procedure menu_windows_tileClick(Sender: TObject);
|
---|
| 118 | procedure menu_windows_closeallClick(Sender: TObject);
|
---|
| 119 | procedure menu_windows_previousClick(Sender: TObject);
|
---|
| 120 | procedure menu_windows_nextClick(Sender: TObject);
|
---|
| 121 | procedure menu_conns_itemClick(Sender: TObject);
|
---|
| 122 | procedure menu_windows_itemClick(Sender: TObject);
|
---|
| 123 | procedure menu_view_mdibarClick(Sender: TObject);
|
---|
| 124 | procedure menu_view_statusbarClick(Sender: TObject);
|
---|
| 125 | procedure menu_view_toolbarClick(Sender: TObject);
|
---|
| 126 |
|
---|
| 127 | procedure menu_AboutClick(Sender: TObject);
|
---|
| 128 |
|
---|
| 129 | procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
|
---|
| 130 | private
|
---|
| 131 | public
|
---|
| 132 | procedure DefaultHandler(var Message); override;
|
---|
| 133 | end;
|
---|
| 134 |
|
---|
| 135 | var
|
---|
| 136 | Form_Main: TForm_Main;
|
---|
| 137 |
|
---|
| 138 | implementation
|
---|
| 139 |
|
---|
| 140 | {$R *.dfm}
|
---|
| 141 |
|
---|
| 142 |
|
---|
| 143 | procedure ShowOpenMsg(msg: TStatusMessages);
|
---|
| 144 | begin
|
---|
| 145 | case msg of
|
---|
| 146 | SM_AlreadyOpened: ShowMessage('File already opened.');
|
---|
| 147 | SM_FileNotFound: ShowMessage('File not found.');
|
---|
| 148 | SM_UnknownExtension: ShowMessage('Unknown extension.');
|
---|
| 149 | SM_IncompatibleFile: ShowMessage('Incompatible file format.');
|
---|
| 150 | SM_UnknownError: ShowMessage('Unknown error.');
|
---|
| 151 | end;
|
---|
| 152 | end;
|
---|
| 153 |
|
---|
| 154 | procedure TForm_Main.CreateConnection(filename: String);
|
---|
| 155 | var
|
---|
| 156 | RepMsg: TStatusMessages;
|
---|
| 157 | begin
|
---|
[97] | 158 | ConManager.OpenConnection(filename, RepMsg);
|
---|
[93] | 159 | ShowOpenMsg(RepMsg);
|
---|
| 160 | if RepMsg = SM_OK then
|
---|
| 161 | begin
|
---|
| 162 | UpdateStatBar;
|
---|
[105] | 163 | UpdateConLists;
|
---|
[93] | 164 | end;
|
---|
| 165 | end;
|
---|
| 166 |
|
---|
[97] | 167 | function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean;
|
---|
| 168 | var
|
---|
| 169 | i: Integer;
|
---|
| 170 | toolform: TForm_ToolTemplate;
|
---|
| 171 | begin
|
---|
| 172 | if MDITab.MDIChildCount > 0 then
|
---|
| 173 | begin
|
---|
| 174 | for i := 0 to MDITab.MDIChildCount - 1 do
|
---|
| 175 | begin
|
---|
| 176 | if MDITab.MDIChildren[i] is TForm_ToolTemplate then
|
---|
| 177 | begin
|
---|
| 178 | toolform := TForm_ToolTemplate(MDITab.MDIChildren[i]);
|
---|
| 179 | if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then
|
---|
| 180 | begin
|
---|
| 181 | if not toolform.Closeable then
|
---|
| 182 | ShowMessage('Can not close toolwindow: ' + toolform.Caption);
|
---|
| 183 | end;
|
---|
| 184 | end;
|
---|
| 185 | end;
|
---|
| 186 | end;
|
---|
| 187 | end;
|
---|
| 188 |
|
---|
| 189 |
|
---|
[93] | 190 | { Eine zweite Instanz hat uns ihre Kommandozeilenparameter geschickt }
|
---|
| 191 | procedure TForm_Main.WMCopyData(var Msg: TWMCopyData);
|
---|
| 192 | var
|
---|
| 193 | strings: TStringList;
|
---|
| 194 | begin
|
---|
| 195 | if (Msg.CopyDataStruct.dwData = SecondInstMsgId) and (SecondInstMsgId <> 0) then
|
---|
| 196 | begin
|
---|
| 197 | Application.BringToFront;
|
---|
| 198 |
|
---|
| 199 | strings := TStringList.Create;
|
---|
| 200 | strings.Text := ParamBlobToStr(Msg.CopyDataStruct.lpData);
|
---|
| 201 | if strings.Count = 2 then
|
---|
| 202 | begin
|
---|
| 203 | if strings.Strings[0] = 'opf' then
|
---|
| 204 | begin
|
---|
| 205 | ShowMessage('Load OPF-File: ' + ParamStr(2));
|
---|
| 206 | end
|
---|
| 207 | else if (strings.Strings[0] = 'oldb') or (strings.Strings[0] = 'dat') then
|
---|
| 208 | begin
|
---|
| 209 | CreateConnection(strings.Strings[1]);
|
---|
| 210 | end;
|
---|
| 211 | end;
|
---|
| 212 | end
|
---|
| 213 | else
|
---|
| 214 | inherited;
|
---|
| 215 | end;
|
---|
| 216 |
|
---|
| 217 | {----------------------------------------------------------------------------}
|
---|
| 218 | { Wir überschreiben den DefaultHandler, der alle Nachrichten zuerst bekommt, }
|
---|
| 219 | { damit wir auf die Nachricht mit der ID SecondInstMsgId reagieren können. }
|
---|
| 220 | { (Dies ist notwendig, da wir jetzt noch nicht wissen welchen Wert }
|
---|
| 221 | { die ID haben wird, weswegen wir keine statische Message-Prozedure, }
|
---|
| 222 | { so wie bei WM_COPYDATA, schreiben können.) }
|
---|
| 223 | {----------------------------------------------------------------------------}
|
---|
| 224 | procedure TForm_Main.DefaultHandler(var Message);
|
---|
| 225 | begin
|
---|
| 226 | if TMessage(Message).Msg = SecondInstMsgId then
|
---|
| 227 | { Eine zweite Instanz hat uns nach dem Handle gefragt }
|
---|
| 228 | { Es wird in die Message-Queue des Threads gepostet. }
|
---|
| 229 | PostThreadMessage(TMessage(Message).WParam, SecondInstMsgId, Handle, 0)
|
---|
| 230 | else
|
---|
| 231 | inherited;
|
---|
| 232 | end;
|
---|
| 233 |
|
---|
| 234 |
|
---|
| 235 |
|
---|
| 236 | procedure TForm_Main.FormCreate(Sender: TObject);
|
---|
| 237 | var
|
---|
| 238 | RepMsg: TStatusMessages;
|
---|
| 239 | begin
|
---|
| 240 | Self.Caption := 'Oni Un/Packer ' + version;
|
---|
| 241 | Self.FormResize(Self);
|
---|
| 242 |
|
---|
[97] | 243 | ConManager.OnCoonnectionListChanged := UpdateConLists;
|
---|
[93] | 244 |
|
---|
| 245 | if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
|
---|
| 246 | begin
|
---|
| 247 | AssignFile(AppSettingsFile, ExtractFilepath(Application.EXEname) +
|
---|
| 248 | '\oniunpacker.ini');
|
---|
| 249 | Reset(AppSettingsFile);
|
---|
| 250 | Read(AppSettingsFile, AppSettings);
|
---|
| 251 | CloseFile(AppSettingsFile);
|
---|
| 252 | end
|
---|
| 253 | else
|
---|
| 254 | begin
|
---|
| 255 | AppSettings.DatPath := ExtractFilepath(Application.EXEname);
|
---|
| 256 | AppSettings.ExtractPath := ExtractFilepath(Application.EXEname) + '\extract';
|
---|
| 257 | AppSettings.CharSet := DEFAULT_CHARSET;
|
---|
| 258 | AppSettings.HideUnusedData := False;
|
---|
| 259 | end;
|
---|
| 260 |
|
---|
| 261 | if MidStr(ParamStr(1), 1, 3) = 'opf' then
|
---|
| 262 | begin
|
---|
| 263 | ShowMessage('Load OPF-File: ' + ParamStr(2));
|
---|
| 264 | end
|
---|
| 265 | else if (MidStr(ParamStr(1), 1, 4) = 'oldb') or (MidStr(ParamStr(1), 1, 3) = 'dat') then
|
---|
| 266 | begin
|
---|
| 267 | CreateConnection(ParamStr(2));
|
---|
| 268 | end;
|
---|
| 269 | UpdateStatBar;
|
---|
| 270 | end;
|
---|
| 271 |
|
---|
| 272 |
|
---|
| 273 |
|
---|
| 274 |
|
---|
| 275 | procedure TForm_Main.FormResize(Sender: TObject);
|
---|
| 276 | begin
|
---|
| 277 | statbar.Panels.Items[0].Width := Self.Width - 200;
|
---|
| 278 | MDITab.Width := Self.Width - 20;
|
---|
| 279 | end;
|
---|
| 280 |
|
---|
| 281 |
|
---|
| 282 |
|
---|
| 283 |
|
---|
| 284 | procedure TForm_Main.MDITabDrawTab(Control: TCustomTabControl;
|
---|
| 285 | TabIndex: Integer; const Rect: TRect; Active: Boolean);
|
---|
| 286 | var
|
---|
| 287 | x, y: Integer;
|
---|
| 288 | iconindex: Integer;
|
---|
| 289 | caption: String;
|
---|
| 290 | begin
|
---|
| 291 | iconindex := TMDITab(Control).Glyphs[TabIndex];
|
---|
| 292 | caption := TMDITab(Control).Captions[TabIndex];
|
---|
| 293 | if active then
|
---|
| 294 | begin
|
---|
| 295 | Control.Canvas.Font.Style := Control.Canvas.Font.Style + [fsItalic];
|
---|
| 296 | y := Rect.Top + 1;
|
---|
| 297 | end else
|
---|
| 298 | y := Rect.Top;
|
---|
| 299 | if iconindex >= 0 then
|
---|
| 300 | begin
|
---|
| 301 | TMDITab(Control).Images.Draw(Control.Canvas, Rect.Left + 4, y, iconindex);
|
---|
| 302 | x := Rect.Left + 26;
|
---|
| 303 | end else
|
---|
| 304 | x := Rect.Left + 4;
|
---|
| 305 | Control.Canvas.TextOut(x, y + 2, caption);
|
---|
| 306 | if active then
|
---|
| 307 | Images_Close.Draw(Control.Canvas, Rect.Right - 18, y, 0)
|
---|
| 308 | else
|
---|
| 309 | Images_Close.Draw(Control.Canvas, Rect.Right - 18, y, 1);
|
---|
| 310 | end;
|
---|
| 311 |
|
---|
| 312 |
|
---|
| 313 | procedure TForm_Main.MDITabMouseMove(Sender: TObject; Shift: TShiftState; X,
|
---|
| 314 | Y: Integer);
|
---|
| 315 | var
|
---|
| 316 | pt: TPoint;
|
---|
| 317 | tabIndex: Integer;
|
---|
| 318 | hint: String;
|
---|
[97] | 319 | tool: TForm_ToolTemplate;
|
---|
[93] | 320 | begin
|
---|
| 321 | pt.X := X;
|
---|
| 322 | pt.Y := Y;
|
---|
| 323 | tabIndex := MDITab.GetTabAtPos(pt);
|
---|
| 324 | hint := '';
|
---|
| 325 |
|
---|
| 326 | if tabIndex >= 0 then
|
---|
| 327 | begin
|
---|
| 328 | if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then
|
---|
| 329 | begin
|
---|
[97] | 330 | tool := TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]);
|
---|
| 331 | if tool.ConnectionID > -1 then
|
---|
[93] | 332 | hint := 'Connection: ' +
|
---|
[97] | 333 | ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) + #13+#10
|
---|
[93] | 334 | else
|
---|
| 335 | hint := 'Connection: none' + #13+#10;
|
---|
[97] | 336 | if tool.SelectedFile.ID > -1 then
|
---|
[93] | 337 | hint := hint + 'Selected File: ' +
|
---|
[97] | 338 | FormatNumber(tool.SelectedFile.ID, 5, '0') + '-' +
|
---|
| 339 | tool.SelectedFile.Name + '.' +
|
---|
| 340 | tool.SelectedFile.Extension
|
---|
[93] | 341 | else
|
---|
| 342 | hint := hint + 'Selected File: none';
|
---|
| 343 | end
|
---|
| 344 | else
|
---|
| 345 | hint := 'Window: ' + MDITab.MDIChildren[tabIndex].Caption;
|
---|
| 346 | if hint <> MDITab.Hint then
|
---|
| 347 | begin
|
---|
| 348 | MDITab.Hint := hint;
|
---|
| 349 | MDITab.ShowHint := True;
|
---|
| 350 | end;
|
---|
| 351 | end
|
---|
| 352 | else
|
---|
| 353 | begin
|
---|
| 354 | MDITab.ShowHint := False;
|
---|
| 355 | MDITab.Hint := '';
|
---|
| 356 | end;
|
---|
| 357 | end;
|
---|
| 358 |
|
---|
| 359 | procedure TForm_Main.MDITabMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
| 360 | Shift: TShiftState; X, Y: Integer);
|
---|
| 361 | var
|
---|
| 362 | pt: TPoint;
|
---|
| 363 | tabIndex: Integer;
|
---|
| 364 | tabRect: TRect;
|
---|
| 365 | tabX, tabY, tabWidth: Integer;
|
---|
| 366 | begin
|
---|
| 367 | pt.X := X;
|
---|
| 368 | pt.Y := Y;
|
---|
| 369 | tabIndex := MDITab.GetTabAtPos(pt);
|
---|
| 370 |
|
---|
| 371 | // if (Button = mbRight) and (tabIndex >= 0) then
|
---|
| 372 | // MDITab.MDIChildren[tabIndex].Close;
|
---|
| 373 |
|
---|
| 374 | if (Button = mbLeft) and (tabIndex >= 0) then
|
---|
| 375 | begin
|
---|
| 376 | tabrect := MDITab.TabRect(tabIndex);
|
---|
| 377 | tabX := X - tabrect.Left;
|
---|
| 378 | tabY := Y - tabrect.Top;
|
---|
| 379 | tabwidth := tabrect.Right - tabrect.Left;
|
---|
| 380 | if (tabY >= 4) and (tabY <= 17) then
|
---|
| 381 | if (tabX >= tabwidth - 19) and (tabX <= tabwidth - 7) then
|
---|
| 382 | MDITab.MDIChildren[tabIndex].Close;
|
---|
| 383 | end;
|
---|
| 384 | end;
|
---|
| 385 |
|
---|
| 386 |
|
---|
| 387 |
|
---|
| 388 |
|
---|
| 389 | procedure TForm_Main.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 390 | begin
|
---|
| 391 | AssignFile(AppSettingsFile, ExtractFilepath(Application.EXEname) + '\oniunpacker.ini');
|
---|
| 392 | if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
|
---|
| 393 | Reset(AppSettingsFile)
|
---|
| 394 | else
|
---|
| 395 | Rewrite(AppSettingsFile);
|
---|
| 396 | Write(AppSettingsFile, AppSettings);
|
---|
| 397 | CloseFile(AppSettingsFile);
|
---|
| 398 | Action := caFree;
|
---|
| 399 | end;
|
---|
| 400 |
|
---|
| 401 |
|
---|
| 402 |
|
---|
| 403 | procedure TForm_Main.ActivateTools(active: Boolean);
|
---|
| 404 | begin
|
---|
| 405 | menu_tools.Enabled := active;
|
---|
| 406 | tb_preview.Enabled := active;
|
---|
| 407 | tb_datedit.Enabled := active;
|
---|
| 408 | tb_rawedit.Enabled := active;
|
---|
| 409 | tb_txmpreplacer.Enabled := active;
|
---|
| 410 | tb_extractor.Enabled := active;
|
---|
| 411 | // tb_compare.Enabled := active;
|
---|
| 412 | // tb_structure.Enabled := active;
|
---|
| 413 | end;
|
---|
| 414 |
|
---|
| 415 | procedure TForm_Main.UpdateStatBar;
|
---|
| 416 | begin
|
---|
[97] | 417 | if ConManager.Count > 0 then
|
---|
[93] | 418 | begin
|
---|
| 419 | Self.Caption := 'Oni Un/Packer ' + version;
|
---|
| 420 | ActivateTools(True);
|
---|
[97] | 421 | statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count);
|
---|
[93] | 422 | end
|
---|
| 423 | else
|
---|
| 424 | begin
|
---|
| 425 | Self.Caption := 'Oni Un/Packer ' + version;
|
---|
| 426 | statbar.Panels.Items[0].Text := '';
|
---|
| 427 | statbar.Panels.Items[1].Text := 'Connections: -';
|
---|
| 428 | statbar.Panels.Items[2].Text := '';
|
---|
| 429 | ActivateTools(False);
|
---|
| 430 | end;
|
---|
[97] | 431 | menu_conns.Enabled := ConManager.Count > 0;
|
---|
[93] | 432 | end;
|
---|
| 433 |
|
---|
| 434 |
|
---|
| 435 |
|
---|
| 436 |
|
---|
| 437 | procedure TForm_Main.ToolbarDockChanged(Sender: TObject);
|
---|
| 438 | var
|
---|
| 439 | toolbar: TTBToolbar;
|
---|
| 440 | position: TTBDockPosition;
|
---|
| 441 | mode: TTBItemDisplayMode;
|
---|
| 442 | i: Integer;
|
---|
| 443 | isEnabled: Boolean;
|
---|
| 444 | begin
|
---|
| 445 | toolbar := TTBToolbar(Sender);
|
---|
| 446 | if toolbar.Floating then
|
---|
| 447 | mode := nbdmImageAndText
|
---|
| 448 | else begin
|
---|
| 449 | position := toolbar.CurrentDock.Position;
|
---|
| 450 | if position in [dpLeft, dpRight] then
|
---|
| 451 | mode := nbdmDefault
|
---|
| 452 | else
|
---|
| 453 | mode := nbdmImageAndText;
|
---|
| 454 | end;
|
---|
| 455 | for i := 0 to toolbar.Items.Count - 1 do
|
---|
| 456 | toolbar.Items.Items[i].DisplayMode := mode;
|
---|
| 457 | end;
|
---|
| 458 |
|
---|
| 459 | function TForm_Main.TryCloseAll: Boolean;
|
---|
| 460 | begin
|
---|
| 461 | menu_windows_closeallClick(Self);
|
---|
| 462 | Application.ProcessMessages;
|
---|
| 463 | if MDITab.MDIChildCount = 0 then
|
---|
| 464 | Result := True
|
---|
| 465 | else
|
---|
| 466 | Result := False;
|
---|
| 467 | end;
|
---|
| 468 |
|
---|
| 469 |
|
---|
| 470 | procedure TForm_Main.UpdateConLists;
|
---|
| 471 | var
|
---|
| 472 | i: Integer;
|
---|
| 473 | entry: TTBItem;
|
---|
| 474 | begin
|
---|
| 475 | if MDITab.MDIChildCount > 0 then
|
---|
| 476 | for i := 0 to MDITab.MDIChildCount - 1 do
|
---|
| 477 | if MDITab.MDIChildren[i] is TForm_ToolTemplate then
|
---|
| 478 | TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList;
|
---|
| 479 |
|
---|
| 480 | menu_conns.Clear;
|
---|
[97] | 481 | if ConManager.Count > 0 then
|
---|
[93] | 482 | begin
|
---|
[97] | 483 | for i := 0 to ConManager.Count - 1 do
|
---|
[93] | 484 | begin
|
---|
| 485 | entry := TTBItem.Create(menu_conns);
|
---|
[97] | 486 | entry.Caption := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
|
---|
[93] | 487 | entry.Name := 'menu_conn_' + IntToStr(i);
|
---|
| 488 | entry.OnClick := menu_conns_itemClick;
|
---|
| 489 | menu_conns.Add(entry);
|
---|
| 490 | entry := nil;
|
---|
| 491 | end;
|
---|
| 492 | end;
|
---|
| 493 | end;
|
---|
| 494 |
|
---|
| 495 |
|
---|
| 496 | procedure TForm_Main.LoadFile(typedb: Boolean);
|
---|
| 497 | var
|
---|
[105] | 498 | i: Integer;
|
---|
[93] | 499 | begin
|
---|
| 500 | opend.InitialDir := AppSettings.DatPath;
|
---|
| 501 | opend.Filter := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
|
---|
| 502 | if typedb then
|
---|
| 503 | opend.FilterIndex := 3
|
---|
| 504 | else
|
---|
| 505 | opend.FilterIndex := 2;
|
---|
| 506 | if opend.Execute then
|
---|
| 507 | begin
|
---|
[105] | 508 | if opend.Files.Count > 0 then
|
---|
| 509 | for i := 0 to opend.Files.Count - 1 do
|
---|
| 510 | CreateConnection(opend.Files.Strings[i]);
|
---|
[93] | 511 | AppSettings.DatPath := ExtractFilepath(opend.FileName);
|
---|
| 512 | end;
|
---|
| 513 | UpdateStatBar;
|
---|
| 514 | end;
|
---|
| 515 |
|
---|
| 516 |
|
---|
| 517 | {#################################}
|
---|
| 518 | {##### Main-Menu-Handlers #####}
|
---|
| 519 | {#################################}
|
---|
| 520 | procedure TForm_Main.menu_loaddbClick(Sender: TObject);
|
---|
| 521 | begin
|
---|
| 522 | LoadFile(True);
|
---|
| 523 | end;
|
---|
| 524 |
|
---|
| 525 | procedure TForm_Main.menu_loadfileClick(Sender: TObject);
|
---|
| 526 | begin
|
---|
| 527 | LoadFile(False);
|
---|
| 528 | end;
|
---|
| 529 |
|
---|
| 530 |
|
---|
| 531 | procedure TForm_Main.menu_settingsClick(Sender: TObject);
|
---|
| 532 | begin
|
---|
| 533 | Form_Settings.Visible := True;
|
---|
| 534 | Self.Enabled := False;
|
---|
| 535 | end;
|
---|
| 536 |
|
---|
| 537 |
|
---|
| 538 | procedure TForm_Main.menu_exitClick(Sender: TObject);
|
---|
| 539 | begin
|
---|
| 540 | Self.Close;
|
---|
| 541 | end;
|
---|
| 542 |
|
---|
| 543 |
|
---|
| 544 | {####################################}
|
---|
| 545 | {##### Converters-Menu-Handlers #####}
|
---|
| 546 | {####################################}
|
---|
| 547 | procedure TForm_Main.menu_createdbClick(Sender: TObject);
|
---|
| 548 | begin
|
---|
| 549 | ShowMessage('Not yet usable');
|
---|
| 550 | {
|
---|
| 551 | opend.Filter := 'Oni-Dat-Files|*.dat';
|
---|
| 552 | saved.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
|
---|
| 553 | saved.DefaultExt := 'oldb';
|
---|
| 554 | if opend.Execute then
|
---|
| 555 | if saved.Execute then
|
---|
| 556 | Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
|
---|
| 557 | }
|
---|
| 558 | end;
|
---|
| 559 |
|
---|
| 560 |
|
---|
| 561 | procedure TForm_Main.menu_createlvlClick(Sender: TObject);
|
---|
| 562 | begin
|
---|
| 563 | ShowMessage('Not yet usable');
|
---|
| 564 | {
|
---|
| 565 | opend.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
|
---|
| 566 | saved.Filter := 'Oni-Dat-Files|*.dat';
|
---|
| 567 | saved.DefaultExt := 'dat';
|
---|
| 568 | if opend.Execute then
|
---|
| 569 | if saved.Execute then
|
---|
| 570 | Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
|
---|
| 571 | }
|
---|
| 572 | end;
|
---|
| 573 |
|
---|
| 574 |
|
---|
| 575 | {#################################}
|
---|
| 576 | {##### Tools-Menu-Handlers #####}
|
---|
| 577 | {#################################}
|
---|
| 578 | procedure TForm_Main.menu_previewClick(Sender: TObject);
|
---|
| 579 | begin
|
---|
[97] | 580 | open_child('preview', -1, -1);
|
---|
[93] | 581 | end;
|
---|
| 582 |
|
---|
| 583 | procedure TForm_Main.menu_bineditClick(Sender: TObject);
|
---|
| 584 | begin
|
---|
[97] | 585 | open_child('binedit', -1, -1);
|
---|
[93] | 586 | end;
|
---|
| 587 |
|
---|
| 588 | procedure TForm_Main.menu_raweditClick(Sender: TObject);
|
---|
| 589 | begin
|
---|
[97] | 590 | open_child('rawedit', -1, -1);
|
---|
[93] | 591 | end;
|
---|
| 592 |
|
---|
| 593 | procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
|
---|
| 594 | begin
|
---|
[97] | 595 | open_child('txmpreplace', -1, -1);
|
---|
[93] | 596 | end;
|
---|
| 597 |
|
---|
| 598 | procedure TForm_Main.menu_extractorClick(Sender: TObject);
|
---|
| 599 | begin
|
---|
[97] | 600 | open_child('extractor', -1, -1);
|
---|
[93] | 601 | end;
|
---|
| 602 |
|
---|
| 603 | procedure TForm_Main.menu_metaClick(Sender: TObject);
|
---|
| 604 | begin
|
---|
| 605 | ShowMessage('TBD');
|
---|
| 606 | end;
|
---|
| 607 |
|
---|
| 608 | procedure TForm_Main.menu_filecompareClick(Sender: TObject);
|
---|
| 609 | begin
|
---|
[97] | 610 | open_child('compare', -1, -1);
|
---|
[93] | 611 | end;
|
---|
| 612 |
|
---|
| 613 |
|
---|
| 614 | {#################################}
|
---|
| 615 | {##### View-Menu-Handlers #####}
|
---|
| 616 | {#################################}
|
---|
| 617 | procedure TForm_Main.menu_windows_cascadeClick(Sender: TObject);
|
---|
| 618 | begin
|
---|
| 619 | Self.Cascade;
|
---|
| 620 | end;
|
---|
| 621 |
|
---|
| 622 | procedure TForm_Main.menu_windows_tilevertClick(Sender: TObject);
|
---|
| 623 | begin
|
---|
| 624 | Self.TileMode := tbVertical;
|
---|
| 625 | Self.Tile;
|
---|
| 626 | end;
|
---|
| 627 |
|
---|
| 628 | procedure TForm_Main.menu_windows_tileClick(Sender: TObject);
|
---|
| 629 | begin
|
---|
| 630 | Self.TileMode := tbHorizontal;
|
---|
| 631 | Self.Tile;
|
---|
| 632 | end;
|
---|
| 633 |
|
---|
| 634 | procedure TForm_Main.menu_windows_closeallClick(Sender: TObject);
|
---|
| 635 | begin
|
---|
| 636 | MDITab.CloseAll;
|
---|
| 637 | end;
|
---|
| 638 |
|
---|
| 639 | procedure TForm_Main.menu_windows_nextClick(Sender: TObject);
|
---|
| 640 | begin
|
---|
| 641 | if MDIChildCount > 1 then
|
---|
| 642 | if MDITab.TabIndex = MDITab.MDIChildCount - 1 then
|
---|
| 643 | MDITab.MDIChildren[0].BringToFront
|
---|
| 644 | else
|
---|
| 645 | MDITab.MDIChildren[MDITab.TabIndex + 1].BringToFront;
|
---|
| 646 | end;
|
---|
| 647 |
|
---|
| 648 | procedure TForm_Main.menu_windows_previousClick(Sender: TObject);
|
---|
| 649 | begin
|
---|
| 650 | if MDIChildCount > 1 then
|
---|
| 651 | if MDITab.TabIndex = 0 then
|
---|
| 652 | MDITab.MDIChildren[MDITab.MDIChildCount - 1].BringToFront
|
---|
| 653 | else
|
---|
| 654 | MDITab.MDIChildren[MDITab.TabIndex - 1].BringToFront;
|
---|
| 655 | end;
|
---|
| 656 |
|
---|
| 657 |
|
---|
| 658 | {##################################}
|
---|
| 659 | {##### Windows-Menu-Handlers #####}
|
---|
| 660 | {##################################}
|
---|
| 661 | procedure TForm_Main.menu_windows_itemClick(Sender: TObject);
|
---|
| 662 | var
|
---|
| 663 | name: String;
|
---|
| 664 | begin
|
---|
| 665 | name := TTBItem(Sender).Name;
|
---|
| 666 | end;
|
---|
| 667 |
|
---|
| 668 |
|
---|
| 669 |
|
---|
| 670 | {######################################}
|
---|
| 671 | {##### Connections-Menu-Handlers #####}
|
---|
| 672 | {######################################}
|
---|
| 673 | procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
|
---|
| 674 | var
|
---|
| 675 | name: String;
|
---|
| 676 | i: Integer;
|
---|
[97] | 677 | index: Integer;
|
---|
| 678 | RepMsg: TStatusMessages;
|
---|
[93] | 679 | begin
|
---|
[97] | 680 | // name := TTBItem(Sender).Caption;
|
---|
| 681 | index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender));
|
---|
| 682 | name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName);
|
---|
[93] | 683 | if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
|
---|
| 684 | name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then
|
---|
| 685 | begin
|
---|
[97] | 686 | CheckConnectionCloseable(index);
|
---|
| 687 | ConManager.CloseConnectionByIndex(index, RepMsg);
|
---|
[105] | 688 | ShowOpenMsg(RepMsg);
|
---|
| 689 | UpdateConLists;
|
---|
[93] | 690 | end;
|
---|
| 691 | UpdateStatBar;
|
---|
| 692 | end;
|
---|
| 693 |
|
---|
| 694 |
|
---|
| 695 | {###################################}
|
---|
| 696 | {##### Toolbars-Menu-Handlers #####}
|
---|
| 697 | {###################################}
|
---|
| 698 | procedure TForm_Main.menu_view_toolbarClick(Sender: TObject);
|
---|
| 699 | begin
|
---|
| 700 | menu_view_toolbar.Checked := not menu_view_toolbar.Checked;
|
---|
| 701 | Toolbar.Visible := menu_view_toolbar.Checked;
|
---|
| 702 | end;
|
---|
| 703 |
|
---|
| 704 | procedure TForm_Main.menu_view_statusbarClick(Sender: TObject);
|
---|
| 705 | begin
|
---|
| 706 | menu_view_statusbar.Checked := not menu_view_statusbar.Checked;
|
---|
| 707 | statbar.Visible := menu_view_statusbar.Checked;
|
---|
| 708 | end;
|
---|
| 709 |
|
---|
| 710 | procedure TForm_Main.menu_view_mdibarClick(Sender: TObject);
|
---|
| 711 | begin
|
---|
| 712 | menu_view_mdibar.Checked := not menu_view_mdibar.Checked;
|
---|
| 713 | mditoolbar.Visible := menu_view_mdibar.Checked;
|
---|
| 714 | end;
|
---|
| 715 |
|
---|
| 716 |
|
---|
| 717 |
|
---|
| 718 | procedure TForm_Main.menu_AboutClick(Sender: TObject);
|
---|
| 719 | begin
|
---|
| 720 | ShowMessage('Will be implemented later ;)');
|
---|
| 721 | end;
|
---|
| 722 |
|
---|
| 723 |
|
---|
| 724 |
|
---|
| 725 |
|
---|
| 726 |
|
---|
| 727 | function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate;
|
---|
| 728 | var
|
---|
| 729 | toolform: TForm_ToolTemplate;
|
---|
| 730 | i: Integer;
|
---|
| 731 | tag: Integer;
|
---|
| 732 | caption_end: String;
|
---|
| 733 | iconindex: Integer;
|
---|
| 734 | begin
|
---|
| 735 | Result := nil;
|
---|
| 736 |
|
---|
| 737 | tag := 1;
|
---|
| 738 | if MDIChildCount > 0 then
|
---|
| 739 | for i := 0 to MDIChildCount - 1 do
|
---|
| 740 | if MDIChildren[i].Tag >= tag then
|
---|
| 741 | tag := MDIChildren[i].Tag + 1;
|
---|
| 742 |
|
---|
| 743 | iconindex := -1;
|
---|
| 744 | caption_end := IntToStr(tag) + ' ';
|
---|
| 745 |
|
---|
| 746 | if window_context = 'binedit' then
|
---|
| 747 | begin
|
---|
[105] | 748 | toolform := TForm_BinEdit.Create(Self);
|
---|
[93] | 749 | toolform.Caption := 'Binary .dat-Editor ' + caption_end;
|
---|
| 750 | iconindex := 5;
|
---|
| 751 | end;
|
---|
| 752 | if window_context = 'extractor' then
|
---|
| 753 | begin
|
---|
[105] | 754 | toolform := TForm_Extractor.Create(Self);
|
---|
[93] | 755 | toolform.Caption := 'Extractor ' + caption_end;
|
---|
| 756 | iconindex := 8;
|
---|
| 757 | end;
|
---|
| 758 | if window_context = 'preview' then
|
---|
| 759 | begin
|
---|
| 760 | toolform := TForm_Preview.Create(Self);
|
---|
| 761 | toolform.Caption := 'Preview-Window ' + caption_end;
|
---|
| 762 | iconindex := 4;
|
---|
| 763 | end;
|
---|
| 764 | if window_context = 'rawedit' then
|
---|
| 765 | begin
|
---|
[105] | 766 | toolform := TForm_RawEdit.Create(Self);
|
---|
[93] | 767 | toolform.Caption := 'Binary .raw-Editor ' + caption_end;
|
---|
| 768 | iconindex := 6;
|
---|
| 769 | end;
|
---|
| 770 | if window_context = 'txmpreplace' then
|
---|
| 771 | begin
|
---|
[105] | 772 | toolform := TForm_TxmpReplace.Create(Self);
|
---|
[93] | 773 | toolform.Caption := 'TXMP Replacer ' + caption_end;
|
---|
| 774 | iconindex := 7;
|
---|
| 775 | end;
|
---|
| 776 |
|
---|
| 777 | if Assigned(toolform) then
|
---|
| 778 | begin
|
---|
| 779 | toolform.Name := window_context + IntToStr(tag);
|
---|
| 780 | toolform.Tag := tag;
|
---|
| 781 | MDITab.AddTab(TForm(toolform), iconindex);
|
---|
| 782 | toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', '');
|
---|
[97] | 783 | if connection > -1 then
|
---|
[93] | 784 | begin
|
---|
[97] | 785 | toolform.SelectConnection(connection);
|
---|
| 786 | if fileid > -1 then
|
---|
| 787 | toolform.SelectFileID(connection, fileid);
|
---|
[93] | 788 | end;
|
---|
| 789 | Result := toolform;
|
---|
| 790 | end;
|
---|
| 791 | end;
|
---|
| 792 |
|
---|
| 793 | end.
|
---|