lr: add support for location resolver disable commands
This commit is contained in:
@@ -27,10 +27,19 @@ namespace ams::lr {
|
||||
using ContentLocationResolverFactory = sf::ObjectFactory<sf::StdAllocationPolicy<std::allocator>>;
|
||||
using RedirectOnlyLocationResolverFactory = sf::ObjectFactory<sf::StdAllocationPolicy<std::allocator>>;
|
||||
|
||||
bool IsAcceptableStorageId(ncm::StorageId storage_id) {
|
||||
if (ncm::IsInstallableStorage(storage_id)) {
|
||||
return storage_id != ncm::StorageId::Any;
|
||||
} else {
|
||||
return storage_id == ncm::StorageId::Host || storage_id == ncm::StorageId::GameCard;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result LocationResolverManagerImpl::OpenLocationResolver(sf::Out<sf::SharedPointer<ILocationResolver>> out, ncm::StorageId storage_id) {
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* Find an existing resolver. */
|
||||
auto resolver = m_location_resolvers.Find(storage_id);
|
||||
|
||||
@@ -39,7 +48,11 @@ namespace ams::lr {
|
||||
if (storage_id == ncm::StorageId::Host) {
|
||||
AMS_ABORT_UNLESS(m_location_resolvers.Insert(storage_id, RedirectOnlyLocationResolverFactory::CreateSharedEmplaced<ILocationResolver, RedirectOnlyLocationResolverImpl>()));
|
||||
} else {
|
||||
auto content_resolver = ContentLocationResolverFactory::CreateSharedEmplaced<ILocationResolver, ContentLocationResolverImpl>(storage_id);
|
||||
/* Get enabled. */
|
||||
auto *enabled = m_location_resolvers_enabled.Find(storage_id);
|
||||
|
||||
/* Create the resolver. */
|
||||
auto content_resolver = ContentLocationResolverFactory::CreateSharedEmplaced<ILocationResolver, ContentLocationResolverImpl>(storage_id, enabled != nullptr ? *enabled : m_default_enabled);
|
||||
R_TRY(content_resolver->Refresh());
|
||||
AMS_ABORT_UNLESS(m_location_resolvers.Insert(storage_id, std::move(content_resolver)));
|
||||
}
|
||||
@@ -94,4 +107,39 @@ namespace ams::lr {
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result LocationResolverManagerImpl::SetEnabled(const sf::InMapAliasArray<ncm::StorageId> &storages) {
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* If we're setting enabled, we're no longer enabled by default. */
|
||||
m_default_enabled = false;
|
||||
|
||||
/* Create entries for each storage. */
|
||||
for (size_t i = 0; i < storages.GetSize(); ++i) {
|
||||
/* Get the storage id. */
|
||||
const auto storage_id = storages[i];
|
||||
|
||||
/* Check that the storage id is acceptable. */
|
||||
R_UNLESS(IsAcceptableStorageId(storage_id), lr::ResultUnknownStorageId());
|
||||
|
||||
/* Set the storage id as enabled. */
|
||||
AMS_ABORT_UNLESS(m_location_resolvers_enabled.InsertOrAssign(storage_id, true));
|
||||
}
|
||||
|
||||
/* Disable any open storages which shouldn't be enabled. */
|
||||
m_location_resolvers.ForEach([&](ncm::StorageId storage_id, sf::SharedPointer<ILocationResolver> &resolver) -> void {
|
||||
/* Check if the storage id is contained in the input array. */
|
||||
for (size_t i = 0; i < storages.GetSize(); ++i) {
|
||||
if (storages[i] == storage_id) {
|
||||
/* The storage is enabled, so we can return. */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* The storage isn't enabled, so disable it. */
|
||||
R_ABORT_UNLESS(resolver->Disable());
|
||||
});
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user