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