#include "stdafx.h"
#include "IniFile.h"

CIniFile::CIniFile(VOID)
{
	ZeroMemory(mFileName, sizeof(mFileName));
}

CIniFile::~CIniFile(VOID)
{
}

BOOL CIniFile::Open(char* fileName)
{
	if (!fileName)
		return FALSE;

	strncpy(mFileName, fileName, MAX_PATH);

	FILE* fp = fopen(fileName, "r");
	if(fp == NULL)
		return FALSE;

	fclose(fp);

	return TRUE;
}

BOOL CIniFile::Close(VOID)
{
	return TRUE;
}

BOOL CIniFile::GetValue(char* keyName, char* valueName, LPDWORD value)
{
	if (!keyName || !valueName || !value)
		return FALSE;

	char Value[16] = {0,};
	GetPrivateProfileString(keyName, valueName, "", Value, 16, mFileName);

	*value = (DWORD) atoi(Value);

	return TRUE;
}

BOOL CIniFile::GetValue(char* keyName, char* valueName, FLOAT *value)
{
	if (!keyName || !valueName || !value)
		return FALSE;

	char Value[16] = {0,};

	GetPrivateProfileString(keyName, valueName, "", Value, 16, mFileName);

	*value = (FLOAT) atof(Value);

	return TRUE;
}

BOOL CIniFile::GetValue(char* keyName, char* valueName, char* value, LPDWORD bufferLength)
{
	if (!keyName || !valueName || !value || !bufferLength)
		return FALSE;

	*bufferLength = GetPrivateProfileString(keyName, valueName, "", value, 512, mFileName);

	return TRUE;
}

BOOL CIniFile::SetValue(char* keyName, char* valueName, DWORD value)
{
	if (!keyName || !valueName)
		return FALSE;

	char Value[16];
	sprintf(Value, "%d", value);

	WritePrivateProfileString(keyName, valueName, Value, mFileName);

	return TRUE;
}

BOOL CIniFile::SetValue(char* keyName, char* valueName, char* value)
{
	if (!keyName || !valueName || !value)
		return FALSE;

	WritePrivateProfileString(keyName, valueName, value, mFileName);

	return TRUE;
}

BOOL CIniFile::SetValue(char* keyName, char* valueName, FLOAT value)
{
	if (!keyName || !valueName)
		return FALSE;

	char Value[16]	= {0,};
	sprintf(Value, "%f", value);

	WritePrivateProfileString(keyName, valueName, Value, mFileName);

	return TRUE;
}
