Skip to content

Commit 2d4971a

Browse files
authored
Add nsListApplicationTitle2 (#717)
1 parent a82e226 commit 2d4971a

2 files changed

Lines changed: 56 additions & 8 deletions

File tree

  • nx
    • include/switch/services
    • source/services

nx/include/switch/services/ns.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,20 @@ Result nsRequestDownloadApplicationControlData(AsyncResult *a, u64 application_i
656656
*/
657657
Result nsListApplicationTitle(AsyncValue *a, NsApplicationControlSource source, const u64 *application_ids, s32 count, void* buffer, size_t size);
658658

659+
/**
660+
* @brief ListApplicationTitle2. Returns \ref NacpLanguageEntry matching currently set system language for each specified ApplicationId.
661+
* @note The data available with \ref asyncValueGet is a s32 for the offset within the buffer where the output data is located, \ref asyncValueGetSize returns the total byte-size of the data located here. The data located here is the \ref NacpLanguageEntry for each specified ApplicationId.
662+
* @note Only available on [20.0.0+].
663+
* @note NacpLanguageEntry is decompressed when necessary only on [21.0.0+].
664+
* @param[out] a \ref AsyncValue
665+
* @param[in] source Source, official sw uses ::NsApplicationControlSource_Storage.
666+
* @param[in] application_ids Input array of ApplicationIds.
667+
* @param[in] count Size of the application_ids array in entries.
668+
* @param buffer 0x1000-byte aligned buffer for TransferMemory. This buffer must not be accessed until the async operation finishes.
669+
* @param[in] size 0x1000-byte aligned buffer size for TransferMemory. This must be at least: count*sizeof(\ref NacpLanguageEntry) + count*sizeof(u64) + sizeof(\ref NsApplicationControlData).
670+
*/
671+
Result nsListApplicationTitle2(AsyncValue *a, NsApplicationControlSource source, const u64 *application_ids, s32 count, void* buffer, size_t size);
672+
659673
/**
660674
* @brief ListApplicationIcon
661675
* @note The data available with \ref asyncValueGet is a s32 for the offset within the buffer where the output data is located, \ref asyncValueGetSize returns the total byte-size of the data located here. This data is: an u64 for total entries, an array of u64s for each icon size, then the icon JPEGs for the specified ApplicationIds.

nx/source/services/ns.c

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -980,10 +980,7 @@ Result nsRequestDownloadApplicationControlData(AsyncResult *a, u64 application_i
980980
return _nsManCmdInU64OutAsyncResult(a, application_id, 402);
981981
}
982982

983-
static Result _nsListApplicationTitleIcon(AsyncValue *a, NsApplicationControlSource source, const u64 *application_ids, s32 count, TransferMemory *tmem, u32 cmd_id) { // [8.0.0+]
984-
Service srv={0};
985-
Result rc = nsGetApplicationManagerInterface(&srv);
986-
983+
static Result _nsListApplicationTitleIcon(Service* srv, AsyncValue *a, NsApplicationControlSource source, const u64 *application_ids, s32 count, TransferMemory *tmem, u32 cmd_id) {
987984
const struct {
988985
u8 source;
989986
u8 pad[7];
@@ -992,7 +989,7 @@ static Result _nsListApplicationTitleIcon(AsyncValue *a, NsApplicationControlSou
992989

993990
memset(a, 0, sizeof(*a));
994991
Handle event = INVALID_HANDLE;
995-
if (R_SUCCEEDED(rc)) rc = serviceDispatchIn(&srv, cmd_id, in,
992+
Result rc = serviceDispatchIn(srv, cmd_id, in,
996993
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In },
997994
.buffers = { { application_ids, count*sizeof(u64) } },
998995
.in_num_handles = 1,
@@ -1006,7 +1003,6 @@ static Result _nsListApplicationTitleIcon(AsyncValue *a, NsApplicationControlSou
10061003
if (R_SUCCEEDED(rc))
10071004
eventLoadRemote(&a->event, event, false);
10081005

1009-
serviceClose(&srv);
10101006
return rc;
10111007
}
10121008

@@ -1016,23 +1012,61 @@ Result nsListApplicationTitle(AsyncValue *a, NsApplicationControlSource source,
10161012

10171013
Result rc=0;
10181014
TransferMemory tmem={0};
1015+
Service srv={0};
10191016

10201017
rc = tmemCreateFromMemory(&tmem, buffer, size, Perm_R);
1021-
if (R_SUCCEEDED(rc)) rc = _nsListApplicationTitleIcon(a, source, application_ids, count, &tmem, 407);
1018+
1019+
if (R_SUCCEEDED(rc)) {
1020+
rc = nsGetApplicationManagerInterface(&srv);
1021+
if (R_SUCCEEDED(rc)) {
1022+
rc = _nsListApplicationTitleIcon(&srv, a, source, application_ids, count, &tmem, 407);
1023+
serviceClose(&srv);
1024+
}
1025+
}
10221026
tmemClose(&tmem);
10231027

10241028
return rc;
10251029
}
10261030

1031+
Result nsListApplicationTitle2(AsyncValue *a, NsApplicationControlSource source, const u64 *application_ids, s32 count, void* buffer, size_t size) {
1032+
if (hosversionBefore(20,0,0))
1033+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
1034+
1035+
Result rc=0;
1036+
TransferMemory tmem={0};
1037+
Service srv={0};
1038+
1039+
rc = tmemCreateFromMemory(&tmem, buffer, size, Perm_R);
1040+
1041+
if (R_SUCCEEDED(rc)) {
1042+
rc = nsGetReadOnlyApplicationControlDataInterface(&srv);
1043+
if (R_SUCCEEDED(rc)) {
1044+
rc = _nsListApplicationTitleIcon(&srv, a, source, application_ids, count, &tmem, 10);
1045+
serviceClose(&srv);
1046+
}
1047+
}
1048+
1049+
tmemClose(&tmem);
1050+
1051+
return rc;
1052+
}
1053+
10271054
Result nsListApplicationIcon(AsyncValue *a, NsApplicationControlSource source, const u64 *application_ids, s32 count, void* buffer, size_t size) {
10281055
if (hosversionBefore(8,0,0))
10291056
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
10301057

10311058
Result rc=0;
10321059
TransferMemory tmem={0};
1060+
Service srv={0};
10331061

10341062
rc = tmemCreateFromMemory(&tmem, buffer, size, Perm_R);
1035-
if (R_SUCCEEDED(rc)) rc = _nsListApplicationTitleIcon(a, source, application_ids, count, &tmem, 408);
1063+
if (R_SUCCEEDED(rc)) {
1064+
rc = nsGetApplicationManagerInterface(&srv);
1065+
if (R_SUCCEEDED(rc)) {
1066+
rc = _nsListApplicationTitleIcon(&srv, a, source, application_ids, count, &tmem, 408);
1067+
serviceClose(&srv);
1068+
}
1069+
}
10361070
tmemClose(&tmem);
10371071

10381072
return rc;

0 commit comments

Comments
 (0)