Catalogs: fix enabling/disabling
Relates to bug Michael found in the launcher: https://sourceforge.net/p/flightgear/codetickets/2380/
This commit is contained in:
parent
c0323e34a5
commit
ed8ff68114
@ -595,13 +595,17 @@ void Catalog::setUserEnabled(bool b)
|
|||||||
|
|
||||||
m_userEnabled = b;
|
m_userEnabled = b;
|
||||||
SGPath disableMarkerFile = installRoot() / "_disabled_";
|
SGPath disableMarkerFile = installRoot() / "_disabled_";
|
||||||
if (m_userEnabled) {
|
|
||||||
sg_ofstream of(disableMarkerFile);
|
if (m_userEnabled == false) {
|
||||||
of << "1\n"; // touch the file
|
sg_ofstream of(disableMarkerFile, std::ios::trunc | std::ios::out);
|
||||||
|
of << "1" << std::flush; // touch the file
|
||||||
|
of.close();
|
||||||
} else {
|
} else {
|
||||||
bool ok = disableMarkerFile.remove();
|
if (disableMarkerFile.exists()) {
|
||||||
if (!ok) {
|
const bool ok = disableMarkerFile.remove();
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Failed to remove catalog-disable marker file:" << disableMarkerFile);
|
if (!ok) {
|
||||||
|
SG_LOG(SG_IO, SG_WARN, "Failed to remove catalog-disable marker file:" << disableMarkerFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -690,14 +690,17 @@ void Root::catalogRefreshStatus(CatalogRef aCat, Delegate::StatusCode aReason)
|
|||||||
d->refreshing.erase(aCat);
|
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());
|
assert(!aCat->id().empty());
|
||||||
d->catalogs.insert(catIt, CatalogDict::value_type(aCat->id(), aCat));
|
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(),
|
auto j = std::find(d->disabledCatalogs.begin(),
|
||||||
d->disabledCatalogs.end(),
|
d->disabledCatalogs.end(),
|
||||||
aCat);
|
aCat);
|
||||||
if (j != d->disabledCatalogs.end()) {
|
if (j != d->disabledCatalogs.end()) {
|
||||||
SG_LOG(SG_GENERAL, SG_INFO, "re-enabling disabled catalog:" << aCat->id());
|
SG_LOG(SG_GENERAL, SG_INFO, "re-enabling disabled catalog:" << aCat->id());
|
||||||
d->disabledCatalogs.erase(j);
|
d->disabledCatalogs.erase(j);
|
||||||
@ -705,7 +708,7 @@ void Root::catalogRefreshStatus(CatalogRef aCat, Delegate::StatusCode aReason)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!aCat->isEnabled()) {
|
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(),
|
auto j = std::find(d->disabledCatalogs.begin(),
|
||||||
d->disabledCatalogs.end(),
|
d->disabledCatalogs.end(),
|
||||||
aCat);
|
aCat);
|
||||||
|
Loading…
Reference in New Issue
Block a user