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:
parent
ce27977ff2
commit
9b32fc7a2b
@ -359,7 +359,7 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
|
||||
HoldPrint(true);
|
||||
|
||||
ZoomInfo zoomInfo(0.0, ZoomInfo::GetDefaultZoom());
|
||||
auto dd = std::make_shared<DirManager>();
|
||||
auto dd = DirManager::Create();
|
||||
const auto t = TrackFactory{ dd, &zoomInfo }.NewWaveTrack(int16Sample);
|
||||
|
||||
t->SetRate(1);
|
||||
|
@ -85,7 +85,6 @@
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include "Clipboard.h"
|
||||
#include "FileNames.h"
|
||||
#include "blockfile/LegacyBlockFile.h"
|
||||
#include "blockfile/LegacyAliasBlockFile.h"
|
||||
@ -356,6 +355,19 @@ wxString DirManager::globaltemp;
|
||||
int DirManager::numDirManagers = 0;
|
||||
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()
|
||||
{
|
||||
@ -410,6 +422,13 @@ 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--;
|
||||
if (numDirManagers == 0) {
|
||||
CleanTempDir();
|
||||
@ -1744,7 +1763,12 @@ void DirManager::FindOrphanBlockFiles(
|
||||
const FilePaths &filePathArray, // input: all files in project directory
|
||||
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++)
|
||||
{
|
||||
@ -1757,17 +1781,15 @@ void DirManager::FindOrphanBlockFiles(
|
||||
(ext.IsSameAs(wxT("au"), 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)
|
||||
if (!(clipboardDM && clipboardDM->ContainsBlockFile(basename)))
|
||||
orphanFilePathArray.push_back(fullname.GetFullPath());
|
||||
if ( std::any_of( otherDirManagers.begin(), otherDirManagers.end(),
|
||||
[&]( const std::shared_ptr< DirManager > &ptr ){
|
||||
return ptr->ContainsBlockFile( basename );
|
||||
}
|
||||
) )
|
||||
continue;
|
||||
|
||||
orphanFilePathArray.push_back(fullname.GetFullPath());
|
||||
}
|
||||
}
|
||||
for ( const auto &orphan : orphanFilePathArray )
|
||||
|
@ -67,9 +67,15 @@ class PROFILE_DLL_API DirManager final : public XMLTagHandler {
|
||||
static void RecursivelyRemove(const FilePaths& filePathArray, int count, int bias,
|
||||
int flags, const wxChar* message = nullptr);
|
||||
|
||||
private:
|
||||
// MM: Construct DirManager
|
||||
// Don't call this directly but use Create() instead
|
||||
DirManager();
|
||||
|
||||
public:
|
||||
|
||||
static std::shared_ptr< DirManager > Create();
|
||||
|
||||
virtual ~DirManager();
|
||||
|
||||
size_t NumBlockFiles() const { return mBlockFileHash.size(); }
|
||||
|
@ -1130,8 +1130,7 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
|
||||
MissingAliasFilesDialog::SetShouldShow(true);
|
||||
|
||||
// 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 = std::make_shared<DirManager>();
|
||||
mDirManager = DirManager::Create();
|
||||
|
||||
mLastSavedTracks.reset();
|
||||
|
||||
@ -5371,7 +5370,7 @@ void AudacityProject::ResetProjectToEmpty() {
|
||||
SelectActions::DoSelectAll(*this);
|
||||
TrackActions::DoRemoveTracks(*this);
|
||||
// A new DirManager.
|
||||
mDirManager = std::make_shared<DirManager>();
|
||||
mDirManager = DirManager::Create();
|
||||
mTrackFactory.reset(safenew TrackFactory{ mDirManager, &mViewInfo });
|
||||
|
||||
// mLastSavedTrack code copied from OnCloseWindow.
|
||||
|
Loading…
x
Reference in New Issue
Block a user