Add prefs for logging. Don't throw if can't open log file. Remove Ragefopen and Rageifstream (they aren't needed).

This commit is contained in:
Chris Danford
2003-08-13 04:40:23 +00:00
parent ab000d06b1
commit 35950c4eaf
18 changed files with 76 additions and 57 deletions
+1 -1
View File
@@ -298,7 +298,7 @@ void Course::Save()
{ {
ASSERT( !m_bIsAutogen ); ASSERT( !m_bIsAutogen );
FILE* fp = Ragefopen( m_sPath, "w" ); FILE* fp = fopen( m_sPath, "w" );
if( fp == NULL ) if( fp == NULL )
{ {
LOG->Warn( "Could not write course file '%s'.", m_sPath.c_str() ); LOG->Warn( "Could not write course file '%s'.", m_sPath.c_str() );
+2 -2
View File
@@ -42,7 +42,7 @@ void IniFile::SetPath(CString newpath)
bool IniFile::ReadFile() bool IniFile::ReadFile()
{ {
LOG->Trace("INI: Reading '%s'",path.c_str() ); LOG->Trace("INI: Reading '%s'",path.c_str() );
FILE *f = Ragefopen(path, "r"); FILE *f = fopen(path, "r");
if (f == NULL) if (f == NULL)
{ {
@@ -101,7 +101,7 @@ LOG->Trace("INI: Reading '%s'",path.c_str() );
// writes data stored in class to ini file // writes data stored in class to ini file
void IniFile::WriteFile() void IniFile::WriteFile()
{ {
FILE* fp = Ragefopen( path, "w" ); FILE* fp = fopen( path, "w" );
if( fp == NULL ) if( fp == NULL )
return; return;
+1 -1
View File
@@ -21,7 +21,7 @@ bool LyricsLoader::LoadFromLRCFile( CString sPath, Song &out )
{ {
LOG->Trace( "LyricsLoader::LoadFromLRCFile(%s)", sPath.c_str() ); LOG->Trace( "LyricsLoader::LoadFromLRCFile(%s)", sPath.c_str() );
Rageifstream input(sPath); ifstream input(sPath);
if(input.bad()) if(input.bad())
{ {
LOG->Warn( "Error opening file '%s' for reading.", sPath.c_str() ); LOG->Warn( "Error opening file '%s' for reading.", sPath.c_str() );
+2 -2
View File
@@ -77,7 +77,7 @@ bool Model::LoadMilkshapeAscii( CString sPath )
CString sDir, sThrowAway; CString sDir, sThrowAway;
splitrelpath( sPath, sDir, sThrowAway, sThrowAway ); splitrelpath( sPath, sDir, sThrowAway, sThrowAway );
FILE *file = Ragefopen (sPath, "rt"); FILE *file = fopen (sPath, "rt");
if (!file) if (!file)
RageException::Throw( "Model::LoadMilkshapeAscii Could not open '%s'.", sPath.c_str() ); RageException::Throw( "Model::LoadMilkshapeAscii Could not open '%s'.", sPath.c_str() );
@@ -438,7 +438,7 @@ bool Model::LoadMilkshapeAsciiBones( CString sAniName, CString sPath )
CString sDir, sThrowAway; CString sDir, sThrowAway;
splitrelpath( sPath, sDir, sThrowAway, sThrowAway ); splitrelpath( sPath, sDir, sThrowAway, sThrowAway );
FILE *file = Ragefopen (sPath, "rt"); FILE *file = fopen (sPath, "rt");
if (!file) if (!file)
RageException::Throw( "Model:: Could not open '%s'.", sPath.c_str() ); RageException::Throw( "Model:: Could not open '%s'.", sPath.c_str() );
+4 -4
View File
@@ -67,7 +67,7 @@ bool BMSLoader::LoadFromBMSFile( const CString &sPath, Steps &out )
NoteData* pNoteData = new NoteData; NoteData* pNoteData = new NoteData;
pNoteData->SetNumTracks( MAX_NOTE_TRACKS ); pNoteData->SetNumTracks( MAX_NOTE_TRACKS );
Rageifstream file(sPath); ifstream file(sPath);
if( file.bad() ) if( file.bad() )
RageException::Throw( "Failed to open %s for reading.", sPath.c_str() ); RageException::Throw( "Failed to open %s for reading.", sPath.c_str() );
@@ -284,7 +284,7 @@ bool BMSLoader::LoadFromDir( CString sDir, Song &out )
CString sPath = out.GetSongDir() + arrayBMSFileNames[0]; CString sPath = out.GetSongDir() + arrayBMSFileNames[0];
Rageifstream file(sPath); ifstream file(sPath);
if( file.bad() ) if( file.bad() )
RageException::Throw( "Failed to open %s for reading.", sPath.c_str() ); RageException::Throw( "Failed to open %s for reading.", sPath.c_str() );
@@ -423,7 +423,7 @@ 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
Rageifstream file(sPath); ifstream file(sPath);
if( file.bad() ) if( file.bad() )
RageException::Throw( "Failed to open %s for reading.", sPath.c_str() ); RageException::Throw( "Failed to open %s for reading.", sPath.c_str() );
@@ -485,7 +485,7 @@ 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
Rageifstream file(sPath); ifstream file(sPath);
if( file.bad() ) if( file.bad() )
RageException::Throw( "Failed to open %s for reading.", sPath.c_str() ); RageException::Throw( "Failed to open %s for reading.", sPath.c_str() );
+1 -1
View File
@@ -323,7 +323,7 @@ bool NotesWriterDWI::WriteDWINotesTag( FILE* fp, const Steps &out )
bool NotesWriterDWI::Write( CString sPath, const Song &out ) bool NotesWriterDWI::Write( CString sPath, const Song &out )
{ {
FILE* fp = Ragefopen( sPath, "w" ); FILE* fp = fopen( sPath, "w" );
if( fp == NULL ) if( fp == NULL )
RageException::Throw( "Error opening song file '%s' for writing.", sPath.c_str() ); RageException::Throw( "Error opening song file '%s' for writing.", sPath.c_str() );
+1 -1
View File
@@ -114,7 +114,7 @@ bool NotesWriterSM::Write(CString sPath, const Song &out, bool bSavingCache)
{ {
unsigned i; unsigned i;
FILE* fp = Ragefopen( sPath, "w" ); FILE* fp = fopen( sPath, "w" );
if( fp == NULL ) if( fp == NULL )
{ {
LOG->Warn( "Error opening song file '%s' for writing: %s", sPath.c_str(), strerror(errno) ); LOG->Warn( "Error opening song file '%s' for writing: %s", sPath.c_str(), strerror(errno) );
+13 -4
View File
@@ -100,8 +100,13 @@ PrefsManager::PrefsManager()
m_bFirstRun = true; m_bFirstRun = true;
m_bAutoMapJoysticks = true; m_bAutoMapJoysticks = true;
m_fGlobalOffsetSeconds = 0; m_fGlobalOffsetSeconds = 0;
m_bDebugMode = false; m_bForceLogFlush = false;
m_bLogging = true;
#ifdef DEBUG
m_bShowLogWindow = true;
#else
m_bShowLogWindow = false;
#endif
m_bTenFooterInRed = true; m_bTenFooterInRed = true;
// set to 0 so people aren't shocked at first // set to 0 so people aren't shocked at first
@@ -257,7 +262,9 @@ void PrefsManager::ReadGlobalPrefsFromDisk( bool bSwitchToLastPlayedGame )
#endif #endif
ini.GetValueB( "Options", "AntiAliasing", m_bAntiAliasing ); ini.GetValueB( "Options", "AntiAliasing", m_bAntiAliasing );
ini.GetValueF( "Options", "GlobalOffsetSeconds", m_fGlobalOffsetSeconds ); ini.GetValueF( "Options", "GlobalOffsetSeconds", m_fGlobalOffsetSeconds );
ini.GetValueB( "Options", "DebugMode", m_bDebugMode ); ini.GetValueB( "Options", "ForceLogFlush", m_bForceLogFlush );
ini.GetValueB( "Options", "Logging", m_bLogging );
ini.GetValueB( "Options", "ShowLogWindow", m_bShowLogWindow );
m_asAdditionalSongFolders.clear(); m_asAdditionalSongFolders.clear();
@@ -357,7 +364,9 @@ void PrefsManager::SaveGlobalPrefsToDisk()
#endif #endif
ini.SetValueB( "Options", "AntiAliasing", m_bAntiAliasing ); ini.SetValueB( "Options", "AntiAliasing", m_bAntiAliasing );
ini.SetValueF( "Options", "GlobalOffsetSeconds", m_fGlobalOffsetSeconds ); ini.SetValueF( "Options", "GlobalOffsetSeconds", m_fGlobalOffsetSeconds );
ini.SetValueB( "Options", "DebugMode", m_bDebugMode ); ini.SetValueB( "Options", "ForceLogFlush", m_bForceLogFlush );
ini.SetValueB( "Options", "Logging", m_bLogging );
ini.SetValueB( "Options", "ShowLogWindow", m_bShowLogWindow );
ini.SetValueB( "Options", "TenFooterInRed", m_bTenFooterInRed ); ini.SetValueB( "Options", "TenFooterInRed", m_bTenFooterInRed );
ini.SetValueI( "Options", "CourseSortOrder", m_iCourseSortOrder ); ini.SetValueI( "Options", "CourseSortOrder", m_iCourseSortOrder );
+3 -1
View File
@@ -85,7 +85,9 @@ public:
bool m_bFirstRun; bool m_bFirstRun;
bool m_bAutoMapJoysticks; bool m_bAutoMapJoysticks;
float m_fGlobalOffsetSeconds; float m_fGlobalOffsetSeconds;
bool m_bDebugMode; bool m_bForceLogFlush;
bool m_bLogging;
bool m_bShowLogWindow;
bool m_bTenFooterInRed; bool m_bTenFooterInRed;
int m_iProgressiveLifebar; int m_iProgressiveLifebar;
int m_iProgressiveStageLifebar; int m_iProgressiveStageLifebar;
-5
View File
@@ -44,8 +44,3 @@ void CollapsePath( CString &sPath )
sPath = join( SLASH, as ); sPath = join( SLASH, as );
} }
// replacement for fopen
FILE* Ragefopen( const char *szPath, const char *szMode )
{
return fopen( FixSlashes(szPath), szMode );
}
+1 -12
View File
@@ -15,22 +15,11 @@
#include <fstream> #include <fstream>
using namespace std; // using "std::ifstream" causes problems below in VC6. Why?!? using namespace std; // using "std::ifstream" causes problems below in VC6. Why?!?
// call FixSlashes on any path that came from the user
void FixSlashesInPlace( CString &sPath ); void FixSlashesInPlace( CString &sPath );
CString FixSlashes( CString sPath ); CString FixSlashes( CString sPath );
void CollapsePath( CString &sPath ); void CollapsePath( CString &sPath );
FILE* Ragefopen( const char *szPath, const char *szMode );
// replacement for ifstream
class Rageifstream : public std::ifstream
{
public:
Rageifstream() {};
Rageifstream( Rageifstream &cpy ); /* not defined; hush warning */
Rageifstream( const char *szPath ) : ifstream(FixSlashes(szPath)) {}
void open( const char *szPath ) { ifstream::open(FixSlashes(szPath)); }
};
#endif #endif
+28 -9
View File
@@ -85,18 +85,24 @@ enum {
RageLog::RageLog() RageLog::RageLog()
{ {
m_bEnabled = true;
// delete old log files // delete old log files
remove( LOG_PATH ); remove( LOG_PATH );
remove( INFO_PATH ); remove( INFO_PATH );
// Open log file and leave it open. // Open log file and leave it open.
m_fileLog = Ragefopen( LOG_PATH, "w" ); m_fileLog = fopen( LOG_PATH, "w" );
if( m_fileLog == NULL )
RageException::Throw( " Couldn't open log.txt: %s", strerror(errno) );
m_fileInfo = Ragefopen( INFO_PATH, "w" ); // Failing to open shouldn't be fatal
if( m_fileInfo == NULL ) //if( m_fileLog == NULL )
RageException::Throw( " Couldn't open info.txt: %s", strerror(errno) ); // RageException::Throw( " Couldn't open log.txt: %s", strerror(errno) );
m_fileInfo = fopen( INFO_PATH, "w" );
// Failing to open shouldn't be fatal
//if( m_fileInfo == NULL )
// RageException::Throw( " Couldn't open info.txt: %s", strerror(errno) );
this->Info( PRODUCT_NAME_VER ); this->Info( PRODUCT_NAME_VER );
@@ -119,8 +125,7 @@ RageLog::RageLog()
RageLog::~RageLog() RageLog::~RageLog()
{ {
/* Add the mapped log data to info.txt. */ /* Add the mapped log data to info.txt. */
fprintf( m_fileInfo, "%s", GetAdditionalLog() ); this->Info( "Statics:\n%s", GetAdditionalLog() );
fprintf( m_fileLog, "\nStatics:\n%s", GetAdditionalLog() );
Flush(); Flush();
HideConsole(); HideConsole();
@@ -128,6 +133,11 @@ RageLog::~RageLog()
if(m_fileInfo) fclose( m_fileInfo ); if(m_fileInfo) fclose( m_fileInfo );
} }
void RageLog::SetLogging( bool b )
{
m_bEnabled = b;
}
void RageLog::ShowConsole() void RageLog::ShowConsole()
{ {
#if defined(WIN32) && !defined(_XBOX) #if defined(WIN32) && !defined(_XBOX)
@@ -147,6 +157,9 @@ void RageLog::HideConsole()
void RageLog::Trace( const char *fmt, ...) void RageLog::Trace( const char *fmt, ...)
{ {
if( !m_bEnabled )
return;
va_list va; va_list va;
va_start(va, fmt); va_start(va, fmt);
CString sBuff = vssprintf( fmt, va ); CString sBuff = vssprintf( fmt, va );
@@ -159,6 +172,9 @@ void RageLog::Trace( const char *fmt, ...)
* in crash dumps. */ * in crash dumps. */
void RageLog::Info( const char *fmt, ...) void RageLog::Info( const char *fmt, ...)
{ {
if( !m_bEnabled )
return;
va_list va; va_list va;
va_start(va, fmt); va_start(va, fmt);
CString sBuff = vssprintf( fmt, va ); CString sBuff = vssprintf( fmt, va );
@@ -169,6 +185,9 @@ void RageLog::Info( const char *fmt, ...)
void RageLog::Warn( const char *fmt, ...) void RageLog::Warn( const char *fmt, ...)
{ {
if( !m_bEnabled )
return;
va_list va; va_list va;
va_start(va, fmt); va_start(va, fmt);
CString sBuff = vssprintf( fmt, va ); CString sBuff = vssprintf( fmt, va );
@@ -208,7 +227,7 @@ void RageLog::Write( int where, CString str)
printf("%s\n", str.c_str() ); printf("%s\n", str.c_str() );
if( (PREFSMAN && PREFSMAN->m_bDebugMode) || (where & WRITE_TO_INFO) ) if( (PREFSMAN && PREFSMAN->m_bForceLogFlush) || (where & WRITE_TO_INFO) )
Flush(); Flush();
} }
+3
View File
@@ -36,7 +36,10 @@ public:
/* Returns NULL if past the last recent log. */ /* Returns NULL if past the last recent log. */
static const char *GetRecentLog( int n ); static const char *GetRecentLog( int n );
void SetLogging( bool b ); // enable or disable logging
private: private:
bool m_bEnabled;
FILE *m_fileLog, *m_fileInfo; FILE *m_fileLog, *m_fileInfo;
void Write( int, CString ); void Write( int, CString );
void UpdateMappedLog(); void UpdateMappedLog();
+2 -2
View File
@@ -505,7 +505,7 @@ CString DerefRedir(const CString &path)
CString sNewFileName; CString sNewFileName;
{ {
Rageifstream file(path); ifstream file(path);
getline(file, sNewFileName); getline(file, sNewFileName);
} }
@@ -534,7 +534,7 @@ CString GetRedirContents(const CString &path)
CString sNewFileName; CString sNewFileName;
{ {
Rageifstream file(path); ifstream file(path);
getline(file, sNewFileName); getline(file, sNewFileName);
} }
+2 -2
View File
@@ -605,7 +605,7 @@ struct SurfaceHeader
/* Save and load SDL_Surfaces to disk. This avoids problems with bitmaps. */ /* Save and load SDL_Surfaces to disk. This avoids problems with bitmaps. */
bool mySDL_SaveSurface( SDL_Surface *img, CString file ) bool mySDL_SaveSurface( SDL_Surface *img, CString file )
{ {
FILE *f = Ragefopen(file.c_str(), "wb+"); FILE *f = fopen(file.c_str(), "wb+");
if(f == NULL) if(f == NULL)
return false; return false;
@@ -643,7 +643,7 @@ bool mySDL_SaveSurface( SDL_Surface *img, CString file )
SDL_Surface *mySDL_LoadSurface( CString file ) SDL_Surface *mySDL_LoadSurface( CString file )
{ {
FILE *f = Ragefopen(file.c_str(), "rb"); FILE *f = fopen(file.c_str(), "rb");
if(f == NULL) if(f == NULL)
return NULL; return NULL;
+8 -8
View File
@@ -266,7 +266,7 @@ void SongManager::FreeSongs()
void SongManager::ReadNoteScoresFromFile( CString fn, int c ) void SongManager::ReadNoteScoresFromFile( CString fn, int c )
{ {
Rageifstream f(fn); ifstream f(fn);
if( !f.good() ) if( !f.good() )
return; return;
CString line; CString line;
@@ -329,7 +329,7 @@ void SongManager::ReadNoteScoresFromFile( CString fn, int c )
void SongManager::ReadCourseScoresFromFile( CString fn, int c ) void SongManager::ReadCourseScoresFromFile( CString fn, int c )
{ {
FILE* fp = Ragefopen( fn, "r" ); FILE* fp = fopen( fn, "r" );
if( !fp ) if( !fp )
return; return;
@@ -369,7 +369,7 @@ void SongManager::ReadCourseScoresFromFile( CString fn, int c )
void SongManager::ReadCategoryRankingsFromFile( CString fn ) void SongManager::ReadCategoryRankingsFromFile( CString fn )
{ {
FILE* fp = Ragefopen( fn, "r" ); FILE* fp = fopen( fn, "r" );
if( !fp ) if( !fp )
return; return;
@@ -392,7 +392,7 @@ void SongManager::ReadCategoryRankingsFromFile( CString fn )
void SongManager::ReadCourseRankingsFromFile( CString fn ) void SongManager::ReadCourseRankingsFromFile( CString fn )
{ {
FILE* fp = Ragefopen( fn, "r" ); FILE* fp = fopen( fn, "r" );
if( !fp ) if( !fp )
return; return;
@@ -465,7 +465,7 @@ void SongManager::SaveCategoryRankingsToFile( CString fn )
// category ranking // category ranking
LOG->Trace("Writing category ranking"); LOG->Trace("Writing category ranking");
FILE* fp = Ragefopen( fn, "w" ); FILE* fp = fopen( fn, "w" );
if( fp ) if( fp )
{ {
fprintf(fp,"%d\n",CATEGORY_RANKING_VERSION); fprintf(fp,"%d\n",CATEGORY_RANKING_VERSION);
@@ -483,7 +483,7 @@ void SongManager::SaveCourseRankingsToFile( CString fn )
// course ranking // course ranking
LOG->Trace("Writing course ranking"); LOG->Trace("Writing course ranking");
{ {
FILE* fp = Ragefopen( fn, "w" ); FILE* fp = fopen( fn, "w" );
if( fp ) if( fp )
{ {
@@ -519,7 +519,7 @@ void SongManager::SaveNoteScoresToFile( CString fn, int c )
// notes scores // notes scores
LOG->Trace("Writing note scores"); LOG->Trace("Writing note scores");
{ {
FILE* fp = Ragefopen( fn, "w" ); FILE* fp = fopen( fn, "w" );
if( fp ) if( fp )
{ {
fprintf(fp,"%d\n",NOTES_SCORES_VERSION); fprintf(fp,"%d\n",NOTES_SCORES_VERSION);
@@ -573,7 +573,7 @@ void SongManager::SaveCourseScoresToFile( CString fn, int c )
// course scores // course scores
LOG->Trace("Writing course scores"); LOG->Trace("Writing course scores");
{ {
FILE* fp = Ragefopen( fn, "w" ); FILE* fp = fopen( fn, "w" );
if( fp ) if( fp )
{ {
fprintf(fp,"%d\n",COURSE_SCORES_VERSION); fprintf(fp,"%d\n",COURSE_SCORES_VERSION);
+3 -1
View File
@@ -481,9 +481,11 @@ int main(int argc, char* argv[])
GAMESTATE = new GameState; GAMESTATE = new GameState;
PREFSMAN = new PrefsManager; PREFSMAN = new PrefsManager;
if( PREFSMAN->m_bDebugMode ) if( PREFSMAN->m_bShowLogWindow )
LOG->ShowConsole(); LOG->ShowConsole();
LOG->SetLogging( PREFSMAN->m_bLogging );
CheckSettings(); CheckSettings();
GAMEMAN = new GameManager; GAMEMAN = new GameManager;
+1 -1
View File
@@ -100,7 +100,7 @@ TitleSubst::TitleSubst(const CString &section)
void TitleSubst::Load(const CString &filename, const CString &section) void TitleSubst::Load(const CString &filename, const CString &section)
{ {
Rageifstream f; ifstream f;
f.open(filename); f.open(filename);
if(!f.good()) return; if(!f.good()) return;