| 1 | unit Settings;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|---|
| 7 | Dialogs, StdCtrls, StrUtils, Grids, Wrapgrid;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 | TForm_Settings = class(TForm)
|
|---|
| 11 | check_filesashex: TCheckBox;
|
|---|
| 12 | btn_ok: TButton;
|
|---|
| 13 | btn_cancel: TButton;
|
|---|
| 14 | label_charset: TLabel;
|
|---|
| 15 | combo_charset: TComboBox;
|
|---|
| 16 | check_hideunused: TCheckBox;
|
|---|
| 17 | check_reg_dat: TCheckBox;
|
|---|
| 18 | check_reg_oldb: TCheckBox;
|
|---|
| 19 | check_reg_opf: TCheckBox;
|
|---|
| 20 | procedure btn_cancelClick(Sender: TObject);
|
|---|
| 21 | procedure btn_okClick(Sender: TObject);
|
|---|
| 22 | procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
|---|
| 23 | procedure FormShow(Sender: TObject);
|
|---|
| 24 | function RegisterExtension(ext: String; iconindex: Integer; reg: Boolean): Integer;
|
|---|
| 25 | private
|
|---|
| 26 | public
|
|---|
| 27 | end;
|
|---|
| 28 |
|
|---|
| 29 | var
|
|---|
| 30 | Form_Settings: TForm_Settings;
|
|---|
| 31 |
|
|---|
| 32 | implementation
|
|---|
| 33 |
|
|---|
| 34 | {$R *.dfm}
|
|---|
| 35 |
|
|---|
| 36 | uses
|
|---|
| 37 | Main, Data, FTypeReg;
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | function ExtensionRegistered(ext: String; var RegisteredAs: String): Boolean;
|
|---|
| 43 | var
|
|---|
| 44 | ftr: TFileTypeRegistration;
|
|---|
| 45 | begin
|
|---|
| 46 | ftr := TFileTypeRegistration.Create;
|
|---|
| 47 | if (ftr <> nil) then
|
|---|
| 48 | begin
|
|---|
| 49 | try
|
|---|
| 50 | RegisteredAs := ftr.GetInternalKey(ext);
|
|---|
| 51 | if RegisteredAs <> '' then
|
|---|
| 52 | Result := True
|
|---|
| 53 | else
|
|---|
| 54 | Result := False;
|
|---|
| 55 | finally
|
|---|
| 56 | ftr.Free;
|
|---|
| 57 | end;
|
|---|
| 58 | end;
|
|---|
| 59 | end;
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 | function TForm_Settings.RegisterExtension(ext: String; iconindex: Integer; reg: Boolean): Integer;
|
|---|
| 65 | var
|
|---|
| 66 | ftr: TFileTypeRegistration;
|
|---|
| 67 | temps: String;
|
|---|
| 68 | warnmsg: String;
|
|---|
| 69 | begin
|
|---|
| 70 | Result := -1;
|
|---|
| 71 | ftr := TFileTypeRegistration.Create;
|
|---|
| 72 | if reg then
|
|---|
| 73 | begin
|
|---|
| 74 | if ExtensionRegistered(ext, temps) then
|
|---|
| 75 | if not ftr.UnregisterExtension(ext) then
|
|---|
| 76 | ShowMessage('Could not unregister ' + ext + '-files');
|
|---|
| 77 | if ftr.RegisterType(ext, 'ONI' + ext, 'ONI ' + ext + '-file', Application.EXEname, iconindex) then
|
|---|
| 78 | begin
|
|---|
| 79 | ftr.AddHandler('open', '"' + Application.EXEname + '" ' + MidStr(
|
|---|
| 80 | ext, 2, Length(ext) - 1) + ' "%1"');
|
|---|
| 81 | ftr.SetDefaultHandler;
|
|---|
| 82 | end;
|
|---|
| 83 | end else begin
|
|---|
| 84 | if ExtensionRegistered(ext, temps) then
|
|---|
| 85 | if not ftr.UnregisterExtension(ext) then
|
|---|
| 86 | ShowMessage('Could not unregister ' + ext + '-files');
|
|---|
| 87 | end;
|
|---|
| 88 | ftr.Free;
|
|---|
| 89 | end;
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 | procedure TForm_Settings.btn_cancelClick(Sender: TObject);
|
|---|
| 95 | begin
|
|---|
| 96 | Self.Close;
|
|---|
| 97 | end;
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 | procedure TForm_Settings.btn_okClick(Sender: TObject);
|
|---|
| 103 | var
|
|---|
| 104 | temps: String;
|
|---|
| 105 | begin
|
|---|
| 106 | AppSettings.FilenumbersAsHex := check_filesashex.Checked;
|
|---|
| 107 | AppSettings.CharSet := StrToInt(
|
|---|
| 108 | MidStr(combo_charset.Items.Strings[combo_charset.ItemIndex], Pos(
|
|---|
| 109 | ' ', combo_charset.Items.Strings[combo_charset.ItemIndex]) + 3, Length(
|
|---|
| 110 | combo_charset.Items.Strings[combo_charset.ItemIndex]) - Pos(
|
|---|
| 111 | ' ', combo_charset.Items.Strings[combo_charset.ItemIndex]) - 2));
|
|---|
| 112 | AppSettings.HideUnusedData := check_hideunused.Checked;
|
|---|
| 113 |
|
|---|
| 114 | if check_reg_dat.Checked then
|
|---|
| 115 | begin
|
|---|
| 116 | if ExtensionRegistered('.dat', temps) then
|
|---|
| 117 | begin
|
|---|
| 118 | if temps <> 'ONI.dat' then
|
|---|
| 119 | if MessageBox(Self.Handle, PChar('.dat-files already registered to "' +
|
|---|
| 120 | temps+'". Reregister?'), PChar('Reregister?'),
|
|---|
| 121 | MB_YESNO + MB_ICONQUESTION) = ID_YES then
|
|---|
| 122 | RegisterExtension('.dat', 2, True);
|
|---|
| 123 | end else
|
|---|
| 124 | RegisterExtension('.dat', 2, True);
|
|---|
| 125 | end else
|
|---|
| 126 | RegisterExtension('.dat', 2, False);
|
|---|
| 127 |
|
|---|
| 128 | if check_reg_oldb.Checked then
|
|---|
| 129 | begin
|
|---|
| 130 | if ExtensionRegistered('.oldb', temps) then
|
|---|
| 131 | begin
|
|---|
| 132 | if temps <> 'ONI.oldb' then
|
|---|
| 133 | if MessageBox(Self.Handle, PChar('.oldb-files already registered to "' +
|
|---|
| 134 | temps+'". Reregister?'), PChar('Reregister?'),
|
|---|
| 135 | MB_YESNO + MB_ICONQUESTION) = ID_YES then
|
|---|
| 136 | RegisterExtension('.oldb', 1, True);
|
|---|
| 137 | end else
|
|---|
| 138 | RegisterExtension('.oldb', 1, True);
|
|---|
| 139 | end else
|
|---|
| 140 | RegisterExtension('.oldb', 1, False);
|
|---|
| 141 |
|
|---|
| 142 | if check_reg_opf.Checked then
|
|---|
| 143 | begin
|
|---|
| 144 | if ExtensionRegistered('.opf', temps) then
|
|---|
| 145 | begin
|
|---|
| 146 | if temps <> 'ONI.opf' then
|
|---|
| 147 | if MessageBox(Self.Handle, PChar('.opf-files already registered to "' +
|
|---|
| 148 | temps+'". Reregister?'), PChar('Reregister?'),
|
|---|
| 149 | MB_YESNO + MB_ICONQUESTION) = ID_YES then
|
|---|
| 150 | RegisterExtension('.opf', 0, True);
|
|---|
| 151 | end else
|
|---|
| 152 | RegisterExtension('.opf', 0, True);
|
|---|
| 153 | end else
|
|---|
| 154 | RegisterExtension('.opf', 0, False);
|
|---|
| 155 |
|
|---|
| 156 | Self.Close;
|
|---|
| 157 | end;
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 | procedure TForm_Settings.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
|---|
| 163 | begin
|
|---|
| 164 | CanClose := False;
|
|---|
| 165 | Self.Visible := False;
|
|---|
| 166 | Form_Main.Enabled := True;
|
|---|
| 167 | Form_Main.SetFocus;
|
|---|
| 168 | end;
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 | procedure TForm_Settings.FormShow(Sender: TObject);
|
|---|
| 174 | var
|
|---|
| 175 | temps: String;
|
|---|
| 176 | i: Byte;
|
|---|
| 177 | begin
|
|---|
| 178 | if ExtensionRegistered('.dat', temps) then
|
|---|
| 179 | check_reg_dat.Checked := temps = 'ONI.dat'
|
|---|
| 180 | else
|
|---|
| 181 | check_reg_dat.Checked := False;
|
|---|
| 182 |
|
|---|
| 183 | if ExtensionRegistered('.oldb', temps) then
|
|---|
| 184 | check_reg_oldb.Checked := temps = 'ONI.oldb'
|
|---|
| 185 | else
|
|---|
| 186 | check_reg_oldb.Checked := False;
|
|---|
| 187 |
|
|---|
| 188 | if ExtensionRegistered('.opf', temps) then
|
|---|
| 189 | check_reg_opf.Checked := temps = 'ONI.opf'
|
|---|
| 190 | else
|
|---|
| 191 | check_reg_opf.Checked := False;
|
|---|
| 192 |
|
|---|
| 193 | check_filesashex.Checked := AppSettings.FilenumbersAsHex;
|
|---|
| 194 | check_hideunused.Checked := AppSettings.HideUnusedData;
|
|---|
| 195 |
|
|---|
| 196 | for i := 0 to combo_charset.Items.Count - 1 do
|
|---|
| 197 | if StrToInt(MidStr(combo_charset.Items.Strings[i], Pos(
|
|---|
| 198 | ' ', combo_charset.Items.Strings[i]) + 3, Length(combo_charset.Items.Strings[i]) -
|
|---|
| 199 | Pos(' ', combo_charset.Items.Strings[i]) - 2)) = AppSettings.CharSet then
|
|---|
| 200 | combo_charset.ItemIndex := i;
|
|---|
| 201 | end;
|
|---|
| 202 |
|
|---|
| 203 | end.
|
|---|