Introduce NACP class for reading control data

This contains info such as the application name and publisher.
This commit is contained in:
Billy Laws 2020-06-19 21:13:29 +01:00 committed by ◱ PixelyIon
parent 5c103ce9a6
commit 4950dd5638
3 changed files with 56 additions and 0 deletions

View File

@ -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)

View File

@ -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<vfs::Backing> &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());
}
}

View File

@ -0,0 +1,40 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
#pragma once
#include <array>
#include <common.h>
#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<char, 0x200> applicationName; //!< The name of the application
std::array<char, 0x100> 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<vfs::Backing> &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
};
}