From 35950c4eaf161d47f7f1e0f73e5f0f98a70c3e40 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 13 Aug 2003 04:40:23 +0000 Subject: [PATCH] Add prefs for logging. Don't throw if can't open log file. Remove Ragefopen and Rageifstream (they aren't needed). --- stepmania/src/Course.cpp | 2 +- stepmania/src/IniFile.cpp | 4 ++-- stepmania/src/LyricsLoader.cpp | 2 +- stepmania/src/Model.cpp | 4 ++-- stepmania/src/NotesLoaderBMS.cpp | 8 +++---- stepmania/src/NotesWriterDWI.cpp | 2 +- stepmania/src/NotesWriterSM.cpp | 2 +- stepmania/src/PrefsManager.cpp | 17 +++++++++---- stepmania/src/PrefsManager.h | 4 +++- stepmania/src/RageFile.cpp | 5 ---- stepmania/src/RageFile.h | 13 +--------- stepmania/src/RageLog.cpp | 37 ++++++++++++++++++++++------- stepmania/src/RageLog.h | 3 +++ stepmania/src/RageUtil.cpp | 4 ++-- stepmania/src/SDL_utils.cpp | 4 ++-- stepmania/src/SongManager.cpp | 16 ++++++------- stepmania/src/StepMania.cpp | 4 +++- stepmania/src/TitleSubstitution.cpp | 2 +- 18 files changed, 76 insertions(+), 57 deletions(-) diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index a9baf4f652..df3f19e3df 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -298,7 +298,7 @@ void Course::Save() { ASSERT( !m_bIsAutogen ); - FILE* fp = Ragefopen( m_sPath, "w" ); + FILE* fp = fopen( m_sPath, "w" ); if( fp == NULL ) { LOG->Warn( "Could not write course file '%s'.", m_sPath.c_str() ); diff --git a/stepmania/src/IniFile.cpp b/stepmania/src/IniFile.cpp index 59261945c5..3bc25a166f 100644 --- a/stepmania/src/IniFile.cpp +++ b/stepmania/src/IniFile.cpp @@ -42,7 +42,7 @@ void IniFile::SetPath(CString newpath) bool IniFile::ReadFile() { LOG->Trace("INI: Reading '%s'",path.c_str() ); - FILE *f = Ragefopen(path, "r"); + FILE *f = fopen(path, "r"); if (f == NULL) { @@ -101,7 +101,7 @@ LOG->Trace("INI: Reading '%s'",path.c_str() ); // writes data stored in class to ini file void IniFile::WriteFile() { - FILE* fp = Ragefopen( path, "w" ); + FILE* fp = fopen( path, "w" ); if( fp == NULL ) return; diff --git a/stepmania/src/LyricsLoader.cpp b/stepmania/src/LyricsLoader.cpp index a9e5819d83..cd5fe5a7ce 100644 --- a/stepmania/src/LyricsLoader.cpp +++ b/stepmania/src/LyricsLoader.cpp @@ -21,7 +21,7 @@ bool LyricsLoader::LoadFromLRCFile( CString sPath, Song &out ) { LOG->Trace( "LyricsLoader::LoadFromLRCFile(%s)", sPath.c_str() ); - Rageifstream input(sPath); + ifstream input(sPath); if(input.bad()) { LOG->Warn( "Error opening file '%s' for reading.", sPath.c_str() ); diff --git a/stepmania/src/Model.cpp b/stepmania/src/Model.cpp index c0b2d2e3bc..7c9ee4da26 100644 --- a/stepmania/src/Model.cpp +++ b/stepmania/src/Model.cpp @@ -77,7 +77,7 @@ bool Model::LoadMilkshapeAscii( CString sPath ) CString sDir, sThrowAway; splitrelpath( sPath, sDir, sThrowAway, sThrowAway ); - FILE *file = Ragefopen (sPath, "rt"); + FILE *file = fopen (sPath, "rt"); if (!file) 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; splitrelpath( sPath, sDir, sThrowAway, sThrowAway ); - FILE *file = Ragefopen (sPath, "rt"); + FILE *file = fopen (sPath, "rt"); if (!file) RageException::Throw( "Model:: Could not open '%s'.", sPath.c_str() ); diff --git a/stepmania/src/NotesLoaderBMS.cpp b/stepmania/src/NotesLoaderBMS.cpp index cf7c39de00..0670fd9449 100644 --- a/stepmania/src/NotesLoaderBMS.cpp +++ b/stepmania/src/NotesLoaderBMS.cpp @@ -67,7 +67,7 @@ bool BMSLoader::LoadFromBMSFile( const CString &sPath, Steps &out ) NoteData* pNoteData = new NoteData; pNoteData->SetNumTracks( MAX_NOTE_TRACKS ); - Rageifstream file(sPath); + ifstream file(sPath); if( file.bad() ) 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]; - Rageifstream file(sPath); + ifstream file(sPath); if( file.bad() ) 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 - Rageifstream file(sPath); + ifstream file(sPath); if( file.bad() ) 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 - Rageifstream file(sPath); + ifstream file(sPath); if( file.bad() ) RageException::Throw( "Failed to open %s for reading.", sPath.c_str() ); diff --git a/stepmania/src/NotesWriterDWI.cpp b/stepmania/src/NotesWriterDWI.cpp index f4aab8e8b6..4ad0baa256 100644 --- a/stepmania/src/NotesWriterDWI.cpp +++ b/stepmania/src/NotesWriterDWI.cpp @@ -323,7 +323,7 @@ bool NotesWriterDWI::WriteDWINotesTag( FILE* fp, const Steps &out ) bool NotesWriterDWI::Write( CString sPath, const Song &out ) { - FILE* fp = Ragefopen( sPath, "w" ); + FILE* fp = fopen( sPath, "w" ); if( fp == NULL ) RageException::Throw( "Error opening song file '%s' for writing.", sPath.c_str() ); diff --git a/stepmania/src/NotesWriterSM.cpp b/stepmania/src/NotesWriterSM.cpp index 92ba2d9891..fbbc609ca4 100644 --- a/stepmania/src/NotesWriterSM.cpp +++ b/stepmania/src/NotesWriterSM.cpp @@ -114,7 +114,7 @@ bool NotesWriterSM::Write(CString sPath, const Song &out, bool bSavingCache) { unsigned i; - FILE* fp = Ragefopen( sPath, "w" ); + FILE* fp = fopen( sPath, "w" ); if( fp == NULL ) { LOG->Warn( "Error opening song file '%s' for writing: %s", sPath.c_str(), strerror(errno) ); diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index 5c5319a701..924c4cb59c 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -100,8 +100,13 @@ PrefsManager::PrefsManager() m_bFirstRun = true; m_bAutoMapJoysticks = true; 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; // set to 0 so people aren't shocked at first @@ -257,7 +262,9 @@ void PrefsManager::ReadGlobalPrefsFromDisk( bool bSwitchToLastPlayedGame ) #endif ini.GetValueB( "Options", "AntiAliasing", m_bAntiAliasing ); 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(); @@ -357,7 +364,9 @@ void PrefsManager::SaveGlobalPrefsToDisk() #endif ini.SetValueB( "Options", "AntiAliasing", m_bAntiAliasing ); 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.SetValueI( "Options", "CourseSortOrder", m_iCourseSortOrder ); diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h index 50f579e9d1..8734aac0b1 100644 --- a/stepmania/src/PrefsManager.h +++ b/stepmania/src/PrefsManager.h @@ -85,7 +85,9 @@ public: bool m_bFirstRun; bool m_bAutoMapJoysticks; float m_fGlobalOffsetSeconds; - bool m_bDebugMode; + bool m_bForceLogFlush; + bool m_bLogging; + bool m_bShowLogWindow; bool m_bTenFooterInRed; int m_iProgressiveLifebar; int m_iProgressiveStageLifebar; diff --git a/stepmania/src/RageFile.cpp b/stepmania/src/RageFile.cpp index e5290af371..b48db6a556 100644 --- a/stepmania/src/RageFile.cpp +++ b/stepmania/src/RageFile.cpp @@ -44,8 +44,3 @@ void CollapsePath( CString &sPath ) sPath = join( SLASH, as ); } -// replacement for fopen -FILE* Ragefopen( const char *szPath, const char *szMode ) -{ - return fopen( FixSlashes(szPath), szMode ); -} diff --git a/stepmania/src/RageFile.h b/stepmania/src/RageFile.h index 165ebf10e9..eda5eb7477 100644 --- a/stepmania/src/RageFile.h +++ b/stepmania/src/RageFile.h @@ -15,22 +15,11 @@ #include 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 ); CString FixSlashes( 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 diff --git a/stepmania/src/RageLog.cpp b/stepmania/src/RageLog.cpp index d0ad79d8cd..62828feec6 100644 --- a/stepmania/src/RageLog.cpp +++ b/stepmania/src/RageLog.cpp @@ -85,18 +85,24 @@ enum { RageLog::RageLog() { + m_bEnabled = true; + // delete old log files remove( LOG_PATH ); remove( INFO_PATH ); // Open log file and leave it open. - m_fileLog = Ragefopen( LOG_PATH, "w" ); - if( m_fileLog == NULL ) - RageException::Throw( " Couldn't open log.txt: %s", strerror(errno) ); + m_fileLog = fopen( LOG_PATH, "w" ); + + // Failing to open shouldn't be fatal + //if( m_fileLog == NULL ) + // RageException::Throw( " Couldn't open log.txt: %s", strerror(errno) ); - m_fileInfo = Ragefopen( INFO_PATH, "w" ); - if( m_fileInfo == NULL ) - RageException::Throw( " Couldn't open info.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 ); @@ -119,8 +125,7 @@ RageLog::RageLog() RageLog::~RageLog() { /* Add the mapped log data to info.txt. */ - fprintf( m_fileInfo, "%s", GetAdditionalLog() ); - fprintf( m_fileLog, "\nStatics:\n%s", GetAdditionalLog() ); + this->Info( "Statics:\n%s", GetAdditionalLog() ); Flush(); HideConsole(); @@ -128,6 +133,11 @@ RageLog::~RageLog() if(m_fileInfo) fclose( m_fileInfo ); } +void RageLog::SetLogging( bool b ) +{ + m_bEnabled = b; +} + void RageLog::ShowConsole() { #if defined(WIN32) && !defined(_XBOX) @@ -147,6 +157,9 @@ void RageLog::HideConsole() void RageLog::Trace( const char *fmt, ...) { + if( !m_bEnabled ) + return; + va_list va; va_start(va, fmt); CString sBuff = vssprintf( fmt, va ); @@ -159,6 +172,9 @@ void RageLog::Trace( const char *fmt, ...) * in crash dumps. */ void RageLog::Info( const char *fmt, ...) { + if( !m_bEnabled ) + return; + va_list va; va_start(va, fmt); CString sBuff = vssprintf( fmt, va ); @@ -169,6 +185,9 @@ void RageLog::Info( const char *fmt, ...) void RageLog::Warn( const char *fmt, ...) { + if( !m_bEnabled ) + return; + va_list va; va_start(va, fmt); CString sBuff = vssprintf( fmt, va ); @@ -208,7 +227,7 @@ void RageLog::Write( int where, CString 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(); } diff --git a/stepmania/src/RageLog.h b/stepmania/src/RageLog.h index 418053c30b..c29cab2275 100644 --- a/stepmania/src/RageLog.h +++ b/stepmania/src/RageLog.h @@ -36,7 +36,10 @@ public: /* Returns NULL if past the last recent log. */ static const char *GetRecentLog( int n ); + void SetLogging( bool b ); // enable or disable logging + private: + bool m_bEnabled; FILE *m_fileLog, *m_fileInfo; void Write( int, CString ); void UpdateMappedLog(); diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index 52051c1c14..4ab7b549d7 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -505,7 +505,7 @@ CString DerefRedir(const CString &path) CString sNewFileName; { - Rageifstream file(path); + ifstream file(path); getline(file, sNewFileName); } @@ -534,7 +534,7 @@ CString GetRedirContents(const CString &path) CString sNewFileName; { - Rageifstream file(path); + ifstream file(path); getline(file, sNewFileName); } diff --git a/stepmania/src/SDL_utils.cpp b/stepmania/src/SDL_utils.cpp index daf5ae85a3..51e881774b 100644 --- a/stepmania/src/SDL_utils.cpp +++ b/stepmania/src/SDL_utils.cpp @@ -605,7 +605,7 @@ struct SurfaceHeader /* Save and load SDL_Surfaces to disk. This avoids problems with bitmaps. */ 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) return false; @@ -643,7 +643,7 @@ bool mySDL_SaveSurface( SDL_Surface *img, 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) return NULL; diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 67efb5867a..457f85a2b1 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -266,7 +266,7 @@ void SongManager::FreeSongs() void SongManager::ReadNoteScoresFromFile( CString fn, int c ) { - Rageifstream f(fn); + ifstream f(fn); if( !f.good() ) return; CString line; @@ -329,7 +329,7 @@ void SongManager::ReadNoteScoresFromFile( CString fn, int c ) void SongManager::ReadCourseScoresFromFile( CString fn, int c ) { - FILE* fp = Ragefopen( fn, "r" ); + FILE* fp = fopen( fn, "r" ); if( !fp ) return; @@ -369,7 +369,7 @@ void SongManager::ReadCourseScoresFromFile( CString fn, int c ) void SongManager::ReadCategoryRankingsFromFile( CString fn ) { - FILE* fp = Ragefopen( fn, "r" ); + FILE* fp = fopen( fn, "r" ); if( !fp ) return; @@ -392,7 +392,7 @@ void SongManager::ReadCategoryRankingsFromFile( CString fn ) void SongManager::ReadCourseRankingsFromFile( CString fn ) { - FILE* fp = Ragefopen( fn, "r" ); + FILE* fp = fopen( fn, "r" ); if( !fp ) return; @@ -465,7 +465,7 @@ void SongManager::SaveCategoryRankingsToFile( CString fn ) // category ranking LOG->Trace("Writing category ranking"); - FILE* fp = Ragefopen( fn, "w" ); + FILE* fp = fopen( fn, "w" ); if( fp ) { fprintf(fp,"%d\n",CATEGORY_RANKING_VERSION); @@ -483,7 +483,7 @@ void SongManager::SaveCourseRankingsToFile( CString fn ) // course ranking LOG->Trace("Writing course ranking"); { - FILE* fp = Ragefopen( fn, "w" ); + FILE* fp = fopen( fn, "w" ); if( fp ) { @@ -519,7 +519,7 @@ void SongManager::SaveNoteScoresToFile( CString fn, int c ) // notes scores LOG->Trace("Writing note scores"); { - FILE* fp = Ragefopen( fn, "w" ); + FILE* fp = fopen( fn, "w" ); if( fp ) { fprintf(fp,"%d\n",NOTES_SCORES_VERSION); @@ -573,7 +573,7 @@ void SongManager::SaveCourseScoresToFile( CString fn, int c ) // course scores LOG->Trace("Writing course scores"); { - FILE* fp = Ragefopen( fn, "w" ); + FILE* fp = fopen( fn, "w" ); if( fp ) { fprintf(fp,"%d\n",COURSE_SCORES_VERSION); diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 3b4d1abcbf..b9894ca37c 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -481,9 +481,11 @@ int main(int argc, char* argv[]) GAMESTATE = new GameState; PREFSMAN = new PrefsManager; - if( PREFSMAN->m_bDebugMode ) + if( PREFSMAN->m_bShowLogWindow ) LOG->ShowConsole(); + LOG->SetLogging( PREFSMAN->m_bLogging ); + CheckSettings(); GAMEMAN = new GameManager; diff --git a/stepmania/src/TitleSubstitution.cpp b/stepmania/src/TitleSubstitution.cpp index c2a16189f4..d9f77eb70c 100644 --- a/stepmania/src/TitleSubstitution.cpp +++ b/stepmania/src/TitleSubstitution.cpp @@ -100,7 +100,7 @@ TitleSubst::TitleSubst(const CString §ion) void TitleSubst::Load(const CString &filename, const CString §ion) { - Rageifstream f; + ifstream f; f.open(filename); if(!f.good()) return;