source: oup/releases/0.33a/Settings.pas@ 455

Last change on this file since 455 was 56, checked in by alloc, 18 years ago
File size: 5.4 KB
Line 
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;
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
29var
30 Form_Settings: TForm_Settings;
31
32implementation
33
34{$R *.dfm}
35
36uses
37 Main, Data, FTypeReg;
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
64function TForm_Settings.RegisterExtension(ext: String; iconindex: Integer; reg: Boolean): Integer;
65var
66 ftr: TFileTypeRegistration;
67 temps: String;
68 warnmsg: String;
69begin
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;
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);
103var
104 temps: String;
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
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;
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
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;
201end;
202
203end.
Note: See TracBrowser for help on using the repository browser.