ldr: use lr bindings

This commit is contained in:
Michael Scire 2020-02-28 10:58:42 -08:00
parent 5f59fb3b5e
commit fb4bda0476
2 changed files with 24 additions and 25 deletions

View File

@ -264,52 +264,51 @@ namespace ams::ldr {
/* Redirection API. */ /* Redirection API. */
Result ResolveContentPath(char *out_path, const ncm::ProgramLocation &loc) { Result ResolveContentPath(char *out_path, const ncm::ProgramLocation &loc) {
char path[FS_MAX_PATH]; lr::Path path;
/* Try to get the path from the registered resolver. */ /* Try to get the path from the registered resolver. */
LrRegisteredLocationResolver reg; lr::RegisteredLocationResolver reg;
R_TRY(lrOpenRegisteredLocationResolver(&reg)); R_TRY(lr::OpenRegisteredLocationResolver(std::addressof(reg)));
ON_SCOPE_EXIT { serviceClose(&reg.s); };
R_TRY_CATCH(lrRegLrResolveProgramPath(&reg, static_cast<u64>(loc.program_id), path)) { R_TRY_CATCH(reg.ResolveProgramPath(std::addressof(path), loc.program_id)) {
R_CATCH(lr::ResultProgramNotFound) { R_CATCH(lr::ResultProgramNotFound) {
/* Program wasn't found via registered resolver, fall back to the normal resolver. */ /* Program wasn't found via registered resolver, fall back to the normal resolver. */
LrLocationResolver lr; lr::LocationResolver lr;
R_TRY(lrOpenLocationResolver(static_cast<NcmStorageId>(loc.storage_id), &lr)); R_TRY(lr::OpenLocationResolver(std::addressof(lr), loc.storage_id));
ON_SCOPE_EXIT { serviceClose(&lr.s); }; R_TRY(lr.ResolveProgramPath(std::addressof(path), loc.program_id));
R_TRY(lrLrResolveProgramPath(&lr, static_cast<u64>(loc.program_id), path));
} }
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
std::strncpy(out_path, path, FS_MAX_PATH); std::strncpy(out_path, path.str, sizeof(path.str));
out_path[FS_MAX_PATH - 1] = '\0'; out_path[sizeof(path.str) - 1] = '\0';
FixFileSystemPath(out_path); FixFileSystemPath(out_path);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectContentPath(const char *path, const ncm::ProgramLocation &loc) { Result RedirectContentPath(const char *path, const ncm::ProgramLocation &loc) {
LrLocationResolver lr; /* Copy in path. */
R_TRY(lrOpenLocationResolver(static_cast<NcmStorageId>(loc.storage_id), &lr)); lr::Path lr_path;
ON_SCOPE_EXIT { serviceClose(&lr.s); }; std::strncpy(lr_path.str, path, sizeof(lr_path.str));
lr_path.str[sizeof(lr_path.str) - 1] = '\0';
return lrLrRedirectProgramPath(&lr, static_cast<u64>(loc.program_id), path); lr::LocationResolver lr;
R_TRY(lr::OpenLocationResolver(std::addressof(lr), loc.storage_id));
return lr.RedirectProgramPath(lr_path, loc.program_id);
} }
Result RedirectHtmlDocumentPathForHbl(const ncm::ProgramLocation &loc) { Result RedirectHtmlDocumentPathForHbl(const ncm::ProgramLocation &loc) {
char path[FS_MAX_PATH]; lr::Path path;
/* Open a location resolver. */ /* Open a location resolver. */
LrLocationResolver lr; lr::LocationResolver lr;
R_TRY(lrOpenLocationResolver(static_cast<NcmStorageId>(loc.storage_id), &lr)); R_TRY(lr::OpenLocationResolver(std::addressof(lr), loc.storage_id));
ON_SCOPE_EXIT { serviceClose(&lr.s); };
/* If there's already a Html Document path, we don't need to set one. */ /* If there's already a Html Document path, we don't need to set one. */
R_UNLESS(R_FAILED(lrLrResolveApplicationHtmlDocumentPath(&lr, static_cast<u64>(loc.program_id), path)), ResultSuccess()); R_UNLESS(R_FAILED(lr.ResolveApplicationHtmlDocumentPath(std::addressof(path), loc.program_id)), ResultSuccess());
/* We just need to set this to any valid NCA path. Let's use the executable path. */ /* We just need to set this to any valid NCA path. Let's use the executable path. */
R_TRY(lrLrResolveProgramPath(&lr, static_cast<u64>(loc.program_id), path)); R_TRY(lr.ResolveProgramPath(std::addressof(path), loc.program_id));
R_TRY(lrLrRedirectApplicationHtmlDocumentPath(&lr, static_cast<u64>(loc.program_id), static_cast<u64>(loc.program_id), path)); R_TRY(lr.RedirectApplicationHtmlDocumentPath(path, loc.program_id, loc.program_id));
return ResultSuccess(); return ResultSuccess();
} }

View File

@ -73,7 +73,7 @@ void __appInit(void) {
/* Initialize services we need. */ /* Initialize services we need. */
sm::DoWithSession([&]() { sm::DoWithSession([&]() {
R_ABORT_UNLESS(fsInitialize()); R_ABORT_UNLESS(fsInitialize());
R_ABORT_UNLESS(lrInitialize()); lr::Initialize();
R_ABORT_UNLESS(fsldrInitialize()); R_ABORT_UNLESS(fsldrInitialize());
}); });
@ -84,7 +84,7 @@ void __appExit(void) {
/* Cleanup services. */ /* Cleanup services. */
fsdevUnmountAll(); fsdevUnmountAll();
fsldrExit(); fsldrExit();
lrExit(); lr::Finalize();
fsExit(); fsExit();
} }