mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-04-22 12:34:47 +00:00
Address more review comments
This commit is contained in:
parent
3b731c9bf2
commit
a02f881ad4
13 changed files with 77 additions and 117 deletions
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<ncm::StorageId, std::shared_ptr<ILocationResolver>, 5> g_location_resolvers;
|
||||
std::shared_ptr<RegisteredLocationResolverInterface> g_registered_location_resolver = nullptr;
|
||||
std::shared_ptr<AddOnContentLocationResolverInterface> g_add_on_content_location_resolver = nullptr;
|
||||
os::Mutex g_mutex;
|
||||
|
||||
}
|
||||
|
||||
Result OpenLocationResolver(sf::Out<std::shared_ptr<ILocationResolver>> out, ncm::StorageId storage_id) {
|
||||
Result LocationResolverManagerImpl::OpenLocationResolver(sf::Out<std::shared_ptr<ILocationResolver>> 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<std::shared_ptr<RegisteredLocationResolverInterface>> out) {
|
||||
Result LocationResolverManagerImpl::OpenRegisteredLocationResolver(sf::Out<std::shared_ptr<RegisteredLocationResolverInterface>> 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<std::shared_ptr<AddOnContentLocationResolverInterface>> out) {
|
||||
Result LocationResolverManagerImpl::OpenAddOnContentLocationResolver(sf::Out<std::shared_ptr<AddOnContentLocationResolverInterface>> out) {
|
||||
std::scoped_lock lk(g_mutex);
|
||||
|
||||
if (!g_add_on_content_location_resolver) {
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#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<ncm::StorageId, std::shared_ptr<ILocationResolver>, 5> g_location_resolvers;
|
||||
std::shared_ptr<RegisteredLocationResolverInterface> g_registered_location_resolver = nullptr;
|
||||
std::shared_ptr<AddOnContentLocationResolverInterface> g_add_on_content_location_resolver = nullptr;
|
||||
os::Mutex g_mutex;
|
||||
public:
|
||||
/* Actual commands. */
|
||||
virtual Result OpenLocationResolver(sf::Out<std::shared_ptr<ILocationResolver>> out, ncm::StorageId storage_id) override;
|
||||
virtual Result OpenRegisteredLocationResolver(sf::Out<std::shared_ptr<RegisteredLocationResolverInterface>> out) override;
|
||||
virtual Result RefreshLocationResolver(ncm::StorageId storage_id) override;
|
||||
virtual Result OpenAddOnContentLocationResolver(sf::Out<std::shared_ptr<AddOnContentLocationResolverInterface>> out) override;
|
||||
};
|
||||
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "../lr_addoncontentlocationresolver.hpp"
|
||||
#include "../lr_ilocationresolver.hpp"
|
||||
#include "../lr_registeredlocationresolver.hpp"
|
||||
|
||||
namespace ams::lr::impl {
|
||||
|
||||
/* Location Resolver API. */
|
||||
Result OpenLocationResolver(sf::Out<std::shared_ptr<ILocationResolver>> out, ncm::StorageId storage_id);
|
||||
Result OpenRegisteredLocationResolver(sf::Out<std::shared_ptr<RegisteredLocationResolverInterface>> out);
|
||||
Result RefreshLocationResolver(ncm::StorageId storage_id);
|
||||
Result OpenAddOnContentLocationResolver(sf::Out<std::shared_ptr<AddOnContentLocationResolverInterface>> out);
|
||||
|
||||
}
|
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "impl/lr_manager.hpp"
|
||||
#include "lr_ilocationresolver.hpp"
|
||||
#include "ncm_icontentmetadatabase.hpp"
|
||||
#include "ncm_icontentstorage.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<std::shared_ptr<ILocationResolver>> out, ncm::StorageId storage_id);
|
||||
virtual Result OpenRegisteredLocationResolver(sf::Out<std::shared_ptr<RegisteredLocationResolverInterface>> out);
|
||||
virtual Result RefreshLocationResolver(ncm::StorageId storage_id);
|
||||
virtual Result OpenAddOnContentLocationResolver(sf::Out<std::shared_ptr<AddOnContentLocationResolverInterface>> out);
|
||||
virtual Result OpenLocationResolver(sf::Out<std::shared_ptr<ILocationResolver>> out, ncm::StorageId storage_id) = 0;
|
||||
virtual Result OpenRegisteredLocationResolver(sf::Out<std::shared_ptr<RegisteredLocationResolverInterface>> out) = 0;
|
||||
virtual Result RefreshLocationResolver(ncm::StorageId storage_id) = 0;
|
||||
virtual Result OpenAddOnContentLocationResolver(sf::Out<std::shared_ptr<AddOnContentLocationResolverInterface>> out) = 0;
|
||||
public:
|
||||
DEFINE_SERVICE_DISPATCH_TABLE {
|
||||
MAKE_SERVICE_COMMAND_META(OpenLocationResolver),
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "impl/lr_manager.hpp"
|
||||
#include "lr_manager_service.hpp"
|
||||
|
||||
namespace ams::lr {
|
||||
|
||||
Result LocationResolverManagerService::OpenLocationResolver(sf::Out<std::shared_ptr<ILocationResolver>> out, ncm::StorageId storage_id) {
|
||||
return impl::OpenLocationResolver(out, storage_id);
|
||||
}
|
||||
|
||||
Result LocationResolverManagerService::OpenRegisteredLocationResolver(sf::Out<std::shared_ptr<RegisteredLocationResolverInterface>> out) {
|
||||
return impl::OpenRegisteredLocationResolver(out);
|
||||
}
|
||||
|
||||
Result LocationResolverManagerService::RefreshLocationResolver(ncm::StorageId storage_id) {
|
||||
return impl::RefreshLocationResolver(storage_id);
|
||||
}
|
||||
|
||||
Result LocationResolverManagerService::OpenAddOnContentLocationResolver(sf::Out<std::shared_ptr<AddOnContentLocationResolverInterface>> out) {
|
||||
return impl::OpenAddOnContentLocationResolver(out);
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <stratosphere.hpp>
|
||||
|
||||
#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<lr::LocationResolverManagerService>(LrServiceName, LrMaxSessions));
|
||||
R_ABORT_UNLESS(g_lr_server_manager.RegisterServer<lr::impl::LocationResolverManagerImpl>(LrServiceName, LrMaxSessions));
|
||||
|
||||
/* Loop forever, servicing our services. */
|
||||
g_lr_server_manager.LoopProcess();
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Add table
Reference in a new issue