IniFile cleanup
This commit is contained in:
@@ -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() );
|
||||
|
||||
@@ -64,8 +64,8 @@ void AddLayersFromAniDir( CString sAniDir, vector<Actor*> &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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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; i<NUM_ATTACK_LEVELS; i++ )
|
||||
for( int j=0; j<NUM_ATTACKS_PER_LEVEL; j++ )
|
||||
|
||||
@@ -783,8 +783,7 @@ void Font::Load(const CString &sFontOrTextureFilePath, CString sChars)
|
||||
IniFile ini;
|
||||
if( !IniPath.empty() )
|
||||
{
|
||||
ini.SetPath( IniPath );
|
||||
ini.ReadFile();
|
||||
ini.ReadFile( IniPath );
|
||||
ini.RenameKey("Char Widths", "main");
|
||||
ini.GetValue( "main", "CapitalsOnly", CapitalsOnly );
|
||||
}
|
||||
|
||||
+66
-97
@@ -1,47 +1,19 @@
|
||||
#include "global.h"
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Class: IniFile
|
||||
|
||||
Desc: See header.
|
||||
|
||||
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
||||
Adam Clauss
|
||||
Chris Danford
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "IniFile.h"
|
||||
#include "RageUtil.h"
|
||||
#include "RageLog.h"
|
||||
#include "RageFile.h"
|
||||
|
||||
IniFile::IniFile(CString inipath)
|
||||
bool IniFile::ReadFile( const CString &sPath )
|
||||
{
|
||||
path = inipath;
|
||||
}
|
||||
|
||||
IniFile::~IniFile()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void IniFile::SetPath(CString newpath)
|
||||
{
|
||||
path = newpath;
|
||||
}
|
||||
|
||||
// reads ini file specified using IniFile::SetPath()
|
||||
// returns true if successful, false otherwise
|
||||
bool IniFile::ReadFile()
|
||||
{
|
||||
CHECKPOINT_M( ssprintf("Reading '%s'",path.c_str()) );
|
||||
m_sPath = sPath;
|
||||
CHECKPOINT_M( ssprintf("Reading '%s'",m_sPath.c_str()) );
|
||||
|
||||
RageFile f;
|
||||
if( !f.Open( path ) )
|
||||
if( !f.Open( m_sPath ) )
|
||||
{
|
||||
LOG->Trace( "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.
|
||||
*/
|
||||
|
||||
+51
-65
@@ -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 <map>
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -79,8 +79,7 @@ void Model::LoadFromModelFile( CString sPath )
|
||||
Clear();
|
||||
|
||||
IniFile ini;
|
||||
ini.SetPath( sPath );
|
||||
ini.ReadFile();
|
||||
ini.ReadFile( sPath );
|
||||
|
||||
CString sDir = Dirname( sPath );
|
||||
|
||||
|
||||
@@ -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() );
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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; i<NUM_SKILL_LEVELS; i++ )
|
||||
{
|
||||
|
||||
@@ -319,8 +319,7 @@ void PrefsManager::ReadStaticPrefsFromDisk()
|
||||
void PrefsManager::ReadPrefsFromFile( CString sIni )
|
||||
{
|
||||
IniFile ini;
|
||||
ini.SetPath( sIni );
|
||||
ini.ReadFile();
|
||||
ini.ReadFile( sIni );
|
||||
|
||||
ini.GetValue( "Options", "Windowed", m_bWindowed );
|
||||
ini.GetValue( "Options", "Interlaced", m_bInterlaced );
|
||||
@@ -554,7 +553,6 @@ void PrefsManager::ReadPrefsFromFile( CString sIni )
|
||||
void PrefsManager::SaveGlobalPrefsToDisk() const
|
||||
{
|
||||
IniFile ini;
|
||||
ini.SetPath( STEPMANIA_INI_PATH );
|
||||
|
||||
ini.SetValue( "Options", "Windowed", m_bWindowed );
|
||||
ini.SetValue( "Options", "CelShadeDancers", m_bCelShadeDancers );
|
||||
@@ -788,7 +786,7 @@ void PrefsManager::SaveGlobalPrefsToDisk() const
|
||||
ini.SetValue( "Debug", "LogCheckpoints", m_bLogCheckpoints );
|
||||
ini.SetValue( "Debug", "ShowLoadingWindow", m_bShowLoadingWindow );
|
||||
|
||||
ini.WriteFile();
|
||||
ini.WriteFile( STEPMANIA_INI_PATH );
|
||||
}
|
||||
|
||||
void PrefsManager::ResetToFactoryDefaults()
|
||||
|
||||
@@ -731,8 +731,8 @@ void Profile::LoadProfileDataFromDirSM390a12( CString sDir )
|
||||
//
|
||||
// read ini
|
||||
//
|
||||
IniFile ini( fn );
|
||||
if( !ini.ReadFile() )
|
||||
IniFile ini;
|
||||
if( !ini.ReadFile( fn ) )
|
||||
return;
|
||||
|
||||
ini.GetValue( "Profile", "DisplayName", m_sDisplayName );
|
||||
@@ -761,14 +761,12 @@ void Profile::LoadProfileDataFromDirSM390a12( CString sDir )
|
||||
void Profile::SaveEditableDataToDir( CString sDir ) const
|
||||
{
|
||||
IniFile ini;
|
||||
CString fn = sDir + EDITABLE_INI;
|
||||
ini.SetPath( fn );
|
||||
|
||||
ini.SetValue( "Editable", "DisplayName", m_sDisplayName );
|
||||
ini.SetValue( "Editable", "LastUsedHighScoreName", m_sLastUsedHighScoreName );
|
||||
ini.SetValue( "Editable", "WeightPounds", m_iWeightPounds );
|
||||
|
||||
ini.WriteFile();
|
||||
ini.WriteFile( sDir + EDITABLE_INI );
|
||||
}
|
||||
|
||||
XNode* Profile::SaveGeneralDataCreateNode() const
|
||||
@@ -899,8 +897,7 @@ void Profile::LoadEditableDataFromDir( CString sDir )
|
||||
|
||||
|
||||
IniFile ini;
|
||||
ini.SetPath( fn );
|
||||
ini.ReadFile();
|
||||
ini.ReadFile( fn );
|
||||
|
||||
ini.GetValue("Editable","DisplayName", m_sDisplayName);
|
||||
ini.GetValue("Editable","LastUsedHighScoreName", m_sLastUsedHighScoreName);
|
||||
|
||||
@@ -24,12 +24,13 @@
|
||||
* in order to find the cache file.
|
||||
*/
|
||||
#define CACHE_DIR "Cache/"
|
||||
#define CACHE_INDEX CACHE_DIR "index.cache"
|
||||
|
||||
|
||||
SongCacheIndex *SONGINDEX;
|
||||
|
||||
SongCacheIndex::SongCacheIndex()
|
||||
{
|
||||
CacheIndex.SetPath( CACHE_DIR "index.cache" );
|
||||
ReadCacheIndex();
|
||||
}
|
||||
|
||||
@@ -53,7 +54,7 @@ static void EmptyDir( CString dir )
|
||||
|
||||
void SongCacheIndex::ReadCacheIndex()
|
||||
{
|
||||
CacheIndex.ReadFile(); // don't care if this fails
|
||||
CacheIndex.ReadFile( CACHE_INDEX ); // don't care if this fails
|
||||
|
||||
int iCacheVersion = -1;
|
||||
CacheIndex.GetValue( "Cache", "CacheVersion", iCacheVersion );
|
||||
@@ -74,7 +75,7 @@ void SongCacheIndex::AddCacheIndex(const CString &path, unsigned hash)
|
||||
++hash; /* no 0 hash values */
|
||||
CacheIndex.SetValue( "Cache", "CacheVersion", FILE_CACHE_VERSION );
|
||||
CacheIndex.SetValue( "Cache", MangleName(path), hash );
|
||||
CacheIndex.WriteFile();
|
||||
CacheIndex.WriteFile( CACHE_INDEX );
|
||||
}
|
||||
|
||||
unsigned SongCacheIndex::GetCacheHash( const CString &path ) const
|
||||
|
||||
@@ -116,8 +116,7 @@ retry:
|
||||
|
||||
// read sprite file
|
||||
IniFile ini;
|
||||
ini.SetPath( m_sSpritePath );
|
||||
if( !ini.ReadFile() )
|
||||
if( !ini.ReadFile( m_sSpritePath ) )
|
||||
RageException::Throw( "Error opening Sprite file '%s'.", m_sSpritePath.c_str() );
|
||||
|
||||
CString sTextureFile;
|
||||
|
||||
@@ -731,11 +731,8 @@ void ReadGamePrefsFromDisk( bool bSwitchToLastPlayedGame )
|
||||
|
||||
CString sGameName = GAMESTATE->GetCurrentGameDef()->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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) )
|
||||
|
||||
Reference in New Issue
Block a user