ncm: minor style fixes

This commit is contained in:
Adubbz 2020-03-07 13:14:34 +11:00
parent 147ea49a3a
commit 9717b554c5
12 changed files with 44 additions and 70 deletions

View File

@ -69,14 +69,14 @@ namespace ams::ncm {
}; };
private: private:
os::Mutex mutex; os::Mutex mutex;
bool initialized = false; bool initialized;
ContentStorageRoot content_storage_roots[MaxContentStorageRoots]; ContentStorageRoot content_storage_roots[MaxContentStorageRoots];
ContentMetaDatabaseRoot content_meta_database_roots[MaxContentMetaDatabaseRoots]; ContentMetaDatabaseRoot content_meta_database_roots[MaxContentMetaDatabaseRoots];
u32 num_content_storage_entries; u32 num_content_storage_entries;
u32 num_content_meta_entries; u32 num_content_meta_entries;
RightsIdCache rights_id_cache; RightsIdCache rights_id_cache;
public: public:
ContentManagerImpl() { /* ... */ }; ContentManagerImpl() : initialized(false) { /* ... */ };
~ContentManagerImpl(); ~ContentManagerImpl();
public: public:
Result Initialize(); Result Initialize();

View File

@ -65,8 +65,7 @@ namespace ams::ncm {
/* Update the cache. */ /* Update the cache. */
eviction_candidate->uuid = content_id.uuid; eviction_candidate->uuid = content_id.uuid;
eviction_candidate->rights_id = rights_id; eviction_candidate->rights_id = rights_id;
eviction_candidate->last_accessed = this->counter; eviction_candidate->last_accessed = this->counter++;
this->counter++;
} }
bool Find(ncm::RightsId *out_rights_id, ContentId content_id) { bool Find(ncm::RightsId *out_rights_id, ContentId content_id) {

View File

@ -23,7 +23,7 @@ namespace ams::lr {
ncm::StorageId storage_id = ncm::StorageId::None; ncm::StorageId storage_id = ncm::StorageId::None;
R_UNLESS(this->registered_storages.Find(&storage_id, id), lr::ResultAddOnContentNotFound()); R_UNLESS(this->registered_storages.Find(&storage_id, id), lr::ResultAddOnContentNotFound());
/* Obtain a Content Meta Database for the storage id. */ /* Obtain a content meta database for the storage id. */
ncm::ContentMetaDatabase content_meta_database; ncm::ContentMetaDatabase content_meta_database;
R_TRY(ncm::OpenContentMetaDatabase(&content_meta_database, storage_id)); R_TRY(ncm::OpenContentMetaDatabase(&content_meta_database, storage_id));
@ -31,7 +31,7 @@ namespace ams::lr {
ncm::ContentId data_content_id; ncm::ContentId data_content_id;
R_TRY(content_meta_database.GetLatestData(&data_content_id, id)); R_TRY(content_meta_database.GetLatestData(&data_content_id, id));
/* Obtain a Content Storage for the storage id. */ /* Obtain a content storage for the storage id. */
ncm::ContentStorage content_storage; ncm::ContentStorage content_storage;
R_TRY(ncm::OpenContentStorage(&content_storage, storage_id)); R_TRY(ncm::OpenContentStorage(&content_storage, storage_id));

View File

@ -106,7 +106,7 @@ namespace ams::lr {
} }
Result ContentLocationResolverImpl::Refresh() { Result ContentLocationResolverImpl::Refresh() {
/* Obtain Content Meta Database and Content Storage objects for this resolver's storage. */ /* Obtain content meta database and content storage objects for this resolver's storage. */
ncm::ContentMetaDatabase meta_db; ncm::ContentMetaDatabase meta_db;
ncm::ContentStorage storage; ncm::ContentStorage storage;
R_TRY(ncm::OpenContentMetaDatabase(&meta_db, this->storage_id)); R_TRY(ncm::OpenContentMetaDatabase(&meta_db, this->storage_id));

View File

@ -42,8 +42,7 @@ namespace ams::lr {
} }
/* Copy the output interface. */ /* Copy the output interface. */
std::shared_ptr<ILocationResolver> new_intf = *resolver; out.SetValue(std::shared_ptr<ILocationResolver>(*resolver));
out.SetValue(std::move(new_intf));
return ResultSuccess(); return ResultSuccess();
} }
@ -56,8 +55,7 @@ namespace ams::lr {
} }
/* Copy the output interface. */ /* Copy the output interface. */
std::shared_ptr<IRegisteredLocationResolver> new_intf = this->registered_location_resolver; out.SetValue(std::shared_ptr<IRegisteredLocationResolver>(this->registered_location_resolver));
out.SetValue(std::move(new_intf));
return ResultSuccess(); return ResultSuccess();
} }
@ -85,8 +83,7 @@ namespace ams::lr {
} }
/* Copy the output interface. */ /* Copy the output interface. */
std::shared_ptr<IAddOnContentLocationResolver> new_intf = this->add_on_content_location_resolver; out.SetValue(std::shared_ptr<IAddOnContentLocationResolver>(this->add_on_content_location_resolver));
out.SetValue(std::move(new_intf));
return ResultSuccess(); return ResultSuccess();
} }

