Improve error logging in IniFile.cpp

This commit is contained in:
sukibaby
2024-06-08 20:31:31 -07:00
committed by teejusb
parent fcb7989a98
commit 471a92e322
+31 -5
View File
@@ -49,6 +49,7 @@ bool IniFile::ReadFile( RageFileBasic &f )
{ {
case -1: case -1:
m_sError = f.GetError(); m_sError = f.GetError();
LOG->Warn("Error reading line in file '%s': %s", m_sPath.c_str(), m_sError.c_str());
return false; return false;
case 0: case 0:
return true; // eof return true; // eof
@@ -107,6 +108,11 @@ bool IniFile::ReadFile( RageFileBasic &f )
SetKeyValue(keychild, valuename, value); SetKeyValue(keychild, valuename, value);
} }
} }
else
{
LOG->Warn("No '=' found in line of file '%s': %s", m_sPath.c_str(), line.c_str());
}
break; break;
} }
} }
@@ -135,6 +141,7 @@ bool IniFile::WriteFile( RageFileBasic &f ) const
if( f.PutLine( ssprintf("[%s]", pKey->GetName().c_str()) ) == -1 ) if( f.PutLine( ssprintf("[%s]", pKey->GetName().c_str()) ) == -1 )
{ {
m_sError = f.GetError(); m_sError = f.GetError();
LOG->Warn( "Error when writing key to file '%s': %s", m_sPath.c_str(), m_sError.c_str() );
return false; return false;
} }
@@ -151,6 +158,7 @@ bool IniFile::WriteFile( RageFileBasic &f ) const
if( f.PutLine( ssprintf("%s=%s", sName.c_str(), sValue.c_str()) ) == -1 ) if( f.PutLine( ssprintf("%s=%s", sName.c_str(), sValue.c_str()) ) == -1 )
{ {
m_sError = f.GetError(); m_sError = f.GetError();
LOG->Warn( "Error when writing attribute: %s", m_sError.c_str() );
return false; return false;
} }
} }
@@ -158,6 +166,7 @@ bool IniFile::WriteFile( RageFileBasic &f ) const
if( f.PutLine( "" ) == -1 ) if( f.PutLine( "" ) == -1 )
{ {
m_sError = f.GetError(); m_sError = f.GetError();
LOG->Warn( "Error when writing newline: %s", m_sError.c_str() );
return false; return false;
} }
} }
@@ -167,18 +176,33 @@ bool IniFile::WriteFile( RageFileBasic &f ) const
bool IniFile::DeleteValue(const RString &keyname, const RString &valuename) bool IniFile::DeleteValue(const RString &keyname, const RString &valuename)
{ {
XNode* pNode = GetChild( keyname ); XNode* pNode = GetChild( keyname );
if( pNode == nullptr ) if ( pNode == nullptr )
{
LOG->Warn("Key '%s' not found when attempting to delete a value.", keyname.c_str());
return false; return false;
return pNode->RemoveAttr( valuename ); }
bool result = pNode->RemoveAttr(valuename);
if (!result)
{
LOG->Warn("Value '%s' not found in key '%s'.", valuename.c_str(), keyname.c_str());
}
return result;
} }
bool IniFile::DeleteKey(const RString &keyname) bool IniFile::DeleteKey(const RString &keyname)
{ {
XNode* pNode = GetChild( keyname ); XNode* pNode = GetChild( keyname );
if( pNode == nullptr ) if( pNode == nullptr )
{
LOG->Warn("Key '%s' not found when attempting to delete a key.", keyname.c_str());
return false; return false;
return RemoveChild( pNode ); }
bool result = RemoveChild(pNode);
if (!result)
{
LOG->Warn("Error removing key '%s'.", keyname.c_str());
}
return result;
} }
bool IniFile::RenameKey(const RString &from, const RString &to) bool IniFile::RenameKey(const RString &from, const RString &to)
@@ -189,7 +213,10 @@ bool IniFile::RenameKey(const RString &from, const RString &to)
XNode* pNode = GetChild( from ); XNode* pNode = GetChild( from );
if( pNode == nullptr ) if( pNode == nullptr )
{
LOG->Warn("Key '%s' not found.", from.c_str());
return false; return false;
}
pNode->SetName( to ); pNode->SetName( to );
RenameChildInByName(pNode); RenameChildInByName(pNode);
@@ -197,7 +224,6 @@ bool IniFile::RenameKey(const RString &from, const RString &to)
return true; return true;
} }
/* /*
* (c) 2001-2004 Adam Clauss, Chris Danford * (c) 2001-2004 Adam Clauss, Chris Danford
* All rights reserved. * All rights reserved.