mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-29 22:15:17 -04:00
Implement the NCM sysmodule (closes #91)
* Implement NCM * Modernize ncm_main * Remove unnecessary smExit * Give access to svcCallSecureMonitor * Stack size bump * Fix incorrect setup for NandUser's content storage entry * Fix a potential data abort when flushing the placeholder accessor cache * Fix HasFile and HasDirectory * Use r+b, not w+b * Misc fixes * errno begone * Fixed more stdio error handling * More main fixes * Various command improvements * Make dispatch tables great again * Fix logic inversion * Fixed content path generation * Bump heap size, fix CleanupAllPlaceHolder * Various fixes. Note: This contains debug stuff which will be removed later. I was getting tired of having to cherrypick tiny changes * Fixed placeholder/content deletion * Fixed incorrect content manager destruction * Prevent automatic placeholder creation on open * Fixed List implementation. Also lots of debug logging. * Removed debug code * Added a scope guard for WritePlaceHolder * Manually prevent placeholder/content appending * Revert "Removed debug code" This reverts commitd6ff261fcc
. * Always cache placeholder file. Switch to ftell for preventing appending * Universally use EnsureEnabled * Abstract away file writing logic * Misc cleanup * Refactor placeholder cacheing * Remove debug code (again) * Revert "Remove debug code (again)" This reverts commit168447d80e
. * Misc changes * Fixed file modes * Fixed ContentId/PlaceHolderId alignment * Improved type safety * Fixed reinitialization * Fixed doubleup on path creation * Remove debug code * Fixed 1.0.0 booting * Correct amount of add on content * Correct main thread stack size * lr: Introducing registered data * Reorder stratosphere Makefile * Move results to libstrat * lr: Cleanup lr_redirection * lr: lr_manager tweaks * lr: Imrpoved path handling and adjust ResolveAddOnContentPath order * lr: Organise types * Add eof newlines * lr: Eliminate unnecessary vars * lr: Unnecessary vars 2 electric boogaloo * lr: Various helpers * lr: RegisteredLocationResolver helpers * ncm: Move ncm_types to libstrat * ncm: Misc cleanup * Implement NCM * Modernize ncm_main * Remove unnecessary smExit * Give access to svcCallSecureMonitor * Stack size bump * Fix incorrect setup for NandUser's content storage entry * Fix a potential data abort when flushing the placeholder accessor cache * Fix HasFile and HasDirectory * Use r+b, not w+b * Misc fixes * errno begone * Fixed more stdio error handling * More main fixes * Various command improvements * Make dispatch tables great again * Fix logic inversion * Fixed content path generation * Bump heap size, fix CleanupAllPlaceHolder * Various fixes. Note: This contains debug stuff which will be removed later. I was getting tired of having to cherrypick tiny changes * Fixed placeholder/content deletion * Fixed incorrect content manager destruction * Prevent automatic placeholder creation on open * Fixed List implementation. Also lots of debug logging. * Removed debug code * Added a scope guard for WritePlaceHolder * Manually prevent placeholder/content appending * Revert "Removed debug code" This reverts commitd6ff261fcc
. * Always cache placeholder file. Switch to ftell for preventing appending * Universally use EnsureEnabled * Abstract away file writing logic * Misc cleanup * Refactor placeholder cacheing * Remove debug code (again) * Revert "Remove debug code (again)" This reverts commit168447d80e
. * Misc changes * Fixed file modes * Fixed ContentId/PlaceHolderId alignment * Improved type safety * Fixed reinitialization * Fixed doubleup on path creation * Remove debug code * Fixed 1.0.0 booting * Correct amount of add on content * Correct main thread stack size * lr: Introducing registered data * Reorder stratosphere Makefile * Move results to libstrat * lr: Cleanup lr_redirection * lr: lr_manager tweaks * lr: Imrpoved path handling and adjust ResolveAddOnContentPath order * lr: Organise types * Add eof newlines * lr: Eliminate unnecessary vars * lr: Unnecessary vars 2 electric boogaloo * lr: Various helpers * lr: RegisteredLocationResolver helpers * ncm: Move ncm_types to libstrat * ncm: Misc cleanup * Updated AddOnContentLocationResolver and RegisteredLocationResolver to 9.0.0 * Finished updating lr to 9.0.0 * Updated NCM to 9.0.0 * Fix libstrat includes * Fixed application launching * title_id_2 -> owner_tid * Updated to new-ipc * Change to using pure virtuals * Title Id -> Program Id * Fixed compilation against master * std::scoped_lock<> -> std::scoped_lock * Adopted R_UNLESS and R_CONVERT * Prefix namespace to Results * Adopt std::numeric_limits * Fixed incorrect error handling in ReadFile * Adopted AMS_ABORT_UNLESS * Adopt util::GenerateUuid() * Syntax improvements * ncm_types: Address review * Address more review comments * Updated copyrights * Address more feedback * More feedback addressed * More changes * Move dispatch tables out of interface files * Addressed remaining comments * lr: move into libstratosphere * ncm: Fix logic inversion * lr: Add comments * lr: Remove whitespace * ncm: Start addressing feedback * ncm: Cleanup InitializeContentManager * lr: support client-side usage * lr_service -> lr_api * ncm: Begin refactoring content manager * ncm: More content manager improvements * ncm: Content manager mount improvements * ldr: use lr bindings * lr bindings usage: minor fixes * ncm/lr: Pointer placement * ncm: placeholder accessor cleanup * ncm: minor fixes * ncm: refactor rights cache * ncm: content meta database cleanup * ncm: move content meta database impl out of interface file * ncm: Use const ContentMetaKey & * ncm: fix other non-const ContentMetaKey references * ncm: content meta database cleanup * ncm: content storage fixes for 2.0.0 * ncm: add missing end of file newlines * ncm: implement ContentMetaReader * ncm: client-side api * ncm: trim trailing spaces * ncm: FS_MAX_PATH-1 -> fs::EntryNameLengthMax * ncm: Use PathString and Path * fs: implement accessor wrappers for ncm * fs: implement user fs wrappers * fs: add MountSdCard * ncm: move to content manager impl * ncm: fix up main * kvdb: use fs:: * fs: Add wrappers needed for ncm * ncm: use fs bindings, other refactoring * ncm: minor fixes * fsa: fix ReadFile without size output * fs: add substorage, rom path tool * ncm: fix dangling fsdev usage * fs: fix bug in Commit * fs: fixed incorrect mode check * fs: implement Mount(System)Data * ncm: don't delete hos * results: add R_SUCCEED_IF * ams-except-ncm: use R_SUCCEED_IF * ncm: added comments * ncm: fix api definitions * ncm: use R_SUCCEED_IF * pm: think of the savings * ncm: employ kernel strats * ncm: Nintendo has 5 MiB of heap. Give ourselves 4 to be safe, pending analysis * ncm: refactor IDs, split types header into many headers * ams.mitm: use fs bindings instead of stdio * fs: SystemData uses SystemDataId * ncm: improve meta-db accuracy * ncm: inline getlatestkey * fs: improve UnsupportedOperation results * fs: modernize mount utils * ams: misc fixes for merge-errors * fs: improve unsupportedoperation results * git subrepo pull emummc subrepo: subdir: "emummc" merged: "d12dd546" upstream: origin: "https://github.com/m4xw/emuMMC" branch: "develop" commit: "d12dd546" git-subrepo: version: "0.4.1" origin: "???" commit: "???" * util: add boundedmap * ncm: minor style fixes * ncm: don't unmount if mounting fails * lr: bug fixes * ncm: implement ncm.for-initialize + ncm.for-safemode * lr: ncm::ProgramId::Invalid -> ncm::InvalidProgramId * ncm: fix open directory mode on 1.0.0 * ncm: fix fs use, implement more of < 4.0.0 for-initialize/safemode * ncm: implement packagedcontent -> content for building metadb * ncm: fix save data flag management * ncm: address some review suggestions (thanks @leoetlino!) * updater: use fs bindings * fs: implement MountCode * fs: prefer make_unique to operator new * ncm: implement remaining ContentMetaDatabaseBuilder functionality Co-authored-by: Michael Scire <SciresM@gmail.com>
This commit is contained in:
parent
f9403201f0
commit
c7026b9094
254 changed files with 16876 additions and 1274 deletions
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "lr_add_on_content_location_resolver_impl.hpp"
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
Result AddOnContentLocationResolverImpl::ResolveAddOnContentPath(sf::Out<Path> out, ncm::DataId id) {
|
||||
/* Find a storage that contains the given program id. */
|
||||
ncm::StorageId storage_id = ncm::StorageId::None;
|
||||
R_UNLESS(this->registered_storages.Find(&storage_id, id), lr::ResultAddOnContentNotFound());
|
||||
|
||||
/* Obtain a content meta database for the storage id. */
|
||||
ncm::ContentMetaDatabase content_meta_database;
|
||||
R_TRY(ncm::OpenContentMetaDatabase(&content_meta_database, storage_id));
|
||||
|
||||
/* Find the latest data content id for the given program id. */
|
||||
ncm::ContentId data_content_id;
|
||||
R_TRY(content_meta_database.GetLatestData(&data_content_id, id));
|
||||
|
||||
/* Obtain a content storage for the storage id. */
|
||||
ncm::ContentStorage content_storage;
|
||||
R_TRY(ncm::OpenContentStorage(&content_storage, storage_id));
|
||||
|
||||
/* Get the path of the data content. */
|
||||
static_assert(sizeof(lr::Path) == sizeof(ncm::Path));
|
||||
content_storage.GetPath(reinterpret_cast<ncm::Path *>(out.GetPointer()), data_content_id);
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result AddOnContentLocationResolverImpl::RegisterAddOnContentStorageDeprecated(ncm::DataId id, ncm::StorageId storage_id) {
|
||||
/* Register storage for the given program id. 2.0.0-8.1.0 did not require an owner application id. */
|
||||
R_UNLESS(this->registered_storages.Register(id, storage_id, ncm::InvalidApplicationId), lr::ResultTooManyRegisteredPaths());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result AddOnContentLocationResolverImpl::RegisterAddOnContentStorage(ncm::DataId id, ncm::ApplicationId application_id, ncm::StorageId storage_id) {
|
||||
/* Register storage for the given program id and owner application. */
|
||||
R_UNLESS(this->registered_storages.Register(id, storage_id, application_id), lr::ResultTooManyRegisteredPaths());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result AddOnContentLocationResolverImpl::UnregisterAllAddOnContentPath() {
|
||||
this->registered_storages.Clear();
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result AddOnContentLocationResolverImpl::RefreshApplicationAddOnContent(const sf::InArray<ncm::ApplicationId> &ids) {
|
||||
if (ids.GetSize() == 0) {
|
||||
/* Clear all registered storages. */
|
||||
this->registered_storages.Clear();
|
||||
} else {
|
||||
/* Clear all registered storages excluding the provided program ids. */
|
||||
this->registered_storages.ClearExcluding(reinterpret_cast<const ncm::ProgramId *>(ids.GetPointer()), ids.GetSize());
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result AddOnContentLocationResolverImpl::UnregisterApplicationAddOnContent(ncm::ApplicationId id) {
|
||||
/* Remove entries belonging to the provided application. */
|
||||
this->registered_storages.UnregisterOwnerProgram(id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
#include "lr_location_redirector.hpp"
|
||||
#include "lr_registered_data.hpp"
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
class AddOnContentLocationResolverImpl : public IAddOnContentLocationResolver {
|
||||
private:
|
||||
/* Storage for RegisteredData entries by data id. */
|
||||
RegisteredStorages<ncm::DataId, 0x800> registered_storages;
|
||||
public:
|
||||
AddOnContentLocationResolverImpl() : registered_storages(hos::GetVersion() < hos::Version_900 ? 0x800 : 0x2) { /* ... */ }
|
||||
|
||||
/* Actual commands. */
|
||||
virtual Result ResolveAddOnContentPath(sf::Out<Path> out, ncm::DataId id) override;
|
||||
virtual Result RegisterAddOnContentStorageDeprecated(ncm::DataId id, ncm::StorageId storage_id) override;
|
||||
virtual Result RegisterAddOnContentStorage(ncm::DataId id, ncm::ApplicationId application_id, ncm::StorageId storage_id) override;
|
||||
virtual Result UnregisterAllAddOnContentPath() override;
|
||||
virtual Result RefreshApplicationAddOnContent(const sf::InArray<ncm::ApplicationId> &ids) override;
|
||||
virtual Result UnregisterApplicationAddOnContent(ncm::ApplicationId id) override;
|
||||
};
|
||||
|
||||
}
|
66
libraries/libstratosphere/source/lr/lr_api.cpp
Normal file
66
libraries/libstratosphere/source/lr/lr_api.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "lr_remote_location_resolver_impl.hpp"
|
||||
#include "lr_remote_registered_location_resolver_impl.hpp"
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
namespace {
|
||||
|
||||
bool g_initialized;
|
||||
|
||||
}
|
||||
|
||||
void Initialize() {
|
||||
AMS_ASSERT(!g_initialized);
|
||||
R_ABORT_UNLESS(lrInitialize());
|
||||
g_initialized = true;
|
||||
}
|
||||
|
||||
void Finalize() {
|
||||
AMS_ASSERT(g_initialized);
|
||||
lrExit();
|
||||
g_initialized = false;
|
||||
}
|
||||
|
||||
|
||||
Result OpenLocationResolver(LocationResolver *out, ncm::StorageId storage_id) {
|
||||
LrLocationResolver lr;
|
||||
R_TRY(lrOpenLocationResolver(static_cast<NcmStorageId>(storage_id), std::addressof(lr)));
|
||||
|
||||
*out = LocationResolver(std::make_shared<RemoteLocationResolverImpl>(lr));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result OpenRegisteredLocationResolver(RegisteredLocationResolver *out) {
|
||||
LrRegisteredLocationResolver lr;
|
||||
R_TRY(lrOpenRegisteredLocationResolver(std::addressof(lr)));
|
||||
|
||||
*out = RegisteredLocationResolver(std::make_shared<RemoteRegisteredLocationResolverImpl>(lr));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result OpenAddOnContentLocationResolver(AddOnContentLocationResolver *out) {
|
||||
/* TODO: libnx binding */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result RefreshLocationResolver(ncm::StorageId storage_id) {
|
||||
/* TODO: libnx binding */
|
||||
AMS_ABORT();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,197 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "lr_content_location_resolver_impl.hpp"
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
ContentLocationResolverImpl::~ContentLocationResolverImpl() {
|
||||
this->ClearRedirections();
|
||||
}
|
||||
|
||||
/* Helper function. */
|
||||
void ContentLocationResolverImpl::GetContentStoragePath(Path *out, ncm::ContentId content_id) {
|
||||
static_assert(sizeof(lr::Path) == sizeof(ncm::Path));
|
||||
this->content_storage.GetPath(reinterpret_cast<ncm::Path *>(out), content_id);
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
/* Use a redirection if present. */
|
||||
R_SUCCEED_IF(this->program_redirector.FindRedirection(out.GetPointer(), id));
|
||||
|
||||
/* Find the latest program content for the program id. */
|
||||
ncm::ContentId program_content_id;
|
||||
R_TRY_CATCH(this->content_meta_database.GetLatestProgram(&program_content_id, id)) {
|
||||
R_CONVERT(ncm::ResultContentMetaNotFound, lr::ResultProgramNotFound())
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
/* Obtain the content path. */
|
||||
this->GetContentStoragePath(out.GetPointer(), program_content_id);
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::RedirectProgramPath(const Path &path, ncm::ProgramId id) {
|
||||
this->program_redirector.SetRedirection(id, path);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
R_UNLESS(this->app_control_redirector.FindRedirection(out.GetPointer(), id), lr::ResultControlNotFound());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
R_UNLESS(this->html_docs_redirector.FindRedirection(out.GetPointer(), id), lr::ResultHtmlDocumentNotFound());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::ResolveDataPath(sf::Out<Path> out, ncm::DataId id) {
|
||||
/* Find the latest data content for the program id. */
|
||||
ncm::ContentId data_content_id;
|
||||
R_TRY(this->content_meta_database.GetLatestData(&data_content_id, id));
|
||||
|
||||
/* Obtain the content path. */
|
||||
this->GetContentStoragePath(out.GetPointer(), data_content_id);
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) {
|
||||
this->app_control_redirector.SetRedirection(id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
|
||||
this->app_control_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) {
|
||||
this->html_docs_redirector.SetRedirection(id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
|
||||
this->html_docs_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
R_UNLESS(this->legal_info_redirector.FindRedirection(out.GetPointer(), id), lr::ResultLegalInformationNotFound());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) {
|
||||
this->legal_info_redirector.SetRedirection(id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
|
||||
this->legal_info_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::Refresh() {
|
||||
/* Obtain content meta database and content storage objects for this resolver's storage. */
|
||||
ncm::ContentMetaDatabase meta_db;
|
||||
ncm::ContentStorage storage;
|
||||
R_TRY(ncm::OpenContentMetaDatabase(&meta_db, this->storage_id));
|
||||
R_TRY(ncm::OpenContentStorage(&storage, this->storage_id));
|
||||
|
||||
/* Store the acquired objects. */
|
||||
this->content_meta_database = std::move(meta_db);
|
||||
this->content_storage = std::move(storage);
|
||||
|
||||
/* Remove any existing redirections. */
|
||||
this->ClearRedirections();
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) {
|
||||
this->program_redirector.SetRedirection(id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
|
||||
this->program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::ClearApplicationRedirectionDeprecated() {
|
||||
this->ClearRedirections(RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::ClearApplicationRedirection(const sf::InArray<ncm::ProgramId> &excluding_ids) {
|
||||
this->ClearRedirections(excluding_ids.GetPointer(), excluding_ids.GetSize());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::EraseProgramRedirection(ncm::ProgramId id) {
|
||||
this->program_redirector.EraseRedirection(id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::EraseApplicationControlRedirection(ncm::ProgramId id) {
|
||||
this->app_control_redirector.EraseRedirection(id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) {
|
||||
this->html_docs_redirector.EraseRedirection(id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::EraseApplicationLegalInformationRedirection(ncm::ProgramId id) {
|
||||
this->legal_info_redirector.EraseRedirection(id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
/* Use a redirection if present. */
|
||||
R_SUCCEED_IF(this->debug_program_redirector.FindRedirection(out.GetPointer(), id));
|
||||
|
||||
/* Otherwise find the path for the program id. */
|
||||
R_TRY_CATCH(this->ResolveProgramPath(out.GetPointer(), id)) {
|
||||
R_CONVERT(ResultProgramNotFound, lr::ResultDebugProgramNotFound())
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) {
|
||||
this->debug_program_redirector.SetRedirection(id, path);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) {
|
||||
this->debug_program_redirector.SetRedirection(id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
|
||||
this->debug_program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ContentLocationResolverImpl::EraseProgramRedirectionForDebug(ncm::ProgramId id) {
|
||||
this->debug_program_redirector.EraseRedirection(id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "lr_location_resolver_impl_base.hpp"
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
class ContentLocationResolverImpl : public LocationResolverImplBase {
|
||||
private:
|
||||
ncm::StorageId storage_id;
|
||||
|
||||
/* Objects for this storage type. */
|
||||
ncm::ContentMetaDatabase content_meta_database;
|
||||
ncm::ContentStorage content_storage;
|
||||
public:
|
||||
ContentLocationResolverImpl(ncm::StorageId storage_id) : storage_id(storage_id) { /* ... */ }
|
||||
|
||||
~ContentLocationResolverImpl();
|
||||
private:
|
||||
/* Helper functions. */
|
||||
void GetContentStoragePath(Path *out, ncm::ContentId content_id);
|
||||
public:
|
||||
/* Actual commands. */
|
||||
virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) override;
|
||||
virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) override;
|
||||
virtual Result ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) override;
|
||||
virtual Result ResolveDataPath(sf::Out<Path> out, ncm::DataId id) override;
|
||||
virtual Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
|
||||
virtual Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
|
||||
virtual Result ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) override;
|
||||
virtual Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
|
||||
virtual Result Refresh() override;
|
||||
virtual Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
|
||||
virtual Result ClearApplicationRedirectionDeprecated() override;
|
||||
virtual Result ClearApplicationRedirection(const sf::InArray<ncm::ProgramId> &excluding_ids) override;
|
||||
virtual Result EraseProgramRedirection(ncm::ProgramId id) override;
|
||||
virtual Result EraseApplicationControlRedirection(ncm::ProgramId id) override;
|
||||
virtual Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) override;
|
||||
virtual Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id) override;
|
||||
virtual Result ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) override;
|
||||
virtual Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
|
||||
virtual Result EraseProgramRedirectionForDebug(ncm::ProgramId id) override;
|
||||
};
|
||||
|
||||
}
|
127
libraries/libstratosphere/source/lr/lr_location_redirector.cpp
Normal file
127
libraries/libstratosphere/source/lr/lr_location_redirector.cpp
Normal file
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "lr_location_redirector.hpp"
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
class LocationRedirector::Redirection : public util::IntrusiveListBaseNode<Redirection> {
|
||||
NON_COPYABLE(Redirection);
|
||||
NON_MOVEABLE(Redirection);
|
||||
private:
|
||||
ncm::ProgramId program_id;
|
||||
ncm::ProgramId owner_id;
|
||||
Path path;
|
||||
u32 flags;
|
||||
public:
|
||||
Redirection(ncm::ProgramId program_id, ncm::ProgramId owner_id, const Path& path, u32 flags) :
|
||||
program_id(program_id), owner_id(owner_id), path(path), flags(flags) { /* ... */ }
|
||||
|
||||
ncm::ProgramId GetProgramId() const {
|
||||
return this->program_id;
|
||||
}
|
||||
|
||||
ncm::ProgramId GetOwnerProgramId() const {
|
||||
return this->owner_id;
|
||||
}
|
||||
|
||||
void GetPath(Path *out) const {
|
||||
*out = this->path;
|
||||
}
|
||||
|
||||
u32 GetFlags() const {
|
||||
return this->flags;
|
||||
}
|
||||
|
||||
void SetFlags(u32 flags) {
|
||||
this->flags = flags;
|
||||
}
|
||||
};
|
||||
|
||||
bool LocationRedirector::FindRedirection(Path *out, ncm::ProgramId program_id) const {
|
||||
/* Obtain the path of a matching redirection. */
|
||||
for (const auto &redirection : this->redirection_list) {
|
||||
if (redirection.GetProgramId() == program_id) {
|
||||
redirection.GetPath(out);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void LocationRedirector::SetRedirection(ncm::ProgramId program_id, const Path &path, u32 flags) {
|
||||
this->SetRedirection(program_id, ncm::InvalidProgramId, path, flags);
|
||||
}
|
||||
|
||||
void LocationRedirector::SetRedirection(ncm::ProgramId program_id, ncm::ProgramId owner_id, const Path &path, u32 flags) {
|
||||
/* Remove any existing redirections for this program id. */
|
||||
this->EraseRedirection(program_id);
|
||||
|
||||
/* Insert a new redirection into the list. */
|
||||
this->redirection_list.push_back(*(new Redirection(program_id, owner_id, path, flags)));
|
||||
}
|
||||
|
||||
void LocationRedirector::SetRedirectionFlags(ncm::ProgramId program_id, u32 flags) {
|
||||
/* Set the flags of a redirection with a matching program id. */
|
||||
for (auto &redirection : this->redirection_list) {
|
||||
if (redirection.GetProgramId() == program_id) {
|
||||
redirection.SetFlags(flags);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocationRedirector::EraseRedirection(ncm::ProgramId program_id)
|
||||
{
|
||||
/* Remove any redirections with a matching program id. */
|
||||
for (auto &redirection : this->redirection_list) {
|
||||
if (redirection.GetProgramId() == program_id) {
|
||||
this->redirection_list.erase(this->redirection_list.iterator_to(redirection));
|
||||
delete &redirection;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocationRedirector::ClearRedirections(u32 flags) {
|
||||
/* Remove any redirections with matching flags. */
|
||||
for (auto it = this->redirection_list.begin(); it != this->redirection_list.end();) {
|
||||
if ((it->GetFlags() & flags) == flags) {
|
||||
auto old = it;
|
||||
it = this->redirection_list.erase(it);
|
||||
delete std::addressof(*old);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocationRedirector::ClearRedirectionsExcludingOwners(const ncm::ProgramId *excluding_ids, size_t num_ids) {
|
||||
for (auto it = this->redirection_list.begin(); it != this->redirection_list.end();) {
|
||||
/* Skip removal if the redirection has an excluded owner program id. */
|
||||
if (this->IsExcluded(it->GetOwnerProgramId(), excluding_ids, num_ids)) {
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Remove the redirection. */
|
||||
auto old = it;
|
||||
it = this->redirection_list.erase(it);
|
||||
delete std::addressof(*old);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
enum RedirectionFlags {
|
||||
RedirectionFlags_None = (0 << 0),
|
||||
RedirectionFlags_Application = (1 << 0),
|
||||
};
|
||||
|
||||
class LocationRedirector {
|
||||
NON_COPYABLE(LocationRedirector);
|
||||
NON_MOVEABLE(LocationRedirector);
|
||||
private:
|
||||
class Redirection;
|
||||
private:
|
||||
using RedirectionList = ams::util::IntrusiveListBaseTraits<Redirection>::ListType;
|
||||
private:
|
||||
RedirectionList redirection_list;
|
||||
public:
|
||||
LocationRedirector() { /* ... */ }
|
||||
~LocationRedirector() { this->ClearRedirections(); }
|
||||
|
||||
/* API. */
|
||||
bool FindRedirection(Path *out, ncm::ProgramId program_id) const;
|
||||
void SetRedirection(ncm::ProgramId program_id, const Path &path, u32 flags = RedirectionFlags_None);
|
||||
void SetRedirection(ncm::ProgramId program_id, ncm::ProgramId owner_id, const Path &path, u32 flags = RedirectionFlags_None);
|
||||
void SetRedirectionFlags(ncm::ProgramId program_id, u32 flags);
|
||||
void EraseRedirection(ncm::ProgramId program_id);
|
||||
void ClearRedirections(u32 flags = RedirectionFlags_None);
|
||||
void ClearRedirectionsExcludingOwners(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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
#include "lr_location_redirector.hpp"
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
class LocationResolverImplBase : public ILocationResolver {
|
||||
NON_COPYABLE(LocationResolverImplBase);
|
||||
NON_MOVEABLE(LocationResolverImplBase);
|
||||
protected:
|
||||
/* Location redirectors. */
|
||||
LocationRedirector program_redirector;
|
||||
LocationRedirector debug_program_redirector;
|
||||
LocationRedirector app_control_redirector;
|
||||
LocationRedirector html_docs_redirector;
|
||||
LocationRedirector legal_info_redirector;
|
||||
protected:
|
||||
LocationResolverImplBase() : program_redirector(), debug_program_redirector(), app_control_redirector(), html_docs_redirector(), legal_info_redirector() { /* ... */ }
|
||||
protected:
|
||||
/* Helper functions. */
|
||||
void ClearRedirections(u32 flags = RedirectionFlags_None) {
|
||||
this->program_redirector.ClearRedirections(flags);
|
||||
this->debug_program_redirector.ClearRedirections(flags);
|
||||
this->app_control_redirector.ClearRedirections(flags);
|
||||
this->html_docs_redirector.ClearRedirections(flags);
|
||||
this->legal_info_redirector.ClearRedirections(flags);
|
||||
}
|
||||
|
||||
void ClearRedirections(const ncm::ProgramId *excluding_ids, size_t num_ids) {
|
||||
this->program_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
|
||||
this->debug_program_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
|
||||
this->app_control_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
|
||||
this->html_docs_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
|
||||
this->legal_info_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include <stratosphere/lr/lr_location_resolver_manager_impl.hpp>
|
||||
#include "lr_content_location_resolver_impl.hpp"
|
||||
#include "lr_redirect_only_location_resolver_impl.hpp"
|
||||
#include "lr_add_on_content_location_resolver_impl.hpp"
|
||||
#include "lr_registered_location_resolver_impl.hpp"
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
Result LocationResolverManagerImpl::OpenLocationResolver(sf::Out<std::shared_ptr<ILocationResolver>> out, ncm::StorageId storage_id) {
|
||||
std::scoped_lock lk(this->mutex);
|
||||
/* Find an existing resolver. */
|
||||
auto resolver = this->location_resolvers.Find(storage_id);
|
||||
|
||||
/* No existing resolver is present, create one. */
|
||||
if (!resolver) {
|
||||
if (storage_id == ncm::StorageId::Host) {
|
||||
AMS_ABORT_UNLESS(this->location_resolvers.Insert(storage_id, std::make_shared<RedirectOnlyLocationResolverImpl>()));
|
||||
} else {
|
||||
auto content_resolver = std::make_shared<ContentLocationResolverImpl>(storage_id);
|
||||
R_TRY(content_resolver->Refresh());
|
||||
AMS_ABORT_UNLESS(this->location_resolvers.Insert(storage_id, std::move(content_resolver)));
|
||||
}
|
||||
|
||||
/* Acquire the newly-created resolver. */
|
||||
resolver = this->location_resolvers.Find(storage_id);
|
||||
}
|
||||
|
||||
/* Copy the output interface. */
|
||||
out.SetValue(std::shared_ptr<ILocationResolver>(*resolver));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result LocationResolverManagerImpl::OpenRegisteredLocationResolver(sf::Out<std::shared_ptr<IRegisteredLocationResolver>> out) {
|
||||
std::scoped_lock lk(this->mutex);
|
||||
|
||||
/* No existing resolver is present, create one. */
|
||||
if (!this->registered_location_resolver) {
|
||||
this->registered_location_resolver = std::make_shared<RegisteredLocationResolverImpl>();
|
||||
}
|
||||
|
||||
/* Copy the output interface. */
|
||||
out.SetValue(std::shared_ptr<IRegisteredLocationResolver>(this->registered_location_resolver));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result LocationResolverManagerImpl::RefreshLocationResolver(ncm::StorageId storage_id) {
|
||||
std::scoped_lock lk(this->mutex);
|
||||
|
||||
/* Attempt to find an existing resolver. */
|
||||
auto resolver = this->location_resolvers.Find(storage_id);
|
||||
R_UNLESS(resolver, lr::ResultUnknownStorageId());
|
||||
|
||||
/* Refresh the resolver. */
|
||||
if (storage_id != ncm::StorageId::Host) {
|
||||
(*resolver)->Refresh();
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result LocationResolverManagerImpl::OpenAddOnContentLocationResolver(sf::Out<std::shared_ptr<IAddOnContentLocationResolver>> out) {
|
||||
std::scoped_lock lk(this->mutex);
|
||||
|
||||
/* No existing resolver is present, create one. */
|
||||
if (!this->add_on_content_location_resolver) {
|
||||
this->add_on_content_location_resolver = std::make_shared<AddOnContentLocationResolverImpl>();
|
||||
}
|
||||
|
||||
/* Copy the output interface. */
|
||||
out.SetValue(std::shared_ptr<IAddOnContentLocationResolver>(this->add_on_content_location_resolver));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "lr_redirect_only_location_resolver_impl.hpp"
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
RedirectOnlyLocationResolverImpl::~RedirectOnlyLocationResolverImpl() {
|
||||
/* Ensure entries are deallocated */
|
||||
this->ClearRedirections();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
R_UNLESS(this->program_redirector.FindRedirection(out.GetPointer(), id), lr::ResultProgramNotFound());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::RedirectProgramPath(const Path &path, ncm::ProgramId id) {
|
||||
this->program_redirector.SetRedirection(id, path);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
R_UNLESS(this->app_control_redirector.FindRedirection(out.GetPointer(), id), lr::ResultControlNotFound());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
R_UNLESS(this->html_docs_redirector.FindRedirection(out.GetPointer(), id), lr::ResultHtmlDocumentNotFound());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::ResolveDataPath(sf::Out<Path> out, ncm::DataId id) {
|
||||
return ResultDataNotFound();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) {
|
||||
this->app_control_redirector.SetRedirection(id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
|
||||
this->app_control_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) {
|
||||
this->html_docs_redirector.SetRedirection(id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
|
||||
this->html_docs_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
R_UNLESS(this->legal_info_redirector.FindRedirection(out.GetPointer(), id), lr::ResultLegalInformationNotFound());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) {
|
||||
this->legal_info_redirector.SetRedirection(id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
|
||||
this->legal_info_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::Refresh() {
|
||||
this->ClearRedirections();
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) {
|
||||
this->program_redirector.SetRedirection(id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
|
||||
this->program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::ClearApplicationRedirectionDeprecated() {
|
||||
this->ClearRedirections(RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::ClearApplicationRedirection(const sf::InArray<ncm::ProgramId> &excluding_ids) {
|
||||
this->ClearRedirections(excluding_ids.GetPointer(), excluding_ids.GetSize());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::EraseProgramRedirection(ncm::ProgramId id) {
|
||||
this->program_redirector.EraseRedirection(id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::EraseApplicationControlRedirection(ncm::ProgramId id) {
|
||||
this->app_control_redirector.EraseRedirection(id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) {
|
||||
this->html_docs_redirector.EraseRedirection(id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::EraseApplicationLegalInformationRedirection(ncm::ProgramId id) {
|
||||
this->legal_info_redirector.EraseRedirection(id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
/* If a debug program redirection is present, use it. */
|
||||
R_SUCCEED_IF(this->debug_program_redirector.FindRedirection(out.GetPointer(), id));
|
||||
|
||||
/* Otherwise, try to find a normal program redirection. */
|
||||
R_UNLESS(this->program_redirector.FindRedirection(out.GetPointer(), id), lr::ResultDebugProgramNotFound());
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) {
|
||||
this->debug_program_redirector.SetRedirection(id, path);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) {
|
||||
this->debug_program_redirector.SetRedirection(id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
|
||||
this->debug_program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::EraseProgramRedirectionForDebug(ncm::ProgramId id) {
|
||||
this->debug_program_redirector.EraseRedirection(id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "lr_location_resolver_impl_base.hpp"
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
class RedirectOnlyLocationResolverImpl : public LocationResolverImplBase {
|
||||
public:
|
||||
~RedirectOnlyLocationResolverImpl();
|
||||
public:
|
||||
/* Actual commands. */
|
||||
virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) override;
|
||||
virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) override;
|
||||
virtual Result ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) override;
|
||||
virtual Result ResolveDataPath(sf::Out<Path> out, ncm::DataId id) override;
|
||||
virtual Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
|
||||
virtual Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
|
||||
virtual Result ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) override;
|
||||
virtual Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
|
||||
virtual Result Refresh() override;
|
||||
virtual Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
|
||||
virtual Result ClearApplicationRedirectionDeprecated() override;
|
||||
virtual Result ClearApplicationRedirection(const sf::InArray<ncm::ProgramId> &excluding_ids) override;
|
||||
virtual Result EraseProgramRedirection(ncm::ProgramId id) override;
|
||||
virtual Result EraseApplicationControlRedirection(ncm::ProgramId id) override;
|
||||
virtual Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) override;
|
||||
virtual Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id) override;
|
||||
virtual Result ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) override;
|
||||
virtual Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
|
||||
virtual Result EraseProgramRedirectionForDebug(ncm::ProgramId id) override;
|
||||
};
|
||||
|
||||
}
|
145
libraries/libstratosphere/source/lr/lr_registered_data.hpp
Normal file
145
libraries/libstratosphere/source/lr/lr_registered_data.hpp
Normal file
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/lr/lr_types.hpp>
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
template<typename Key, typename Value, size_t NumEntries>
|
||||
class RegisteredData {
|
||||
NON_COPYABLE(RegisteredData);
|
||||
NON_MOVEABLE(RegisteredData);
|
||||
private:
|
||||
struct Entry {
|
||||
Value value;
|
||||
ncm::ProgramId owner_id;
|
||||
Key key;
|
||||
bool is_valid;
|
||||
};
|
||||
private:
|
||||
Entry entries[NumEntries];
|
||||
size_t capacity;
|
||||
private:
|
||||
inline bool IsExcluded(const ncm::ProgramId id, const ncm::ProgramId *excluding_ids, size_t num_ids) const {
|
||||
/* Try to find program id in exclusions. */
|
||||
for (size_t i = 0; i < num_ids; i++) {
|
||||
if (id == excluding_ids[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void RegisterImpl(size_t i, const Key &key, const Value &value, const ncm::ProgramId owner_id) {
|
||||
/* Populate entry. */
|
||||
Entry& entry = this->entries[i];
|
||||
entry.key = key;
|
||||
entry.value = value;
|
||||
entry.owner_id = owner_id;
|
||||
entry.is_valid = true;
|
||||
}
|
||||
public:
|
||||
RegisteredData(size_t capacity = NumEntries) : capacity(capacity) {
|
||||
this->Clear();
|
||||
}
|
||||
|
||||
bool Register(const Key &key, const Value &value, const ncm::ProgramId owner_id) {
|
||||
/* Try to find an existing value. */
|
||||
for (size_t i = 0; i < this->GetCapacity(); i++) {
|
||||
Entry& entry = this->entries[i];
|
||||
if (entry.is_valid && entry.key == key) {
|
||||
this->RegisterImpl(i, key, value, owner_id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* We didn't find an existing entry, so try to create a new one. */
|
||||
for (size_t i = 0; i < this->GetCapacity(); i++) {
|
||||
Entry& entry = this->entries[i];
|
||||
if (!entry.is_valid) {
|
||||
this->RegisterImpl(i, key, value, owner_id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Unregister(const Key &key) {
|
||||
/* Invalidate entries with a matching key. */
|
||||
for (size_t i = 0; i < this->GetCapacity(); i++) {
|
||||
Entry& entry = this->entries[i];
|
||||
if (entry.is_valid && entry.key == key) {
|
||||
entry.is_valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UnregisterOwnerProgram(ncm::ProgramId owner_id) {
|
||||
/* Invalidate entries with a matching owner id. */
|
||||
for (size_t i = 0; i < this->GetCapacity(); i++) {
|
||||
Entry& entry = this->entries[i];
|
||||
if (entry.owner_id == owner_id) {
|
||||
entry.is_valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Find(Value *out, const Key &key) const {
|
||||
/* Locate a matching entry. */
|
||||
for (size_t i = 0; i < this->GetCapacity(); i++) {
|
||||
const Entry& entry = this->entries[i];
|
||||
if (entry.is_valid && entry.key == key) {
|
||||
*out = entry.value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
/* Invalidate all entries. */
|
||||
for (size_t i = 0; i < this->GetCapacity(); i++) {
|
||||
this->entries[i].is_valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ClearExcluding(const ncm::ProgramId *ids, size_t num_ids) {
|
||||
/* Invalidate all entries unless excluded. */
|
||||
for (size_t i = 0; i < this->GetCapacity(); i++) {
|
||||
Entry& entry = this->entries[i];
|
||||
|
||||
if (!this->IsExcluded(entry.owner_id, ids, num_ids)) {
|
||||
entry.is_valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t GetCapacity() const {
|
||||
return this->capacity;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Key, size_t NumEntries>
|
||||
using RegisteredLocations = RegisteredData<Key, lr::Path, NumEntries>;
|
||||
|
||||
template<typename Key, size_t NumEntries>
|
||||
using RegisteredStorages = RegisteredData<Key, ncm::StorageId, NumEntries>;
|
||||
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "lr_registered_location_resolver_impl.hpp"
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
namespace {
|
||||
|
||||
template<size_t N>
|
||||
bool ResolvePath(Path *out, const LocationRedirector &redirector, const RegisteredLocations<ncm::ProgramId, N> &locations, ncm::ProgramId id) {
|
||||
/* Attempt to use a redirection if present. */
|
||||
if (!redirector.FindRedirection(out, id)) {
|
||||
/* Otherwise try and use a registered location. */
|
||||
if (!locations.Find(out, id)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
void RegisterPath(RegisteredLocations<ncm::ProgramId, N> &locations, ncm::ProgramId id, const Path& path, ncm::ProgramId owner_id) {
|
||||
/* If we register successfully, we're good. */
|
||||
if (locations.Register(id, path, owner_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Otherwise, clear and register (this should always succeed). */
|
||||
locations.Clear();
|
||||
locations.Register(id, path, owner_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RegisteredLocationResolverImpl::~RegisteredLocationResolverImpl() {
|
||||
/* Ensure entries are deallocated */
|
||||
this->ClearRedirections();
|
||||
}
|
||||
|
||||
/* Helper function. */
|
||||
void RegisteredLocationResolverImpl::ClearRedirections(u32 flags) {
|
||||
this->html_docs_redirector.ClearRedirections(flags);
|
||||
this->program_redirector.ClearRedirections(flags);
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::RefreshImpl(const ncm::ProgramId *excluding_ids, size_t num_ids) {
|
||||
/* On < 9.0.0, exclusion lists were not supported yet, so simply clear and return. */
|
||||
if (hos::GetVersion() < hos::Version_900) {
|
||||
this->ClearRedirections();
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
if (num_ids) {
|
||||
/* If we have exclusion lists, explicitly clear our locations. */
|
||||
this->registered_program_locations.ClearExcluding(excluding_ids, num_ids);
|
||||
this->registered_html_docs_locations.ClearExcluding(excluding_ids, num_ids);
|
||||
} else {
|
||||
/* If we don't, just perform a general clear (as pre 9.0.0 did). */
|
||||
this->ClearRedirections();
|
||||
}
|
||||
|
||||
/* Clear redirectors using exclusion lists. */
|
||||
this->program_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
|
||||
this->html_docs_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
R_UNLESS(ResolvePath(out.GetPointer(), this->program_redirector, this->registered_program_locations, id), lr::ResultProgramNotFound());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id) {
|
||||
RegisterPath(this->registered_program_locations, id, path, ncm::InvalidProgramId);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
|
||||
RegisterPath(this->registered_program_locations, id, path, owner_id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::UnregisterProgramPath(ncm::ProgramId id) {
|
||||
this->registered_program_locations.Unregister(id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id) {
|
||||
this->program_redirector.SetRedirection(id, path);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
|
||||
this->program_redirector.SetRedirection(id, owner_id, path);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::ResolveHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
R_UNLESS(ResolvePath(out.GetPointer(), this->html_docs_redirector, this->registered_html_docs_locations, id), lr::ResultHtmlDocumentNotFound());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) {
|
||||
RegisterPath(this->registered_html_docs_locations, id, path, ncm::InvalidProgramId);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
|
||||
RegisterPath(this->registered_html_docs_locations, id, path, owner_id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::UnregisterHtmlDocumentPath(ncm::ProgramId id) {
|
||||
this->registered_html_docs_locations.Unregister(id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) {
|
||||
this->html_docs_redirector.SetRedirection(id, path);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
|
||||
this->html_docs_redirector.SetRedirection(id, owner_id, path);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::Refresh() {
|
||||
return this->RefreshImpl(nullptr, 0);
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverImpl::RefreshExcluding(const sf::InArray<ncm::ProgramId> &ids) {
|
||||
return this->RefreshImpl(ids.GetPointer(), ids.GetSize());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
#include "lr_location_redirector.hpp"
|
||||
#include "lr_registered_data.hpp"
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
class RegisteredLocationResolverImpl : public IRegisteredLocationResolver {
|
||||
private:
|
||||
static constexpr size_t MaxRegisteredLocationsDeprecated = 0x10;
|
||||
static constexpr size_t MaxRegisteredLocations = 0x20;
|
||||
static_assert(MaxRegisteredLocations >= MaxRegisteredLocationsDeprecated);
|
||||
private:
|
||||
static ALWAYS_INLINE size_t GetMaxRegisteredLocations() {
|
||||
if (hos::GetVersion() >= hos::Version_900) {
|
||||
return MaxRegisteredLocations;
|
||||
} else {
|
||||
return MaxRegisteredLocationsDeprecated;
|
||||
}
|
||||
}
|
||||
private:
|
||||
/* Redirection and registered location storage. */
|
||||
LocationRedirector program_redirector;
|
||||
RegisteredLocations<ncm::ProgramId, MaxRegisteredLocations> registered_program_locations;
|
||||
LocationRedirector html_docs_redirector;
|
||||
RegisteredLocations<ncm::ProgramId, MaxRegisteredLocations> registered_html_docs_locations;
|
||||
private:
|
||||
/* Helper functions. */
|
||||
void ClearRedirections(u32 flags = RedirectionFlags_None);
|
||||
Result RefreshImpl(const ncm::ProgramId *excluding_ids, size_t num_ids);
|
||||
public:
|
||||
RegisteredLocationResolverImpl() : registered_program_locations(GetMaxRegisteredLocations()), registered_html_docs_locations(GetMaxRegisteredLocations()) { /* ... */ }
|
||||
~RegisteredLocationResolverImpl();
|
||||
public:
|
||||
/* Actual commands. */
|
||||
virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) override;
|
||||
virtual Result RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
|
||||
virtual Result UnregisterProgramPath(ncm::ProgramId id) override;
|
||||
virtual Result RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
|
||||
virtual Result ResolveHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) override;
|
||||
virtual Result RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
|
||||
virtual Result UnregisterHtmlDocumentPath(ncm::ProgramId id) override;
|
||||
virtual Result RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override;
|
||||
virtual Result RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
|
||||
virtual Result Refresh() override;
|
||||
virtual Result RefreshExcluding(const sf::InArray<ncm::ProgramId> &ids) override;
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
class RemoteLocationResolverImpl : public ILocationResolver {
|
||||
private:
|
||||
::LrLocationResolver srv;
|
||||
public:
|
||||
RemoteLocationResolverImpl(::LrLocationResolver &l) : srv(l) { /* ... */ }
|
||||
|
||||
~RemoteLocationResolverImpl() { ::serviceClose(&srv.s); }
|
||||
public:
|
||||
/* Actual commands. */
|
||||
virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) override {
|
||||
return lrLrResolveProgramPath(std::addressof(this->srv), static_cast<u64>(id), out->str);
|
||||
}
|
||||
|
||||
virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id) override {
|
||||
return lrLrRedirectProgramPath(std::addressof(this->srv), static_cast<u64>(id), path.str);
|
||||
}
|
||||
|
||||
virtual Result ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) override {
|
||||
return lrLrResolveApplicationControlPath(std::addressof(this->srv), static_cast<u64>(id), out->str);
|
||||
}
|
||||
|
||||
virtual Result ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) override {
|
||||
return lrLrResolveApplicationHtmlDocumentPath(std::addressof(this->srv), static_cast<u64>(id), out->str);
|
||||
}
|
||||
|
||||
virtual Result ResolveDataPath(sf::Out<Path> out, ncm::DataId id) override {
|
||||
return lrLrResolveDataPath(std::addressof(this->srv), id.value, out->str);
|
||||
}
|
||||
|
||||
virtual Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) override {
|
||||
return lrLrRedirectApplicationControlPath(std::addressof(this->srv), static_cast<u64>(id), 0, path.str);
|
||||
}
|
||||
|
||||
virtual Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
|
||||
return lrLrRedirectApplicationControlPath(std::addressof(this->srv), static_cast<u64>(id), static_cast<u64>(owner_id), path.str);
|
||||
}
|
||||
|
||||
virtual Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override {
|
||||
return lrLrRedirectApplicationHtmlDocumentPath(std::addressof(this->srv), static_cast<u64>(id), 0, path.str);
|
||||
}
|
||||
|
||||
virtual Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
|
||||
return lrLrRedirectApplicationHtmlDocumentPath(std::addressof(this->srv), static_cast<u64>(id), static_cast<u64>(owner_id), path.str);
|
||||
}
|
||||
|
||||
virtual Result ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) override {
|
||||
return lrLrResolveApplicationLegalInformationPath(std::addressof(this->srv), static_cast<u64>(id), out->str);
|
||||
}
|
||||
|
||||
virtual Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) override {
|
||||
return lrLrRedirectApplicationLegalInformationPath(std::addressof(this->srv), static_cast<u64>(id), 0, path.str);
|
||||
}
|
||||
|
||||
virtual Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
|
||||
return lrLrRedirectApplicationLegalInformationPath(std::addressof(this->srv), static_cast<u64>(id), static_cast<u64>(owner_id), path.str);
|
||||
}
|
||||
|
||||
virtual Result Refresh() override {
|
||||
return lrLrRefresh(std::addressof(this->srv));
|
||||
}
|
||||
|
||||
virtual Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result ClearApplicationRedirectionDeprecated() override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result ClearApplicationRedirection(const sf::InArray<ncm::ProgramId> &excluding_ids) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result EraseProgramRedirection(ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result EraseApplicationControlRedirection(ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result EraseProgramRedirectionForDebug(ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
class RemoteRegisteredLocationResolverImpl : public IRegisteredLocationResolver {
|
||||
private:
|
||||
::LrRegisteredLocationResolver srv;
|
||||
public:
|
||||
RemoteRegisteredLocationResolverImpl(::LrRegisteredLocationResolver &l) : srv(l) { /* ... */ }
|
||||
|
||||
~RemoteRegisteredLocationResolverImpl() { ::serviceClose(&srv.s); }
|
||||
public:
|
||||
/* Actual commands. */
|
||||
virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) override {
|
||||
return lrRegLrResolveProgramPath(std::addressof(this->srv), static_cast<u64>(id), out->str);
|
||||
}
|
||||
|
||||
virtual Result RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result UnregisterProgramPath(ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result ResolveHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result UnregisterHtmlDocumentPath(ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result Refresh() override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
virtual Result RefreshExcluding(const sf::InArray<ncm::ProgramId> &ids) override {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue