Some minor cleanups and optimizations (#4174)
* Replace Array.Clear(x, 0, x.Length) with Array.Clear(x) * Use DateTime.UnixEpoch field * Replace SHA256.ComputeHash calls with static SHA256.HashData call More performant and avoids the need to initialize a SHA256 instance.
This commit is contained in:
parent
f906eb06c2
commit
37d27c4c99
6 changed files with 19 additions and 33 deletions
|
@ -140,7 +140,7 @@ namespace ARMeilleure.Translation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Array.Clear(localDefs, 0, localDefs.Length);
|
Array.Clear(localDefs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,6 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
|
||||||
{
|
{
|
||||||
public class UserProfile
|
public class UserProfile
|
||||||
{
|
{
|
||||||
private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
||||||
|
|
||||||
public UserId UserId { get; }
|
public UserId UserId { get; }
|
||||||
|
|
||||||
public long LastModifiedTimestamp { get; set; }
|
public long LastModifiedTimestamp { get; set; }
|
||||||
|
@ -83,7 +81,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
|
||||||
|
|
||||||
private void UpdateLastModifiedTimestamp()
|
private void UpdateLastModifiedTimestamp()
|
||||||
{
|
{
|
||||||
LastModifiedTimestamp = (long)(DateTime.Now - Epoch).TotalSeconds;
|
LastModifiedTimestamp = (long)(DateTime.Now - DateTime.UnixEpoch).TotalSeconds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -100,10 +100,8 @@ namespace Ryujinx.HLE.HOS.Services.Caps
|
||||||
Unknown0x1f = 1
|
Unknown0x1f = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
using (SHA256 sha256Hash = SHA256.Create())
|
|
||||||
{
|
|
||||||
// NOTE: The hex hash is a HMAC-SHA256 (first 32 bytes) using a hardcoded secret key over the titleId, we can simulate it by hashing the titleId instead.
|
// NOTE: The hex hash is a HMAC-SHA256 (first 32 bytes) using a hardcoded secret key over the titleId, we can simulate it by hashing the titleId instead.
|
||||||
string hash = BitConverter.ToString(sha256Hash.ComputeHash(BitConverter.GetBytes(titleId))).Replace("-", "").Remove(0x20);
|
string hash = BitConverter.ToString(SHA256.HashData(BitConverter.GetBytes(titleId))).Replace("-", "").Remove(0x20);
|
||||||
string folderPath = Path.Combine(_sdCardPath, "Nintendo", "Album", currentDateTime.Year.ToString("00"), currentDateTime.Month.ToString("00"), currentDateTime.Day.ToString("00"));
|
string folderPath = Path.Combine(_sdCardPath, "Nintendo", "Album", currentDateTime.Year.ToString("00"), currentDateTime.Month.ToString("00"), currentDateTime.Day.ToString("00"));
|
||||||
string filePath = GenerateFilePath(folderPath, applicationAlbumEntry, currentDateTime, hash);
|
string filePath = GenerateFilePath(folderPath, applicationAlbumEntry, currentDateTime, hash);
|
||||||
|
|
||||||
|
@ -119,7 +117,6 @@ namespace Ryujinx.HLE.HOS.Services.Caps
|
||||||
|
|
||||||
// NOTE: The saved JPEG file doesn't have the limitation in the extra EXIF data.
|
// NOTE: The saved JPEG file doesn't have the limitation in the extra EXIF data.
|
||||||
Image.LoadPixelData<Rgba32>(screenshotData, 1280, 720).SaveAsJpegAsync(filePath);
|
Image.LoadPixelData<Rgba32>(screenshotData, 1280, 720).SaveAsJpegAsync(filePath);
|
||||||
}
|
|
||||||
|
|
||||||
return ResultCode.Success;
|
return ResultCode.Success;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,7 @@ namespace Ryujinx.HLE.HOS.Services.Pcv.Bpc
|
||||||
public static ResultCode GetExternalRtcValue(out ulong rtcValue)
|
public static ResultCode GetExternalRtcValue(out ulong rtcValue)
|
||||||
{
|
{
|
||||||
// TODO: emulate MAX77620/MAX77812 RTC
|
// TODO: emulate MAX77620/MAX77812 RTC
|
||||||
DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
rtcValue = (ulong)(DateTime.Now.ToUniversalTime() - DateTime.UnixEpoch).TotalSeconds;
|
||||||
|
|
||||||
rtcValue = (ulong)(DateTime.Now.ToUniversalTime() - unixEpoch).TotalSeconds;
|
|
||||||
|
|
||||||
return ResultCode.Success;
|
return ResultCode.Success;
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,14 +142,9 @@ namespace Ryujinx.HLE.HOS.Services.Ro
|
||||||
|
|
||||||
_owner.CpuMemory.Read(nroAddress, nroData);
|
_owner.CpuMemory.Read(nroAddress, nroData);
|
||||||
|
|
||||||
byte[] nroHash = null;
|
|
||||||
|
|
||||||
MemoryStream stream = new MemoryStream(nroData);
|
MemoryStream stream = new MemoryStream(nroData);
|
||||||
|
|
||||||
using (SHA256 hasher = SHA256.Create())
|
byte[] nroHash = SHA256.HashData(stream);
|
||||||
{
|
|
||||||
nroHash = hasher.ComputeHash(stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!IsNroHashPresent(nroHash))
|
if (!IsNroHashPresent(nroHash))
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,8 +10,6 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||||
|
|
||||||
public static readonly TimeSpanType Zero = new TimeSpanType(0);
|
public static readonly TimeSpanType Zero = new TimeSpanType(0);
|
||||||
|
|
||||||
private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
||||||
|
|
||||||
public long NanoSeconds;
|
public long NanoSeconds;
|
||||||
|
|
||||||
public TimeSpanType(long nanoSeconds)
|
public TimeSpanType(long nanoSeconds)
|
||||||
|
@ -31,7 +29,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||||
|
|
||||||
public bool IsDaylightSavingTime()
|
public bool IsDaylightSavingTime()
|
||||||
{
|
{
|
||||||
return UnixEpoch.AddSeconds(ToSeconds()).ToLocalTime().IsDaylightSavingTime();
|
return DateTime.UnixEpoch.AddSeconds(ToSeconds()).ToLocalTime().IsDaylightSavingTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TimeSpanType FromSeconds(long seconds)
|
public static TimeSpanType FromSeconds(long seconds)
|
||||||
|
|
Reference in a new issue