source: oup/releases/0.32a/Unit14_settings.pas@ 455

Last change on this file since 455 was 35, checked in by alloc, 18 years ago
File size: 5.2 KB
Line 
1unit Unit14_settings;
2interface
3uses
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls, StrUtils, Grids, Wrapgrid;
6
7type
8 TForm14 = class(TForm)
9 check_filesashex: TCheckBox;
10 btn_ok: TButton;
11 btn_cancel: TButton;
12 btn_register_oldb: TButton;
13 btn_register_opf: TButton;
14 btn_register_dat: TButton;
15 label_charset: TLabel;
16 combo_charset: TComboBox;
17 check_hideunused: TCheckBox;
18 procedure btn_register_opfClick(Sender: TObject);
19 procedure btn_register_oldbClick(Sender: TObject);
20 procedure btn_register_datClick(Sender: TObject);
21 procedure btn_cancelClick(Sender: TObject);
22 procedure btn_okClick(Sender: TObject);
23 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
24 procedure FormShow(Sender: TObject);
25 function RegisterExtension(ext:String):Integer;
26 private
27 public
28 end;
29
30var
31 Form14: TForm14;
32
33implementation
34{$R *.dfm}
35uses
36 Unit1_main, Unit3_data, ftypesAPI;
37
38function ExtensionRegistered(ext:String; var RegisteredAs:String):Boolean;
39 var
40 ftr:TFileTypeRegistration;
41 begin
42 ftr:=TFileTypeRegistration.Create;
43 if(ftr <> nil) then begin
44 try
45 RegisteredAs:=ftr.GetInternalKey(ext);
46 if RegisteredAs<>'' then
47 Result:=True
48 else
49 Result:=False;
50 finally
51 ftr.Free;
52 end;
53 end;
54 end;
55
56function TForm14.RegisterExtension(ext:String):Integer;
57 var
58 ftr:TFileTypeRegistration;
59 temps:String;
60 warnmsg:String;
61 begin
62 Result:=-1;
63 if ExtensionRegistered(ext,temps) then begin
64 if temps<>'ONI'+ext then begin
65 warnmsg:=ext+'-files are not registered to OUP but as "'+temps+'"-files.'+#13+#10+
66 'Do you really want to unregister'+ext+'-files?';
67 if MessageBox(Self.Handle, PChar(warnmsg),PChar('Warning'),MB_YESNO)=ID_NO then
68 Exit;
69 end;
70 ftr:=TFileTypeRegistration.Create;
71 if ftr<>nil then
72 try
73 if not ftr.UnregisterExtension(ext) then
74 ShowMessage('Could not unregister '+ext+'-files')
75 else
76 Result:=2;
77 finally
78 ftr.Free;
79 end;
80 end else begin
81 ftr:=TFileTypeRegistration.Create;
82 if ftr<>nil then begin
83 try
84 if ftr.RegisterType(ext,'ONI'+ext,'ONI '+ext+'-file',Application.EXEname+',1') then begin
85 ftr.AddHandler('open','"'+Application.EXEname+'" '+MidStr(ext,2,Length(ext)-1)+' "%1"');
86 ftr.SetDefaultHandler;
87 Result:=1;
88 end;
89 finally
90 ftr.Free;
91 end;
92 end;
93 end;
94 end;
95
96procedure TForm14.btn_cancelClick(Sender: TObject);
97 begin
98 Self.Close;
99 end;
100
101procedure TForm14.btn_okClick(Sender: TObject);
102 begin
103 AppSettings.FilenumbersAsHex:=check_filesashex.Checked;
104 AppSettings.CharSet:=StrToInt(MidStr(combo_charset.Items.Strings[combo_charset.ItemIndex],Pos(' ',combo_charset.Items.Strings[combo_charset.ItemIndex])+3,Length(combo_charset.Items.Strings[combo_charset.ItemIndex])-Pos(' ',combo_charset.Items.Strings[combo_charset.ItemIndex])-2));
105 AppSettings.HideUnusedData:=check_hideunused.Checked;
106
107 Self.Close;
108 end;
109
110procedure TForm14.btn_register_datClick(Sender: TObject);
111 begin
112 case RegisterExtension('.dat') of
113 2: btn_register_dat.Caption:='Register .dat files with OUP';
114 1: btn_register_dat.Caption:='Unregister .dat files';
115 end;
116 end;
117
118procedure TForm14.btn_register_oldbClick(Sender: TObject);
119 begin
120 case RegisterExtension('.oldb') of
121 2: btn_register_oldb.Caption:='Register .oldb files with OUP';
122 1: btn_register_oldb.Caption:='Unregister .oldb files';
123 end;
124 end;
125
126procedure TForm14.btn_register_opfClick(Sender: TObject);
127 begin
128 case RegisterExtension('.opf') of
129 2: btn_register_opf.Caption:='Register .opf files with OUP';
130 1: btn_register_opf.Caption:='Unregister .opf files';
131 end;
132 end;
133
134procedure TForm14.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
135 begin
136 CanClose:=False;
137 Self.Visible:=False;
138 Form1.Enabled:=True;
139 Form1.SetFocus;
140 end;
141
142procedure TForm14.FormShow(Sender: TObject);
143 var
144 temps:String;
145 i:Byte;
146 begin
147 if ExtensionRegistered('.dat',temps) then
148 btn_register_dat.Caption:='Unregister .dat files'
149 else
150 btn_register_dat.Caption:='Register .dat files with OUP';
151 if ExtensionRegistered('.oldb',temps) then
152 btn_register_oldb.Caption:='Unregister .oldb files'
153 else
154 btn_register_oldb.Caption:='Register .oldb files with OUP';
155 if ExtensionRegistered('.opf',temps) then
156 btn_register_opf.Caption:='Unregister .opf files'
157 else
158 btn_register_opf.Caption:='Register .opf files with OUP';
159 check_filesashex.Checked:=AppSettings.FilenumbersAsHex;
160 check_hideunused.Checked:=AppSettings.HideUnusedData;
161
162 for i:=0 to combo_charset.Items.Count-1 do
163 if StrToInt(MidStr(combo_charset.Items.Strings[i],Pos(' ',combo_charset.Items.Strings[i])+3,Length(combo_charset.Items.Strings[i])-Pos(' ',combo_charset.Items.Strings[i])-2))=AppSettings.CharSet then
164 combo_charset.ItemIndex:=i;
165 end;
166
167end.
Note: See TracBrowser for help on using the repository browser.