MCPcopy Create free account
hub / github.com/XorTroll/uLaunch / ReadTargetInput

Function ReadTargetInput

projects/uLoader/source/ul/loader/loader_Input.cpp:9–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7namespace ul::loader {
8
9 Result ReadTargetInput(TargetInput &out_target_ipt) {
10 UL_RC_TRY(appletInitialize());
11 util::OnScopeExit applet_exit([]() {
12 appletExit();
13 });
14
15 AppletStorage target_ipt_storage;
16 if(SelfIsApplet()) {
17 // We don't make use of the common args storage
18 AppletStorage common_args_storage;
19 UL_RC_TRY(appletPopInData(&common_args_storage));
20 appletStorageClose(&common_args_storage);
21
22 UL_RC_TRY(appletPopInData(&target_ipt_storage));
23 }
24 else if(SelfIsApplication()) {
25 UL_RC_TRY(appletPopLaunchParameter(&target_ipt_storage, AppletLaunchParameterKind_UserChannel));
26 }
27 else {
28 return ResultInvalidProcessType;
29 }
30 util::OnScopeExit close_storage([&]() {
31 appletStorageClose(&target_ipt_storage);
32 });
33
34 s64 storage_size;
35 UL_RC_TRY(appletStorageGetSize(&target_ipt_storage, &storage_size));
36 if(static_cast<size_t>(storage_size) >= sizeof(out_target_ipt)) {
37 UL_RC_TRY(appletStorageRead(&target_ipt_storage, 0, std::addressof(out_target_ipt), sizeof(out_target_ipt)));
38 if(out_target_ipt.magic == TargetInput::Magic) {
39 // By default, argv = <nro-path>
40 if(strlen(out_target_ipt.nro_argv) == 0) {
41 util::CopyToStringBuffer(out_target_ipt.nro_argv, out_target_ipt.nro_path);
42 }
43
44 return ResultSuccess;
45 }
46 else {
47 return ResultInvalidTargetInputMagic;
48 }
49 }
50 else {
51 return ResultInvalidTargetInputSize;
52 }
53 }
54
55 Result WriteTargetOutput(const TargetOutput &target_opt) {
56 UL_RC_TRY(appletInitialize());

Callers 1

mainFunction · 0.85

Calls 3

SelfIsAppletFunction · 0.85
SelfIsApplicationFunction · 0.85
CopyToStringBufferFunction · 0.85

Tested by

no test coverage detected