Added wrapper for accountListAllUsers

This commit is contained in:
3Daniel 2018-06-27 22:52:15 +12:00
parent fe4fe73513
commit a590ed50da
2 changed files with 39 additions and 4 deletions

View File

@ -39,10 +39,12 @@ Service* accountGetService(void);
Result accountGetUserCount(s32* user_count); Result accountGetUserCount(s32* user_count);
/** /**
* @brief Get a list of all user IDs * @brief Get a list of all user IDs. The returned list will never be larger than ACC_USER_LIST_SIZE
* @param userIDs Pointer to array of user IDs, array must be exactly ACC_USER_LIST_SIZE * @param userIDs Pointer to array of user IDs
* @param max_userIDs Maximum number of user IDs to return
* @param actual_total The actual total number of user IDs found
*/ */
Result accountListAllUsers(u128* userIDs); Result accountListAllUsers(u128* userIDs, size_t max_userIDs, size_t *actual_total);
/// Get the userID for the currently active user. The output userID is only valid when the output account_selected==1, otherwise no user is currently selected. /// Get the userID for the currently active user. The output userID is only valid when the output account_selected==1, otherwise no user is currently selected.
/// An user is only selected when the user-account selection applet was used to select an user at least once before. /// An user is only selected when the user-account selection applet was used to select an user at least once before.

View File

@ -1,4 +1,5 @@
#include <string.h> #include <string.h>
#include <malloc.h>
#include "types.h" #include "types.h"
#include "arm/atomics.h" #include "arm/atomics.h"
@ -70,7 +71,7 @@ Result accountGetUserCount(s32* user_count)
return rc; return rc;
} }
Result accountListAllUsers(u128* userIDs) static Result _accountListAllUsers(u128* userIDs)
{ {
IpcCommand c; IpcCommand c;
ipcInitialize(&c); ipcInitialize(&c);
@ -108,6 +109,38 @@ Result accountListAllUsers(u128* userIDs)
return rc; return rc;
} }
Result accountListAllUsers(u128* userIDs, size_t max_userIDs, size_t *actual_total)
{
Result rc=0;
u128 *temp_userIDs;
temp_userIDs = malloc(sizeof(u128) * ACC_USER_LIST_SIZE);
rc = _accountListAllUsers(temp_userIDs);
if (R_SUCCEEDED(rc)) {
size_t total_userIDs = 0;
for (int i = 0; i < ACC_USER_LIST_SIZE; i++) {
if (temp_userIDs[i]) {
total_userIDs++;
}
}
if (max_userIDs > total_userIDs) {
max_userIDs = total_userIDs;
}
for (int i = 0; i < max_userIDs; i++) {
userIDs[i] = temp_userIDs[i];
}
*actual_total = total_userIDs;
}
return rc;
}
Result accountGetActiveUser(u128 *userID, bool *account_selected) Result accountGetActiveUser(u128 *userID, bool *account_selected)
{ {
IpcCommand c; IpcCommand c;