-
Notifications
You must be signed in to change notification settings - Fork 9
/
Ini.ahk
111 lines (95 loc) · 2.34 KB
/
Ini.ahk
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
class Ini {
filename := ""
data := {}
mainSection := ""
__New(filename)
{
this.filename := filename
}
Load()
{
IniRead, sections, % this.filename
Loop, Parse, sections, `n, `r
{
section := A_LoopField
IniRead, pairs, % this.filename, % section
Loop, Parse, pairs, `n, `r
{
pair := StrSplit(A_LoopField, "=")
key := pair[1]
IniRead, value, % this.filename, % section, % key
if(value == "false")
{
value := 0
}
if(value == "true")
{
value := 1
}
if(!this.data.HasKey(section))
{
this.data[section] := {}
}
this.data[section][key] := value
;record the first section as the main section for later use
if(!this.mainSection)
{
this.mainSection := section
}
;MsgBox, % section . "." . key . " = " . value
}
}
;MsgBox, % this.mainSection
}
HasSection(section)
{
return this.data.HasKey(section)
}
Has(section, key)
{
return this.HasSection(section) && this.data[section].HasKey(key)
}
GetSection(section)
{
if(!this.HasSection(section))
{
return {}
}
return this.data[section]
}
Get(section, key, default)
{
if(!this.Has(section, key))
{
return default
}
return this.data[section][key]
}
GetMain(key, default)
{
return this.Get(this.mainSection, key, default)
}
Set(section, key, value)
{
if(!this.HasSection(section))
{
this.data[section] = {}
}
this.data[section][key] := value
}
SetMain(key, value)
{
this.Set(this.mainSection, key, value)
}
Save()
{
for section, values in this.data
{
for key, value in values
{
IniWrite, % value, % this.filename, % section, % key
;MsgBox % section . "." . key . "=" . value
}
}
}
}