This repository has been archived by the owner on Mar 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.pas
93 lines (73 loc) · 2.14 KB
/
config.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
unit config;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
IniFiles;
const
DefaultConfigFile = 'config.ini';
type
{ TIRCConfig }
TIRCConfig = class
private
FHost: string;
FPort: integer;
FUsername: string;
FNickname: string;
FRealName: string;
FAltNickname: string;
FChannels: TStrings;
FIni: TIniFile;
public
procedure Save;
procedure Load;
property Host: string read FHost write FHost;
property Port: integer read FPort write FPort;
property Username: string read FUsername write FUsername;
property Nickname: string read FNickname write FNickname;
property RealName: string read FRealName write FRealName;
property AltNickname: string read FAltNickname write FAltNickname;
property Channels: TStrings read FChannels;
constructor Create;
destructor Destroy; override;
end;
implementation
const
SectionServer = 'Server';
SectionUser = 'User';
SectionChannels = 'Channels';
{ TIRCConfig }
procedure TIRCConfig.Save;
begin
FIni.WriteString(SectionServer, 'Host', FHost);
FIni.WriteInteger(SectionServer, 'Port', FPort);
FIni.WriteString(SectionUser, 'Username', FUsername);
FIni.WriteString(SectionUser, 'Nickname', FNickname);
FIni.WriteString(SectionUser, 'RealName', FRealName);
FIni.WriteString(SectionUser, 'AltNickname', FAltNickname);
FIni.WriteString(SectionChannels, 'AutoJoin', FChannels.CommaText);
FIni.UpdateFile;
end;
procedure TIRCConfig.Load;
begin
FHost := FIni.ReadString(SectionServer, 'Host', '');
FPort := FIni.ReadInteger(SectionServer, 'Port', 6667);
FUsername := FIni.ReadString(SectionUser, 'Username', '');
FNickname := FIni.ReadString(SectionUser, 'Nickname', '');
FRealName := FIni.ReadString(SectionUser, 'RealName', '');
FAltNickname := FIni.ReadString(SectionUser, 'AltNickname', '');
FChannels.CommaText := FIni.ReadString(SectionChannels, 'AutoJoin', '');
end;
constructor TIRCConfig.Create;
begin
FChannels := TStringList.Create;
Fini := TIniFile.Create('config.ini');
end;
destructor TIRCConfig.Destroy;
begin
FChannels.Free;
FIni.Free;
inherited Destroy;
end;
end.