Skip to content

Commit

Permalink
Attempt to fix crash when running against a very old config GrandOrgu…
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg68 committed Mar 3, 2024
1 parent 5a8256d commit 1e57ef8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
9 changes: 6 additions & 3 deletions src/core/GOOrganList.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2023 GrandOrgue contributors (see AUTHORS)
* Copyright 2009-2024 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/
Expand Down Expand Up @@ -60,8 +60,11 @@ void GOOrganList::RemoveInvalidTmpOrgans() {
}
for (int i = m_ArchiveList.size() - 1; i >= 0; i--) {
const GOArchiveFile &aF = *m_ArchiveList[i];
const wxString &archivePath = aF.GetPath();

if (!aF.IsUsable(*this) && aF.GetPath().StartsWith(tmpDirPrefix))
if (
!archivePath.IsEmpty() && !aF.IsUsable()
&& archivePath.StartsWith(tmpDirPrefix))
m_ArchiveList.erase(i);
}
}
Expand Down Expand Up @@ -107,7 +110,7 @@ const GOArchiveFile *GOOrganList::GetArchiveByID(
const wxString &id, bool useable) const {
for (unsigned i = 0; i < m_ArchiveList.size(); i++)
if (m_ArchiveList[i]->GetID() == id)
if (!useable || m_ArchiveList[i]->IsUsable(*this))
if (!useable || m_ArchiveList[i]->IsUsable())
return m_ArchiveList[i];
return NULL;
}
Expand Down
27 changes: 14 additions & 13 deletions src/core/archive/GOArchiveFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,21 @@ const std::vector<wxString> &GOArchiveFile::GetDependencyTitles() const {
return m_DependencyTitles;
}

bool GOArchiveFile::IsUsable(const GOOrganList &organs) const {
return wxFileExists(m_Path);
bool GOArchiveFile::IsUsable() const {
return !m_Path.IsEmpty() && wxFileExists(m_Path);
}

bool GOArchiveFile::IsComplete(const GOOrganList &organs) const {
if (!IsUsable(organs))
return false;
for (unsigned i = 0; i < m_Dependencies.size(); i++) {
const GOArchiveFile *archive
= organs.GetArchiveByID(m_Dependencies[i], true);
if (!archive)
return false;
if (!archive->IsUsable(organs))
return false;
}
return true;
bool isOk = IsUsable();

if (isOk)
for (auto &dep : m_Dependencies) {
const GOArchiveFile *archive = organs.GetArchiveByID(dep, true);

isOk = archive && archive->IsUsable();

if (!isOk)
break;
}
return isOk;
}
4 changes: 2 additions & 2 deletions src/core/archive/GOArchiveFile.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2023 GrandOrgue contributors (see AUTHORS)
* Copyright 2009-2024 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/
Expand Down Expand Up @@ -52,7 +52,7 @@ class GOArchiveFile {
const std::vector<wxString> &GetDependencies() const;
const std::vector<wxString> &GetDependencyTitles() const;

bool IsUsable(const GOOrganList &organs) const;
bool IsUsable() const;
bool IsComplete(const GOOrganList &organs) const;
};

Expand Down
8 changes: 5 additions & 3 deletions src/grandorgue/GOFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,15 @@ void GOFrame::Init(const wxString &filename, bool isGuiOnly) {
GetEventHandler()->AddPendingEvent(event);
}

GOArchiveManager manager(m_config, m_config.OrganCachePath());

manager.RegisterPackageDirectory(m_config.GetPackageDirectory());
manager.RegisterPackageDirectory(m_config.OrganPackagePath());

// Remove demo organs that have been registered from temporary (appimage)
// directories and they are not more valid
m_config.RemoveInvalidTmpOrgans();

GOArchiveManager manager(m_config, m_config.OrganCachePath());
manager.RegisterPackageDirectory(m_config.GetPackageDirectory());
manager.RegisterPackageDirectory(m_config.OrganPackagePath());
if (!filename.IsEmpty())
SendLoadFile(filename);
else
Expand Down
4 changes: 2 additions & 2 deletions src/grandorgue/dialogs/settings/GOSettingsOrgans.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2023 GrandOrgue contributors (see AUTHORS)
* Copyright 2009-2024 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/
Expand Down Expand Up @@ -372,7 +372,7 @@ void GOSettingsOrgans::RefreshFocused() {
wxString archiveInfo = EMPTY_STRING;

if (a) {
if (!a->IsUsable(m_config))
if (!a->IsUsable())
archiveInfo = _("MISSING - ");
else if (!a->IsComplete(m_config)) {
archiveInfo = _("INCOMPLETE - ");
Expand Down

0 comments on commit 1e57ef8

Please sign in to comment.