Catalogs: fix enabling/disabling

Relates to bug Michael found in the launcher:
https://sourceforge.net/p/flightgear/codetickets/2380/
This commit is contained in:
Automatic Release Builder 2020-09-30 14:38:35 +01:00 committed by James Turner
parent c0323e34a5
commit ed8ff68114
2 changed files with 18 additions and 11 deletions

View File

@ -595,13 +595,17 @@ void Catalog::setUserEnabled(bool b)
m_userEnabled = b;
SGPath disableMarkerFile = installRoot() / "_disabled_";
if (m_userEnabled) {
sg_ofstream of(disableMarkerFile);
of << "1\n"; // touch the file
if (m_userEnabled == false) {
sg_ofstream of(disableMarkerFile, std::ios::trunc | std::ios::out);
of << "1" << std::flush; // touch the file
of.close();
} else {
bool ok = disableMarkerFile.remove();
if (!ok) {
SG_LOG(SG_GENERAL, SG_ALERT, "Failed to remove catalog-disable marker file:" << disableMarkerFile);
if (disableMarkerFile.exists()) {
const bool ok = disableMarkerFile.remove();
if (!ok) {
SG_LOG(SG_IO, SG_WARN, "Failed to remove catalog-disable marker file:" << disableMarkerFile);
}
}
}

View File

@ -690,14 +690,17 @@ void Root::catalogRefreshStatus(CatalogRef aCat, Delegate::StatusCode aReason)
d->refreshing.erase(aCat);
}
if ((aReason == Delegate::STATUS_REFRESHED) && (catIt == d->catalogs.end())) {
if (aCat->isUserEnabled() &&
(aReason == Delegate::STATUS_REFRESHED) &&
(catIt == d->catalogs.end()))
{
assert(!aCat->id().empty());
d->catalogs.insert(catIt, CatalogDict::value_type(aCat->id(), aCat));
// catalog might have been previously disabled, let's remove in that case
// catalog might have been previously disabled, let's remove in that case
auto j = std::find(d->disabledCatalogs.begin(),
d->disabledCatalogs.end(),
aCat);
d->disabledCatalogs.end(),
aCat);
if (j != d->disabledCatalogs.end()) {
SG_LOG(SG_GENERAL, SG_INFO, "re-enabling disabled catalog:" << aCat->id());
d->disabledCatalogs.erase(j);
@ -705,7 +708,7 @@ void Root::catalogRefreshStatus(CatalogRef aCat, Delegate::StatusCode aReason)
}
if (!aCat->isEnabled()) {
// catalog has errors, disable it
// catalog has errors or was disabled by user, disable it
auto j = std::find(d->disabledCatalogs.begin(),
d->disabledCatalogs.end(),
aCat);