mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-04-22 20:44:49 +00:00
ncm: Misc cleanup
This commit is contained in:
parent
4310a0018c
commit
fec5432c4b
9 changed files with 83 additions and 80 deletions
|
@ -17,10 +17,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
#include "../lr/lr_types.hpp"
|
||||
#include "../util/util_uuid.hpp"
|
||||
|
||||
namespace sts::ncm {
|
||||
|
||||
using Path = lr::Path;
|
||||
|
||||
/* Storage IDs. */
|
||||
enum class StorageId : u8 {
|
||||
None = 0,
|
||||
|
|
|
@ -349,7 +349,7 @@ namespace sts::updater {
|
|||
void *work = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(work_buffer) + BctSize);
|
||||
|
||||
size_t size;
|
||||
R_TRY(ReadFile(&size, bct, BctSize, GetBctPath(boot_image_update_type)));
|
||||
R_TRY(fs::ReadFile(&size, bct, BctSize, GetBctPath(boot_image_update_type)));
|
||||
if (HasEks(boot_image_update_type)) {
|
||||
R_TRY(boot0_accessor.UpdateEks(bct, work));
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ namespace sts::updater {
|
|||
void *work = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(work_buffer) + BctSize);
|
||||
|
||||
size_t size;
|
||||
R_TRY(ReadFile(&size, bct, BctSize, GetBctPath(boot_image_update_type)));
|
||||
R_TRY(fs::ReadFile(&size, bct, BctSize, GetBctPath(boot_image_update_type)));
|
||||
if (HasEks(boot_image_update_type)) {
|
||||
R_TRY(boot0_accessor.UpdateEks(bct, work));
|
||||
}
|
||||
|
@ -465,7 +465,7 @@ namespace sts::updater {
|
|||
void *work = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(work_buffer) + BctSize);
|
||||
|
||||
size_t size;
|
||||
R_TRY(ReadFile(&size, bct, BctSize, GetBctPath(boot_image_update_type)));
|
||||
R_TRY(fs::ReadFile(&size, bct, BctSize, GetBctPath(boot_image_update_type)));
|
||||
if (HasEks(boot_image_update_type)) {
|
||||
R_TRY(accessor.UpdateEks(bct, work));
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace sts::ncm::impl {
|
|||
this->storage_id = storage_id;
|
||||
this->content_storage_id = content_storage_id;
|
||||
this->content_storage = nullptr;
|
||||
MountName mount_name = CreateUniqueMountName();
|
||||
MountName mount_name = fs::CreateUniqueMountName();
|
||||
strcpy(this->mount_point, mount_name.name);
|
||||
snprintf(this->root_path, 0x80, "%s:/", this->mount_point);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ namespace sts::ncm::impl {
|
|||
this->save_meta = save_meta;
|
||||
this->content_meta_database = nullptr;
|
||||
this->kvs.reset();
|
||||
MountName mount_name = CreateUniqueMountName();
|
||||
MountName mount_name = fs::CreateUniqueMountName();
|
||||
strcpy(this->mount_point, mount_name.name);
|
||||
this->mount_point[0] = '#';
|
||||
snprintf(this->meta_path, 0x80, "%s:/meta", this->mount_point);
|
||||
|
@ -195,8 +195,8 @@ namespace sts::ncm::impl {
|
|||
}
|
||||
|
||||
u32 current_flags = 0;
|
||||
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_200 && R_SUCCEEDED(GetSaveDataFlags(¤t_flags, 0x8000000000000120)) && current_flags != (FsSaveDataFlags_SurviveFactoryReset | FsSaveDataFlags_SurviveFactoryResetForRefurbishment)) {
|
||||
SetSaveDataFlags(0x8000000000000120, FsSaveDataSpaceId_NandSystem, FsSaveDataFlags_SurviveFactoryReset | FsSaveDataFlags_SurviveFactoryResetForRefurbishment);
|
||||
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_200 && R_SUCCEEDED(fs::GetSaveDataFlags(¤t_flags, 0x8000000000000120)) && current_flags != (FsSaveDataFlags_SurviveFactoryReset | FsSaveDataFlags_SurviveFactoryResetForRefurbishment)) {
|
||||
fs::SetSaveDataFlags(0x8000000000000120, FsSaveDataSpaceId_NandSystem, FsSaveDataFlags_SurviveFactoryReset | FsSaveDataFlags_SurviveFactoryResetForRefurbishment);
|
||||
}
|
||||
|
||||
R_TRY(ActivateContentMetaDatabase(StorageId::NandSystem));
|
||||
|
@ -291,14 +291,14 @@ namespace sts::ncm::impl {
|
|||
return ResultNcmUnknownStorage;
|
||||
}
|
||||
|
||||
R_TRY(MountContentStorage(entry->mount_point, entry->content_storage_id));
|
||||
R_TRY(fs::MountContentStorage(entry->mount_point, entry->content_storage_id));
|
||||
|
||||
ON_SCOPE_EXIT {
|
||||
Unmount(entry->mount_point);
|
||||
fs::Unmount(entry->mount_point);
|
||||
};
|
||||
|
||||
R_TRY(EnsureDirectoryRecursively(entry->root_path));
|
||||
R_TRY(EnsureContentAndPlaceHolderRoot(entry->root_path));
|
||||
R_TRY(fs::EnsureDirectoryRecursively(entry->root_path));
|
||||
R_TRY(fs::EnsureContentAndPlaceHolderRoot(entry->root_path));
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
@ -316,17 +316,17 @@ namespace sts::ncm::impl {
|
|||
return ResultNcmUnknownStorage;
|
||||
}
|
||||
|
||||
MountName mount_name = CreateUniqueMountName();
|
||||
MountName mount_name = fs::CreateUniqueMountName();
|
||||
char mount_root[128] = {0};
|
||||
strcpy(mount_root, mount_name.name);
|
||||
strcat(mount_root, strchr(entry->root_path, ':'));
|
||||
R_TRY(MountContentStorage(mount_name.name, entry->content_storage_id));
|
||||
R_TRY(fs::MountContentStorage(mount_name.name, entry->content_storage_id));
|
||||
|
||||
ON_SCOPE_EXIT {
|
||||
Unmount(mount_name.name);
|
||||
fs::Unmount(mount_name.name);
|
||||
};
|
||||
|
||||
R_TRY(CheckContentStorageDirectoriesExist(mount_root));
|
||||
R_TRY(fs::CheckContentStorageDirectoriesExist(mount_root));
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
@ -394,7 +394,7 @@ namespace sts::ncm::impl {
|
|||
|
||||
/* N doesn't bother checking the result of this */
|
||||
entry->content_storage->DisableForcibly();
|
||||
Unmount(entry->mount_point);
|
||||
fs::Unmount(entry->mount_point);
|
||||
entry->content_storage = nullptr;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
@ -419,17 +419,17 @@ namespace sts::ncm::impl {
|
|||
|
||||
if (storage_id == StorageId::GameCard) {
|
||||
FsGameCardHandle gc_hnd;
|
||||
R_TRY(GetGameCardHandle(&gc_hnd));
|
||||
R_TRY(MountGameCardPartition(entry->mount_point, gc_hnd, FsGameCardPartiton_Secure));
|
||||
auto mount_guard = SCOPE_GUARD { Unmount(entry->mount_point); };
|
||||
R_TRY(fs::GetGameCardHandle(&gc_hnd));
|
||||
R_TRY(fs::MountGameCardPartition(entry->mount_point, gc_hnd, FsGameCardPartiton_Secure));
|
||||
auto mount_guard = SCOPE_GUARD { fs::Unmount(entry->mount_point); };
|
||||
auto content_storage = std::make_shared<ReadOnlyContentStorageInterface>();
|
||||
|
||||
R_TRY(content_storage->Initialize(entry->root_path, path::MakeContentPathFlat));
|
||||
entry->content_storage = std::move(content_storage);
|
||||
mount_guard.Cancel();
|
||||
} else {
|
||||
R_TRY(MountContentStorage(entry->mount_point, entry->content_storage_id));
|
||||
auto mount_guard = SCOPE_GUARD { Unmount(entry->mount_point); };
|
||||
R_TRY(fs::MountContentStorage(entry->mount_point, entry->content_storage_id));
|
||||
auto mount_guard = SCOPE_GUARD { fs::Unmount(entry->mount_point); };
|
||||
MakeContentPathFunc content_path_func = nullptr;
|
||||
MakePlaceHolderPathFunc placeholder_path_func = nullptr;
|
||||
bool delay_flush = false;
|
||||
|
@ -477,7 +477,7 @@ namespace sts::ncm::impl {
|
|||
|
||||
entry->content_storage->DisableForcibly();
|
||||
entry->content_storage = nullptr;
|
||||
Unmount(entry->mount_point);
|
||||
fs::Unmount(entry->mount_point);
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
|
@ -497,18 +497,18 @@ namespace sts::ncm::impl {
|
|||
/* N doesn't bother checking the result of this. */
|
||||
fsDisableAutoSaveDataCreation();
|
||||
|
||||
R_TRY_CATCH(MountSystemSaveData(entry->mount_point, entry->save_meta.space_id, entry->save_meta.id)) {
|
||||
R_TRY_CATCH(fs::MountSystemSaveData(entry->mount_point, entry->save_meta.space_id, entry->save_meta.id)) {
|
||||
R_CATCH(ResultFsTargetNotFound) {
|
||||
R_TRY(fsCreate_SystemSaveData(entry->save_meta.space_id, entry->save_meta.id, entry->save_meta.size, entry->save_meta.journal_size, entry->save_meta.flags));
|
||||
R_TRY(MountSystemSaveData(entry->mount_point, entry->save_meta.space_id, entry->save_meta.id));
|
||||
R_TRY(fs::MountSystemSaveData(entry->mount_point, entry->save_meta.space_id, entry->save_meta.id));
|
||||
}
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
ON_SCOPE_EXIT {
|
||||
Unmount(entry->mount_point);
|
||||
fs::Unmount(entry->mount_point);
|
||||
};
|
||||
|
||||
R_TRY(EnsureDirectoryRecursively(entry->meta_path));
|
||||
R_TRY(fs::EnsureDirectoryRecursively(entry->meta_path));
|
||||
R_TRY(fsdevCommitDevice(entry->mount_point));
|
||||
|
||||
return ResultSuccess;
|
||||
|
@ -534,18 +534,18 @@ namespace sts::ncm::impl {
|
|||
bool mounted_save_data = false;
|
||||
|
||||
if (!entry->content_meta_database) {
|
||||
R_TRY(MountSystemSaveData(entry->mount_point, entry->save_meta.space_id, entry->save_meta.id));
|
||||
R_TRY(fs::MountSystemSaveData(entry->mount_point, entry->save_meta.space_id, entry->save_meta.id));
|
||||
mounted_save_data = true;
|
||||
}
|
||||
|
||||
ON_SCOPE_EXIT {
|
||||
if (mounted_save_data) {
|
||||
Unmount(entry->mount_point);
|
||||
fs::Unmount(entry->mount_point);
|
||||
}
|
||||
};
|
||||
|
||||
bool has_meta_path = false;
|
||||
R_TRY(HasDirectory(&has_meta_path, entry->meta_path));
|
||||
R_TRY(fs::HasDirectory(&has_meta_path, entry->meta_path));
|
||||
if (!has_meta_path) {
|
||||
return ResultNcmInvalidContentMetaDatabase;
|
||||
}
|
||||
|
@ -620,7 +620,7 @@ namespace sts::ncm::impl {
|
|||
content_meta_db->DisableForcibly();
|
||||
|
||||
if (storage_id != StorageId::GameCard) {
|
||||
Unmount(entry->mount_point);
|
||||
fs::Unmount(entry->mount_point);
|
||||
}
|
||||
|
||||
entry->content_meta_database = nullptr;
|
||||
|
@ -663,8 +663,8 @@ namespace sts::ncm::impl {
|
|||
entry->kvs.emplace();
|
||||
|
||||
if (storage_id != StorageId::GameCard) {
|
||||
R_TRY(MountSystemSaveData(entry->mount_point, entry->save_meta.space_id, entry->save_meta.id));
|
||||
auto mount_guard = SCOPE_GUARD { Unmount(entry->mount_point); };
|
||||
R_TRY(fs::MountSystemSaveData(entry->mount_point, entry->save_meta.space_id, entry->save_meta.id));
|
||||
auto mount_guard = SCOPE_GUARD { fs::Unmount(entry->mount_point); };
|
||||
R_TRY(entry->kvs->Initialize(entry->meta_path, entry->max_content_metas));
|
||||
R_TRY(entry->kvs->Load());
|
||||
|
||||
|
@ -701,7 +701,7 @@ namespace sts::ncm::impl {
|
|||
entry->kvs.reset();
|
||||
|
||||
if (storage_id != StorageId::GameCard) {
|
||||
Unmount(entry->mount_point);
|
||||
fs::Unmount(entry->mount_point);
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace sts::ncm::impl {
|
|||
this->MakePath(placeholder_path, placeholder_id);
|
||||
|
||||
FILE* f = nullptr;
|
||||
R_TRY(OpenFile(&f, placeholder_path, FS_OPEN_WRITE));
|
||||
R_TRY(fs::OpenFile(&f, placeholder_path, FS_OPEN_WRITE));
|
||||
|
||||
*out_handle = f;
|
||||
return ResultSuccess;
|
||||
|
@ -164,7 +164,7 @@ namespace sts::ncm::impl {
|
|||
this->StoreToCache(f, placeholder_id);
|
||||
};
|
||||
|
||||
R_TRY(WriteFile(f, offset, buffer, size, !this->delay_flush));
|
||||
R_TRY(fs::WriteFile(f, offset, buffer, size, !this->delay_flush));
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ namespace sts::ncm::impl {
|
|||
Result PlaceHolderAccessor::EnsureRecursively(PlaceHolderId placeholder_id) {
|
||||
char placeholder_path[FS_MAX_PATH] = {0};
|
||||
this->MakePath(placeholder_path, placeholder_id);
|
||||
R_TRY(EnsureParentDirectoryRecursively(placeholder_path));
|
||||
R_TRY(fs::EnsureParentDirectoryRecursively(placeholder_path));
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,15 +21,15 @@ namespace sts::ncm {
|
|||
|
||||
namespace {
|
||||
|
||||
struct InstallContentMetaHeader {
|
||||
struct ContentMetaHeader {
|
||||
u16 extended_header_size;
|
||||
u16 content_count;
|
||||
u16 content_meta_count;
|
||||
ContentMetaAttribute attributes;
|
||||
u8 padding;
|
||||
StorageId storage_id;
|
||||
};
|
||||
|
||||
static_assert(sizeof(InstallContentMetaHeader) == 0x8, "InstallContentMetaHeader definition!");
|
||||
static_assert(sizeof(ContentMetaHeader) == 0x8, "ContentMetaHeader definition!");
|
||||
|
||||
struct ApplicationMetaExtendedHeader {
|
||||
TitleId patch_id;
|
||||
|
@ -54,17 +54,17 @@ namespace sts::ncm {
|
|||
u32 extended_data_size;
|
||||
};
|
||||
|
||||
inline const InstallContentMetaHeader* GetValueHeader(const void* value) {
|
||||
return reinterpret_cast<const InstallContentMetaHeader*>(value);
|
||||
inline const ContentMetaHeader* GetValueHeader(const void* value) {
|
||||
return reinterpret_cast<const ContentMetaHeader*>(value);
|
||||
}
|
||||
|
||||
template<typename ExtendedHeaderType>
|
||||
inline const ExtendedHeaderType* GetValueExtendedHeader(const void* value) {
|
||||
return reinterpret_cast<const ExtendedHeaderType*>(reinterpret_cast<const u8*>(value) + sizeof(InstallContentMetaHeader));
|
||||
return reinterpret_cast<const ExtendedHeaderType*>(reinterpret_cast<const u8*>(value) + sizeof(ContentMetaHeader));
|
||||
}
|
||||
|
||||
inline const ContentInfo* GetValueContentInfos(const void* value) {
|
||||
return reinterpret_cast<const ContentInfo*>(reinterpret_cast<const u8*>(value) + sizeof(InstallContentMetaHeader) + GetValueHeader(value)->extended_header_size);
|
||||
return reinterpret_cast<const ContentInfo*>(reinterpret_cast<const u8*>(value) + sizeof(ContentMetaHeader) + GetValueHeader(value)->extended_header_size);
|
||||
}
|
||||
|
||||
inline const ContentMetaInfo* GetValueContentMetaInfos(const void* value) {
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace sts::ncm {
|
|||
|
||||
Result ContentStorageInterface::Initialize(const char* root_path, MakeContentPathFunc content_path_func, MakePlaceHolderPathFunc placeholder_path_func, bool delay_flush) {
|
||||
R_TRY(this->EnsureEnabled());
|
||||
R_TRY(CheckContentStorageDirectoriesExist(root_path));
|
||||
R_TRY(fs::CheckContentStorageDirectoriesExist(root_path));
|
||||
const size_t root_path_len = strnlen(root_path, FS_MAX_PATH-1);
|
||||
|
||||
if (root_path_len >= FS_MAX_PATH-1) {
|
||||
|
@ -76,7 +76,7 @@ namespace sts::ncm {
|
|||
char content_path[FS_MAX_PATH] = {0};
|
||||
this->GetContentPath(content_path, content_id);
|
||||
|
||||
R_TRY_CATCH(OpenFile(&this->content_cache_file_handle, content_path, FS_OPEN_READ)) {
|
||||
R_TRY_CATCH(fs::OpenFile(&this->content_cache_file_handle, content_path, FS_OPEN_READ)) {
|
||||
R_CATCH(ResultFsPathNotFound) {
|
||||
return ResultNcmContentNotFound;
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ namespace sts::ncm {
|
|||
char content_path[FS_MAX_PATH] = {0};
|
||||
this->GetContentPath(content_path, content_id);
|
||||
|
||||
R_TRY(EnsureParentDirectoryRecursively(content_path));
|
||||
R_TRY(fs::EnsureParentDirectoryRecursively(content_path));
|
||||
R_TRY(this->placeholder_accessor.Create(placeholder_id, size));
|
||||
|
||||
return ResultSuccess;
|
||||
|
@ -119,7 +119,7 @@ namespace sts::ncm {
|
|||
this->placeholder_accessor.MakePath(placeholder_path, placeholder_id);
|
||||
|
||||
bool has = false;
|
||||
R_TRY(HasFile(&has, placeholder_path));
|
||||
R_TRY(fs::HasFile(&has, placeholder_path));
|
||||
out.SetValue(has);
|
||||
|
||||
return ResultSuccess;
|
||||
|
@ -185,7 +185,7 @@ namespace sts::ncm {
|
|||
this->GetContentPath(content_path, content_id);
|
||||
|
||||
bool has = false;
|
||||
R_TRY(HasFile(&has, content_path));
|
||||
R_TRY(fs::HasFile(&has, content_path));
|
||||
out.SetValue(has);
|
||||
|
||||
return ResultSuccess;
|
||||
|
@ -197,7 +197,7 @@ namespace sts::ncm {
|
|||
char content_path[FS_MAX_PATH] = {0};
|
||||
char common_path[FS_MAX_PATH] = {0};
|
||||
this->GetContentPath(content_path, content_id);
|
||||
R_TRY(ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, content_path));
|
||||
R_TRY(fs::ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, content_path));
|
||||
*out.pointer = common_path;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ namespace sts::ncm {
|
|||
char placeholder_path[FS_MAX_PATH] = {0};
|
||||
char common_path[FS_MAX_PATH] = {0};
|
||||
this->placeholder_accessor.GetPath(placeholder_path, placeholder_id);
|
||||
R_TRY(ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, placeholder_path));
|
||||
R_TRY(fs::ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, placeholder_path));
|
||||
*out.pointer = common_path;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ namespace sts::ncm {
|
|||
const unsigned int dir_depth = this->placeholder_accessor.GetDirectoryDepth();
|
||||
size_t entry_count = 0;
|
||||
|
||||
R_TRY(TraverseDirectory(placeholder_root_path, dir_depth, [&](bool* should_continue, bool* should_retry_dir_read, const char* current_path, struct dirent* dir_entry) {
|
||||
R_TRY(fs::TraverseDirectory(placeholder_root_path, dir_depth, [&](bool* should_continue, bool* should_retry_dir_read, const char* current_path, struct dirent* dir_entry) {
|
||||
*should_continue = true;
|
||||
*should_retry_dir_read = false;
|
||||
|
||||
|
@ -268,7 +268,7 @@ namespace sts::ncm {
|
|||
const unsigned int dir_depth = this->GetContentDirectoryDepth();
|
||||
u32 content_count = 0;
|
||||
|
||||
R_TRY(TraverseDirectory(content_root_path, dir_depth, [&](bool* should_continue, bool* should_retry_dir_read, const char* current_path, struct dirent* dir_entry) {
|
||||
R_TRY(fs::TraverseDirectory(content_root_path, dir_depth, [&](bool* should_continue, bool* should_retry_dir_read, const char* current_path, struct dirent* dir_entry) {
|
||||
*should_continue = true;
|
||||
*should_retry_dir_read = false;
|
||||
|
||||
|
@ -295,7 +295,7 @@ namespace sts::ncm {
|
|||
const unsigned int dir_depth = this->GetContentDirectoryDepth();
|
||||
size_t entry_count = 0;
|
||||
|
||||
R_TRY(TraverseDirectory(content_root_path, dir_depth, [&](bool* should_continue, bool* should_retry_dir_read, const char* current_path, struct dirent* dir_entry) {
|
||||
R_TRY(fs::TraverseDirectory(content_root_path, dir_depth, [&](bool* should_continue, bool* should_retry_dir_read, const char* current_path, struct dirent* dir_entry) {
|
||||
*should_retry_dir_read = false;
|
||||
*should_continue = true;
|
||||
|
||||
|
@ -368,7 +368,7 @@ namespace sts::ncm {
|
|||
|
||||
/* Ensure the new content path is ready. */
|
||||
this->GetContentPath(new_content_path, new_content_id);
|
||||
R_TRY(EnsureParentDirectoryRecursively(new_content_path));
|
||||
R_TRY(fs::EnsureParentDirectoryRecursively(new_content_path));
|
||||
|
||||
R_TRY(this->placeholder_accessor.EnsureRecursively(placeholder_id));
|
||||
this->placeholder_accessor.GetPath(placeholder_path, placeholder_id);
|
||||
|
@ -402,7 +402,7 @@ namespace sts::ncm {
|
|||
char content_path[FS_MAX_PATH] = {0};
|
||||
this->GetContentPath(content_path, content_id);
|
||||
R_TRY(this->OpenCachedContentFile(content_id));
|
||||
R_TRY(ReadFile(this->content_cache_file_handle, offset, buf.buffer, buf.num_elements));
|
||||
R_TRY(fs::ReadFile(this->content_cache_file_handle, offset, buf.buffer, buf.num_elements));
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
@ -416,7 +416,7 @@ namespace sts::ncm {
|
|||
char placeholder_path[FS_MAX_PATH] = {0};
|
||||
char common_path[FS_MAX_PATH] = {0};
|
||||
this->placeholder_accessor.GetPath(placeholder_path, placeholder_id);
|
||||
R_TRY(ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, placeholder_path));
|
||||
R_TRY(fs::ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, placeholder_path));
|
||||
R_TRY(fsGetRightsIdAndKeyGenerationByPath(common_path, &key_generation, &rights_id));
|
||||
|
||||
out_rights_id.SetValue(rights_id);
|
||||
|
@ -452,7 +452,7 @@ namespace sts::ncm {
|
|||
char content_path[FS_MAX_PATH] = {0};
|
||||
char common_path[FS_MAX_PATH] = {0};
|
||||
this->GetContentPath(content_path, content_id);
|
||||
R_TRY(ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, content_path));
|
||||
R_TRY(fs::ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, content_path));
|
||||
R_TRY(fsGetRightsIdAndKeyGenerationByPath(common_path, &key_generation, &rights_id));
|
||||
|
||||
{
|
||||
|
@ -504,13 +504,13 @@ namespace sts::ncm {
|
|||
this->GetContentPath(content_path, content_id);
|
||||
|
||||
FILE* f = nullptr;
|
||||
R_TRY(OpenFile(&f, content_path, FS_OPEN_WRITE));
|
||||
R_TRY(fs::OpenFile(&f, content_path, FS_OPEN_WRITE));
|
||||
|
||||
ON_SCOPE_EXIT {
|
||||
fclose(f);
|
||||
};
|
||||
|
||||
R_TRY(WriteFile(f, offset, data.buffer, data.num_elements, FS_WRITEOPTION_FLUSH));
|
||||
R_TRY(fs::WriteFile(f, offset, data.buffer, data.num_elements, FS_WRITEOPTION_FLUSH));
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
@ -584,14 +584,14 @@ namespace sts::ncm {
|
|||
return ResultSuccess;
|
||||
};
|
||||
|
||||
R_TRY(TraverseDirectory(content_root_path, dir_depth, fix_file_attributes));
|
||||
R_TRY(fs::TraverseDirectory(content_root_path, dir_depth, fix_file_attributes));
|
||||
|
||||
char placeholder_root_path[FS_MAX_PATH] = {0};
|
||||
this->placeholder_accessor.InvalidateAll();
|
||||
this->placeholder_accessor.MakeRootPath(placeholder_root_path);
|
||||
dir_depth = this->placeholder_accessor.GetDirectoryDepth();
|
||||
|
||||
R_TRY(TraverseDirectory(placeholder_root_path, dir_depth, fix_file_attributes));
|
||||
R_TRY(fs::TraverseDirectory(placeholder_root_path, dir_depth, fix_file_attributes));
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
@ -623,7 +623,7 @@ namespace sts::ncm {
|
|||
char placeholder_path[FS_MAX_PATH] = {0};
|
||||
char common_path[FS_MAX_PATH] = {0};
|
||||
this->placeholder_accessor.GetPath(placeholder_path, placeholder_id);
|
||||
R_TRY(ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, placeholder_path));
|
||||
R_TRY(fs::ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, placeholder_path));
|
||||
R_TRY(fsGetRightsIdAndKeyGenerationByPath(common_path, &key_generation, &rights_id));
|
||||
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "ncm_fs.hpp"
|
||||
#include "ncm_path_utils.hpp"
|
||||
|
||||
namespace sts::ncm {
|
||||
namespace sts::ncm::fs {
|
||||
|
||||
Result OpenFile(FILE** out, const char* path, u32 mode) {
|
||||
bool has = false;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <stratosphere.hpp>
|
||||
#include <sys/dirent.h>
|
||||
|
||||
namespace sts::ncm {
|
||||
namespace sts::ncm::fs {
|
||||
|
||||
Result OpenFile(FILE** out, const char* path, u32 mode);
|
||||
Result WriteFile(FILE* f, size_t offset, const void* buffer, size_t size, u32 option);
|
||||
|
@ -50,12 +50,6 @@ namespace sts::ncm {
|
|||
Result GetSaveDataFlags(u32* out_flags, u64 save_id);
|
||||
Result SetSaveDataFlags(u64 save_id, FsSaveDataSpaceId space_id, u32 flags);
|
||||
|
||||
template<typename F>
|
||||
Result TraverseDirectory(const char* root_path, int max_level, F f) {
|
||||
bool should_continue = false;
|
||||
return TraverseDirectory(&should_continue, root_path, max_level, f);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
Result TraverseDirectory(bool* out_should_continue, const char* root_path, int max_level, F f) {
|
||||
DIR *dir;
|
||||
|
@ -111,4 +105,10 @@ namespace sts::ncm {
|
|||
return ResultSuccess;
|
||||
};
|
||||
|
||||
template<typename F>
|
||||
Result TraverseDirectory(const char* root_path, int max_level, F f) {
|
||||
bool should_continue = false;
|
||||
return TraverseDirectory(&should_continue, root_path, max_level, f);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,11 +69,11 @@ namespace sts::ncm {
|
|||
this->make_content_path_func(content_path, content_id, this->root_path);
|
||||
|
||||
bool has = false;
|
||||
R_TRY(HasFile(&has, content_path));
|
||||
R_TRY(fs::HasFile(&has, content_path));
|
||||
|
||||
if (!has) {
|
||||
path::GetContentMetaPath(content_path, content_id, this->make_content_path_func, this->root_path);
|
||||
R_TRY(HasFile(&has, content_path));
|
||||
R_TRY(fs::HasFile(&has, content_path));
|
||||
}
|
||||
|
||||
out.SetValue(has);
|
||||
|
@ -88,13 +88,13 @@ namespace sts::ncm {
|
|||
bool is_content_meta_file = false;
|
||||
|
||||
path::GetContentMetaPath(content_path, content_id, this->make_content_path_func, this->root_path);
|
||||
R_TRY(HasFile(&is_content_meta_file, content_path));
|
||||
R_TRY(fs::HasFile(&is_content_meta_file, content_path));
|
||||
|
||||
if (!is_content_meta_file) {
|
||||
this->make_content_path_func(content_path, content_id, this->root_path);
|
||||
}
|
||||
|
||||
R_TRY(ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, content_path));
|
||||
R_TRY(fs::ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, content_path));
|
||||
*out.pointer = common_path;
|
||||
|
||||
return ResultSuccess;
|
||||
|
@ -127,7 +127,7 @@ namespace sts::ncm {
|
|||
bool is_content_file = false;
|
||||
|
||||
this->make_content_path_func(content_path, content_id, this->root_path);
|
||||
R_TRY(HasFile(&is_content_file, content_path));
|
||||
R_TRY(fs::HasFile(&is_content_file, content_path));
|
||||
|
||||
if (!is_content_file) {
|
||||
path::GetContentMetaPath(content_path, content_id, this->make_content_path_func, this->root_path);
|
||||
|
@ -167,20 +167,20 @@ namespace sts::ncm {
|
|||
bool is_content_file = false;
|
||||
|
||||
this->make_content_path_func(content_path, content_id, this->root_path);
|
||||
R_TRY(HasFile(&is_content_file, content_path));
|
||||
R_TRY(fs::HasFile(&is_content_file, content_path));
|
||||
|
||||
if (!is_content_file) {
|
||||
path::GetContentMetaPath(content_path, content_id, this->make_content_path_func, this->root_path);
|
||||
}
|
||||
|
||||
FILE* f = nullptr;
|
||||
R_TRY(OpenFile(&f, content_path, FS_OPEN_READ));
|
||||
R_TRY(fs::OpenFile(&f, content_path, FS_OPEN_READ));
|
||||
|
||||
ON_SCOPE_EXIT {
|
||||
fclose(f);
|
||||
};
|
||||
|
||||
R_TRY(ReadFile(f, offset, buf.buffer, buf.num_elements));
|
||||
R_TRY(fs::ReadFile(f, offset, buf.buffer, buf.num_elements));
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
@ -200,13 +200,13 @@ namespace sts::ncm {
|
|||
bool is_content_meta_file = false;
|
||||
|
||||
path::GetContentMetaPath(content_path, content_id, this->make_content_path_func, this->root_path);
|
||||
R_TRY(HasFile(&is_content_meta_file, content_path));
|
||||
R_TRY(fs::HasFile(&is_content_meta_file, content_path));
|
||||
|
||||
if (!is_content_meta_file) {
|
||||
this->make_content_path_func(content_path, content_id, this->root_path);
|
||||
}
|
||||
|
||||
R_TRY(ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, content_path));
|
||||
R_TRY(fs::ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, content_path));
|
||||
R_TRY(fsGetRightsIdAndKeyGenerationByPath(common_path, &key_generation, &rights_id));
|
||||
|
||||
out_rights_id.SetValue(rights_id);
|
||||
|
|
Loading…
Add table
Reference in a new issue