From c0adadd3a561528c2847aa3f0dba05290af177d8 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 23 May 2004 02:27:51 +0000 Subject: [PATCH] IniFile cleanup --- stepmania/src/ActorUtil.cpp | 5 +- stepmania/src/BGAnimation.cpp | 8 +- stepmania/src/BGAnimationLayer.cpp | 4 +- stepmania/src/BannerCache.cpp | 7 +- stepmania/src/Character.cpp | 3 +- stepmania/src/Font.cpp | 3 +- stepmania/src/IniFile.cpp | 163 ++++++++++--------------- stepmania/src/IniFile.h | 116 ++++++++---------- stepmania/src/InputMapper.cpp | 10 +- stepmania/src/Model.cpp | 3 +- stepmania/src/ModelTypes.cpp | 5 +- stepmania/src/NoteFieldPositioning.cpp | 8 +- stepmania/src/NoteSkinManager.cpp | 9 +- stepmania/src/PlayerAI.cpp | 3 +- stepmania/src/PrefsManager.cpp | 6 +- stepmania/src/Profile.cpp | 11 +- stepmania/src/SongCacheIndex.cpp | 7 +- stepmania/src/Sprite.cpp | 3 +- stepmania/src/StepMania.cpp | 16 +-- stepmania/src/ThemeManager.cpp | 34 +++--- stepmania/src/Transition.cpp | 3 +- 21 files changed, 180 insertions(+), 247 deletions(-) diff --git a/stepmania/src/ActorUtil.cpp b/stepmania/src/ActorUtil.cpp index 901022552f..154dda5bd6 100644 --- a/stepmania/src/ActorUtil.cpp +++ b/stepmania/src/ActorUtil.cpp @@ -34,9 +34,8 @@ Actor* LoadFromActorFile( CString sIniPath, CString sLayer ) { // TODO: Check for recursive loading IniFile ini; - ini.SetPath( sIniPath ); - if( !ini.ReadFile() ) - RageException::Throw( "%s", ini.error.c_str() ); + if( !ini.ReadFile( sIniPath ) ) + RageException::Throw( "%s", ini.GetError().c_str() ); if( !ini.GetKey(sLayer) ) RageException::Throw( "The file '%s' doesn't have layer '%s'.", sIniPath.c_str(), sLayer.c_str() ); diff --git a/stepmania/src/BGAnimation.cpp b/stepmania/src/BGAnimation.cpp index 2a538585d1..f2d111a46b 100644 --- a/stepmania/src/BGAnimation.cpp +++ b/stepmania/src/BGAnimation.cpp @@ -64,8 +64,8 @@ void AddLayersFromAniDir( CString sAniDir, vector &layersAddTo, bool Gen CString sPathToIni = sAniDir + "BGAnimation.ini"; - IniFile ini(sPathToIni); - ini.ReadFile(); + IniFile ini; + ini.ReadFile( sPathToIni ); { CString expr; @@ -129,8 +129,8 @@ void BGAnimation::LoadFromAniDir( CString sAniDir ) // This is a new style BGAnimation (using .ini) AddLayersFromAniDir( sAniDir, m_SubActors, m_bGeneric ); // TODO: Check for circular load - IniFile ini(sPathToIni); - ini.ReadFile(); + IniFile ini; + ini.ReadFile( sPathToIni ); if( !ini.GetValue( "BGAnimation", "LengthSeconds", m_fLengthSeconds ) ) { /* XXX: if m_bGeneric, simply constructing the BG layer won't run "On", diff --git a/stepmania/src/BGAnimationLayer.cpp b/stepmania/src/BGAnimationLayer.cpp index 0254251d58..f7753d0de0 100644 --- a/stepmania/src/BGAnimationLayer.cpp +++ b/stepmania/src/BGAnimationLayer.cpp @@ -440,8 +440,8 @@ void BGAnimationLayer::LoadFromIni( CString sAniDir, CString sLayer ) CString sPathToIni = sAniDir + "BGAnimation.ini"; - IniFile ini(sPathToIni); - ini.ReadFile(); + IniFile ini; + ini.ReadFile( sPathToIni ); { // // Can we ditch this? It's the same as "Condition=IsPlayerEnabled(p)". -Chris diff --git a/stepmania/src/BannerCache.cpp b/stepmania/src/BannerCache.cpp index c6957bfee2..f7b62f8de8 100644 --- a/stepmania/src/BannerCache.cpp +++ b/stepmania/src/BannerCache.cpp @@ -25,6 +25,8 @@ #include "Banner.h" #define CACHE_DIR "Cache/" +#define BANNER_CACHE_INDEX CACHE_DIR "banners.cache" + /* Call CacheBanner to cache a banner by path. If the banner is already * cached, it'll be recreated. This is efficient if the banner hasn't changed, @@ -119,8 +121,7 @@ void BannerCache::UnloadAllBanners() BannerCache::BannerCache() { - BannerData.SetPath( CACHE_DIR "banners.cache" ); - BannerData.ReadFile(); // don't care if this fails + BannerData.ReadFile( BANNER_CACHE_INDEX ); // don't care if this fails } BannerCache::~BannerCache() @@ -416,7 +417,7 @@ void BannerCache::CacheBannerInternal( CString BannerPath ) BannerData.SetValue( BannerPath, "FullHash", GetHashForFile( BannerPath ) ); /* Remember this, so we can hint Sprite. */ BannerData.SetValue( BannerPath, "Rotated", WasRotatedBanner ); - BannerData.WriteFile(); + BannerData.WriteFile( BANNER_CACHE_INDEX ); } /* diff --git a/stepmania/src/Character.cpp b/stepmania/src/Character.cpp index 4c78ff2548..56482771a2 100644 --- a/stepmania/src/Character.cpp +++ b/stepmania/src/Character.cpp @@ -30,8 +30,7 @@ bool Character::Load( CString sCharDir ) // Save attacks IniFile ini; - ini.SetPath( sCharDir+"character.ini" ); - if( !ini.ReadFile() ) + if( !ini.ReadFile( sCharDir+"character.ini" ) ) return false; for( int i=0; iTrace( "Reading '%s' failed: %s", path.c_str(), f.GetError().c_str() ); - error = f.GetError(); + LOG->Trace( "Reading '%s' failed: %s", m_sPath.c_str(), f.GetError().c_str() ); + m_sError = f.GetError(); return 0; } @@ -52,13 +24,13 @@ bool IniFile::ReadFile() switch( f.GetLine(line) ) { case -1: - error = f.GetError(); + m_sError = f.GetError(); return false; case 0: return true; /* eof */ } - if(line.size() >= 3 && + if( line.size() >= 3 && line[0] == '\xef' && line[1] == '\xbb' && line[2] == '\xbf' @@ -68,14 +40,15 @@ bool IniFile::ReadFile() line.erase(0, 3); } - if (line == "") + if( line == "" ) continue; - if (line.substr(0, 2) == "//" || line.substr(0) == "#") + if( line.substr(0, 2) == "//" || line.substr(0) == "#" ) continue; /* comment */ - if (line[0] == '[' && line[line.GetLength()-1] == ']') //if a section heading + if( line[0] == '[' && line[line.GetLength()-1] == ']' ) { + /* New section. */ keyname = line.substr(1, line.size()-2); } else //if a value @@ -91,25 +64,24 @@ bool IniFile::ReadFile() } } -// writes data stored in class to ini file -bool IniFile::WriteFile() +bool IniFile::WriteFile( const CString &sPath ) { RageFile f; - if( !f.Open( path, RageFile::WRITE ) ) + if( !f.Open( sPath, RageFile::WRITE ) ) { - LOG->Trace( "Writing '%s' failed: %s", path.c_str(), f.GetError().c_str() ); - error = f.GetError(); + 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) + for( keymap::const_iterator k = keys.begin(); k != keys.end(); ++k ) { if (k->second.empty()) continue; f.PutLine( ssprintf("[%s]", k->first.c_str()) ); - for (key::const_iterator i = k->second.begin(); i != k->second.end(); ++i) + 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()) ); f.PutLine( "" ); @@ -117,51 +89,40 @@ bool IniFile::WriteFile() return true; } -// deletes all stored ini data void IniFile::Reset() { keys.clear(); } -// returns number of keys currently in the ini int IniFile::GetNumKeys() const { return keys.size(); } -// returns number of values stored for specified key, or -1 if key not found -int IniFile::GetNumValues(const CString &keyname) const +int IniFile::GetNumValues( const CString &keyname ) const { keymap::const_iterator k = keys.find(keyname); - if (k == keys.end()) + if( k == keys.end() ) return -1; return k->second.size(); } -// gets value of [keyname] valuename = -bool IniFile::GetValue(const CString &keyname, const CString &valuename, CString& value) const +bool IniFile::GetValue( const CString &keyname, const CString &valuename, CString& value ) const { keymap::const_iterator k = keys.find(keyname); if (k == keys.end()) - { - error = "Unable to locate specified key."; return false; - } key::const_iterator i = k->second.find(valuename); - if (i == k->second.end()) - { - error = "Unable to locate specified value."; + if( i == k->second.end() ) return false; - } value = i->second; return true; } -// gets value of [keyname] valuename = bool IniFile::GetValue(const CString &keyname, const CString &valuename, int& value) const { CString sValue; @@ -180,7 +141,6 @@ bool IniFile::GetValue(const CString &keyname, const CString &valuename, unsigne return true; } -// gets value of [keyname] valuename = bool IniFile::GetValue(const CString &keyname, const CString &valuename, float& value) const { CString sValue; @@ -190,8 +150,7 @@ bool IniFile::GetValue(const CString &keyname, const CString &valuename, float& return true; } -// gets value of [keyname] valuename = -bool IniFile::GetValue(const CString &keyname, const CString &valuename, bool& value) const +bool IniFile::GetValue( const CString &keyname, const CString &valuename, bool& value ) const { CString sValue; if( !GetValue(keyname,valuename,sValue) ) @@ -200,67 +159,50 @@ bool IniFile::GetValue(const CString &keyname, const CString &valuename, bool& v return true; } -// sets value of [keyname] valuename =. -// specify the optional paramter as false (0) if you do not want it to create -// the key if it doesn't exist. Returns true if data entered, false otherwise -bool IniFile::SetValue(const CString &keyname, const CString &valuename, const CString &value, bool create) +bool IniFile::SetValue( const CString &keyname, const CString &valuename, const CString &value ) { - if (!create && keys.find(keyname) == keys.end()) //if key doesn't exist - return false; // stop entering this key - - // find value - if (!create && keys[keyname].find(valuename) == keys[keyname].end()) - return false; - keys[keyname][valuename] = value; return true; } -// sets value of [keyname] valuename =. -// specify the optional paramter as false (0) if you do not want it to create -// the key if it doesn't exist. Returns true if data entered, false otherwise -bool IniFile::SetValue(const CString &keyname, const CString &valuename, int value, bool create) +bool IniFile::SetValue( const CString &keyname, const CString &valuename, int value ) { - return SetValue(keyname, valuename, ssprintf("%d",value), create); + return SetValue( keyname, valuename, ssprintf("%d",value) ); } -bool IniFile::SetValue(const CString &keyname, const CString &valuename, unsigned value, bool create) +bool IniFile::SetValue( const CString &keyname, const CString &valuename, unsigned value ) { - return SetValue(keyname, valuename, ssprintf("%u",value), create); + return SetValue( keyname, valuename, ssprintf("%u",value) ); } -bool IniFile::SetValue(const CString &keyname, const CString &valuename, float value, bool create) +bool IniFile::SetValue( const CString &keyname, const CString &valuename, float value ) { - return SetValue(keyname, valuename, ssprintf("%f",value), create); + return SetValue( keyname, valuename, ssprintf("%f",value) ); } -bool IniFile::SetValue(const CString &keyname, const CString &valuename, bool value, bool create) +bool IniFile::SetValue( const CString &keyname, const CString &valuename, bool value ) { - return SetValue(keyname, valuename, ssprintf("%d",value), create); + return SetValue( keyname, valuename, ssprintf("%d",value) ); } -// deletes specified value -// returns true if value existed and deleted, false otherwise bool IniFile::DeleteValue(const CString &keyname, const CString &valuename) { keymap::iterator k = keys.find(keyname); - if (k == keys.end()) + if( k == keys.end() ) return false; key::iterator i = k->second.find(valuename); - if(i == k->second.end()) + if( i == k->second.end() ) return false; k->second.erase(i); return true; } -// deletes specified key and all values contained within -// returns true if key existed and deleted, false otherwise bool IniFile::DeleteKey(const CString &keyname) { keymap::iterator k = keys.find(keyname); - if (k == keys.end()) + if( k == keys.end() ) return false; keys.erase(k); @@ -270,22 +212,49 @@ bool IniFile::DeleteKey(const CString &keyname) const IniFile::key *IniFile::GetKey(const CString &keyname) const { keymap::const_iterator i = keys.find(keyname); - if(i == keys.end()) return NULL; + if( i == keys.end() ) + return NULL; return &i->second; } void IniFile::SetValue(const CString &keyname, const key &key) { - keys[keyname]=key; + keys[keyname] = key; } void IniFile::RenameKey(const CString &from, const CString &to) { - if(keys.find(from) == keys.end()) + if( keys.find(from) == keys.end() ) return; - if(keys.find(to) != keys.end()) + if( keys.find(to) != keys.end() ) return; keys[to] = keys[from]; keys.erase(from); } + +/* + * (c) 2001-2004 Adam Clauss, Chris Danford + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ diff --git a/stepmania/src/IniFile.h b/stepmania/src/IniFile.h index 7b9649c3d2..bce3e353c5 100644 --- a/stepmania/src/IniFile.h +++ b/stepmania/src/IniFile.h @@ -1,16 +1,7 @@ +/* IniFile - Reading and writing .INI files. */ + #ifndef INIFILE_H #define INIFILE_H -/* ------------------------------------------------------------------------------ - Class: IniFile - - Desc: Wrapper for reading and writing an .ini file. - - Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. - Adam Clauss - Chris Danford ------------------------------------------------------------------------------ -*/ #include using namespace std; @@ -28,77 +19,72 @@ public: const_iterator end() const { return keys.end(); } private: - //stores pathname of ini file to read/write - CString path; + CString m_sPath; - // keys in ini keymap keys; + mutable CString m_sError; public: + /* Retrieve the filename of the last file loaded. */ + CString GetPath() const { return m_sPath; } + const CString &GetError() const { return m_sError; } - //will contain error info if one occurs - //ended up not using much, just in ReadFile and GetValue - mutable CString error; - - //constructor, can specify pathname here instead of using SetPath later - IniFile(CString inipath = ""); - - //default destructor - virtual ~IniFile(); - - //sets path of ini file to read and write from - void SetPath(CString newpath); - CString GetPath() const { return path; } - - //reads ini file specified using IniFile::SetPath() - //returns true if successful, false otherwise - bool ReadFile(); - - //writes data stored in class to ini file - bool WriteFile(); - - //deletes all stored ini data + bool ReadFile( const CString &sPath ); + bool WriteFile( const CString &sPath ); void Reset(); - //returns number of keys currently in the ini int GetNumKeys() const; + int GetNumValues( const CString &keyname ) const; - //returns number of values stored for specified key - int GetNumValues(const CString &keyname) const; + bool GetValue( const CString &key, const CString &valuename, CString& value ) const; + bool GetValue( const CString &key, const CString &valuename, int& value ) const; + bool GetValue( const CString &key, const CString &valuename, unsigned& value ) const; + bool GetValue( const CString &key, const CString &valuename, float& value ) const; + bool GetValue( const CString &key, const CString &valuename, bool& value ) const; - //gets value of [keyname] valuename = - //returns "", or 0 if key/value not found. Sets error member to show problem - bool GetValue(const CString &key, const CString &valuename, CString& value) const; - bool GetValue(const CString &key, const CString &valuename, int& value) const; - bool GetValue(const CString &key, const CString &valuename, unsigned& value) const; - bool GetValue(const CString &key, const CString &valuename, float& value) const; - bool GetValue(const CString &key, const CString &valuename, bool& value) const; + bool SetValue( const CString &key, const CString &valuename, const CString &value ); + bool SetValue( const CString &key, const CString &valuename, int value ); + bool SetValue( const CString &key, const CString &valuename, unsigned value ); + bool SetValue( const CString &key, const CString &valuename, float value ); + bool SetValue( const CString &key, const CString &valuename, bool value ); - //sets value of [keyname] valuename =. - //specify the optional paramter as false (0) if you do not want it to create - //the key if it doesn't exist. Returns true if data entered, false otherwise - bool SetValue(const CString &key, const CString &valuename, const CString &value, bool create = 1); - bool SetValue(const CString &key, const CString &valuename, int value, bool create = 1); - bool SetValue(const CString &key, const CString &valuename, unsigned value, bool create = 1); - bool SetValue(const CString &key, const CString &valuename, float value, bool create = 1); - bool SetValue(const CString &key, const CString &valuename, bool value, bool create = 1); + bool DeleteKey( const CString &keyname ); + bool DeleteValue( const CString &keyname, const CString &valuename ); - //deletes specified value - //returns true if value existed and deleted, false otherwise - bool DeleteValue(const CString &keyname, const CString &valuename); - - //deletes specified key and all values contained within - //returns true if key existed and deleted, false otherwise - bool DeleteKey(const CString &keyname); - - const key *GetKey(const CString &keyname) const; - void SetValue(const CString &keyname, const key &key); + const key *GetKey( const CString &keyname ) const; + void SetValue( const CString &keyname, const key &key ); /* Rename a key. For example, call RenameKey("foo", "main") after * reading an INI where [foo] is an alias to [main]. If to already * exists, nothing happens. */ - void RenameKey(const CString &from, const CString &to); + void RenameKey( const CString &from, const CString &to ); }; #endif + +/* + * (c) 2001-2004 Adam Clauss, Chris Danford + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ diff --git a/stepmania/src/InputMapper.cpp b/stepmania/src/InputMapper.cpp index d9dbd6968c..8384e22e82 100644 --- a/stepmania/src/InputMapper.cpp +++ b/stepmania/src/InputMapper.cpp @@ -373,9 +373,8 @@ void InputMapper::ReadMappingsFromDisk() ClearAllMappings(); IniFile ini; - ini.SetPath( KEYMAPS_PATH ); - if( !ini.ReadFile() ) - LOG->Trace( "Couldn't open mapping file \"%s\": %s.", KEYMAPS_PATH, ini.error.c_str() ); + if( !ini.ReadFile( KEYMAPS_PATH ) ) + LOG->Trace( "Couldn't open mapping file \"%s\": %s.", KEYMAPS_PATH, ini.GetError().c_str() ); const IniFile::key *Key = ini.GetKey( GAMESTATE->GetCurrentGameDef()->m_szName ); @@ -410,8 +409,7 @@ void InputMapper::ReadMappingsFromDisk() void InputMapper::SaveMappingsToDisk() { IniFile ini; - ini.SetPath( KEYMAPS_PATH ); - ini.ReadFile(); + ini.ReadFile( KEYMAPS_PATH ); // erase the key so that we overwrite everything for this game ini.DeleteKey( GAMESTATE->GetCurrentGameDef()->m_szName ); @@ -432,7 +430,7 @@ void InputMapper::SaveMappingsToDisk() } } - ini.WriteFile(); + ini.WriteFile( KEYMAPS_PATH ); } diff --git a/stepmania/src/Model.cpp b/stepmania/src/Model.cpp index ea632ab8f6..581d23d9d5 100644 --- a/stepmania/src/Model.cpp +++ b/stepmania/src/Model.cpp @@ -79,8 +79,7 @@ void Model::LoadFromModelFile( CString sPath ) Clear(); IniFile ini; - ini.SetPath( sPath ); - ini.ReadFile(); + ini.ReadFile( sPath ); CString sDir = Dirname( sPath ); diff --git a/stepmania/src/ModelTypes.cpp b/stepmania/src/ModelTypes.cpp index 8244762856..d8045183c8 100644 --- a/stepmania/src/ModelTypes.cpp +++ b/stepmania/src/ModelTypes.cpp @@ -36,9 +36,8 @@ void AnimatedTexture::Load( CString sTexOrIniPath ) if( GetExtension(sTexOrIniPath).CompareNoCase("ini")==0 ) { IniFile ini; - ini.SetPath( sTexOrIniPath ); - if( !ini.ReadFile() ) - RageException::Throw( "Error reading %s: %s", sTexOrIniPath.c_str(), ini.error.c_str() ); + if( !ini.ReadFile( sTexOrIniPath ) ) + RageException::Throw( "Error reading %s: %s", sTexOrIniPath.c_str(), ini.GetError().c_str() ); if( !ini.GetKey("AnimatedTexture") ) RageException::Throw( "The animated texture file '%s' doesn't contain a section called 'AnimatedTexture'.", sTexOrIniPath.c_str() ); diff --git a/stepmania/src/NoteFieldPositioning.cpp b/stepmania/src/NoteFieldPositioning.cpp index 30f08d8d1b..fe7f828841 100644 --- a/stepmania/src/NoteFieldPositioning.cpp +++ b/stepmania/src/NoteFieldPositioning.cpp @@ -144,8 +144,8 @@ void NoteFieldMode::Load(IniFile &ini, CString id, int pn) NoteFieldPositioning::NoteFieldPositioning(CString fn) { m_Filename = fn; - IniFile ini(fn); - if(!ini.ReadFile()) + IniFile ini; + if( !ini.ReadFile(fn) ) return; for(IniFile::const_iterator i = ini.begin(); i != ini.end(); ++i) @@ -190,8 +190,8 @@ void NoteFieldPositioning::Load(PlayerNumber pn) /* We have a custom mode. Reload the mode on top of the default style * table settings. */ - IniFile ini(m_Filename); - if(!ini.ReadFile()) + IniFile ini; + if( !ini.ReadFile(m_Filename) ) return; mode.Load(ini, Modes[ModeNum].m_Id, pn); diff --git a/stepmania/src/NoteSkinManager.cpp b/stepmania/src/NoteSkinManager.cpp index 8192da501c..85d9fd3287 100644 --- a/stepmania/src/NoteSkinManager.cpp +++ b/stepmania/src/NoteSkinManager.cpp @@ -78,16 +78,13 @@ void NoteSkinManager::LoadNoteSkinData( CString sNoteSkinName, NoteSkinData& dat data_out.metrics.Reset(); /* Load global NoteSkin defaults */ - data_out.metrics.SetPath( GLOBAL_BASE_NOTESKIN_DIR+"metrics.ini" ); - data_out.metrics.ReadFile(); + data_out.metrics.ReadFile( GLOBAL_BASE_NOTESKIN_DIR+"metrics.ini" ); /* Load game NoteSkin defaults */ - data_out.metrics.SetPath( GetNoteSkinDir(GAME_BASE_NOTESKIN_NAME)+"metrics.ini" ); - data_out.metrics.ReadFile(); + data_out.metrics.ReadFile( GetNoteSkinDir(GAME_BASE_NOTESKIN_NAME)+"metrics.ini" ); /* Read the active NoteSkin */ - data_out.metrics.SetPath( GetNoteSkinDir(sNoteSkinName)+"metrics.ini" ); - data_out.metrics.ReadFile(); + data_out.metrics.ReadFile( GetNoteSkinDir(sNoteSkinName)+"metrics.ini" ); } diff --git a/stepmania/src/PlayerAI.cpp b/stepmania/src/PlayerAI.cpp index 4fa9dcc782..dd6e6a6dbb 100644 --- a/stepmania/src/PlayerAI.cpp +++ b/stepmania/src/PlayerAI.cpp @@ -45,8 +45,7 @@ TapScoreDistribution g_Distributions[NUM_SKILL_LEVELS]; void PlayerAI::InitFromDisk() { IniFile ini; - ini.SetPath( AI_PATH ); - ini.ReadFile(); + ini.ReadFile( AI_PATH ); for( int i=0; iGetCurrentGameDef()->m_szName; IniFile ini; - ini.SetPath( GAMEPREFS_INI_PATH ); - ini.ReadFile(); // it's OK if this fails - - ini.SetPath( STATIC_INI_PATH ); - ini.ReadFile(); // it's OK if this fails, too + ini.ReadFile( GAMEPREFS_INI_PATH ); // it's OK if this fails + ini.ReadFile( STATIC_INI_PATH ); // it's OK if this fails, too CString sAnnouncer = sGameName, sTheme = sGameName, sNoteSkin = sGameName; @@ -770,15 +767,14 @@ void SaveGamePrefsToDisk() CString sGameName = GAMESTATE->GetCurrentGameDef()->m_szName; IniFile ini; - ini.SetPath( GAMEPREFS_INI_PATH ); - ini.ReadFile(); // it's OK if this fails + ini.ReadFile( GAMEPREFS_INI_PATH ); // it's OK if this fails ini.SetValue( sGameName, "Announcer", ANNOUNCER->GetCurAnnouncerName() ); ini.SetValue( sGameName, "Theme", THEME->GetCurThemeName() ); ini.SetValue( sGameName, "DefaultModifiers", PREFSMAN->m_sDefaultModifiers ); ini.SetValue( "Options", "Game", (CString)GAMESTATE->GetCurrentGameDef()->m_szName ); - ini.WriteFile(); + ini.WriteFile( GAMEPREFS_INI_PATH ); } static void OnFirstRun() @@ -1563,12 +1559,12 @@ static void GameLoop() /* If we don't have focus, give up lots of CPU. */ if( !g_bHasFocus ) - SDL_Delay( 10 );// give some time to other processes and threads + usleep( 10000 );// give some time to other processes and threads #if defined(_WINDOWS) /* In Windows, we want to give up some CPU for other threads. Most OS's do * this more intelligently. */ else - SDL_Delay( 1 ); // give some time to other processes and threads + usleep( 1000 ); // give some time to other processes and threads #endif } } diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index 7446f7b016..854009c2f4 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -181,24 +181,15 @@ void ThemeManager::SwitchThemeAndLanguage( CString sThemeName, CString sLanguage // read new metrics. First read base metrics, then read cur theme's metrics, overriding base theme m_pIniCurMetrics->Reset(); m_pIniBaseMetrics->Reset(); - m_pIniBaseMetrics->SetPath( GetMetricsIniPath(FALLBACK_THEME_NAME) ); - m_pIniBaseMetrics->ReadFile(); - m_pIniBaseMetrics->SetPath( GetMetricsIniPath(BASE_THEME_NAME) ); - m_pIniBaseMetrics->ReadFile(); - m_pIniCurMetrics->SetPath( GetMetricsIniPath(m_sCurThemeName) ); - m_pIniCurMetrics->ReadFile(); - m_pIniBaseMetrics->SetPath( GetLanguageIniPath(FALLBACK_THEME_NAME,BASE_LANGUAGE) ); - m_pIniBaseMetrics->ReadFile(); - m_pIniBaseMetrics->SetPath( GetLanguageIniPath(BASE_THEME_NAME,BASE_LANGUAGE) ); - m_pIniBaseMetrics->ReadFile(); - m_pIniCurMetrics->SetPath( GetLanguageIniPath(m_sCurThemeName,BASE_LANGUAGE) ); - m_pIniCurMetrics->ReadFile(); - m_pIniBaseMetrics->SetPath( GetLanguageIniPath(FALLBACK_THEME_NAME,m_sCurLanguage) ); - m_pIniBaseMetrics->ReadFile(); - m_pIniBaseMetrics->SetPath( GetLanguageIniPath(BASE_THEME_NAME,m_sCurLanguage) ); - m_pIniBaseMetrics->ReadFile(); - m_pIniCurMetrics->SetPath( GetLanguageIniPath(m_sCurThemeName,m_sCurLanguage) ); - m_pIniCurMetrics->ReadFile(); + m_pIniBaseMetrics->ReadFile( GetMetricsIniPath(FALLBACK_THEME_NAME) ); + m_pIniBaseMetrics->ReadFile( GetMetricsIniPath(BASE_THEME_NAME) ); + m_pIniCurMetrics->ReadFile( GetMetricsIniPath(m_sCurThemeName) ); + m_pIniBaseMetrics->ReadFile( GetLanguageIniPath(FALLBACK_THEME_NAME,BASE_LANGUAGE) ); + m_pIniBaseMetrics->ReadFile( GetLanguageIniPath(BASE_THEME_NAME,BASE_LANGUAGE) ); + m_pIniCurMetrics->ReadFile( GetLanguageIniPath(m_sCurThemeName,BASE_LANGUAGE) ); + m_pIniBaseMetrics->ReadFile( GetLanguageIniPath(FALLBACK_THEME_NAME,m_sCurLanguage) ); + m_pIniBaseMetrics->ReadFile( GetLanguageIniPath(BASE_THEME_NAME,m_sCurLanguage) ); + m_pIniCurMetrics->ReadFile( GetLanguageIniPath(m_sCurThemeName,m_sCurLanguage) ); CString sMetric; for( i = 0; GetCommandlineArgument( "metric", &sMetric, i ); ++i ) @@ -597,8 +588,15 @@ float ThemeManager::GetMetricF( CString sClassName, CString sValueName ) return (float)atof( GetMetricRaw(sClassName,sValueName) ); } +// #include "LuaHelpers.h" bool ThemeManager::GetMetricB( CString sClassName, CString sValueName ) { +// const CString str = GetMetricRaw( sClassName,sValueName ); +// if( str == "0" ) +// return false; /* optimization */ +// if( str == "1" ) +// return true; /* optimization */ +// return Lua::RunExpression( str ); return atoi( GetMetricRaw(sClassName,sValueName) ) != 0; } diff --git a/stepmania/src/Transition.cpp b/stepmania/src/Transition.cpp index 1e6094ce09..151cba8fdc 100644 --- a/stepmania/src/Transition.cpp +++ b/stepmania/src/Transition.cpp @@ -35,8 +35,7 @@ void Transition::Load( CString sBGAniDir ) // load sound from file specified by ini, or use the first sound in the directory IniFile ini; - ini.SetPath( sBGAniDir+"BGAnimation.ini" ); - ini.ReadFile(); + ini.ReadFile( sBGAniDir+"BGAnimation.ini" ); CString sSoundFileName; if( ini.GetValue("BGAnimation","Sound",sSoundFileName) )