fixed crash in MsdFile. Also, updated ez2 and SMMAX2 themes to new element names.

This commit is contained in:
Chris Danford
2002-09-15 07:03:32 +00:00
parent 35688cfea5
commit fdb09fc810
6 changed files with 27 additions and 31 deletions
+2 -2
View File
@@ -42,8 +42,8 @@ void Course::LoadFromCRSFile( CString sPath, CArray<Song*,Song*> &apSongs )
for( int i=0; i<msd.m_iNumValues; i++ )
{
CString sValueName = msd.m_szValuesAndParams[i][0];
CString* sParams = msd.m_sValuesAndParams[i];
CString sValueName = msd.m_sParams[i][0];
CString* sParams = msd.m_sParams[i];
// handle the data
if( 0 == stricmp(sValueName, "COURSE") )
+20 -21
View File
@@ -15,13 +15,11 @@
MsdFile::MsdFile()
{
m_szFileString = NULL;
m_iNumValues = 0;
}
MsdFile::~MsdFile()
{
delete [] m_szFileString;
}
//returns true if successful, false otherwise
@@ -42,16 +40,16 @@ bool MsdFile::ReadFile( CString sNewPath )
CloseHandle( hFile );
// allocate a string to hold the file
delete [] m_szFileString;
m_szFileString = new char[iBufferSize];
char* szFileString = new char[iBufferSize];
char* szParams[MAX_VALUES][MAX_PARAMS_PER_VALUE];
FILE* fp = fopen(sNewPath, "r");
if( fp == NULL )
return false;
int iBytesRead = fread( m_szFileString, 1, iBufferSize, fp );
int iBytesRead = fread( szFileString, 1, iBufferSize, fp );
ASSERT( iBufferSize > iBytesRead );
ASSERT( iBufferSize > iBytesRead ); // why are these not always =?
m_iNumValues = 0;
@@ -59,7 +57,7 @@ bool MsdFile::ReadFile( CString sNewPath )
int i;
for( i=0; i<iBytesRead; i++ )
{
switch( m_szFileString[i] )
switch( szFileString[i] )
{
case '#': // begins a new value
{
@@ -71,9 +69,9 @@ bool MsdFile::ReadFile( CString sNewPath )
/* Make sure this # is the first non-whitespace character on the line. */
bool FirstChar = true;
int j;
for(j = i-1; j >= 0 && !strchr("\r\n", m_szFileString[j]); --j)
for(j = i-1; j >= 0 && !strchr("\r\n", szFileString[j]); --j)
{
if(m_szFileString[j] == ' ' || m_szFileString[j] == '\t')
if(szFileString[j] == ' ' || szFileString[j] == '\t')
continue;
FirstChar = false;
@@ -84,45 +82,45 @@ bool MsdFile::ReadFile( CString sNewPath )
break;
}
for(j = i-1; j >= 0 && isspace(m_szFileString[j]); --j)
m_szFileString[j] = 0;
for(j = i-1; j >= 0 && isspace(szFileString[j]); --j)
szFileString[j] = 0;
}
ReadingValue=true;
m_iNumValues++;
int iCurValueIndex = m_iNumValues-1;
m_iNumParams[iCurValueIndex] = 1;
m_szValuesAndParams[iCurValueIndex][0] = &m_szFileString[i+1];
szParams[iCurValueIndex][0] = &szFileString[i+1];
}
break;
case ':': // begins a new parameter
{
m_szFileString[i] = '\0';
szFileString[i] = '\0';
int iCurValueIndex = m_iNumValues-1;
m_iNumParams[iCurValueIndex] ++;
int iCurParamIndex = m_iNumParams[iCurValueIndex]-1;
m_szValuesAndParams[iCurValueIndex][iCurParamIndex] = &m_szFileString[i+1];
szParams[iCurValueIndex][iCurParamIndex] = &szFileString[i+1];
}
break;
case ';': // ends a value
{
m_szFileString[i] = '\0';
szFileString[i] = '\0';
// fast forward until just before the next '#'
while( m_szFileString[i+1] != '#' && i<iBytesRead )
while( szFileString[i+1] != '#' && i<iBytesRead )
i++;
ReadingValue=false;
}
break;
case '/':
if( m_szFileString[i+1] == '/' )
if( szFileString[i+1] == '/' )
{
// advance until new line
for( ; i<iBytesRead; i++ )
{
if( m_szFileString[i] == '\n' )
if( szFileString[i] == '\n' )
break;
else
m_szFileString[i] = ' ';
szFileString[i] = ' ';
}
}
// fall through. If we didn't take the if above, then this '/' is part of a parameter!
@@ -131,17 +129,18 @@ bool MsdFile::ReadFile( CString sNewPath )
}
}
m_szFileString[i] = '\0';
szFileString[i] = '\0';
for( i=0; i<m_iNumValues; i++ )
{
for( int j=0; j<m_iNumParams[i]; j++ )
{
m_sValuesAndParams[i][j] = m_szValuesAndParams[i][j];
m_sParams[i][j] = szParams[i][j];
}
}
fclose( fp );
delete [] szFileString;
return true;
}
+1 -4
View File
@@ -26,10 +26,7 @@ public:
//returns true if successful, false otherwise
bool ReadFile( CString sFilePath );
char* m_szFileString;
char* m_szValuesAndParams[MAX_VALUES][MAX_PARAMS_PER_VALUE];
CString m_sValuesAndParams[MAX_VALUES][MAX_PARAMS_PER_VALUE];
CString m_sParams[MAX_VALUES][MAX_PARAMS_PER_VALUE];
int m_iNumValues; // tells how many values are valid
int m_iNumParams[MAX_VALUES]; // tells how many params this value has
+1 -1
View File
@@ -255,7 +255,7 @@ bool DWILoader::LoadFromDWIFile( CString sPath, Song &out )
for( int i=0; i<msd.m_iNumValues; i++ )
{
int iNumParams = msd.m_iNumParams[i];
CString* sParams = msd.m_sValuesAndParams[i];
CString* sParams = msd.m_sParams[i];
CString sValueName = sParams[0];
// handle the data
+2 -2
View File
@@ -23,7 +23,7 @@ bool KSFLoader::LoadFromKSFFile( const CString &sPath, Notes &out )
for( int i=0; i<msd.m_iNumValues; i++ )
{
CString* sParams = msd.m_sValuesAndParams[i];
CString* sParams = msd.m_sParams[i];
CString sValueName = sParams[0];
// handle the data
@@ -169,7 +169,7 @@ bool KSFLoader::LoadFromDir( CString sDir, Song &out )
for( i=0; i<msd.m_iNumValues; i++ )
{
CString* sParams = msd.m_sValuesAndParams[i];
CString* sParams = msd.m_sParams[i];
CString sValueName = sParams[0];
// handle the data
+1 -1
View File
@@ -64,7 +64,7 @@ bool SMLoader::LoadFromSMFile( CString sPath, Song &out )
for( i=0; i<msd.m_iNumValues; i++ )
{
int iNumParams = msd.m_iNumParams[i];
CString* sParams = msd.m_sValuesAndParams[i];
CString* sParams = msd.m_sParams[i];
CString sValueName = sParams[0];
// handle the data