View File

@ -51,9 +51,7 @@ namespace ams::ncm {
ContentIdString GetContentIdString(ContentId id) { ContentIdString GetContentIdString(ContentId id) {
ContentIdString str; ContentIdString str;
GetStringFromContentId(str.data, sizeof(str), id); GetStringFromContentId(str.data, sizeof(str), id);
return str; return str;
} }

View File

@ -91,8 +91,8 @@ namespace ams::ncm {
ALWAYS_INLINE Result GetContentStorageNotActiveResult(StorageId storage_id) { ALWAYS_INLINE Result GetContentStorageNotActiveResult(StorageId storage_id) {
switch (storage_id) { switch (storage_id) {
case StorageId::GameCard: return ResultGameCardContentStorageNotActive(); case StorageId::GameCard: return ResultGameCardContentStorageNotActive();
case StorageId::BuiltInSystem: return ResultNandSystemContentStorageNotActive(); case StorageId::BuiltInSystem: return ResultBuiltInSystemContentStorageNotActive();
case StorageId::BuiltInUser: return ResultNandUserContentStorageNotActive(); case StorageId::BuiltInUser: return ResultBuiltInUserContentStorageNotActive();
case StorageId::SdCard: return ResultSdCardContentStorageNotActive(); case StorageId::SdCard: return ResultSdCardContentStorageNotActive();
default: return ResultUnknownContentStorageNotActive(); default: return ResultUnknownContentStorageNotActive();
} }
@ -101,8 +101,8 @@ namespace ams::ncm {
ALWAYS_INLINE Result GetContentMetaDatabaseNotActiveResult(StorageId storage_id) { ALWAYS_INLINE Result GetContentMetaDatabaseNotActiveResult(StorageId storage_id) {
switch (storage_id) { switch (storage_id) {
case StorageId::GameCard: return ResultGameCardContentMetaDatabaseNotActive(); case StorageId::GameCard: return ResultGameCardContentMetaDatabaseNotActive();
case StorageId::BuiltInSystem: return ResultNandSystemContentMetaDatabaseNotActive(); case StorageId::BuiltInSystem: return ResultBuiltInSystemContentMetaDatabaseNotActive();
case StorageId::BuiltInUser: return ResultNandUserContentMetaDatabaseNotActive(); case StorageId::BuiltInUser: return ResultBuiltInUserContentMetaDatabaseNotActive();
case StorageId::SdCard: return ResultSdCardContentMetaDatabaseNotActive(); case StorageId::SdCard: return ResultSdCardContentMetaDatabaseNotActive();
default: return ResultUnknownContentMetaDatabaseNotActive(); default: return ResultUnknownContentMetaDatabaseNotActive();
} }
@ -290,9 +290,7 @@ namespace ams::ncm {
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)); return ContentStorageImpl::InitializeBase(root->path);
return ResultSuccess();
} }
Result ContentManagerImpl::CreateContentMetaDatabase(StorageId storage_id) { Result ContentManagerImpl::CreateContentMetaDatabase(StorageId storage_id) {
@ -312,9 +310,7 @@ namespace ams::ncm {
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)); return fs::CommitSaveData(root->mount_name);
return ResultSuccess();
} }
Result ContentManagerImpl::VerifyContentStorage(StorageId storage_id) { Result ContentManagerImpl::VerifyContentStorage(StorageId storage_id) {
@ -334,9 +330,7 @@ namespace ams::ncm {
ON_SCOPE_EXIT { fs::Unmount(mount_name.str); }; ON_SCOPE_EXIT { fs::Unmount(mount_name.str); };
/* Ensure the root, content and placeholder directories exist for the storage. */ /* Ensure the root, content and placeholder directories exist for the storage. */
R_TRY(ContentStorageImpl::VerifyBase(path)); return ContentStorageImpl::VerifyBase(path);
return ResultSuccess();
} }
Result ContentManagerImpl::VerifyContentMetaDatabase(StorageId storage_id) { Result ContentManagerImpl::VerifyContentMetaDatabase(StorageId storage_id) {
@ -382,8 +376,7 @@ namespace ams::ncm {
} }
} }
auto content_storage = root->content_storage; out.SetValue(std::shared_ptr<IContentStorage>(root->content_storage));
out.SetValue(std::move(content_storage));
return ResultSuccess(); return ResultSuccess();
} }
@ -404,8 +397,7 @@ namespace ams::ncm {
} }
} }
auto content_meta_db = root->content_meta_database; out.SetValue(std::shared_ptr<IContentMetaDatabase>(root->content_meta_database));
out.SetValue(std::move(content_meta_db));
return ResultSuccess(); return ResultSuccess();
} }
@ -428,8 +420,7 @@ namespace ams::ncm {
R_TRY(this->GetContentMetaDatabaseRoot(&root, storage_id)); R_TRY(this->GetContentMetaDatabaseRoot(&root, storage_id));
/* Delete save data for the content meta database root. */ /* Delete save data for the content meta database root. */
R_TRY(fs::DeleteSaveData(root->info.space_id, root->info.id)); return fs::DeleteSaveData(root->info.space_id, root->info.id);
return ResultSuccess();
} }
Result ContentManagerImpl::ActivateContentStorage(StorageId storage_id) { Result ContentManagerImpl::ActivateContentStorage(StorageId storage_id) {

View File

@ -249,6 +249,8 @@ namespace ams::ncm {
Result ContentMetaDatabaseImpl::GetRequiredSystemVersion(sf::Out<u32> out_version, const ContentMetaKey &key) { Result ContentMetaDatabaseImpl::GetRequiredSystemVersion(sf::Out<u32> out_version, const ContentMetaKey &key) {
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
/* Only applications and patches have a required system version. */
R_UNLESS(key.type == ContentMetaType::Application || key.type == ContentMetaType::Patch, ncm::ResultInvalidContentMetaKey()); R_UNLESS(key.type == ContentMetaType::Application || key.type == ContentMetaType::Patch, ncm::ResultInvalidContentMetaKey());
/* Obtain the content meta for the key. */ /* Obtain the content meta for the key. */
@ -275,6 +277,8 @@ namespace ams::ncm {
Result ContentMetaDatabaseImpl::GetPatchId(sf::Out<PatchId> out_patch_id, const ContentMetaKey &key) { Result ContentMetaDatabaseImpl::GetPatchId(sf::Out<PatchId> out_patch_id, const ContentMetaKey &key) {
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
/* Only applications can have patches. */
R_UNLESS(key.type == ContentMetaType::Application, ncm::ResultInvalidContentMetaKey()); R_UNLESS(key.type == ContentMetaType::Application, ncm::ResultInvalidContentMetaKey());
/* Obtain the content meta for the key. */ /* Obtain the content meta for the key. */
@ -378,6 +382,7 @@ namespace ams::ncm {
out_meta_info[count] = *reader.GetContentMetaInfo(count + offset); out_meta_info[count] = *reader.GetContentMetaInfo(count + offset);
} }
/* Set the ouput value. */
out_entries_written.SetValue(count); out_entries_written.SetValue(count);
return ResultSuccess(); return ResultSuccess();
} }
@ -393,6 +398,7 @@ namespace ams::ncm {
/* Create a reader. */ /* Create a reader. */
ContentMetaReader reader(meta, meta_size); ContentMetaReader reader(meta, meta_size);
/* Set the ouput value. */
out_attributes.SetValue(reader.GetHeader()->attributes); out_attributes.SetValue(reader.GetHeader()->attributes);
return ResultSuccess(); return ResultSuccess();
} }
@ -422,6 +428,7 @@ namespace ams::ncm {
AMS_UNREACHABLE_DEFAULT_CASE(); AMS_UNREACHABLE_DEFAULT_CASE();
} }
/* Set the ouput value. */
out_version.SetValue(required_version); out_version.SetValue(required_version);
return ResultSuccess(); return ResultSuccess();
} }

View File

@ -176,9 +176,7 @@ namespace ams::ncm {
/* Create the placeholder directory. */ /* Create the placeholder directory. */
PlaceHolderAccessor::MakeBaseDirectoryPath(std::addressof(path), root_path); PlaceHolderAccessor::MakeBaseDirectoryPath(std::addressof(path), root_path);
R_TRY(impl::EnsureDirectoryRecursively(path)); return impl::EnsureDirectoryRecursively(path);
return ResultSuccess();
} }
Result ContentStorageImpl::CleanupBase(const char *root_path) { Result ContentStorageImpl::CleanupBase(const char *root_path) {
@ -190,9 +188,7 @@ namespace ams::ncm {
/* Create the placeholder directory. */ /* Create the placeholder directory. */
PlaceHolderAccessor::MakeBaseDirectoryPath(std::addressof(path), root_path); PlaceHolderAccessor::MakeBaseDirectoryPath(std::addressof(path), root_path);
R_TRY(CleanDirectoryRecursively(path)); return CleanDirectoryRecursively(path);
return ResultSuccess();
} }
Result ContentStorageImpl::VerifyBase(const char *root_path) { Result ContentStorageImpl::VerifyBase(const char *root_path) {
@ -259,7 +255,6 @@ namespace ams::ncm {
this->make_content_path_func = content_path_func; this->make_content_path_func = content_path_func;
this->placeholder_accessor.Initialize(std::addressof(this->root_path), placeholder_path_func, delay_flush); this->placeholder_accessor.Initialize(std::addressof(this->root_path), placeholder_path_func, delay_flush);
this->rights_id_cache = rights_id_cache; this->rights_id_cache = rights_id_cache;
return ResultSuccess(); return ResultSuccess();
} }
@ -271,11 +266,8 @@ namespace ams::ncm {
Result ContentStorageImpl::CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, s64 size) { Result ContentStorageImpl::CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, s64 size) {
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
R_TRY(EnsureContentDirectory(content_id, this->make_content_path_func, this->root_path)); R_TRY(EnsureContentDirectory(content_id, this->make_content_path_func, this->root_path));
R_TRY(this->placeholder_accessor.CreatePlaceHolderFile(placeholder_id, size)); return this->placeholder_accessor.CreatePlaceHolderFile(placeholder_id, size);
return ResultSuccess();
} }
Result ContentStorageImpl::DeletePlaceHolder(PlaceHolderId placeholder_id) { Result ContentStorageImpl::DeletePlaceHolder(PlaceHolderId placeholder_id) {
@ -294,7 +286,6 @@ namespace ams::ncm {
bool has = false; bool has = false;
R_TRY(impl::HasFile(&has, placeholder_path)); R_TRY(impl::HasFile(&has, placeholder_path));
out.SetValue(has); out.SetValue(has);
return ResultSuccess(); return ResultSuccess();
} }
@ -343,7 +334,6 @@ namespace ams::ncm {
bool has = false; bool has = false;
R_TRY(impl::HasFile(&has, content_path)); R_TRY(impl::HasFile(&has, content_path));
out.SetValue(has); out.SetValue(has);
return ResultSuccess(); return ResultSuccess();
} }
@ -649,23 +639,15 @@ namespace ams::ncm {
ON_SCOPE_EXIT { fs::CloseFile(file); }; ON_SCOPE_EXIT { fs::CloseFile(file); };
/* Write the provided data to the file. */ /* Write the provided data to the file. */
R_TRY(fs::WriteFile(file, offset, data.GetPointer(), data.GetSize(), fs::WriteOption::Flush)); return fs::WriteFile(file, offset, data.GetPointer(), data.GetSize(), fs::WriteOption::Flush);
return ResultSuccess();
} }
Result ContentStorageImpl::GetFreeSpaceSize(sf::Out<s64> out_size) { Result ContentStorageImpl::GetFreeSpaceSize(sf::Out<s64> out_size) {
s64 size; return fs::GetFreeSpaceSize(out_size.GetPointer(), this->root_path);
R_TRY(fs::GetFreeSpaceSize(std::addressof(size), this->root_path));
out_size.SetValue(size);
return ResultSuccess();
} }
Result ContentStorageImpl::GetTotalSpaceSize(sf::Out<s64> out_size) { Result ContentStorageImpl::GetTotalSpaceSize(sf::Out<s64> out_size) {
s64 size; return fs::GetTotalSpaceSize(out_size.GetPointer(), this->root_path);
R_TRY(fs::GetTotalSpaceSize(std::addressof(size), this->root_path));
out_size.SetValue(size);
return ResultSuccess();
} }
Result ContentStorageImpl::FlushPlaceHolder() { Result ContentStorageImpl::FlushPlaceHolder() {

View File

@ -97,7 +97,7 @@ namespace ams::ncm {
bool PlaceHolderAccessor::LoadFromCache(fs::FileHandle *out_handle, PlaceHolderId placeholder_id) { bool PlaceHolderAccessor::LoadFromCache(fs::FileHandle *out_handle, PlaceHolderId placeholder_id) {
std::scoped_lock lk(this->cache_mutex); std::scoped_lock lk(this->cache_mutex);
/* attempt to find an entry in the cache. */ /* Attempt to find an entry in the cache. */
CacheEntry *entry = this->FindInCache(placeholder_id); CacheEntry *entry = this->FindInCache(placeholder_id);
if (!entry) { if (!entry) {
return false; return false;

View File

@ -42,15 +42,15 @@ namespace ams::ncm {
R_DEFINE_ERROR_RANGE(ContentStorageNotActive, 250, 258); R_DEFINE_ERROR_RANGE(ContentStorageNotActive, 250, 258);
R_DEFINE_ERROR_RESULT(GameCardContentStorageNotActive, 251); R_DEFINE_ERROR_RESULT(GameCardContentStorageNotActive, 251);
R_DEFINE_ERROR_RESULT(NandSystemContentStorageNotActive, 252); R_DEFINE_ERROR_RESULT(BuiltInSystemContentStorageNotActive, 252);
R_DEFINE_ERROR_RESULT(NandUserContentStorageNotActive, 253); R_DEFINE_ERROR_RESULT(BuiltInUserContentStorageNotActive, 253);
R_DEFINE_ERROR_RESULT(SdCardContentStorageNotActive, 254); R_DEFINE_ERROR_RESULT(SdCardContentStorageNotActive, 254);
R_DEFINE_ERROR_RESULT(UnknownContentStorageNotActive, 258); R_DEFINE_ERROR_RESULT(UnknownContentStorageNotActive, 258);
R_DEFINE_ERROR_RANGE(ContentMetaDatabaseNotActive, 260, 268); R_DEFINE_ERROR_RANGE(ContentMetaDatabaseNotActive, 260, 268);
R_DEFINE_ERROR_RESULT(GameCardContentMetaDatabaseNotActive, 261); R_DEFINE_ERROR_RESULT(GameCardContentMetaDatabaseNotActive, 261);
R_DEFINE_ERROR_RESULT(NandSystemContentMetaDatabaseNotActive, 262); R_DEFINE_ERROR_RESULT(BuiltInSystemContentMetaDatabaseNotActive, 262);
R_DEFINE_ERROR_RESULT(NandUserContentMetaDatabaseNotActive, 263); R_DEFINE_ERROR_RESULT(BuiltInUserContentMetaDatabaseNotActive, 263);
R_DEFINE_ERROR_RESULT(SdCardContentMetaDatabaseNotActive, 264); R_DEFINE_ERROR_RESULT(SdCardContentMetaDatabaseNotActive, 264);
R_DEFINE_ERROR_RESULT(UnknownContentMetaDatabaseNotActive, 268); R_DEFINE_ERROR_RESULT(UnknownContentMetaDatabaseNotActive, 268);