From 1d9b8b7bad2dec747149b31aca12fcfb24b03c68 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 16 Jan 2018 17:14:01 -0500 Subject: [PATCH 1/6] Undo confusing tangle of Save and SaveAs each calling the other... Now Save may call SaveAs, which does not call back; each calls DoSave. --- src/Project.cpp | 29 +++++++++++++++++++---------- src/Project.h | 6 +++++- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/Project.cpp b/src/Project.cpp index 20c96524a..2d4c7e491 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -3769,16 +3769,27 @@ private: }; #endif -bool AudacityProject::Save(bool overwrite /* = true */ , - bool fromSaveAs /* = false */, - bool bWantSaveCompressed /*= false*/) +bool AudacityProject::Save() +{ + if (mDirManager->GetProjectName() == wxT("")) + return SaveAs(); + + return DoSave(true, false, false); +} + + +// Assumes AudacityProject::mFileName has been set to the desired path. +bool AudacityProject::DoSave + (const bool overwrite, const bool fromSaveAs, const bool bWantSaveCompressed) { // See explanation above // ProjectDisabler disabler(this); if (bWantSaveCompressed) wxASSERT(fromSaveAs); - else + + // Some confirmation dialogs + if (!bWantSaveCompressed) { TrackListIterator iter(GetTracks()); bool bHasTracks = (iter.First() != NULL); @@ -3793,9 +3804,6 @@ bool AudacityProject::Save(bool overwrite /* = true */ , } } - if (!fromSaveAs && mDirManager->GetProjectName() == wxT("")) - return SaveAs(); - // If the user has recently imported dependencies, show // a dialog where the user can see audio files that are // aliased by this project. The user may make the project @@ -3808,6 +3816,7 @@ bool AudacityProject::Save(bool overwrite /* = true */ , mImportedDependencies = false; // do not show again } } + // End of confirmations // // Always save a backup of the original project file @@ -4331,7 +4340,7 @@ bool AudacityProject::SaveAs(const wxString & newFileName, bool bWantSaveCompres //Don't change the title, unless we succeed. //SetProjectTitle(); - success = Save(false, true, bWantSaveCompressed); + success = DoSave(false, true, bWantSaveCompressed); if (success && addToHistory) { wxGetApp().AddFileToHistory(mFileName); @@ -4430,7 +4439,7 @@ For an audio file that will open in other apps, use 'Export'.\n"), mFileName = oldFileName; } ); - success = Save(false, true, bWantSaveCompressed); + success = DoSave(false, true, bWantSaveCompressed); if (success) { wxGetApp().AddFileToHistory(mFileName); @@ -5817,7 +5826,7 @@ bool AudacityProject::SaveFromTimerRecording(wxFileName fnFile) { mFileName = sOldFilename; } ); - bSuccess = Save(false, true, false); + bSuccess = DoSave(false, true, false); if (bSuccess) { wxGetApp().AddFileToHistory(mFileName); diff --git a/src/Project.h b/src/Project.h index 629de1af5..5e9431e0d 100644 --- a/src/Project.h +++ b/src/Project.h @@ -272,12 +272,16 @@ public: AddImportedTracks(const wxString &fileName, TrackHolders &&newTracks); - bool Save(bool overwrite = true, bool fromSaveAs = false, bool bWantSaveCompressed = false); + bool Save(); bool SaveAs(bool bWantSaveCompressed = false); bool SaveAs(const wxString & newFileName, bool bWantSaveCompressed = false, bool addToHistory = true); #ifdef USE_LIBVORBIS bool SaveCompressedWaveTracks(const wxString & strProjectPathName); // full path for aup except extension #endif +private: + bool DoSave(bool overwrite, bool fromSaveAs, bool bWantSaveCompressed); +public: + void Clear(); const wxString &GetFileName() { return mFileName; } From 4d364ee7f3e58f29370db642a2fe4943d32f15c7 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 16 Jan 2018 17:34:27 -0500 Subject: [PATCH 2/6] Remove overwrite argument -- it's always !fromSaveAs --- src/Project.cpp | 14 +++++++------- src/Project.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Project.cpp b/src/Project.cpp index 2d4c7e491..17c47bf71 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -3774,13 +3774,13 @@ bool AudacityProject::Save() if (mDirManager->GetProjectName() == wxT("")) return SaveAs(); - return DoSave(true, false, false); + return DoSave(false, false); } // Assumes AudacityProject::mFileName has been set to the desired path. bool AudacityProject::DoSave - (const bool overwrite, const bool fromSaveAs, const bool bWantSaveCompressed) + (const bool fromSaveAs, const bool bWantSaveCompressed) { // See explanation above // ProjectDisabler disabler(this); @@ -3940,7 +3940,7 @@ bool AudacityProject::DoSave // be empty of all of its files.) std::vector> lockers; - if (mLastSavedTracks && !overwrite) { + if (mLastSavedTracks && fromSaveAs) { lockers.reserve(mLastSavedTracks->size()); TrackListIterator iter(mLastSavedTracks.get()); Track *t = iter.First(); @@ -3955,7 +3955,7 @@ bool AudacityProject::DoSave // This renames the project directory, and moves or copies // all of our block files over. - success = mDirManager->SetProject(projPath, projName, !overwrite); + success = mDirManager->SetProject(projPath, projName, fromSaveAs); } if (!success) @@ -4340,7 +4340,7 @@ bool AudacityProject::SaveAs(const wxString & newFileName, bool bWantSaveCompres //Don't change the title, unless we succeed. //SetProjectTitle(); - success = DoSave(false, true, bWantSaveCompressed); + success = DoSave(true, bWantSaveCompressed); if (success && addToHistory) { wxGetApp().AddFileToHistory(mFileName); @@ -4439,7 +4439,7 @@ For an audio file that will open in other apps, use 'Export'.\n"), mFileName = oldFileName; } ); - success = DoSave(false, true, bWantSaveCompressed); + success = DoSave(true, bWantSaveCompressed); if (success) { wxGetApp().AddFileToHistory(mFileName); @@ -5826,7 +5826,7 @@ bool AudacityProject::SaveFromTimerRecording(wxFileName fnFile) { mFileName = sOldFilename; } ); - bSuccess = DoSave(false, true, false); + bSuccess = DoSave(true, false); if (bSuccess) { wxGetApp().AddFileToHistory(mFileName); diff --git a/src/Project.h b/src/Project.h index 5e9431e0d..44ea68c35 100644 --- a/src/Project.h +++ b/src/Project.h @@ -279,7 +279,7 @@ public: bool SaveCompressedWaveTracks(const wxString & strProjectPathName); // full path for aup except extension #endif private: - bool DoSave(bool overwrite, bool fromSaveAs, bool bWantSaveCompressed); + bool DoSave(bool fromSaveAs, bool bWantSaveCompressed); public: void Clear(); From 356763c90bee656562cb613fad926fd5798aabf8 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 16 Jan 2018 17:51:03 -0500 Subject: [PATCH 3/6] remove unused --- src/DirManager.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/DirManager.h b/src/DirManager.h index 61f817da3..0d70a67b8 100644 --- a/src/DirManager.h +++ b/src/DirManager.h @@ -29,7 +29,6 @@ class wxHashTable; class BlockArray; class BlockFile; -class SequenceTest; #define FSCKstatus_CLOSE_REQ 0x1 #define FSCKstatus_CHANGED 0x2 @@ -232,8 +231,6 @@ class PROFILE_DLL_API DirManager final : public XMLTagHandler { wxString mytemp; static int numDirManagers; static bool dontDeleteTempFiles; - - friend class SequenceTest; }; #endif From d37c319923de2b79e3836eff23ad0f19b59453cd Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 16 Jan 2018 18:26:33 -0500 Subject: [PATCH 4/6] Fewer uses of DirManager::GetProjectName() --- src/Project.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Project.cpp b/src/Project.cpp index 17c47bf71..ce2a6b8fb 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -3661,7 +3661,7 @@ void AudacityProject::WriteXML(XMLWriter &xmlFile, bool bWantSaveCompressed) // then the file has been saved. This is not neccessarily true when // autosaving as it gets set by AddImportedTracks (presumably as a proposal). // I don't think that mDirManager.projName gets set without a save so check that. - if( mDirManager->GetProjectName() == wxT("") ) + if( !IsProjectSaved() ) projName = wxT("_data"); } @@ -3771,7 +3771,7 @@ private: bool AudacityProject::Save() { - if (mDirManager->GetProjectName() == wxT("")) + if ( !IsProjectSaved() ) return SaveAs(); return DoSave(false, false); @@ -3872,7 +3872,7 @@ bool AudacityProject::DoSave mStrOtherNamesArray.clear(); } ); - if (fromSaveAs || mDirManager->GetProjectName() == wxT("")) { + if (fromSaveAs || !IsProjectSaved() ) { // This block of code is duplicated in WriteXML, for now... project = mFileName; if (project.Len() > 4 && project.Mid(project.Len() - 4) == wxT(".aup")) @@ -3929,7 +3929,7 @@ bool AudacityProject::DoSave if (!success) return false; - if (fromSaveAs || mDirManager->GetProjectName() == wxT("")) { + if (fromSaveAs || !IsProjectSaved() ) { if (!bWantSaveCompressed) { // We are about to move files from the current directory to @@ -4215,7 +4215,7 @@ AudacityProject::AddImportedTracks(const wxString &fileName, wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI | wxEVT_CATEGORY_USER_INPUT); #endif - if (initiallyEmpty && mDirManager->GetProjectName() == wxT("")) { + if (initiallyEmpty && !IsProjectSaved() ) { wxString name = fileName.AfterLast(wxFILE_SEP_PATH).BeforeLast(wxT('.')); mFileName =::wxPathOnly(fileName) + wxFILE_SEP_PATH + name + wxT(".aup"); mbLoadedFromAup = false; @@ -5794,6 +5794,9 @@ int AudacityProject::GetOpenProjectCount() { } bool AudacityProject::IsProjectSaved() { + // This is true if a project was opened from an .aup + // Otherwise it becomes true only when a project is first saved successfully + // in DirManager::SetProject wxString sProjectName = mDirManager->GetProjectName(); return (sProjectName != wxT("")); } From 133bbd927d7d4ff87ef2029d54f5394e8d8115a4 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 16 Jan 2018 18:31:50 -0500 Subject: [PATCH 5/6] We can simplify logic further --- src/Project.cpp | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/Project.cpp b/src/Project.cpp index ce2a6b8fb..0f18abafb 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -3872,7 +3872,7 @@ bool AudacityProject::DoSave mStrOtherNamesArray.clear(); } ); - if (fromSaveAs || !IsProjectSaved() ) { + if (fromSaveAs) { // This block of code is duplicated in WriteXML, for now... project = mFileName; if (project.Len() > 4 && project.Mid(project.Len() - 4) == wxT(".aup")) @@ -3929,35 +3929,32 @@ bool AudacityProject::DoSave if (!success) return false; - if (fromSaveAs || !IsProjectSaved() ) { - if (!bWantSaveCompressed) - { - // We are about to move files from the current directory to - // the NEW directory. We need to make sure files that belonged - // to the last saved project don't get erased, so we "lock" them, so that - // SetProject() copies instead of moves the files. - // (Otherwise the NEW project would be fine, but the old one would - // be empty of all of its files.) + if (fromSaveAs && !bWantSaveCompressed) { + // We are about to move files from the current directory to + // the NEW directory. We need to make sure files that belonged + // to the last saved project don't get erased, so we "lock" them, so that + // SetProject() copies instead of moves the files. + // (Otherwise the NEW project would be fine, but the old one would + // be empty of all of its files.) - std::vector> lockers; - if (mLastSavedTracks && fromSaveAs) { - lockers.reserve(mLastSavedTracks->size()); - TrackListIterator iter(mLastSavedTracks.get()); - Track *t = iter.First(); - while (t) { - if (t->GetKind() == Track::Wave) - lockers.push_back( - make_movable( - static_cast(t))); - t = iter.Next(); - } + std::vector> lockers; + if (mLastSavedTracks) { + lockers.reserve(mLastSavedTracks->size()); + TrackListIterator iter(mLastSavedTracks.get()); + Track *t = iter.First(); + while (t) { + if (t->GetKind() == Track::Wave) + lockers.push_back( + make_movable( + static_cast(t))); + t = iter.Next(); } - - // This renames the project directory, and moves or copies - // all of our block files over. - success = mDirManager->SetProject(projPath, projName, fromSaveAs); } + // This renames the project directory, and moves or copies + // all of our block files over. + success = mDirManager->SetProject(projPath, projName, true); + if (!success) return false; } From 059e186db6226bd114384f2c5647e9a1740363e8 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 16 Jan 2018 18:41:23 -0500 Subject: [PATCH 6/6] Treat save-as of a file to its own path as a simple save --- src/Project.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Project.cpp b/src/Project.cpp index 0f18abafb..d0835d3ca 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -4310,6 +4310,8 @@ bool AudacityProject::Import(const wxString &fileName, WaveTrackArray* pTrackArr bool AudacityProject::SaveAs(const wxString & newFileName, bool bWantSaveCompressed /*= false*/, bool addToHistory /*= true*/) { + // This version of SaveAs is invoked only from scripting and does not + // prompt for a file name wxString oldFileName = mFileName; bool bOwnsNewAupName = mbLoadedFromAup && (mFileName==newFileName); @@ -4337,7 +4339,7 @@ bool AudacityProject::SaveAs(const wxString & newFileName, bool bWantSaveCompres //Don't change the title, unless we succeed. //SetProjectTitle(); - success = DoSave(true, bWantSaveCompressed); + success = DoSave(!bOwnsNewAupName || bWantSaveCompressed, bWantSaveCompressed); if (success && addToHistory) { wxGetApp().AddFileToHistory(mFileName); @@ -4436,7 +4438,7 @@ For an audio file that will open in other apps, use 'Export'.\n"), mFileName = oldFileName; } ); - success = DoSave(true, bWantSaveCompressed); + success = DoSave(!bOwnsNewAupName || bWantSaveCompressed, bWantSaveCompressed); if (success) { wxGetApp().AddFileToHistory(mFileName);