コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: TimeZoneManager.cs プロジェクト: Furtif/Ryujinx
        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);
            }
        }
コード例 #4
0
ファイル: TimeZoneManager.cs プロジェクト: Furtif/Ryujinx
        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);
        }
コード例 #5
0
ファイル: TimeZoneManager.cs プロジェクト: Furtif/Ryujinx
        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);
        }
コード例 #6
0
ファイル: TimeZoneManager.cs プロジェクト: ianuub/Ryujinxxx
        public ResultCode ToPosixTime(TimeZoneRule rules, CalendarTime calendarTime, out long posixTime)
        {
            ResultCode result;

            lock (_lock)
            {
                result = TimeZone.ToPosixTime(rules, calendarTime, out posixTime);
            }

            return(result);
        }
コード例 #7
0
ファイル: TimeZoneManager.cs プロジェクト: ianuub/Ryujinxxx
        public ResultCode ToCalendarTime(TimeZoneRule rules, long time, out CalendarInfo calendar)
        {
            ResultCode result;

            lock (_lock)
            {
                result = TimeZone.ToCalendarTime(rules, time, out calendar);
            }

            return(result);
        }
コード例 #8
0
ファイル: TimeZoneManager.cs プロジェクト: amaron2/Ryujinx
        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);
        }
コード例 #9
0
ファイル: TimeZoneManager.cs プロジェクト: amaron2/Ryujinx
        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);
        }
コード例 #10
0
ファイル: TimeZoneManager.cs プロジェクト: Furtif/Ryujinx
        public ResultCode SetDeviceLocationName(string locationName)
        {
            ResultCode resultCode = LoadTimeZoneRules(out TimeZoneRule rules, locationName);

            if (resultCode == 0)
            {
                _myRules            = rules;
                _deviceLocationName = locationName;
            }

            return(resultCode);
        }
コード例 #11
0
ファイル: TimeZoneManager.cs プロジェクト: Furtif/Ryujinx
        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";
        }
コード例 #12
0
ファイル: TimeZoneManager.cs プロジェクト: ianuub/Ryujinxxx
        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);
        }
コード例 #13
0
ファイル: TimeZoneManager.cs プロジェクト: ianuub/Ryujinxxx
        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);
        }
コード例 #14
0
ファイル: TimeZoneManager.cs プロジェクト: ianuub/Ryujinxxx
        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();
        }