mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-16 22:23:53 +01:00
Rewrite functions managing the missing block file...
... removing one ref and deref of block files. This unblocks a future development that will manage all block files with std::shared_ptr.
This commit is contained in:
@@ -889,24 +889,15 @@ void AudacityApp::OnTimer(wxTimerEvent& WXUNUSED(event))
|
|||||||
// find which project owns the blockfile
|
// find which project owns the blockfile
|
||||||
// note: there may be more than 1, but just go with the first one.
|
// note: there may be more than 1, but just go with the first one.
|
||||||
size_t numProjects = gAudacityProjects.size();
|
size_t numProjects = gAudacityProjects.size();
|
||||||
|
AudacityProject *offendingProject {};
|
||||||
wxString missingFileName;
|
wxString missingFileName;
|
||||||
AudacityProject *offendingProject = NULL;
|
|
||||||
|
|
||||||
m_LastMissingBlockFileLock.Lock();
|
{
|
||||||
if (numProjects == 1) {
|
ODLocker locker { &m_LastMissingBlockFileLock };
|
||||||
// if there is only one project open, no need to search
|
offendingProject =
|
||||||
offendingProject = gAudacityProjects[0].get();
|
AProjectHolder{ m_LastMissingBlockFileProject }.get();
|
||||||
} else if (numProjects > 1) {
|
missingFileName = m_LastMissingBlockFilePath;
|
||||||
for (size_t i = 0; i < numProjects; i++) {
|
|
||||||
// search each project for the blockfile
|
|
||||||
if (gAudacityProjects[i]->GetDirManager()->ContainsBlockFile(m_LastMissingBlockFile)) {
|
|
||||||
offendingProject = gAudacityProjects[i].get();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
missingFileName = ((AliasBlockFile*)m_LastMissingBlockFile)->GetAliasedFileName().GetFullPath();
|
|
||||||
m_LastMissingBlockFileLock.Unlock();
|
|
||||||
|
|
||||||
// if there are no projects open, don't show the warning (user has closed it)
|
// if there are no projects open, don't show the warning (user has closed it)
|
||||||
if (offendingProject) {
|
if (offendingProject) {
|
||||||
@@ -937,19 +928,26 @@ locations of the missing files."), missingFileName.c_str());
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudacityApp::MarkAliasedFilesMissingWarning(const BlockFile *b)
|
void AudacityApp::MarkAliasedFilesMissingWarning(const AliasBlockFile *b)
|
||||||
{
|
{
|
||||||
// the reference counting provides thread safety.
|
ODLocker locker { &m_LastMissingBlockFileLock };
|
||||||
|
if (b) {
|
||||||
|
size_t numProjects = gAudacityProjects.size();
|
||||||
|
for (size_t ii = 0; ii < numProjects; ++ii) {
|
||||||
|
// search each project for the blockfile
|
||||||
|
if (gAudacityProjects[ii]->GetDirManager()->ContainsBlockFile(b)) {
|
||||||
|
m_LastMissingBlockFileProject = gAudacityProjects[ii];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_LastMissingBlockFileProject = {};
|
||||||
|
|
||||||
if (b)
|
if (b)
|
||||||
b->Ref();
|
m_LastMissingBlockFilePath = b->GetAliasedFileName().GetFullPath();
|
||||||
|
else
|
||||||
m_LastMissingBlockFileLock.Lock();
|
m_LastMissingBlockFilePath = wxString{};
|
||||||
if (m_LastMissingBlockFile)
|
|
||||||
m_LastMissingBlockFile->Deref();
|
|
||||||
|
|
||||||
m_LastMissingBlockFile = b;
|
|
||||||
|
|
||||||
m_LastMissingBlockFileLock.Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudacityApp::SetMissingAliasedFileWarningShouldShow(bool b)
|
void AudacityApp::SetMissingAliasedFileWarningShouldShow(bool b)
|
||||||
@@ -961,15 +959,15 @@ void AudacityApp::SetMissingAliasedFileWarningShouldShow(bool b)
|
|||||||
m_aliasMissingWarningShouldShow = b;
|
m_aliasMissingWarningShouldShow = b;
|
||||||
// reset the warnings as they were probably marked by a previous run
|
// reset the warnings as they were probably marked by a previous run
|
||||||
if (m_aliasMissingWarningShouldShow) {
|
if (m_aliasMissingWarningShouldShow) {
|
||||||
MarkAliasedFilesMissingWarning(NULL);
|
MarkAliasedFilesMissingWarning( nullptr );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudacityApp::ShouldShowMissingAliasedFileWarning()
|
bool AudacityApp::ShouldShowMissingAliasedFileWarning()
|
||||||
{
|
{
|
||||||
bool ret = m_LastMissingBlockFile && m_aliasMissingWarningShouldShow;
|
ODLocker locker { &m_LastMissingBlockFileLock };
|
||||||
|
auto ptr = m_LastMissingBlockFileProject.lock();
|
||||||
return ret;
|
return ptr && m_aliasMissingWarningShouldShow;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudacityLogger *AudacityApp::GetLogger()
|
AudacityLogger *AudacityApp::GetLogger()
|
||||||
@@ -1185,7 +1183,6 @@ bool AudacityApp::OnInit()
|
|||||||
mLocale = NULL;
|
mLocale = NULL;
|
||||||
|
|
||||||
m_aliasMissingWarningShouldShow = true;
|
m_aliasMissingWarningShouldShow = true;
|
||||||
m_LastMissingBlockFile = NULL;
|
|
||||||
|
|
||||||
#if defined(__WXMAC__)
|
#if defined(__WXMAC__)
|
||||||
// Disable window animation
|
// Disable window animation
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class Importer;
|
|||||||
class CommandHandler;
|
class CommandHandler;
|
||||||
class AppCommandEvent;
|
class AppCommandEvent;
|
||||||
class AudacityLogger;
|
class AudacityLogger;
|
||||||
|
class AudacityProject;
|
||||||
|
|
||||||
void SaveWindowSize();
|
void SaveWindowSize();
|
||||||
|
|
||||||
@@ -179,6 +180,7 @@ inline CommandFlag & operator |= (CommandFlag &lhs, CommandFlag rhs)
|
|||||||
using CommandMask = CommandFlag;
|
using CommandMask = CommandFlag;
|
||||||
|
|
||||||
class BlockFile;
|
class BlockFile;
|
||||||
|
class AliasBlockFile;
|
||||||
|
|
||||||
class AudacityApp final : public wxApp {
|
class AudacityApp final : public wxApp {
|
||||||
public:
|
public:
|
||||||
@@ -226,7 +228,7 @@ class AudacityApp final : public wxApp {
|
|||||||
* ShouldShowMissingAliasedFileWarning can be called to determine
|
* ShouldShowMissingAliasedFileWarning can be called to determine
|
||||||
* if the user should be notified
|
* if the user should be notified
|
||||||
*/
|
*/
|
||||||
void MarkAliasedFilesMissingWarning(const BlockFile *b);
|
void MarkAliasedFilesMissingWarning(const AliasBlockFile *b);
|
||||||
|
|
||||||
/** \brief Changes the behavior of missing aliased blockfiles warnings
|
/** \brief Changes the behavior of missing aliased blockfiles warnings
|
||||||
*/
|
*/
|
||||||
@@ -293,7 +295,8 @@ class AudacityApp final : public wxApp {
|
|||||||
wxTimer mTimer;
|
wxTimer mTimer;
|
||||||
|
|
||||||
bool m_aliasMissingWarningShouldShow;
|
bool m_aliasMissingWarningShouldShow;
|
||||||
const BlockFile *m_LastMissingBlockFile;
|
std::weak_ptr< AudacityProject > m_LastMissingBlockFileProject;
|
||||||
|
wxString m_LastMissingBlockFilePath;
|
||||||
|
|
||||||
ODLock m_LastMissingBlockFileLock;
|
ODLock m_LastMissingBlockFileLock;
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ using std::isinf;
|
|||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
using std::tr1::shared_ptr;
|
using std::tr1::shared_ptr;
|
||||||
|
using std::tr1::weak_ptr;
|
||||||
using std::tr1::remove_reference;
|
using std::tr1::remove_reference;
|
||||||
|
|
||||||
template<typename X> struct default_delete
|
template<typename X> struct default_delete
|
||||||
|
|||||||
Reference in New Issue
Block a user