Address comments

This commit is contained in:
Thog 2019-07-03 19:40:11 +02:00
commit 32d3fc8df5
No known key found for this signature in database
GPG key ID: 0CD291558FAFDBC6
2 changed files with 26 additions and 30 deletions

View file

@ -412,12 +412,10 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
Chars = new char[TzCharsArraySize] Chars = new char[TzCharsArraySize]
}; };
int stdLen; int stdLen;
Span<char> stdName = name;
int namePosition = 0; int namePosition = 0;
int stdOffset = 0;
Span<char> stdName = name;
int stdOffset = 0;
if (lastDitch) if (lastDitch)
{ {
@ -462,7 +460,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
} }
} }
int charCount = (int)stdLen + 1; int charCount = stdLen + 1;
int destLen = 0; int destLen = 0;
int dstOffset = 0; int dstOffset = 0;
@ -572,10 +570,10 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
outRules.DefaultType = 0; outRules.DefaultType = 0;
int timeCount = 0; int timeCount = 0;
long janFirst = 0; long janFirst = 0;
int janOffset = 0; int janOffset = 0;
int yearBegining = EpochYear; int yearBegining = EpochYear;
do do
{ {
@ -1079,29 +1077,29 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
} }
long position = (p - workBufferPtrStart); long position = (p - workBufferPtrStart);
long nread = streamLength - position; long nRead = streamLength - position;
if (nread < 0) if (nRead < 0)
{ {
return false; return false;
} }
// Nintendo abort in case of a TzIf file with a POSIX TZ Name too long to fit inside a TimeZoneRule. // Nintendo abort in case of a TzIf file with a POSIX TZ Name too long to fit inside a TimeZoneRule.
// As it's impossible in normal usage to achive this, we also force a crash. // As it's impossible in normal usage to achive this, we also force a crash.
if (nread > (TzNameMax + 1)) if (nRead > (TzNameMax + 1))
{ {
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
char[] tempName = new char[TzNameMax + 1]; char[] tempName = new char[TzNameMax + 1];
Array.Copy(workBuffer, position, tempName, 0, nread); Array.Copy(workBuffer, position, tempName, 0, nRead);
if (nread > 2 && tempName[0] == '\n' && tempName[nread - 1] == '\n' && outRules.TypeCount + 2 <= TzMaxTypes) if (nRead > 2 && tempName[0] == '\n' && tempName[nRead - 1] == '\n' && outRules.TypeCount + 2 <= TzMaxTypes)
{ {
tempName[nread - 1] = '\0'; tempName[nRead - 1] = '\0';
char[] name = new char[TzNameMax]; char[] name = new char[TzNameMax];
Array.Copy(tempName, 1, name, 0, nread - 1); Array.Copy(tempName, 1, name, 0, nRead - 1);
if (ParsePosixName(name, out TimeZoneRule tempRules, false)) if (ParsePosixName(name, out TimeZoneRule tempRules, false))
{ {
@ -1381,7 +1379,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
TimezoneName = new char[8] TimezoneName = new char[8]
}; };
int result = 0; int result;
if ((rules.GoAhead && time < rules.Ats[0]) || (rules.GoBack && time > rules.Ats[rules.TimeCount - 1])) if ((rules.GoAhead && time < rules.Ats[0]) || (rules.GoBack && time > rules.Ats[rules.TimeCount - 1]))
{ {

View file

@ -22,15 +22,13 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
private static object instanceLock = new object(); private static object instanceLock = new object();
private Switch _device; private Switch _device;
private TimeZoneRule _myRules; private TimeZoneRule _myRules;
private string _deviceLocationName; private string _deviceLocationName;
private string[] _locationNameCache; private string[] _locationNameCache;
TimeZoneManager() TimeZoneManager()
{ {
_device = null;
// Empty rules (UTC) // Empty rules (UTC)
_myRules = new TimeZoneRule _myRules = new TimeZoneRule
{ {
@ -56,9 +54,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
{ {
using (IStorage ncaFileStream = new LocalStorage(_device.FileSystem.SwitchPathToSystemPath(GetTimeZoneBinaryTitleContentPath()), FileAccess.Read, FileMode.Open)) using (IStorage ncaFileStream = new LocalStorage(_device.FileSystem.SwitchPathToSystemPath(GetTimeZoneBinaryTitleContentPath()), FileAccess.Read, FileMode.Open))
{ {
Nca nca = new Nca(_device.System.KeySet, ncaFileStream); Nca nca = new Nca(_device.System.KeySet, ncaFileStream);
IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel); IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel);
Stream binaryListStream = romfs.OpenFile("binaryList.txt", OpenMode.Read).AsStream(); Stream binaryListStream = romfs.OpenFile("binaryList.txt", OpenMode.Read).AsStream();
StreamReader reader = new StreamReader(binaryListStream); StreamReader reader = new StreamReader(binaryListStream);
@ -96,8 +94,8 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
// As we aren't using the system archive, "UTC" might not exist on the host system. // As we aren't using the system archive, "UTC" might not exist on the host system.
// Load from C# TimeZone APIs UTC id. // Load from C# TimeZone APIs UTC id.
string utcId = TimeZoneInfo.Utc.Id; string utcId = TimeZoneInfo.Utc.Id;
bool utcNeedConversion = TZConvert.TryWindowsToIana(utcId, out string utcConvertedName); bool utcNeedConversion = TZConvert.TryWindowsToIana(utcId, out string utcConvertedName);
if (utcNeedConversion) if (utcNeedConversion)
{ {
utcId = utcConvertedName; utcId = utcConvertedName;