cache m_sSongFileName

This commit is contained in:
Glenn Maynard
2003-12-30 02:46:47 +00:00
parent f89940ac02
commit 5ec05b31ba
3 changed files with 52 additions and 42 deletions
+10 -1
View File
@@ -147,7 +147,7 @@ bool SMLoader::LoadFromSMFile( CString sPath, Song &out )
{
int iNumParams = msd.GetNumParams(i);
const MsdFile::value_t &sParams = msd.GetValue(i);
const CString sValueName = sParams[0];
const CString &sValueName = sParams[0];
// handle the data
if( 0==stricmp(sValueName,"TITLE") )
@@ -214,6 +214,15 @@ bool SMLoader::LoadFromSMFile( CString sPath, Song &out )
}
out.m_fLastBeat = (float)atof( sParams[1] );
}
else if( 0==stricmp(sValueName,"SONGFILENAME") )
{
if(!FromCache)
{
LOG->Trace("Ignored #SONGFILENAME (cache only)");
continue;
}
out.m_sSongFileName = sParams[1];
}
else if( 0==stricmp(sValueName,"SAMPLESTART") )
out.m_fMusicSampleStartSeconds = TimeToSeconds( sParams[1] );
+1
View File
@@ -171,6 +171,7 @@ bool NotesWriterSM::Write(CString sPath, const Song &out, bool bSavingCache)
{
f.PutLine( ssprintf( "#FIRSTBEAT:%.3f;\n", out.m_fFirstBeat ) );
f.PutLine( ssprintf( "#LASTBEAT:%.3f;\n", out.m_fLastBeat ) );
f.PutLine( ssprintf( "#SONGFILENAME:%s;\n", out.m_sSongFileName.c_str() ) );
}
//
+40 -40
View File
@@ -50,7 +50,7 @@
#define CACHE_DIR "Cache/"
const int FILE_CACHE_VERSION = 131; // increment this when Song or Steps changes to invalidate cache
const int FILE_CACHE_VERSION = 132; // increment this when Song or Steps changes to invalidate cache
const float DEFAULT_MUSIC_SAMPLE_LENGTH = 12.f;
@@ -249,45 +249,6 @@ bool Song::LoadFromSongDir( CString sDir, bool bAllowCache )
if( HasBanner() )
BANNERCACHE->LoadBanner( GetBannerPath() );
{
/* Generated filename; this doesn't always point to a loadable file,
* but instead points to the file we should write changed files to,
* and will always be an .SM.
*
* This is a little tricky. We can't always use the song title directly,
* since it might contain characters we can't store in filenames. Two
* easy options: we could manually filter out invalid characters, or we
* could use the name of the directory, which is always a valid filename
* and should always be the same as the song. The former might not catch
* everything--filename restrictions are platform-specific; we might even
* be on an 8.3 filesystem, so let's do the latter.
*
* We can't rely on searching for other data filenames; it works for DWIs,
* but not KSFs and BMSs.
*
* So, let's do this (by priority):
* 1. If there's an .SM file, use that filename. No reason to use anything
* else; it's the filename in use.
* 2. If there's a .DWI, use it with a changed extension.
* 3. Otherwise, use the name of the directory, since it's definitely a valid
* filename, and should always be the title of the song (unlike KSFs).
*/
m_sSongFileName = m_sSongDir;
CStringArray asFileNames;
GetDirListing( m_sSongDir+"*.sm", asFileNames );
if( !asFileNames.empty() )
m_sSongFileName += asFileNames[0];
else {
GetDirListing( m_sSongDir+"*.dwi", asFileNames );
if( !asFileNames.empty() ) {
m_sSongFileName += SetExtension( asFileNames[0], "sm" );
} else {
m_sSongFileName += sDirectoryParts[sDirectoryParts.size()-2]; // last item
m_sSongFileName += ".sm";
}
}
}
/* Add AutoGen pointers. (These aren't cached.) */
AddAutoGenNotes();
@@ -764,6 +725,45 @@ void Song::TidyUpData()
}
}
{
/* Generated filename; this doesn't always point to a loadable file,
* but instead points to the file we should write changed files to,
* and will always be an .SM.
*
* This is a little tricky. We can't always use the song title directly,
* since it might contain characters we can't store in filenames. Two
* easy options: we could manually filter out invalid characters, or we
* could use the name of the directory, which is always a valid filename
* and should always be the same as the song. The former might not catch
* everything--filename restrictions are platform-specific; we might even
* be on an 8.3 filesystem, so let's do the latter.
*
* We can't rely on searching for other data filenames; it works for DWIs,
* but not KSFs and BMSs.
*
* So, let's do this (by priority):
* 1. If there's an .SM file, use that filename. No reason to use anything
* else; it's the filename in use.
* 2. If there's a .DWI, use it with a changed extension.
* 3. Otherwise, use the name of the directory, since it's definitely a valid
* filename, and should always be the title of the song (unlike KSFs).
*/
m_sSongFileName = m_sSongDir;
CStringArray asFileNames;
GetDirListing( m_sSongDir+"*.sm", asFileNames );
if( !asFileNames.empty() )
m_sSongFileName += asFileNames[0];
else {
GetDirListing( m_sSongDir+"*.dwi", asFileNames );
if( !asFileNames.empty() ) {
m_sSongFileName += SetExtension( asFileNames[0], "sm" );
} else {
m_sSongFileName += Basename(m_sSongDir);
m_sSongFileName += ".sm";
}
}
}
// Compress all Steps
for( i=0; i<m_apNotes.size(); i++ )