From 4bc54a88d7a8fd0c2e38ba25492b3ed06a7aed7a Mon Sep 17 00:00:00 2001 From: Adubbz Date: Fri, 16 Aug 2019 16:40:08 +1000 Subject: [PATCH] lr: RegisteredLocationResolver helpers --- .../source/lr_registeredlocationresolver.cpp | 55 ++++++++++--------- .../source/lr_registeredlocationresolver.hpp | 4 ++ 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/stratosphere/ncm/source/lr_registeredlocationresolver.cpp b/stratosphere/ncm/source/lr_registeredlocationresolver.cpp index 8e9f53efa..939cf3de6 100644 --- a/stratosphere/ncm/source/lr_registeredlocationresolver.cpp +++ b/stratosphere/ncm/source/lr_registeredlocationresolver.cpp @@ -20,28 +20,40 @@ namespace sts::lr { RegisteredLocationResolverInterface::~RegisteredLocationResolverInterface() { /* Ensure entries are deallocated */ + this->ClearRedirections(); + } + + void RegisteredLocationResolverInterface::ClearRedirections(u32 flags) { this->html_docs_redirector.ClearRedirections(); this->program_redirector.ClearRedirections(); } - Result RegisteredLocationResolverInterface::ResolveProgramPath(OutPointerWithServerSize out, ncm::TitleId tid) { - if (!this->program_redirector.FindRedirection(out.pointer, tid)) { - if (!this->registered_program_locations.Find(out.pointer, tid)) { - return ResultLrProgramNotFound; + void RegisteredLocationResolverInterface::RegisterPath(const Path& path, impl::RegisteredLocations* locations, ncm::TitleId tid) { + if (!locations->Register(tid, path)) { + locations->Clear(); + locations->Register(tid, path); + } + } + + bool RegisteredLocationResolverInterface::ResolvePath(Path* out, impl::LocationRedirector* redirector, impl::RegisteredLocations* locations, ncm::TitleId tid) { + if (!redirector->FindRedirection(out, tid)) { + if (!locations->Find(out, tid)) { + return false; } } - + return true; + } + + Result RegisteredLocationResolverInterface::ResolveProgramPath(OutPointerWithServerSize out, ncm::TitleId tid) { + if (!this->ResolvePath(out.pointer, &this->program_redirector, &this->registered_program_locations, tid)) { + return ResultLrProgramNotFound; + } + return ResultSuccess; } Result RegisteredLocationResolverInterface::RegisterProgramPath(InPointer path, ncm::TitleId tid) { - const Path& tmp_path = *path.pointer; - - if (!this->registered_program_locations.Register(tid, tmp_path)) { - this->registered_program_locations.Clear(); - this->registered_program_locations.Register(tid, tmp_path); - } - + this->RegisterPath(*path.pointer, &this->registered_program_locations, tid); return ResultSuccess; } @@ -56,23 +68,15 @@ namespace sts::lr { } Result RegisteredLocationResolverInterface::ResolveHtmlDocumentPath(OutPointerWithServerSize out, ncm::TitleId tid) { - if (!this->html_docs_redirector.FindRedirection(out.pointer, tid)) { - if (!this->registered_html_docs_locations.Find(out.pointer, tid)) { - return ResultLrProgramNotFound; - } + if (!this->ResolvePath(out.pointer, &this->html_docs_redirector, &this->registered_html_docs_locations, tid)) { + return ResultLrHtmlDocumentNotFound; } - return ResultLrHtmlDocumentNotFound; + return ResultSuccess; } Result RegisteredLocationResolverInterface::RegisterHtmlDocumentPath(InPointer path, ncm::TitleId tid) { - const Path& tmp_path = *path.pointer; - - if (!this->registered_html_docs_locations.Register(tid, tmp_path)) { - this->registered_html_docs_locations.Clear(); - this->registered_html_docs_locations.Register(tid, tmp_path); - } - + this->RegisterPath(*path.pointer, &this->registered_html_docs_locations, tid); return ResultSuccess; } @@ -87,8 +91,7 @@ namespace sts::lr { } Result RegisteredLocationResolverInterface::Refresh() { - this->registered_program_locations.Clear(); - this->registered_html_docs_locations.Clear(); + this->ClearRedirections(); return ResultSuccess; } diff --git a/stratosphere/ncm/source/lr_registeredlocationresolver.hpp b/stratosphere/ncm/source/lr_registeredlocationresolver.hpp index 0d6f0f4d7..f2e774c31 100644 --- a/stratosphere/ncm/source/lr_registeredlocationresolver.hpp +++ b/stratosphere/ncm/source/lr_registeredlocationresolver.hpp @@ -41,6 +41,10 @@ namespace sts::lr { impl::RegisteredLocations registered_program_locations; impl::LocationRedirector html_docs_redirector; impl::RegisteredLocations registered_html_docs_locations; + private: + void ClearRedirections(u32 flags = impl::RedirectionFlags_None); + void RegisterPath(const Path& path, impl::RegisteredLocations* locations, ncm::TitleId tid); + bool ResolvePath(Path* out, impl::LocationRedirector* redirector, impl::RegisteredLocations* locations, ncm::TitleId tid); public: ~RegisteredLocationResolverInterface();