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:
@@ -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() );
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() );
|
||||
|
||||
@@ -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() );
|
||||
|
||||
|
||||
@@ -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() );
|
||||
|
||||
|
||||
@@ -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() );
|
||||
|
||||
|
||||
@@ -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) );
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -15,22 +15,11 @@
|
||||
#include <fstream>
|
||||
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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user