[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,
|
---|
[222] | 9 | Functions, Settings,
|
---|
| 10 | RawEdit, BinEdit, Extractor, Preview, TxmpReplace,
|
---|
| 11 | _BaseTemplate, _TemplateFile, _TemplateFileList;
|
---|
[93] | 12 |
|
---|
| 13 | type
|
---|
| 14 | TForm_Main = class(TForm)
|
---|
| 15 | saved: TSaveDialog;
|
---|
| 16 | opend: TOpenDialog;
|
---|
| 17 | statbar: TStatusBar;
|
---|
| 18 | MenuImages: TImageList;
|
---|
| 19 | DockTop: TTBDock;
|
---|
| 20 | MainMenu: TTBToolbar;
|
---|
| 21 | menu_main: TTBSubmenuItem;
|
---|
| 22 | menu_loadfile: TTBItem;
|
---|
| 23 | menu_sep1: TTBSeparatorItem;
|
---|
| 24 | menu_settings: TTBItem;
|
---|
| 25 | menu_sep4: TTBSeparatorItem;
|
---|
| 26 | menu_exit: TTBItem;
|
---|
| 27 | menu_convert: TTBSubmenuItem;
|
---|
| 28 | menu_createdb: TTBItem;
|
---|
| 29 | menu_createlvl: TTBItem;
|
---|
| 30 | menu_tools: TTBSubmenuItem;
|
---|
| 31 | menu_preview: TTBItem;
|
---|
| 32 | menu_binedit: TTBItem;
|
---|
| 33 | menu_rawedit: TTBItem;
|
---|
| 34 | menu_txmpreplace: TTBItem;
|
---|
| 35 | menu_extractor: TTBItem;
|
---|
| 36 | menu_filecompare: TTBItem;
|
---|
| 37 | menu_levelstructedit: TTBItem;
|
---|
| 38 | menu_view: TTBSubmenuItem;
|
---|
| 39 | menu_windows_cascade: TTBItem;
|
---|
| 40 | menu_windows_tile: TTBItem;
|
---|
| 41 | menu_windows_closeall: TTBItem;
|
---|
| 42 | menu_sep3: TTBSeparatorItem;
|
---|
| 43 | menu_windows_next: TTBItem;
|
---|
| 44 | menu_windows_previous: TTBItem;
|
---|
| 45 | menu_sep2: TTBSeparatorItem;
|
---|
| 46 | menu_About: TTBItem;
|
---|
| 47 | Toolbar: TTBToolbar;
|
---|
| 48 | tbOpen: TTBItem;
|
---|
| 49 | DockLeft: TTBDock;
|
---|
| 50 | DockRight: TTBDock;
|
---|
| 51 | DockBottom: TTBDock;
|
---|
| 52 | MDIToolbar: TTBToolbar;
|
---|
| 53 | TBControlItem1: TTBControlItem;
|
---|
| 54 | MDITab: TMDITab;
|
---|
| 55 | menu_toolbars: TTBSubmenuItem;
|
---|
| 56 | menu_view_mdibar: TTBItem;
|
---|
| 57 | menu_view_statusbar: TTBItem;
|
---|
| 58 | menu_view_toolbar: TTBItem;
|
---|
| 59 | tb_separator1: TTBSeparatorItem;
|
---|
| 60 | tb_preview: TTBItem;
|
---|
| 61 | tb_structure: TTBItem;
|
---|
| 62 | tb_compare: TTBItem;
|
---|
| 63 | tb_extractor: TTBItem;
|
---|
| 64 | tb_txmpreplacer: TTBItem;
|
---|
| 65 | tb_rawedit: TTBItem;
|
---|
| 66 | tb_datedit: TTBItem;
|
---|
| 67 | menu_windows_tilevert: TTBItem;
|
---|
| 68 | tb_meta: TTBItem;
|
---|
| 69 | menu_meta: TTBItem;
|
---|
| 70 | TBSeparatorItem1: TTBSeparatorItem;
|
---|
| 71 | tb_db2dat: TTBItem;
|
---|
| 72 | tb_dat2db: TTBItem;
|
---|
| 73 | menu_loaddb: TTBItem;
|
---|
| 74 | tb_opendb: TTBItem;
|
---|
| 75 | Images_Close: TImageList;
|
---|
| 76 | menu_conns: TTBSubmenuItem;
|
---|
| 77 | menu_windows: TTBSubmenuItem;
|
---|
| 78 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 79 | procedure FormResize(Sender: TObject);
|
---|
| 80 | procedure FormCreate(Sender: TObject);
|
---|
| 81 | procedure ActivateTools(active: Boolean);
|
---|
| 82 | procedure UpdateStatBar;
|
---|
| 83 | procedure UpdateConLists;
|
---|
| 84 | procedure LoadFile(typedb: Boolean);
|
---|
| 85 | function TryCloseAll: Boolean;
|
---|
| 86 | procedure MDITabDrawTab(Control: TCustomTabControl; TabIndex: Integer;
|
---|
| 87 | const Rect: TRect; Active: Boolean);
|
---|
| 88 | procedure MDITabMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
| 89 | Shift: TShiftState; X, Y: Integer);
|
---|
| 90 | procedure MDITabMouseMove(Sender: TObject; Shift: TShiftState; X,
|
---|
| 91 | Y: Integer);
|
---|
| 92 | procedure ToolbarDockChanged(Sender: TObject);
|
---|
| 93 | procedure CreateConnection(filename: String);
|
---|
[97] | 94 | function CheckConnectionCloseable(index: Integer): Boolean;
|
---|
[93] | 95 |
|
---|
| 96 | procedure menu_loadfileClick(Sender: TObject);
|
---|
| 97 | procedure menu_loaddbClick(Sender: TObject);
|
---|
| 98 | procedure menu_settingsClick(Sender: TObject);
|
---|
| 99 | procedure menu_exitClick(Sender: TObject);
|
---|
| 100 |
|
---|
| 101 | procedure menu_createlvlClick(Sender: TObject);
|
---|
| 102 | procedure menu_createdbClick(Sender: TObject);
|
---|
| 103 |
|
---|
| 104 | procedure menu_bineditClick(Sender: TObject);
|
---|
| 105 | procedure menu_filecompareClick(Sender: TObject);
|
---|
| 106 | procedure menu_raweditClick(Sender: TObject);
|
---|
| 107 | procedure menu_extractorClick(Sender: TObject);
|
---|
| 108 | procedure menu_txmpreplaceClick(Sender: TObject);
|
---|
| 109 | procedure menu_previewClick(Sender: TObject);
|
---|
| 110 | procedure menu_metaClick(Sender: TObject);
|
---|
| 111 |
|
---|
| 112 | procedure menu_windows_cascadeClick(Sender: TObject);
|
---|
| 113 | procedure menu_windows_tilevertClick(Sender: TObject);
|
---|
| 114 | procedure menu_windows_tileClick(Sender: TObject);
|
---|
| 115 | procedure menu_windows_closeallClick(Sender: TObject);
|
---|
| 116 | procedure menu_windows_previousClick(Sender: TObject);
|
---|
| 117 | procedure menu_windows_nextClick(Sender: TObject);
|
---|
| 118 | procedure menu_conns_itemClick(Sender: TObject);
|
---|
| 119 | procedure menu_windows_itemClick(Sender: TObject);
|
---|
| 120 | procedure menu_view_mdibarClick(Sender: TObject);
|
---|
| 121 | procedure menu_view_statusbarClick(Sender: TObject);
|
---|
| 122 | procedure menu_view_toolbarClick(Sender: TObject);
|
---|
| 123 |
|
---|
| 124 | procedure menu_AboutClick(Sender: TObject);
|
---|
| 125 |
|
---|
| 126 | procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
|
---|
| 127 | private
|
---|
| 128 | public
|
---|
[222] | 129 | function open_child(window_context: String; Connection, FileID: Integer): TForm_BaseTemplate; overload;
|
---|
| 130 | function open_child(window_context: String; Connection: Integer): TForm_BaseTemplate; overload;
|
---|
| 131 | function open_child(window_context: String): TForm_BaseTemplate; overload;
|
---|
[93] | 132 | procedure DefaultHandler(var Message); override;
|
---|
| 133 | end;
|
---|
| 134 |
|
---|
| 135 | var
|
---|
| 136 | Form_Main: TForm_Main;
|
---|
| 137 |
|
---|
| 138 | implementation
|
---|
| 139 |
|
---|
[129] | 140 | uses
|
---|
[209] | 141 | LevelDB, MetaEditor;
|
---|
[129] | 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;
|
---|
[222] | 173 | toolform: TForm_BaseTemplate;
|
---|
[97] | 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
|
---|
[222] | 180 | if MDITab.MDIChildren[i] is TForm_BaseTemplate then
|
---|
[97] | 181 | begin
|
---|
[222] | 182 | toolform := TForm_BaseTemplate(MDITab.MDIChildren[i]);
|
---|
[97] | 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
|
---|
[197] | 260 | ShowMessage('Warning!' + #13#10 +
|
---|
| 261 | 'It seems like this is the first time you OUP.' + #13#10 +
|
---|
| 262 | 'I do not take any responsibility for messed up data files' + #13+#10 +
|
---|
| 263 | 'Do not forget to make backup copies of your *.dat/*.raw/*.sep files!');
|
---|
[93] | 264 | AppSettings.DatPath := ExtractFilepath(Application.EXEname);
|
---|
| 265 | AppSettings.ExtractPath := ExtractFilepath(Application.EXEname) + '\extract';
|
---|
| 266 | AppSettings.CharSet := DEFAULT_CHARSET;
|
---|
| 267 | AppSettings.HideUnusedData := False;
|
---|
| 268 | end;
|
---|
| 269 |
|
---|
| 270 | if MidStr(ParamStr(1), 1, 3) = 'opf' then
|
---|
| 271 | begin
|
---|
| 272 | ShowMessage('Load OPF-File: ' + ParamStr(2));
|
---|
| 273 | end
|
---|
| 274 | else if (MidStr(ParamStr(1), 1, 4) = 'oldb') or (MidStr(ParamStr(1), 1, 3) = 'dat') then
|
---|
| 275 | begin
|
---|
| 276 | CreateConnection(ParamStr(2));
|
---|
| 277 | end;
|
---|
| 278 | UpdateStatBar;
|
---|
| 279 | end;
|
---|
| 280 |
|
---|
| 281 |
|
---|
| 282 |
|
---|
| 283 |
|
---|
| 284 | procedure TForm_Main.FormResize(Sender: TObject);
|
---|
| 285 | begin
|
---|
| 286 | statbar.Panels.Items[0].Width := Self.Width - 200;
|
---|
| 287 | MDITab.Width := Self.Width - 20;
|
---|
| 288 | end;
|
---|
| 289 |
|
---|
| 290 |
|
---|
| 291 |
|
---|
| 292 |
|
---|
| 293 | procedure TForm_Main.MDITabDrawTab(Control: TCustomTabControl;
|
---|
| 294 | TabIndex: Integer; const Rect: TRect; Active: Boolean);
|
---|
| 295 | var
|
---|
| 296 | x, y: Integer;
|
---|
| 297 | iconindex: Integer;
|
---|
| 298 | caption: String;
|
---|
| 299 | begin
|
---|
| 300 | iconindex := TMDITab(Control).Glyphs[TabIndex];
|
---|
| 301 | caption := TMDITab(Control).Captions[TabIndex];
|
---|
| 302 | if active then
|
---|
| 303 | begin
|
---|
| 304 | Control.Canvas.Font.Style := Control.Canvas.Font.Style + [fsItalic];
|
---|
| 305 | y := Rect.Top + 1;
|
---|
| 306 | end else
|
---|
| 307 | y := Rect.Top;
|
---|
| 308 | if iconindex >= 0 then
|
---|
| 309 | begin
|
---|
| 310 | TMDITab(Control).Images.Draw(Control.Canvas, Rect.Left + 4, y, iconindex);
|
---|
| 311 | x := Rect.Left + 26;
|
---|
| 312 | end else
|
---|
| 313 | x := Rect.Left + 4;
|
---|
| 314 | Control.Canvas.TextOut(x, y + 2, caption);
|
---|
| 315 | if active then
|
---|
| 316 | Images_Close.Draw(Control.Canvas, Rect.Right - 18, y, 0)
|
---|
| 317 | else
|
---|
| 318 | Images_Close.Draw(Control.Canvas, Rect.Right - 18, y, 1);
|
---|
| 319 | end;
|
---|
| 320 |
|
---|
| 321 |
|
---|
| 322 | procedure TForm_Main.MDITabMouseMove(Sender: TObject; Shift: TShiftState; X,
|
---|
| 323 | Y: Integer);
|
---|
| 324 | var
|
---|
| 325 | pt: TPoint;
|
---|
| 326 | tabIndex: Integer;
|
---|
| 327 | hint: String;
|
---|
[222] | 328 | tool: TForm_BaseTemplate;
|
---|
[93] | 329 | begin
|
---|
| 330 | pt.X := X;
|
---|
| 331 | pt.Y := Y;
|
---|
| 332 | tabIndex := MDITab.GetTabAtPos(pt);
|
---|
| 333 | hint := '';
|
---|
| 334 |
|
---|
| 335 | if tabIndex >= 0 then
|
---|
| 336 | begin
|
---|
[222] | 337 | if MDITab.MDIChildren[tabIndex] is TForm_BaseTemplate then
|
---|
[93] | 338 | begin
|
---|
[222] | 339 | tool := TForm_BaseTemplate(MDITab.MDIChildren[tabIndex]);
|
---|
[97] | 340 | if tool.ConnectionID > -1 then
|
---|
[93] | 341 | hint := 'Connection: ' +
|
---|
[222] | 342 | ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName)
|
---|
[93] | 343 | else
|
---|
[222] | 344 | hint := 'Connection: none';
|
---|
| 345 | if tool is TForm_TemplateFile then
|
---|
| 346 | begin
|
---|
| 347 | if TForm_TemplateFile(tool).SelectedFile.ID > -1 then
|
---|
| 348 | hint := hint + #13+#10 + 'Selected File: ' +
|
---|
| 349 | FormatNumber(TForm_TemplateFile(tool).SelectedFile.ID, 5, '0') + '-' +
|
---|
| 350 | TForm_TemplateFile(tool).SelectedFile.Name + '.' +
|
---|
| 351 | TForm_TemplateFile(tool).SelectedFile.Extension
|
---|
| 352 | else
|
---|
| 353 | hint := hint + #13+#10 + 'Selected File: none';
|
---|
| 354 | end;
|
---|
[93] | 355 | end
|
---|
| 356 | else
|
---|
| 357 | hint := 'Window: ' + MDITab.MDIChildren[tabIndex].Caption;
|
---|
| 358 | if hint <> MDITab.Hint then
|
---|
| 359 | begin
|
---|
| 360 | MDITab.Hint := hint;
|
---|
| 361 | MDITab.ShowHint := True;
|
---|
| 362 | end;
|
---|
| 363 | end
|
---|
| 364 | else
|
---|
| 365 | begin
|
---|
| 366 | MDITab.ShowHint := False;
|
---|
| 367 | MDITab.Hint := '';
|
---|
| 368 | end;
|
---|
| 369 | end;
|
---|
| 370 |
|
---|
| 371 | procedure TForm_Main.MDITabMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
| 372 | Shift: TShiftState; X, Y: Integer);
|
---|
| 373 | var
|
---|
| 374 | pt: TPoint;
|
---|
| 375 | tabIndex: Integer;
|
---|
| 376 | tabRect: TRect;
|
---|
| 377 | tabX, tabY, tabWidth: Integer;
|
---|
| 378 | begin
|
---|
| 379 | pt.X := X;
|
---|
| 380 | pt.Y := Y;
|
---|
| 381 | tabIndex := MDITab.GetTabAtPos(pt);
|
---|
| 382 |
|
---|
| 383 | // if (Button = mbRight) and (tabIndex >= 0) then
|
---|
| 384 | // MDITab.MDIChildren[tabIndex].Close;
|
---|
| 385 |
|
---|
| 386 | if (Button = mbLeft) and (tabIndex >= 0) then
|
---|
| 387 | begin
|
---|
| 388 | tabrect := MDITab.TabRect(tabIndex);
|
---|
| 389 | tabX := X - tabrect.Left;
|
---|
| 390 | tabY := Y - tabrect.Top;
|
---|
| 391 | tabwidth := tabrect.Right - tabrect.Left;
|
---|
| 392 | if (tabY >= 4) and (tabY <= 17) then
|
---|
| 393 | if (tabX >= tabwidth - 19) and (tabX <= tabwidth - 7) then
|
---|
| 394 | MDITab.MDIChildren[tabIndex].Close;
|
---|
| 395 | end;
|
---|
| 396 | end;
|
---|
| 397 |
|
---|
| 398 |
|
---|
| 399 |
|
---|
| 400 |
|
---|
| 401 | procedure TForm_Main.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 402 | begin
|
---|
| 403 | AssignFile(AppSettingsFile, ExtractFilepath(Application.EXEname) + '\oniunpacker.ini');
|
---|
| 404 | if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
|
---|
| 405 | Reset(AppSettingsFile)
|
---|
| 406 | else
|
---|
| 407 | Rewrite(AppSettingsFile);
|
---|
| 408 | Write(AppSettingsFile, AppSettings);
|
---|
| 409 | CloseFile(AppSettingsFile);
|
---|
| 410 | Action := caFree;
|
---|
| 411 | end;
|
---|
| 412 |
|
---|
| 413 |
|
---|
| 414 |
|
---|
| 415 | procedure TForm_Main.ActivateTools(active: Boolean);
|
---|
| 416 | begin
|
---|
| 417 | menu_tools.Enabled := active;
|
---|
| 418 | tb_preview.Enabled := active;
|
---|
| 419 | tb_datedit.Enabled := active;
|
---|
| 420 | tb_rawedit.Enabled := active;
|
---|
| 421 | tb_txmpreplacer.Enabled := active;
|
---|
| 422 | tb_extractor.Enabled := active;
|
---|
[209] | 423 | tb_meta.Enabled := active;
|
---|
[93] | 424 | // tb_compare.Enabled := active;
|
---|
| 425 | // tb_structure.Enabled := active;
|
---|
| 426 | end;
|
---|
| 427 |
|
---|
| 428 | procedure TForm_Main.UpdateStatBar;
|
---|
| 429 | begin
|
---|
[97] | 430 | if ConManager.Count > 0 then
|
---|
[93] | 431 | begin
|
---|
| 432 | Self.Caption := 'Oni Un/Packer ' + version;
|
---|
| 433 | ActivateTools(True);
|
---|
[97] | 434 | statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count);
|
---|
[93] | 435 | end
|
---|
| 436 | else
|
---|
| 437 | begin
|
---|
| 438 | Self.Caption := 'Oni Un/Packer ' + version;
|
---|
| 439 | statbar.Panels.Items[0].Text := '';
|
---|
| 440 | statbar.Panels.Items[1].Text := 'Connections: -';
|
---|
| 441 | statbar.Panels.Items[2].Text := '';
|
---|
| 442 | ActivateTools(False);
|
---|
| 443 | end;
|
---|
[97] | 444 | menu_conns.Enabled := ConManager.Count > 0;
|
---|
[93] | 445 | end;
|
---|
| 446 |
|
---|
| 447 |
|
---|
| 448 |
|
---|
| 449 |
|
---|
| 450 | procedure TForm_Main.ToolbarDockChanged(Sender: TObject);
|
---|
| 451 | var
|
---|
| 452 | toolbar: TTBToolbar;
|
---|
| 453 | position: TTBDockPosition;
|
---|
| 454 | mode: TTBItemDisplayMode;
|
---|
| 455 | i: Integer;
|
---|
| 456 | begin
|
---|
| 457 | toolbar := TTBToolbar(Sender);
|
---|
| 458 | if toolbar.Floating then
|
---|
| 459 | mode := nbdmImageAndText
|
---|
| 460 | else begin
|
---|
| 461 | position := toolbar.CurrentDock.Position;
|
---|
| 462 | if position in [dpLeft, dpRight] then
|
---|
| 463 | mode := nbdmDefault
|
---|
| 464 | else
|
---|
| 465 | mode := nbdmImageAndText;
|
---|
| 466 | end;
|
---|
| 467 | for i := 0 to toolbar.Items.Count - 1 do
|
---|
| 468 | toolbar.Items.Items[i].DisplayMode := mode;
|
---|
| 469 | end;
|
---|
| 470 |
|
---|
| 471 | function TForm_Main.TryCloseAll: Boolean;
|
---|
| 472 | begin
|
---|
| 473 | menu_windows_closeallClick(Self);
|
---|
| 474 | Application.ProcessMessages;
|
---|
| 475 | if MDITab.MDIChildCount = 0 then
|
---|
| 476 | Result := True
|
---|
| 477 | else
|
---|
| 478 | Result := False;
|
---|
| 479 | end;
|
---|
| 480 |
|
---|
| 481 |
|
---|
| 482 | procedure TForm_Main.UpdateConLists;
|
---|
| 483 | var
|
---|
| 484 | i: Integer;
|
---|
| 485 | entry: TTBItem;
|
---|
| 486 | begin
|
---|
| 487 | if MDITab.MDIChildCount > 0 then
|
---|
| 488 | for i := 0 to MDITab.MDIChildCount - 1 do
|
---|
[222] | 489 | if MDITab.MDIChildren[i] is TForm_BaseTemplate then
|
---|
| 490 | TForm_BaseTemplate(MDITab.MDIChildren[i]).UpdateConList;
|
---|
[93] | 491 |
|
---|
| 492 | menu_conns.Clear;
|
---|
[97] | 493 | if ConManager.Count > 0 then
|
---|
[93] | 494 | begin
|
---|
[97] | 495 | for i := 0 to ConManager.Count - 1 do
|
---|
[93] | 496 | begin
|
---|
| 497 | entry := TTBItem.Create(menu_conns);
|
---|
[97] | 498 | entry.Caption := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
|
---|
[93] | 499 | entry.Name := 'menu_conn_' + IntToStr(i);
|
---|
| 500 | entry.OnClick := menu_conns_itemClick;
|
---|
| 501 | menu_conns.Add(entry);
|
---|
| 502 | entry := nil;
|
---|
| 503 | end;
|
---|
| 504 | end;
|
---|
| 505 | end;
|
---|
| 506 |
|
---|
| 507 |
|
---|
| 508 | procedure TForm_Main.LoadFile(typedb: Boolean);
|
---|
| 509 | var
|
---|
[105] | 510 | i: Integer;
|
---|
[93] | 511 | begin
|
---|
| 512 | opend.InitialDir := AppSettings.DatPath;
|
---|
| 513 | opend.Filter := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
|
---|
| 514 | if typedb then
|
---|
| 515 | opend.FilterIndex := 3
|
---|
| 516 | else
|
---|
| 517 | opend.FilterIndex := 2;
|
---|
| 518 | if opend.Execute then
|
---|
| 519 | begin
|
---|
[105] | 520 | if opend.Files.Count > 0 then
|
---|
| 521 | for i := 0 to opend.Files.Count - 1 do
|
---|
| 522 | CreateConnection(opend.Files.Strings[i]);
|
---|
[93] | 523 | AppSettings.DatPath := ExtractFilepath(opend.FileName);
|
---|
| 524 | end;
|
---|
| 525 | UpdateStatBar;
|
---|
| 526 | end;
|
---|
| 527 |
|
---|
| 528 |
|
---|
| 529 | {#################################}
|
---|
| 530 | {##### Main-Menu-Handlers #####}
|
---|
| 531 | {#################################}
|
---|
| 532 | procedure TForm_Main.menu_loaddbClick(Sender: TObject);
|
---|
| 533 | begin
|
---|
| 534 | LoadFile(True);
|
---|
| 535 | end;
|
---|
| 536 |
|
---|
| 537 | procedure TForm_Main.menu_loadfileClick(Sender: TObject);
|
---|
| 538 | begin
|
---|
| 539 | LoadFile(False);
|
---|
| 540 | end;
|
---|
| 541 |
|
---|
| 542 |
|
---|
| 543 | procedure TForm_Main.menu_settingsClick(Sender: TObject);
|
---|
| 544 | begin
|
---|
| 545 | Form_Settings.Visible := True;
|
---|
| 546 | Self.Enabled := False;
|
---|
| 547 | end;
|
---|
| 548 |
|
---|
| 549 |
|
---|
| 550 | procedure TForm_Main.menu_exitClick(Sender: TObject);
|
---|
| 551 | begin
|
---|
| 552 | Self.Close;
|
---|
| 553 | end;
|
---|
| 554 |
|
---|
| 555 |
|
---|
| 556 | {####################################}
|
---|
| 557 | {##### Converters-Menu-Handlers #####}
|
---|
| 558 | {####################################}
|
---|
| 559 | procedure TForm_Main.menu_createdbClick(Sender: TObject);
|
---|
| 560 | begin
|
---|
| 561 | opend.Filter := 'Oni-Dat-Files|*.dat';
|
---|
| 562 | saved.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
|
---|
| 563 | saved.DefaultExt := 'oldb';
|
---|
| 564 | if opend.Execute then
|
---|
| 565 | if saved.Execute then
|
---|
| 566 | Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
|
---|
| 567 | end;
|
---|
| 568 |
|
---|
| 569 |
|
---|
| 570 | procedure TForm_Main.menu_createlvlClick(Sender: TObject);
|
---|
| 571 | begin
|
---|
| 572 | opend.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
|
---|
| 573 | saved.Filter := 'Oni-Dat-Files|*.dat';
|
---|
| 574 | saved.DefaultExt := 'dat';
|
---|
| 575 | if opend.Execute then
|
---|
| 576 | if saved.Execute then
|
---|
| 577 | Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
|
---|
| 578 | end;
|
---|
| 579 |
|
---|
| 580 |
|
---|
| 581 | {#################################}
|
---|
| 582 | {##### Tools-Menu-Handlers #####}
|
---|
| 583 | {#################################}
|
---|
| 584 | procedure TForm_Main.menu_previewClick(Sender: TObject);
|
---|
| 585 | begin
|
---|
[222] | 586 | open_child('preview');
|
---|
[93] | 587 | end;
|
---|
| 588 |
|
---|
| 589 | procedure TForm_Main.menu_bineditClick(Sender: TObject);
|
---|
| 590 | begin
|
---|
[222] | 591 | open_child('binedit');
|
---|
[93] | 592 | end;
|
---|
| 593 |
|
---|
| 594 | procedure TForm_Main.menu_raweditClick(Sender: TObject);
|
---|
| 595 | begin
|
---|
[222] | 596 | open_child('rawedit');
|
---|
[93] | 597 | end;
|
---|
| 598 |
|
---|
| 599 | procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
|
---|
| 600 | begin
|
---|
[222] | 601 | open_child('txmpreplace');
|
---|
[93] | 602 | end;
|
---|
| 603 |
|
---|
| 604 | procedure TForm_Main.menu_extractorClick(Sender: TObject);
|
---|
| 605 | begin
|
---|
[222] | 606 | open_child('extractor');
|
---|
[93] | 607 | end;
|
---|
| 608 |
|
---|
| 609 | procedure TForm_Main.menu_metaClick(Sender: TObject);
|
---|
| 610 | begin
|
---|
[222] | 611 | open_child('meta');
|
---|
[93] | 612 | end;
|
---|
| 613 |
|
---|
| 614 | procedure TForm_Main.menu_filecompareClick(Sender: TObject);
|
---|
| 615 | begin
|
---|
[222] | 616 | open_child('compare');
|
---|
[93] | 617 | end;
|
---|
| 618 |
|
---|
| 619 |
|
---|
| 620 | {#################################}
|
---|
| 621 | {##### View-Menu-Handlers #####}
|
---|
| 622 | {#################################}
|
---|
| 623 | procedure TForm_Main.menu_windows_cascadeClick(Sender: TObject);
|
---|
| 624 | begin
|
---|
| 625 | Self.Cascade;
|
---|
| 626 | end;
|
---|
| 627 |
|
---|
| 628 | procedure TForm_Main.menu_windows_tilevertClick(Sender: TObject);
|
---|
| 629 | begin
|
---|
| 630 | Self.TileMode := tbVertical;
|
---|
| 631 | Self.Tile;
|
---|
| 632 | end;
|
---|
| 633 |
|
---|
| 634 | procedure TForm_Main.menu_windows_tileClick(Sender: TObject);
|
---|
| 635 | begin
|
---|
| 636 | Self.TileMode := tbHorizontal;
|
---|
| 637 | Self.Tile;
|
---|
| 638 | end;
|
---|
| 639 |
|
---|
| 640 | procedure TForm_Main.menu_windows_closeallClick(Sender: TObject);
|
---|
| 641 | begin
|
---|
| 642 | MDITab.CloseAll;
|
---|
| 643 | end;
|
---|
| 644 |
|
---|
| 645 | procedure TForm_Main.menu_windows_nextClick(Sender: TObject);
|
---|
| 646 | begin
|
---|
| 647 | if MDIChildCount > 1 then
|
---|
| 648 | if MDITab.TabIndex = MDITab.MDIChildCount - 1 then
|
---|
| 649 | MDITab.MDIChildren[0].BringToFront
|
---|
| 650 | else
|
---|
| 651 | MDITab.MDIChildren[MDITab.TabIndex + 1].BringToFront;
|
---|
| 652 | end;
|
---|
| 653 |
|
---|
| 654 | procedure TForm_Main.menu_windows_previousClick(Sender: TObject);
|
---|
| 655 | begin
|
---|
| 656 | if MDIChildCount > 1 then
|
---|
| 657 | if MDITab.TabIndex = 0 then
|
---|
| 658 | MDITab.MDIChildren[MDITab.MDIChildCount - 1].BringToFront
|
---|
| 659 | else
|
---|
| 660 | MDITab.MDIChildren[MDITab.TabIndex - 1].BringToFront;
|
---|
| 661 | end;
|
---|
| 662 |
|
---|
| 663 |
|
---|
| 664 | {##################################}
|
---|
| 665 | {##### Windows-Menu-Handlers #####}
|
---|
| 666 | {##################################}
|
---|
| 667 | procedure TForm_Main.menu_windows_itemClick(Sender: TObject);
|
---|
| 668 | var
|
---|
| 669 | name: String;
|
---|
| 670 | begin
|
---|
| 671 | name := TTBItem(Sender).Name;
|
---|
| 672 | end;
|
---|
| 673 |
|
---|
| 674 |
|
---|
| 675 |
|
---|
| 676 | {######################################}
|
---|
| 677 | {##### Connections-Menu-Handlers #####}
|
---|
| 678 | {######################################}
|
---|
| 679 | procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
|
---|
| 680 | var
|
---|
| 681 | name: String;
|
---|
[97] | 682 | index: Integer;
|
---|
| 683 | RepMsg: TStatusMessages;
|
---|
[93] | 684 | begin
|
---|
[97] | 685 | index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender));
|
---|
| 686 | name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName);
|
---|
[93] | 687 | if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
|
---|
| 688 | name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then
|
---|
| 689 | begin
|
---|
[97] | 690 | CheckConnectionCloseable(index);
|
---|
| 691 | ConManager.CloseConnectionByIndex(index, RepMsg);
|
---|
[105] | 692 | ShowOpenMsg(RepMsg);
|
---|
| 693 | UpdateConLists;
|
---|
[93] | 694 | end;
|
---|
| 695 | UpdateStatBar;
|
---|
| 696 | end;
|
---|
| 697 |
|
---|
| 698 |
|
---|
| 699 | {###################################}
|
---|
| 700 | {##### Toolbars-Menu-Handlers #####}
|
---|
| 701 | {###################################}
|
---|
| 702 | procedure TForm_Main.menu_view_toolbarClick(Sender: TObject);
|
---|
| 703 | begin
|
---|
| 704 | menu_view_toolbar.Checked := not menu_view_toolbar.Checked;
|
---|
| 705 | Toolbar.Visible := menu_view_toolbar.Checked;
|
---|
| 706 | end;
|
---|
| 707 |
|
---|
| 708 | procedure TForm_Main.menu_view_statusbarClick(Sender: TObject);
|
---|
| 709 | begin
|
---|
| 710 | menu_view_statusbar.Checked := not menu_view_statusbar.Checked;
|
---|
| 711 | statbar.Visible := menu_view_statusbar.Checked;
|
---|
| 712 | end;
|
---|
| 713 |
|
---|
| 714 | procedure TForm_Main.menu_view_mdibarClick(Sender: TObject);
|
---|
| 715 | begin
|
---|
| 716 | menu_view_mdibar.Checked := not menu_view_mdibar.Checked;
|
---|
| 717 | mditoolbar.Visible := menu_view_mdibar.Checked;
|
---|
| 718 | end;
|
---|
| 719 |
|
---|
| 720 |
|
---|
| 721 |
|
---|
| 722 | procedure TForm_Main.menu_AboutClick(Sender: TObject);
|
---|
| 723 | begin
|
---|
| 724 | ShowMessage('Will be implemented later ;)');
|
---|
| 725 | end;
|
---|
| 726 |
|
---|
| 727 |
|
---|
| 728 |
|
---|
| 729 |
|
---|
| 730 |
|
---|
[222] | 731 | function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_BaseTemplate;
|
---|
[172] | 732 | type
|
---|
[222] | 733 | TTemplate = class of TForm_BaseTemplate;
|
---|
[172] | 734 | TTool = record
|
---|
| 735 | name: String;
|
---|
| 736 | icon: Integer;
|
---|
| 737 | caption: String;
|
---|
| 738 | classt: TTemplate;
|
---|
| 739 | end;
|
---|
| 740 | const
|
---|
[224] | 741 | Tools: array[0..5] of TTool = (
|
---|
[172] | 742 | (name: 'binedit'; icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit),
|
---|
| 743 | (name: 'extractor'; icon: 8; caption: 'Extractor'; classt: TForm_Extractor),
|
---|
| 744 | (name: 'preview'; icon: 4; caption: 'Preview-Window'; classt: TForm_Preview),
|
---|
| 745 | (name: 'rawedit'; icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit),
|
---|
[224] | 746 | (name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer'; classt: TForm_TxmpReplace),
|
---|
[222] | 747 | (name: 'meta'; icon: 11; caption: 'MetaEditor'; classt: TForm_Meta)
|
---|
[172] | 748 | );
|
---|
[93] | 749 | var
|
---|
[222] | 750 | toolform: TForm_BaseTemplate;
|
---|
[93] | 751 | i: Integer;
|
---|
| 752 | tag: Integer;
|
---|
| 753 | iconindex: Integer;
|
---|
| 754 | begin
|
---|
| 755 | Result := nil;
|
---|
| 756 |
|
---|
| 757 | tag := 1;
|
---|
| 758 | if MDIChildCount > 0 then
|
---|
| 759 | for i := 0 to MDIChildCount - 1 do
|
---|
| 760 | if MDIChildren[i].Tag >= tag then
|
---|
| 761 | tag := MDIChildren[i].Tag + 1;
|
---|
| 762 |
|
---|
| 763 | iconindex := -1;
|
---|
| 764 |
|
---|
[113] | 765 | toolform := nil;
|
---|
| 766 |
|
---|
[172] | 767 | for i := 0 to High(Tools) do
|
---|
| 768 | if Tools[i].name = window_context then
|
---|
| 769 | Break;
|
---|
| 770 | if i < Length(Tools) then
|
---|
[93] | 771 | begin
|
---|
[172] | 772 | toolform := TTemplate(Tools[i].classt).Create(Self);
|
---|
| 773 | toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + ' ';
|
---|
| 774 | iconindex := Tools[i].icon;
|
---|
| 775 | end else begin
|
---|
| 776 | ShowMessage('WindowContext not found!');
|
---|
[93] | 777 | end;
|
---|
| 778 |
|
---|
| 779 | if Assigned(toolform) then
|
---|
| 780 | begin
|
---|
| 781 | toolform.Name := window_context + IntToStr(tag);
|
---|
| 782 | toolform.Tag := tag;
|
---|
| 783 | MDITab.AddTab(TForm(toolform), iconindex);
|
---|
| 784 | toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', '');
|
---|
[222] | 785 | if Connection > -1 then
|
---|
[93] | 786 | begin
|
---|
[97] | 787 | toolform.SelectConnection(connection);
|
---|
[222] | 788 | if (FileID > -1) and (toolform is TForm_TemplateFile) then
|
---|
| 789 | TForm_TemplateFile(toolform).SelectFileID(Connection, FileID);
|
---|
[93] | 790 | end;
|
---|
| 791 | Result := toolform;
|
---|
| 792 | end;
|
---|
| 793 | end;
|
---|
| 794 |
|
---|
[222] | 795 | function TForm_Main.open_child(window_context: String; Connection: Integer): TForm_BaseTemplate;
|
---|
| 796 | begin
|
---|
| 797 | open_child(window_context, Connection, -1);
|
---|
| 798 | end;
|
---|
| 799 |
|
---|
| 800 | function TForm_Main.open_child(window_context: String): TForm_BaseTemplate;
|
---|
| 801 | begin
|
---|
| 802 | open_child(window_context, -1, -1);
|
---|
| 803 | end;
|
---|
| 804 |
|
---|
[93] | 805 | end.
|
---|