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