mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2025-01-05 11:58:00 +00:00
Universally use EnsureEnabled
This commit is contained in:
parent
cf06cb7628
commit
fac8acebba
8 changed files with 50 additions and 103 deletions
|
@ -179,15 +179,6 @@ namespace sts::ncm {
|
|||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result ContentMetaDatabaseInterface::EnsureEnabled() {
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentMetaDatabase;
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
|
||||
Result ContentMetaDatabaseInterface::Set(ContentMetaKey key, InBuffer<u8> value) {
|
||||
R_DEBUG_START
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
|
|
@ -31,8 +31,6 @@ namespace sts::ncm {
|
|||
private:
|
||||
Result GetContentIdByTypeImpl(ContentId* out, const ContentMetaKey& key, ContentType type, std::optional<u8> id_offset);
|
||||
Result GetLatestContentMetaKeyImpl(ContentMetaKey* out_key, TitleId tid);
|
||||
protected:
|
||||
Result EnsureEnabled();
|
||||
public:
|
||||
virtual Result Set(ContentMetaKey key, InBuffer<u8> value) override;
|
||||
virtual Result Get(Out<u64> out_size, ContentMetaKey key, OutBuffer<u8> out_value) override;
|
||||
|
|
|
@ -29,10 +29,7 @@ namespace sts::ncm {
|
|||
}
|
||||
|
||||
Result ContentStorageInterface::Initialize(const char* root_path, MakeContentPathFunc content_path_func, MakePlaceHolderPathFunc placeholder_path_func, bool delay_flush) {
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
|
||||
R_TRY(this->EnsureEnabled());
|
||||
R_TRY(CheckContentStorageDirectoriesExist(root_path));
|
||||
const size_t root_path_len = strnlen(root_path, FS_MAX_PATH-1);
|
||||
|
||||
|
@ -95,9 +92,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::GeneratePlaceHolderId(Out<PlaceHolderId> out) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
sts::rnd::GenerateRandomBytes(out.GetPointer(), sizeof(NcmNcaId));
|
||||
return ResultSuccess;
|
||||
|
@ -106,9 +101,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, u64 size) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char content_path[FS_MAX_PATH] = {0};
|
||||
this->GetContentPath(content_path, content_id);
|
||||
|
@ -122,9 +115,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::DeletePlaceHolder(PlaceHolderId placeholder_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
return this->placeholder_accessor.Delete(placeholder_id);
|
||||
R_DEBUG_END
|
||||
|
@ -132,9 +123,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::HasPlaceHolder(Out<bool> out, PlaceHolderId placeholder_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char placeholder_path[FS_MAX_PATH] = {0};
|
||||
this->placeholder_accessor.GetPlaceHolderPath(placeholder_path, placeholder_id);
|
||||
|
@ -154,9 +143,7 @@ namespace sts::ncm {
|
|||
return ResultNcmInvalidOffset;
|
||||
}
|
||||
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
FILE* f = nullptr;
|
||||
|
||||
|
@ -199,10 +186,7 @@ namespace sts::ncm {
|
|||
Result ContentStorageInterface::Register(PlaceHolderId placeholder_id, ContentId content_id) {
|
||||
R_DEBUG_START
|
||||
this->ClearContentCache();
|
||||
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char placeholder_path[FS_MAX_PATH] = {0};
|
||||
char content_path[FS_MAX_PATH] = {0};
|
||||
|
@ -227,9 +211,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::Delete(ContentId content_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
this->ClearContentCache();
|
||||
char content_path[FS_MAX_PATH] = {0};
|
||||
|
@ -249,9 +231,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::Has(Out<bool> out, ContentId content_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char content_path[FS_MAX_PATH] = {0};
|
||||
this->GetContentPath(content_path, content_id);
|
||||
|
@ -266,9 +246,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::GetPath(OutPointerWithServerSize<lr::Path, 0x1> out, ContentId content_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char content_path[FS_MAX_PATH] = {0};
|
||||
char common_path[FS_MAX_PATH] = {0};
|
||||
|
@ -282,9 +260,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::GetPlaceHolderPath(OutPointerWithServerSize<lr::Path, 0x1> out, PlaceHolderId placeholder_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char placeholder_path[FS_MAX_PATH] = {0};
|
||||
char common_path[FS_MAX_PATH] = {0};
|
||||
|
@ -297,9 +273,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::CleanupAllPlaceHolder() {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char placeholder_root_path[FS_MAX_PATH] = {0};
|
||||
this->placeholder_accessor.ClearAllCaches();
|
||||
|
@ -319,9 +293,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::ListPlaceHolder(Out<u32> out_count, OutBuffer<PlaceHolderId> out_buf) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char placeholder_root_path[FS_MAX_PATH] = {0};
|
||||
this->placeholder_accessor.GetPlaceHolderRootPath(placeholder_root_path);
|
||||
|
@ -352,9 +324,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::GetContentCount(Out<u32> out_count) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char content_root_path[FS_MAX_PATH] = {0};
|
||||
this->GetContentRootPath(content_root_path);
|
||||
|
@ -383,9 +353,7 @@ namespace sts::ncm {
|
|||
return ResultNcmInvalidOffset;
|
||||
}
|
||||
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char content_root_path[FS_MAX_PATH] = {0};
|
||||
this->GetContentRootPath(content_root_path);
|
||||
|
@ -436,9 +404,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::GetSizeFromContentId(Out<u64> out_size, ContentId content_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char content_path[FS_MAX_PATH] = {0};
|
||||
this->GetContentPath(content_path, content_id);
|
||||
|
@ -464,9 +430,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::RevertToPlaceHolder(PlaceHolderId placeholder_id, ContentId old_content_id, ContentId new_content_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char old_content_path[FS_MAX_PATH] = {0};
|
||||
char new_content_path[FS_MAX_PATH] = {0};
|
||||
|
@ -497,9 +461,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::SetPlaceHolderSize(PlaceHolderId placeholder_id, u64 size) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
R_TRY(this->placeholder_accessor.SetSize(placeholder_id, size));
|
||||
return ResultSuccess;
|
||||
|
@ -513,9 +475,7 @@ namespace sts::ncm {
|
|||
return ResultNcmInvalidOffset;
|
||||
}
|
||||
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char content_path[FS_MAX_PATH] = {0};
|
||||
this->GetContentPath(content_path, content_id);
|
||||
|
@ -535,9 +495,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::GetRightsIdFromPlaceHolderId(Out<FsRightsId> out_rights_id, Out<u64> out_key_generation, PlaceHolderId placeholder_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
FsRightsId rights_id = {0};
|
||||
u8 key_generation = 0;
|
||||
|
@ -557,9 +515,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::GetRightsIdFromContentId(Out<FsRightsId> out_rights_id, Out<u64> out_key_generation, ContentId content_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
impl::RightsIdCache* rights_id_cache = impl::GetRightsIdCache();
|
||||
|
||||
|
@ -625,9 +581,7 @@ namespace sts::ncm {
|
|||
return ResultNcmInvalidOffset;
|
||||
}
|
||||
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
bool is_development = false;
|
||||
|
||||
|
@ -706,9 +660,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::GetSizeFromPlaceHolderId(Out<u64> out_size, PlaceHolderId placeholder_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
bool found_in_cache = false;
|
||||
size_t size = 0;
|
||||
|
@ -768,9 +720,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::GetRightsIdFromPlaceHolderIdWithCache(Out<FsRightsId> out_rights_id, Out<u64> out_key_generation, PlaceHolderId placeholder_id, ContentId cache_content_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
impl::RightsIdCache* rights_id_cache = impl::GetRightsIdCache();
|
||||
|
||||
|
|
|
@ -18,6 +18,14 @@
|
|||
|
||||
namespace sts::ncm {
|
||||
|
||||
Result IContentMetaDatabase::EnsureEnabled() {
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentMetaDatabase;
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result IContentMetaDatabase::Set(ContentMetaKey key, InBuffer<u8> value) {
|
||||
std::abort();
|
||||
}
|
||||
|
|
|
@ -52,6 +52,8 @@ namespace sts::ncm {
|
|||
sts::kvdb::MemoryKeyValueStore<ContentMetaKey>* kvs;
|
||||
char mount_name[16];
|
||||
bool disabled;
|
||||
protected:
|
||||
Result EnsureEnabled();
|
||||
public:
|
||||
IContentMetaDatabase(sts::kvdb::MemoryKeyValueStore<ContentMetaKey>* kvs) :
|
||||
kvs(kvs), disabled(false)
|
||||
|
|
|
@ -18,6 +18,14 @@
|
|||
|
||||
namespace sts::ncm {
|
||||
|
||||
Result IContentStorage::EnsureEnabled() {
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result IContentStorage::GeneratePlaceHolderId(Out<PlaceHolderId> out) {
|
||||
std::abort();
|
||||
}
|
||||
|
|
|
@ -59,6 +59,8 @@ namespace sts::ncm {
|
|||
char root_path[FS_MAX_PATH-1];
|
||||
MakeContentPathFunc make_content_path_func;
|
||||
bool disabled;
|
||||
protected:
|
||||
Result EnsureEnabled();
|
||||
public:
|
||||
virtual Result GeneratePlaceHolderId(Out<PlaceHolderId> out);
|
||||
virtual Result CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, u64 size);
|
||||
|
|
|
@ -24,9 +24,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ReadOnlyContentStorageInterface::Initialize(const char* root_path, MakeContentPathFunc content_path_func) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
const size_t root_path_len = strnlen(root_path, FS_MAX_PATH-1);
|
||||
|
||||
|
@ -84,9 +82,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ReadOnlyContentStorageInterface::Has(Out<bool> out, ContentId content_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char content_path[FS_MAX_PATH] = {0};
|
||||
this->make_content_path_func(content_path, content_id, this->root_path);
|
||||
|
@ -106,9 +102,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ReadOnlyContentStorageInterface::GetPath(OutPointerWithServerSize<lr::Path, 0x1> out, ContentId content_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char content_path[FS_MAX_PATH] = {0};
|
||||
char common_path[FS_MAX_PATH] = {0};
|
||||
|
@ -160,9 +154,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ReadOnlyContentStorageInterface::GetSizeFromContentId(Out<u64> out_size, ContentId content_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char content_path[FS_MAX_PATH] = {0};
|
||||
bool is_content_file = false;
|
||||
|
@ -210,9 +202,7 @@ namespace sts::ncm {
|
|||
return ResultNcmInvalidOffset;
|
||||
}
|
||||
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char content_path[FS_MAX_PATH] = {0};
|
||||
bool is_content_file = false;
|
||||
|
@ -251,9 +241,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ReadOnlyContentStorageInterface::GetRightsIdFromContentId(Out<FsRightsId> out_rights_id, Out<u64> out_key_generation, ContentId content_id) {
|
||||
R_DEBUG_START
|
||||
if (this->disabled) {
|
||||
return ResultNcmInvalidContentStorage;
|
||||
}
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
FsRightsId rights_id = {0};
|
||||
u8 key_generation = 0;
|
||||
|
|
Loading…
Reference in a new issue