From 4950dd56383d15029ac9e6046e4c5719102f4806 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Fri, 19 Jun 2020 21:13:29 +0100 Subject: [PATCH] Introduce NACP class for reading control data This contains info such as the application name and publisher. --- app/CMakeLists.txt | 1 + app/src/main/cpp/skyline/vfs/nacp.cpp | 15 ++++++++++ app/src/main/cpp/skyline/vfs/nacp.h | 40 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 app/src/main/cpp/skyline/vfs/nacp.cpp create mode 100644 app/src/main/cpp/skyline/vfs/nacp.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 5f23c7bc..0e0993ac 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -95,6 +95,7 @@ add_library(skyline SHARED ${source_DIR}/skyline/services/visrv/IManagerRootService.cpp ${source_DIR}/skyline/services/visrv/ISystemDisplayService.cpp ${source_DIR}/skyline/vfs/os_backing.cpp + ${source_DIR}/skyline/vfs/nacp.cpp ) target_link_libraries(skyline vulkan android fmt tinyxml2 oboe) diff --git a/app/src/main/cpp/skyline/vfs/nacp.cpp b/app/src/main/cpp/skyline/vfs/nacp.cpp new file mode 100644 index 00000000..522dea56 --- /dev/null +++ b/app/src/main/cpp/skyline/vfs/nacp.cpp @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#include "nacp.h" + +namespace skyline::vfs { + NACP::NACP(const std::shared_ptr &backing) { + backing->Read(&nacpContents); + + // TODO: Select based on language settings, complete struct, yada yada + ApplicationTitle &languageEntry = nacpContents.titleEntries[0]; + applicationName = std::string(languageEntry.applicationName.data(), languageEntry.applicationName.size()); + applicationPublisher = std::string(languageEntry.applicationPublisher.data(), languageEntry.applicationPublisher.size()); + } +} \ No newline at end of file diff --git a/app/src/main/cpp/skyline/vfs/nacp.h b/app/src/main/cpp/skyline/vfs/nacp.h new file mode 100644 index 00000000..e6297e1f --- /dev/null +++ b/app/src/main/cpp/skyline/vfs/nacp.h @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#pragma once + +#include +#include +#include "backing.h" + +namespace skyline::vfs { + /** + * @brief The NACP class provides easy access to the data found in an NACP file (https://switchbrew.org/wiki/NACP_Format) + */ + class NACP { + private: + /** + * @brief This contains the name and publisher of an application for one language + */ + struct ApplicationTitle { + std::array applicationName; //!< The name of the application + std::array applicationPublisher; //!< The publisher of the application + }; + static_assert(sizeof(ApplicationTitle) == 0x300); + + /** + * @brief This struct encapsulates all the data within an NACP file + */ + struct NacpData { + ApplicationTitle titleEntries[0x10]; //!< Title entries for each language + u8 _pad_[0x4000 - (0x10 * 0x300)]; + } nacpContents{}; + static_assert(sizeof(NacpData) == 0x4000); + + public: + NACP(const std::shared_ptr &backing); + + std::string applicationName; //!< The name of the application in the currently selected language + std::string applicationPublisher; //!< The publisher of the application in the currently selected language + }; +} \ No newline at end of file