-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathIni.cpp
85 lines (70 loc) · 1.85 KB
/
Ini.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
#include "stdafx.h"
#include "res/ResExtractData.h"
#include "Common.h"
#include "Ini.h"
CIni::CIni()
{
TCHAR modulePath[MAX_PATH];
GetModuleFileName(NULL, modulePath, sizeof(modulePath));
PathRemoveFileSpec(modulePath);
TCHAR szIniPath[MAX_PATH];
wsprintf(szIniPath, _T("%s\\ExtractData.ini"), modulePath);
m_sIniPath = szIniPath;
}
CIni::CIni(LPCTSTR IniName)
{
TCHAR modulePath[MAX_PATH];
GetModuleFileName(NULL, modulePath, sizeof(modulePath));
PathRemoveFileSpec(modulePath);
TCHAR szIniPath[MAX_PATH];
wsprintf(szIniPath, _T("%s\\%s.ini"), modulePath, IniName);
m_sIniPath = szIniPath;
}
void CIni::SetSection(HINSTANCE hInst, UINT uID)
{
TCHAR section[256];
LoadString(hInst, uID, section, sizeof(section));
SetSection(section);
}
void CIni::GetHex(LPDWORD hex, LPCTSTR def)
{
TCHAR str[256];
GetPrivateProfileString(m_sSection, m_sKey, def, str, sizeof(str), m_sIniPath);
*hex = strtoul( str, NULL, 16 );
}
void CIni::GetStr(LPTSTR str, LPCTSTR def, DWORD len)
{
GetPrivateProfileString(m_sSection, m_sKey, def, str, len, m_sIniPath);
}
void CIni::GetStr(YCString& str, YCString def)
{
TCHAR szStr[1024];
GetPrivateProfileString(m_sSection, m_sKey, def, szStr, 1024, m_sIniPath);
str = szStr;
}
void CIni::WriteBool(BOOL flag)
{
TCHAR str[256];
wsprintf(str, _T("%d"), flag);
WritePrivateProfileString(m_sSection, m_sKey, str, m_sIniPath);
}
void CIni::WriteDec(INT dec)
{
TCHAR str[256];
wsprintf(str, _T("%d"), dec);
WritePrivateProfileString(m_sSection, m_sKey, str, m_sIniPath);
}
void CIni::WriteHex(DWORD hex)
{
TCHAR str[256];
wsprintf(str, _T("%06x"), hex);
WritePrivateProfileString(m_sSection, m_sKey, str, m_sIniPath);
}
void CIni::WriteStr(LPCTSTR str)
{
WritePrivateProfileString(m_sSection, m_sKey, str, m_sIniPath);
}
BOOL CIni::DeleteSection()
{
return WritePrivateProfileString(m_sSection, NULL, NULL, m_sIniPath);
}