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
+1 -1
View File
@@ -20,7 +20,7 @@ bool CourseWriterCRS::Write( const Course &course, const CString &sPath, bool bS
return CourseWriterCRS::Write( course, f, bSavingCache ); return CourseWriterCRS::Write( course, f, bSavingCache );
} }
void CourseWriterCRS::GetEditFile( const Course *pCourse, CString &sOut ) void CourseWriterCRS::GetEditFileContents( const Course *pCourse, CString &sOut )
{ {
RageFileObjMem mem; RageFileObjMem mem;
CourseWriterCRS::Write( *pCourse, mem, true ); CourseWriterCRS::Write( *pCourse, mem, true );
+2 -1
View File
@@ -11,7 +11,8 @@ class CourseWriterCRS
public: public:
static bool Write( const Course &course, RageFileBasic &f, bool bSavingCache ); static bool Write( const Course &course, RageFileBasic &f, bool bSavingCache );
static bool Write( const Course &course, const CString &sPath, bool bSavingCache ); static bool Write( const Course &course, const CString &sPath, bool bSavingCache );
static void GetEditFile( const Course *pCourse, CString &sOut ); static void GetEditFileContents( const Course *pCourse, CString &sOut );
static void WriteEditFileToMachine( const Course *pCourse );
}; };
#endif #endif
+1
View File
@@ -40,6 +40,7 @@ public:
static void LoadTimingFromSMFile( const MsdFile &msd, TimingData &out ); static void LoadTimingFromSMFile( const MsdFile &msd, TimingData &out );
static bool LoadEdit( CString sEditFilePath, ProfileSlot slot ); static bool LoadEdit( CString sEditFilePath, ProfileSlot slot );
static bool LoadEditFromBuffer( const CString &sBuffer, CString sEditFilePath, ProfileSlot slot ); static bool LoadEditFromBuffer( const CString &sBuffer, CString sEditFilePath, ProfileSlot slot );
private:
static bool LoadEditFromMsd( const MsdFile &msd, CString sEditFilePath, ProfileSlot slot ); static bool LoadEditFromMsd( const MsdFile &msd, CString sEditFilePath, ProfileSlot slot );
}; };
+48 -3
View File
@@ -12,6 +12,8 @@
#include <cerrno> #include <cerrno>
#include "Foreach.h" #include "Foreach.h"
#include "BackgroundUtil.h" #include "BackgroundUtil.h"
#include "ProfileManager.h"
#include "Profile.h"
static CString BackgroundChangeToString( const BackgroundChange &bgc ) 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 // Save all Steps for this file
// //
const vector<Steps*>& vpSteps = out.GetAllSteps(); 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() ) if( pSteps->IsAutogen() )
continue; /* don't write autogen notes */ continue; /* don't write autogen notes */
@@ -239,7 +241,7 @@ bool NotesWriterSM::Write(CString sPath, const Song &out, bool bSavingCache)
return true; 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 = ""; sOut = "";
CString sDir = pSong->GetSongDir(); CString sDir = pSong->GetSongDir();
@@ -253,6 +255,49 @@ void NotesWriterSM::GetEditFile( const Song *pSong, const Steps *pSteps, CString
sOut += GetSMNotesTag( *pSong, *pSteps, false ); 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 * (c) 2001-2004 Chris Danford, Glenn Maynard
* All rights reserved. * All rights reserved.
+3 -1
View File
@@ -13,7 +13,9 @@ class NotesWriterSM
public: public:
bool Write( CString sPath, const Song &out, bool bSavingCache ); bool Write( CString sPath, const Song &out, bool bSavingCache );
static void GetEditFile( const Song *pSong, const Steps *pSteps, CString &sOut ); static void GetEditFileContents( const Song *pSong, const Steps *pSteps, CString &sOut );
CString GetEditFileName( const Song *pSong, const Steps *pSteps );
bool WriteEditFileToMachine( const Song *pSong, Steps *pSteps );
}; };
#endif #endif
+15 -1
View File
@@ -32,6 +32,7 @@
#include <utility> #include <utility>
#include <float.h> #include <float.h>
#include "InputEventPlus.h" #include "InputEventPlus.h"
#include "NotesWriterSM.h"
static Preference<float> g_iDefaultRecordLength( "DefaultRecordLength", 4 ); static Preference<float> g_iDefaultRecordLength( "DefaultRecordLength", 4 );
@@ -2546,6 +2547,18 @@ void ScreenEdit::HandleMainMenuChoice( MainMenuChoice c, const vector<int> &iAns
{ {
case EDIT_MODE_HOME: case EDIT_MODE_HOME:
{ {
ASSERT( pSteps->IsAnEdit() );
pSteps->SetSavedToDisk( true );
CopyToLastSave();
NotesWriterSM w;
w.WriteEditFileToMachine( pSong, pSteps );
SCREENMAN->ZeroNextUpdate();
/* FIXME
CString s; CString s;
switch( c ) switch( c )
{ {
@@ -2554,6 +2567,7 @@ void ScreenEdit::HandleMainMenuChoice( MainMenuChoice c, const vector<int> &iAns
default: ASSERT(0); default: ASSERT(0);
} }
SCREENMAN->AddNewScreenToTop( s ); SCREENMAN->AddNewScreenToTop( s );
*/
} }
break; break;
case EDIT_MODE_FULL: case EDIT_MODE_FULL:
@@ -2561,7 +2575,7 @@ void ScreenEdit::HandleMainMenuChoice( MainMenuChoice c, const vector<int> &iAns
pSteps->SetSavedToDisk( true ); pSteps->SetSavedToDisk( true );
CopyToLastSave(); CopyToLastSave();
GAMESTATE->m_pCurSong->Save(); pSong->Save();
SCREENMAN->ZeroNextUpdate(); SCREENMAN->ZeroNextUpdate();
// we shouldn't say we're saving a DWI if we're on any game besides // we shouldn't say we're saving a DWI if we're on any game besides
+1 -1
View File
@@ -292,7 +292,7 @@ bool Song::LoadFromSongDir( CString sDir )
FOREACH( Steps*, m_vpSteps, s ) FOREACH( Steps*, m_vpSteps, s )
{ {
(*s)->SetFile( GetCacheFilePath() ); (*s)->SetFilename( GetCacheFilePath() );
/* Compress all Steps. During initial caching, this will remove cached NoteData; /* Compress all Steps. During initial caching, this will remove cached NoteData;
* during cached loads, this will just remove cached SMData. */ * during cached loads, this will just remove cached SMData. */
-5
View File
@@ -321,11 +321,6 @@ bool Steps::IsAutogen() const
return parent != NULL; return parent != NULL;
} }
void Steps::SetFile( CString fn )
{
m_sFilename = fn;
}
void Steps::SetDifficultyAndDescription( Difficulty dc, CString sDescription ) void Steps::SetDifficultyAndDescription( Difficulty dc, CString sDescription )
{ {
DeAutogen(); DeAutogen();
+4 -3
View File
@@ -41,9 +41,10 @@ public:
int GetMeter() const { return Real()->m_iMeter; } int GetMeter() const { return Real()->m_iMeter; }
const RadarValues& GetRadarValues() const { return Real()->m_CachedRadarValues; } const RadarValues& GetRadarValues() const { return Real()->m_CachedRadarValues; }
void SetFile( CString fn ); void SetFilename( CString fn ) { m_sFilename = fn; }
CString GetFilename() const { return m_sFilename; }
void SetSavedToDisk( bool b ) { m_bSavedToDisk = b; } void SetSavedToDisk( bool b ) { m_bSavedToDisk = b; }
bool GetSavedToDisk() { return m_bSavedToDisk; } bool GetSavedToDisk() const { return m_bSavedToDisk; }
void SetDifficultyAndDescription( Difficulty dc, CString sDescription ); void SetDifficultyAndDescription( Difficulty dc, CString sDescription );
void SetDifficulty( Difficulty dc ) { SetDifficultyAndDescription( dc, this->GetDescription() ); } void SetDifficulty( Difficulty dc ) { SetDifficultyAndDescription( dc, this->GetDescription() ); }
void SetDescription( CString sDescription ) { SetDifficultyAndDescription( this->GetDifficulty(), sDescription ); } void SetDescription( CString sDescription ) { SetDifficultyAndDescription( this->GetDifficulty(), sDescription ); }
@@ -83,7 +84,7 @@ protected:
const Steps *Real() const; const Steps *Real() const;
CString m_sFilename; CString m_sFilename;
bool m_bSavedToDisk; // true if this was loaded from disk or has been saved to disk. bool m_bSavedToDisk; // true if this was loaded from disk or has been saved to disk.
/* These values are pulled from the autogen source first, if there is one. */ /* These values are pulled from the autogen source first, if there is one. */
ProfileSlot m_LoadedFromProfile; // ProfileSlot_INVALID if wasn't loaded from a profile ProfileSlot m_LoadedFromProfile; // ProfileSlot_INVALID if wasn't loaded from a profile