More loops and count_ifs.
This commit is contained in:
+18
-33
@@ -28,26 +28,19 @@ RString ClearMachineStats()
|
|||||||
static LocalizedString MACHINE_EDITS_CLEARED( "ScreenServiceAction", "%d edits cleared, %d errors." );
|
static LocalizedString MACHINE_EDITS_CLEARED( "ScreenServiceAction", "%d edits cleared, %d errors." );
|
||||||
static RString ClearMachineEdits()
|
static RString ClearMachineEdits()
|
||||||
{
|
{
|
||||||
int iNumAttempted = 0;
|
|
||||||
int iNumSuccessful = 0;
|
|
||||||
|
|
||||||
vector<RString> vsEditFiles;
|
vector<RString> vsEditFiles;
|
||||||
GetDirListing( PROFILEMAN->GetProfileDir(ProfileSlot_Machine)+EDIT_STEPS_SUBDIR+"*.edit", vsEditFiles, false, true );
|
GetDirListing( PROFILEMAN->GetProfileDir(ProfileSlot_Machine)+EDIT_STEPS_SUBDIR+"*.edit", vsEditFiles, false, true );
|
||||||
GetDirListing( PROFILEMAN->GetProfileDir(ProfileSlot_Machine)+EDIT_COURSES_SUBDIR+"*.crs", vsEditFiles, false, true );
|
GetDirListing( PROFILEMAN->GetProfileDir(ProfileSlot_Machine)+EDIT_COURSES_SUBDIR+"*.crs", vsEditFiles, false, true );
|
||||||
FOREACH_CONST( RString, vsEditFiles, i )
|
|
||||||
{
|
int editCount = vsEditFiles.size();
|
||||||
iNumAttempted++;
|
int removedCount = std::count_if(vsEditFiles.begin(), vsEditFiles.end(), [](RString const &i) { return FILEMAN->Remove(i); });
|
||||||
bool bSuccess = FILEMAN->Remove( *i );
|
|
||||||
if( bSuccess )
|
|
||||||
iNumSuccessful++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// reload the machine profile
|
// reload the machine profile
|
||||||
PROFILEMAN->SaveMachineProfile();
|
PROFILEMAN->SaveMachineProfile();
|
||||||
PROFILEMAN->LoadMachineProfile();
|
PROFILEMAN->LoadMachineProfile();
|
||||||
|
|
||||||
int iNumErrors = iNumAttempted-iNumSuccessful;
|
int errorCount = editCount - removedCount;
|
||||||
return ssprintf(MACHINE_EDITS_CLEARED.GetValue(),iNumSuccessful,iNumErrors);
|
return ssprintf(MACHINE_EDITS_CLEARED.GetValue(), editCount, errorCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PlayerNumber GetFirstReadyMemoryCard()
|
static PlayerNumber GetFirstReadyMemoryCard()
|
||||||
@@ -73,9 +66,6 @@ static RString ClearMemoryCardEdits()
|
|||||||
if( pn == PLAYER_INVALID )
|
if( pn == PLAYER_INVALID )
|
||||||
return MEMORY_CARD_EDITS_NOT_CLEARED.GetValue();
|
return MEMORY_CARD_EDITS_NOT_CLEARED.GetValue();
|
||||||
|
|
||||||
int iNumAttempted = 0;
|
|
||||||
int iNumSuccessful = 0;
|
|
||||||
|
|
||||||
if( !MEMCARDMAN->IsMounted(pn) )
|
if( !MEMCARDMAN->IsMounted(pn) )
|
||||||
MEMCARDMAN->MountCard(pn);
|
MEMCARDMAN->MountCard(pn);
|
||||||
|
|
||||||
@@ -83,17 +73,12 @@ static RString ClearMemoryCardEdits()
|
|||||||
vector<RString> vsEditFiles;
|
vector<RString> vsEditFiles;
|
||||||
GetDirListing( sDir+EDIT_STEPS_SUBDIR+"*.edit", vsEditFiles, false, true );
|
GetDirListing( sDir+EDIT_STEPS_SUBDIR+"*.edit", vsEditFiles, false, true );
|
||||||
GetDirListing( sDir+EDIT_COURSES_SUBDIR+"*.crs", vsEditFiles, false, true );
|
GetDirListing( sDir+EDIT_COURSES_SUBDIR+"*.crs", vsEditFiles, false, true );
|
||||||
FOREACH_CONST( RString, vsEditFiles, i )
|
int editCount = vsEditFiles.size();
|
||||||
{
|
int removedCount = std::count_if(vsEditFiles.begin(), vsEditFiles.end(), [](RString const &i) { return FILEMAN->Remove(i); });
|
||||||
iNumAttempted++;
|
|
||||||
bool bSuccess = FILEMAN->Remove( *i );
|
|
||||||
if( bSuccess )
|
|
||||||
iNumSuccessful++;
|
|
||||||
}
|
|
||||||
|
|
||||||
MEMCARDMAN->UnmountCard(pn);
|
MEMCARDMAN->UnmountCard(pn);
|
||||||
|
|
||||||
return ssprintf(EDITS_CLEARED.GetValue(),iNumSuccessful,iNumAttempted-iNumSuccessful);
|
return ssprintf(EDITS_CLEARED.GetValue(), editCount, editCount - removedCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -177,11 +162,11 @@ static void CopyEdits( const RString &sFromProfileDir, const RString &sToProfile
|
|||||||
|
|
||||||
vector<RString> vsFiles;
|
vector<RString> vsFiles;
|
||||||
GetDirListing( sFromDir+"*.edit", vsFiles, false, false );
|
GetDirListing( sFromDir+"*.edit", vsFiles, false, false );
|
||||||
FOREACH_CONST( RString, vsFiles, i )
|
for (RString const &i : vsFiles)
|
||||||
{
|
{
|
||||||
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 )
|
||||||
iNumSucceeded++;
|
iNumSucceeded++;
|
||||||
else
|
else
|
||||||
@@ -189,7 +174,7 @@ static void CopyEdits( const RString &sFromProfileDir, const RString &sToProfile
|
|||||||
|
|
||||||
// Test whether the song we need for this edit is present and ignore this edit if not present.
|
// Test whether the song we need for this edit is present and ignore this edit if not present.
|
||||||
SSCLoader loaderSSC;
|
SSCLoader loaderSSC;
|
||||||
if( !loaderSSC.LoadEditFromFile( sFromDir+*i, ProfileSlot_Machine, false ) )
|
if( !loaderSSC.LoadEditFromFile( sFromDir + i, ProfileSlot_Machine, false ) )
|
||||||
{
|
{
|
||||||
iNumIgnored++;
|
iNumIgnored++;
|
||||||
continue;
|
continue;
|
||||||
@@ -205,11 +190,11 @@ static void CopyEdits( const RString &sFromProfileDir, const RString &sToProfile
|
|||||||
|
|
||||||
vector<RString> vsFiles;
|
vector<RString> vsFiles;
|
||||||
GetDirListing( sFromDir+"*.crs", vsFiles, false, false );
|
GetDirListing( sFromDir+"*.crs", vsFiles, false, false );
|
||||||
FOREACH_CONST( RString, vsFiles, i )
|
for (RString const &i : vsFiles)
|
||||||
{
|
{
|
||||||
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 )
|
||||||
iNumSucceeded++;
|
iNumSucceeded++;
|
||||||
else
|
else
|
||||||
@@ -366,12 +351,12 @@ static RString CopyEditsMemoryCardToMachine()
|
|||||||
vector<RString> vs;
|
vector<RString> vs;
|
||||||
vs.push_back( ssprintf( COPIED_FROM_CARD.GetValue(), pn+1 ) );
|
vs.push_back( ssprintf( COPIED_FROM_CARD.GetValue(), pn+1 ) );
|
||||||
|
|
||||||
FOREACH_CONST( RString, vsSubDirs, sSubDir )
|
for (RString const &sSubDir : vsSubDirs)
|
||||||
{
|
{
|
||||||
RString sFromDir = MEM_CARD_MOUNT_POINT[pn] + (RString)(*sSubDir) + "/";
|
RString sFromDir = MEM_CARD_MOUNT_POINT[pn] + sSubDir + "/";
|
||||||
RString sToDir = PROFILEMAN->GetProfileDir(ProfileSlot_Machine);
|
RString sToDir = PROFILEMAN->GetProfileDir(ProfileSlot_Machine);
|
||||||
|
|
||||||
RString s = CopyEdits( sFromDir, sToDir, *sSubDir );
|
RString s = CopyEdits( sFromDir, sToDir, sSubDir );
|
||||||
vs.push_back( s );
|
vs.push_back( s );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user