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