From: <sag...@us...> - 2013-04-22 15:31:04
|
Revision: 1930 http://sourceforge.net/p/modplug/code/1930 Author: saga-games Date: 2013-04-22 15:30:53 +0000 (Mon, 22 Apr 2013) Log Message: ----------- [Mod] Dont's show message log during autosave. Modified Paths: -------------- trunk/OpenMPT/mptrack/AutoSaver.cpp trunk/OpenMPT/mptrack/AutoSaver.h trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Moddoc.h Modified: trunk/OpenMPT/mptrack/AutoSaver.cpp =================================================================== --- trunk/OpenMPT/mptrack/AutoSaver.cpp 2013-04-21 20:57:27 UTC (rev 1929) +++ trunk/OpenMPT/mptrack/AutoSaver.cpp 2013-04-22 15:30:53 UTC (rev 1930) @@ -59,48 +59,34 @@ //------------------------------------ { bool success = true; - + //If time to save and not already having save in progress. if (CheckTimer(curTime) && !m_bSaveInProgress) { m_bSaveInProgress = true; - CDocTemplate *pDocTemplate; - CModDoc *pModDoc; - POSITION posTemplate,posDocument; - CTrackApp *pTrackApp=(CTrackApp*)::AfxGetApp(); - if (!pTrackApp) - { - m_bSaveInProgress = false; - return false; - } - pTrackApp->BeginWaitCursor(); //display hour glass + theApp.BeginWaitCursor(); //display hour glass - posTemplate = pTrackApp->GetFirstDocTemplatePosition(); - while (posTemplate) { //for all "templates" (we should have just 1) - pDocTemplate = pTrackApp->GetNextDocTemplate(posTemplate); - posDocument = pDocTemplate->GetFirstDocPosition(); - - while (posDocument) //for all open documents + std::vector<CModDoc *> docs = theApp.GetOpenDocuments(); + for(std::vector<CModDoc *>::iterator doc = docs.begin(); doc != docs.end(); doc++) + { + CModDoc &modDoc = **doc; + if(modDoc.ModifiedSinceLastAutosave()) { - pModDoc = (CModDoc*)(pDocTemplate->GetNextDoc(posDocument)); - if(pModDoc && pModDoc->ModifiedSinceLastAutosave()) + if(SaveSingleFile(modDoc)) { - if (SaveSingleFile(pModDoc)) - { - CleanUpBackups(pModDoc); - } else - { - m_bEnabled = false; - Reporting::Warning("Warning: Autosave failed and has been disabled. Please:\n- Review your autosave paths\n- Check available diskspace & filesystem access rights\n- If you are using the ITP format, ensure all instruments exist as independant .iti files"); - success = false; - } + CleanUpBackups(modDoc); + } else + { + m_bEnabled = false; + Reporting::Warning("Warning: Autosave failed and has been disabled. Please:\n- Review your autosave paths\n- Check available diskspace & filesystem access rights\n- If you are using the ITP format, ensure all instruments exist as independant .iti files"); + success = false; } - } //end all open documents + } + } - } //end pointless template loop (we have just 1 template) m_nLastSave = timeGetTime(); - pTrackApp->EndWaitCursor(); //end display hour glass + theApp.EndWaitCursor(); //end display hour glass m_bSaveInProgress = false; } @@ -220,56 +206,57 @@ } -CString CAutoSaver::BuildFileName(CModDoc* pModDoc) -//------------------------------------------------- +CString CAutoSaver::BuildFileName(CModDoc &modDoc) +//------------------------------------------------ { CString timeStamp = (CTime::GetCurrentTime()).Format("%Y%m%d.%H%M%S"); CString name; - if (m_bUseOriginalPath) + if(m_bUseOriginalPath) { - if (pModDoc->m_bHasValidPath) + if(modDoc.m_bHasValidPath) { // Check that the file has a user-chosen path - name = pModDoc->GetPathName(); + name = modDoc.GetPathName(); } else { // if it doesnt, put it in settings dir - name = theApp.GetConfigPath() + pModDoc->GetTitle(); + name = theApp.GetConfigPath() + modDoc.GetTitle(); } - } else { - name = m_csPath+pModDoc->GetTitle(); + name = m_csPath+modDoc.GetTitle(); } - name.Append(".AutoSave."); //append backup tag name.Append(timeStamp); //append timestamp name.Append("."); //append extension - if(pModDoc->GetrSoundFile().m_SongFlags[SONG_ITPROJECT]) + if(modDoc.GetrSoundFile().m_SongFlags[SONG_ITPROJECT]) { name.Append("itp"); } else { - name.Append(pModDoc->GetrSoundFile().GetModSpecifications().fileExtension); + name.Append(modDoc.GetrSoundFile().GetModSpecifications().fileExtension); } return name; } -bool CAutoSaver::SaveSingleFile(CModDoc *pModDoc) -//----------------------------------------------- +bool CAutoSaver::SaveSingleFile(CModDoc &modDoc) +//---------------------------------------------- { // We do not call CModDoc::DoSave as this populates the Recent Files // list with backups... hence we have duplicated code.. :( - bool success = false; - CSoundFile &sndFile = pModDoc->GetrSoundFile(); + CSoundFile &sndFile = modDoc.GetrSoundFile(); - CString fileName = BuildFileName(pModDoc); + CString fileName = BuildFileName(modDoc); - switch (pModDoc->GetModType()) + // We are acutally not going to show the log for autosaved files. + ScopedLogCapturer logcapturer(modDoc, "", nullptr, false); + + bool success = false; + switch(modDoc.GetModType()) { case MOD_TYPE_MOD: success = sndFile.SaveMod(fileName); @@ -293,24 +280,23 @@ //Using IT save function also for MPT. success = sndFile.SaveIT(fileName); break; - //default: - //Do nothing } + return success; } -void CAutoSaver::CleanUpBackups(CModDoc *pModDoc) -//----------------------------------------------- +void CAutoSaver::CleanUpBackups(CModDoc &modDoc) +//---------------------------------------------- { CString path; if (m_bUseOriginalPath) { - if (pModDoc->m_bHasValidPath) // Check that the file has a user-chosen path + if (modDoc.m_bHasValidPath) // Check that the file has a user-chosen path { - CString fullPath = pModDoc->GetPathName(); - path = fullPath.Left(fullPath.GetLength() - pModDoc->GetTitle().GetLength()); //remove file name if necessary + CString fullPath = modDoc.GetPathName(); + path = fullPath.Left(fullPath.GetLength() - modDoc.GetTitle().GetLength()); //remove file name if necessary } else { path = theApp.GetConfigPath(); @@ -320,7 +306,7 @@ path = m_csPath; } - CString searchPattern = path + pModDoc->GetTitle() + ".AutoSave.*"; + CString searchPattern = path + modDoc.GetTitle() + ".AutoSave.*"; CFileFind finder; BOOL bResult = finder.FindFile(searchPattern); Modified: trunk/OpenMPT/mptrack/AutoSaver.h =================================================================== --- trunk/OpenMPT/mptrack/AutoSaver.h 2013-04-21 20:57:27 UTC (rev 1929) +++ trunk/OpenMPT/mptrack/AutoSaver.h 2013-04-22 15:30:53 UTC (rev 1930) @@ -42,9 +42,9 @@ //internal implementation private: - bool SaveSingleFile(CModDoc *pModDoc); - CString BuildFileName(CModDoc *pModDoc); - void CleanUpBackups(CModDoc *pModDoc); + bool SaveSingleFile(CModDoc &modDoc); + CString BuildFileName(CModDoc &modDoc); + void CleanUpBackups(CModDoc &modDoc); bool CheckTimer(DWORD curTime); //internal implementation members Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-04-21 20:57:27 UTC (rev 1929) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-04-22 15:30:53 UTC (rev 1930) @@ -808,9 +808,9 @@ } -ScopedLogCapturer::ScopedLogCapturer(CModDoc &modDoc, const std::string &title, CWnd *parent) : -m_modDoc(modDoc), m_oldLogMode(m_modDoc.GetLogMode()), m_title(title), m_pParent(parent) -//--------------------------------------------------------------------------------------------- +ScopedLogCapturer::ScopedLogCapturer(CModDoc &modDoc, const std::string &title, CWnd *parent, bool showLog) : +m_modDoc(modDoc), m_oldLogMode(m_modDoc.GetLogMode()), m_title(title), m_pParent(parent), m_showLog(showLog) +//----------------------------------------------------------------------------------------------------------- { m_modDoc.SetLogMode(LogModeGather); } @@ -841,7 +841,10 @@ ScopedLogCapturer::~ScopedLogCapturer() //------------------------------------- { - ShowLog(); + if(m_showLog) + ShowLog(); + else + m_modDoc.ClearLog(); m_modDoc.SetLogMode(m_oldLogMode); } Modified: trunk/OpenMPT/mptrack/Moddoc.h =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.h 2013-04-21 20:57:27 UTC (rev 1929) +++ trunk/OpenMPT/mptrack/Moddoc.h 2013-04-22 15:30:53 UTC (rev 1930) @@ -164,8 +164,9 @@ LogMode m_oldLogMode; std::string m_title; CWnd *m_pParent; + bool m_showLog; public: - ScopedLogCapturer(CModDoc &modDoc, const std::string &title = "", CWnd *parent = nullptr); + ScopedLogCapturer(CModDoc &modDoc, const std::string &title = "", CWnd *parent = nullptr, bool showLog = true); ~ScopedLogCapturer(); void ShowLog(bool force = false); void ShowLog(const std::string &preamble, bool force = false); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |