internal ResultCode LoadTimeZoneRule(out TimeZoneRule outRules, string locationName) { outRules = new TimeZoneRule { Ats = new long[TzMaxTimes], Types = new byte[TzMaxTimes], Ttis = new TimeTypeInfo[TzMaxTypes], Chars = new char[TzCharsArraySize] }; if (!HasTimeZoneBinaryTitle()) { throw new InvalidSystemResourceException($"TimeZoneBinary system title not found! Please provide it. (See https://github.com/Ryujinx/Ryujinx#requirements for more informations)"); } ResultCode result = GetTimeZoneBinary(locationName, out Stream timeZoneBinaryStream, out LocalStorage ncaFile); if (result == ResultCode.Success) { result = Manager.ParseTimeZoneRuleBinary(out outRules, timeZoneBinaryStream); ncaFile.Dispose(); } return(result); }
internal ResultCode LoadTimeZoneRule(out TimeZoneRule outRules, string locationName) { outRules = new TimeZoneRule { Ats = new long[TzMaxTimes], Types = new byte[TzMaxTimes], Ttis = new TimeTypeInfo[TzMaxTypes], Chars = new char[TzCharsArraySize] }; if (!HasTimeZoneBinaryTitle()) { throw new InvalidSystemResourceException(TimeZoneSystemTitleMissingErrorMessage); } ResultCode result = GetTimeZoneBinary(locationName, out Stream timeZoneBinaryStream, out LocalStorage ncaFile); if (result == ResultCode.Success) { result = Manager.ParseTimeZoneRuleBinary(out outRules, timeZoneBinaryStream); ncaFile.Dispose(); } return(result); }
internal ResultCode LoadTimeZoneRules(out TimeZoneRule outRules, string locationName) { outRules = new TimeZoneRule { Ats = new long[TzMaxTimes], Types = new byte[TzMaxTimes], Ttis = new TimeTypeInfo[TzMaxTypes], Chars = new char[TzCharsArraySize] }; if (!IsLocationNameValid(locationName)) { return(ResultCode.TimeZoneNotFound); } if (!HasTimeZoneBinaryTitle()) { // If the user doesn't have the system archives, we generate a POSIX rule string and parse it to generate a incomplete TimeZoneRule // TODO: As for now not having system archives is fine, we should enforce the usage of system archives later. Logger.PrintWarning(LogClass.ServiceTime, "TimeZoneBinary system archive not found! Time conversions will not be accurate!"); try { TimeZoneInfo info = TZConvert.GetTimeZoneInfo(locationName); string posixRule = PosixTimeZone.FromTimeZoneInfo(info); if (!TimeZone.ParsePosixName(posixRule, out outRules)) { return(ResultCode.TimeZoneConversionFailed); } return(0); } catch (TimeZoneNotFoundException) { Logger.PrintWarning(LogClass.ServiceTime, $"Timezone not found for string: {locationName})"); return(ResultCode.TimeZoneNotFound); } } else { using (IStorage ncaFileStream = new LocalStorage(_device.FileSystem.SwitchPathToSystemPath(GetTimeZoneBinaryTitleContentPath()), FileAccess.Read, FileMode.Open)) { Nca nca = new Nca(_device.System.KeySet, ncaFileStream); IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel); Stream tzIfStream = romfs.OpenFile($"zoneinfo/{locationName}", OpenMode.Read).AsStream(); if (!TimeZone.LoadTimeZoneRules(out outRules, tzIfStream)) { return(ResultCode.TimeZoneConversionFailed); } } return(0); } }
internal static ResultCode ToPosixTime(TimeZoneRule rules, CalendarTime calendarTime, out long posixTime) { ResultCode error = TimeZone.ToPosixTime(rules, calendarTime, out posixTime); if (error != ResultCode.Success) { return(error); } return(ResultCode.Success); }
internal static ResultCode ToCalendarTime(TimeZoneRule rules, long time, out CalendarInfo calendar) { ResultCode error = TimeZone.ToCalendarTime(rules, time, out calendar); if (error != ResultCode.Success) { return(error); } return(ResultCode.Success); }
public ResultCode ToPosixTime(TimeZoneRule rules, CalendarTime calendarTime, out long posixTime) { ResultCode result; lock (_lock) { result = TimeZone.ToPosixTime(rules, calendarTime, out posixTime); } return(result); }
public ResultCode ToCalendarTime(TimeZoneRule rules, long time, out CalendarInfo calendar) { ResultCode result; lock (_lock) { result = TimeZone.ToCalendarTime(rules, time, out calendar); } return(result); }
internal static uint ToPosixTime(TimeZoneRule rules, CalendarTime calendarTime, out long posixTime) { int error = TimeZone.ToPosixTime(rules, calendarTime, out posixTime); if (error != 0) { return(MakeError(ErrorModule.Time, error)); } return(0); }
internal static uint ToCalendarTime(TimeZoneRule rules, long time, out CalendarInfo calendar) { int error = TimeZone.ToCalendarTime(rules, time, out calendar); if (error != 0) { return(MakeError(ErrorModule.Time, error)); } return(0); }
public ResultCode SetDeviceLocationName(string locationName) { ResultCode resultCode = LoadTimeZoneRules(out TimeZoneRule rules, locationName); if (resultCode == 0) { _myRules = rules; _deviceLocationName = locationName; } return(resultCode); }
TimeZoneManager() { // Empty rules (UTC) _myRules = new TimeZoneRule { Ats = new long[TzMaxTimes], Types = new byte[TzMaxTimes], Ttis = new TimeTypeInfo[TzMaxTypes], Chars = new char[TzCharsArraySize] }; _deviceLocationName = "UTC"; }
public ResultCode ParseTimeZoneRuleBinary(out TimeZoneRule outRules, Stream timeZoneBinaryStream) { ResultCode result = ResultCode.Success; lock (_lock) { bool timeZoneConversionSuccess = TimeZone.ParseTimeZoneBinary(out outRules, timeZoneBinaryStream); if (!timeZoneConversionSuccess) { result = ResultCode.TimeZoneConversionFailed; } } return(result); }
public ResultCode SetDeviceLocationNameWithTimeZoneRule(string locationName, Stream timeZoneBinaryStream) { ResultCode result = ResultCode.TimeZoneConversionFailed; lock (_lock) { bool timeZoneConversionSuccess = TimeZone.ParseTimeZoneBinary(out TimeZoneRule rules, timeZoneBinaryStream); if (timeZoneConversionSuccess) { _deviceLocationName = locationName; _myRules = rules; result = ResultCode.Success; } } return(result); }
public TimeZoneManager() { _isInitialized = false; _deviceLocationName = "UTC"; _timeZoneRuleVersion = new UInt128(); _lock = new object(); // Empty rules _myRules = new TimeZoneRule { Ats = new long[TzMaxTimes], Types = new byte[TzMaxTimes], Ttis = new TimeTypeInfo[TzMaxTypes], Chars = new char[TzCharsArraySize] }; _timeZoneUpdateTimePoint = SteadyClockTimePoint.GetRandom(); }