aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Library/ml_pmp/config.cpp
blob: c14f110d51948f4f82aa4957e3dd9a802f71be24 (plain) (blame)
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
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>

#include "config.h"

C_Config::~C_Config()
{
  free(m_inifile);
  free(m_section);
}

C_Config::C_Config(wchar_t *ini, wchar_t *section, C_Config * globalWrite) : globalWrite(globalWrite)
{
  m_strbuf[0]=0;
  m_inifile=_wcsdup(ini);
  m_section=_wcsdup(section);
}

void C_Config::WriteInt(wchar_t *name, int value, wchar_t *section)
{
  wchar_t buf[32] = {0};
  wsprintf(buf,L"%d",value);
  WriteString(name,buf,section);
}

int C_Config::ReadInt(wchar_t *name, int defvalue, wchar_t *section)
{
  return GetPrivateProfileInt(section?section:m_section,name,defvalue,m_inifile);
}

wchar_t *C_Config::WriteString(wchar_t *name, wchar_t *string, wchar_t *section)
{
  if(globalWrite && !section) globalWrite->WriteString(name,string,m_section);
  WritePrivateProfileString(section?section:m_section,name,string,m_inifile);
  return name;
}

wchar_t *C_Config::ReadString(wchar_t *name, wchar_t *defstr, wchar_t *section)
{
  static wchar_t foobuf[] = L"___________config_lameness___________";
  m_strbuf[0]=0;
  GetPrivateProfileString(section?section:m_section,name,foobuf,m_strbuf,sizeof(m_strbuf)/sizeof(wchar_t),m_inifile);
  if (!lstrcmp(foobuf,m_strbuf)) return defstr;

  m_strbuf[sizeof(m_strbuf)/sizeof(wchar_t)-1]=0;
  return m_strbuf;
}