From ee9e244b77a78e5fcfeda16b366ecfa71e2ee2ce Mon Sep 17 00:00:00 2001 From: mchinen Date: Thu, 21 Apr 2011 21:51:56 +0000 Subject: [PATCH] Bug 137 (P2) - fix false positive detection of orphaned files that belong to the clipboard (triggered by cut commands) --- src/DirManager.cpp | 27 ++++++++++++++++++++++++--- src/DirManager.h | 4 +++- src/Project.cpp | 6 ++++++ src/Project.h | 2 +- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/DirManager.cpp b/src/DirManager.cpp index 27adcf128..4c5dba5be 100644 --- a/src/DirManager.cpp +++ b/src/DirManager.cpp @@ -910,11 +910,17 @@ BlockFile *DirManager::NewODDecodeBlockFile( return newBlockFile; } -bool DirManager::ContainsBlockFile(BlockFile *b) { - // check what the hash returns in case the blockfile is from a different project +bool DirManager::ContainsBlockFile(BlockFile *b) +{ return b ? mBlockFileHash[b->GetFileName().GetName()] == b : NULL; } +bool DirManager::ContainsBlockFile(wxString filepath) +{ + // check what the hash returns in case the blockfile is from a different project + return mBlockFileHash[filepath] != NULL; +} + // Adds one to the reference count of the block file, // UNLESS it is "locked", then it makes a new copy of // the BlockFile. @@ -1695,6 +1701,8 @@ void DirManager::FindOrphanBlockFiles( const wxArrayString& filePathArray, // input: all files in project directory wxArrayString& orphanFilePathArray) // output: orphan files { + DirManager *clipboardDM = NULL; + for (size_t i = 0; i < filePathArray.GetCount(); i++) { wxFileName fullname = filePathArray[i]; @@ -1705,7 +1713,20 @@ void DirManager::FindOrphanBlockFiles( (fullname.GetExt().IsSameAs(wxT("au")) || fullname.GetExt().IsSameAs(wxT("auf")))) { - orphanFilePathArray.Add(fullname.GetFullPath()); + if (!clipboardDM) { + TrackList *clipTracks = AudacityProject::GetClipboardTracks(); + + if (clipTracks) { + TrackListIterator clipIter(clipTracks); + Track *track = clipIter.First(); + if (track) + clipboardDM = track->GetDirManager(); + } + } + + // Ignore it if it exists in the clipboard (from a previously closed project) + if (clipboardDM && clipboardDM->ContainsBlockFile(fullname.GetFullPath())) + orphanFilePathArray.Add(fullname.GetFullPath()); } } for (size_t i = 0; i < orphanFilePathArray.GetCount(); i++) diff --git a/src/DirManager.h b/src/DirManager.h index 9d6d51586..b9f3d27af 100644 --- a/src/DirManager.h +++ b/src/DirManager.h @@ -70,8 +70,10 @@ class DirManager: public XMLTagHandler { BlockFile *NewODDecodeBlockFile( wxString aliasedFile, sampleCount aliasStart, sampleCount aliasLen, int aliasChannel, int decodeType); - /// Returns true if the blockfile is contained by the DirManager + /// Returns true if the blockfile pointed to by b is contained by the DirManager bool ContainsBlockFile(BlockFile *b); + /// Check for existing using filename using complete filename + bool ContainsBlockFile(wxString filepath); // Adds one to the reference count of the block file, // UNLESS it is "locked", then it makes a new copy of diff --git a/src/Project.cpp b/src/Project.cpp index 1ae522849..a0c23641c 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -3727,6 +3727,12 @@ void AudacityProject::UpdateMixerBoard() // Clipboard methods // +//static +TrackList *AudacityProject::GetClipboardTracks() +{ + return msClipboard; +} + //static void AudacityProject::DeleteClipboard() { diff --git a/src/Project.h b/src/Project.h index 4cd52e633..4edeb0bdc 100644 --- a/src/Project.h +++ b/src/Project.h @@ -275,7 +275,7 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame, void UpdateLayout(); // Other commands - + static TrackList *GetClipboardTracks(); static void DeleteClipboard(); static void DeleteAllProjectsDeleteLock();