fix up MsdFile; get rid of arbitrary limits
This commit is contained in:
@@ -50,8 +50,8 @@ void Course::LoadFromCRSFile( CString sPath, vector<Song*> &apSongs )
|
||||
|
||||
for( unsigned i=0; i<msd.GetNumValues(); i++ )
|
||||
{
|
||||
CString sValueName = msd.m_sParams[i][0];
|
||||
CString* sParams = msd.m_sParams[i];
|
||||
CString sValueName = msd.GetParam(i, 0);
|
||||
const MsdFile::value_t &sParams = msd.GetValue(i);
|
||||
|
||||
// handle the data
|
||||
if( 0 == stricmp(sValueName, "COURSE") )
|
||||
@@ -59,20 +59,17 @@ void Course::LoadFromCRSFile( CString sPath, vector<Song*> &apSongs )
|
||||
|
||||
else if( 0 == stricmp(sValueName, "REPEAT") )
|
||||
{
|
||||
sParams[1].MakeLower();
|
||||
if( sParams[1].Find("yes") != -1 )
|
||||
CString str = sParams[1];
|
||||
str.MakeLower();
|
||||
if( str.Find("yes") != -1 )
|
||||
m_bRepeat = true;
|
||||
}
|
||||
|
||||
else if( 0 == stricmp(sValueName, "LIVES") )
|
||||
{
|
||||
m_iLives = atoi( sParams[1] );
|
||||
}
|
||||
|
||||
else if( 0 == stricmp(sValueName, "EXTRA") )
|
||||
{
|
||||
m_iExtra = atoi( sParams[1] );
|
||||
}
|
||||
|
||||
else if( 0 == stricmp(sValueName, "SONG") )
|
||||
{
|
||||
|
||||
+12
-20
@@ -7,6 +7,7 @@
|
||||
|
||||
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
||||
Chris Danford
|
||||
Glenn Maynard
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@@ -40,37 +41,21 @@
|
||||
#include "RageLog.h"
|
||||
#include "io.h"
|
||||
#include "fcntl.h"
|
||||
|
||||
|
||||
MsdFile::MsdFile()
|
||||
{
|
||||
m_iNumValues = 0;
|
||||
}
|
||||
|
||||
MsdFile::~MsdFile()
|
||||
{
|
||||
}
|
||||
#include "RageUtil.h"
|
||||
|
||||
void MsdFile::AddParam( char *buf, int len )
|
||||
{
|
||||
int valueno = m_iNumValues-1;
|
||||
int paramno = m_iNumParams[valueno];
|
||||
ASSERT( paramno < MAX_PARAMS_PER_VALUE );
|
||||
m_iNumParams[valueno]++;
|
||||
m_sParams[valueno][paramno] = CString(buf, len);
|
||||
values.back().params.push_back(CString(buf, len));
|
||||
}
|
||||
|
||||
void MsdFile::AddValue() /* (no extra charge) */
|
||||
{
|
||||
m_iNumValues++;
|
||||
ASSERT( m_iNumValues < MAX_VALUES );
|
||||
values.push_back(value_t());
|
||||
}
|
||||
|
||||
void MsdFile::ReadBuf( char *buf, int len )
|
||||
{
|
||||
int value_start = -1;
|
||||
memset(m_iNumParams, 0, sizeof(m_iNumParams));
|
||||
m_iNumValues = 0;
|
||||
|
||||
bool ReadingValue=false;
|
||||
int i = 0;
|
||||
@@ -163,7 +148,7 @@ bool MsdFile::ReadFile( CString sNewPath )
|
||||
if( (fd = open(sNewPath, _O_RDONLY, 0)) == -1 )
|
||||
return false;
|
||||
|
||||
int iBufferSize = _filelength( fd ) + 1000; // +1000 because sometimes the bytes read is > filelength. Why?
|
||||
int iBufferSize = GetFileSizeInBytes(sNewPath) + 1000; // +1000 because sometimes the bytes read is > filelength. Why?
|
||||
|
||||
// allocate a string to hold the file
|
||||
char* szFileString = new char[iBufferSize];
|
||||
@@ -181,3 +166,10 @@ bool MsdFile::ReadFile( CString sNewPath )
|
||||
return true;
|
||||
}
|
||||
|
||||
CString MsdFile::GetParam(unsigned val, unsigned par) const
|
||||
{
|
||||
if(val >= GetNumValues()) return 0;
|
||||
if(par >= GetNumParams(val)) return 0;
|
||||
|
||||
return values[val].params[par];
|
||||
}
|
||||
|
||||
+22
-21
@@ -8,37 +8,38 @@
|
||||
|
||||
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
||||
Chris Danford
|
||||
Glenn Maynard
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
const unsigned MAX_VALUES = 200;
|
||||
const unsigned MAX_PARAMS_PER_VALUE = 10;
|
||||
|
||||
class MsdFile
|
||||
{
|
||||
public:
|
||||
/* #param:param:param:param; <- one whole value */
|
||||
struct value_t
|
||||
{
|
||||
vector<CString> params;
|
||||
|
||||
CString operator[](unsigned i) const { if(i >= params.size()) return ""; return params[i]; }
|
||||
};
|
||||
|
||||
virtual ~MsdFile() { }
|
||||
|
||||
//returns true if successful, false otherwise
|
||||
bool ReadFile( CString sFilePath );
|
||||
|
||||
unsigned GetNumValues() const { return values.size(); }
|
||||
unsigned GetNumParams(unsigned val) const { if(val >= GetNumValues()) return 0; return values[val].params.size(); }
|
||||
const value_t &GetValue(unsigned val) const { ASSERT(val < GetNumValues()); return values[val]; }
|
||||
CString GetParam(unsigned val, unsigned par) const;
|
||||
|
||||
private:
|
||||
void ReadBuf( char *buf, int len );
|
||||
void AddParam( char *buf, int len );
|
||||
void AddValue();
|
||||
|
||||
unsigned m_iNumValues; // tells how many values are valid
|
||||
|
||||
public:
|
||||
MsdFile();
|
||||
|
||||
//default destructor
|
||||
virtual ~MsdFile();
|
||||
|
||||
//reads ini file specified using MsdFile::SetPath()
|
||||
//returns true if successful, false otherwise
|
||||
bool ReadFile( CString sFilePath );
|
||||
|
||||
CString m_sParams[MAX_VALUES][MAX_PARAMS_PER_VALUE];
|
||||
|
||||
/* #param:param:param:param; <- one whole value */
|
||||
unsigned m_iNumParams[MAX_VALUES]; // tells how many params this value has
|
||||
|
||||
unsigned GetNumValues() const { return m_iNumValues; }
|
||||
vector<value_t> values;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -247,20 +247,26 @@ bool DWILoader::LoadFromDWITokens(
|
||||
* or milliseconds.
|
||||
* What's even more dumb is that the value can contain a ':'. Colon is supposed to be a parameter separator!
|
||||
*/
|
||||
float DWILoader::ParseBrokenDWITimestamp(const CString *sParams, int iNumParams)
|
||||
float DWILoader::ParseBrokenDWITimestamp(const CString &arg1, const CString &arg2, const CString &arg3)
|
||||
{
|
||||
if( iNumParams == 4 )
|
||||
return TimeToSeconds( sParams[1]+":"+sParams[2]+":"+sParams[3] );
|
||||
|
||||
if( iNumParams == 3 )
|
||||
return TimeToSeconds( sParams[1]+":"+sParams[2] );
|
||||
|
||||
// iNumParams == 2
|
||||
/* If the value contains a period, treat it as seconds; otherwise ms. */
|
||||
if(sParams[1].find_first_of(".") != sParams[1].npos)
|
||||
return (float)atof(sParams[1].GetString());
|
||||
else
|
||||
return float(atof(sParams[1].GetString())) / 1000.f;
|
||||
if(arg1.empty()) return 0;
|
||||
|
||||
/* 1+ args */
|
||||
if(arg2.empty())
|
||||
{
|
||||
/* If the value contains a period, treat it as seconds; otherwise ms. */
|
||||
if(arg1.find_first_of(".") != arg1.npos)
|
||||
return (float)atof(arg1.GetString());
|
||||
else
|
||||
return float(atof(arg1.GetString())) / 1000.f;
|
||||
}
|
||||
|
||||
/* 2+ args */
|
||||
if(arg3.empty())
|
||||
return TimeToSeconds( arg1+":"+arg2 );
|
||||
|
||||
/* 3+ args */
|
||||
return TimeToSeconds( arg1+":"+arg2+":"+arg3 );
|
||||
}
|
||||
|
||||
bool DWILoader::LoadFromDWIFile( CString sPath, Song &out )
|
||||
@@ -275,8 +281,8 @@ bool DWILoader::LoadFromDWIFile( CString sPath, Song &out )
|
||||
|
||||
for( unsigned i=0; i<msd.GetNumValues(); i++ )
|
||||
{
|
||||
int iNumParams = msd.m_iNumParams[i];
|
||||
CString* sParams = msd.m_sParams[i];
|
||||
int iNumParams = msd.GetNumParams(i);
|
||||
const MsdFile::value_t &sParams = msd.GetValue(i);
|
||||
CString sValueName = sParams[0];
|
||||
|
||||
if(iNumParams < 1)
|
||||
@@ -306,10 +312,10 @@ bool DWILoader::LoadFromDWIFile( CString sPath, Song &out )
|
||||
out.m_fBeat0OffsetInSeconds = -atoi( sParams[1] ) / 1000.0f;
|
||||
|
||||
else if( 0==stricmp(sValueName,"SAMPLESTART") )
|
||||
out.m_fMusicSampleStartSeconds = ParseBrokenDWITimestamp(sParams, iNumParams);
|
||||
out.m_fMusicSampleStartSeconds = ParseBrokenDWITimestamp(sParams[1], sParams[2], sParams[3]);
|
||||
|
||||
else if( 0==stricmp(sValueName,"SAMPLELENGTH") )
|
||||
out.m_fMusicSampleLengthSeconds = ParseBrokenDWITimestamp(sParams, iNumParams);
|
||||
out.m_fMusicSampleLengthSeconds = ParseBrokenDWITimestamp(sParams[1], sParams[2], sParams[3]);
|
||||
|
||||
else if( 0==stricmp(sValueName,"FREEZE") )
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ class DWILoader: public NotesLoader {
|
||||
|
||||
bool LoadFromDWIFile( CString sPath, Song &out );
|
||||
|
||||
static float ParseBrokenDWITimestamp(const CString *sParams, int iNumParams);
|
||||
static float DWILoader::ParseBrokenDWITimestamp(const CString &arg1, const CString &arg2, const CString &arg3);
|
||||
public:
|
||||
void GetApplicableFiles( CString sPath, CStringArray &out );
|
||||
bool Loadable( CString sPath );
|
||||
|
||||
@@ -23,7 +23,7 @@ bool KSFLoader::LoadFromKSFFile( const CString &sPath, Notes &out )
|
||||
|
||||
for( unsigned i=0; i<msd.GetNumValues(); i++ )
|
||||
{
|
||||
CString* sParams = msd.m_sParams[i];
|
||||
const MsdFile::value_t &sParams = msd.GetValue(i);
|
||||
CString sValueName = sParams[0];
|
||||
|
||||
// handle the data
|
||||
@@ -192,7 +192,7 @@ bool KSFLoader::LoadFromDir( CString sDir, Song &out )
|
||||
|
||||
for( i=0; i < msd.GetNumValues(); i++ )
|
||||
{
|
||||
CString* sParams = msd.m_sParams[i];
|
||||
const MsdFile::value_t &sParams = msd.GetValue(i);
|
||||
CString sValueName = sParams[0];
|
||||
|
||||
// handle the data
|
||||
|
||||
@@ -61,8 +61,8 @@ bool SMLoader::LoadFromSMFile( CString sPath, Song &out )
|
||||
|
||||
for( unsigned i=0; i<msd.GetNumValues(); i++ )
|
||||
{
|
||||
int iNumParams = msd.m_iNumParams[i];
|
||||
CString* sParams = msd.m_sParams[i];
|
||||
int iNumParams = msd.GetNumParams(i);
|
||||
const MsdFile::value_t &sParams = msd.GetValue(i);
|
||||
CString sValueName = sParams[0];
|
||||
|
||||
// handle the data
|
||||
|
||||
Reference in New Issue
Block a user