-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSettings.pas
332 lines (302 loc) · 10.3 KB
/
Settings.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
(* DosPanel - Windows GUI for DOSBox
=================================
Global settings
---------------
© J. Rathlev, D-24222 Schwentinental (kontakt(a)rathlev-home.de)
The contents of this file may be used under the terms of the
Mozilla Public License ("MPL") or
GNU Lesser General Public License Version 2 or later (the "LGPL")
Software distributed under this License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
J. Rathlev, Dec. 2011
last modified: Dec. 2017
*)
unit Settings;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons,
Vcl.ExtCtrls;
const
DosBoxName = 'DOSBox.exe';
type
TCodePageInfo = record
CodePageName : string;
CodePageNr : integer;
end;
const
CodePages : array [0..9] of TCodePageInfo = (
// (CodePageName : ''; CodePageNr : ),
(CodePageName : 'US (437)'; CodePageNr : 437),
(CodePageName : 'ANSI Latin (1252)'; CodePageNr : 1252),
(CodePageName : 'Latin-1 (850)'; CodePageNr : 850),
(CodePageName : 'Latin-2 (852)'; CodePageNr : 852),
(CodePageName : 'Latin-1 + Euro (858)'; CodePageNr : 858),
(CodePageName : 'Portuguese (860)'; CodePageNr : 860),
(CodePageName : 'Nordic (865)'; CodePageNr : 865),
(CodePageName : 'Cyrillic (866)'; CodePageNr : 866),
(CodePageName : 'Greek (869)'; CodePageNr : 869),
(CodePageName : 'Baltic (775)'; CodePageNr : 775)
);
type
TBasicSettings = record
DosBoxPath,
RootPath,
ConfFile,
LangFile,
MapperFile,
KeyLayout,
TextEditor : string;
Codepage : integer;
AutoStart,
HideCon : boolean;
end;
TDosBoxSetDialog = class(TForm)
OKBtn: TBitBtn;
CancelBtn: TBitBtn;
edPath: TLabeledEdit;
btPath: TSpeedButton;
cbConsole: TCheckBox;
edRootPath: TLabeledEdit;
btRootPath: TSpeedButton;
edConfFile: TLabeledEdit;
edLangFile: TLabeledEdit;
btConf: TSpeedButton;
btLang: TSpeedButton;
OpenDialog: TOpenDialog;
edMapperFile: TLabeledEdit;
gbKeyLayout: TGroupBox;
rbAutoKey: TRadioButton;
rbKeyLayout: TRadioButton;
cbKeyLayout: TComboBox;
gbCodePage: TGroupBox;
cbCodePages: TComboBox;
gbDosBox: TGroupBox;
cbAutoStart: TCheckBox;
edEditor: TLabeledEdit;
btEditor: TSpeedButton;
btMapper: TSpeedButton;
btEditConf: TSpeedButton;
btEditMapper: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure btPathClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure btRootPathClick(Sender: TObject);
procedure btConfClick(Sender: TObject);
procedure btLangClick(Sender: TObject);
procedure btMapperClick(Sender: TObject);
procedure btEditorClick(Sender: TObject);
procedure btEditConfClick(Sender: TObject);
procedure btEditMapperClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
function Execute (var ASettings : TBasicSettings) : boolean;
end;
function GetKeyboardLayoutDosName : string;
function GetCodePage : integer;
var
DosBoxSetDialog: TDosBoxSetDialog;
implementation
{$R *.dfm}
uses Winapi.ShellApi, DosPanelMain, GnuGetText, StringUtils, PathUtils, WinUtils,
MsgDialogs, ShellDirDlg;
{ ------------------------------------------------------------------- }
function GetKeyboardLayoutDosName : string;
var
kbId : cardinal;
begin
kbId:=GetKeyboardLayout(0) and $3FF;
case kbId of
$02 : Result:='BG'; //Bulgarien - 866
$05 : Result:='CZ243'; //Tschechien - 852
$0c : Result:='FR'; //Frankreich - 858
$08 : Result:='GK'; //Griechenland - 869
$07 : Result:='GR'; //Deutschland/Österreich - 858
$1a : Result:='HR'; //Kroatien - 852
$0e : Result:='HU'; //Ungarn - 852
$10 : Result:='IT'; //Italien - 858
$13 : Result:='NL'; //Niederlande - 858
$14 : Result:='NO'; //Norwegen - 865
$15 : Result:='PL'; //Polen - 852
$19 : Result:='RU'; //Russland - 866
$1b : Result:='SK'; //Slowakei - 852
$0a : Result:='SP'; //Spanien - 858
$0b : Result:='SU'; //Finnland - 858
$1d : Result:='SV'; //Schweden - 850
else Result:='';
end;
end;
function GetCodePage : integer;
var
kbId : cardinal;
begin
kbId:=GetKeyboardLayout(0) and $3FF;
case kbId of
$02 : Result:=866; //Bulgarien - 866
$05 : Result:=852; //Tschechien - 852
$0c : Result:=858; //Frankreich - 858
$08 : Result:=869; //Griechenland - 869
$07 : Result:=858; //Deutschland/Österreich - 858
$1a : Result:=852; //Kroatien - 852
$0e : Result:=852; //Ungarn - 852
$10 : Result:=858; //Italien - 858
$13 : Result:=858; //Niederlande - 858
$14 : Result:=865; //Norwegen - 865
$15 : Result:=852; //Polen - 852
$19 : Result:=866; //Russland - 866
$1b : Result:=852; //Slowakei - 852
$0a : Result:=858; //Spanien - 858
$0b : Result:=858; //Finnland - 858
$1d : Result:=850; //Schweden - 850
else Result:=437;
end;
end;
procedure TDosBoxSetDialog.FormCreate(Sender: TObject);
var
i : integer;
begin
TranslateComponent(self);
with cbCodePages do begin
Items.Clear;
for i:=0 to High(CodePages) do Items.Add(CodePages[i].CodePageName);
ItemIndex:=0;
end;
end;
procedure TDosBoxSetDialog.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
if (Modalresult=mrOK) then begin
if not FileExists(SetDirName(edPath.Text)+DosBoxName) then
CanClose:=not ConfirmDialog(_('DosBox.exe not found in the specified directory!'+
sLineBreak+'Adjust setting?'));
if not DirectoryExists(SetDirName(edRootPath.Text)) then
CanClose:=not ConfirmDialog(_('Root path to DOS applications not found!'+
sLineBreak+'Adjust setting?'));
end;
end;
procedure TDosBoxSetDialog.btConfClick(Sender: TObject);
begin
with OpenDialog do begin
if length(edConfFile.Text)>0 then InitialDir:=ExtractFilePath(edConfFile.Text)
else InitialDir:=frmMain.LocPath;
DefaultExt:='conf';
Filename:='';
Filter:=_('DOSBox configuration files')+'|*.conf|'+_('All')+'|*.*';
Title:=_('Select basic configuration file');
if Execute then edConfFile.Text:=Filename;
end;
end;
procedure TDosBoxSetDialog.btLangClick(Sender: TObject);
begin
with OpenDialog do begin
if length(edLangFile.Text)>0 then InitialDir:=ExtractFilePath(edLangFile.Text)
else InitialDir:=frmMain.LocPath;
DefaultExt:='lang';
Filename:='';
Filter:=_('DOSBox language files')+'|*.lang|'+_('All')+'|*.*';
Title:=_('Select language file');
if Execute then edLangFile.Text:=Filename;
end;
end;
procedure TDosBoxSetDialog.btMapperClick(Sender: TObject);
begin
with OpenDialog do begin
if length(edMapperFile.Text)>0 then InitialDir:=ExtractFilePath(edMapperFile.Text)
else InitialDir:=frmMain.LocPath;
DefaultExt:='map';
Filename:='';
Filter:=_('DOSBox key mapper files')+'|*.map;*.txt|'+_('All')+'|*.*';
Title:=_('Select key mapper file');
if Execute then edMapperFile.Text:=Filename;
end;
end;
procedure TDosBoxSetDialog.btPathClick(Sender: TObject);
var
s : string;
begin
s:=edPath.Text;
if length(s)=0 then s:=frmMain.ProgPath;
if ShellDirDialog.Execute (_('Select DOSBox program directory'),
false,true,false,frmMain.ProgPath,s) then edPath.Text:=s;
end;
procedure TDosBoxSetDialog.btRootPathClick(Sender: TObject);
var
s : string;
begin
s:=edRootPath.Text;
if length(s)= 0 then s:=frmMain.UserPath;
if ShellDirDialog.Execute (_('Select root path to DOS applications'),
false,true,false,frmMain.ProgPath,s) then edRootPath.Text:=s;
end;
procedure TDosBoxSetDialog.btEditConfClick(Sender: TObject);
begin
ShellExecute (Application.Handle,'open',PChar(MakeQuotedStr(frmMain.BasicSettings.TextEditor,[' '])),
PChar(MakeQuotedStr(edConfFile.Text,[' '])),nil,SW_RESTORE);
end;
procedure TDosBoxSetDialog.btEditMapperClick(Sender: TObject);
begin
ShellExecute (Application.Handle,'open',PChar(MakeQuotedStr(frmMain.BasicSettings.TextEditor,[' '])),
PChar(MakeQuotedStr(edMapperFile.Text,[' '])),nil,SW_RESTORE);
end;
procedure TDosBoxSetDialog.btEditorClick(Sender: TObject);
begin
with OpenDialog do begin
if length(edEditor.Text)>0 then InitialDir:=ExtractFilePath(edEditor.Text)
else InitialDir:=frmMain.ProgPath;
DefaultExt:='exe';
Filename:='';
Filter:=_('Programs')+'|*.exe|'+_('All')+'|*.*';
Title:=_('Select text editor');
if Execute then begin
edEditor.Text:=Filename;
btEditConf.Enabled:=true;
btEditMapper.Enabled:=btEditConf.Enabled;
end;
end;
end;
function TDosBoxSetDialog.Execute (var ASettings : TBasicSettings) : boolean;
var
i : integer;
begin
with ASettings do begin
edRootPath.Text:=RootPath;
edPath.Text:=DosBoxPath;
edConfFile.Text:=ConfFile;
edLangFile.Text:=LangFile;
edMapperFile.Text:=MapperFile;
if length(KeyLayout)=0 then begin
rbAutoKey.Checked:=true;
cbKeyLayout.Text:=GetKeyboardLayoutDosName;
end
else begin
rbKeyLayout.Checked:=true;
cbKeyLayout.Text:=KeyLayout;
end;
for i:=0 to High(CodePages) do if CodePages[i].CodePageNr=CodePage then Break;
if i>High(CodePages) then i:=0;
cbCodePages.ItemIndex:=i;
cbConsole.Checked:=HideCon;
edEditor.Text:=TextEditor;
btEditConf.Enabled:=FileExists(TextEditor);
btEditMapper.Enabled:=btEditConf.Enabled;
cbAutoStart.Checked:=AutoStart;
Result:=ShowModal=mrOK;
if Result then begin
RootPath:=edRootPath.Text;
DosBoxPath:=edPath.Text;
ConfFile:=edConfFile.Text;
LangFile:=edLangFile.Text;
MapperFile:=edMapperFile.Text;
if rbAutoKey.Checked then KeyLayout:=''
else KeyLayout:=cbKeyLayout.Text;
CodePage:=CodePages[cbCodePages.ItemIndex].CodePageNr;
HideCon:=cbConsole.Checked;
TextEditor:=edEditor.Text;
AutoStart:=cbAutoStart.Checked;
end;
end;
end;
end.