yuzu/src/core/file_sys/content_archive.h

108 lines
2.7 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <array>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "common/common_funcs.h"
#include "common/common_types.h"
#include "common/swap.h"
2018-07-28 03:55:23 +00:00
#include "core/crypto/key_manager.h"
#include "core/file_sys/vfs.h"
namespace Loader {
enum class ResultStatus : u16;
}
namespace FileSys {
2023-08-11 01:34:43 +00:00
class NcaReader;
/// Describes the type of content within an NCA archive.
enum class NCAContentType : u8 {
/// Executable-related data
Program = 0,
/// Metadata.
Meta = 1,
/// Access control data.
Control = 2,
/// Information related to the game manual
/// e.g. Legal information, etc.
Manual = 3,
/// System data.
Data = 4,
/// Data that can be accessed by applications.
PublicData = 5,
};
2023-08-11 01:34:43 +00:00
using RightsId = std::array<u8, 0x10>;
inline bool IsDirectoryExeFS(const VirtualDir& pfs) {
// According to switchbrew, an exefs must only contain these two files:
return pfs->GetFile("main") != nullptr && pfs->GetFile("main.npdm") != nullptr;
}
inline bool IsDirectoryLogoPartition(const VirtualDir& pfs) {
// NintendoLogo is the static image in the top left corner while StartupMovie is the animation
// in the bottom right corner.
return pfs->GetFile("NintendoLogo.png") != nullptr &&
pfs->GetFile("StartupMovie.gif") != nullptr;
}
2023-03-12 03:10:38 +00:00
// An implementation of VfsDirectory that represents a Nintendo Content Archive (NCA) container.
// After construction, use GetStatus to determine if the file is valid and ready to be used.
class NCA : public ReadOnlyVfsDirectory {
public:
2023-08-11 01:34:43 +00:00
explicit NCA(VirtualFile file, const NCA* base_nca = nullptr);
~NCA() override;
Loader::ResultStatus GetStatus() const;
std::vector<VirtualFile> GetFiles() const override;
std::vector<VirtualDir> GetSubdirectories() const override;
std::string GetName() const override;
VirtualDir GetParentDirectory() const override;
NCAContentType GetType() const;
u64 GetTitleId() const;
2023-08-11 01:34:43 +00:00
RightsId GetRightsId() const;
u32 GetSDKVersion() const;
bool IsUpdate() const;
VirtualFile GetRomFS() const;
VirtualDir GetExeFS() const;
2018-07-28 03:55:23 +00:00
VirtualFile GetBaseFile() const;
VirtualDir GetLogoPartition() const;
private:
std::vector<VirtualDir> dirs;
std::vector<VirtualFile> files;
VirtualFile romfs = nullptr;
VirtualDir exefs = nullptr;
VirtualDir logo = nullptr;
VirtualFile file;
Loader::ResultStatus status{};
2018-07-28 03:55:23 +00:00
bool encrypted = false;
bool is_update = false;
2018-07-28 03:55:23 +00:00
Core::Crypto::KeyManager& keys;
2023-08-11 01:34:43 +00:00
std::shared_ptr<NcaReader> reader;
};
} // namespace FileSys