-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathini.cpp
More file actions
90 lines (69 loc) · 2.31 KB
/
ini.cpp
File metadata and controls
90 lines (69 loc) · 2.31 KB
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
#include "ini.h"
#include <iostream>
#include <Windows.h>
#include "log.h"
#define MAX_INI 255
#pragma warning (disable : 4996 )
#pragma warning (disable : 4244 )
char m_szFileName[MAX_INI];
void set_config_file(char* szFileName)
{
memset(m_szFileName, 0x00, MAX_INI);
memcpy(m_szFileName, szFileName, strlen(szFileName));
}
int get_config_int(char* szSection, char* szKey, int iDefaultValue)
{
int iResult = GetPrivateProfileIntA(szSection, szKey, iDefaultValue, m_szFileName);
return iResult;
}
float get_config_float(char* szSection, char* szKey, float fltDefaultValue)
{
char szResult[255];
char szDefault[255];
float fltResult;
sprintf(szDefault, "%f", fltDefaultValue);
GetPrivateProfileStringA(szSection, szKey, szDefault, szResult, MAX_INI, m_szFileName);
fltResult = atof(szResult);
return fltResult;
}
bool get_config_bool(char* szSection, char* szKey, bool bolDefaultValue)
{
char szResult[MAX_INI];
char szDefault[MAX_INI];
bool bolResult;
sprintf(szDefault, "%s", bolDefaultValue ? "True" : "False");
GetPrivateProfileStringA(szSection, szKey, szDefault, szResult, MAX_INI, m_szFileName);
bolResult = (strcmp(szResult, "True") == 0 ||
strcmp(szResult, "true") == 0) ? true : false;
return bolResult;
}
char* get_config_string(char* szSection, char* szKey, const char* szDefaultValue)
{
char* szResult = new char[MAX_INI];
memset(szResult, 0x00, MAX_INI);
GetPrivateProfileStringA(szSection, szKey,
szDefaultValue, szResult, MAX_INI, m_szFileName);
return szResult;
}
void set_config_int(char* szSection, char* szKey, int iValue)
{
char szValue[MAX_INI];
sprintf(szValue, "%d", iValue);
WritePrivateProfileStringA(szSection, szKey, szValue, m_szFileName);
}
void set_config_float(char* szSection, char* szKey, float fltValue)
{
char szValue[MAX_INI];
sprintf(szValue, "%f", fltValue);
WritePrivateProfileStringA(szSection, szKey, szValue, m_szFileName);
}
void set_config_bool(char* szSection, char* szKey, bool bolValue)
{
char szValue[MAX_INI];
sprintf(szValue, "%s", bolValue ? "True" : "False");
WritePrivateProfileStringA(szSection, szKey, szValue, m_szFileName);
}
void set_config_string(char* szSection, char* szKey, char* szValue)
{
WritePrivateProfileStringA(szSection, szKey, szValue, m_szFileName);
}