diff options
| author | Ac_K <Acoustik666@gmail.com> | 2019-07-14 21:04:38 +0200 |
|---|---|---|
| committer | gdkchan <gab.dark.100@gmail.com> | 2019-07-14 16:04:38 -0300 |
| commit | 4ad3936afd4ca393a05b330e3848958e9598e910 (patch) | |
| tree | e0b3bc963230d3ea3d6cc57b5bc6caeba9233479 /Ryujinx.HLE/HOS/Services/Time/TimeZone | |
| parent | 4926f6523d3130879e108403979ab68f1212f544 (diff) | |
Refactoring result codes (#731)
* refactoring result codes
- Add a main enum who can handle some orphalin result codes and the default `ResultCode.Success` one.
- Add sub-enum by services when it's needed.
- Remove some empty line.
- Recast all service calls to ResultCode.
- Remove some unneeded static declaration.
- Delete unused `NvHelper` class.
* NvResult is back
* Fix
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Time/TimeZone')
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZone.cs | 56 | ||||
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneManager.cs | 47 |
2 files changed, 51 insertions, 52 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZone.cs b/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZone.cs index 8039dc89..4898b2b9 100644 --- a/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZone.cs +++ b/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZone.cs @@ -1237,7 +1237,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone } } - private static int CreateCalendarTime(long time, int gmtOffset, out CalendarTimeInternal calendarTime, out CalendarAdditionalInfo calendarAdditionalInfo) + private static ResultCode CreateCalendarTime(long time, int gmtOffset, out CalendarTimeInternal calendarTime, out CalendarAdditionalInfo calendarAdditionalInfo) { long year = EpochYear; long timeDays = time / SecondsPerDay; @@ -1263,7 +1263,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (IncrementOverflow64(ref newYear, delta)) { - return TimeError.OutOfRange; + return ResultCode.OutOfRange; } long leapDays = GetLeapDays(newYear - 1) - GetLeapDays(year - 1); @@ -1290,7 +1290,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { if (IncrementOverflow64(ref year, -1)) { - return TimeError.OutOfRange; + return ResultCode.OutOfRange; } dayOfYear += YearLengths[IsLeap((int)year)]; @@ -1302,7 +1302,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (IncrementOverflow64(ref year, 1)) { - return TimeError.OutOfRange; + return ResultCode.OutOfRange; } } @@ -1340,7 +1340,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone return 0; } - private static int ToCalendarTimeInternal(TimeZoneRule rules, long time, out CalendarTimeInternal calendarTime, out CalendarAdditionalInfo calendarAdditionalInfo) + private static ResultCode ToCalendarTimeInternal(TimeZoneRule rules, long time, out CalendarTimeInternal calendarTime, out CalendarAdditionalInfo calendarAdditionalInfo) { calendarTime = new CalendarTimeInternal(); calendarAdditionalInfo = new CalendarAdditionalInfo() @@ -1348,7 +1348,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone TimezoneName = new char[8] }; - int result; + ResultCode result; if ((rules.GoAhead && time < rules.Ats[0]) || (rules.GoBack && time > rules.Ats[rules.TimeCount - 1])) { @@ -1382,7 +1382,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (newTime < rules.Ats[0] && newTime > rules.Ats[rules.TimeCount - 1]) { - return TimeError.TimeNotFound; + return ResultCode.TimeNotFound; } result = ToCalendarTimeInternal(rules, newTime, out calendarTime, out calendarAdditionalInfo); @@ -1400,7 +1400,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone calendarTime.Year += years; } - return 0; + return ResultCode.Success; } int ttiIndex; @@ -1453,7 +1453,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone return result; } - private static int ToPosixTimeInternal(TimeZoneRule rules, CalendarTimeInternal calendarTime, out long posixTime) + private static ResultCode ToPosixTimeInternal(TimeZoneRule rules, CalendarTimeInternal calendarTime, out long posixTime) { posixTime = 0; @@ -1462,7 +1462,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (NormalizeOverflow32(ref hour, ref minute, MinutesPerHour)) { - return TimeError.Overflow; + return ResultCode.Overflow; } calendarTime.Minute = (sbyte)minute; @@ -1470,7 +1470,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone int day = calendarTime.Day; if (NormalizeOverflow32(ref day, ref hour, HoursPerDays)) { - return TimeError.Overflow; + return ResultCode.Overflow; } calendarTime.Day = (sbyte)day; @@ -1481,21 +1481,21 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (NormalizeOverflow64(ref year, ref month, MonthsPerYear)) { - return TimeError.Overflow; + return ResultCode.Overflow; } calendarTime.Month = (sbyte)month; if (IncrementOverflow64(ref year, YearBase)) { - return TimeError.Overflow; + return ResultCode.Overflow; } while (day <= 0) { if (IncrementOverflow64(ref year, -1)) { - return TimeError.Overflow; + return ResultCode.Overflow; } long li = year; @@ -1521,7 +1521,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (IncrementOverflow64(ref year, 1)) { - return TimeError.Overflow; + return ResultCode.Overflow; } } @@ -1542,7 +1542,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone calendarTime.Month = 0; if (IncrementOverflow64(ref year, 1)) { - return TimeError.Overflow; + return ResultCode.Overflow; } } } @@ -1551,7 +1551,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (IncrementOverflow64(ref year, -YearBase)) { - return TimeError.Overflow; + return ResultCode.Overflow; } calendarTime.Year = year; @@ -1567,7 +1567,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone int second = calendarTime.Second; if (IncrementOverflow32(ref second, 1 - SecondsPerMinute)) { - return TimeError.Overflow; + return ResultCode.Overflow; } savedSeconds = second; @@ -1597,7 +1597,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone int direction; - int result = ToCalendarTimeInternal(rules, pivot, out CalendarTimeInternal candidateCalendarTime, out _); + ResultCode result = ToCalendarTimeInternal(rules, pivot, out CalendarTimeInternal candidateCalendarTime, out _); if (result != 0) { if (pivot > 0) @@ -1620,7 +1620,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if ((timeResult < pivot) != (savedSeconds < 0)) { - return TimeError.Overflow; + return ResultCode.Overflow; } posixTime = timeResult; @@ -1632,7 +1632,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { if (pivot == long.MaxValue) { - return TimeError.TimeNotFound; + return ResultCode.TimeNotFound; } pivot += 1; @@ -1642,7 +1642,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { if (pivot == long.MinValue) { - return TimeError.TimeNotFound; + return ResultCode.TimeNotFound; } pivot -= 1; @@ -1651,7 +1651,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (low > high) { - return TimeError.TimeNotFound; + return ResultCode.TimeNotFound; } if (direction > 0) @@ -1665,12 +1665,12 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone } } - return 0; + return ResultCode.Success; } - internal static int ToCalendarTime(TimeZoneRule rules, long time, out CalendarInfo calendar) + internal static ResultCode ToCalendarTime(TimeZoneRule rules, long time, out CalendarInfo calendar) { - int result = ToCalendarTimeInternal(rules, time, out CalendarTimeInternal calendarTime, out CalendarAdditionalInfo calendarAdditionalInfo); + ResultCode result = ToCalendarTimeInternal(rules, time, out CalendarTimeInternal calendarTime, out CalendarAdditionalInfo calendarAdditionalInfo); calendar = new CalendarInfo() { @@ -1689,7 +1689,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone return result; } - internal static int ToPosixTime(TimeZoneRule rules, CalendarTime calendarTime, out long posixTime) + internal static ResultCode ToPosixTime(TimeZoneRule rules, CalendarTime calendarTime, out long posixTime) { CalendarTimeInternal calendarTimeInternal = new CalendarTimeInternal() { @@ -1704,4 +1704,4 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone return ToPosixTimeInternal(rules, calendarTimeInternal, out posixTime); } } -} +}
\ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneManager.cs b/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneManager.cs index b3dc4c34..cf27639b 100644 --- a/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneManager.cs +++ b/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneManager.cs @@ -10,7 +10,6 @@ using TimeZoneConverter.Posix; using TimeZoneConverter; using static Ryujinx.HLE.HOS.Services.Time.TimeZoneRule; -using static Ryujinx.HLE.HOS.ErrorCode; namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { @@ -138,9 +137,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone return _deviceLocationName; } - public uint SetDeviceLocationName(string locationName) + public ResultCode SetDeviceLocationName(string locationName) { - uint resultCode = LoadTimeZoneRules(out TimeZoneRule rules, locationName); + ResultCode resultCode = LoadTimeZoneRules(out TimeZoneRule rules, locationName); if (resultCode == 0) { @@ -151,7 +150,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone return resultCode; } - public uint LoadLocationNameList(uint index, out string[] outLocationNameArray, uint maxLength) + public ResultCode LoadLocationNameList(uint index, out string[] outLocationNameArray, uint maxLength) { List<string> locationNameList = new List<string>(); @@ -169,7 +168,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { outLocationNameArray = new string[0]; - return MakeError(ErrorModule.Time, TimeError.LocationNameTooLong); + return ResultCode.LocationNameTooLong; } locationNameList.Add(locationName); @@ -177,7 +176,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone outLocationNameArray = locationNameList.ToArray(); - return 0; + return ResultCode.Success; } public uint GetTotalLocationNameCount() @@ -195,7 +194,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone return !string.IsNullOrEmpty(GetTimeZoneBinaryTitleContentPath()); } - internal uint LoadTimeZoneRules(out TimeZoneRule outRules, string locationName) + internal ResultCode LoadTimeZoneRules(out TimeZoneRule outRules, string locationName) { outRules = new TimeZoneRule { @@ -207,7 +206,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (!IsLocationNameValid(locationName)) { - return MakeError(ErrorModule.Time, TimeError.TimeZoneNotFound); + return ResultCode.TimeZoneNotFound; } if (!HasTimeZoneBinaryTitle()) @@ -222,7 +221,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (!TimeZone.ParsePosixName(posixRule, out outRules)) { - return MakeError(ErrorModule.Time, TimeError.TimeZoneConversionFailed); + return ResultCode.TimeZoneConversionFailed; } return 0; @@ -231,7 +230,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { Logger.PrintWarning(LogClass.ServiceTime, $"Timezone not found for string: {locationName})"); - return MakeError(ErrorModule.Time, TimeError.TimeZoneNotFound); + return ResultCode.TimeZoneNotFound; } } else @@ -244,7 +243,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (!TimeZone.LoadTimeZoneRules(out outRules, tzIfStream)) { - return MakeError(ErrorModule.Time, TimeError.TimeZoneConversionFailed); + return ResultCode.TimeZoneConversionFailed; } } @@ -252,38 +251,38 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone } } - internal uint ToCalendarTimeWithMyRules(long time, out CalendarInfo calendar) + internal ResultCode ToCalendarTimeWithMyRules(long time, out CalendarInfo calendar) { return ToCalendarTime(_myRules, time, out calendar); } - internal static uint ToCalendarTime(TimeZoneRule rules, long time, out CalendarInfo calendar) + internal static ResultCode ToCalendarTime(TimeZoneRule rules, long time, out CalendarInfo calendar) { - int error = TimeZone.ToCalendarTime(rules, time, out calendar); + ResultCode error = TimeZone.ToCalendarTime(rules, time, out calendar); - if (error != 0) + if (error != ResultCode.Success) { - return MakeError(ErrorModule.Time, error); + return error; } - return 0; + return ResultCode.Success; } - internal uint ToPosixTimeWithMyRules(CalendarTime calendarTime, out long posixTime) + internal ResultCode ToPosixTimeWithMyRules(CalendarTime calendarTime, out long posixTime) { return ToPosixTime(_myRules, calendarTime, out posixTime); } - internal static uint ToPosixTime(TimeZoneRule rules, CalendarTime calendarTime, out long posixTime) + internal static ResultCode ToPosixTime(TimeZoneRule rules, CalendarTime calendarTime, out long posixTime) { - int error = TimeZone.ToPosixTime(rules, calendarTime, out posixTime); + ResultCode error = TimeZone.ToPosixTime(rules, calendarTime, out posixTime); - if (error != 0) + if (error != ResultCode.Success) { - return MakeError(ErrorModule.Time, error); + return error; } - return 0; + return ResultCode.Success; } } -} +}
\ No newline at end of file |
