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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
#include <windows.h>
#include <strsafe.h>
#include "config.h"
#include "../nu/AutoCharFn.h"
C_Config::C_Config( wchar_t *ini )
{
memset( m_strbuf, 0, sizeof( m_strbuf ) );
memset( m_strbufA, 0, sizeof( m_strbufA ) );
m_inifile = _wcsdup( ini );
m_inifileA = _strdup( AutoCharFn( m_inifile ) );
m_section = 0;
}
C_Config::~C_Config()
{
if ( m_inifile )
free( m_inifile );
if ( m_inifileA )
free( m_inifileA );
if ( m_section )
free( m_section );
}
void C_Config::WriteInt( wchar_t *name, int value )
{
wchar_t buf[ 32 ] = { 0 };
StringCchPrintfW( buf, 32, L"%d", value );
WriteString( name, buf );
}
int C_Config::ReadInt( wchar_t *name, int defvalue )
{
return GetPrivateProfileIntW( L"gen_ml_config", name, defvalue, m_inifile );
}
wchar_t *C_Config::WriteString( wchar_t *name, wchar_t *string )
{
WritePrivateProfileStringW( L"gen_ml_config", name, string, m_inifile );
return name;
}
char *C_Config::WriteString( char *name, char *string )
{
WritePrivateProfileStringA( "gen_ml_config", name, string, m_inifileA );
return name;
}
wchar_t *C_Config::ReadString( wchar_t *name, wchar_t *defstr )
{
static wchar_t foobuf[] = L"___________gen_ml_lameness___________";
m_strbuf[ 0 ] = 0;
GetPrivateProfileStringW( L"gen_ml_config", name, foobuf, m_strbuf, ARRAYSIZE( m_strbuf ), m_inifile );
if ( !wcscmp( foobuf, m_strbuf ) )
return defstr;
m_strbuf[ ARRAYSIZE( m_strbuf ) - 1 ] = 0;
return m_strbuf;
}
bool C_Config::ReadString( const wchar_t *name, const wchar_t *defvalue, wchar_t *storage, size_t len )
{
static wchar_t foobuf[] = L"___________gen_ml_lameness___________";
storage[ 0 ] = 0;
GetPrivateProfileStringW( L"gen_ml_config", name, foobuf, storage, (DWORD)len, m_inifile );
if ( !wcscmp( foobuf, storage ) )
{
if ( defvalue )
lstrcpynW( storage, defvalue, (int)len );
return false;
}
return true;
}
char *C_Config::ReadString( const char *name, char *defstr )
{
static char foobuf[] = "___________gen_ml_lameness___________";
m_strbufA[ 0 ] = 0;
GetPrivateProfileStringA( "gen_ml_config", name, foobuf, m_strbufA, ARRAYSIZE( m_strbufA ), m_inifileA );
if ( !strcmp( foobuf, m_strbufA ) )
return defstr;
m_strbufA[ ARRAYSIZE( m_strbufA ) - 1 ] = 0;
return m_strbufA;
}
char *C_Config::ReadString( const char *section_name, const char *key_name, char *defvalue )
{
static char foobuf[] = "___________lameness___________";
m_strbufA[ 0 ] = 0;
GetPrivateProfileStringA( section_name, key_name, foobuf, m_strbufA, ARRAYSIZE( m_strbufA ), m_inifileA );
if ( !strcmp( foobuf, m_strbufA ) )
return defvalue;
m_strbufA[ ARRAYSIZE( m_strbufA ) - 1 ] = 0;
return m_strbufA;
}
bool C_Config::ReadString( const char *name, const char *defvalue, char *storage, size_t len )
{
static char foobuf[] = "___________gen_ml_lameness___________";
storage[ 0 ] = 0;
GetPrivateProfileStringA( "gen_ml_config", name, foobuf, storage, (DWORD)len, m_inifileA );
if ( !strcmp( foobuf, storage ) )
{
if ( defvalue )
lstrcpynA( storage, defvalue, (int)len );
return false;
}
return true;
}
|