write "metrics.ini.new" that automatically converts absolute screen positions to use the SCREEN_* constants

This commit is contained in:
Chris Danford
2004-11-06 19:47:23 +00:00
parent 222f6d67b0
commit 3594cc345e
3 changed files with 219 additions and 0 deletions
+146
View File
@@ -242,6 +242,152 @@ void IniFile::RenameKey(const CString &from, const CString &to)
keys.erase(from);
}
bool IniFilePreserveOrder::ReadFile( const CString &sPath )
{
m_sPath = sPath;
CHECKPOINT_M( ssprintf("Reading '%s'",m_sPath.c_str()) );
RageFile f;
if( !f.Open( m_sPath ) )
{
LOG->Trace( "Reading '%s' failed: %s", m_sPath.c_str(), f.GetError().c_str() );
m_sError = f.GetError();
return 0;
}
CString keyname;
while( 1 )
{
CString line;
switch( f.GetLine(line) )
{
case -1:
m_sError = f.GetError();
return false;
case 0:
return true; /* eof */
}
if( line.size() >= 3 &&
line[0] == '\xef' &&
line[1] == '\xbb' &&
line[2] == '\xbf'
)
{
/* Obnoxious NT marker for UTF-8. Remove it. */
line.erase(0, 3);
}
if( line == "" )
continue;
if( line.substr(0, 2) == "//" || line.substr(0) == "#" )
continue; /* comment */
if( line[0] == '[' && line[line.GetLength()-1] == ']' )
{
/* New section. */
keyname = line.substr(1, line.size()-2);
}
else //if a value
{
int iEqualIndex = line.Find("=");
if( iEqualIndex != -1 )
{
CString valuename = line.Left(iEqualIndex);
CString value = line.Right(line.GetLength()-valuename.GetLength()-1);
SetValue(keyname,valuename,value);
}
}
}
}
bool IniFilePreserveOrder::WriteFile( const CString &sPath )
{
RageFile f;
if( !f.Open( sPath, RageFile::WRITE ) )
{
LOG->Trace( "Writing '%s' failed: %s", sPath.c_str(), f.GetError().c_str() );
m_sError = f.GetError();
return false;
}
for( keymap::const_iterator k = keys.begin(); k != keys.end(); ++k )
{
if (k->second.empty())
continue;
if( f.PutLine( ssprintf("[%s]", k->first.c_str()) ) == -1 )
{
m_sError = f.GetError();
return false;
}
for( key::const_iterator i = k->second.begin(); i != k->second.end(); ++i )
f.PutLine( ssprintf("%s=%s", i->first.c_str(), i->second.c_str()) );
if( f.PutLine( "" ) == -1 )
{
m_sError = f.GetError();
return false;
}
}
return true;
}
bool IniFilePreserveOrder::SetValue( const CString &keyname, const CString &valuename, const CString &value )
{
int iIndexOfKey = -1;
for( unsigned i=0; i<keys.size(); i++ )
{
if( keys[i].first == keyname )
{
iIndexOfKey = i;
break;
}
}
if( iIndexOfKey == -1 )
{
iIndexOfKey = keys.size();
keys.resize( keys.size()+1 );
keys.back().first = keyname;
}
key &k = keys[iIndexOfKey].second;
int iIndexOfValue = -1;
for( unsigned i=0; i<k.size(); i++ )
{
if( k[i].first == valuename )
{
iIndexOfValue = i;
break;
}
}
if( iIndexOfValue == -1 )
{
iIndexOfValue = k.size();
k.resize( k.size()+1 );
k.back().first = valuename;
}
k[iIndexOfValue].second = value;
return true;
}
/*
* (c) 2001-2004 Adam Clauss, Chris Danford
*