2018-02-25 19:58:16 +01:00
|
|
|
using Ryujinx.Core.OsHle.Ipc;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2018-03-20 21:00:00 +01:00
|
|
|
namespace Ryujinx.Core.OsHle.Services.Time
|
2018-02-25 19:58:16 +01:00
|
|
|
{
|
2018-03-19 19:58:46 +01:00
|
|
|
class ITimeZoneService : IpcService
|
2018-02-25 19:58:16 +01:00
|
|
|
{
|
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
|
|
|
|
2018-03-19 19:58:46 +01:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
2018-02-25 19:58:16 +01:00
|
|
|
|
2018-04-11 02:16:27 +02:00
|
|
|
private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
2018-02-25 19:58:16 +01:00
|
|
|
|
|
|
|
public ITimeZoneService()
|
|
|
|
{
|
|
|
|
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
|
|
|
{
|
|
|
|
{ 101, ToCalendarTimeWithMyRule }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public long ToCalendarTimeWithMyRule(ServiceCtx Context)
|
|
|
|
{
|
|
|
|
long PosixTime = Context.RequestData.ReadInt64();
|
|
|
|
|
2018-04-11 02:16:27 +02:00
|
|
|
DateTime CurrentTime = Epoch.AddSeconds(PosixTime).ToLocalTime();
|
2018-02-25 19:58:16 +01:00
|
|
|
|
2018-04-11 02:16:27 +02:00
|
|
|
Context.ResponseData.Write((ushort)Epoch.Year);
|
2018-02-25 19:58:16 +01:00
|
|
|
Context.ResponseData.Write((byte)Epoch.Month);
|
|
|
|
Context.ResponseData.Write((byte)Epoch.Day);
|
|
|
|
Context.ResponseData.Write((byte)Epoch.Hour);
|
|
|
|
Context.ResponseData.Write((byte)Epoch.Minute);
|
|
|
|
Context.ResponseData.Write((byte)Epoch.Second);
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
Context.ResponseData.Write((int)Epoch.DayOfWeek);
|
2018-04-11 02:16:27 +02:00
|
|
|
|
2018-02-25 19:58:16 +01:00
|
|
|
Context.ResponseData.Write(Epoch.DayOfYear);
|
2018-04-11 02:16:27 +02:00
|
|
|
|
|
|
|
//TODO: Find out the names used.
|
2018-02-25 19:58:16 +01:00
|
|
|
Context.ResponseData.Write(new byte[8]);
|
2018-04-11 02:16:27 +02:00
|
|
|
|
|
|
|
Context.ResponseData.Write((byte)(Epoch.IsDaylightSavingTime() ? 1 : 0));
|
|
|
|
|
|
|
|
Context.ResponseData.Write((int)TimeZoneInfo.Local.GetUtcOffset(Epoch).TotalSeconds);
|
2018-02-25 19:58:16 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|