source: oup/rewrite/Settings.pas@ 104

Last change on this file since 104 was 93, checked in by alloc, 18 years ago
File size: 5.4 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 check_filesashex: TCheckBox;
10 btn_ok: TButton;
11 btn_cancel: TButton;
12 label_charset: TLabel;
13 combo_charset: TComboBox;
14 check_hideunused: TCheckBox;
15 check_reg_dat: TCheckBox;
16 check_reg_oldb: TCheckBox;
17 check_reg_opf: 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 ftr := TFileTypeRegistration.Create;
44 if (ftr <> nil) then
45 begin
46 try
47 RegisteredAs := ftr.GetInternalKey(ext);
48 if RegisteredAs <> '' then
49 Result := True
50 else
51 Result := False;
52 finally
53 ftr.Free;
54 end;
55 end;
56end;
57
58
59
60function TForm_Settings.RegisterExtension(ext: String; iconindex: Integer; reg: Boolean): Integer;
61var
62 ftr: TFileTypeRegistration;
63 temps: String;
64 warnmsg: 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.FilenumbersAsHex := check_filesashex.Checked;
101 AppSettings.CharSet := StrToInt(
102 MidStr(combo_charset.Items.Strings[combo_charset.ItemIndex], Pos(
103 ' ', combo_charset.Items.Strings[combo_charset.ItemIndex]) + 3, Length(
104 combo_charset.Items.Strings[combo_charset.ItemIndex]) - Pos(
105 ' ', combo_charset.Items.Strings[combo_charset.ItemIndex]) - 2));
106 AppSettings.HideUnusedData := check_hideunused.Checked;
107
108 if check_reg_dat.Checked then
109 begin
110 if ExtensionRegistered('.dat', temps) then
111 begin
112 if temps <> 'ONI.dat' then
113 if MessageBox(Self.Handle, PChar('.dat-files already registered to "' +
114 temps+'". Reregister?'), PChar('Reregister?'),
115 MB_YESNO + MB_ICONQUESTION) = ID_YES then
116 RegisterExtension('.dat', 2, True);
117 end else
118 RegisterExtension('.dat', 2, True);
119 end else
120 RegisterExtension('.dat', 2, False);
121
122 if check_reg_oldb.Checked then
123 begin
124 if ExtensionRegistered('.oldb', temps) then
125 begin
126 if temps <> 'ONI.oldb' then
127 if MessageBox(Self.Handle, PChar('.oldb-files already registered to "' +
128 temps+'". Reregister?'), PChar('Reregister?'),
129 MB_YESNO + MB_ICONQUESTION) = ID_YES then
130 RegisterExtension('.oldb', 1, True);
131 end else
132 RegisterExtension('.oldb', 1, True);
133 end else
134 RegisterExtension('.oldb', 1, False);
135
136 if check_reg_opf.Checked then
137 begin
138 if ExtensionRegistered('.opf', temps) then
139 begin
140 if temps <> 'ONI.opf' then
141 if MessageBox(Self.Handle, PChar('.opf-files already registered to "' +
142 temps+'". Reregister?'), PChar('Reregister?'),
143 MB_YESNO + MB_ICONQUESTION) = ID_YES then
144 RegisterExtension('.opf', 0, True);
145 end else
146 RegisterExtension('.opf', 0, True);
147 end else
148 RegisterExtension('.opf', 0, False);
149
150 Self.Close;
151end;
152
153
154
155procedure TForm_Settings.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
156begin
157 CanClose := False;
158 Self.Visible := False;
159 Form_Main.Enabled := True;
160 Form_Main.SetFocus;
161end;
162
163
164
165procedure TForm_Settings.FormShow(Sender: TObject);
166var
167 temps: String;
168 i: Byte;
169begin
170 if ExtensionRegistered('.dat', temps) then
171 check_reg_dat.Checked := temps = 'ONI.dat'
172 else
173 check_reg_dat.Checked := False;
174
175 if ExtensionRegistered('.oldb', temps) then
176 check_reg_oldb.Checked := temps = 'ONI.oldb'
177 else
178 check_reg_oldb.Checked := False;
179
180 if ExtensionRegistered('.opf', temps) then
181 check_reg_opf.Checked := temps = 'ONI.opf'
182 else
183 check_reg_opf.Checked := False;
184
185 check_filesashex.Checked := AppSettings.FilenumbersAsHex;
186 check_hideunused.Checked := AppSettings.HideUnusedData;
187
188 for i := 0 to combo_charset.Items.Count - 1 do
189 if StrToInt(MidStr(combo_charset.Items.Strings[i], Pos(
190 ' ', combo_charset.Items.Strings[i]) + 3, Length(combo_charset.Items.Strings[i]) -
191 Pos(' ', combo_charset.Items.Strings[i]) - 2)) = AppSettings.CharSet then
192 combo_charset.ItemIndex := i;
193end;
194
195end.
Note: See TracBrowser for help on using the repository browser.