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