diff --git a/stratosphere/libstratosphere/include/stratosphere.hpp b/stratosphere/libstratosphere/include/stratosphere.hpp index 78832a5de..f40b22ba2 100644 --- a/stratosphere/libstratosphere/include/stratosphere.hpp +++ b/stratosphere/libstratosphere/include/stratosphere.hpp @@ -47,6 +47,7 @@ #include "stratosphere/cfg.hpp" #include "stratosphere/fatal.hpp" #include "stratosphere/hid.hpp" +#include "stratosphere/lr.hpp" #include "stratosphere/ncm.hpp" #include "stratosphere/pm.hpp" #include "stratosphere/rnd.hpp" diff --git a/stratosphere/libstratosphere/include/stratosphere/lr.hpp b/stratosphere/libstratosphere/include/stratosphere/lr.hpp new file mode 100644 index 000000000..51ea02934 --- /dev/null +++ b/stratosphere/libstratosphere/include/stratosphere/lr.hpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2018-2019 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 . + */ + +#pragma once +#include + +#include "lr/lr_types.hpp" diff --git a/stratosphere/libstratosphere/include/stratosphere/lr/lr_types.hpp b/stratosphere/libstratosphere/include/stratosphere/lr/lr_types.hpp new file mode 100644 index 000000000..e845201d9 --- /dev/null +++ b/stratosphere/libstratosphere/include/stratosphere/lr/lr_types.hpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2019 Adubbz + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include + +namespace sts::lr { + + constexpr size_t MaxPathLen = 0x300; + + struct Path { + char path[MaxPathLen]; + + Path() { + path[0] = '\0'; + } + + Path(const char* path) { + strncpy(this->path, path, MaxPathLen-1); + this->EnsureNullTerminated(); + } + + Path& operator=(const Path& other) { + /* N appears to always memcpy paths, so we will too. */ + std::memcpy(this->path, other.path, MaxPathLen); + this->EnsureNullTerminated(); + return *this; + } + + void EnsureNullTerminated() { + path[MaxPathLen-1] = '\0'; + } + }; + +} diff --git a/stratosphere/ncm/source/impl/lr_manager.cpp b/stratosphere/ncm/source/impl/lr_manager.cpp index 38144661d..356808c8f 100644 --- a/stratosphere/ncm/source/impl/lr_manager.cpp +++ b/stratosphere/ncm/source/impl/lr_manager.cpp @@ -17,12 +17,13 @@ #include "../lr_contentlocationresolver.hpp" #include "../lr_redirectonlylocationresolver.hpp" #include "lr_manager.hpp" +#include "ncm_bounded_map.hpp" namespace sts::lr::impl { namespace { - BoundedMap, 5> g_location_resolvers; + ncm::impl::BoundedMap, 5> g_location_resolvers; std::shared_ptr g_registered_location_resolver = nullptr; std::shared_ptr g_add_on_content_location_resolver = nullptr; HosMutex g_mutex; diff --git a/stratosphere/ncm/source/impl/lr_redirection.hpp b/stratosphere/ncm/source/impl/lr_redirection.hpp index 2d182137d..3aa97ee09 100644 --- a/stratosphere/ncm/source/impl/lr_redirection.hpp +++ b/stratosphere/ncm/source/impl/lr_redirection.hpp @@ -18,8 +18,6 @@ #include #include -#include "../lr_types.hpp" - namespace sts::lr::impl { enum RedirectionFlags { diff --git a/stratosphere/ncm/source/impl/lr_registered_data.hpp b/stratosphere/ncm/source/impl/lr_registered_data.hpp index 5d54b8e16..7217a946d 100644 --- a/stratosphere/ncm/source/impl/lr_registered_data.hpp +++ b/stratosphere/ncm/source/impl/lr_registered_data.hpp @@ -18,8 +18,6 @@ #include #include -#include "../lr_types.hpp" - namespace sts::lr::impl { template diff --git a/stratosphere/ncm/source/lr_types.hpp b/stratosphere/ncm/source/impl/ncm_bounded_map.hpp similarity index 79% rename from stratosphere/ncm/source/lr_types.hpp rename to stratosphere/ncm/source/impl/ncm_bounded_map.hpp index 1c523acd8..e2b5d6d6a 100644 --- a/stratosphere/ncm/source/lr_types.hpp +++ b/stratosphere/ncm/source/impl/ncm_bounded_map.hpp @@ -18,34 +18,8 @@ #include #include -namespace sts::lr { - - constexpr size_t MaxPathLen = 0x300; - - struct Path { - char path[MaxPathLen]; - - Path() { - path[0] = '\0'; - } - - Path(const char* path) { - strncpy(this->path, path, MaxPathLen-1); - this->EnsureNullTerminated(); - } - - Path& operator=(const Path& other) { - /* N appears to always memcpy paths, so we will too. */ - std::memcpy(this->path, other.path, MaxPathLen); - this->EnsureNullTerminated(); - return *this; - } - - void EnsureNullTerminated() { - path[MaxPathLen-1] = '\0'; - } - }; - +namespace sts::ncm::impl { + template class BoundedMap { private: @@ -107,4 +81,4 @@ namespace sts::lr { } }; -} \ No newline at end of file +} diff --git a/stratosphere/ncm/source/lr_addoncontentlocationresolver.hpp b/stratosphere/ncm/source/lr_addoncontentlocationresolver.hpp index cb9056b6d..320f651c0 100644 --- a/stratosphere/ncm/source/lr_addoncontentlocationresolver.hpp +++ b/stratosphere/ncm/source/lr_addoncontentlocationresolver.hpp @@ -19,7 +19,6 @@ #include #include "impl/lr_registered_data.hpp" -#include "lr_types.hpp" namespace sts::lr { diff --git a/stratosphere/ncm/source/lr_registeredlocationresolver.hpp b/stratosphere/ncm/source/lr_registeredlocationresolver.hpp index cc0516272..97a5bc49a 100644 --- a/stratosphere/ncm/source/lr_registeredlocationresolver.hpp +++ b/stratosphere/ncm/source/lr_registeredlocationresolver.hpp @@ -20,7 +20,6 @@ #include "impl/lr_redirection.hpp" #include "impl/lr_registered_data.hpp" -#include "lr_types.hpp" namespace sts::lr { diff --git a/stratosphere/ncm/source/ncm_icontentstorage.hpp b/stratosphere/ncm/source/ncm_icontentstorage.hpp index 3e1d1d1f6..626787797 100644 --- a/stratosphere/ncm/source/ncm_icontentstorage.hpp +++ b/stratosphere/ncm/source/ncm_icontentstorage.hpp @@ -18,7 +18,6 @@ #include #include -#include "lr_types.hpp" #include "ncm_types.hpp" namespace sts::ncm {