mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-04-22 20:44:49 +00:00
ncm: Move ncm_types to libstrat
This commit is contained in:
parent
8bfc1c5394
commit
4310a0018c
14 changed files with 209 additions and 222 deletions
|
@ -17,6 +17,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
#include "../util/util_uuid.hpp"
|
||||
|
||||
namespace sts::ncm {
|
||||
|
||||
|
@ -30,6 +31,104 @@ namespace sts::ncm {
|
|||
SdCard = 5,
|
||||
};
|
||||
|
||||
enum class ContentMetaType : u8 {
|
||||
Unknown = 0x0,
|
||||
SystemProgram = 0x1,
|
||||
SystemData = 0x2,
|
||||
SystemUpdate = 0x3,
|
||||
BootImagePackage = 0x4,
|
||||
BootImagePackageSafe = 0x5,
|
||||
Application = 0x80,
|
||||
Patch = 0x81,
|
||||
AddOnContent = 0x82,
|
||||
Delta = 0x83,
|
||||
};
|
||||
|
||||
enum class ContentType : u8 {
|
||||
Meta = 0,
|
||||
Program = 1,
|
||||
Data = 2,
|
||||
Control = 3,
|
||||
HtmlDocument = 4,
|
||||
LegalInformation = 5,
|
||||
DeltaFragment = 6,
|
||||
};
|
||||
|
||||
enum class ContentMetaAttribute : u8 {
|
||||
None = 0,
|
||||
IncludesExFatDriver = 1,
|
||||
Rebootless = 2,
|
||||
};
|
||||
|
||||
enum class ContentInstallType : u8 {
|
||||
Full = 0,
|
||||
FragmentOnly = 1,
|
||||
Unknown = 7,
|
||||
};
|
||||
|
||||
struct MountName {
|
||||
char name[0x10];
|
||||
};
|
||||
|
||||
struct PlaceHolderId {
|
||||
util::Uuid uuid;
|
||||
|
||||
bool operator==(const PlaceHolderId& other) const {
|
||||
return this->uuid == other.uuid;
|
||||
}
|
||||
|
||||
bool operator!=(const PlaceHolderId& other) const {
|
||||
return this->uuid != other.uuid;
|
||||
}
|
||||
|
||||
bool operator==(const util::Uuid& other) const {
|
||||
return this->uuid == other;
|
||||
}
|
||||
|
||||
bool operator!=(const util::Uuid& other) const {
|
||||
return this->uuid != other;
|
||||
}
|
||||
} __attribute__((aligned(8)));
|
||||
|
||||
static_assert(__alignof__(PlaceHolderId) == 8, "PlaceHolderId definition!");
|
||||
|
||||
struct ContentId {
|
||||
util::Uuid uuid;
|
||||
|
||||
bool operator==(const ContentId& other) const {
|
||||
return this->uuid == other.uuid;
|
||||
}
|
||||
|
||||
bool operator!=(const ContentId& other) const {
|
||||
return this->uuid != other.uuid;
|
||||
}
|
||||
|
||||
bool operator==(const util::Uuid& other) const {
|
||||
return this->uuid == other;
|
||||
}
|
||||
|
||||
bool operator!=(const util::Uuid& other) const {
|
||||
return this->uuid != other;
|
||||
}
|
||||
} __attribute__((aligned(4)));
|
||||
|
||||
static_assert(__alignof__(ContentId) == 4, "ContentId definition!");
|
||||
|
||||
static constexpr PlaceHolderId InvalidPlaceHolderId = { util::InvalidUuid };
|
||||
static constexpr ContentId InvalidContentId = { util::InvalidUuid };
|
||||
|
||||
struct ContentInfo {
|
||||
ContentId content_id;
|
||||
u8 size[6];
|
||||
ContentType content_type;
|
||||
u8 id_offset;
|
||||
};
|
||||
|
||||
static_assert(sizeof(ContentInfo) == 0x18, "ContentInfo definition!");
|
||||
|
||||
typedef void (*MakeContentPathFunc)(char* out, ContentId content_id, const char* root);
|
||||
typedef void (*MakePlaceHolderPathFunc)(char* out, PlaceHolderId placeholder_id, const char* root);
|
||||
|
||||
/* Title IDs. */
|
||||
struct TitleId {
|
||||
u64 value;
|
||||
|
@ -429,4 +528,65 @@ namespace sts::ncm {
|
|||
|
||||
static_assert(sizeof(TitleLocation) == 0x10 && std::is_pod<TitleLocation>::value, "TitleLocation definition!");
|
||||
|
||||
struct ContentMetaKey {
|
||||
TitleId id;
|
||||
u32 version;
|
||||
ContentMetaType type;
|
||||
ContentInstallType install_type;
|
||||
u8 padding[2];
|
||||
|
||||
bool operator<(const ContentMetaKey& other) const {
|
||||
if (this->id < other.id) {
|
||||
return true;
|
||||
} else if (this->id != other.id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this->version < other.version) {
|
||||
return true;
|
||||
} else if (this->version != other.version) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this->type < other.type) {
|
||||
return true;
|
||||
} else if (this->type != other.type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this->install_type < other.install_type;
|
||||
}
|
||||
|
||||
bool operator==(const ContentMetaKey& other) const {
|
||||
return this->id == other.id &&
|
||||
this->version == other.version &&
|
||||
this->type == other.type &&
|
||||
this->install_type == other.install_type;
|
||||
}
|
||||
|
||||
bool operator!=(const ContentMetaKey& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
static constexpr ContentMetaKey Make(TitleId title_id, u32 version, ContentMetaType type) {
|
||||
return { .id = title_id, .version = version, .type = type };
|
||||
}
|
||||
|
||||
static constexpr ContentMetaKey Make(TitleId title_id, u32 version, ContentMetaType type, ContentInstallType install_type) {
|
||||
return { .id = title_id, .version = version, .type = type, .install_type = install_type };
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(sizeof(ContentMetaKey) == 0x10, "ContentMetaKey definition!");
|
||||
|
||||
/* Used by system updates. They share the exact same struct as ContentMetaKey */
|
||||
typedef ContentMetaKey ContentMetaInfo;
|
||||
|
||||
struct ApplicationContentMetaKey {
|
||||
ContentMetaKey key;
|
||||
TitleId application_title_id;
|
||||
};
|
||||
|
||||
static_assert(sizeof(ApplicationContentMetaKey) == 0x18, "ApplicationContentMetaKey definition!");
|
||||
|
||||
}
|
||||
|
|
|
@ -21,3 +21,4 @@
|
|||
#include "util/util_ini.hpp"
|
||||
#include "util/util_intrusive_list.hpp"
|
||||
#include "util/util_intrusive_red_black_tree.hpp"
|
||||
#include "util/util_uuid.hpp"
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2019 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
|
||||
namespace sts::util {
|
||||
|
||||
struct Uuid {
|
||||
u8 uuid[0x10];
|
||||
|
||||
bool operator==(const Uuid& other) const {
|
||||
return memcmp(this->uuid, other.uuid, sizeof(Uuid)) == 0;
|
||||
}
|
||||
|
||||
bool operator!=(const Uuid& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
u8& operator[](size_t i) {
|
||||
return uuid[i];
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(sizeof(Uuid) == 0x10, "Uuid definition!");
|
||||
|
||||
static constexpr Uuid InvalidUuid = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } };
|
||||
|
||||
}
|
|
@ -18,7 +18,6 @@
|
|||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "../ncm_types.hpp"
|
||||
#include "../ncm_path_utils.hpp"
|
||||
|
||||
namespace sts::ncm::impl {
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "../ncm_types.hpp"
|
||||
|
||||
namespace sts::ncm::impl {
|
||||
|
||||
class RightsIdCache {
|
||||
|
@ -28,7 +26,7 @@ namespace sts::ncm::impl {
|
|||
public:
|
||||
struct Entry {
|
||||
public:
|
||||
Uuid uuid;
|
||||
util::Uuid uuid;
|
||||
FsRightsId rights_id;
|
||||
u64 key_generation;
|
||||
u64 last_accessed = 1;
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#include <stratosphere.hpp>
|
||||
#include <sys/dirent.h>
|
||||
|
||||
#include "ncm_types.hpp"
|
||||
|
||||
namespace sts::ncm {
|
||||
|
||||
Result OpenFile(FILE** out, const char* path, u32 mode);
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#include <stratosphere.hpp>
|
||||
#include <stratosphere/kvdb/kvdb_memory_key_value_store.hpp>
|
||||
|
||||
#include "ncm_types.hpp"
|
||||
|
||||
namespace sts::ncm {
|
||||
|
||||
class IContentMetaDatabase : public IServiceObject {
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "ncm_types.hpp"
|
||||
|
||||
namespace sts::ncm {
|
||||
|
||||
class IContentStorage : public IServiceObject {
|
||||
|
|
|
@ -21,15 +21,15 @@ namespace sts::ncm::path {
|
|||
|
||||
namespace {
|
||||
|
||||
u16 Get16BitSha256HashPrefix(Uuid uuid) {
|
||||
u16 Get16BitSha256HashPrefix(util::Uuid uuid) {
|
||||
u8 hash[SHA256_HASH_SIZE];
|
||||
sha256CalculateHash(hash, uuid.uuid, sizeof(Uuid));
|
||||
sha256CalculateHash(hash, uuid.uuid, sizeof(util::Uuid));
|
||||
return static_cast<u16>(hash[0]) | (static_cast<u16>(hash[1]) << 8);
|
||||
}
|
||||
|
||||
u8 Get8BitSha256HashPrefix(Uuid uuid) {
|
||||
u8 Get8BitSha256HashPrefix(util::Uuid uuid) {
|
||||
u8 hash[SHA256_HASH_SIZE];
|
||||
sha256CalculateHash(hash, uuid.uuid, sizeof(Uuid));
|
||||
sha256CalculateHash(hash, uuid.uuid, sizeof(util::Uuid));
|
||||
return hash[0];
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "ncm_types.hpp"
|
||||
|
||||
namespace sts::ncm::path {
|
||||
|
||||
void MakeContentPathFlat(char* out_path, ContentId content_id, const char* root);
|
||||
|
|
|
@ -66,7 +66,7 @@ namespace sts::ncm::path {
|
|||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sizeof(Uuid)*2; i++) {
|
||||
for (size_t i = 0; i < sizeof(util::Uuid)*2; i++) {
|
||||
if (!std::isxdigit(file_name.at(i))) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "ncm_types.hpp"
|
||||
|
||||
namespace sts::ncm::path {
|
||||
|
||||
inline void GetContentRootPath(char* out_content_root, const char* root_path) {
|
||||
|
|
|
@ -1,201 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Adubbz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace sts::ncm {
|
||||
|
||||
struct MountName {
|
||||
char name[0x10];
|
||||
};
|
||||
|
||||
struct Uuid {
|
||||
u8 uuid[0x10];
|
||||
|
||||
bool operator==(const Uuid& other) const {
|
||||
return memcmp(this->uuid, other.uuid, sizeof(Uuid)) == 0;
|
||||
}
|
||||
|
||||
bool operator!=(const Uuid& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
u8& operator[](size_t i) {
|
||||
return uuid[i];
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(sizeof(Uuid) == 0x10, "Uuid definition!");
|
||||
|
||||
struct PlaceHolderId {
|
||||
Uuid uuid;
|
||||
|
||||
bool operator==(const PlaceHolderId& other) const {
|
||||
return this->uuid == other.uuid;
|
||||
}
|
||||
|
||||
bool operator!=(const PlaceHolderId& other) const {
|
||||
return this->uuid != other.uuid;
|
||||
}
|
||||
|
||||
bool operator==(const Uuid& other) const {
|
||||
return this->uuid == other;
|
||||
}
|
||||
|
||||
bool operator!=(const Uuid& other) const {
|
||||
return this->uuid != other;
|
||||
}
|
||||
} __attribute__((aligned(8)));
|
||||
|
||||
static_assert(__alignof__(PlaceHolderId) == 8, "PlaceHolderId definition!");
|
||||
|
||||
struct ContentId {
|
||||
Uuid uuid;
|
||||
|
||||
bool operator==(const ContentId& other) const {
|
||||
return this->uuid == other.uuid;
|
||||
}
|
||||
|
||||
bool operator!=(const ContentId& other) const {
|
||||
return this->uuid != other.uuid;
|
||||
}
|
||||
|
||||
bool operator==(const Uuid& other) const {
|
||||
return this->uuid == other;
|
||||
}
|
||||
|
||||
bool operator!=(const Uuid& other) const {
|
||||
return this->uuid != other;
|
||||
}
|
||||
} __attribute__((aligned(4)));
|
||||
|
||||
static_assert(__alignof__(ContentId) == 4, "ContentId definition!");
|
||||
|
||||
static constexpr Uuid InvalidUuid = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } };
|
||||
static constexpr PlaceHolderId InvalidPlaceHolderId = { InvalidUuid };
|
||||
static constexpr ContentId InvalidContentId = { InvalidUuid };
|
||||
|
||||
enum class ContentMetaType : u8 {
|
||||
Unknown = 0x0,
|
||||
SystemProgram = 0x1,
|
||||
SystemData = 0x2,
|
||||
SystemUpdate = 0x3,
|
||||
BootImagePackage = 0x4,
|
||||
BootImagePackageSafe = 0x5,
|
||||
Application = 0x80,
|
||||
Patch = 0x81,
|
||||
AddOnContent = 0x82,
|
||||
Delta = 0x83,
|
||||
};
|
||||
|
||||
enum class ContentType : u8 {
|
||||
Meta = 0,
|
||||
Program = 1,
|
||||
Data = 2,
|
||||
Control = 3,
|
||||
HtmlDocument = 4,
|
||||
LegalInformation = 5,
|
||||
DeltaFragment = 6,
|
||||
};
|
||||
|
||||
enum class ContentMetaAttribute : u8 {
|
||||
None = 0,
|
||||
IncludesExFatDriver = 1,
|
||||
Rebootless = 2,
|
||||
};
|
||||
|
||||
enum class ContentInstallType : u8 {
|
||||
Full = 0,
|
||||
FragmentOnly = 1,
|
||||
Unknown = 7,
|
||||
};
|
||||
|
||||
struct ContentMetaKey {
|
||||
TitleId id;
|
||||
u32 version;
|
||||
ContentMetaType type;
|
||||
ContentInstallType install_type;
|
||||
u8 padding[2];
|
||||
|
||||
bool operator<(const ContentMetaKey& other) const {
|
||||
if (this->id < other.id) {
|
||||
return true;
|
||||
} else if (this->id != other.id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this->version < other.version) {
|
||||
return true;
|
||||
} else if (this->version != other.version) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this->type < other.type) {
|
||||
return true;
|
||||
} else if (this->type != other.type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this->install_type < other.install_type;
|
||||
}
|
||||
|
||||
bool operator==(const ContentMetaKey& other) const {
|
||||
return this->id == other.id &&
|
||||
this->version == other.version &&
|
||||
this->type == other.type &&
|
||||
this->install_type == other.install_type;
|
||||
}
|
||||
|
||||
bool operator!=(const ContentMetaKey& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
static constexpr ContentMetaKey Make(TitleId title_id, u32 version, ContentMetaType type) {
|
||||
return { .id = title_id, .version = version, .type = type };
|
||||
}
|
||||
|
||||
static constexpr ContentMetaKey Make(TitleId title_id, u32 version, ContentMetaType type, ContentInstallType install_type) {
|
||||
return { .id = title_id, .version = version, .type = type, .install_type = install_type };
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(sizeof(ContentMetaKey) == 0x10, "ContentMetaKey definition!");
|
||||
|
||||
// Used by system updates. They share the exact same struct as ContentMetaKey;
|
||||
typedef ContentMetaKey ContentMetaInfo;
|
||||
|
||||
struct ApplicationContentMetaKey {
|
||||
ContentMetaKey key;
|
||||
TitleId application_title_id;
|
||||
};
|
||||
|
||||
static_assert(sizeof(ApplicationContentMetaKey) == 0x18, "ApplicationContentMetaKey definition!");
|
||||
|
||||
struct ContentInfo {
|
||||
ContentId content_id;
|
||||
u8 size[6];
|
||||
ContentType content_type;
|
||||
u8 id_offset;
|
||||
};
|
||||
|
||||
static_assert(sizeof(ContentInfo) == 0x18, "ContentInfo definition!");
|
||||
|
||||
typedef void (*MakeContentPathFunc)(char* out, ContentId content_id, const char* root);
|
||||
typedef void (*MakePlaceHolderPathFunc)(char* out, PlaceHolderId placeholder_id, const char* root);
|
||||
|
||||
}
|
|
@ -19,8 +19,6 @@
|
|||
#include <stratosphere.hpp>
|
||||
#include <sys/dirent.h>
|
||||
|
||||
#include "ncm_types.hpp"
|
||||
|
||||
namespace sts::ncm {
|
||||
|
||||
void GetStringFromContentId(char* out, ContentId content_id);
|
||||
|
|
Loading…
Add table
Reference in a new issue