[43] | 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 | btn_register_oldb: TButton;
|
---|
| 15 | btn_register_opf: TButton;
|
---|
| 16 | btn_register_dat: TButton;
|
---|
| 17 | label_charset: TLabel;
|
---|
| 18 | combo_charset: TComboBox;
|
---|
| 19 | check_hideunused: TCheckBox;
|
---|
| 20 | procedure btn_register_opfClick(Sender: TObject);
|
---|
| 21 | procedure btn_register_oldbClick(Sender: TObject);
|
---|
| 22 | procedure btn_register_datClick(Sender: TObject);
|
---|
| 23 | procedure btn_cancelClick(Sender: TObject);
|
---|
| 24 | procedure btn_okClick(Sender: TObject);
|
---|
| 25 | procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
---|
| 26 | procedure FormShow(Sender: TObject);
|
---|
| 27 | function RegisterExtension(ext: String): Integer;
|
---|
| 28 | private
|
---|
| 29 | public
|
---|
| 30 | end;
|
---|
| 31 |
|
---|
| 32 | var
|
---|
| 33 | Form_Settings: TForm_Settings;
|
---|
| 34 |
|
---|
| 35 | implementation
|
---|
| 36 |
|
---|
| 37 | {$R *.dfm}
|
---|
| 38 |
|
---|
| 39 | uses
|
---|
[46] | 40 | Main, Data, FTypeReg;
|
---|
[43] | 41 |
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | function ExtensionRegistered(ext: String; var RegisteredAs: String): Boolean;
|
---|
| 46 | var
|
---|
| 47 | ftr: TFileTypeRegistration;
|
---|
| 48 | begin
|
---|
| 49 | ftr := TFileTypeRegistration.Create;
|
---|
| 50 | if (ftr <> nil) then
|
---|
| 51 | begin
|
---|
| 52 | try
|
---|
| 53 | RegisteredAs := ftr.GetInternalKey(ext);
|
---|
| 54 | if RegisteredAs <> '' then
|
---|
| 55 | Result := True
|
---|
| 56 | else
|
---|
| 57 | Result := False;
|
---|
| 58 | finally
|
---|
| 59 | ftr.Free;
|
---|
| 60 | end;
|
---|
| 61 | end;
|
---|
| 62 | end;
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 | function TForm_Settings.RegisterExtension(ext: String): Integer;
|
---|
| 68 | var
|
---|
| 69 | ftr: TFileTypeRegistration;
|
---|
| 70 | temps: String;
|
---|
| 71 | warnmsg: String;
|
---|
| 72 | begin
|
---|
| 73 | Result := -1;
|
---|
| 74 | if ExtensionRegistered(ext, temps) then
|
---|
| 75 | begin
|
---|
| 76 | if temps <> 'ONI' + ext then
|
---|
| 77 | begin
|
---|
| 78 | warnmsg := ext + '-files are not registered to OUP but as "' +
|
---|
| 79 | temps + '"-files.' + #13 + #10 + 'Do you really want to unregister' +
|
---|
| 80 | ext + '-files?';
|
---|
| 81 | if MessageBox(Self.Handle, PChar(warnmsg), PChar('Warning'), MB_YESNO) = ID_NO then
|
---|
| 82 | Exit;
|
---|
| 83 | end;
|
---|
| 84 | ftr := TFileTypeRegistration.Create;
|
---|
| 85 | if ftr <> nil then
|
---|
| 86 | try
|
---|
| 87 | if not ftr.UnregisterExtension(ext) then
|
---|
| 88 | ShowMessage('Could not unregister ' + ext + '-files')
|
---|
| 89 | else
|
---|
| 90 | Result := 2;
|
---|
| 91 | finally
|
---|
| 92 | ftr.Free;
|
---|
| 93 | end;
|
---|
| 94 | end
|
---|
| 95 | else
|
---|
| 96 | begin
|
---|
| 97 | ftr := TFileTypeRegistration.Create;
|
---|
| 98 | if ftr <> nil then
|
---|
| 99 | begin
|
---|
| 100 | try
|
---|
| 101 | if ftr.RegisterType(ext, 'ONI' + ext, 'ONI ' + ext + '-file',
|
---|
| 102 | Application.EXEname + ',1') then
|
---|
| 103 | begin
|
---|
| 104 | ftr.AddHandler('open', '"' + Application.EXEname + '" ' + MidStr(
|
---|
| 105 | ext, 2, Length(ext) - 1) + ' "%1"');
|
---|
| 106 | ftr.SetDefaultHandler;
|
---|
| 107 | Result := 1;
|
---|
| 108 | end;
|
---|
| 109 | finally
|
---|
| 110 | ftr.Free;
|
---|
| 111 | end;
|
---|
| 112 | end;
|
---|
| 113 | end;
|
---|
| 114 | end;
|
---|
| 115 |
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 |
|
---|
| 119 | procedure TForm_Settings.btn_cancelClick(Sender: TObject);
|
---|
| 120 | begin
|
---|
| 121 | Self.Close;
|
---|
| 122 | end;
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 | procedure TForm_Settings.btn_okClick(Sender: TObject);
|
---|
| 128 | begin
|
---|
| 129 | AppSettings.FilenumbersAsHex := check_filesashex.Checked;
|
---|
| 130 | AppSettings.CharSet := StrToInt(
|
---|
| 131 | MidStr(combo_charset.Items.Strings[combo_charset.ItemIndex], Pos(
|
---|
| 132 | ' ', combo_charset.Items.Strings[combo_charset.ItemIndex]) + 3, Length(
|
---|
| 133 | combo_charset.Items.Strings[combo_charset.ItemIndex]) - Pos(
|
---|
| 134 | ' ', combo_charset.Items.Strings[combo_charset.ItemIndex]) - 2));
|
---|
| 135 | AppSettings.HideUnusedData := check_hideunused.Checked;
|
---|
| 136 |
|
---|
| 137 | Self.Close;
|
---|
| 138 | end;
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 |
|
---|
| 143 | procedure TForm_Settings.btn_register_datClick(Sender: TObject);
|
---|
| 144 | begin
|
---|
| 145 | case RegisterExtension('.dat') of
|
---|
| 146 | 2:
|
---|
| 147 | btn_register_dat.Caption := 'Register .dat files with OUP';
|
---|
| 148 | 1:
|
---|
| 149 | btn_register_dat.Caption := 'Unregister .dat files';
|
---|
| 150 | end;
|
---|
| 151 | end;
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 | procedure TForm_Settings.btn_register_oldbClick(Sender: TObject);
|
---|
| 157 | begin
|
---|
| 158 | case RegisterExtension('.oldb') of
|
---|
| 159 | 2:
|
---|
| 160 | btn_register_oldb.Caption := 'Register .oldb files with OUP';
|
---|
| 161 | 1:
|
---|
| 162 | btn_register_oldb.Caption := 'Unregister .oldb files';
|
---|
| 163 | end;
|
---|
| 164 | end;
|
---|
| 165 |
|
---|
| 166 |
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 | procedure TForm_Settings.btn_register_opfClick(Sender: TObject);
|
---|
| 170 | begin
|
---|
| 171 | case RegisterExtension('.opf') of
|
---|
| 172 | 2:
|
---|
| 173 | btn_register_opf.Caption := 'Register .opf files with OUP';
|
---|
| 174 | 1:
|
---|
| 175 | btn_register_opf.Caption := 'Unregister .opf files';
|
---|
| 176 | end;
|
---|
| 177 | end;
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 |
|
---|
| 181 |
|
---|
| 182 | procedure TForm_Settings.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
---|
| 183 | begin
|
---|
| 184 | CanClose := False;
|
---|
| 185 | Self.Visible := False;
|
---|
| 186 | Form_Main.Enabled := True;
|
---|
| 187 | Form_Main.SetFocus;
|
---|
| 188 | end;
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 |
|
---|
| 192 |
|
---|
| 193 | procedure TForm_Settings.FormShow(Sender: TObject);
|
---|
| 194 | var
|
---|
| 195 | temps: String;
|
---|
| 196 | i: Byte;
|
---|
| 197 | begin
|
---|
| 198 | if ExtensionRegistered('.dat', temps) then
|
---|
| 199 | btn_register_dat.Caption := 'Unregister .dat files'
|
---|
| 200 | else
|
---|
| 201 | btn_register_dat.Caption := 'Register .dat files with OUP';
|
---|
| 202 | if ExtensionRegistered('.oldb', temps) then
|
---|
| 203 | btn_register_oldb.Caption := 'Unregister .oldb files'
|
---|
| 204 | else
|
---|
| 205 | btn_register_oldb.Caption := 'Register .oldb files with OUP';
|
---|
| 206 | if ExtensionRegistered('.opf', temps) then
|
---|
| 207 | btn_register_opf.Caption := 'Unregister .opf files'
|
---|
| 208 | else
|
---|
| 209 | btn_register_opf.Caption := 'Register .opf files with OUP';
|
---|
| 210 | check_filesashex.Checked := AppSettings.FilenumbersAsHex;
|
---|
| 211 | check_hideunused.Checked := AppSettings.HideUnusedData;
|
---|
| 212 |
|
---|
| 213 | for i := 0 to combo_charset.Items.Count - 1 do
|
---|
| 214 | if StrToInt(MidStr(combo_charset.Items.Strings[i], Pos(
|
---|
| 215 | ' ', combo_charset.Items.Strings[i]) + 3, Length(combo_charset.Items.Strings[i]) -
|
---|
| 216 | Pos(' ', combo_charset.Items.Strings[i]) - 2)) = AppSettings.CharSet then
|
---|
| 217 | combo_charset.ItemIndex := i;
|
---|
| 218 | end;
|
---|
| 219 |
|
---|
| 220 | end.
|
---|