ITimeZoneService.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Ryujinx.Core.OsHle.Ipc;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace Ryujinx.Core.OsHle.Services.Time
  5. {
  6. class ITimeZoneService : IpcService
  7. {
  8. private Dictionary<int, ServiceProcessRequest> m_Commands;
  9. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  10. private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
  11. public ITimeZoneService()
  12. {
  13. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  14. {
  15. { 0, GetDeviceLocationName },
  16. { 101, ToCalendarTimeWithMyRule }
  17. };
  18. }
  19. public long GetDeviceLocationName(ServiceCtx Context)
  20. {
  21. Logging.Stub(LogClass.ServiceTime, "Stubbed");
  22. for (int Index = 0; Index < 0x24; Index++)
  23. {
  24. Context.ResponseData.Write((byte)0);
  25. }
  26. return 0;
  27. }
  28. public long ToCalendarTimeWithMyRule(ServiceCtx Context)
  29. {
  30. long PosixTime = Context.RequestData.ReadInt64();
  31. DateTime CurrentTime = Epoch.AddSeconds(PosixTime).ToLocalTime();
  32. Context.ResponseData.Write((ushort)CurrentTime.Year);
  33. Context.ResponseData.Write((byte)CurrentTime.Month);
  34. Context.ResponseData.Write((byte)CurrentTime.Day);
  35. Context.ResponseData.Write((byte)CurrentTime.Hour);
  36. Context.ResponseData.Write((byte)CurrentTime.Minute);
  37. Context.ResponseData.Write((byte)CurrentTime.Second);
  38. Context.ResponseData.Write((byte)0);
  39. /* Thanks to TuxSH
  40. struct CalendarAdditionalInfo {
  41. u32 tm_wday; //day of week [0,6] (Sunday = 0)
  42. s32 tm_yday; //day of year [0,365]
  43. struct timezone {
  44. char[8] tz_name;
  45. bool isDaylightSavingTime;
  46. s32 utcOffsetSeconds;
  47. };
  48. };
  49. */
  50. Context.ResponseData.Write((int)CurrentTime.DayOfWeek);
  51. Context.ResponseData.Write(CurrentTime.DayOfYear);
  52. //TODO: Find out the names used.
  53. Context.ResponseData.Write(new byte[8]);
  54. Context.ResponseData.Write((byte)(CurrentTime.IsDaylightSavingTime() ? 1 : 0));
  55. Context.ResponseData.Write((int)TimeZoneInfo.Local.GetUtcOffset(CurrentTime).TotalSeconds);
  56. return 0;
  57. }
  58. }
  59. }