mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-07-13 20:52:15 +02:00
ncm: use R_SUCCEED_IF
This commit is contained in:
parent
510a764350
commit
241697b8ba
@ -81,7 +81,7 @@ namespace ams::ncm {
|
|||||||
|
|
||||||
/* Obtain the existing flags. */
|
/* Obtain the existing flags. */
|
||||||
R_TRY(fs::GetSaveDataFlags(std::addressof(cur_flags), BuiltInSystemSaveDataId));
|
R_TRY(fs::GetSaveDataFlags(std::addressof(cur_flags), BuiltInSystemSaveDataId));
|
||||||
|
|
||||||
/* Update the flags if needed. */
|
/* Update the flags if needed. */
|
||||||
if (cur_flags != BuiltInSystemSaveDataFlags) {
|
if (cur_flags != BuiltInSystemSaveDataFlags) {
|
||||||
R_TRY(fs::SetSaveDataFlags(BuiltInSystemSaveDataId, fs::SaveDataSpaceId::System, BuiltInSystemSaveDataFlags));
|
R_TRY(fs::SetSaveDataFlags(BuiltInSystemSaveDataId, fs::SaveDataSpaceId::System, BuiltInSystemSaveDataFlags));
|
||||||
@ -222,8 +222,8 @@ namespace ams::ncm {
|
|||||||
Result ContentManagerImpl::Initialize() {
|
Result ContentManagerImpl::Initialize() {
|
||||||
std::scoped_lock lk(this->mutex);
|
std::scoped_lock lk(this->mutex);
|
||||||
|
|
||||||
/* Already initialized. */
|
/* Check if we've already initialized. */
|
||||||
R_UNLESS(!this->initialized, ResultSuccess());
|
R_SUCCEED_IF(this->initialized);
|
||||||
|
|
||||||
/* Clear storage id for all roots. */
|
/* Clear storage id for all roots. */
|
||||||
for (auto &root : this->content_storage_roots) {
|
for (auto &root : this->content_storage_roots) {
|
||||||
@ -289,7 +289,7 @@ namespace ams::ncm {
|
|||||||
|
|
||||||
/* Ensure the content storage root's path exists. */
|
/* Ensure the content storage root's path exists. */
|
||||||
R_TRY(impl::EnsureDirectoryRecursively(root->path));
|
R_TRY(impl::EnsureDirectoryRecursively(root->path));
|
||||||
|
|
||||||
/* Initialize content and placeholder directories for the root. */
|
/* Initialize content and placeholder directories for the root. */
|
||||||
R_TRY(ContentStorageImpl::InitializeBase(root->path));
|
R_TRY(ContentStorageImpl::InitializeBase(root->path));
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ namespace ams::ncm {
|
|||||||
/* Ensure the content meta database root's path exists. */
|
/* Ensure the content meta database root's path exists. */
|
||||||
R_TRY(impl::EnsureDirectoryRecursively(root->path));
|
R_TRY(impl::EnsureDirectoryRecursively(root->path));
|
||||||
|
|
||||||
/* Commit our changes. */
|
/* Commit our changes. */
|
||||||
R_TRY(fs::CommitSaveData(root->mount_name));
|
R_TRY(fs::CommitSaveData(root->mount_name));
|
||||||
|
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
@ -342,7 +342,7 @@ namespace ams::ncm {
|
|||||||
|
|
||||||
Result ContentManagerImpl::VerifyContentMetaDatabase(StorageId storage_id) {
|
Result ContentManagerImpl::VerifyContentMetaDatabase(StorageId storage_id) {
|
||||||
/* Game card content meta databases will always be valid. */
|
/* Game card content meta databases will always be valid. */
|
||||||
R_UNLESS(storage_id != StorageId::GameCard, ResultSuccess());
|
R_SUCCEED_IF(storage_id == StorageId::GameCard);
|
||||||
|
|
||||||
std::scoped_lock lk(this->mutex);
|
std::scoped_lock lk(this->mutex);
|
||||||
|
|
||||||
@ -441,7 +441,7 @@ namespace ams::ncm {
|
|||||||
R_TRY(this->GetContentStorageRoot(std::addressof(root), storage_id));
|
R_TRY(this->GetContentStorageRoot(std::addressof(root), storage_id));
|
||||||
|
|
||||||
/* Check if the storage is already activated. */
|
/* Check if the storage is already activated. */
|
||||||
R_UNLESS(root->content_storage == nullptr, ResultSuccess());
|
R_SUCCEED_IF(root->content_storage != nullptr);
|
||||||
|
|
||||||
/* Mount based on the storage type. */
|
/* Mount based on the storage type. */
|
||||||
if (storage_id == StorageId::GameCard) {
|
if (storage_id == StorageId::GameCard) {
|
||||||
@ -511,7 +511,7 @@ namespace ams::ncm {
|
|||||||
R_TRY(this->GetContentMetaDatabaseRoot(&root, storage_id));
|
R_TRY(this->GetContentMetaDatabaseRoot(&root, storage_id));
|
||||||
|
|
||||||
/* Already activated. */
|
/* Already activated. */
|
||||||
R_UNLESS(root->content_meta_database == nullptr, ResultSuccess());
|
R_SUCCEED_IF(root->content_meta_database != nullptr);
|
||||||
|
|
||||||
/* Make a new kvs. */
|
/* Make a new kvs. */
|
||||||
root->kvs.emplace();
|
root->kvs.emplace();
|
||||||
|
@ -215,9 +215,12 @@ namespace ams::ncm {
|
|||||||
|
|
||||||
/* Check if keys are present. */
|
/* Check if keys are present. */
|
||||||
for (size_t i = 0; i < keys.GetSize(); i++) {
|
for (size_t i = 0; i < keys.GetSize(); i++) {
|
||||||
|
/* Check if we have the current key. */
|
||||||
bool has;
|
bool has;
|
||||||
R_TRY(this->Has(std::addressof(has), keys[i]));
|
R_TRY(this->Has(std::addressof(has), keys[i]));
|
||||||
R_UNLESS(has, ResultSuccess());
|
|
||||||
|
/* If we don't, then we can early return because we don't have all. */
|
||||||
|
R_SUCCEED_IF(!has);
|
||||||
}
|
}
|
||||||
|
|
||||||
*out = true;
|
*out = true;
|
||||||
@ -288,9 +291,6 @@ namespace ams::ncm {
|
|||||||
out_orphaned[i] = true;
|
out_orphaned[i] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If key value store is empty, all content is orphaned. */
|
|
||||||
R_UNLESS(this->kvs->GetCount() != 0, ResultSuccess());
|
|
||||||
|
|
||||||
auto IsOrphanedContent = [](const sf::InArray<ContentId> &list, const ncm::ContentId &id) ALWAYS_INLINE_LAMBDA {
|
auto IsOrphanedContent = [](const sf::InArray<ContentId> &list, const ncm::ContentId &id) ALWAYS_INLINE_LAMBDA {
|
||||||
/* Check if any input content ids match our found content id. */
|
/* Check if any input content ids match our found content id. */
|
||||||
for (size_t i = 0; i < list.GetSize(); i++) {
|
for (size_t i = 0; i < list.GetSize(); i++) {
|
||||||
|
@ -56,7 +56,8 @@ namespace ams::ncm {
|
|||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
Result TraverseDirectory(bool *out_should_continue, const char *root_path, int max_level, F f) {
|
Result TraverseDirectory(bool *out_should_continue, const char *root_path, int max_level, F f) {
|
||||||
R_UNLESS(max_level > 0, ResultSuccess());
|
/* If the level is zero, we're done. */
|
||||||
|
R_SUCCEED_IF(max_level <= 0);
|
||||||
|
|
||||||
/* Retry traversal upon request. */
|
/* Retry traversal upon request. */
|
||||||
bool retry_dir_read = true;
|
bool retry_dir_read = true;
|
||||||
@ -230,7 +231,8 @@ namespace ams::ncm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result ContentStorageImpl::OpenContentIdFile(ContentId content_id) {
|
Result ContentStorageImpl::OpenContentIdFile(ContentId content_id) {
|
||||||
R_UNLESS(this->cached_content_id != content_id, ResultSuccess());
|
/* If the file is the currently cached one, we've nothing to do. */
|
||||||
|
R_SUCCEED_IF(this->cached_content_id == content_id);
|
||||||
|
|
||||||
/* Close any cached file. */
|
/* Close any cached file. */
|
||||||
this->InvalidateFileCache();
|
this->InvalidateFileCache();
|
||||||
|
@ -84,7 +84,7 @@ namespace ams::ncm {
|
|||||||
|
|
||||||
Result PlaceHolderAccessor::Open(fs::FileHandle *out_handle, PlaceHolderId placeholder_id) {
|
Result PlaceHolderAccessor::Open(fs::FileHandle *out_handle, PlaceHolderId placeholder_id) {
|
||||||
/* Try to load from the cache. */
|
/* Try to load from the cache. */
|
||||||
R_UNLESS(!this->LoadFromCache(out_handle, placeholder_id), ResultSuccess());
|
R_SUCCEED_IF(this->LoadFromCache(out_handle, placeholder_id));
|
||||||
|
|
||||||
/* Make the path of the placeholder. */
|
/* Make the path of the placeholder. */
|
||||||
PathString placeholder_path;
|
PathString placeholder_path;
|
||||||
@ -231,7 +231,7 @@ namespace ams::ncm {
|
|||||||
/* Attempt to find the placeholder in the cache. */
|
/* Attempt to find the placeholder in the cache. */
|
||||||
fs::FileHandle handle;
|
fs::FileHandle handle;
|
||||||
auto found = this->LoadFromCache(std::addressof(handle), placeholder_id);
|
auto found = this->LoadFromCache(std::addressof(handle), placeholder_id);
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
/* Renew the entry in the cache. */
|
/* Renew the entry in the cache. */
|
||||||
this->StoreToCache(placeholder_id, handle);
|
this->StoreToCache(placeholder_id, handle);
|
||||||
|
Loading…
Reference in New Issue
Block a user