-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigure.cpp
72 lines (57 loc) · 1.82 KB
/
Configure.cpp
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
//author:autumoon
//mail:[email protected]
#include "Configure.h"
inline _tstring VectorToString(const std::vector<_tstring>& vStrings)
{
_tstring strRes;
const size_t num = vStrings.size();
if (num > 0)
{
for (size_t i = 0; i < num - 1; ++i)
{
const _tstring& strCurItems = vStrings[i];
strRes += strCurItems + _T('|');
}
strRes += vStrings[vStrings.size() - 1];
}
return strRes;
}
int ReadIniFile(const _tstring& strIniPath, config_s& _cfg)
{
bool bRes = CStdFile::IfAccessFile(strIniPath.c_str());
CSimpleIni Ini;
Ini.SetUnicode();
if (bRes)
{
//¶ÁÈ¡ÐÅÏ¢
Ini.LoadFile(strIniPath.c_str());
_cfg.bRemPath = Ini.GetBoolValue(INI_PRESUFFIX, INI_REMPATH, _cfg.bRemPath);
_tstring strRootDirs = VectorToString(_cfg.vDstPaths);
strRootDirs = Ini.GetValue(INI_PRESUFFIX, INI_PATH_DIRS, strRootDirs.c_str());
_cfg.vDstPaths = CStdStr::Split(strRootDirs, _T("|"));
_tstring strAllDirs = VectorToString(_cfg.vItemPaths);
strAllDirs = Ini.GetValue(INI_PRESUFFIX, INI_PATH_FILES, strAllDirs.c_str());
_cfg.vItemPaths = CStdStr::Split(strAllDirs, _T("|"));
_tstring strSuffixs = VectorToString(_cfg.vSuffixs);
strSuffixs = Ini.GetValue(INI_PRESUFFIX, INI_FILE_SUFFIXS, strSuffixs.c_str());
_cfg.vSuffixs = CStdStr::Split(strSuffixs, _T("|"));
}
else
{
WriteIniFile(strIniPath, _cfg);
}
Ini.Reset();
return 0;
}
int WriteIniFile(const _tstring& strIniPath, const config_s& _cfg)
{
CSimpleIni Ini;
Ini.SetUnicode();
Ini.SetBoolValue(INI_PRESUFFIX, INI_REMPATH, _cfg.bRemPath);
Ini.SetValue(INI_PRESUFFIX, INI_PATH_DIRS, VectorToString(_cfg.vDstPaths).c_str());
Ini.SetValue(INI_PRESUFFIX, INI_PATH_FILES, VectorToString(_cfg.vItemPaths).c_str());
Ini.SetValue(INI_PRESUFFIX, INI_FILE_SUFFIXS, VectorToString(_cfg.vSuffixs).c_str());
Ini.SaveFile(strIniPath.c_str());
Ini.Reset();
return 0;
}