mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2025-01-03 19:14:44 +00:00
Loader: Fix game update content loading, fix SD card mounting on newer firmwares. Closes #61.
This commit is contained in:
parent
44127faa17
commit
aa158dbb5a
3 changed files with 41 additions and 25 deletions
|
@ -16,9 +16,12 @@ Result ContentManagement::MountCode(u64 tid, FsStorageId sid) {
|
||||||
Result rc;
|
Result rc;
|
||||||
|
|
||||||
/* We defer SD card mounting, so if relevant ensure it is mounted. */
|
/* We defer SD card mounting, so if relevant ensure it is mounted. */
|
||||||
TryMountSdCard();
|
if (!g_has_initialized_fs_dev) {
|
||||||
|
TryMountSdCard();
|
||||||
if (R_FAILED(rc = GetContentPath(path, tid, sid))) {
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (R_FAILED(rc = ResolveContentPath(path, tid, sid))) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,31 +56,34 @@ Result ContentManagement::MountCodeForTidSid(Registration::TidSid *tid_sid) {
|
||||||
return MountCode(tid_sid->title_id, tid_sid->storage_id);
|
return MountCode(tid_sid->title_id, tid_sid->storage_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ContentManagement::GetContentPath(char *out_path, u64 tid, FsStorageId sid) {
|
Result ContentManagement::ResolveContentPath(char *out_path, u64 tid, FsStorageId sid) {
|
||||||
Result rc;
|
Result rc;
|
||||||
LrRegisteredLocationResolver reg;
|
LrRegisteredLocationResolver reg;
|
||||||
LrLocationResolver lr;
|
LrLocationResolver lr;
|
||||||
char path[FS_MAX_PATH] = {0};
|
char path[FS_MAX_PATH] = {0};
|
||||||
|
|
||||||
/* Try to get the path from the registered resolver. */
|
/* Try to get the path from the registered resolver. */
|
||||||
if (R_FAILED(rc = lrGetRegisteredLocationResolver(®))) {
|
if (R_FAILED(rc = lrOpenRegisteredLocationResolver(®))) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc = lrRegLrGetProgramPath(®, tid, path))) {
|
if (R_SUCCEEDED(rc = lrRegLrResolveProgramPath(®, tid, path))) {
|
||||||
strncpy(out_path, path, sizeof(path));
|
strncpy(out_path, path, sizeof(path));
|
||||||
} else if (rc != 0x408) {
|
} else if (rc != 0x408) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceClose(®.s);
|
serviceClose(®.s);
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
/* If getting the path from the registered resolver fails, fall back to the normal resolver. */
|
|
||||||
if (R_FAILED(rc = lrGetLocationResolver(sid, &lr))) {
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc = lrLrGetProgramPath(&lr, tid, path))) {
|
/* If getting the path from the registered resolver fails, fall back to the normal resolver. */
|
||||||
|
if (R_FAILED(rc = lrOpenLocationResolver(sid, &lr))) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc = lrLrResolveProgramPath(&lr, tid, path))) {
|
||||||
strncpy(out_path, path, sizeof(path));
|
strncpy(out_path, path, sizeof(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,27 +92,27 @@ Result ContentManagement::GetContentPath(char *out_path, u64 tid, FsStorageId si
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ContentManagement::GetContentPathForTidSid(char *out_path, Registration::TidSid *tid_sid) {
|
Result ContentManagement::ResolveContentPathForTidSid(char *out_path, Registration::TidSid *tid_sid) {
|
||||||
return GetContentPath(out_path, tid_sid->title_id, tid_sid->storage_id);
|
return ResolveContentPath(out_path, tid_sid->title_id, tid_sid->storage_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ContentManagement::SetContentPath(const char *path, u64 tid, FsStorageId sid) {
|
Result ContentManagement::RedirectContentPath(const char *path, u64 tid, FsStorageId sid) {
|
||||||
Result rc;
|
Result rc;
|
||||||
LrLocationResolver lr;
|
LrLocationResolver lr;
|
||||||
|
|
||||||
if (R_FAILED(rc = lrGetLocationResolver(sid, &lr))) {
|
if (R_FAILED(rc = lrOpenLocationResolver(sid, &lr))) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = lrLrSetProgramPath(&lr, tid, path);
|
rc = lrLrRedirectProgramPath(&lr, tid, path);
|
||||||
|
|
||||||
serviceClose(&lr.s);
|
serviceClose(&lr.s);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ContentManagement::SetContentPathForTidSid(const char *path, Registration::TidSid *tid_sid) {
|
Result ContentManagement::RedirectContentPathForTidSid(const char *path, Registration::TidSid *tid_sid) {
|
||||||
return SetContentPath(path, tid_sid->title_id, tid_sid->storage_id);
|
return RedirectContentPath(path, tid_sid->title_id, tid_sid->storage_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContentManagement::HasCreatedTitle(u64 tid) {
|
bool ContentManagement::HasCreatedTitle(u64 tid) {
|
||||||
|
@ -122,8 +128,18 @@ void ContentManagement::SetCreatedTitle(u64 tid) {
|
||||||
void ContentManagement::TryMountSdCard() {
|
void ContentManagement::TryMountSdCard() {
|
||||||
/* Mount SD card, if psc, bus, and pcv have been created. */
|
/* Mount SD card, if psc, bus, and pcv have been created. */
|
||||||
if (!g_has_initialized_fs_dev && HasCreatedTitle(0x0100000000000021) && HasCreatedTitle(0x010000000000000A) && HasCreatedTitle(0x010000000000001A)) {
|
if (!g_has_initialized_fs_dev && HasCreatedTitle(0x0100000000000021) && HasCreatedTitle(0x010000000000000A) && HasCreatedTitle(0x010000000000001A)) {
|
||||||
|
Handle tmp_hnd = 0;
|
||||||
|
static const char *required_active_services[] = {"pcv", "gpio", "pinmux", "psc:c"};
|
||||||
|
for (unsigned int i = 0; i < sizeof(required_active_services) / sizeof(required_active_services[0]); i++) {
|
||||||
|
if (R_FAILED(smGetServiceOriginal(&tmp_hnd, smEncodeName(required_active_services[i])))) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
svcCloseHandle(tmp_hnd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (R_SUCCEEDED(fsdevMountSdmc())) {
|
if (R_SUCCEEDED(fsdevMountSdmc())) {
|
||||||
g_has_initialized_fs_dev = true;
|
g_has_initialized_fs_dev = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,10 @@ class ContentManagement {
|
||||||
static Result UnmountCode();
|
static Result UnmountCode();
|
||||||
static Result MountCodeForTidSid(Registration::TidSid *tid_sid);
|
static Result MountCodeForTidSid(Registration::TidSid *tid_sid);
|
||||||
|
|
||||||
static Result GetContentPath(char *out_path, u64 tid, FsStorageId sid);
|
static Result ResolveContentPath(char *out_path, u64 tid, FsStorageId sid);
|
||||||
static Result SetContentPath(const char *path, u64 tid, FsStorageId sid);
|
static Result RedirectContentPath(const char *path, u64 tid, FsStorageId sid);
|
||||||
static Result GetContentPathForTidSid(char *out_path, Registration::TidSid *tid_sid);
|
static Result ResolveContentPathForTidSid(char *out_path, Registration::TidSid *tid_sid);
|
||||||
static Result SetContentPathForTidSid(const char *path, Registration::TidSid *tid_sid);
|
static Result RedirectContentPathForTidSid(const char *path, Registration::TidSid *tid_sid);
|
||||||
|
|
||||||
static bool HasCreatedTitle(u64 tid);
|
static bool HasCreatedTitle(u64 tid);
|
||||||
static void SetCreatedTitle(u64 tid);
|
static void SetCreatedTitle(u64 tid);
|
||||||
|
|
|
@ -42,7 +42,7 @@ std::tuple<Result, MovedHandle> ProcessManagerService::create_process(u64 flags,
|
||||||
return {rc, MovedHandle{process_h}};
|
return {rc, MovedHandle{process_h}};
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = ContentManagement::GetContentPathForTidSid(nca_path, &tid_sid);
|
rc = ContentManagement::ResolveContentPathForTidSid(nca_path, &tid_sid);
|
||||||
if (R_FAILED(rc)) {
|
if (R_FAILED(rc)) {
|
||||||
return {rc, MovedHandle{process_h}};
|
return {rc, MovedHandle{process_h}};
|
||||||
}
|
}
|
||||||
|
@ -71,12 +71,12 @@ std::tuple<Result> ProcessManagerService::get_program_info(Registration::TidSid
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tid_sid.title_id != out_program_info.pointer->title_id) {
|
if (tid_sid.title_id != out_program_info.pointer->title_id) {
|
||||||
rc = ContentManagement::GetContentPathForTidSid(nca_path, &tid_sid);
|
rc = ContentManagement::ResolveContentPathForTidSid(nca_path, &tid_sid);
|
||||||
if (R_FAILED(rc)) {
|
if (R_FAILED(rc)) {
|
||||||
return {rc};
|
return {rc};
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = ContentManagement::SetContentPath(nca_path, out_program_info.pointer->title_id, tid_sid.storage_id);
|
rc = ContentManagement::RedirectContentPath(nca_path, out_program_info.pointer->title_id, tid_sid.storage_id);
|
||||||
if (R_FAILED(rc)) {
|
if (R_FAILED(rc)) {
|
||||||
return {rc};
|
return {rc};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue