1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-03 22:19:07 +02:00

DirManager.cpp doesn't depend on Clipboard...

... Locate other outstanding DirManagers by other means, a global tracking
array.

This does not yet break any dependency cycles.
This commit is contained in:
Paul Licameli 2019-05-13 21:17:41 -04:00
parent ce27977ff2
commit 9b32fc7a2b
4 changed files with 43 additions and 16 deletions

View File

@ -359,7 +359,7 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
HoldPrint(true); HoldPrint(true);
ZoomInfo zoomInfo(0.0, ZoomInfo::GetDefaultZoom()); ZoomInfo zoomInfo(0.0, ZoomInfo::GetDefaultZoom());
auto dd = std::make_shared<DirManager>(); auto dd = DirManager::Create();
const auto t = TrackFactory{ dd, &zoomInfo }.NewWaveTrack(int16Sample); const auto t = TrackFactory{ dd, &zoomInfo }.NewWaveTrack(int16Sample);
t->SetRate(1); t->SetRate(1);

View File

@ -85,7 +85,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
#include "Clipboard.h"
#include "FileNames.h" #include "FileNames.h"
#include "blockfile/LegacyBlockFile.h" #include "blockfile/LegacyBlockFile.h"
#include "blockfile/LegacyAliasBlockFile.h" #include "blockfile/LegacyAliasBlockFile.h"
@ -356,6 +355,19 @@ wxString DirManager::globaltemp;
int DirManager::numDirManagers = 0; int DirManager::numDirManagers = 0;
bool DirManager::dontDeleteTempFiles = false; bool DirManager::dontDeleteTempFiles = false;
namespace {
// Global tracking of all outstanding DirManagers
std::vector< std::weak_ptr< DirManager > > sDirManagers;
}
std::shared_ptr<DirManager> DirManager::Create()
{
auto result = std::shared_ptr< DirManager >( safenew DirManager );
sDirManagers.push_back( result );
return result;
}
DirManager::DirManager() DirManager::DirManager()
{ {
@ -410,6 +422,13 @@ DirManager::DirManager()
DirManager::~DirManager() DirManager::~DirManager()
{ {
auto start = sDirManagers.begin(), finish = sDirManagers.end(),
iter = std::remove_if( start, finish,
[=]( const std::weak_ptr<DirManager> &ptr ){
return ptr.expired() || ptr.lock().get() == this;
} );
sDirManagers.erase( iter, finish );
numDirManagers--; numDirManagers--;
if (numDirManagers == 0) { if (numDirManagers == 0) {
CleanTempDir(); CleanTempDir();
@ -1744,7 +1763,12 @@ void DirManager::FindOrphanBlockFiles(
const FilePaths &filePathArray, // input: all files in project directory const FilePaths &filePathArray, // input: all files in project directory
FilePaths &orphanFilePathArray) // output: orphan files FilePaths &orphanFilePathArray) // output: orphan files
{ {
DirManager *clipboardDM = NULL; std::vector< std::shared_ptr<DirManager> > otherDirManagers;
for ( auto &wPtr : sDirManagers ) {
auto sPtr = wPtr.lock();
if ( sPtr && sPtr.get() != this )
otherDirManagers.push_back( sPtr );
}
for (size_t i = 0; i < filePathArray.size(); i++) for (size_t i = 0; i < filePathArray.size(); i++)
{ {
@ -1757,17 +1781,15 @@ void DirManager::FindOrphanBlockFiles(
(ext.IsSameAs(wxT("au"), false) || (ext.IsSameAs(wxT("au"), false) ||
ext.IsSameAs(wxT("auf"), false))) ext.IsSameAs(wxT("auf"), false)))
{ {
if (!clipboardDM) {
auto &clipTracks = Clipboard::Get().GetTracks();
auto track = *clipTracks.Any().first;
if (track)
clipboardDM = track->GetDirManager().get();
}
// Ignore it if it exists in the clipboard (from a previously closed project) // Ignore it if it exists in the clipboard (from a previously closed project)
if (!(clipboardDM && clipboardDM->ContainsBlockFile(basename))) if ( std::any_of( otherDirManagers.begin(), otherDirManagers.end(),
orphanFilePathArray.push_back(fullname.GetFullPath()); [&]( const std::shared_ptr< DirManager > &ptr ){
return ptr->ContainsBlockFile( basename );
}
) )
continue;
orphanFilePathArray.push_back(fullname.GetFullPath());
} }
} }
for ( const auto &orphan : orphanFilePathArray ) for ( const auto &orphan : orphanFilePathArray )

View File

@ -67,9 +67,15 @@ class PROFILE_DLL_API DirManager final : public XMLTagHandler {
static void RecursivelyRemove(const FilePaths& filePathArray, int count, int bias, static void RecursivelyRemove(const FilePaths& filePathArray, int count, int bias,
int flags, const wxChar* message = nullptr); int flags, const wxChar* message = nullptr);
private:
// MM: Construct DirManager // MM: Construct DirManager
// Don't call this directly but use Create() instead
DirManager(); DirManager();
public:
static std::shared_ptr< DirManager > Create();
virtual ~DirManager(); virtual ~DirManager();
size_t NumBlockFiles() const { return mBlockFileHash.size(); } size_t NumBlockFiles() const { return mBlockFileHash.size(); }

View File

@ -1130,8 +1130,7 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
MissingAliasFilesDialog::SetShouldShow(true); MissingAliasFilesDialog::SetShouldShow(true);
// MM: DirManager is created dynamically, freed on demand via ref-counting // MM: DirManager is created dynamically, freed on demand via ref-counting
// MM: We don't need to Ref() here because it start with refcount=1 mDirManager = DirManager::Create();
mDirManager = std::make_shared<DirManager>();
mLastSavedTracks.reset(); mLastSavedTracks.reset();
@ -5371,7 +5370,7 @@ void AudacityProject::ResetProjectToEmpty() {
SelectActions::DoSelectAll(*this); SelectActions::DoSelectAll(*this);
TrackActions::DoRemoveTracks(*this); TrackActions::DoRemoveTracks(*this);
// A new DirManager. // A new DirManager.
mDirManager = std::make_shared<DirManager>(); mDirManager = DirManager::Create();
mTrackFactory.reset(safenew TrackFactory{ mDirManager, &mViewInfo }); mTrackFactory.reset(safenew TrackFactory{ mDirManager, &mViewInfo });
// mLastSavedTrack code copied from OnCloseWindow. // mLastSavedTrack code copied from OnCloseWindow.