From aa932a6df1764b7c600ae0ba4e0c7a0ba802f312 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Thu, 23 Dec 2021 09:55:50 -0700 Subject: Update to LibHac v0.14.3 (#2925) * Update to LibHac v0.14.3 * Fix loading NCAs that don't have a data partition --- .../Time/TimeZone/TimeZoneContentManager.cs | 63 +++++++++++----------- 1 file changed, 33 insertions(+), 30 deletions(-) (limited to 'Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneContentManager.cs') diff --git a/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneContentManager.cs b/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneContentManager.cs index 963ea9fd..4a27bb5f 100644 --- a/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneContentManager.cs +++ b/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneContentManager.cs @@ -91,9 +91,11 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFileStream); IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _fsIntegrityCheckLevel); - romfs.OpenFile(out IFile binaryListFile, "/binaryList.txt".ToU8Span(), OpenMode.Read).ThrowIfFailure(); + using var binaryListFile = new UniqueRef(); - StreamReader reader = new StreamReader(binaryListFile.AsStream()); + romfs.OpenFile(ref binaryListFile.Ref(), "/binaryList.txt".ToU8Span(), OpenMode.Read).ThrowIfFailure(); + + StreamReader reader = new StreamReader(binaryListFile.Get.AsStream()); List locationNameList = new List(); @@ -135,44 +137,43 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone continue; } - if (romfs.OpenFile(out IFile tzif, $"/zoneinfo/{locName}".ToU8Span(), OpenMode.Read).IsFailure()) + using var tzif = new UniqueRef(); + + if (romfs.OpenFile(ref tzif.Ref(), $"/zoneinfo/{locName}".ToU8Span(), OpenMode.Read).IsFailure()) { Logger.Error?.Print(LogClass.ServiceTime, $"Error opening /zoneinfo/{locName}"); continue; } - using (tzif) - { - TimeZone.ParseTimeZoneBinary(out TimeZoneRule tzRule, tzif.AsStream()); + TimeZone.ParseTimeZoneBinary(out TimeZoneRule tzRule, tzif.Get.AsStream()); - TimeTypeInfo ttInfo; - if (tzRule.TimeCount > 0) // Find the current transition period + TimeTypeInfo ttInfo; + if (tzRule.TimeCount > 0) // Find the current transition period + { + int fin = 0; + for (int i = 0; i < tzRule.TimeCount; ++i) { - int fin = 0; - for (int i = 0; i < tzRule.TimeCount; ++i) + if (tzRule.Ats[i] <= now) { - if (tzRule.Ats[i] <= now) - { - fin = i; - } + fin = i; } - ttInfo = tzRule.Ttis[tzRule.Types[fin]]; - } - else if (tzRule.TypeCount >= 1) // Otherwise, use the first offset in TTInfo - { - ttInfo = tzRule.Ttis[0]; - } - else - { - Logger.Error?.Print(LogClass.ServiceTime, $"Couldn't find UTC offset for zone {locName}"); - continue; } + ttInfo = tzRule.Ttis[tzRule.Types[fin]]; + } + else if (tzRule.TypeCount >= 1) // Otherwise, use the first offset in TTInfo + { + ttInfo = tzRule.Ttis[0]; + } + else + { + Logger.Error?.Print(LogClass.ServiceTime, $"Couldn't find UTC offset for zone {locName}"); + continue; + } - var abbrStart = tzRule.Chars.AsSpan(ttInfo.AbbreviationListIndex); - int abbrEnd = abbrStart.IndexOf('\0'); + var abbrStart = tzRule.Chars.AsSpan(ttInfo.AbbreviationListIndex); + int abbrEnd = abbrStart.IndexOf('\0'); - outList.Add((ttInfo.GmtOffset, locName, abbrStart.Slice(0, abbrEnd).ToString())); - } + outList.Add((ttInfo.GmtOffset, locName, abbrStart.Slice(0, abbrEnd).ToString())); } } @@ -262,9 +263,11 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile); IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _fsIntegrityCheckLevel); - Result result = romfs.OpenFile(out IFile timeZoneBinaryFile, $"/zoneinfo/{locationName}".ToU8Span(), OpenMode.Read); + using var timeZoneBinaryFile = new UniqueRef(); + + Result result = romfs.OpenFile(ref timeZoneBinaryFile.Ref(), $"/zoneinfo/{locationName}".ToU8Span(), OpenMode.Read); - timeZoneBinaryStream = timeZoneBinaryFile.AsStream(); + timeZoneBinaryStream = timeZoneBinaryFile.Release().AsStream(); return (ResultCode)result.Value; } -- cgit v1.2.3