source: oup/_old_/Settings.pas@ 189

Last change on this file since 189 was 108, checked in by alloc, 18 years ago
File size: 5.4 KB
RevLine 
[43]1unit Settings;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, StdCtrls, StrUtils, Grids, Wrapgrid;
8
9type
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;
[53]17 check_reg_dat: TCheckBox;
18 check_reg_oldb: TCheckBox;
19 check_reg_opf: TCheckBox;
[43]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);
[56]24 function RegisterExtension(ext: String; iconindex: Integer; reg: Boolean): Integer;
[43]25 private
26 public
27 end;
28
29var
30 Form_Settings: TForm_Settings;
31
32implementation
33
34{$R *.dfm}
35
36uses
[46]37 Main, Data, FTypeReg;
[43]38
39
40
41
42function ExtensionRegistered(ext: String; var RegisteredAs: String): Boolean;
43var
44 ftr: TFileTypeRegistration;
45begin
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;
59end;
60
61
62
63
[56]64function TForm_Settings.RegisterExtension(ext: String; iconindex: Integer; reg: Boolean): Integer;
[43]65var
66 ftr: TFileTypeRegistration;
67 temps: String;
68 warnmsg: String;
69begin
70 Result := -1;
[53]71 ftr := TFileTypeRegistration.Create;
72 if reg then
[43]73 begin
[53]74 if ExtensionRegistered(ext, temps) then
75 if not ftr.UnregisterExtension(ext) then
76 ShowMessage('Could not unregister ' + ext + '-files');
[56]77 if ftr.RegisterType(ext, 'ONI' + ext, 'ONI ' + ext + '-file', Application.EXEname, iconindex) then
[43]78 begin
[53]79 ftr.AddHandler('open', '"' + Application.EXEname + '" ' + MidStr(
80 ext, 2, Length(ext) - 1) + ' "%1"');
81 ftr.SetDefaultHandler;
[43]82 end;
[53]83 end else begin
84 if ExtensionRegistered(ext, temps) then
85 if not ftr.UnregisterExtension(ext) then
86 ShowMessage('Could not unregister ' + ext + '-files');
[43]87 end;
[53]88 ftr.Free;
[43]89end;
90
91
92
93
94procedure TForm_Settings.btn_cancelClick(Sender: TObject);
95begin
96 Self.Close;
97end;
98
99
100
101
102procedure TForm_Settings.btn_okClick(Sender: TObject);
[53]103var
104 temps: String;
[43]105begin
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
[53]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
[56]122 RegisterExtension('.dat', 2, True);
[53]123 end else
[56]124 RegisterExtension('.dat', 2, True);
[53]125 end else
[56]126 RegisterExtension('.dat', 2, False);
[43]127
[53]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
[56]136 RegisterExtension('.oldb', 1, True);
[53]137 end else
[56]138 RegisterExtension('.oldb', 1, True);
[53]139 end else
[56]140 RegisterExtension('.oldb', 1, False);
[43]141
[53]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
[56]150 RegisterExtension('.opf', 0, True);
[53]151 end else
[56]152 RegisterExtension('.opf', 0, True);
[53]153 end else
[56]154 RegisterExtension('.opf', 0, False);
[43]155
[53]156 Self.Close;
[43]157end;
158
159
160
161
162procedure TForm_Settings.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
163begin
164 CanClose := False;
165 Self.Visible := False;
166 Form_Main.Enabled := True;
167 Form_Main.SetFocus;
168end;
169
170
171
172
173procedure TForm_Settings.FormShow(Sender: TObject);
174var
175 temps: String;
176 i: Byte;
177begin
178 if ExtensionRegistered('.dat', temps) then
[53]179 check_reg_dat.Checked := temps = 'ONI.dat'
[43]180 else
[53]181 check_reg_dat.Checked := False;
182
[43]183 if ExtensionRegistered('.oldb', temps) then
[53]184 check_reg_oldb.Checked := temps = 'ONI.oldb'
[43]185 else
[53]186 check_reg_oldb.Checked := False;
187
[43]188 if ExtensionRegistered('.opf', temps) then
[53]189 check_reg_opf.Checked := temps = 'ONI.opf'
[43]190 else
[53]191 check_reg_opf.Checked := False;
192
[43]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;
201end;
202
203end.
Note: See TracBrowser for help on using the repository browser.