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