mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-09 22:56:35 +00:00
Clean up Nso fopen semantics
This commit is contained in:
parent
1c47959bca
commit
5e5dd530c7
3 changed files with 26 additions and 21 deletions
|
@ -6,14 +6,26 @@
|
|||
static NsoUtils::NsoHeader g_nso_headers[NSO_NUM_MAX] = {0};
|
||||
static bool g_nso_present[NSO_NUM_MAX] = {0};
|
||||
|
||||
void NsoUtils::GetNsoCodePath(char *content_path, unsigned int index) {
|
||||
std::fill(content_path, content_path + FS_MAX_PATH, 0);
|
||||
snprintf(content_path, FS_MAX_PATH, "code:/%s", NsoUtils::GetNsoFileName(index));
|
||||
static char g_nso_path[FS_MAX_PATH] = {0};
|
||||
|
||||
FILE *NsoUtils::OpenNsoFromExeFS(unsigned int index) {
|
||||
std::fill(g_nso_path, g_nso_path + FS_MAX_PATH, 0);
|
||||
snprintf(g_nso_path, FS_MAX_PATH, "code:/%s", NsoUtils::GetNsoFileName(index));
|
||||
return fopen(g_nso_path, "rb");
|
||||
}
|
||||
|
||||
void NsoUtils::GetNsoSdPath(char *content_path, u64 title_id, unsigned int index) {
|
||||
std::fill(content_path, content_path + FS_MAX_PATH, 0);
|
||||
snprintf(content_path, FS_MAX_PATH, "sdmc:/atmosphere/titles/%016lx/exefs/%s", title_id, NsoUtils::GetNsoFileName(index));
|
||||
FILE *NsoUtils::OpenNsoFromSdCard(unsigned int index, u64 title_id) {
|
||||
std::fill(g_nso_path, g_nso_path + FS_MAX_PATH, 0);
|
||||
snprintf(g_nso_path, FS_MAX_PATH, "sdmc:/atmosphere/titles/%016lx/exefs/%s", title_id, NsoUtils::GetNsoFileName(index));
|
||||
return fopen(g_nso_path, "rb");
|
||||
}
|
||||
|
||||
FILE *NsoUtils::OpenNso(unsigned int index, u64 title_id) {
|
||||
FILE *f_out = OpenNsoFromSdCard(index, title_id);
|
||||
if (f_out != NULL) {
|
||||
return f_out;
|
||||
}
|
||||
return OpenNsoFromExeFS(index);
|
||||
}
|
||||
|
||||
bool NsoUtils::IsNsoPresent(unsigned int index) {
|
||||
|
@ -21,7 +33,6 @@ bool NsoUtils::IsNsoPresent(unsigned int index) {
|
|||
}
|
||||
|
||||
Result NsoUtils::LoadNsoHeaders(u64 title_id) {
|
||||
char nso_path[FS_MAX_PATH] = {0};
|
||||
FILE *f_nso;
|
||||
|
||||
/* Zero out the cache. */
|
||||
|
@ -29,17 +40,8 @@ Result NsoUtils::LoadNsoHeaders(u64 title_id) {
|
|||
std::fill(g_nso_headers, g_nso_headers + NSO_NUM_MAX, (const NsoUtils::NsoHeader &){0});
|
||||
|
||||
for (unsigned int i = 0; i < NSO_NUM_MAX; i++) {
|
||||
GetNsoSdPath(nso_path, title_id, i);
|
||||
if ((f_nso = fopen(nso_path, "rb")) != NULL) {
|
||||
if (fread(&g_nso_headers[i], sizeof(NsoUtils::NsoHeader), 1, f_nso) != sizeof(NsoUtils::NsoHeader)) {
|
||||
return 0xA09;
|
||||
}
|
||||
g_nso_present[i] = true;
|
||||
fclose(f_nso);
|
||||
continue;
|
||||
}
|
||||
GetNsoCodePath(nso_path, i);
|
||||
if ((f_nso = fopen(nso_path, "rb")) != NULL) {
|
||||
f_nso = OpenNso(i, title_id);
|
||||
if (f_nso != NULL) {
|
||||
if (fread(&g_nso_headers[i], sizeof(NsoUtils::NsoHeader), 1, f_nso) != sizeof(NsoUtils::NsoHeader)) {
|
||||
return 0xA09;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <cstdio>
|
||||
|
||||
#define MAGIC_NSO0 0x304F534E
|
||||
#define NSO_NUM_MAX 13
|
||||
|
@ -64,8 +65,9 @@ class NsoUtils {
|
|||
}
|
||||
}
|
||||
|
||||
static void GetNsoCodePath(char *content_path, unsigned int index);
|
||||
static void GetNsoSdPath(char *content_path, u64 title_id, unsigned int index);
|
||||
static FILE *OpenNsoFromExeFS(unsigned int index);
|
||||
static FILE *OpenNsoFromSdCard(unsigned int index, u64 title_id);
|
||||
static FILE *OpenNso(unsigned int index, u64 title_id);
|
||||
|
||||
static bool IsNsoPresent(unsigned int index);
|
||||
static Result LoadNsoHeaders(u64 title_id);
|
||||
|
|
|
@ -90,6 +90,7 @@ Result ProcessCreation::CreateProcess(Handle *out_process_h, u64 index, char *nc
|
|||
NpdmUtils::NpdmInfo npdm_info = {0};
|
||||
ProcessInfo process_info = {0};
|
||||
Registration::Process *target_process;
|
||||
Handle process_h = 0;
|
||||
Result rc;
|
||||
|
||||
/* Get the process from the registration queue. */
|
||||
|
@ -143,7 +144,7 @@ Result ProcessCreation::CreateProcess(Handle *out_process_h, u64 index, char *nc
|
|||
/* TODO: Figure out where NSOs will be mapped, and how much space they (and arguments) will take up. */
|
||||
|
||||
/* Call svcCreateProcess(). */
|
||||
rc = svcCreateProcess(out_process_h, &process_info, (u32 *)npdm_info.aci0_kac, npdm_info.aci0->kac_size/sizeof(u32));
|
||||
rc = svcCreateProcess(&process_h, &process_info, (u32 *)npdm_info.aci0_kac, npdm_info.aci0->kac_size/sizeof(u32));
|
||||
if (R_FAILED(rc)) {
|
||||
goto CREATE_PROCESS_END;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue