forked from NobahdiAtoll/CRDataManager
-
Notifications
You must be signed in to change notification settings - Fork 1
/
iniReadWrite.py
46 lines (40 loc) · 1.31 KB
/
iniReadWrite.py
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
import clr
import System
import System.IO
from System.IO import File, Path, Directory
def ReadKey(iniFilePath, strKey):
dictKeys = LoadFile(iniFilePath)
strReturn = ''
if dictKeys.has_key(strKey):
strReturn = dictKeys[strKey]
return strReturn
def ReadKeyAsStringList(iniFilePath, strKey):
dictKeys = LoadFile(iniFilePath)
ListReturn = []
if dictKeys.has_key(strKey):
ListReturn = dictKeys[strKey].split(',')
return ListReturn
def ReadKeyAsBool(iniFilePath, strKey):
dictKeys = LoadFile(iniFilePath)
bReturn = False
try:
bReturn = bool.Parse(dictKeys[strKey])
except:
pass
return bReturn
def WriteKey(iniFilePath, strKey, strValue):
dictKeys = LoadFile(iniFilePath)
dictKeys[strKey] = strValue
strFile = ""
for item in dictKeys:
strFile += item + ' = ' + dictKeys[item] + System.Environment.NewLine
File.WriteAllText(iniFilePath, strFile)
pass
def LoadFile(iniFilePath):
dictKeys = dict()
if File.Exists(iniFilePath):
KeyLines = File.ReadAllLines(iniFilePath)
for line in KeyLines:
if not line.startswith(';') and not line.strip() == '':
dictKeys.Add(line.split(' = ')[0].strip(),line.split('=')[1].strip())
return dictKeys