get rid of CStdioFile

This commit is contained in:
Glenn Maynard
2002-10-31 03:54:50 +00:00
parent 31fa2adaa4
commit 7d46004e54
4 changed files with 65 additions and 74 deletions
+42 -51
View File
@@ -12,11 +12,8 @@
*/ */
#include "IniFile.h" #include "IniFile.h"
#include <fstream>
using namespace std;
/////////////////////////////////////////////////////////////////////
// Construction/Destruction
/////////////////////////////////////////////////////////////////////
//constructor, can specify pathname here instead of using SetPath later //constructor, can specify pathname here instead of using SetPath later
IniFile::IniFile(CString inipath) IniFile::IniFile(CString inipath)
@@ -30,33 +27,28 @@ IniFile::~IniFile()
} }
///////////////////////////////////////////////////////////////////// // sets path of ini file to read and write from
// Public Functions
/////////////////////////////////////////////////////////////////////
//sets path of ini file to read and write from
void IniFile::SetPath(CString newpath) void IniFile::SetPath(CString newpath)
{ {
path = newpath; path = newpath;
} }
//reads ini file specified using IniFile::SetPath() // reads ini file specified using IniFile::SetPath()
//returns true if successful, false otherwise // returns true if successful, false otherwise
bool IniFile::ReadFile() bool IniFile::ReadFile()
{ {
CStdioFile file; ifstream file(path);
CFileStatus status;
if (!file.GetStatus(path,status)) if (file.bad())
return 0;
if (!file.Open(path, CFile::modeRead))
{ {
error = "Unable to open ini file."; error = "Unable to open ini file.";
return 0; return 0;
} }
CString keyname, valuename, value; CString keyname, valuename, value;
CString temp; CString temp;
CString line; CString line;
while (file.ReadString(line)) while (getline(file, line))
{ {
if (line == "") if (line == "")
continue; continue;
@@ -78,11 +70,10 @@ bool IniFile::ReadFile()
} }
} }
} }
file.Close();
return 1; return 1;
} }
//writes data stored in class to ini file // writes data stored in class to ini file
void IniFile::WriteFile() void IniFile::WriteFile()
{ {
FILE* fp = fopen( path, "w" ); FILE* fp = fopen( path, "w" );
@@ -101,19 +92,19 @@ void IniFile::WriteFile()
fclose( fp ); fclose( fp );
} }
//deletes all stored ini data // deletes all stored ini data
void IniFile::Reset() void IniFile::Reset()
{ {
keys.clear(); keys.clear();
} }
//returns number of keys currently in the ini // returns number of keys currently in the ini
int IniFile::GetNumKeys() const int IniFile::GetNumKeys() const
{ {
return keys.size(); return keys.size();
} }
//returns number of values stored for specified key, or -1 if key not found // 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); keymap::const_iterator k = keys.find(keyname);
@@ -123,8 +114,8 @@ int IniFile::GetNumValues(const CString &keyname) const
return k->second.size(); return k->second.size();
} }
//gets value of [keyname] valuename = // gets value of [keyname] valuename =
//overloaded to return CString, int, and double // overloaded to return CString, int, and double
bool IniFile::GetValue(const CString &keyname, const CString &valuename, CString& value) bool IniFile::GetValue(const CString &keyname, const CString &valuename, CString& value)
{ {
keymap::const_iterator k = keys.find(keyname); keymap::const_iterator k = keys.find(keyname);
@@ -146,8 +137,8 @@ bool IniFile::GetValue(const CString &keyname, const CString &valuename, CString
return true; return true;
} }
//gets value of [keyname] valuename = // gets value of [keyname] valuename =
//overloaded to return CString, int, and double // overloaded to return CString, int, and double
bool IniFile::GetValueI(const CString &keyname, const CString &valuename, int& value) bool IniFile::GetValueI(const CString &keyname, const CString &valuename, int& value)
{ {
CString sValue; CString sValue;
@@ -158,8 +149,8 @@ bool IniFile::GetValueI(const CString &keyname, const CString &valuename, int& v
return true; return true;
} }
//gets value of [keyname] valuename = // gets value of [keyname] valuename =
//overloaded to return CString, int, and double // overloaded to return CString, int, and double
bool IniFile::GetValueF(const CString &keyname, const CString &valuename, float& value) bool IniFile::GetValueF(const CString &keyname, const CString &valuename, float& value)
{ {
CString sValue; CString sValue;
@@ -170,8 +161,8 @@ bool IniFile::GetValueF(const CString &keyname, const CString &valuename, float&
return true; return true;
} }
//gets value of [keyname] valuename = // gets value of [keyname] valuename =
//overloaded to return CString, int, and double // overloaded to return CString, int, and double
bool IniFile::GetValueB(const CString &keyname, const CString &valuename, bool& value) bool IniFile::GetValueB(const CString &keyname, const CString &valuename, bool& value)
{ {
CString sValue; CString sValue;
@@ -182,10 +173,10 @@ bool IniFile::GetValueB(const CString &keyname, const CString &valuename, bool&
return true; return true;
} }
//sets value of [keyname] valuename =. // sets value of [keyname] valuename =.
//specify the optional paramter as false (0) if you do not want it to create // 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 // the key if it doesn't exist. Returns true if data entered, false otherwise
//overloaded to accept CString, int, and double // overloaded to accept CString, int, and double
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, bool create)
{ {
if (!create && keys.find(keyname) == keys.end()) //if key doesn't exist if (!create && keys.find(keyname) == keys.end()) //if key doesn't exist
@@ -199,10 +190,10 @@ bool IniFile::SetValue(const CString &keyname, const CString &valuename, const C
return true; return true;
} }
//sets value of [keyname] valuename =. // sets value of [keyname] valuename =.
//specify the optional paramter as false (0) if you do not want it to create // 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 // the key if it doesn't exist. Returns true if data entered, false otherwise
//overloaded to accept CString, int, and double // overloaded to accept CString, int, and double
bool IniFile::SetValueI(const CString &keyname, const CString &valuename, int value, bool create) bool IniFile::SetValueI(const CString &keyname, const CString &valuename, int value, bool create)
{ {
CString temp; CString temp;
@@ -210,10 +201,10 @@ bool IniFile::SetValueI(const CString &keyname, const CString &valuename, int va
return SetValue(keyname, valuename, temp, create); return SetValue(keyname, valuename, temp, create);
} }
//sets value of [keyname] valuename =. // sets value of [keyname] valuename =.
//specify the optional paramter as false (0) if you do not want it to create // 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 // the key if it doesn't exist. Returns true if data entered, false otherwise
//overloaded to accept CString, int, and double // overloaded to accept CString, int, and double
bool IniFile::SetValueF(const CString &keyname, const CString &valuename, float value, bool create) bool IniFile::SetValueF(const CString &keyname, const CString &valuename, float value, bool create)
{ {
CString temp; CString temp;
@@ -221,10 +212,10 @@ bool IniFile::SetValueF(const CString &keyname, const CString &valuename, float
return SetValue(keyname, valuename, temp, create); return SetValue(keyname, valuename, temp, create);
} }
//sets value of [keyname] valuename =. // sets value of [keyname] valuename =.
//specify the optional paramter as false (0) if you do not want it to create // 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 // the key if it doesn't exist. Returns true if data entered, false otherwise
//overloaded to accept CString, int, and double // overloaded to accept CString, int, and double
bool IniFile::SetValueB(const CString &keyname, const CString &valuename, bool value, bool create) bool IniFile::SetValueB(const CString &keyname, const CString &valuename, bool value, bool create)
{ {
CString temp; CString temp;
@@ -232,8 +223,8 @@ bool IniFile::SetValueB(const CString &keyname, const CString &valuename, bool v
return SetValue(keyname, valuename, temp, create); return SetValue(keyname, valuename, temp, create);
} }
//deletes specified value // deletes specified value
//returns true if value existed and deleted, false otherwise // returns true if value existed and deleted, false otherwise
bool IniFile::DeleteValue(const CString &keyname, const CString &valuename) bool IniFile::DeleteValue(const CString &keyname, const CString &valuename)
{ {
keymap::iterator k = keys.find(keyname); keymap::iterator k = keys.find(keyname);
@@ -248,8 +239,8 @@ bool IniFile::DeleteValue(const CString &keyname, const CString &valuename)
return true; return true;
} }
//deletes specified key and all values contained within // deletes specified key and all values contained within
//returns true if key existed and deleted, false otherwise // returns true if key existed and deleted, false otherwise
bool IniFile::DeleteKey(const CString &keyname) bool IniFile::DeleteKey(const CString &keyname)
{ {
keymap::iterator k = keys.find(keyname); keymap::iterator k = keys.find(keyname);
+13 -15
View File
@@ -8,6 +8,7 @@
#include "RageLog.h" #include "RageLog.h"
#include "GameManager.h" #include "GameManager.h"
#include "RageException.h" #include "RageException.h"
#include <fstream>
// BMS encoding: tap-hold // BMS encoding: tap-hold
// 4&8panel: Player1 Player2 // 4&8panel: Player1 Player2
@@ -67,12 +68,12 @@ bool BMSLoader::LoadFromBMSFile( const CString &sPath, Notes &out )
NoteData* pNoteData = new NoteData; NoteData* pNoteData = new NoteData;
pNoteData->m_iNumTracks = MAX_NOTE_TRACKS; pNoteData->m_iNumTracks = MAX_NOTE_TRACKS;
CStdioFile file; ifstream file(sPath);
if( !file.Open( sPath, CFile::modeRead|CFile::shareDenyNone ) ) if( file.bad() )
throw RageException( "Failed to open %s for reading.", sPath.GetString() ); throw RageException( "Failed to open %s for reading.", sPath.GetString() );
CString line; CString line;
while( file.ReadString(line) ) // foreach line while( getline(file, line) ) // foreach line
{ {
CString value_name; // fill these in CString value_name; // fill these in
CString value_data; CString value_data;
@@ -276,12 +277,12 @@ bool BMSLoader::LoadFromDir( CString sDir, Song &out )
CString sPath = out.m_sSongDir + arrayBMSFileNames[0]; CString sPath = out.m_sSongDir + arrayBMSFileNames[0];
CStdioFile file; ifstream file(sPath);
if( !file.Open( sPath, CFile::modeRead|CFile::shareDenyNone ) ) if( file.bad() )
throw RageException( "Failed to open %s for reading.", sPath.GetString() ); throw RageException( "Failed to open %s for reading.", sPath.GetString() );
CString line; CString line;
while( file.ReadString(line) ) // foreach line while( getline(file, line) ) // foreach line
{ {
CString value_name; // fill these in CString value_name; // fill these in
CString value_data; CString value_data;
@@ -413,12 +414,12 @@ bool BMSLoader::LoadFromDir( CString sDir, Song &out )
// open the song file again and and look for this tag's value // open the song file again and and look for this tag's value
CStdioFile file; ifstream file(sPath);
if( !file.Open( sPath, CFile::modeRead|CFile::shareDenyNone ) ) if( file.bad() )
throw RageException( "Failed to open %s for reading.", sPath.GetString() ); throw RageException( "Failed to open %s for reading.", sPath.GetString() );
CString line; CString line;
while( file.ReadString(line) ) // foreach line while( getline(file, line) ) // foreach line
{ {
CString value_name; // fill these in CString value_name; // fill these in
CString value_data; CString value_data;
@@ -463,7 +464,6 @@ bool BMSLoader::LoadFromDir( CString sDir, Song &out )
LOG->Trace( "Inserting new BPM change at beat %f, BPM %f", newSeg.m_fStartBeat, newSeg.m_fBPM ); LOG->Trace( "Inserting new BPM change at beat %f, BPM %f", newSeg.m_fStartBeat, newSeg.m_fBPM );
} }
file.Close();
break; break;
} }
case 9: { // stop case 9: { // stop
@@ -475,12 +475,12 @@ bool BMSLoader::LoadFromDir( CString sDir, Song &out )
// open the song file again and and look for this tag's value // open the song file again and and look for this tag's value
CStdioFile file; ifstream file(sPath);
if( !file.Open( sPath, CFile::modeRead|CFile::shareDenyNone ) ) if( file.bad() )
throw RageException( "Failed to open %s for reading.", sPath.GetString() ); throw RageException( "Failed to open %s for reading.", sPath.GetString() );
CString line; CString line;
while( file.ReadString(line) ) // foreach line while( getline(file, line) ) // foreach line
{ {
CString value_name; // fill these in CString value_name; // fill these in
CString value_data; CString value_data;
@@ -540,7 +540,6 @@ bool BMSLoader::LoadFromDir( CString sDir, Song &out )
LOG->Trace( "Inserting new Freeze at beat %f, secs %f", newSeg.m_fStartBeat, newSeg.m_fStopSeconds ); LOG->Trace( "Inserting new Freeze at beat %f, secs %f", newSeg.m_fStartBeat, newSeg.m_fStopSeconds );
} }
file.Close();
break; break;
} }
} }
@@ -552,7 +551,6 @@ bool BMSLoader::LoadFromDir( CString sDir, Song &out )
LOG->Trace( "There is a BPM change at beat %f, BPM %f, index %d", LOG->Trace( "There is a BPM change at beat %f, BPM %f, index %d",
out.m_BPMSegments[i].m_fStartBeat, out.m_BPMSegments[i].m_fBPM, i ); out.m_BPMSegments[i].m_fStartBeat, out.m_BPMSegments[i].m_fBPM, i );
file.Close();
return true; return true;
} }
+1 -1
View File
@@ -65,7 +65,7 @@ CString NotesWriterDWI::NotesToDWIString( char cNoteCol1, char cNoteCol2, char c
if( cHold != '0' ) if( cHold != '0' )
return ssprintf( "%c!%c", cShow, cHold ); return ssprintf( "%c!%c", cShow, cHold );
else else
return cShow; return ssprintf( "%c", cShow );
} }
CString NotesWriterDWI::NotesToDWIString( char cNoteCol1, char cNoteCol2, char cNoteCol3, char cNoteCol4 ) CString NotesWriterDWI::NotesToDWIString( char cNoteCol1, char cNoteCol2, char cNoteCol3, char cNoteCol4 )
+9 -7
View File
@@ -20,6 +20,8 @@
#include "IniFile.h" #include "IniFile.h"
#include "RageTimer.h" #include "RageTimer.h"
#include <fstream>
using namespace std;
ThemeManager* THEME = NULL; // global object accessable from anywhere in the program ThemeManager* THEME = NULL; // global object accessable from anywhere in the program
@@ -127,10 +129,9 @@ try_element_again:
GetDirListing( sCurrentThemeDir + sAssetCategory+"\\"+sFileName + "*.redir", asPossibleElementFilePaths, false, true ); GetDirListing( sCurrentThemeDir + sAssetCategory+"\\"+sFileName + "*.redir", asPossibleElementFilePaths, false, true );
if( !asPossibleElementFilePaths.empty() ) if( !asPossibleElementFilePaths.empty() )
{ {
CStdioFile file; ifstream file(asPossibleElementFilePaths[0]);
file.Open( asPossibleElementFilePaths[0], CFile::modeRead );
CString sLine; CString sLine;
file.ReadString( sLine ); getline(file, sLine);
} }
@@ -196,13 +197,14 @@ try_element_again:
CString sDir, sFName, sExt; CString sDir, sFName, sExt;
splitrelpath( sRedirFilePath, sDir, sFName, sExt ); splitrelpath( sRedirFilePath, sDir, sFName, sExt );
CStdioFile file;
file.Open( sRedirFilePath, CFile::modeRead );
CString sNewFileName; CString sNewFileName;
file.ReadString( sNewFileName ); {
ifstream file(sRedirFilePath);
getline(file, sNewFileName );
// CString sNewFilePath = sDir+"\\"+sNewFileName; // This is what it used to be, FONT redirs were getting extra slashes // CString sNewFilePath = sDir+"\\"+sNewFileName; // This is what it used to be, FONT redirs were getting extra slashes
// at the start of their file names, so I took out this extra slash - Andy. // at the start of their file names, so I took out this extra slash - Andy.
file.Close(); }
CString sNewFilePath = sDir+sNewFileName; CString sNewFilePath = sDir+sNewFileName;
if( sNewFileName == "" || !DoesFileExist(sNewFilePath) ) if( sNewFileName == "" || !DoesFileExist(sNewFilePath) )
{ {