source: oup/releases/0.34a/Settings.pas@ 509

Last change on this file since 509 was 200, checked in by alloc, 18 years ago
File size: 5.3 KB
RevLine 
[200]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 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
26var
27 Form_Settings: TForm_Settings;
28
29implementation
30
31{$R *.dfm}
32
33uses
34 Main, Data, FTypeReg;
35
36
37
38function ExtensionRegistered(ext: String; var RegisteredAs: String): Boolean;
39var
40 ftr: TFileTypeRegistration;
41begin
42 ftr := TFileTypeRegistration.Create;
43 if (ftr <> nil) then
44 begin
45 try
46 RegisteredAs := ftr.GetInternalKey(ext);
47 if RegisteredAs <> '' then
48 Result := True
49 else
50 Result := False;
51 finally
52 ftr.Free;
53 end;
54 end;
55end;
56
57
58
59function TForm_Settings.RegisterExtension(ext: String; iconindex: Integer; reg: Boolean): Integer;
60var
61 ftr: TFileTypeRegistration;
62 temps: String;
63 warnmsg: String;
64begin
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;
84end;
85
86
87
88procedure TForm_Settings.btn_cancelClick(Sender: TObject);
89begin
90 Self.Close;
91end;
92
93
94
95procedure TForm_Settings.btn_okClick(Sender: TObject);
96var
97 temps: String;
98begin
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;
149end;
150
151
152
153procedure TForm_Settings.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
154begin
155 CanClose := False;
156 Self.Visible := False;
157 Form_Main.Enabled := True;
158 Form_Main.SetFocus;
159end;
160
161
162
163procedure TForm_Settings.FormShow(Sender: TObject);
164var
165 temps: String;
166 i: Byte;
167begin
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;
190end;
191
192end.
Note: See TracBrowser for help on using the repository browser.