-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathIni.pas
98 lines (71 loc) · 2.69 KB
/
Ini.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
//This Source Code Form is subject to the terms of the Mozilla Public
//License, v. 2.0. If a copy of the MPL was not distributed with this
//file, You can obtain one at http://mozilla.org/MPL/2.0/.
//Copyright (c) 2013 Alex Shovkoplyas VE3NEA
unit Ini;
interface
uses
Windows, SysUtils, Forms, ShlObj, IniFiles;
procedure ToIni;
procedure FromIni;
function GetIniFolder: TFileName;
implementation
uses
Main, VnaCli;
//------------------------------------------------------------------------------
// ini folder
//------------------------------------------------------------------------------
function GetIniName: TFileName;
var
AppName: TFileName;
begin
if (GetVersion and $FF) < 6 //6.0 = Vista
then
Result := ChangeFileExt(ParamStr(0), '.ini')
else
begin
AppName := ChangeFileExt(ExtractFileName(ParamStr(0)), '');
SetLength(Result, MAX_PATH);
SHGetSpecialFolderPath(Application.Handle, @Result[1], CSIDL_APPDATA, true);
Result := PChar(Result) + '\Afreet\Products\' + AppName + '\';
try ForceDirectories(Result); except end;
Result := Result + AppName + '.ini';
end;
end;
function GetIniFolder: TFileName;
begin
Result := ExtractFilePath(GetIniName);
end;
//------------------------------------------------------------------------------
// ini read/write
//------------------------------------------------------------------------------
procedure ToIni;
begin
with TIniFile.Create(GetIniName) do
try
WriteBool('Settings', 'Run', MainForm.Cli.State = vsRunning);
WriteBool('Settings', 'Mode', MainForm.ReflModeRadioButton.Checked);
WriteBool('Settings', 'SmithChart', MainForm.SmithChartRadioButton.Checked);
WriteString('Settings', 'CalibrationFile', MainForm.Clb.FileName);
finally
Free;
end;
end;
procedure FromIni;
begin
with TIniFile.Create(GetIniName) do
try
//mode and chart
MainForm.ReflModeRadioButton.Checked := ReadBool('Settings', 'Mode', MainForm.ReflModeRadioButton.Checked);
MainForm.TransModeRadioButton.Checked := not MainForm.ReflModeRadioButton.Checked;
MainForm.SelectSmithMode(ReadBool('Settings', 'SmithChart', MainForm.SmithChartRadioButton.Checked));
//calibration file
MainForm.Clb.FileName := ReadString('Settings', 'CalibrationFile', MainForm.Clb.FileName);
with MainForm.Clb do if FileName <> '' then LoadFromFile(FileName);
//auto-start
if ReadBool('Settings', 'Run', false) then PostMessage(MainForm.Handle, WM_RUN, 0, 0);
finally
Free;
end;
end;
end.