test whether the song required for an edit is present before copying it. Fixes "game said it copied N edits, but none of them are showing".

This commit is contained in:
Chris Danford
2006-03-27 20:17:05 +00:00
parent 9bee8d3b4a
commit 6efb162723
6 changed files with 46 additions and 28 deletions
+1 -1
View File
@@ -348,7 +348,7 @@ bool CourseLoaderCRS::LoadFromCRSFile( const RString &_sPath, Course &out )
return true; return true;
} }
bool CourseLoaderCRS::LoadEdit( const RString &sEditFilePath, ProfileSlot slot ) bool CourseLoaderCRS::LoadEditFromFile( const RString &sEditFilePath, ProfileSlot slot )
{ {
LOG->Trace( "CourseLoaderCRS::LoadEdit(%s)", sEditFilePath.c_str() ); LOG->Trace( "CourseLoaderCRS::LoadEdit(%s)", sEditFilePath.c_str() );
+1 -1
View File
@@ -13,7 +13,7 @@ public:
static bool LoadFromCRSFile( const RString &sPath, Course &out ); static bool LoadFromCRSFile( const RString &sPath, Course &out );
static bool LoadFromMsd( const RString &sPath, const MsdFile &msd, Course &out, bool bFromCache ); static bool LoadFromMsd( const RString &sPath, const MsdFile &msd, Course &out, bool bFromCache );
static bool LoadFromBuffer( const RString &sPath, const RString &sBuffer, Course &out ); static bool LoadFromBuffer( const RString &sPath, const RString &sBuffer, Course &out );
static bool LoadEdit( const RString &sEditFilePath, ProfileSlot slot ); static bool LoadEditFromFile( const RString &sEditFilePath, ProfileSlot slot );
static bool LoadEditFromBuffer( const RString &sBuffer, const RString &sPath, ProfileSlot slot ); static bool LoadEditFromBuffer( const RString &sBuffer, const RString &sPath, ProfileSlot slot );
}; };
+8 -5
View File
@@ -462,9 +462,9 @@ bool SMLoader::LoadFromDir( const RString &sPath, Song &out )
return LoadFromSMFile( sPath + aFileNames[0], out ); return LoadFromSMFile( sPath + aFileNames[0], out );
} }
bool SMLoader::LoadEdit( RString sEditFilePath, ProfileSlot slot ) bool SMLoader::LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong )
{ {
LOG->Trace( "SMLoader::LoadEdit(%s)", sEditFilePath.c_str() ); LOG->Trace( "SMLoader::LoadEditFromFile(%s)", sEditFilePath.c_str() );
int iBytes = FILEMAN->GetFileSizeInBytes( sEditFilePath ); int iBytes = FILEMAN->GetFileSizeInBytes( sEditFilePath );
if( iBytes > MAX_EDIT_STEPS_SIZE_BYTES ) if( iBytes > MAX_EDIT_STEPS_SIZE_BYTES )
@@ -480,17 +480,17 @@ bool SMLoader::LoadEdit( RString sEditFilePath, ProfileSlot slot )
return false; return false;
} }
return LoadEditFromMsd( msd, sEditFilePath, slot ); return LoadEditFromMsd( msd, sEditFilePath, slot, bAddStepsToSong );
} }
bool SMLoader::LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot ) bool SMLoader::LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot )
{ {
MsdFile msd; MsdFile msd;
msd.ReadFromString( sBuffer ); msd.ReadFromString( sBuffer );
return LoadEditFromMsd( msd, sEditFilePath, slot ); return LoadEditFromMsd( msd, sEditFilePath, slot, true );
} }
bool SMLoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot ) bool SMLoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong )
{ {
Song* pSong = NULL; Song* pSong = NULL;
@@ -541,6 +541,9 @@ bool SMLoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath
continue; continue;
} }
if( !bAddStepsToSong )
return true;
Steps* pNewNotes = new Steps; Steps* pNewNotes = new Steps;
LoadFromSMTokens( LoadFromSMTokens(
sParams[1], sParams[2], sParams[3], sParams[4], sParams[5], sParams[6], sParams[1], sParams[2], sParams[3], sParams[4], sParams[5], sParams[6],
+2 -3
View File
@@ -38,10 +38,9 @@ public:
void TidyUpData( Song &song, bool cache ); void TidyUpData( Song &song, bool cache );
static bool LoadTimingFromFile( const RString &fn, TimingData &out ); static bool LoadTimingFromFile( const RString &fn, TimingData &out );
static void LoadTimingFromSMFile( const MsdFile &msd, TimingData &out ); static void LoadTimingFromSMFile( const MsdFile &msd, TimingData &out );
static bool LoadEdit( RString sEditFilePath, ProfileSlot slot ); static bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong );
static bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot ); static bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot );
private: static bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong );
static bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot );
}; };
#endif #endif
+32 -16
View File
@@ -15,6 +15,7 @@
#include "PlayerState.h" #include "PlayerState.h"
#include "LocalizedString.h" #include "LocalizedString.h"
#include "StepMania.h" #include "StepMania.h"
#include "NotesLoaderSM.h"
static LocalizedString BOOKKEEPING_DATA_CLEARED( "ScreenServiceAction", "Bookkeeping data cleared." ); static LocalizedString BOOKKEEPING_DATA_CLEARED( "ScreenServiceAction", "Bookkeeping data cleared." );
static RString ClearBookkeepingData() static RString ClearBookkeepingData()
@@ -175,11 +176,12 @@ static RString TransferStatsMemoryCardToMachine()
return s; return s;
} }
static void CopyEdits( const RString &sFromProfileDir, const RString &sToProfileDir, int &iNumAttempted, int &iNumSuccessful, int &iNumOverwritten ) static void CopyEdits( const RString &sFromProfileDir, const RString &sToProfileDir, int &iNumSucceeded, int &iNumOverwritten, int &iNumIgnored, int &iNumErrored )
{ {
iNumAttempted = 0; iNumSucceeded = 0;
iNumSuccessful = 0;
iNumOverwritten = 0; iNumOverwritten = 0;
iNumIgnored = 0;
iNumErrored = 0;
{ {
RString sFromDir = sFromProfileDir + EDIT_STEPS_SUBDIR; RString sFromDir = sFromProfileDir + EDIT_STEPS_SUBDIR;
@@ -189,17 +191,27 @@ static void CopyEdits( const RString &sFromProfileDir, const RString &sToProfile
GetDirListing( sFromDir+"*.edit", vsFiles, false, false ); GetDirListing( sFromDir+"*.edit", vsFiles, false, false );
FOREACH_CONST( RString, vsFiles, i ) FOREACH_CONST( RString, vsFiles, i )
{ {
iNumAttempted++;
if( DoesFileExist(sToDir+*i) ) if( DoesFileExist(sToDir+*i) )
iNumOverwritten++; iNumOverwritten++;
bool bSuccess = FileCopy( sFromDir+*i, sToDir+*i ); bool bSuccess = FileCopy( sFromDir+*i, sToDir+*i );
if( bSuccess ) if( bSuccess )
iNumSuccessful++; iNumSucceeded++;
else
iNumErrored++;
// Test whether the song we need for this edit is present and ignore this edit if not present.
if( !SMLoader::LoadEditFromFile( sFromDir+*i, ProfileSlot_Machine, false ) )
{
iNumIgnored++;
continue;
}
} }
FILEMAN->FlushDirCache( sToDir ); FILEMAN->FlushDirCache( sToDir );
} }
// TODO: Seprarate copying stats for steps and courses
{ {
RString sFromDir = sFromProfileDir + EDIT_COURSES_SUBDIR; RString sFromDir = sFromProfileDir + EDIT_COURSES_SUBDIR;
RString sToDir = sToProfileDir + EDIT_COURSES_SUBDIR; RString sToDir = sToProfileDir + EDIT_COURSES_SUBDIR;
@@ -208,12 +220,13 @@ static void CopyEdits( const RString &sFromProfileDir, const RString &sToProfile
GetDirListing( sFromDir+"*.crs", vsFiles, false, false ); GetDirListing( sFromDir+"*.crs", vsFiles, false, false );
FOREACH_CONST( RString, vsFiles, i ) FOREACH_CONST( RString, vsFiles, i )
{ {
iNumAttempted++;
if( DoesFileExist(sToDir+*i) ) if( DoesFileExist(sToDir+*i) )
iNumOverwritten++; iNumOverwritten++;
bool bSuccess = FileCopy( sFromDir+*i, sToDir+*i ); bool bSuccess = FileCopy( sFromDir+*i, sToDir+*i );
if( bSuccess ) if( bSuccess )
iNumSuccessful++; iNumSucceeded++;
else
iNumErrored++;
} }
FILEMAN->FlushDirCache( sToDir ); FILEMAN->FlushDirCache( sToDir );
@@ -225,24 +238,27 @@ static LocalizedString EDITS_NOT_COPIED ( "ScreenServiceAction", "Edits not cop
static LocalizedString COPIED_TO_CARD ( "ScreenServiceAction", "Copied to P%d card:" ); static LocalizedString COPIED_TO_CARD ( "ScreenServiceAction", "Copied to P%d card:" );
static LocalizedString COPIED ( "ScreenServiceAction", "%d copied" ); static LocalizedString COPIED ( "ScreenServiceAction", "%d copied" );
static LocalizedString OVERWRITTEN ( "ScreenServiceAction", "%d overwritten" ); static LocalizedString OVERWRITTEN ( "ScreenServiceAction", "%d overwritten" );
static LocalizedString ADDED_AND_OVERWRITTEN ( "ScreenServiceAction", "%d added, %d overwritten" ); static LocalizedString ADDED ( "ScreenServiceAction", "%d added" );
static LocalizedString IGNORED ( "ScreenServiceAction", "%d ignored" );
static LocalizedString FAILED ( "ScreenServiceAction", "%d failed" ); static LocalizedString FAILED ( "ScreenServiceAction", "%d failed" );
static LocalizedString DELETED ( "ScreenServiceAction", "%d deleted" ); static LocalizedString DELETED ( "ScreenServiceAction", "%d deleted" );
static RString CopyEdits( const RString &sFromProfileDir, const RString &sToProfileDir, const RString &sDisplayDir ) static RString CopyEdits( const RString &sFromProfileDir, const RString &sToProfileDir, const RString &sDisplayDir )
{ {
int iNumAttempted = 0; int iNumSucceeded = 0;
int iNumSuccessful = 0;
int iNumOverwritten = 0; int iNumOverwritten = 0;
int iNumIgnored = 0;
int iNumErrored = 0;
CopyEdits( sFromProfileDir, sToProfileDir, iNumAttempted, iNumSuccessful, iNumOverwritten ); CopyEdits( sFromProfileDir, sToProfileDir, iNumSucceeded, iNumOverwritten, iNumIgnored, iNumErrored );
vector<RString> vs; vector<RString> vs;
vs.push_back( sDisplayDir ); vs.push_back( sDisplayDir );
vs.push_back( ssprintf( COPIED.GetValue(), iNumSuccessful ) ); vs.push_back( ssprintf( COPIED.GetValue(), iNumSucceeded ) + ", " + ssprintf( OVERWRITTEN.GetValue(), iNumOverwritten ) );
vs.push_back( ssprintf( OVERWRITTEN.GetValue(), iNumOverwritten ) ); if( iNumIgnored )
if( iNumSuccessful < iNumAttempted ) vs.push_back( ssprintf( IGNORED.GetValue(), iNumIgnored ) );
vs.push_back( ssprintf( FAILED.GetValue(), iNumAttempted-iNumSuccessful ) ); if( iNumErrored )
vs.push_back( ssprintf( FAILED.GetValue(), iNumErrored ) );
return join( "\n", vs ); return join( "\n", vs );
} }
@@ -343,7 +359,7 @@ static RString SyncEditsMachineToMemoryCard()
MEMCARDMAN->UnmountCard(pn); MEMCARDMAN->UnmountCard(pn);
RString sRet = ssprintf( COPIED_TO_CARD.GetValue(), pn+1 ) + " "; RString sRet = ssprintf( COPIED_TO_CARD.GetValue(), pn+1 ) + " ";
sRet += ssprintf( ADDED_AND_OVERWRITTEN.GetValue(), iNumAdded, iNumOverwritten ); sRet += ssprintf( ADDED.GetValue(), iNumAdded ) + ", " + ssprintf( OVERWRITTEN.GetValue(), iNumOverwritten );
if( iNumDeleted ) if( iNumDeleted )
sRet += RString(" ") + ssprintf( DELETED.GetValue(), iNumDeleted ); sRet += RString(" ") + ssprintf( DELETED.GetValue(), iNumDeleted );
if( iNumFailed ) if( iNumFailed )
+2 -2
View File
@@ -1395,7 +1395,7 @@ void SongManager::LoadAllFromProfileDir( const RString &sProfileDir, ProfileSlot
{ {
RString fn = vsFiles[i]; RString fn = vsFiles[i];
SMLoader::LoadEdit( fn, slot ); SMLoader::LoadEditFromFile( fn, slot, true );
} }
} }
@@ -1415,7 +1415,7 @@ void SongManager::LoadAllFromProfileDir( const RString &sProfileDir, ProfileSlot
{ {
RString fn = vsFiles[i]; RString fn = vsFiles[i];
CourseLoaderCRS::LoadEdit( fn, slot ); CourseLoaderCRS::LoadEditFromFile( fn, slot );
} }
} }
} }