This "bug" occurs in every line. For a time it worked to cut off the last two signs...but now it doesn't....i'm veeeeeeery confused....
#ifndef INIREADER_H
#define INIREADER_H
class CIniReader
{
public:
CIniReader(char* szFileName);
int ReadInteger(char* szSection, char* szKey, int iDefaultValue);
float ReadFloat(char* szSection, char* szKey, float fltDefaultValue);
bool ReadBoolean(char* szSection, char* szKey, bool bolDefaultValue);
char* ReadString(char* szSection, char* szKey, const char* szDefaultValue);
private:
char m_szFileName[255];
};
#endif//INIREADER_H
#ifndef INIWRITER_H
#define INIWRITER_H
class CIniWriter
{
public:
CIniWriter(char* szFileName);
void WriteInteger(char* szSection, char* szKey, int iValue);
void WriteFloat(char* szSection, char* szKey, float fltValue);
void WriteBoolean(char* szSection, char* szKey, bool bolValue);
void WriteString(char* szSection, char* szKey, char* szValue);
private:
char m_szFileName[255];
};
#endif //INIWRITER_H
#ifndef INI_H
#define INI_H
#include <Windows.h>
#include <Stdio.h>
#include "IniReader.h"
#include "IniWriter.h"
/*******************************************************************************
# INI READER
*******************************************************************************/
CIniReader::CIniReader(char* szFileName)
{
memset(m_szFileName, 0x00, 255);
memcpy(m_szFileName, szFileName, strlen(szFileName));
}
int CIniReader::ReadInteger(char* szSection, char* szKey, int iDefaultValue)
{
int iResult = GetPrivateProfileInt(szSection, szKey, iDefaultValue, m_szFileName);
return iResult;
}
float CIniReader::ReadFloat(char* szSection, char* szKey, float fltDefaultValue)
{
char szResult[255];
char szDefault[255];
float fltResult;
sprintf(szDefault, "%f",fltDefaultValue);
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
fltResult = atof(szResult);
return fltResult;
}
bool CIniReader::ReadBoolean(char* szSection, char* szKey, bool bolDefaultValue)
{
char szResult[255];
char szDefault[255];
bool bolResult;
sprintf(szDefault, "%s", bolDefaultValue? "True" : "False");
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
CharLower(szResult);
bolResult = (strcmp(szResult, "true") == 0) ? true : false;
return bolResult;
}
char* CIniReader::ReadString(char* szSection, char* szKey, const char* szDefaultValue)
{
char* szResult = new char[255];
memset(szResult, 0x00, 255);
GetPrivateProfileString(szSection, szKey, szDefaultValue, szResult, 255, m_szFileName);
return szResult;
}
/*******************************************************************************
# INI WRITER
*******************************************************************************/
CIniWriter::CIniWriter(char* szFileName)
{
memset(m_szFileName, 0x00, 255);
memcpy(m_szFileName, szFileName, strlen(szFileName));
}
void CIniWriter::WriteInteger(char* szSection, char* szKey, int iValue)
{
char szValue[255];
sprintf(szValue, "%d", iValue);
WritePrivateProfileString(szSection, szKey, szValue, m_szFileName);
}
void CIniWriter::WriteFloat(char* szSection, char* szKey, float fltValue)
{
char szValue[255];
sprintf(szValue, "%f", fltValue);
WritePrivateProfileString(szSection, szKey, szValue, m_szFileName);
}
void CIniWriter::WriteBoolean(char* szSection, char* szKey, bool bolValue)
{
char szValue[255];
sprintf(szValue, "%s", bolValue ? "True" : "False");
WritePrivateProfileString(szSection, szKey, szValue, m_szFileName);
}
void CIniWriter::WriteString(char* szSection, char* szKey, char* szValue)
{
WritePrivateProfileString(szSection, szKey, szValue, m_szFileName);
}
#endif //INI_H

Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
bool CConfigManager::saveChanges()
{
switch(deviceParam.DriverType)
{
case EDT_SOFTWARE: ini->addKeyToSection("Settings","DriverType","EDT_SOFTWARE");
break;
case EDT_BURNINGSVIDEO: ini->addKeyToSection("Settings","DriverType","EDT_BURNINGSVIDEO");
break;
case EDT_DIRECT3D8: ini->addKeyToSection("Settings","DriverType","EDT_DIRECT3D8");
break;
case EDT_DIRECT3D9: ini->addKeyToSection("Settings","DriverType","EDT_DIRECT3D9");
break;
case EDT_OPENGL: ini->addKeyToSection("Settings","DriverType","EDT_OPENGL");
break;
default: ini->addKeyToSection("Settings","DriverType","EDT_NULL");
}
stringc winSize = deviceParam.WindowSize.Width;
winSize += "x";
winSize += deviceParam.WindowSize.Height;
ini->addKeyToSection("Settings","WindowSize",winSize.c_str());
ini->setSaveFileName(iniFilePath);
return ini->save();
}
config.ini wrote:[Settings]
DriverType=EDT_OPENGL
WindowSize=800x600
Bits=32
Fullscreen=false
Stencilbuffer=false
Vsync=false
AntiAlias=false
HighPrecisionFPU=false
EDT_DIRECT3D8=ֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽ
1024x768=ֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽֽ

Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Sylence wrote:Yeah I know about this bug and to be honest I didn't figure out yet why the file is read wrong if there is no new line at the end of the file.
I'll try to fix this when I have more time to work on it (maybe in 2 weeks or so)
@bull When you only need configuration files lua is overkill.
oh and btw you can pass a dimension2d directy to setValue()

if(value)
strncpy(k->Name,value,64);
if(value)
strncpy(k->Value,value,64);
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
config.ini wrote:[Settings]
DriverType=EDT_OPENGL
WindowSize=800x600
Bits=32
Fullscreen=false
Stencilbuffer=false
Vsync=false
AntiAlias=false
HighPrecisionFPU=false
DriverType=EDT_DIRECT3D8
WindowSize=1024x768

Users browsing this forum: No registered users and 1 guest