ns: Added nsGetFactoryResetInterface(). Added support for IFactoryResetInterface. Improved docs, etc.

This commit is contained in:
yellows8 2020-02-26 17:35:01 -05:00
parent 4a493775b4
commit 8ae9b5e1a9
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43
2 changed files with 123 additions and 0 deletions

View File

@ -234,6 +234,50 @@ Service* nsGetServiceSession_GetterInterface(void);
/// Gets the Service object for IApplicationManagerInterface.
Service* nsGetServiceSession_ApplicationManagerInterface(void);
/// Gets the Service object for IFactoryResetInterface via the cmd for that.
Result nsGetFactoryResetInterface(Service* srv_out);
///@}
///@name IFactoryResetInterface
///@{
/**
* @brief ResetToFactorySettings
* @note Uses \ref nsGetFactoryResetInterface on [3.0.0+], otherwise IApplicationManagerInterface is used.
*/
Result nsResetToFactorySettings(void);
/**
* @brief ResetToFactorySettingsWithoutUserSaveData
* @note Uses \ref nsGetFactoryResetInterface on [3.0.0+], otherwise IApplicationManagerInterface is used.
*/
Result nsResetToFactorySettingsWithoutUserSaveData(void);
/**
* @brief ResetToFactorySettingsForRefurbishment
* @note Uses \ref nsGetFactoryResetInterface on [3.0.0+], otherwise IApplicationManagerInterface is used.
* @note Only available on [2.0.0+].
*/
Result nsResetToFactorySettingsForRefurbishment(void);
/**
* @brief ResetToFactorySettingsWithPlatformRegion
* @note Only available on [9.1.0+].
*/
Result nsResetToFactorySettingsWithPlatformRegion(void);
/**
* @brief ResetToFactorySettingsWithPlatformRegionAuthentication
* @note Only available on [9.1.0+].
*/
Result nsResetToFactorySettingsWithPlatformRegionAuthentication(void);
///@}
///@name IApplicationManagerInterface
///@{
/**
* @brief Gets an listing of \ref NsApplicationRecord.
* @param[out] records Output array of \ref NsApplicationRecord.

View File

@ -46,6 +46,10 @@ Service* nsGetServiceSession_ApplicationManagerInterface(void) {
return &g_nsAppManSrv;
}
Result nsGetFactoryResetInterface(Service* srv_out) {
return _nsGetSession(&g_nsGetterSrv, srv_out, 7994);
}
static Result _nsGetSession(Service* srv, Service* srv_out, u32 cmd_id) {
return serviceDispatch(srv, cmd_id,
.out_num_objects = 1,
@ -234,6 +238,81 @@ static Result _nsCheckNifm(void) {
return nifmIsAnyInternetRequestAccepted(nifmGetClientId()) ? 0 : MAKERESULT(16, 340);
}
// IFactoryResetInterface
Result nsResetToFactorySettings(void) {
Service srv={0}, *srv_ptr = &srv;
Result rc=0;
if (hosversionAtLeast(3,0,0))
rc = nsGetFactoryResetInterface(&srv);
else
srv_ptr = &g_nsAppManSrv;
if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(srv_ptr, 100);
serviceClose(&srv);
return rc;
}
Result nsResetToFactorySettingsWithoutUserSaveData(void) {
Service srv={0}, *srv_ptr = &srv;
Result rc=0;
if (hosversionAtLeast(3,0,0))
rc = nsGetFactoryResetInterface(&srv);
else
srv_ptr = &g_nsAppManSrv;
if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(srv_ptr, 101);
serviceClose(&srv);
return rc;
}
Result nsResetToFactorySettingsForRefurbishment(void) {
if (hosversionBefore(2,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
Service srv={0}, *srv_ptr = &srv;
Result rc=0;
if (hosversionAtLeast(3,0,0))
rc = nsGetFactoryResetInterface(&srv);
else
srv_ptr = &g_nsAppManSrv;
if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(srv_ptr, 102);
serviceClose(&srv);
return rc;
}
Result nsResetToFactorySettingsWithPlatformRegion(void) {
if (hosversionBefore(9,1,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
Service srv={0};
Result rc = nsGetFactoryResetInterface(&srv);
if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(&srv, 103);
serviceClose(&srv);
return rc;
}
Result nsResetToFactorySettingsWithPlatformRegionAuthentication(void) {
if (hosversionBefore(9,1,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
Service srv={0};
Result rc = nsGetFactoryResetInterface(&srv);
if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(&srv, 104);
serviceClose(&srv);
return rc;
}
// IApplicationManagerInterface
Result nsListApplicationRecord(NsApplicationRecord* records, s32 count, s32 entry_offset, s32* out_entrycount) {
return serviceDispatchInOut(&g_nsAppManSrv, 0, entry_offset, *out_entrycount,
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out },