Improved type safety

This commit is contained in:
Adubbz 2019-08-09 15:44:47 +10:00
parent 15e8e32409
commit 1aa23b62bd
3 changed files with 18 additions and 10 deletions

View file

@ -518,7 +518,7 @@ namespace sts::ncm {
}
/* Update the cache. */
eviction_candidate->uuid = content_id;
eviction_candidate->uuid = content_id.uuid;
eviction_candidate->rights_id = rights_id;
eviction_candidate->key_generation = key_generation;
eviction_candidate->last_accessed = rights_id_cache->counter;
@ -705,7 +705,7 @@ namespace sts::ncm {
}
/* Update the cache. */
eviction_candidate->uuid = cache_content_id;
eviction_candidate->uuid = cache_content_id.uuid;
eviction_candidate->rights_id = rights_id;
eviction_candidate->key_generation = key_generation;
eviction_candidate->last_accessed = rights_id_cache->counter;

View file

@ -45,7 +45,7 @@ namespace sts::ncm::path {
void MakeContentPathDualLayered(char* path_out, ContentId content_id, const char* root) {
char content_name[FS_MAX_PATH] = {0};
const u16 hash = Get16BitSha256HashPrefix(content_id);
const u16 hash = Get16BitSha256HashPrefix(content_id.uuid);
const u32 hash_lower = (hash >> 4) & 0x3f;
const u32 hash_upper = (hash >> 10) & 0x3f;
@ -57,7 +57,7 @@ namespace sts::ncm::path {
void MakeContentPath10BitLayered(char* path_out, ContentId content_id, const char* root) {
char content_name[FS_MAX_PATH] = {0};
const u32 hash = (Get16BitSha256HashPrefix(content_id) >> 6) & 0x3FF;
const u32 hash = (Get16BitSha256HashPrefix(content_id.uuid) >> 6) & 0x3FF;
GetContentFileName(content_name, content_id);
if (snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%s", root, hash, content_name) < 0) {
std::abort();
@ -66,7 +66,7 @@ namespace sts::ncm::path {
void MakeContentPathHashByteLayered(char* path_out, ContentId content_id, const char* root) {
char content_name[FS_MAX_PATH] = {0};
const u32 hash_byte = static_cast<u32>(Get8BitSha256HashPrefix(content_id));
const u32 hash_byte = static_cast<u32>(Get8BitSha256HashPrefix(content_id.uuid));
GetContentFileName(content_name, content_id);
if (snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%s", root, hash_byte, content_name) < 0) {
std::abort();
@ -83,7 +83,7 @@ namespace sts::ncm::path {
void MakePlaceHolderPathHashByteLayered(char* path_out, PlaceHolderId placeholder_id, const char* root) {
char placeholder_name[FS_MAX_PATH] = {0};
const u32 hash_byte = static_cast<u32>(Get8BitSha256HashPrefix(placeholder_id));
const u32 hash_byte = static_cast<u32>(Get8BitSha256HashPrefix(placeholder_id.uuid));
GetPlaceHolderFileName(placeholder_name, placeholder_id);
if (snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%s", root, hash_byte, placeholder_name) < 0) {
std::abort();

View file

@ -45,8 +45,12 @@ namespace sts::ncm {
struct PlaceHolderId {
Uuid uuid;
inline operator Uuid() const {
return this->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 {
@ -63,8 +67,12 @@ namespace sts::ncm {
struct ContentId {
Uuid uuid;
inline operator Uuid() const {
return this->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 {