Skip to content

Commit

Permalink
Fixed error messages after multiple runs of GrandOrgue ftom Appimage …
Browse files Browse the repository at this point in the history
…with a demo organ #1660 (#1681)

* Added passing an archive file path when opening an archived organ

* Added a changelog entry
  • Loading branch information
oleg68 authored Oct 16, 2023
1 parent 3b57558 commit 8b62bfd
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Fixed error messages after multiple runs of GrandOrgue ftom Appimage with a demo organ https://github.com/GrandOrgue/grandorgue/issues/1660
# 3.13.0 (2023-10-11)
- Implemented option to send MIDI Note Off as 0x8X or 0x9X with velocity 0 https://github.com/GrandOrgue/grandorgue/issues/1640
- Added capability of control buttons with Control Change MIDI events with different keys but same values using "Bx Ctrl Change Fixed On Value Toggle" and "Bx Ctrl Change Fixed Off Value Toggle" https://github.com/GrandOrgue/grandorgue/issues/1392
Expand Down
4 changes: 3 additions & 1 deletion src/core/archive/GOArchiveCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ bool GOArchiveCreator::AddPackage(const wxString &path) {
return true;
}
m_packageIDs.push_back(a);
GOArchive *archive = m_Manager.LoadArchive(a->GetID());

GOArchive *archive = m_Manager.LoadArchive(a->GetID(), path);

if (!archive) {
wxLogError(_("Failed to load organ package %s"), path.c_str());
return false;
Expand Down
40 changes: 23 additions & 17 deletions src/core/archive/GOArchiveManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,31 @@ bool GOArchiveManager::ReadIndex(GOArchive *archive, bool InstallOrgans) {
return true;
}

GOArchive *GOArchiveManager::LoadArchive(const wxString &id) {
for (unsigned i = 0; i < m_OrganList.GetArchiveList().size(); i++) {
const GOArchiveFile *file = m_OrganList.GetArchiveList()[i];
if (file->GetID() != id)
continue;
GOArchive *archive = OpenArchive(file->GetPath());
if (!archive)
continue;
if (!ReadIndex(archive, archive->GetArchiveID() != id)) {
delete archive;
continue;
GOArchive *GOArchiveManager::LoadArchive(
const wxString &id, const wxString &archivePath) {
GOArchive *pResArchive = nullptr;

for (const GOArchiveFile *file : m_OrganList.GetArchiveList()) {
const wxString &filePath = file->GetPath();

if (
file->GetID() == id
&& (archivePath.IsEmpty() || filePath == archivePath)) {
GOArchive *archiveProbe = OpenArchive(filePath);

if (archiveProbe) {
bool isSameOrgan = archiveProbe->GetArchiveID() == id;

// if (!isSameOrgan) install organs from the archive but don't use it
if (ReadIndex(archiveProbe, !isSameOrgan) && isSameOrgan) {
pResArchive = archiveProbe;
break;
}
delete archiveProbe;
}
}
if (archive->GetArchiveID() != id) {
delete archive;
continue;
}
return archive;
}
return NULL;
return pResArchive;
}

wxString GOArchiveManager::InstallPackage(
Expand Down
2 changes: 1 addition & 1 deletion src/core/archive/GOArchiveManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GOArchiveManager {
GOArchiveManager(GOOrganList &OrganList, const wxString &cacheDir);
~GOArchiveManager();

GOArchive *LoadArchive(const wxString &id);
GOArchive *LoadArchive(const wxString &id, const wxString &archivePath);
wxString InstallPackage(const wxString &path);
bool RegisterPackage(const wxString &path);
void RegisterPackageDirectory(const wxString &path);
Expand Down
6 changes: 5 additions & 1 deletion src/grandorgue/GOOrganController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,11 @@ wxString GOOrganController::Load(
wxString errMsg;

if (!m_FileStore.LoadArchives(
m_config, m_config.OrganCachePath(), organ.GetArchiveID(), errMsg))
m_config,
m_config.OrganCachePath(),
organ.GetArchiveID(),
organ.GetArchivePath(),
errMsg))
return errMsg;
m_ArchivePath = organ.GetArchivePath();
m_odf = organ.GetODFPath();
Expand Down
14 changes: 9 additions & 5 deletions src/grandorgue/loader/GOFileStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ void GOFileStore::SetDirectory(const wxString &directory) {
bool GOFileStore::LoadArchive(
GOOrganList &organList,
const wxString &cacheDir,
const wxString id,
const wxString &id,
const wxString &archivePath,
const wxString &parentId,
wxString &errMsg) {
bool isOk = true;
GOArchiveManager manager(organList, cacheDir);
GOArchive *archive = manager.LoadArchive(id);
GOArchive *archive = manager.LoadArchive(id, archivePath);

if (archive)
m_archives.push_back(archive);
Expand Down Expand Up @@ -61,15 +62,18 @@ bool GOFileStore::LoadArchive(
bool GOFileStore::LoadArchives(
GOOrganList &organList,
const wxString &cacheDir,
const wxString mainId,
const wxString &mainArchiveId,
const wxString &mainArchivePath,
wxString &errMsg) {
SetDirectory(wxEmptyString); // clean up all

bool isOk = LoadArchive(organList, cacheDir, mainId, wxEmptyString, errMsg);
bool isOk = LoadArchive(
organList, cacheDir, mainArchiveId, mainArchivePath, wxEmptyString, errMsg);

if (isOk)
for (auto depId : m_archives[0]->GetDependencies()) {
isOk = LoadArchive(organList, cacheDir, depId, mainId, errMsg);
isOk = LoadArchive(
organList, cacheDir, depId, wxEmptyString, mainArchiveId, errMsg);
if (!isOk)
break;
}
Expand Down
10 changes: 7 additions & 3 deletions src/grandorgue/loader/GOFileStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class GOFileStore {
bool LoadArchive(
GOOrganList &organList,
const wxString &cacheDir,
const wxString id,
const wxString &id,
const wxString &archivePath,
const wxString &parentId,
wxString &errMsg);

Expand All @@ -50,15 +51,18 @@ class GOFileStore {
* Load archive directories for the given archive id and all it's dependencies
* @param organList - a list of registered organs
* @param cacheDir - a directory to read/write index files
* @param mainId - an identifier of the main archive to load
* @param mainArchiveId - an identifier of the main archive to load
* @param mainArchivePath - an path to the main archive to load. If empty
* then search among organList
* @param errMsg - an error message that is returned if the operation fails
* @return - true if success and false if any error occured (the error message
* is returned in errMsg)
*/
bool LoadArchives(
GOOrganList &organList,
const wxString &cacheDir,
const wxString mainId,
const wxString &mainArchiveId,
const wxString &mainArchivePath,
wxString &errMsg);

/**
Expand Down

0 comments on commit 8b62bfd

Please sign in to comment.