mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-05 14:18:53 +02:00
Rewrite functions managing the missing block file...
This commit is contained in:
commit
48731c08b2
@ -889,24 +889,15 @@ void AudacityApp::OnTimer(wxTimerEvent& WXUNUSED(event))
|
||||
// find which project owns the blockfile
|
||||
// note: there may be more than 1, but just go with the first one.
|
||||
size_t numProjects = gAudacityProjects.size();
|
||||
AudacityProject *offendingProject {};
|
||||
wxString missingFileName;
|
||||
AudacityProject *offendingProject = NULL;
|
||||
|
||||
m_LastMissingBlockFileLock.Lock();
|
||||
if (numProjects == 1) {
|
||||
// if there is only one project open, no need to search
|
||||
offendingProject = gAudacityProjects[0].get();
|
||||
} else if (numProjects > 1) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
{
|
||||
ODLocker locker { &m_LastMissingBlockFileLock };
|
||||
offendingProject =
|
||||
AProjectHolder{ m_LastMissingBlockFileProject }.get();
|
||||
missingFileName = m_LastMissingBlockFilePath;
|
||||
}
|
||||
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 (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)
|
||||
b->Ref();
|
||||
|
||||
m_LastMissingBlockFileLock.Lock();
|
||||
if (m_LastMissingBlockFile)
|
||||
m_LastMissingBlockFile->Deref();
|
||||
|
||||
m_LastMissingBlockFile = b;
|
||||
|
||||
m_LastMissingBlockFileLock.Unlock();
|
||||
m_LastMissingBlockFilePath = b->GetAliasedFileName().GetFullPath();
|
||||
else
|
||||
m_LastMissingBlockFilePath = wxString{};
|
||||
}
|
||||
|
||||
void AudacityApp::SetMissingAliasedFileWarningShouldShow(bool b)
|
||||
@ -961,15 +959,15 @@ void AudacityApp::SetMissingAliasedFileWarningShouldShow(bool b)
|
||||
m_aliasMissingWarningShouldShow = b;
|
||||
// reset the warnings as they were probably marked by a previous run
|
||||
if (m_aliasMissingWarningShouldShow) {
|
||||
MarkAliasedFilesMissingWarning(NULL);
|
||||
MarkAliasedFilesMissingWarning( nullptr );
|
||||
}
|
||||
}
|
||||
|
||||
bool AudacityApp::ShouldShowMissingAliasedFileWarning()
|
||||
{
|
||||
bool ret = m_LastMissingBlockFile && m_aliasMissingWarningShouldShow;
|
||||
|
||||
return ret;
|
||||
ODLocker locker { &m_LastMissingBlockFileLock };
|
||||
auto ptr = m_LastMissingBlockFileProject.lock();
|
||||
return ptr && m_aliasMissingWarningShouldShow;
|
||||
}
|
||||
|
||||
AudacityLogger *AudacityApp::GetLogger()
|
||||
@ -1185,7 +1183,6 @@ bool AudacityApp::OnInit()
|
||||
mLocale = NULL;
|
||||
|
||||
m_aliasMissingWarningShouldShow = true;
|
||||
m_LastMissingBlockFile = NULL;
|
||||
|
||||
#if defined(__WXMAC__)
|
||||
// Disable window animation
|
||||
|
@ -41,6 +41,7 @@ class Importer;
|
||||
class CommandHandler;
|
||||
class AppCommandEvent;
|
||||
class AudacityLogger;
|
||||
class AudacityProject;
|
||||
|
||||
void SaveWindowSize();
|
||||
|
||||
@ -179,6 +180,7 @@ inline CommandFlag & operator |= (CommandFlag &lhs, CommandFlag rhs)
|
||||
using CommandMask = CommandFlag;
|
||||
|
||||
class BlockFile;
|
||||
class AliasBlockFile;
|
||||
|
||||
class AudacityApp final : public wxApp {
|
||||
public:
|
||||
@ -226,7 +228,7 @@ class AudacityApp final : public wxApp {
|
||||
* ShouldShowMissingAliasedFileWarning can be called to determine
|
||||
* 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
|
||||
*/
|
||||
@ -293,7 +295,8 @@ class AudacityApp final : public wxApp {
|
||||
wxTimer mTimer;
|
||||
|
||||
bool m_aliasMissingWarningShouldShow;
|
||||
const BlockFile *m_LastMissingBlockFile;
|
||||
std::weak_ptr< AudacityProject > m_LastMissingBlockFileProject;
|
||||
wxString m_LastMissingBlockFilePath;
|
||||
|
||||
ODLock m_LastMissingBlockFileLock;
|
||||
|
||||
|
@ -233,7 +233,7 @@ class AliasBlockFile /* not final */ : public BlockFile
|
||||
//
|
||||
// These methods are for advanced use only!
|
||||
//
|
||||
const wxFileName &GetAliasedFileName() { return mAliasedFileName; }
|
||||
const wxFileName &GetAliasedFileName() const { return mAliasedFileName; }
|
||||
void ChangeAliasedFileName(wxFileNameWrapper &&newAliasedFile);
|
||||
bool IsAlias() const override { return true; }
|
||||
|
||||
|
@ -33,6 +33,7 @@ using std::isinf;
|
||||
|
||||
namespace std {
|
||||
using std::tr1::shared_ptr;
|
||||
using std::tr1::weak_ptr;
|
||||
using std::tr1::remove_reference;
|
||||
|
||||
template<typename X> struct default_delete
|
||||
|
@ -526,14 +526,16 @@ AudacityProject *CreateNewAudacityProject()
|
||||
bool bIconized;
|
||||
GetNextWindowPlacement(&wndRect, &bMaximized, &bIconized);
|
||||
|
||||
//Create and show a NEW project
|
||||
gAudacityProjects.push_back(
|
||||
make_movable_with_deleter<AudacityProject, Destroyer< AudacityProject > >
|
||||
({},
|
||||
nullptr, -1,
|
||||
wxDefaultPosition,
|
||||
wxSize(wndRect.width, wndRect.height))
|
||||
);
|
||||
// Create and show a NEW project
|
||||
// Use a non-default deleter in the smart pointer!
|
||||
gAudacityProjects.push_back( AProjectHolder {
|
||||
safenew AudacityProject(
|
||||
nullptr, -1,
|
||||
wxDefaultPosition,
|
||||
wxSize(wndRect.width, wndRect.height)
|
||||
),
|
||||
Destroyer< AudacityProject > {}
|
||||
} );
|
||||
const auto p = gAudacityProjects.back().get();
|
||||
|
||||
// wxGTK3 seems to need to require creating the window using default position
|
||||
|
@ -110,8 +110,8 @@ void GetDefaultWindowRect(wxRect *defRect);
|
||||
void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized);
|
||||
bool IsWindowAccessible(wxRect *requestedRect);
|
||||
|
||||
using AProjectHolder =
|
||||
movable_ptr_with_deleter< AudacityProject, Destroyer< AudacityProject > >;
|
||||
// Use shared_ptr to projects, because elsewhere we need weak_ptr
|
||||
using AProjectHolder = std::shared_ptr< AudacityProject >;
|
||||
using AProjectArray = std::vector< AProjectHolder >;
|
||||
|
||||
extern AProjectArray gAudacityProjects;
|
||||
|
Loading…
x
Reference in New Issue
Block a user