source: oup/current/Settings.pas@ 610

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