mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-02 23:59:49 -04:00
creport: use fs bindings
This commit is contained in:
parent
c703be86fc
commit
40c6733de3
24 changed files with 391 additions and 243 deletions
|
@ -260,7 +260,7 @@ namespace ams::ncm {
|
|||
ON_SCOPE_EXIT { fs::Unmount(root->mount_name); };
|
||||
|
||||
/* Ensure the path exists for us to import to. */
|
||||
R_TRY(impl::EnsureDirectoryRecursively(root->path));
|
||||
R_TRY(fs::EnsureDirectoryRecursively(root->path));
|
||||
|
||||
/* Copy the file from bis to our save. */
|
||||
R_TRY(impl::CopyFile(savedata_db_path, bis_db_path));
|
||||
|
@ -389,7 +389,7 @@ namespace ams::ncm {
|
|||
ON_SCOPE_EXIT { fs::Unmount(root->mount_name); };
|
||||
|
||||
/* Ensure the content storage root's path exists. */
|
||||
R_TRY(impl::EnsureDirectoryRecursively(root->path));
|
||||
R_TRY(fs::EnsureDirectoryRecursively(root->path));
|
||||
|
||||
/* Initialize content and placeholder directories for the root. */
|
||||
return ContentStorageImpl::InitializeBase(root->path);
|
||||
|
@ -409,7 +409,7 @@ namespace ams::ncm {
|
|||
ON_SCOPE_EXIT { fs::Unmount(root->mount_name); };
|
||||
|
||||
/* Ensure the content meta database root's path exists. */
|
||||
R_TRY(impl::EnsureDirectoryRecursively(root->path));
|
||||
R_TRY(fs::EnsureDirectoryRecursively(root->path));
|
||||
|
||||
/* Commit our changes. */
|
||||
return fs::CommitSaveData(root->mount_name);
|
||||
|
@ -454,7 +454,7 @@ namespace ams::ncm {
|
|||
|
||||
/* Ensure the root path exists. */
|
||||
bool has_dir = false;
|
||||
R_TRY(impl::HasDirectory(&has_dir, root->path));
|
||||
R_TRY(fs::HasDirectory(&has_dir, root->path));
|
||||
R_UNLESS(has_dir, ncm::ResultInvalidContentMetaDatabase());
|
||||
|
||||
return ResultSuccess();
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace ams::ncm {
|
|||
Result EnsureContentDirectory(ContentId id, MakeContentPathFunction func, const char *root_path) {
|
||||
PathString path;
|
||||
MakeContentPath(std::addressof(path), id, func, root_path);
|
||||
return impl::EnsureParentDirectoryRecursively(path);
|
||||
return fs::EnsureParentDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
Result DeleteContentFile(ContentId id, MakeContentPathFunction func, const char *root_path) {
|
||||
|
@ -175,11 +175,11 @@ namespace ams::ncm {
|
|||
|
||||
/* Create the content directory. */
|
||||
MakeBaseContentDirectoryPath(std::addressof(path), root_path);
|
||||
R_TRY(impl::EnsureDirectoryRecursively(path));
|
||||
R_TRY(fs::EnsureDirectoryRecursively(path));
|
||||
|
||||
/* Create the placeholder directory. */
|
||||
PlaceHolderAccessor::MakeBaseDirectoryPath(std::addressof(path), root_path);
|
||||
return impl::EnsureDirectoryRecursively(path);
|
||||
return fs::EnsureDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
Result ContentStorageImpl::CleanupBase(const char *root_path) {
|
||||
|
@ -199,18 +199,18 @@ namespace ams::ncm {
|
|||
|
||||
/* Check if root directory exists. */
|
||||
bool has_dir;
|
||||
R_TRY(impl::HasDirectory(std::addressof(has_dir), root_path));
|
||||
R_TRY(fs::HasDirectory(std::addressof(has_dir), root_path));
|
||||
R_UNLESS(has_dir, ncm::ResultContentStorageBaseNotFound());
|
||||
|
||||
/* Check if content directory exists. */
|
||||
bool has_registered;
|
||||
MakeBaseContentDirectoryPath(std::addressof(path), root_path);
|
||||
R_TRY(impl::HasDirectory(std::addressof(has_registered), path));
|
||||
R_TRY(fs::HasDirectory(std::addressof(has_registered), path));
|
||||
|
||||
/* Check if placeholder directory exists. */
|
||||
bool has_placeholder;
|
||||
PlaceHolderAccessor::MakeBaseDirectoryPath(std::addressof(path), root_path);
|
||||
R_TRY(impl::HasDirectory(std::addressof(has_placeholder), path));
|
||||
R_TRY(fs::HasDirectory(std::addressof(has_placeholder), path));
|
||||
|
||||
/* Convert findings to results. */
|
||||
R_UNLESS(has_registered || has_placeholder, ncm::ResultContentStorageBaseNotFound());
|
||||
|
@ -287,7 +287,7 @@ namespace ams::ncm {
|
|||
|
||||
/* Check if placeholder file exists. */
|
||||
bool has = false;
|
||||
R_TRY(impl::HasFile(&has, placeholder_path));
|
||||
R_TRY(fs::HasFile(&has, placeholder_path));
|
||||
out.SetValue(has);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
@ -335,7 +335,7 @@ namespace ams::ncm {
|
|||
|
||||
/* Check if the content file exists. */
|
||||
bool has = false;
|
||||
R_TRY(impl::HasFile(&has, content_path));
|
||||
R_TRY(fs::HasFile(&has, content_path));
|
||||
out.SetValue(has);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
|
|
@ -20,78 +20,10 @@ namespace ams::ncm::impl {
|
|||
|
||||
namespace {
|
||||
|
||||
Result EnsureDirectory(const char *path) {
|
||||
/* Create the path, and allow it to already exist. */
|
||||
R_TRY_CATCH(fs::CreateDirectory(path)) {
|
||||
R_CONVERT(fs::ResultPathAlreadyExists, ResultSuccess())
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result EnsureDirectoryRecursivelyImpl(const char *path, bool create_last) {
|
||||
char work_buf[fs::EntryNameLengthMax];
|
||||
|
||||
/* Ensure the path is not too long. */
|
||||
const size_t len = std::strlen(path);
|
||||
R_UNLESS(len + 1 <= sizeof(work_buf), ResultAllocationFailed());
|
||||
|
||||
/* Copy in the path. */
|
||||
std::strncpy(work_buf, path, sizeof(work_buf));
|
||||
|
||||
/* Create all but the last directory. */
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (i > 0 && fs::PathTool::IsSeparator(work_buf[i]) && !fs::PathTool::IsDriveSeparator(work_buf[i-1])) {
|
||||
work_buf[i] = fs::StringTraits::NullTerminator;
|
||||
R_TRY(EnsureDirectory(work_buf));
|
||||
work_buf[i] = fs::StringTraits::DirectorySeparator;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create the last directory if requested. */
|
||||
if (create_last) {
|
||||
R_TRY(EnsureDirectory(path));
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result HasEntry(bool *out, const char *path, fs::DirectoryEntryType type) {
|
||||
/* Set out to false initially. */
|
||||
*out = false;
|
||||
|
||||
/* Try to get the entry type. */
|
||||
fs::DirectoryEntryType entry_type;
|
||||
R_TRY_CATCH(fs::GetEntryType(std::addressof(entry_type), path)) {
|
||||
/* If the path doesn't exist, nothing has gone wrong. */
|
||||
R_CONVERT(fs::ResultPathNotFound, ResultSuccess());
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
/* We succeeded. */
|
||||
*out = entry_type == type;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
std::atomic<u32> g_mount_name_count;
|
||||
|
||||
}
|
||||
|
||||
Result HasFile(bool *out, const char *path) {
|
||||
return HasEntry(out, path, fs::DirectoryEntryType_File);
|
||||
}
|
||||
|
||||
Result HasDirectory(bool *out, const char *path) {
|
||||
return HasEntry(out, path, fs::DirectoryEntryType_Directory);
|
||||
}
|
||||
|
||||
Result EnsureDirectoryRecursively(const char *path) {
|
||||
return EnsureDirectoryRecursivelyImpl(path, true);
|
||||
}
|
||||
|
||||
Result EnsureParentDirectoryRecursively(const char *path) {
|
||||
return EnsureDirectoryRecursivelyImpl(path, false);
|
||||
}
|
||||
|
||||
bool PathView::HasPrefix(std::string_view prefix) const {
|
||||
return this->path.compare(0, prefix.length(), prefix) == 0;
|
||||
}
|
||||
|
|
|
@ -18,12 +18,6 @@
|
|||
|
||||
namespace ams::ncm::impl {
|
||||
|
||||
Result HasFile(bool *out, const char *path);
|
||||
Result HasDirectory(bool *out, const char *path);
|
||||
|
||||
Result EnsureDirectoryRecursively(const char *path);
|
||||
Result EnsureParentDirectoryRecursively(const char *path);
|
||||
|
||||
Result CopyFile(const char *dst_path, const char *src_path);
|
||||
|
||||
class PathView {
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace ams::ncm {
|
|||
Result PlaceHolderAccessor::EnsurePlaceHolderDirectory(PlaceHolderId placeholder_id) {
|
||||
PathString path;
|
||||
this->MakePath(std::addressof(path), placeholder_id);
|
||||
return impl::EnsureParentDirectoryRecursively(path);
|
||||
return fs::EnsureParentDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
Result PlaceHolderAccessor::GetPlaceHolderIdFromFileName(PlaceHolderId *out, const char *name) {
|
||||
|
|
|
@ -97,12 +97,12 @@ namespace ams::ncm {
|
|||
|
||||
/* Check if the file exists. */
|
||||
bool has;
|
||||
R_TRY(impl::HasFile(std::addressof(has), content_path));
|
||||
R_TRY(fs::HasFile(std::addressof(has), content_path));
|
||||
|
||||
/* If the file is absent, make the path for game card content meta and check presence again. */
|
||||
if (!has) {
|
||||
MakeGameCardContentMetaPath(std::addressof(content_path), content_id, this->make_content_path_func, this->root_path);
|
||||
R_TRY(impl::HasFile(std::addressof(has), content_path));
|
||||
R_TRY(fs::HasFile(std::addressof(has), content_path));
|
||||
}
|
||||
|
||||
out.SetValue(has);
|
||||
|
@ -118,7 +118,7 @@ namespace ams::ncm {
|
|||
|
||||
/* Check if the file exists. */
|
||||
bool has_file;
|
||||
R_TRY(impl::HasFile(std::addressof(has_file), content_path));
|
||||
R_TRY(fs::HasFile(std::addressof(has_file), content_path));
|
||||
|
||||
/* If the file is absent, make the path for regular content. */
|
||||
if (!has_file) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue