mirror of
https://github.com/1dot13/source.git
synced 2026-08-05 14:00:23 +02:00
Remove #ifdefs for USE_VFS
This commit is contained in:
+1
-110
@@ -12,9 +12,7 @@
|
||||
|
||||
#include <vfs/Core/vfs.h>
|
||||
|
||||
#ifdef USE_VFS
|
||||
std::set<vfs::Path,vfs::Path::Less> CIniReader::m_merge_files;
|
||||
#endif
|
||||
std::stack<std::string> iniErrorMessages;
|
||||
|
||||
template<typename ValueType>
|
||||
@@ -32,26 +30,14 @@ void PushErrorMessage(std::string const& filename,
|
||||
iniErrorMessages.push(errMessage.str());
|
||||
}
|
||||
|
||||
#ifdef USE_VFS
|
||||
void CIniReader::RegisterFileForMerging(vfs::Path const& filename)
|
||||
{
|
||||
m_merge_files.insert(filename);
|
||||
}
|
||||
#endif
|
||||
|
||||
CIniReader::CIniReader(const STR8 szFileName)
|
||||
{
|
||||
memset(m_szFileName,0,sizeof(m_szFileName));
|
||||
#ifndef USE_VFS
|
||||
// Snap: Look for the INI file in the custom Data directory.
|
||||
// If not there, leave at default location.
|
||||
if ( gCustomDataCat.FindFile(szFileName) ) {
|
||||
sprintf(m_szFileName, "%s\\%s", gCustomDataCat.GetRootDir().c_str(), szFileName);
|
||||
}
|
||||
else {
|
||||
sprintf(m_szFileName, "%s\\%s", gDefaultDataCat.GetRootDir().c_str(), szFileName);
|
||||
}
|
||||
#else
|
||||
strncpy(m_szFileName,szFileName, std::min<int>(strlen(szFileName), sizeof(m_szFileName)-1));
|
||||
if(m_merge_files.find(szFileName) == m_merge_files.end())
|
||||
{
|
||||
@@ -81,7 +67,6 @@ CIniReader::CIniReader(const STR8 szFileName)
|
||||
if(getVFS()->fileExists(OvrFileName))
|
||||
m_oProps.initFromIniFile(vfs::Path(OvrFileName));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
CIniReader::CIniReader(const STR8 szFileName, BOOLEAN Force_Custom_Data_Path)
|
||||
@@ -89,32 +74,6 @@ CIniReader::CIniReader(const STR8 szFileName, BOOLEAN Force_Custom_Data_Path)
|
||||
memset(m_szFileName,0,sizeof(m_szFileName));
|
||||
// ary-05/05/2009 : force custom data path for potential non existing file -or- force default data path
|
||||
// : Also, flag file detection to allow functions to determine course of action for case of file [not found/is found].
|
||||
#ifndef USE_VFS
|
||||
if ( Force_Custom_Data_Path )
|
||||
{
|
||||
if ( gCustomDataCat.FindFile(szFileName) )
|
||||
{
|
||||
CIniReader_File_Found = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
CIniReader_File_Found = FALSE;
|
||||
}
|
||||
sprintf(m_szFileName, "%s\\%s", gCustomDataCat.GetRootDir().c_str(), szFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( gDefaultDataCat.FindFile(szFileName) )
|
||||
{
|
||||
CIniReader_File_Found = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
CIniReader_File_Found = FALSE;
|
||||
}
|
||||
sprintf(m_szFileName, "%s\\%s", gDefaultDataCat.GetRootDir().c_str(), szFileName);
|
||||
}
|
||||
#else
|
||||
strncpy(m_szFileName,szFileName, std::min<int>(strlen(szFileName), sizeof(m_szFileName)-1));
|
||||
if(m_merge_files.find(szFileName) == m_merge_files.end())
|
||||
{
|
||||
@@ -137,38 +96,24 @@ CIniReader::CIniReader(const STR8 szFileName, BOOLEAN Force_Custom_Data_Path)
|
||||
rev_order.pop();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIniReader::Clear()
|
||||
{
|
||||
#ifndef USE_VFS
|
||||
memset(m_szFileName, 0, MAX_PATH);
|
||||
#else
|
||||
memset(m_szFileName, 0, MAX_PATH);
|
||||
m_oProps.clearContainer();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int iDefaultValue)
|
||||
{
|
||||
#ifndef USE_VFS
|
||||
return GetPrivateProfileInt(szSection, szKey, iDefaultValue, m_szFileName);
|
||||
#else
|
||||
return (int)(m_oProps.getIntProperty(szSection, szKey, iDefaultValue));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int defaultValue, int minValue, int maxValue)
|
||||
{
|
||||
#ifndef USE_VFS
|
||||
int iniValueReadFromFile = (int)(GetPrivateProfileInt(szSection, szKey, defaultValue, m_szFileName));
|
||||
#else
|
||||
int iniValueReadFromFile = (int)(m_oProps.getIntProperty(szSection, szKey, defaultValue));
|
||||
#endif
|
||||
//AssertGE(iniValueReadFromFile, minValue);
|
||||
//AssertLE(iniValueReadFromFile, maxValue);
|
||||
if (iniValueReadFromFile < minValue)
|
||||
@@ -200,15 +145,7 @@ int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int defaultV
|
||||
double CIniReader::ReadDouble(const STR8 szSection, const STR8 szKey, double defaultValue, double minValue, double maxValue)
|
||||
{
|
||||
double iniValueReadFromFile;
|
||||
#ifndef USE_VFS
|
||||
char szResult[255];
|
||||
char szDefault[255];
|
||||
sprintf(szDefault, "%f", defaultValue);
|
||||
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
|
||||
iniValueReadFromFile = (float) atof(szResult);
|
||||
#else
|
||||
iniValueReadFromFile = m_oProps.getFloatProperty(szSection, szKey, defaultValue);
|
||||
#endif
|
||||
//AssertGE(iniValueReadFromFile, minValue);
|
||||
//AssertLE(iniValueReadFromFile, maxValue);
|
||||
if (iniValueReadFromFile < minValue)
|
||||
@@ -227,15 +164,7 @@ double CIniReader::ReadDouble(const STR8 szSection, const STR8 szKey, double def
|
||||
FLOAT CIniReader::ReadFloat(const STR8 szSection, const STR8 szKey, FLOAT defaultValue, FLOAT minValue, FLOAT maxValue)
|
||||
{
|
||||
FLOAT iniValueReadFromFile;
|
||||
#ifndef USE_VFS
|
||||
char szResult[255];
|
||||
char szDefault[255];
|
||||
sprintf(szDefault, "%f", defaultValue);
|
||||
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
|
||||
iniValueReadFromFile = (FLOAT) atof(szResult);
|
||||
#else
|
||||
iniValueReadFromFile = (FLOAT) m_oProps.getFloatProperty(szSection, szKey, (float)defaultValue);
|
||||
#endif
|
||||
|
||||
//AssertGE(iniValueReadFromFile, minValue);
|
||||
//AssertLE(iniValueReadFromFile, maxValue);
|
||||
@@ -329,18 +258,6 @@ void CIniReader::ReadINT32Array(const STR8 szSection, const STR8 szKey, std::vec
|
||||
|
||||
BOOLEAN CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool defaultValue, bool bolDisplayError)
|
||||
{
|
||||
#ifndef USE_VFS
|
||||
char szResult[255];
|
||||
char szDefault[255];
|
||||
sprintf(szDefault, "%s", defaultValue? "TRUE" : "FALSE");
|
||||
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
|
||||
for (int idx=0; (szResult[idx] != 0) && (idx < 255); ++idx)
|
||||
szResult[idx] = toupper(szResult[idx]);
|
||||
if (strcmp(szResult, "TRUE") == 0)
|
||||
return TRUE;
|
||||
else if (strcmp(szResult, "FALSE") == 0)
|
||||
return FALSE;
|
||||
#else
|
||||
vfs::String str = m_oProps.getStringProperty(szSection, szKey, L"");
|
||||
if( vfs::StrCmp::Equal(str, L"true") )
|
||||
{
|
||||
@@ -353,7 +270,7 @@ BOOLEAN CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool def
|
||||
std::string szResult = str.utf8();
|
||||
char szDefault[255];
|
||||
sprintf(szDefault, "%s", defaultValue? "TRUE" : "FALSE");
|
||||
#endif
|
||||
|
||||
if(bolDisplayError){
|
||||
std::stringstream errMessage;
|
||||
errMessage << "The value [" << szSection << "][" << szKey << "] = \"" << szResult << "\" "
|
||||
@@ -370,14 +287,10 @@ BOOLEAN CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool def
|
||||
|
||||
void CIniReader::ReadString(const STR8 szSection, const STR8 szKey, const STR8 szDefaultValue, STR8 input_buffer, size_t buffer_size)
|
||||
{
|
||||
#ifndef USE_VFS
|
||||
GetPrivateProfileString(szSection, szKey, szDefaultValue, input_buffer, buffer_size, m_szFileName);
|
||||
#else
|
||||
std::string s = m_oProps.getStringProperty(szSection, szKey, szDefaultValue).utf8();
|
||||
int len = std::min<unsigned int>(s.length(),buffer_size-1);
|
||||
strncpy(input_buffer, s.c_str(), len);
|
||||
input_buffer[len] = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// WANNE - MP: Old version, currently used by Multiplayer
|
||||
@@ -386,12 +299,8 @@ STR8 CIniReader::ReadString(const STR8 szSection, const STR8 szKey, const STR8 s
|
||||
// >>>>> Memory Leak <<<<<
|
||||
STR8 szResult = new char[255];
|
||||
memset(szResult, 0x00, 255);
|
||||
#ifndef USE_VFS
|
||||
GetPrivateProfileString(szSection, szKey, szDefaultValue, szResult, 255, m_szFileName);
|
||||
#else
|
||||
std::string s = m_oProps.getStringProperty(szSection, szKey, szDefaultValue).utf8();
|
||||
strncpy(szResult, s.c_str(), std::min<int>(s.length(),254));
|
||||
#endif
|
||||
return szResult;
|
||||
}
|
||||
|
||||
@@ -429,20 +338,7 @@ UINT32 CIniReader::ReadUINT32(const STR8 szSection, const STR8 szKey, UINT32 def
|
||||
UINT32 CIniReader::ReadUINT(const STR8 szSection, const STR8 szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue )
|
||||
{
|
||||
UINT32 iniValueReadFromFile;
|
||||
#ifndef USE_VFS
|
||||
STR8 szResult = new char[255];
|
||||
STR8 szDefault = new char[255];
|
||||
|
||||
memset(szResult, 0x00, 255);
|
||||
memset(szDefault, 0x00, 255);
|
||||
|
||||
sprintf(szDefault, "%u", defaultValue);
|
||||
|
||||
this->ReadString (szSection , szKey , szDefault, szResult, (size_t) 255 );
|
||||
iniValueReadFromFile = (UINT32) strtoul(szResult,NULL,0);
|
||||
#else
|
||||
iniValueReadFromFile = (UINT32) m_oProps.getUIntProperty(szSection, szKey, defaultValue);
|
||||
#endif
|
||||
//AssertGE(iniValueReadFromFile, minValue);
|
||||
//AssertLE(iniValueReadFromFile, maxValue);
|
||||
|
||||
@@ -457,10 +353,5 @@ UINT32 CIniReader::ReadUINT(const STR8 szSection, const STR8 szKey, UINT32 defau
|
||||
iniValueReadFromFile = maxValue;
|
||||
}
|
||||
|
||||
#ifndef USE_VFS
|
||||
delete [] szResult ;
|
||||
delete [] szDefault ;
|
||||
#endif
|
||||
return iniValueReadFromFile;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user