-
Notifications
You must be signed in to change notification settings - Fork 3
/
freeeim_config.cpp
100 lines (77 loc) · 1.98 KB
/
freeeim_config.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
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
#include "StdAfx.h"
#include "EIM02Dlg.h"
#include "thirdpartclass/INI.h"
#include "freeeim_config.h"
#include "em/EM_UserInfo.h"
// Download by http://www.codefans.net
FreeEIM_Config::FreeEIM_Config()
{
m_strDisplayName = "";
m_strGroup = "";
m_pUserInfo = NULL;
ReadConfig();
}
FreeEIM_Config::~FreeEIM_Config()
{
if (NULL != m_pUserInfo)
{
delete m_pUserInfo;
m_pUserInfo = NULL;
}
}
EM_UserInfo *FreeEIM_Config::GetUserInfo()
{
m_pUserInfo = new EM_UserInfo((LPSTR)(LPCTSTR)m_strDisplayName, "male", (LPSTR)(LPCTSTR)m_strGroup);
return m_pUserInfo;
}
void FreeEIM_Config::ReadConfig()
{
m_pMainTop = (CEIM02Dlg*)AfxGetMainWnd();
// 检查用户设置文件
/**/char szFileName[_MAX_PATH];
/**/m_pMainTop->GetProgramDirectory(szFileName);
/**/strcat(szFileName, "freeeim.ini");
CIniReader iniReader(szFileName);
if (iniReader.sectionExists("freeeim"))
{
// 当前用户名
m_strDisplayName = iniReader.getKeyValue("display", "freeeim");
// 当前分组
m_strGroup = iniReader.getKeyValue("group", "freeeim");
}
else // 如果没有配置文件则新建一个,并且使用默认信息
{
m_strDisplayName = GetComputerName();
m_strGroup = FreeEIM_Default_Group;
iniReader.setKey((LPCTSTR)m_strDisplayName, "display", "freeeim");
iniReader.setKey((LPCTSTR)m_strGroup, "group", "freeeim");
}
}
void FreeEIM_Config::SaveConfig()
{
m_pMainTop = (CEIM02Dlg*)AfxGetMainWnd();
// 检查用户设置文件
/**/char szFileName[_MAX_PATH];
/**/m_pMainTop->GetProgramDirectory(szFileName);
/**/strcat(szFileName, "freeeim.ini");
CIniReader iniReader(szFileName);
if (iniReader.sectionExists("freeeim"))
{
iniReader.setKey((LPCTSTR)m_strDisplayName, "display", "freeeim");
iniReader.setKey((LPCTSTR)m_strGroup, "group", "freeeim");
}
}
CString FreeEIM_Config::GetDisplayName()
{
return m_strDisplayName;
}
CString FreeEIM_Config::GetGroup()
{
return m_strGroup;
}
CString FreeEIM_Config::GetComputerName()
{
m_pMainTop = (CEIM02Dlg*)AfxGetMainWnd();
// 获取本机计算机名
return m_pMainTop->GetComputerName();
}