Fix RageFile, use RageFile. Const fix in LyricsLoader.
This commit is contained in:
@@ -18,8 +18,8 @@
|
|||||||
#include "IniFile.h"
|
#include "IniFile.h"
|
||||||
#include "GameConstantsAndTypes.h"
|
#include "GameConstantsAndTypes.h"
|
||||||
#include "SongManager.h"
|
#include "SongManager.h"
|
||||||
|
#include "RageFile.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
|
|
||||||
Bookkeeper* BOOKKEEPER = NULL; // global and accessable from anywhere in our program
|
Bookkeeper* BOOKKEEPER = NULL; // global and accessable from anywhere in our program
|
||||||
@@ -92,14 +92,15 @@ void Bookkeeper::ReadFromDisk()
|
|||||||
ini.GetValue( "MachineStatistics", "TotalPlays", m_iTotalPlays );
|
ini.GetValue( "MachineStatistics", "TotalPlays", m_iTotalPlays );
|
||||||
|
|
||||||
// read dat
|
// read dat
|
||||||
FILE* fp = fopen( COINS_DAT, "r" );
|
RageFile file(COINS_DAT, "r");
|
||||||
if( fp )
|
if (file.IsOpen())
|
||||||
{
|
{
|
||||||
for( int i=0; i<DAYS_PER_YEAR; i++ )
|
FILE *fp = file.GetFilePointer();
|
||||||
for( int j=0; j<HOURS_PER_DAY; j++ )
|
|
||||||
fscanf( fp, "%d ", &m_iCoinsByHourForYear[i][j] );
|
for (int i=0; i<DAYS_PER_YEAR; ++i)
|
||||||
fclose( fp );
|
for (int j=0; j<HOURS_PER_DAY; ++j)
|
||||||
}
|
fscanf(fp, "%d ", &m_iCoinsByHourForYear[i][j]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bookkeeper::WriteToDisk()
|
void Bookkeeper::WriteToDisk()
|
||||||
@@ -117,14 +118,16 @@ void Bookkeeper::WriteToDisk()
|
|||||||
ini.WriteFile();
|
ini.WriteFile();
|
||||||
|
|
||||||
// write dat
|
// write dat
|
||||||
FILE* fp = fopen( COINS_DAT, "w" );
|
RageFile file(COINS_DAT, "w");
|
||||||
if( fp )
|
|
||||||
{
|
if (file.IsOpen())
|
||||||
for( int i=0; i<DAYS_PER_YEAR; i++ )
|
{
|
||||||
for( int j=0; j<HOURS_PER_DAY; j++ )
|
FILE *fp = file.GetFilePointer();
|
||||||
fprintf( fp, "%d ", m_iCoinsByHourForYear[i][j] );
|
|
||||||
fclose( fp );
|
for (int i=0; i<DAYS_PER_YEAR; ++i)
|
||||||
}
|
for (int j=0; j<HOURS_PER_DAY; ++j)
|
||||||
|
fprintf(fp, "%d ", m_iCoinsByHourForYear[i][j]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bookkeeper::UpdateLastSeenTime()
|
void Bookkeeper::UpdateLastSeenTime()
|
||||||
|
|||||||
+14
-11
@@ -31,9 +31,10 @@
|
|||||||
#include "ProfileManager.h"
|
#include "ProfileManager.h"
|
||||||
#include "arch/arch.h"
|
#include "arch/arch.h"
|
||||||
#include "ThemeManager.h"
|
#include "ThemeManager.h"
|
||||||
#include "fstream"
|
//#include "fstream"
|
||||||
#include "Bookkeeper.h"
|
#include "Bookkeeper.h"
|
||||||
#include "LightsManager.h"
|
#include "LightsManager.h"
|
||||||
|
#include "RageFile.h"
|
||||||
|
|
||||||
#define DEFAULT_MODIFIERS THEME->GetMetric( "Common","DefaultModifiers" )
|
#define DEFAULT_MODIFIERS THEME->GetMetric( "Common","DefaultModifiers" )
|
||||||
|
|
||||||
@@ -1007,18 +1008,20 @@ void GameState::StoreRankingName( PlayerNumber pn, CString name )
|
|||||||
// Filter swear words from name
|
// Filter swear words from name
|
||||||
//
|
//
|
||||||
name.MakeUpper();
|
name.MakeUpper();
|
||||||
ifstream f;
|
RageFile file(NAMES_BLACKLIST_FILE);
|
||||||
f.open( NAMES_BLACKLIST_FILE );
|
|
||||||
if( f.good() )
|
if (file.IsOpen())
|
||||||
{
|
|
||||||
CString sLine;
|
|
||||||
while( getline(f,sLine) )
|
|
||||||
{
|
{
|
||||||
sLine.MakeUpper();
|
CString line;
|
||||||
if( name.Find(sLine) != -1 )
|
|
||||||
name = "";
|
while (!file.AtEOF())
|
||||||
|
{
|
||||||
|
line = file.GetLine();
|
||||||
|
line.MakeUpper();
|
||||||
|
if (name.Find(line) != -1)
|
||||||
|
name = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
vector<RankingFeats> aFeats;
|
vector<RankingFeats> aFeats;
|
||||||
GetRankingFeats( pn, aFeats );
|
GetRankingFeats( pn, aFeats );
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
#include "LyricsLoader.h"
|
#include "LyricsLoader.h"
|
||||||
#include "ThemeManager.h"
|
#include "ThemeManager.h"
|
||||||
|
|
||||||
#include "RageFile.h"
|
#include "RageFile.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -20,25 +19,25 @@ static int CompareLyricSegments(const LyricSegment &seg1, const LyricSegment &se
|
|||||||
return seg1.m_fStartTime < seg2.m_fStartTime;
|
return seg1.m_fStartTime < seg2.m_fStartTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LyricsLoader::LoadFromLRCFile( CString sPath, Song &out )
|
bool LyricsLoader::LoadFromLRCFile(const CString& sPath, Song& out)
|
||||||
{
|
{
|
||||||
LOG->Trace( "LyricsLoader::LoadFromLRCFile(%s)", sPath.c_str() );
|
LOG->Trace( "LyricsLoader::LoadFromLRCFile(%s)", sPath.c_str() );
|
||||||
|
|
||||||
ifstream input(sPath);
|
RageFile input(sPath, "r");
|
||||||
if(input.bad())
|
|
||||||
|
if (!input.IsOpen())
|
||||||
{
|
{
|
||||||
LOG->Warn( "Error opening file '%s' for reading.", sPath.c_str() );
|
LOG->Warn("Error opening file '%s' for reading.", sPath.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string line;
|
|
||||||
|
|
||||||
RageColor CurrentColor = LYRICS_DEFAULT_COLOR;
|
RageColor CurrentColor = LYRICS_DEFAULT_COLOR;
|
||||||
|
|
||||||
out.m_LyricSegments.clear();
|
out.m_LyricSegments.clear();
|
||||||
|
|
||||||
while(input.good() && getline(input, line))
|
while(input.GetError() == 0 && !input.AtEOF())
|
||||||
{
|
{
|
||||||
|
CString line = input.GetLine();
|
||||||
if(!line.compare(0, 2, "//"))
|
if(!line.compare(0, 2, "//"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -63,7 +62,7 @@ bool LyricsLoader::LoadFromLRCFile( CString sPath, Song &out )
|
|||||||
if(result != 3)
|
if(result != 3)
|
||||||
{
|
{
|
||||||
LOG->Trace( "The color value '%s' in '%s' is invalid.",
|
LOG->Trace( "The color value '%s' in '%s' is invalid.",
|
||||||
sValueData.c_str(), sPath.c_str() );
|
sValueData.c_str(), sPath.c_str() );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +72,7 @@ bool LyricsLoader::LoadFromLRCFile( CString sPath, Song &out )
|
|||||||
|
|
||||||
{
|
{
|
||||||
/* If we've gotten this far, and no other statement caught
|
/* If we've gotten this far, and no other statement caught
|
||||||
* this value before this does, assume it's a time value. */
|
* this value before this does, assume it's a time value. */
|
||||||
|
|
||||||
LyricSegment seg;
|
LyricSegment seg;
|
||||||
seg.m_Color = CurrentColor;
|
seg.m_Color = CurrentColor;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
class LyricsLoader {
|
class LyricsLoader {
|
||||||
public:
|
public:
|
||||||
bool LoadFromLRCFile( CString sPath, Song &out );
|
bool LoadFromLRCFile( const CString& sPath, Song &out );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -155,13 +155,13 @@ bool BMSLoader::LoadFromBMSFile( const CString &sPath, Steps &out )
|
|||||||
pNoteData->SetNumTracks( MAX_NOTE_TRACKS );
|
pNoteData->SetNumTracks( MAX_NOTE_TRACKS );
|
||||||
ResetTracksMagic();
|
ResetTracksMagic();
|
||||||
|
|
||||||
ifstream file(sPath);
|
RageFile file(sPath);
|
||||||
if( file.bad() )
|
|
||||||
RageException::Throw( "Failed to open %s for reading.", sPath.c_str() );
|
|
||||||
|
|
||||||
CString line;
|
if (!file.IsOpen())
|
||||||
while( getline(file, line) ) // foreach line
|
RageException::Throw("Failed to open %s for reading.", sPath.c_str());
|
||||||
|
while (!file.AtEOF())
|
||||||
{
|
{
|
||||||
|
CString line = file.GetLine();
|
||||||
StripCrnl(line);
|
StripCrnl(line);
|
||||||
CString value_name; // fill these in
|
CString value_name; // fill these in
|
||||||
CString value_data;
|
CString value_data;
|
||||||
@@ -454,15 +454,14 @@ bool BMSLoader::LoadFromDir( CString sDir, Song &out )
|
|||||||
|
|
||||||
CString sPath = out.GetSongDir() + arrayBMSFileNames[0];
|
CString sPath = out.GetSongDir() + arrayBMSFileNames[0];
|
||||||
|
|
||||||
ifstream file(sPath);
|
RageFile file(sPath);
|
||||||
if( file.bad() )
|
|
||||||
|
if (!file.IsOpen())
|
||||||
RageException::Throw( "Failed to open %s for reading.", sPath.c_str() );
|
RageException::Throw( "Failed to open %s for reading.", sPath.c_str() );
|
||||||
|
while (!file.AtEOF())
|
||||||
CString line;
|
|
||||||
while( getline(file, line) ) // foreach line
|
|
||||||
{
|
{
|
||||||
|
CString line = file.GetLine();
|
||||||
StripCrnl(line);
|
StripCrnl(line);
|
||||||
|
|
||||||
CString value_name; // fill these in
|
CString value_name; // fill these in
|
||||||
CString value_data;
|
CString value_data;
|
||||||
|
|
||||||
@@ -577,20 +576,6 @@ bool BMSLoader::LoadFromDir( CString sDir, Song &out )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let me just take a moment to express how frustrated I am with the new,
|
|
||||||
// poorly-designed changes to the BMS format.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhh!!!!!!!!!!!!!!!
|
|
||||||
//
|
|
||||||
// Thank you.
|
|
||||||
|
|
||||||
// MD 10/26/03 - And allow me to add to that my opinion of the BMS format in general.
|
|
||||||
//
|
|
||||||
// ()*&@^*&^@$(*&^!@(*&^($*&^!#(*&@!&*#*#*@#*@#(*@(%@(*!
|
|
||||||
//
|
|
||||||
// end MD 10/26/03
|
|
||||||
|
|
||||||
case 8: { // indirect bpm
|
case 8: { // indirect bpm
|
||||||
// This is a very inefficient way to parse, but it doesn't matter much
|
// This is a very inefficient way to parse, but it doesn't matter much
|
||||||
// because this is only parsed on the first run after the song is installed.
|
// because this is only parsed on the first run after the song is installed.
|
||||||
@@ -599,13 +584,17 @@ 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
|
||||||
ifstream file(sPath);
|
/* I don't like this. I think we should just seek back to the beginning
|
||||||
if( file.bad() )
|
* rather than open the file again. However, I'm not changing the logic,
|
||||||
RageException::Throw( "Failed to open %s for reading.", sPath.c_str() );
|
* only the implementation. -- Steve
|
||||||
|
*/
|
||||||
|
RageFile file(sPath);//Why doesn't VC6 bitch here but it does with int??
|
||||||
|
|
||||||
CString line;
|
if (!file.IsOpen())
|
||||||
while( getline(file, line) ) // foreach line
|
RageException::Throw( "Failed to open %s for reading.", sPath.c_str() );
|
||||||
|
while (!file.AtEOF())
|
||||||
{
|
{
|
||||||
|
CString line = file.GetLine();
|
||||||
StripCrnl(line);
|
StripCrnl(line);
|
||||||
CString value_name; // fill these in
|
CString value_name; // fill these in
|
||||||
CString value_data;
|
CString value_data;
|
||||||
@@ -628,9 +617,7 @@ bool BMSLoader::LoadFromDir( CString sDir, Song &out )
|
|||||||
value_data.erase(0,iIndexOfSeparator+1);
|
value_data.erase(0,iIndexOfSeparator+1);
|
||||||
}
|
}
|
||||||
else // no separator
|
else // no separator
|
||||||
{
|
|
||||||
value_name = line;
|
value_name = line;
|
||||||
}
|
|
||||||
|
|
||||||
if( 0==stricmp(value_name, sTagToLookFor) )
|
if( 0==stricmp(value_name, sTagToLookFor) )
|
||||||
{
|
{
|
||||||
@@ -640,9 +627,7 @@ bool BMSLoader::LoadFromDir( CString sDir, Song &out )
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( fBPM == -1 ) // we didn't find the line we were looking for
|
if( fBPM == -1 ) // we didn't find the line we were looking for
|
||||||
{
|
|
||||||
LOG->Trace( "WARNING: Couldn't find tag '%s' in '%s'.", sTagToLookFor.c_str(), sPath.c_str() );
|
LOG->Trace( "WARNING: Couldn't find tag '%s' in '%s'.", sTagToLookFor.c_str(), sPath.c_str() );
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BPMSegment newSeg( NoteRowToBeat(iStepIndex), fBPM );
|
BPMSegment newSeg( NoteRowToBeat(iStepIndex), fBPM );
|
||||||
@@ -661,13 +646,13 @@ 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
|
||||||
ifstream file(sPath);
|
RageFile file(sPath);//Why doesn't VC6 bitch here but it does with int??
|
||||||
if( file.bad() )
|
|
||||||
RageException::Throw( "Failed to open %s for reading.", sPath.c_str() );
|
|
||||||
|
|
||||||
CString line;
|
if (!file.IsOpen())
|
||||||
while( getline(file, line) ) // foreach line
|
RageException::Throw( "Failed to open %s for reading.", sPath.c_str() );
|
||||||
|
while (!file.AtEOF())
|
||||||
{
|
{
|
||||||
|
CString line = file.GetLine();
|
||||||
StripCrnl(line);
|
StripCrnl(line);
|
||||||
CString value_name; // fill these in
|
CString value_name; // fill these in
|
||||||
CString value_data;
|
CString value_data;
|
||||||
|
|||||||
@@ -46,6 +46,12 @@ void CollapsePath( CString &sPath )
|
|||||||
sPath = join( SLASH, as );
|
sPath = join( SLASH, as );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RageFile::RageFile(const CString& path, const char *mode)
|
||||||
|
{
|
||||||
|
mFP = NULL;
|
||||||
|
Open(path, mode);
|
||||||
|
}
|
||||||
|
|
||||||
bool RageFile::Open(const CString& path, const char *mode)
|
bool RageFile::Open(const CString& path, const char *mode)
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
// call FixSlashes on any path that came from the user
|
// call FixSlashes on any path that came from the user
|
||||||
void FixSlashesInPlace( CString &sPath );
|
void FixSlashesInPlace( CString &sPath );
|
||||||
@@ -31,7 +30,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
RageFile() : mPath("") { mFP = NULL; }
|
RageFile() : mPath("") { mFP = NULL; }
|
||||||
RageFile(const CString& path, const char *mode = "r") { Open(path, mode); }
|
RageFile(const CString& path, const char *mode = "r");
|
||||||
~RageFile() { Close(); }
|
~RageFile() { Close(); }
|
||||||
|
|
||||||
bool Open(const CString& path, const char *mode = "r");
|
bool Open(const CString& path, const char *mode = "r");
|
||||||
|
|||||||
@@ -508,14 +508,10 @@ CString DerefRedir(const CString &path)
|
|||||||
|
|
||||||
CString GetRedirContents(const CString &path)
|
CString GetRedirContents(const CString &path)
|
||||||
{
|
{
|
||||||
CString sNewFileName;
|
RageFile file(path);
|
||||||
{
|
CString sNewFileName = file.GetLine();
|
||||||
ifstream file(path);
|
|
||||||
getline(file, sNewFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
StripCrnl(sNewFileName);
|
StripCrnl(sNewFileName);
|
||||||
|
|
||||||
return sNewFileName;
|
return sNewFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ SongManager* SONGMAN = NULL; // global and accessable from anywhere in our progr
|
|||||||
#define SONGS_DIR BASE_PATH "Songs" SLASH
|
#define SONGS_DIR BASE_PATH "Songs" SLASH
|
||||||
#define COURSES_DIR BASE_PATH "Courses" SLASH
|
#define COURSES_DIR BASE_PATH "Courses" SLASH
|
||||||
#define STATS_PATH BASE_PATH "stats.html"
|
#define STATS_PATH BASE_PATH "stats.html"
|
||||||
|
#define GROUP_SORT_COLOR_FILE BASE_PATH "Data" SLASH "GroupSortColor.ini"
|
||||||
const CString CATEGORY_RANKING_FILE = BASE_PATH "Data" SLASH "CategoryRanking.dat";
|
const CString CATEGORY_RANKING_FILE = BASE_PATH "Data" SLASH "CategoryRanking.dat";
|
||||||
const CString MACHINE_STEPS_MEM_CARD_DATA = BASE_PATH "Data" SLASH "MachineStepsMemCardData.dat";
|
const CString MACHINE_STEPS_MEM_CARD_DATA = BASE_PATH "Data" SLASH "MachineStepsMemCardData.dat";
|
||||||
const CString MACHINE_COURSE_MEM_CARD_DATA = BASE_PATH "Data" SLASH "MachineCourseMemCardData.dat";
|
const CString MACHINE_COURSE_MEM_CARD_DATA = BASE_PATH "Data" SLASH "MachineCourseMemCardData.dat";
|
||||||
@@ -88,6 +89,36 @@ SongManager::SongManager( LoadingWindow *ld )
|
|||||||
|
|
||||||
g_LastMetricUpdate.SetZero();
|
g_LastMetricUpdate.SetZero();
|
||||||
UpdateMetrics();
|
UpdateMetrics();
|
||||||
|
|
||||||
|
IniFile gsc(GROUP_SORT_COLOR_FILE);
|
||||||
|
const CString sortKey("Sort");
|
||||||
|
const CString colorsKey("Colors");
|
||||||
|
const IniFile::key *key;
|
||||||
|
int i = 0;
|
||||||
|
CString value;
|
||||||
|
|
||||||
|
if (!gsc.ReadFile())
|
||||||
|
return;
|
||||||
|
|
||||||
|
gsc.GetValue(sortKey, "UnsortedAtEnd", m_bUnsortedAtEnd);
|
||||||
|
while (gsc.GetValue(sortKey, ssprintf("Group%d", ++i), value))
|
||||||
|
m_sSortedGroupNames.push_back(value);
|
||||||
|
|
||||||
|
key = gsc.GetKey(colorsKey);
|
||||||
|
|
||||||
|
if (!key)
|
||||||
|
return;
|
||||||
|
|
||||||
|
IniFile::key::const_iterator iter = key->begin();
|
||||||
|
|
||||||
|
while (iter != key->end())
|
||||||
|
{
|
||||||
|
RageColor c(1,1,1,1);
|
||||||
|
sscanf((*iter).second, "%f,%f,%f,%f", &c.r, &c.g, &c.b, &c.a);
|
||||||
|
m_mMappedGroupColors[(*iter).first] = c;
|
||||||
|
LOG->Trace("Found color: %f.%f.%f.%f", c.r, c.g, c.b, c.a);
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SongManager::~SongManager()
|
SongManager::~SongManager()
|
||||||
@@ -346,60 +377,67 @@ void SongManager::FreeSongs()
|
|||||||
//
|
//
|
||||||
// Helper function for reading/writing scores
|
// Helper function for reading/writing scores
|
||||||
//
|
//
|
||||||
bool FileRead( ifstream& f, CString& sOut )
|
bool FileRead(RageFile& f, CString& sOut)
|
||||||
{
|
{
|
||||||
if( f.eof() )
|
if (f.AtEOF())
|
||||||
return false;
|
return false;
|
||||||
getline(f, sOut);
|
sOut = f.GetLine();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool FileRead( ifstream& f, int& iOut )
|
|
||||||
|
bool FileRead(RageFile& f, int& iOut)
|
||||||
{
|
{
|
||||||
CString s;
|
CString s;
|
||||||
if( !FileRead( f, s ) )
|
if (!FileRead(f, s))
|
||||||
return false;
|
return false;
|
||||||
iOut = atoi( s );
|
iOut = atoi(s);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool FileRead( ifstream& f, unsigned& uOut )
|
|
||||||
|
bool FileRead(RageFile& f, unsigned& uOut)
|
||||||
{
|
{
|
||||||
CString s;
|
CString s;
|
||||||
if( !FileRead( f, s ) )
|
if (!FileRead(f, s))
|
||||||
return false;
|
return false;
|
||||||
uOut = atoi( s );
|
uOut = atoi(s);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool FileRead( ifstream& f, float& fOut )
|
|
||||||
|
bool FileRead(RageFile& f, float& fOut)
|
||||||
{
|
{
|
||||||
CString s;
|
CString s;
|
||||||
if( !FileRead( f, s ) )
|
if (!FileRead(f, s))
|
||||||
return false;
|
return false;
|
||||||
fOut = (float) atof( s );
|
fOut = (float)atof(s);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void FileWrite( ofstream& f, const CString& sWrite )
|
|
||||||
|
void FileWrite(RageFile& f, const CString& sWrite)
|
||||||
{
|
{
|
||||||
f << sWrite << "\n";
|
f.PutString(sWrite + "\n");
|
||||||
}
|
}
|
||||||
void FileWrite( ofstream& f, int iWrite )
|
|
||||||
|
void FileWrite(RageFile& f, int iWrite)
|
||||||
{
|
{
|
||||||
f << iWrite << "\n";
|
f.PutString(ssprintf("%d\n", iWrite));
|
||||||
}
|
}
|
||||||
void FileWrite( ofstream& f, size_t uWrite )
|
|
||||||
|
void FileWrite(RageFile& f, size_t uWrite)
|
||||||
{
|
{
|
||||||
f << uWrite << "\n";
|
f.PutString(ssprintf("%lu\n", uWrite));
|
||||||
}
|
}
|
||||||
void FileWrite( ofstream& f, float fWrite )
|
|
||||||
|
void FileWrite(RageFile& f, float fWrite)
|
||||||
{
|
{
|
||||||
f << fWrite << "\n";
|
f.PutString(ssprintf("%f\n", fWrite));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define WARN_AND_RETURN { LOG->Warn("Error parsing file '%s' at %s:%d",fn.c_str(),__FILE__,__LINE__); return; }
|
#define WARN_AND_RETURN { LOG->Warn("Error parsing file '%s' at %s:%d",fn.c_str(),__FILE__,__LINE__); return; }
|
||||||
|
|
||||||
void SongManager::ReadStepsMemCardDataFromFile( CString fn, int mc )
|
void SongManager::ReadStepsMemCardDataFromFile( CString fn, int mc )
|
||||||
{
|
{
|
||||||
ifstream f(fn);
|
RageFile f(fn);
|
||||||
if( !f.good() )
|
if (!f.IsOpen() || f.GetError() != 0)
|
||||||
WARN_AND_RETURN;
|
WARN_AND_RETURN;
|
||||||
|
|
||||||
int version;
|
int version;
|
||||||
@@ -493,8 +531,8 @@ void SongManager::ReadStepsMemCardDataFromFile( CString fn, int mc )
|
|||||||
|
|
||||||
void SongManager::ReadCategoryRankingsFromFile( CString fn )
|
void SongManager::ReadCategoryRankingsFromFile( CString fn )
|
||||||
{
|
{
|
||||||
ifstream f(fn);
|
RageFile f(fn);
|
||||||
if( !f.good() )
|
if (!f.IsOpen() || f.GetError() != 0)
|
||||||
WARN_AND_RETURN;
|
WARN_AND_RETURN;
|
||||||
|
|
||||||
int version;
|
int version;
|
||||||
@@ -525,8 +563,8 @@ void SongManager::ReadCategoryRankingsFromFile( CString fn )
|
|||||||
|
|
||||||
void SongManager::ReadCourseMemCardDataFromFile( CString fn, int mc )
|
void SongManager::ReadCourseMemCardDataFromFile( CString fn, int mc )
|
||||||
{
|
{
|
||||||
ifstream f(fn);
|
RageFile f(fn);
|
||||||
if( !f.good() )
|
if (!f.IsOpen() || f.GetError() != 0)
|
||||||
WARN_AND_RETURN;
|
WARN_AND_RETURN;
|
||||||
|
|
||||||
int version;
|
int version;
|
||||||
@@ -680,8 +718,8 @@ void SongManager::SaveCategoryRankingsToFile( CString fn )
|
|||||||
{
|
{
|
||||||
LOG->Trace("SongManager::SaveCategoryRankingsToFile");
|
LOG->Trace("SongManager::SaveCategoryRankingsToFile");
|
||||||
|
|
||||||
ofstream f(fn);
|
RageFile f(fn);
|
||||||
if( !f.good() )
|
if (!f.IsOpen() || f.GetError() != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FileWrite( f, CATEGORY_RANKING_VERSION );
|
FileWrite( f, CATEGORY_RANKING_VERSION );
|
||||||
@@ -708,8 +746,8 @@ void SongManager::SaveCourseMemCardDataToFile( CString fn, int mc )
|
|||||||
{
|
{
|
||||||
LOG->Trace("SongManager::SaveCourseMemCardDataToFile");
|
LOG->Trace("SongManager::SaveCourseMemCardDataToFile");
|
||||||
|
|
||||||
ofstream f(fn);
|
RageFile f(fn);
|
||||||
if( !f.good() )
|
if (!f.IsOpen() || f.GetError() != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FileWrite( f, COURSE_MEM_CARD_DATA_VERSION );
|
FileWrite( f, COURSE_MEM_CARD_DATA_VERSION );
|
||||||
@@ -761,8 +799,8 @@ void SongManager::SaveStepsMemCardDataToFile( CString fn, int mc )
|
|||||||
{
|
{
|
||||||
LOG->Trace("SongManager::SaveStepsMemCardDataToFile %s", fn.c_str());
|
LOG->Trace("SongManager::SaveStepsMemCardDataToFile %s", fn.c_str());
|
||||||
|
|
||||||
ofstream f(fn);
|
RageFile f(fn);
|
||||||
if( !f.good() )
|
if (!f.IsOpen() || f.GetError() != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FileWrite( f, STEPS_MEM_CARD_DATA_VERSION );
|
FileWrite( f, STEPS_MEM_CARD_DATA_VERSION );
|
||||||
@@ -847,6 +885,11 @@ bool SongManager::DoesGroupExist( CString sGroupName )
|
|||||||
|
|
||||||
RageColor SongManager::GetGroupColor( const CString &sGroupName )
|
RageColor SongManager::GetGroupColor( const CString &sGroupName )
|
||||||
{
|
{
|
||||||
|
const map<CString, RageColor>::const_iterator iter = m_mMappedGroupColors.find(sGroupName);
|
||||||
|
|
||||||
|
if (iter != m_mMappedGroupColors.end())
|
||||||
|
return (*iter).second;
|
||||||
|
|
||||||
UpdateMetrics();
|
UpdateMetrics();
|
||||||
|
|
||||||
// search for the group index
|
// search for the group index
|
||||||
|
|||||||
@@ -101,18 +101,22 @@ TitleSubst::TitleSubst(const CString §ion)
|
|||||||
|
|
||||||
void TitleSubst::Load(const CString &filename, const CString §ion)
|
void TitleSubst::Load(const CString &filename, const CString §ion)
|
||||||
{
|
{
|
||||||
ifstream f;
|
RageFile f(filename);
|
||||||
f.open(filename);
|
|
||||||
if(!f.good()) return;
|
if (!f.IsOpen() || f.GetError() != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
CString CurrentSection;
|
CString CurrentSection;
|
||||||
TitleTrans tr;
|
TitleTrans tr;
|
||||||
|
|
||||||
while(!f.eof())
|
while (!f.AtEOF())
|
||||||
{
|
{
|
||||||
CString line;
|
CString line = f.GetLine();
|
||||||
if(!getline(f, line)) continue;
|
if (f.GetError() != 0)
|
||||||
|
{
|
||||||
|
clearerr(f.GetFilePointer());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if(line.size() > 0 && utf8_get_char(line.c_str()) == 0xFEFF)
|
if(line.size() > 0 && utf8_get_char(line.c_str()) == 0xFEFF)
|
||||||
{
|
{
|
||||||
/* Annoying header that Windows puts on UTF-8 plaintext
|
/* Annoying header that Windows puts on UTF-8 plaintext
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "RageLog.h"
|
#include "RageLog.h"
|
||||||
#include "MovieTexture_Null.h"
|
#include "MovieTexture_Null.h"
|
||||||
#include "PrefsManager.h"
|
#include "PrefsManager.h"
|
||||||
|
#include "RageFile.h"
|
||||||
|
|
||||||
/* _WINDOWS is Windows only, where _WIN32 is Windows and Xbox, I think. Does this
|
/* _WINDOWS is Windows only, where _WIN32 is Windows and Xbox, I think. Does this
|
||||||
* work on the Xbox? -glenn */
|
* work on the Xbox? -glenn */
|
||||||
@@ -21,7 +22,6 @@
|
|||||||
#include "MovieTexture_FFMpeg.h"
|
#include "MovieTexture_FFMpeg.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "RageFile.h"
|
|
||||||
bool RageMovieTexture::GetFourCC( CString fn, CString &handler, CString &type )
|
bool RageMovieTexture::GetFourCC( CString fn, CString &handler, CString &type )
|
||||||
{
|
{
|
||||||
CString ignore, ext;
|
CString ignore, ext;
|
||||||
@@ -35,32 +35,37 @@ bool RageMovieTexture::GetFourCC( CString fn, CString &handler, CString &type )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifstream f;
|
//Not very pretty but should do all the same error checking without iostream
|
||||||
f.exceptions( ifstream::eofbit | ifstream::failbit | ifstream::badbit );
|
#define HANDLE_ERROR(x) {error = x; goto errorLabel;}
|
||||||
|
RageFile file(fn);
|
||||||
|
CString error("");
|
||||||
|
int i;
|
||||||
|
|
||||||
try {
|
if (!file.IsOpen())
|
||||||
f.open(fn);
|
HANDLE_ERROR("Could not open file.");
|
||||||
|
if (!file.Seek(0x70, SEEK_SET))
|
||||||
|
HANDLE_ERROR("Could not seek.");
|
||||||
|
type = " ";
|
||||||
|
if (file.Read((char *)type.c_str(), 4) != 4)
|
||||||
|
HANDLE_ERROR("Could not read.");
|
||||||
|
for (i=0; i<4; ++i)
|
||||||
|
if (type[i] < 0x20 || type[i] > 0x7E) type[i] = '?';
|
||||||
|
|
||||||
f.seekg( 0x70, ios_base::beg );
|
if (!file.Seek(0xBC, SEEK_SET))
|
||||||
type = " ";
|
HANDLE_ERROR("Could not seek.");
|
||||||
f.read((char *) type.c_str(), 4);
|
handler = " ";
|
||||||
int i;
|
if (file.Read((char *)handler.c_str(), 4) != 4)
|
||||||
for( i = 0; i < 4; ++i)
|
HANDLE_ERROR("Could not read.");
|
||||||
if(type[i] < 0x20 || type[i] > 0x7E) type[i] = '?';
|
for (i=0; i<4; ++i)
|
||||||
|
if (handler[i] < 0x20 || handler[i] > 0x7E) handler[i] = '?';
|
||||||
f.seekg( 0xBC, ios_base::beg );
|
|
||||||
|
|
||||||
handler = " ";
|
|
||||||
f.read((char *) handler.c_str(), 4);
|
|
||||||
for(i = 0; i < 4; ++i)
|
|
||||||
if(handler[i] < 0x20 || handler[i] > 0x7E) handler[i] = '?';
|
|
||||||
} catch(ifstream::failure e) {
|
|
||||||
LOG->Warn("error on %s: %s", fn.c_str(), e.what() );
|
|
||||||
handler = type = "";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
errorLabel:
|
||||||
|
LOG->Warn("Error on %s: %s.", fn.c_str(), error.c_str());
|
||||||
|
handler = type = "";
|
||||||
|
return false;
|
||||||
|
#undef HANDLE_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpAVIDebugInfo( CString fn )
|
static void DumpAVIDebugInfo( CString fn )
|
||||||
|
|||||||
Reference in New Issue
Block a user