From ba77c128ac87b7e2d80ee0118e23e4a32b14af41 Mon Sep 17 00:00:00 2001 From: zilmar Date: Wed, 13 Jan 2016 05:38:10 +1100 Subject: [PATCH] [Project64] Cleanup IniFileClass.cpp --- Source/Common/IniFileClass.cpp | 216 ++++++++++++++++----------------- Source/Common/IniFileClass.h | 62 +++++----- 2 files changed, 139 insertions(+), 139 deletions(-) diff --git a/Source/Common/IniFileClass.cpp b/Source/Common/IniFileClass.cpp index 2f4cd0a73..d17c9a006 100644 --- a/Source/Common/IniFileClass.cpp +++ b/Source/Common/IniFileClass.cpp @@ -3,14 +3,14 @@ #include CIniFileBase::CIniFileBase(CFileBase & FileObject, LPCTSTR FileName) : - m_lastSectionSearch(0), - m_CurrentSectionFilePos(0), - m_LineFeed("\r\n"), - m_ReadOnly(true), - m_InstantFlush(true), - m_File(FileObject), - m_FileName(FileName), - m_CurrentSectionDirty(false) +m_lastSectionSearch(0), +m_CurrentSectionFilePos(0), +m_LineFeed("\r\n"), +m_ReadOnly(true), +m_InstantFlush(true), +m_File(FileObject), +m_FileName(FileName), +m_CurrentSectionDirty(false) { } @@ -19,36 +19,36 @@ CIniFileBase::~CIniFileBase(void) SaveCurrentSection(); } -void CIniFileBase::fInsertSpaces ( int Pos, int NoOfSpaces ) +void CIniFileBase::fInsertSpaces(int Pos, int NoOfSpaces) { - enum { fIS_MvSize = 0x2000 }; + enum { fIS_MvSize = 0x2000 }; unsigned char Data[fIS_MvSize + 1]; int SizeToRead, result; long end, WritePos; - m_File.Seek(0,CFileBase::end); + m_File.Seek(0, CFileBase::end); end = m_File.GetPosition(); if (NoOfSpaces > 0) { - stdstr_f SpaceBuffer(_T("%*c"),NoOfSpaces,' '); + stdstr_f SpaceBuffer(_T("%*c"), NoOfSpaces, ' '); do { SizeToRead = end - Pos; if (SizeToRead > fIS_MvSize) { SizeToRead = fIS_MvSize; } if (SizeToRead > 0) { - m_File.Seek(SizeToRead * -1,CFileBase::current); + m_File.Seek(SizeToRead * -1, CFileBase::current); WritePos = m_File.GetPosition(); - memset(Data,0,sizeof(Data)); - result = m_File.Read(Data,SizeToRead); - m_File.Seek(WritePos,CFileBase::begin); + memset(Data, 0, sizeof(Data)); + result = m_File.Read(Data, SizeToRead); + m_File.Seek(WritePos, CFileBase::begin); end = WritePos; - m_File.Write(SpaceBuffer.c_str(),(ULONG)SpaceBuffer.length()); - m_File.Write(Data,result); - m_File.Seek(WritePos,CFileBase::begin); + m_File.Write(SpaceBuffer.c_str(), (ULONG)SpaceBuffer.length()); + m_File.Write(Data, result); + m_File.Seek(WritePos, CFileBase::begin); } } while (SizeToRead > 0); } @@ -60,25 +60,25 @@ void CIniFileBase::fInsertSpaces ( int Pos, int NoOfSpaces ) do { SizeToRead = end - ReadPos; if (SizeToRead > fIS_MvSize) { SizeToRead = fIS_MvSize; } - m_File.Seek(ReadPos,CFileBase::begin); - m_File.Read(Data,SizeToRead); - m_File.Seek(WritePos,CFileBase::begin); - m_File.Write(Data,SizeToRead); + m_File.Seek(ReadPos, CFileBase::begin); + m_File.Read(Data, SizeToRead); + m_File.Seek(WritePos, CFileBase::begin); + m_File.Write(Data, SizeToRead); ReadPos += SizeToRead; WritePos += SizeToRead; } while (SizeToRead > 0); - m_File.Seek(WritePos,CFileBase::begin); - stdstr_f SpaceBuffer(_T("%*c"),(NoOfSpaces * -1),' '); - m_File.Write(SpaceBuffer.c_str(),(ULONG)SpaceBuffer.length()); + m_File.Seek(WritePos, CFileBase::begin); + stdstr_f SpaceBuffer(_T("%*c"), (NoOfSpaces * -1), ' '); + m_File.Write(SpaceBuffer.c_str(), (ULONG)SpaceBuffer.length()); - m_File.Seek(WritePos,CFileBase::begin); + m_File.Seek(WritePos, CFileBase::begin); m_File.SetEndOfFile(); - m_File.Seek(0,CFileBase::begin); + m_File.Seek(0, CFileBase::begin); } } -int CIniFileBase::GetStringFromFile ( char * & String, char * &Data, int & MaxDataSize, int & DataSize, int & ReadPos ) +int CIniFileBase::GetStringFromFile(char * & String, char * &Data, int & MaxDataSize, int & DataSize, int & ReadPos) { enum { BufferIncrease = 0x2000 }; if (MaxDataSize == 0) @@ -86,20 +86,20 @@ int CIniFileBase::GetStringFromFile ( char * & String, char * &Data, int & MaxDa ReadPos = 0; MaxDataSize = BufferIncrease; Data = new char[MaxDataSize]; - DataSize = m_File.Read(&Data[DataSize],MaxDataSize); + DataSize = m_File.Read(&Data[DataSize], MaxDataSize); } for (;;) { int count; - for (count = ReadPos; count < DataSize; count ++) + for (count = ReadPos; count < DataSize; count++) { if (Data[count] == '\n') { int len = (count - ReadPos) + 1; String = &Data[ReadPos]; - String[len-1] = 0; + String[len - 1] = 0; ReadPos = count + 1; return len; } @@ -107,9 +107,9 @@ int CIniFileBase::GetStringFromFile ( char * & String, char * &Data, int & MaxDa if (ReadPos != 0) { - if ((DataSize - ReadPos) > 0 ) + if ((DataSize - ReadPos) > 0) { - memmove(Data,&Data[ReadPos],DataSize - ReadPos); + memmove(Data, &Data[ReadPos], DataSize - ReadPos); } DataSize -= ReadPos; ReadPos = 0; @@ -123,20 +123,20 @@ int CIniFileBase::GetStringFromFile ( char * & String, char * &Data, int & MaxDa { return -1; } - memcpy(NewBuffer,Data,DataSize); + memcpy(NewBuffer, Data, DataSize); MaxDataSize = NewMaxDataSize; - delete [] Data; + delete[] Data; Data = NewBuffer; } - int dwRead = m_File.Read(&Data[DataSize],MaxDataSize - DataSize); + int dwRead = m_File.Read(&Data[DataSize], MaxDataSize - DataSize); if (dwRead == 0) { if (DataSize > 0) { int len = DataSize + 1; String = &Data[ReadPos]; - String[len-1] = 0; + String[len - 1] = 0; DataSize = 0; ReadPos = 0; return len; @@ -147,7 +147,7 @@ int CIniFileBase::GetStringFromFile ( char * & String, char * &Data, int & MaxDa } } -void CIniFileBase::SaveCurrentSection ( void ) +void CIniFileBase::SaveCurrentSection(void) { if (!m_CurrentSectionDirty) { @@ -164,21 +164,21 @@ void CIniFileBase::SaveCurrentSection ( void ) if (m_CurrentSectionFilePos == -1) { //Section has not been added yet - m_File.Seek(0,CFileBase::end); + m_File.Seek(0, CFileBase::end); int len = (int)m_CurrentSection.length() + (lineFeedLen * 2) + 5; AUTO_PTR SectionName(new char[len]); if (m_File.GetLength() < (int)strlen(m_LineFeed)) { - sprintf(SectionName.get(),"[%s]%s",m_CurrentSection.c_str(),m_LineFeed); + sprintf(SectionName.get(), "[%s]%s", m_CurrentSection.c_str(), m_LineFeed); } else { - sprintf(SectionName.get(),"%s[%s]%s",m_LineFeed,m_CurrentSection.c_str(),m_LineFeed); + sprintf(SectionName.get(), "%s[%s]%s", m_LineFeed, m_CurrentSection.c_str(), m_LineFeed); } - m_File.Write(SectionName.get(),(int)strlen(SectionName.get())); + m_File.Write(SectionName.get(), (int)strlen(SectionName.get())); m_CurrentSectionFilePos = m_File.GetPosition(); - m_SectionsPos.insert(FILELOC::value_type(m_CurrentSection,m_CurrentSectionFilePos)); + m_SectionsPos.insert(FILELOC::value_type(m_CurrentSection, m_CurrentSectionFilePos)); } else { @@ -196,7 +196,7 @@ void CIniFileBase::SaveCurrentSection ( void ) LineData.reset(new char[newLen]); len = newLen; } - sprintf(LineData.get(),"%s=%s%s",iter->first.c_str(),iter->second.c_str(),m_LineFeed); + sprintf(LineData.get(), "%s=%s%s", iter->first.c_str(), iter->second.c_str(), m_LineFeed); NeededBufferLen += (int)strlen(LineData.get()); } } @@ -211,7 +211,7 @@ void CIniFileBase::SaveCurrentSection ( void ) int StartPos = m_CurrentSectionFilePos; int EndPos = StartPos; do { - result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos); + result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos); if (result <= 1) { continue; } if (strlen(CleanLine(Input)) <= 1 || Input[0] != '[') { @@ -227,11 +227,11 @@ void CIniFileBase::SaveCurrentSection ( void ) } while (result >= 0); currentLen = EndPos - StartPos; - if (Data) { delete [] Data; Data = NULL; } + if (Data) { delete[] Data; Data = NULL; } if (NeededBufferLen != currentLen) { - fInsertSpaces(StartPos,NeededBufferLen - currentLen); + fInsertSpaces(StartPos, NeededBufferLen - currentLen); m_File.Flush(); ClearSectionPosList(StartPos); } @@ -251,16 +251,16 @@ void CIniFileBase::SaveCurrentSection ( void ) LineData.reset(new char[newLen]); len = newLen; } - sprintf(LineData.get(),"%s=%s%s",iter->first.c_str(),iter->second.c_str(),m_LineFeed); - m_File.Write(LineData.get(),(int)strlen(LineData.get())); + sprintf(LineData.get(), "%s=%s%s", iter->first.c_str(), iter->second.c_str(), m_LineFeed); + m_File.Write(LineData.get(), (int)strlen(LineData.get())); } } m_File.Flush(); } -bool CIniFileBase::MoveToSectionNameData ( LPCSTR lpSectionName, bool ChangeCurrentSection ) +bool CIniFileBase::MoveToSectionNameData(LPCSTR lpSectionName, bool ChangeCurrentSection) { - if (strcmp(lpSectionName,m_CurrentSection.c_str()) == 0) + if (strcmp(lpSectionName, m_CurrentSection.c_str()) == 0) { return true; } @@ -282,7 +282,7 @@ bool CIniFileBase::MoveToSectionNameData ( LPCSTR lpSectionName, bool ChangeCurr m_CurrentSection = iter->first; m_CurrentSectionFilePos = iter->second; } - m_File.Seek(iter->second,CFileBase::begin); + m_File.Seek(iter->second, CFileBase::begin); bFoundSection = true; } else @@ -296,7 +296,7 @@ bool CIniFileBase::MoveToSectionNameData ( LPCSTR lpSectionName, bool ChangeCurr pUTF8[2] = 0xbf; do { - result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos); + result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos); if (result <= 1) { continue; } if (strlen(CleanLine(Input)) <= 1) { continue; } @@ -315,9 +315,9 @@ bool CIniFileBase::MoveToSectionNameData ( LPCSTR lpSectionName, bool ChangeCurr CurrentSection[lineEndPos] = 0; CurrentSection += 1; m_lastSectionSearch = (m_File.GetPosition() - DataSize) + ReadPos; - m_SectionsPos.insert(FILELOC::value_type(CurrentSection,m_lastSectionSearch)); + m_SectionsPos.insert(FILELOC::value_type(CurrentSection, m_lastSectionSearch)); - if (_stricmp(lpSectionName,CurrentSection) != 0) + if (_stricmp(lpSectionName, CurrentSection) != 0) { continue; } @@ -329,7 +329,7 @@ bool CIniFileBase::MoveToSectionNameData ( LPCSTR lpSectionName, bool ChangeCurr } else { - m_File.Seek(m_lastSectionSearch,CFileBase::begin); + m_File.Seek(m_lastSectionSearch, CFileBase::begin); } bFoundSection = true; break; @@ -340,44 +340,44 @@ bool CIniFileBase::MoveToSectionNameData ( LPCSTR lpSectionName, bool ChangeCurr { m_CurrentSectionData.clear(); do { - result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos); + result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos); if (result <= 1) { continue; } if (strlen(CleanLine(Input)) <= 1) { continue; } if (Input[0] == '[') { break; } - char * Pos = strchr(Input,'='); + char * Pos = strchr(Input, '='); if (Pos == NULL) { continue; } char * Value = &Pos[1]; - char * Pos1 = Pos-1; + char * Pos1 = Pos - 1; while (((*Pos1 == ' ') || (*Pos1 == '\t')) && (Pos1 > Input)) { Pos1--; } Pos1[1] = 0; - m_CurrentSectionData.insert(KeyValueList::value_type(Input,Value)); + m_CurrentSectionData.insert(KeyValueList::value_type(Input, Value)); } while (result >= 0); } - if (Data) { delete [] Data; Data = NULL; } + if (Data) { delete[] Data; Data = NULL; } return bFoundSection; } -const char * CIniFileBase::CleanLine ( char * const Line ) +const char * CIniFileBase::CleanLine(char * const Line) { char * Pos = Line; //Remove any comment from the line while (Pos != NULL) { - Pos = strchr(Pos,'/'); + Pos = strchr(Pos, '/'); if (Pos != NULL) { if (Pos[1] == '/') { if (Pos > Line) { - char * Pos_1 = Pos-1; + char * Pos_1 = Pos - 1; if (Pos_1[0] != ':') { @@ -399,7 +399,7 @@ const char * CIniFileBase::CleanLine ( char * const Line ) } //strip any spaces or line feeds from the end of the line - for (int count = (int)strlen(&Line[0]) - 1; count >= 0; count --) + for (int count = (int)strlen(&Line[0]) - 1; count >= 0; count--) { if (Line[count] != ' ' && Line[count] != '\r') { break; } Line[count] = 0; @@ -409,10 +409,10 @@ const char * CIniFileBase::CleanLine ( char * const Line ) void CIniFileBase::OpenIniFileReadOnly() { - if (m_File.Open(m_FileName.c_str(),CFileBase::modeRead)) + if (m_File.Open(m_FileName.c_str(), CFileBase::modeRead)) { m_ReadOnly = true; - m_File.Seek(0,CFileBase::begin); + m_File.Seek(0, CFileBase::begin); } } @@ -420,13 +420,13 @@ void CIniFileBase::OpenIniFile(bool bCreate) { //Open for reading/Writing m_ReadOnly = false; - if (!m_File.Open(m_FileName.c_str(),CFileBase::modeReadWrite | CFileBase::shareDenyWrite)) + if (!m_File.Open(m_FileName.c_str(), CFileBase::modeReadWrite | CFileBase::shareDenyWrite)) { - if (!m_File.Open(m_FileName.c_str(),CFileBase::modeRead)) + if (!m_File.Open(m_FileName.c_str(), CFileBase::modeRead)) { - if(bCreate) + if (bCreate) { - if (!m_File.Open(m_FileName.c_str(),CFileBase::modeReadWrite | CFileBase::modeCreate | CFileBase::shareDenyWrite)) + if (!m_File.Open(m_FileName.c_str(), CFileBase::modeReadWrite | CFileBase::modeCreate | CFileBase::shareDenyWrite)) { return; } @@ -437,7 +437,7 @@ void CIniFileBase::OpenIniFile(bool bCreate) m_ReadOnly = true; } } - m_File.Seek(0,CFileBase::begin); + m_File.Seek(0, CFileBase::begin); } bool CIniFileBase::IsEmpty() @@ -447,14 +447,14 @@ bool CIniFileBase::IsEmpty() return false; } -bool CIniFileBase::IsFileOpen ( void ) +bool CIniFileBase::IsFileOpen(void) { return m_File.IsOpen(); } -bool CIniFileBase::DeleteSection ( LPCTSTR lpSectionName ) +bool CIniFileBase::DeleteSection(LPCTSTR lpSectionName) { - stdstr_f strSection("[%s]",lpSectionName); + stdstr_f strSection("[%s]", lpSectionName); /*if(m_File.IsOpen()) { @@ -516,7 +516,7 @@ bool CIniFileBase::DeleteSection ( LPCTSTR lpSectionName ) return true; } -bool CIniFileBase::GetString ( LPCSTR lpSectionName, LPCSTR lpKeyName, LPCSTR lpDefault, stdstr & Value ) +bool CIniFileBase::GetString(LPCSTR lpSectionName, LPCSTR lpKeyName, LPCSTR lpDefault, stdstr & Value) { CGuard Guard(m_CS); @@ -525,7 +525,7 @@ bool CIniFileBase::GetString ( LPCSTR lpSectionName, LPCSTR lpKeyName, LPCSTR lp lpSectionName = "default"; } - if (m_File.IsOpen() && MoveToSectionNameData(lpSectionName,true)) + if (m_File.IsOpen() && MoveToSectionNameData(lpSectionName, true)) { KeyValueList::iterator iter = m_CurrentSectionData.find(lpKeyName); if (iter != m_CurrentSectionData.end()) @@ -538,10 +538,10 @@ bool CIniFileBase::GetString ( LPCSTR lpSectionName, LPCSTR lpKeyName, LPCSTR lp return false; } -stdstr CIniFileBase::GetString ( LPCSTR lpSectionName, LPCSTR lpKeyName, LPCSTR lpDefault ) +stdstr CIniFileBase::GetString(LPCSTR lpSectionName, LPCSTR lpKeyName, LPCSTR lpDefault) { stdstr Value; - GetString(lpSectionName,lpKeyName,lpDefault,Value); + GetString(lpSectionName, lpKeyName, lpDefault, Value); return Value; } @@ -583,7 +583,7 @@ stdstr CIniFileBase::GetString ( LPCWSTR lpSectionName, LPCWSTR lpKeyName, LPCW #endif -uint32_t CIniFileBase::GetString ( LPCTSTR lpSectionName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, uint32_t nSize ) +uint32_t CIniFileBase::GetString(LPCTSTR lpSectionName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, uint32_t nSize) { CGuard Guard(m_CS); @@ -598,17 +598,17 @@ uint32_t CIniFileBase::GetString ( LPCTSTR lpSectionName, LPCTSTR lpKeyName, LP strSection = lpSectionName; } - if (m_File.IsOpen() && MoveToSectionNameData(strSection.c_str(),true)) + if (m_File.IsOpen() && MoveToSectionNameData(strSection.c_str(), true)) { KeyValueList::iterator iter = m_CurrentSectionData.find(lpKeyName); if (iter != m_CurrentSectionData.end()) { - _tcsncpy(lpReturnedString,iter->second.c_str(),nSize - 1); + _tcsncpy(lpReturnedString, iter->second.c_str(), nSize - 1); lpReturnedString[nSize - 1] = 0; return (ULONG)_tcslen(lpReturnedString); } } - _tcsncpy(lpReturnedString,lpDefault,nSize - 1); + _tcsncpy(lpReturnedString, lpDefault, nSize - 1); lpReturnedString[nSize - 1] = 0; return (ULONG)_tcslen(lpReturnedString); } @@ -637,14 +637,14 @@ bool CIniFileBase::GetNumber ( LPCWSTR lpSectionName, LPCWSTR lpKeyName, ULONG n } #endif -uint32_t CIniFileBase::GetNumber ( LPCSTR lpSectionName, LPCSTR lpKeyName, uint32_t nDefault ) +uint32_t CIniFileBase::GetNumber(LPCSTR lpSectionName, LPCSTR lpKeyName, uint32_t nDefault) { uint32_t Value; - GetNumber(lpSectionName,lpKeyName,nDefault,Value); + GetNumber(lpSectionName, lpKeyName, nDefault, Value); return Value; } -bool CIniFileBase::GetNumber ( LPCSTR lpSectionName, LPCSTR lpKeyName, uint32_t nDefault, uint32_t & Value ) +bool CIniFileBase::GetNumber(LPCSTR lpSectionName, LPCSTR lpKeyName, uint32_t nDefault, uint32_t & Value) { CGuard Guard(m_CS); @@ -653,7 +653,7 @@ bool CIniFileBase::GetNumber ( LPCSTR lpSectionName, LPCSTR lpKeyName, uint32_t lpSectionName = "default"; } - if (m_File.IsOpen() && MoveToSectionNameData(lpSectionName,true)) + if (m_File.IsOpen() && MoveToSectionNameData(lpSectionName, true)) { KeyValueList::iterator iter = m_CurrentSectionData.find(lpKeyName); if (iter != m_CurrentSectionData.end()) @@ -667,7 +667,7 @@ bool CIniFileBase::GetNumber ( LPCSTR lpSectionName, LPCSTR lpKeyName, uint32_t return false; } -void CIniFileBase::SaveString ( LPCTSTR lpSectionName, LPCTSTR lpKeyName, LPCTSTR lpString ) +void CIniFileBase::SaveString(LPCTSTR lpSectionName, LPCTSTR lpKeyName, LPCTSTR lpString) { CGuard Guard(m_CS); if (!m_File.IsOpen()) @@ -692,7 +692,7 @@ void CIniFileBase::SaveString ( LPCTSTR lpSectionName, LPCTSTR lpKeyName, LPCTS strSection = lpSectionName; } - if (!MoveToSectionNameData(strSection.c_str(),true)) + if (!MoveToSectionNameData(strSection.c_str(), true)) { m_CurrentSection = strSection; m_CurrentSectionData.clear(); @@ -720,7 +720,7 @@ void CIniFileBase::SaveString ( LPCTSTR lpSectionName, LPCTSTR lpKeyName, LPCTS { if (lpString) { - m_CurrentSectionData.insert(KeyValueList::value_type(lpKeyName,lpString)); + m_CurrentSectionData.insert(KeyValueList::value_type(lpKeyName, lpString)); m_CurrentSectionDirty = true; } } @@ -731,19 +731,19 @@ void CIniFileBase::SaveString ( LPCTSTR lpSectionName, LPCTSTR lpKeyName, LPCTS } } -void CIniFileBase::SaveNumber ( LPCTSTR lpSectionName, LPCTSTR lpKeyName, uint32_t Value ) +void CIniFileBase::SaveNumber(LPCTSTR lpSectionName, LPCTSTR lpKeyName, uint32_t Value) { //translate the string to an ascii version and save as text - SaveString(lpSectionName,lpKeyName,stdstr_f(_T("%d"),Value).c_str()); + SaveString(lpSectionName, lpKeyName, stdstr_f(_T("%d"), Value).c_str()); } -void CIniFileBase::FlushChanges (void) +void CIniFileBase::FlushChanges(void) { CGuard Guard(m_CS); SaveCurrentSection(); } -void CIniFileBase::SetAutoFlush (bool AutoFlush) +void CIniFileBase::SetAutoFlush(bool AutoFlush) { m_InstantFlush = AutoFlush; if (AutoFlush) @@ -752,7 +752,7 @@ void CIniFileBase::SetAutoFlush (bool AutoFlush) } } -void CIniFileBase::GetKeyList ( LPCTSTR lpSectionName, strlist &List ) +void CIniFileBase::GetKeyList(LPCTSTR lpSectionName, strlist &List) { List.clear(); @@ -767,7 +767,7 @@ void CIniFileBase::GetKeyList ( LPCTSTR lpSectionName, strlist &List ) lpSectionName = "default"; } - if (MoveToSectionNameData(lpSectionName,true)) + if (MoveToSectionNameData(lpSectionName, true)) { for (KeyValueList::iterator iter = m_CurrentSectionData.begin(); iter != m_CurrentSectionData.end(); iter++) { @@ -776,7 +776,7 @@ void CIniFileBase::GetKeyList ( LPCTSTR lpSectionName, strlist &List ) } } -void CIniFileBase::GetKeyValueData ( LPCTSTR lpSectionName, KeyValueData & List ) +void CIniFileBase::GetKeyValueData(LPCTSTR lpSectionName, KeyValueData & List) { CGuard Guard(m_CS); if (!m_File.IsOpen()) @@ -795,25 +795,25 @@ void CIniFileBase::GetKeyValueData ( LPCTSTR lpSectionName, KeyValueData & List strSection = lpSectionName; } - if (!MoveToSectionNameData(strSection.c_str(),false)) { return; } + if (!MoveToSectionNameData(strSection.c_str(), false)) { return; } int MaxDataSize = 0, DataSize = 0, ReadPos = 0, result; char *Input = NULL, *Data = NULL; do { - result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos); + result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos); if (result <= 1) { continue; } if (strlen(CleanLine(Input)) <= 1) { continue; } if (Input[0] == '[') { break; } - char * Pos = strchr(Input,'='); + char * Pos = strchr(Input, '='); if (Pos == NULL) { continue; } Pos[0] = 0; - List.insert(KeyValueData::value_type(Input,&Pos[1])); + List.insert(KeyValueData::value_type(Input, &Pos[1])); } while (result >= 0); - if (Data) { delete [] Data; Data = NULL; } + if (Data) { delete[] Data; Data = NULL; } } -void CIniFileBase::ClearSectionPosList( long FilePos ) +void CIniFileBase::ClearSectionPosList(long FilePos) { if (FilePos <= 0) { @@ -826,7 +826,7 @@ void CIniFileBase::ClearSectionPosList( long FilePos ) while (iter != m_SectionsPos.end()) { FILELOC::iterator CurrentIter = iter; - iter ++; + iter++; long TestFilePos = CurrentIter->second; if (TestFilePos > FilePos) { @@ -837,7 +837,7 @@ void CIniFileBase::ClearSectionPosList( long FilePos ) } } -void CIniFileBase::GetVectorOfSections( SectionList & sections) +void CIniFileBase::GetVectorOfSections(SectionList & sections) { sections.clear(); @@ -848,8 +848,8 @@ void CIniFileBase::GetVectorOfSections( SectionList & sections) } { - stdstr_f DoesNotExist(_T("DoesNotExist%d%d%d"),rand(),rand(),rand()); - MoveToSectionNameData(DoesNotExist.c_str(),false); + stdstr_f DoesNotExist(_T("DoesNotExist%d%d%d"), rand(), rand(), rand()); + MoveToSectionNameData(DoesNotExist.c_str(), false); } for (FILELOC::const_iterator iter = m_SectionsPos.begin(); iter != m_SectionsPos.end(); iter++) diff --git a/Source/Common/IniFileClass.h b/Source/Common/IniFileClass.h index 5dc624536..853311997 100644 --- a/Source/Common/IniFileClass.h +++ b/Source/Common/IniFileClass.h @@ -9,16 +9,16 @@ class CIniFileBase { struct insensitive_compare { - bool operator() (const std::string & a, const std::string & b) const { return _stricmp(a.c_str(),b.c_str()) < 0; } + bool operator() (const std::string & a, const std::string & b) const { return _stricmp(a.c_str(), b.c_str()) < 0; } }; typedef std::string ansi_string; - typedef std::map FILELOC; + typedef std::map FILELOC; typedef FILELOC::iterator FILELOC_ITR; - typedef std::map KeyValueList; + typedef std::map KeyValueList; public: - typedef std::map KeyValueData; + typedef std::map KeyValueData; typedef std::vector SectionList; protected: @@ -43,29 +43,29 @@ private: //void AddItemData ( const char * lpKeyName, const char * lpString); //bool ChangeItemData ( const char * lpKeyName, const char * lpString ); //void DeleteItem ( const char * lpKeyName ); - void fInsertSpaces ( int Pos, int NoOfSpaces ); - int GetStringFromFile ( char * & String, char * &Data, int & MaxDataSize, int & DataSize, int & ReadPos ); - bool MoveToSectionNameData(const char * lpSectionName, bool ChangeCurrentSection); - const char * CleanLine ( char * const Line ); - void ClearSectionPosList( long FilePos ); + void fInsertSpaces(int Pos, int NoOfSpaces); + int GetStringFromFile(char * & String, char * &Data, int & MaxDataSize, int & DataSize, int & ReadPos); + bool MoveToSectionNameData(const char * lpSectionName, bool ChangeCurrentSection); + const char * CleanLine(char * const Line); + void ClearSectionPosList(long FilePos); protected: void OpenIniFileReadOnly(); void OpenIniFile(bool bCreate = true); - void SaveCurrentSection ( void ); + void SaveCurrentSection(void); public: - CIniFileBase(CFileBase & FileObject, const char * FileName); + CIniFileBase(CFileBase & FileObject, const char * FileName); virtual ~CIniFileBase(void); bool IsEmpty(); - bool IsFileOpen ( void ); - bool DeleteSection(const char * lpSectionName); - bool GetString ( const char * lpSectionName, const char * lpKeyName, const char * lpDefault, stdstr & Value ); - stdstr GetString ( const char * lpSectionName, const char * lpKeyName, const char * lpDefault ); - uint32_t GetString ( const char * lpSectionName, const char * lpKeyName, const char * lpDefault, char * lpReturnedString, uint32_t nSize ); - uint32_t GetNumber ( const char * lpSectionName, const char * lpKeyName, uint32_t nDefault ); - bool GetNumber ( const char * lpSectionName, const char * lpKeyName, uint32_t nDefault, uint32_t & Value ); + bool IsFileOpen(void); + bool DeleteSection(const char * lpSectionName); + bool GetString(const char * lpSectionName, const char * lpKeyName, const char * lpDefault, stdstr & Value); + stdstr GetString(const char * lpSectionName, const char * lpKeyName, const char * lpDefault); + uint32_t GetString(const char * lpSectionName, const char * lpKeyName, const char * lpDefault, char * lpReturnedString, uint32_t nSize); + uint32_t GetNumber(const char * lpSectionName, const char * lpKeyName, uint32_t nDefault); + bool GetNumber(const char * lpSectionName, const char * lpKeyName, uint32_t nDefault, uint32_t & Value); #ifdef _UNICODE bool DeleteSection ( LPCWSTR lpSectionName ); @@ -77,15 +77,15 @@ public: #endif - virtual void SaveString ( const char * lpSectionName, const char * lpKeyName, const char * lpString ); - virtual void SaveNumber ( const char * lpSectionName, const char * lpKeyName, uint32_t Value ); - void SetAutoFlush (bool AutoFlush); - void FlushChanges (void); - void GetKeyList ( const char * lpSectionName, strlist &List ); - void GetKeyValueData ( const char * lpSectionName, KeyValueData & List ); + virtual void SaveString(const char * lpSectionName, const char * lpKeyName, const char * lpString); + virtual void SaveNumber(const char * lpSectionName, const char * lpKeyName, uint32_t Value); + void SetAutoFlush(bool AutoFlush); + void FlushChanges(void); + void GetKeyList(const char * lpSectionName, strlist &List); + void GetKeyValueData(const char * lpSectionName, KeyValueData & List); - void GetVectorOfSections( SectionList & sections); - const stdstr &GetFileName() {return m_FileName;} + void GetVectorOfSections(SectionList & sections); + const stdstr &GetFileName() { return m_FileName; } }; template @@ -93,17 +93,17 @@ class CIniFileT : public CIniFileBase { public: - CIniFileT( const char * FileName ) : - CIniFileBase(m_FileObject,FileName) + CIniFileT(const char * FileName) : + CIniFileBase(m_FileObject, FileName) { //Try to open file for reading OpenIniFile(); } - CIniFileT( const char * FileName, bool bCreate, bool bReadOnly) : - CIniFileBase(m_FileObject,FileName) + CIniFileT(const char * FileName, bool bCreate, bool bReadOnly) : + CIniFileBase(m_FileObject, FileName) { - if(bReadOnly) + if (bReadOnly) { OpenIniFileReadOnly(); }