save edits to machine profile

This commit is contained in:
Chris Danford
2005-12-03 20:34:49 +00:00
parent 6647949a00
commit 9e8469eb65
9 changed files with 75 additions and 16 deletions
+48 -3
View File
@@ -12,6 +12,8 @@
#include <cerrno>
#include "Foreach.h"
#include "BackgroundUtil.h"
#include "ProfileManager.h"
#include "Profile.h"
static CString BackgroundChangeToString( const BackgroundChange &bgc )
{
@@ -222,9 +224,9 @@ bool NotesWriterSM::Write(CString sPath, const Song &out, bool bSavingCache)
// Save all Steps for this file
//
const vector<Steps*>& vpSteps = out.GetAllSteps();
for( unsigned i=0; i<vpSteps.size(); i++ )
FOREACH_CONST( Steps*, vpSteps, s )
{
const Steps* pSteps = vpSteps[i];
const Steps* pSteps = *s;
if( pSteps->IsAutogen() )
continue; /* don't write autogen notes */
@@ -239,7 +241,7 @@ bool NotesWriterSM::Write(CString sPath, const Song &out, bool bSavingCache)
return true;
}
void NotesWriterSM::GetEditFile( const Song *pSong, const Steps *pSteps, CString &sOut )
void NotesWriterSM::GetEditFileContents( const Song *pSong, const Steps *pSteps, CString &sOut )
{
sOut = "";
CString sDir = pSong->GetSongDir();
@@ -253,6 +255,49 @@ void NotesWriterSM::GetEditFile( const Song *pSong, const Steps *pSteps, CString
sOut += GetSMNotesTag( *pSong, *pSteps, false );
}
CString NotesWriterSM::GetEditFileName( const Song *pSong, const Steps *pSteps )
{
// guaranteed to be a unique name
return pSong->GetTranslitFullTitle() + " - " + pSteps->GetDescription();
}
bool NotesWriterSM::WriteEditFileToMachine( const Song *pSong, Steps *pSteps )
{
ASSERT( pSteps->WasLoadedFromProfile() );
CString sDir = PROFILEMAN->GetProfileDir( ProfileSlot_Machine ) + EDIT_STEPS_SUBDIR;
/* If the file name of the edit has changed since the last save, then delete the old
* file before saving the new one.
*/
bool bFileNameChanged =
pSteps->GetSavedToDisk() &&
pSteps->GetFilename() != GetEditFileName(pSong,pSteps);
if( bFileNameChanged )
FILEMAN->Remove( pSteps->GetFilename() );
CString sPath = sDir + GetEditFileName(pSong,pSteps);
pSteps->SetFilename( sPath );
/* Flush dir cache when writing steps, so the old size isn't cached. */
FILEMAN->FlushDirCache( Dirname(sPath) );
int flags = RageFile::WRITE | RageFile::SLOW_FLUSH;
RageFile f;
if( !f.Open( sPath, flags ) )
{
LOG->Warn( "Error opening song file '%s' for writing: %s", sPath.c_str(), f.GetError().c_str() );
return false;
}
CString sTag;
GetEditFileContents( pSong, pSteps, sTag );
f.PutLine( sTag );
return true;
}
/*
* (c) 2001-2004 Chris Danford, Glenn Maynard
* All rights reserved.