diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_types.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_types.hpp index 5e8238817..e349a3e56 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_types.hpp @@ -58,7 +58,7 @@ namespace ams::ncm { char name[0x10]; }; - alignas(8) struct PlaceHolderId { + struct alignas(8) PlaceHolderId { util::Uuid uuid; bool operator==(const PlaceHolderId& other) const { @@ -80,7 +80,7 @@ namespace ams::ncm { static_assert(alignof(PlaceHolderId) == 8, "PlaceHolderId definition!"); - alignas(4) struct ContentId { + struct alignas(4) ContentId { util::Uuid uuid; bool operator==(const ContentId& other) const { diff --git a/libraries/libvapours/include/vapours/results/ncm_results.hpp b/libraries/libvapours/include/vapours/results/ncm_results.hpp index 1b9b066f3..08175b37c 100644 --- a/libraries/libvapours/include/vapours/results/ncm_results.hpp +++ b/libraries/libvapours/include/vapours/results/ncm_results.hpp @@ -21,7 +21,7 @@ namespace ams::ncm { R_DEFINE_NAMESPACE_RESULT_MODULE(5); - R_DEFINE_ERROR_RESULT(StoragePathNotFound, 1); + R_DEFINE_ERROR_RESULT(InvalidContentStorageBase, 1); R_DEFINE_ERROR_RESULT(PlaceHolderAlreadyExists, 2); R_DEFINE_ERROR_RESULT(PlaceHolderNotFound, 3); R_DEFINE_ERROR_RESULT(ContentAlreadyExists, 4); @@ -33,12 +33,12 @@ namespace ams::ncm { R_DEFINE_ERROR_RESULT(InvalidContentStorage, 100); R_DEFINE_ERROR_RESULT(InvalidContentMetaDatabase, 110); - R_DEFINE_ERROR_RESULT(InvalidPlaceHolderDirectoryEntry, 170); + R_DEFINE_ERROR_RESULT(InvalidPlaceHolderFile, 170); R_DEFINE_ERROR_RESULT(BufferInsufficient, 180); R_DEFINE_ERROR_RESULT(InvalidContentStorageOperation, 190); R_DEFINE_ERROR_RESULT(InvalidContentMetaKey, 240); - R_DEFINE_ERROR_RESULT(StorageRootNotFound, 310); + R_DEFINE_ERROR_RESULT(ContentStorageBaseNotFound, 310); R_DEFINE_ERROR_RANGE(ContentStorageNotActive, 250, 258); R_DEFINE_ERROR_RESULT(GameCardContentStorageNotActive, 251); diff --git a/stratosphere/ncm/source/impl/lr_manager.cpp b/stratosphere/ncm/source/impl/lr_location_resolver_manager_impl.cpp similarity index 76% rename from stratosphere/ncm/source/impl/lr_manager.cpp rename to stratosphere/ncm/source/impl/lr_location_resolver_manager_impl.cpp index 4ca529681..1d498f3e2 100644 --- a/stratosphere/ncm/source/impl/lr_manager.cpp +++ b/stratosphere/ncm/source/impl/lr_location_resolver_manager_impl.cpp @@ -16,21 +16,11 @@ #include "../lr_contentlocationresolver.hpp" #include "../lr_redirectonlylocationresolver.hpp" -#include "lr_manager.hpp" -#include "ncm_bounded_map.hpp" +#include "lr_location_resolver_manager_impl.hpp" namespace ams::lr::impl { - namespace { - - ncm::impl::BoundedMap, 5> g_location_resolvers; - std::shared_ptr g_registered_location_resolver = nullptr; - std::shared_ptr g_add_on_content_location_resolver = nullptr; - os::Mutex g_mutex; - - } - - Result OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id) { + Result LocationResolverManagerImpl::OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id) { std::scoped_lock lk(g_mutex); auto resolver = g_location_resolvers.Find(storage_id); @@ -50,7 +40,7 @@ namespace ams::lr::impl { return ResultSuccess(); } - Result OpenRegisteredLocationResolver(sf::Out> out) { + Result LocationResolverManagerImpl::OpenRegisteredLocationResolver(sf::Out> out) { std::scoped_lock lk(g_mutex); if (!g_registered_location_resolver) { @@ -62,7 +52,7 @@ namespace ams::lr::impl { return ResultSuccess(); } - Result RefreshLocationResolver(ncm::StorageId storage_id) { + Result LocationResolverManagerImpl::RefreshLocationResolver(ncm::StorageId storage_id) { std::scoped_lock lk(g_mutex); auto resolver = g_location_resolvers.Find(storage_id); @@ -75,7 +65,7 @@ namespace ams::lr::impl { return ResultSuccess(); } - Result OpenAddOnContentLocationResolver(sf::Out> out) { + Result LocationResolverManagerImpl::OpenAddOnContentLocationResolver(sf::Out> out) { std::scoped_lock lk(g_mutex); if (!g_add_on_content_location_resolver) { diff --git a/stratosphere/ncm/source/impl/lr_location_resolver_manager_impl.hpp b/stratosphere/ncm/source/impl/lr_location_resolver_manager_impl.hpp new file mode 100644 index 000000000..297aa44c6 --- /dev/null +++ b/stratosphere/ncm/source/impl/lr_location_resolver_manager_impl.hpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2019 Adubbz + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include + +#include "../lr_addoncontentlocationresolver.hpp" +#include "../lr_ilocationresolver.hpp" +#include "../lr_i_location_resolver_manager.hpp" +#include "../lr_registeredlocationresolver.hpp" +#include "ncm_bounded_map.hpp" + +namespace ams::lr::impl { + + class LocationResolverManagerImpl final : public ILocationResolverManager { + private: + ncm::impl::BoundedMap, 5> g_location_resolvers; + std::shared_ptr g_registered_location_resolver = nullptr; + std::shared_ptr g_add_on_content_location_resolver = nullptr; + os::Mutex g_mutex; + public: + /* Actual commands. */ + virtual Result OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id) override; + virtual Result OpenRegisteredLocationResolver(sf::Out> out) override; + virtual Result RefreshLocationResolver(ncm::StorageId storage_id) override; + virtual Result OpenAddOnContentLocationResolver(sf::Out> out) override; + }; + +} diff --git a/stratosphere/ncm/source/impl/lr_manager.hpp b/stratosphere/ncm/source/impl/lr_manager.hpp deleted file mode 100644 index 0032642c0..000000000 --- a/stratosphere/ncm/source/impl/lr_manager.hpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2019 Adubbz - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once -#include -#include - -#include "../lr_addoncontentlocationresolver.hpp" -#include "../lr_ilocationresolver.hpp" -#include "../lr_registeredlocationresolver.hpp" - -namespace ams::lr::impl { - - /* Location Resolver API. */ - Result OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id); - Result OpenRegisteredLocationResolver(sf::Out> out); - Result RefreshLocationResolver(ncm::StorageId storage_id); - Result OpenAddOnContentLocationResolver(sf::Out> out); - -} diff --git a/stratosphere/ncm/source/impl/lr_redirection.cpp b/stratosphere/ncm/source/impl/lr_redirection.cpp index cde4227b9..4db28a03b 100644 --- a/stratosphere/ncm/source/impl/lr_redirection.cpp +++ b/stratosphere/ncm/source/impl/lr_redirection.cpp @@ -107,24 +107,14 @@ namespace ams::lr::impl { void LocationRedirector::ClearRedirections(const ncm::ProgramId* excluding_ids, size_t num_ids) { for (auto it = this->redirection_list.begin(); it != this->redirection_list.end();) { - bool skip = false; - for (size_t i = 0; i < num_ids; i++) { - ncm::ProgramId id = excluding_ids[i]; - - if (it->GetOwnerProgramId() == id) { - skip = true; - break; - } - } - - if (skip) { + if (this->IsExcluded(it->GetOwnerProgramId(), excluding_ids, num_ids)) { + it++; continue; } auto old = it; it = this->redirection_list.erase(it); delete &(*old); - it++; } } diff --git a/stratosphere/ncm/source/impl/lr_redirection.hpp b/stratosphere/ncm/source/impl/lr_redirection.hpp index d3b854cdc..52ac180fe 100644 --- a/stratosphere/ncm/source/impl/lr_redirection.hpp +++ b/stratosphere/ncm/source/impl/lr_redirection.hpp @@ -42,6 +42,16 @@ namespace ams::lr::impl { void EraseRedirection(ncm::ProgramId program_id); void ClearRedirections(u32 flags = RedirectionFlags_None); void ClearRedirections(const ncm::ProgramId* excluding_ids, size_t num_ids); + private: + inline bool IsExcluded(const ncm::ProgramId id, const ncm::ProgramId* excluding_ids, size_t num_ids) const { + for (size_t i = 0; i < num_ids; i++) { + if (id == excluding_ids[i]) { + return true; + } + } + + return false; + } }; } diff --git a/stratosphere/ncm/source/lr_contentlocationresolver.hpp b/stratosphere/ncm/source/lr_contentlocationresolver.hpp index a53e142b9..474766d14 100644 --- a/stratosphere/ncm/source/lr_contentlocationresolver.hpp +++ b/stratosphere/ncm/source/lr_contentlocationresolver.hpp @@ -18,7 +18,6 @@ #include #include -#include "impl/lr_manager.hpp" #include "lr_ilocationresolver.hpp" #include "ncm_icontentmetadatabase.hpp" #include "ncm_icontentstorage.hpp" diff --git a/stratosphere/ncm/source/lr_manager_service.hpp b/stratosphere/ncm/source/lr_i_location_resolver_manager.hpp similarity index 89% rename from stratosphere/ncm/source/lr_manager_service.hpp rename to stratosphere/ncm/source/lr_i_location_resolver_manager.hpp index bdab705af..005a3c981 100644 --- a/stratosphere/ncm/source/lr_manager_service.hpp +++ b/stratosphere/ncm/source/lr_i_location_resolver_manager.hpp @@ -24,7 +24,7 @@ namespace ams::lr { - class LocationResolverManagerService final : public sf::IServiceObject { + class ILocationResolverManager : public sf::IServiceObject { protected: enum class CommandId { OpenLocationResolver = 0, @@ -34,10 +34,10 @@ namespace ams::lr { }; public: /* Actual commands. */ - virtual Result OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id); - virtual Result OpenRegisteredLocationResolver(sf::Out> out); - virtual Result RefreshLocationResolver(ncm::StorageId storage_id); - virtual Result OpenAddOnContentLocationResolver(sf::Out> out); + virtual Result OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id) = 0; + virtual Result OpenRegisteredLocationResolver(sf::Out> out) = 0; + virtual Result RefreshLocationResolver(ncm::StorageId storage_id) = 0; + virtual Result OpenAddOnContentLocationResolver(sf::Out> out) = 0; public: DEFINE_SERVICE_DISPATCH_TABLE { MAKE_SERVICE_COMMAND_META(OpenLocationResolver), diff --git a/stratosphere/ncm/source/lr_manager_service.cpp b/stratosphere/ncm/source/lr_manager_service.cpp deleted file mode 100644 index 47b3d50a3..000000000 --- a/stratosphere/ncm/source/lr_manager_service.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2019 Adubbz - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include - -#include "impl/lr_manager.hpp" -#include "lr_manager_service.hpp" - -namespace ams::lr { - - Result LocationResolverManagerService::OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id) { - return impl::OpenLocationResolver(out, storage_id); - } - - Result LocationResolverManagerService::OpenRegisteredLocationResolver(sf::Out> out) { - return impl::OpenRegisteredLocationResolver(out); - } - - Result LocationResolverManagerService::RefreshLocationResolver(ncm::StorageId storage_id) { - return impl::RefreshLocationResolver(storage_id); - } - - Result LocationResolverManagerService::OpenAddOnContentLocationResolver(sf::Out> out) { - return impl::OpenAddOnContentLocationResolver(out); - } - -} diff --git a/stratosphere/ncm/source/ncm_fs.cpp b/stratosphere/ncm/source/ncm_fs.cpp index c529c808c..dd4f31c3e 100644 --- a/stratosphere/ncm/source/ncm_fs.cpp +++ b/stratosphere/ncm/source/ncm_fs.cpp @@ -104,17 +104,17 @@ namespace ams::ncm::fs { bool has_root = false; R_TRY(HasDirectory(&has_root, root_path)); - R_UNLESS(has_root, ncm::ResultStorageRootNotFound()); + R_UNLESS(has_root, ncm::ResultContentStorageBaseNotFound()); path::GetContentRootPath(content_root, root_path); bool has_content_root = false; R_TRY(HasDirectory(&has_content_root, content_root)); - R_UNLESS(has_content_root, ncm::ResultStoragePathNotFound()); + R_UNLESS(has_content_root, ncm::ResultInvalidContentStorageBase()); path::GetPlaceHolderRootPath(placeholder_root, root_path); bool has_placeholder_root = false; R_TRY(HasDirectory(&has_placeholder_root, placeholder_root)); - R_UNLESS(has_placeholder_root, ncm::ResultStoragePathNotFound()); + R_UNLESS(has_placeholder_root, ncm::ResultInvalidContentStorageBase()); return ResultSuccess(); } diff --git a/stratosphere/ncm/source/ncm_main.cpp b/stratosphere/ncm/source/ncm_main.cpp index caa4c7cfb..72379b92f 100644 --- a/stratosphere/ncm/source/ncm_main.cpp +++ b/stratosphere/ncm/source/ncm_main.cpp @@ -17,7 +17,7 @@ #include #include "impl/ncm_content_manager.hpp" -#include "lr_manager_service.hpp" +#include "impl/lr_location_resolver_manager_impl.hpp" #include "ncm_content_manager_service.hpp" extern "C" { @@ -115,7 +115,7 @@ void ContentManagerServerMain(void* arg) { void LocationResolverServerMain(void* arg) { /* Create services. */ - R_ABORT_UNLESS(g_lr_server_manager.RegisterServer(LrServiceName, LrMaxSessions)); + R_ABORT_UNLESS(g_lr_server_manager.RegisterServer(LrServiceName, LrMaxSessions)); /* Loop forever, servicing our services. */ g_lr_server_manager.LoopProcess(); diff --git a/stratosphere/ncm/source/ncm_utils.cpp b/stratosphere/ncm/source/ncm_utils.cpp index c78f34b09..ea59ead3b 100644 --- a/stratosphere/ncm/source/ncm_utils.cpp +++ b/stratosphere/ncm/source/ncm_utils.cpp @@ -31,8 +31,8 @@ namespace ams::ncm { } Result GetPlaceHolderIdFromDirEntry(PlaceHolderId* out, struct dirent* dir_entry) { - R_UNLESS(strnlen(dir_entry->d_name, 0x30) == 0x24, ncm::ResultInvalidPlaceHolderDirectoryEntry()); - R_UNLESS(strncmp(dir_entry->d_name + 0x20, ".nca", 4) == 0, ncm::ResultInvalidPlaceHolderDirectoryEntry()); + R_UNLESS(strnlen(dir_entry->d_name, 0x30) == 0x24, ncm::ResultInvalidPlaceHolderFile()); + R_UNLESS(strncmp(dir_entry->d_name + 0x20, ".nca", 4) == 0, ncm::ResultInvalidPlaceHolderFile()); u8 tmp[sizeof(PlaceHolderId)] = {}; char byte_string[2];