2021-04-08 05:15:36 +00:00
|
|
|
#include <psp2/apputil.h>
|
|
|
|
#include <psp2/common_dialog.h>
|
2021-04-11 18:32:15 +00:00
|
|
|
#include <psp2/rtc.h>
|
|
|
|
#include <psp2/kernel/clib.h>
|
2021-04-08 05:15:36 +00:00
|
|
|
|
2021-04-08 15:58:17 +00:00
|
|
|
#include "log.h"
|
2021-04-08 05:15:36 +00:00
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
namespace Utils {
|
|
|
|
int InitAppUtil(void) {
|
|
|
|
SceAppUtilInitParam init;
|
|
|
|
SceAppUtilBootParam boot;
|
|
|
|
sceClibMemset(&init, 0, sizeof(SceAppUtilInitParam));
|
|
|
|
sceClibMemset(&boot, 0, sizeof(SceAppUtilBootParam));
|
|
|
|
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (R_FAILED(ret = sceAppUtilInit(&init, &boot))) {
|
2021-04-08 15:58:17 +00:00
|
|
|
Log::Error("sceAppUtilInit failed: 0x%lx\n", ret);
|
2021-04-08 05:15:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
SceCommonDialogConfigParam param;
|
|
|
|
sceCommonDialogConfigParamInit(¶m);
|
|
|
|
|
|
|
|
if (R_FAILED(ret = sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_LANG, reinterpret_cast<int *>(¶m.language)))) {
|
2021-04-08 15:58:17 +00:00
|
|
|
Log::Error("sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_LANG) failed: 0x%lx\n", ret);
|
2021-04-08 05:15:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (R_FAILED(ret = sceCommonDialogSetConfigParam(¶m))) {
|
2021-04-08 15:58:17 +00:00
|
|
|
Log::Error("sceCommonDialogSetConfigParam failed: 0x%lx\n", ret);
|
2021-04-08 05:15:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int EndAppUtil(void) {
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (R_FAILED(ret = sceAppUtilShutdown())) {
|
2021-04-08 15:58:17 +00:00
|
|
|
Log::Error("sceAppUtilShutdown failed: 0x%lx\n", ret);
|
2021-04-08 05:15:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2021-04-11 18:32:15 +00:00
|
|
|
|
|
|
|
int GetDateFormat(void) {
|
|
|
|
int format = 0, ret = 0;
|
|
|
|
|
|
|
|
if (R_FAILED(ret = sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_DATE_FORMAT, &format))) {
|
|
|
|
Log::Error("sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_DATE_FORMAT) failed: 0x%lx\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
// From VitaShell by TheOfficialFloW -> https://github.com/TheOfficialFloW/VitaShell/blob/master/utils.c#L349
|
2021-08-24 22:56:47 +00:00
|
|
|
static void ConvertLocalTimeToUTC(SceDateTime &time_utc, SceDateTime &time_local) {
|
2021-04-11 18:32:15 +00:00
|
|
|
// sceRtcGetTick and other sceRtc functions fails with year > 9999
|
2021-08-24 22:56:47 +00:00
|
|
|
int year_local = time_local.year;
|
2021-04-11 18:32:15 +00:00
|
|
|
int year_delta = year_local < 9999 ? 0 : year_local - 9998;
|
2021-08-24 22:56:47 +00:00
|
|
|
time_local.year -= year_delta;
|
2021-04-11 18:32:15 +00:00
|
|
|
|
|
|
|
SceRtcTick tick;
|
2021-08-24 22:56:47 +00:00
|
|
|
sceRtcGetTick(&time_local, &tick);
|
|
|
|
time_local.year = year_local;
|
2021-04-11 18:32:15 +00:00
|
|
|
|
|
|
|
sceRtcConvertLocalTimeToUtc(&tick, &tick);
|
2021-08-24 22:56:47 +00:00
|
|
|
sceRtcSetTick(&time_utc, &tick);
|
|
|
|
time_utc.year += year_delta;
|
2021-04-11 18:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// From VitaShell by TheOfficialFloW -> https://github.com/TheOfficialFloW/VitaShell/blob/master/utils.c#L364
|
2021-08-24 22:56:47 +00:00
|
|
|
void GetDateString(char string[24], SceSystemParamDateFormat format, SceDateTime &time) {
|
2021-04-11 18:32:15 +00:00
|
|
|
SceDateTime local_time;
|
2021-08-24 22:56:47 +00:00
|
|
|
Utils::ConvertLocalTimeToUTC(local_time, time);
|
2021-04-11 18:32:15 +00:00
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case SCE_SYSTEM_PARAM_DATE_FORMAT_YYYYMMDD:
|
2021-07-20 23:54:31 +00:00
|
|
|
sceClibSnprintf(string, 24, "%04d/%02d/%02d", local_time.year, local_time.month, local_time.day);
|
2021-04-11 18:32:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCE_SYSTEM_PARAM_DATE_FORMAT_DDMMYYYY:
|
2021-07-20 23:54:31 +00:00
|
|
|
sceClibSnprintf(string, 24, "%02d/%02d/%04d", local_time.day, local_time.month, local_time.year);
|
2021-04-11 18:32:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCE_SYSTEM_PARAM_DATE_FORMAT_MMDDYYYY:
|
2021-07-20 23:54:31 +00:00
|
|
|
sceClibSnprintf(string, 24, "%02d/%02d/%04d", local_time.month, local_time.day, local_time.year);
|
2021-04-11 18:32:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-04-08 05:15:36 +00:00
|
|
|
}
|