Fix RageFile, use RageFile. Const fix in LyricsLoader.

This commit is contained in:
Steve Checkoway
2003-11-30 06:20:25 +00:00
parent 2da10fc9eb
commit b125e3d980
11 changed files with 216 additions and 173 deletions
+21 -22
View File
@@ -8,7 +8,6 @@
#include "RageUtil.h"
#include "LyricsLoader.h"
#include "ThemeManager.h"
#include "RageFile.h"
#include <map>
using namespace std;
@@ -20,40 +19,40 @@ static int CompareLyricSegments(const LyricSegment &seg1, const LyricSegment &se
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() );
ifstream input(sPath);
if(input.bad())
RageFile input(sPath, "r");
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;
}
string line;
RageColor CurrentColor = LYRICS_DEFAULT_COLOR;
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, "//"))
continue;
/* "[data1] data2". Ignore whitespace at the beginning of the line. */
static Regex x("^ *\\[([^]]+)\\] *(.*)$");
vector<CString> matches;
if(!x.Compare(line, matches))
continue;
ASSERT( matches.size() == 2 );
CString &sValueName = matches[0];
CString &sValueData = matches[1];
StripCrnl(sValueData);
// handle the data
if( 0==stricmp(sValueName,"COLOUR") || 0==stricmp(sValueName,"COLOR") )
{
@@ -63,17 +62,17 @@ bool LyricsLoader::LoadFromLRCFile( CString sPath, Song &out )
if(result != 3)
{
LOG->Trace( "The color value '%s' in '%s' is invalid.",
sValueData.c_str(), sPath.c_str() );
sValueData.c_str(), sPath.c_str() );
continue;
}
CurrentColor = RageColor(r / 256.0f, g / 256.0f, b / 256.0f, 1);
continue;
}
{
/* 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;
seg.m_Color = CurrentColor;
@@ -84,13 +83,13 @@ bool LyricsLoader::LoadFromLRCFile( CString sPath, Song &out )
out.AddLyricSegment( seg );
}
}
sort( out.m_LyricSegments.begin(), out.m_LyricSegments.end(), CompareLyricSegments );
LOG->Trace( "LyricsLoader::LoadFromLRCFile done" );
return true;
}
/*
-----------------------------------------------------------------------------
Copyright (c) 2003 by the person(s) listed below. All rights reserved.