2018-04-24 11:57:39 -07:00
|
|
|
using Ryujinx.Core.Logging;
|
2018-02-25 10:58:16 -08:00
|
|
|
using Ryujinx.Core.OsHle.Ipc;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2018-03-20 13:00:00 -07:00
|
|
|
namespace Ryujinx.Core.OsHle.Services.Time
|
2018-02-25 10:58:16 -08:00
|
|
|
{
|
2018-03-19 11:58:46 -07:00
|
|
|
class ITimeZoneService : IpcService
|
2018-02-25 10:58:16 -08:00
|
|
|
{
|
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
|
|
|
|
2018-03-19 11:58:46 -07:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
2018-02-25 10:58:16 -08:00
|
|
|
|
2018-04-10 17:16:27 -07:00
|
|
|
private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
2018-02-25 10:58:16 -08:00
|
|
|
|
|
|
|
public ITimeZoneService()
|
|
|
|
{
|
|
|
|
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
|
|
|
{
|
2018-04-24 11:57:39 -07:00
|
|
|
{ 0, GetDeviceLocationName },
|
2018-04-21 21:21:49 -07:00
|
|
|
{ 101, ToCalendarTimeWithMyRule }
|
2018-02-25 10:58:16 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-21 21:21:49 -07:00
|
|
|
public long GetDeviceLocationName(ServiceCtx Context)
|
|
|
|
{
|
2018-04-24 11:57:39 -07:00
|
|
|
Context.Ns.Log.PrintStub(LogClass.ServiceTime, "Stubbed.");
|
2018-04-21 21:21:49 -07:00
|
|
|
|
|
|
|
for (int Index = 0; Index < 0x24; Index++)
|
|
|
|
{
|
|
|
|
Context.ResponseData.Write((byte)0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-25 10:58:16 -08:00
|
|
|
public long ToCalendarTimeWithMyRule(ServiceCtx Context)
|
|
|
|
{
|
|
|
|
long PosixTime = Context.RequestData.ReadInt64();
|
|
|
|
|
2018-04-10 17:16:27 -07:00
|
|
|
DateTime CurrentTime = Epoch.AddSeconds(PosixTime).ToLocalTime();
|
2018-02-25 10:58:16 -08:00
|
|
|
|
2018-04-10 17:18:20 -07:00
|
|
|
Context.ResponseData.Write((ushort)CurrentTime.Year);
|
|
|
|
Context.ResponseData.Write((byte)CurrentTime.Month);
|
|
|
|
Context.ResponseData.Write((byte)CurrentTime.Day);
|
|
|
|
Context.ResponseData.Write((byte)CurrentTime.Hour);
|
|
|
|
Context.ResponseData.Write((byte)CurrentTime.Minute);
|
|
|
|
Context.ResponseData.Write((byte)CurrentTime.Second);
|
2018-02-25 10:58:16 -08:00
|
|
|
Context.ResponseData.Write((byte)0);
|
|
|
|
|
|
|
|
/* Thanks to TuxSH
|
|
|
|
struct CalendarAdditionalInfo {
|
|
|
|
u32 tm_wday; //day of week [0,6] (Sunday = 0)
|
|
|
|
s32 tm_yday; //day of year [0,365]
|
|
|
|
struct timezone {
|
|
|
|
char[8] tz_name;
|
|
|
|
bool isDaylightSavingTime;
|
|
|
|
s32 utcOffsetSeconds;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
*/
|
2018-04-10 17:18:20 -07:00
|
|
|
Context.ResponseData.Write((int)CurrentTime.DayOfWeek);
|
2018-04-10 17:16:27 -07:00
|
|
|
|
2018-04-24 11:57:39 -07:00
|
|
|
Context.ResponseData.Write(CurrentTime.DayOfYear - 1);
|
2018-04-10 17:16:27 -07:00
|
|
|
|
|
|
|
//TODO: Find out the names used.
|
2018-02-25 10:58:16 -08:00
|
|
|
Context.ResponseData.Write(new byte[8]);
|
2018-04-10 17:16:27 -07:00
|
|
|
|
2018-04-10 17:18:20 -07:00
|
|
|
Context.ResponseData.Write((byte)(CurrentTime.IsDaylightSavingTime() ? 1 : 0));
|
2018-04-10 17:16:27 -07:00
|
|
|
|
2018-04-10 17:18:20 -07:00
|
|
|
Context.ResponseData.Write((int)TimeZoneInfo.Local.GetUtcOffset(CurrentTime).TotalSeconds);
|
2018-02-25 10:58:16 -08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|