mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2026-05-25 06:29:14 +00:00
@@ -40,10 +40,10 @@ namespace Ryujinx.Common
|
||||
|
||||
return (value >> 32) | (value << 32);
|
||||
}
|
||||
|
||||
|
||||
// Never actually written bit packing logic before, so I looked it up.
|
||||
// This code is from https://gist.github.com/Alan-FGR/04938e93e2bffdf5802ceb218a37c195
|
||||
|
||||
|
||||
public static ulong PackBitFields(this uint[] values, byte[] bitFields)
|
||||
{
|
||||
ulong retVal = values[0]; //we set the first value right away
|
||||
@@ -52,6 +52,7 @@ namespace Ryujinx.Common
|
||||
retVal <<= bitFields[f]; // we shift the previous value
|
||||
retVal += values[f];// and add our current value
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -68,6 +69,7 @@ namespace Ryujinx.Common
|
||||
int leftShift = 64 - curPos; // we figure how much left shift we gotta apply for the other numbers to overflow into oblivion
|
||||
retArr[f] = (uint)((packed << leftShift) >> leftShift + lastEnd); // we do magic
|
||||
}
|
||||
|
||||
return retArr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Ryujinx.Common.Utilities
|
||||
|
||||
public static string SanitizeFileName(string fileName)
|
||||
{
|
||||
HashSet<char> reservedChars = new(Path.GetInvalidFileNameChars());
|
||||
HashSet<char> reservedChars = [.. Path.GetInvalidFileNameChars()];
|
||||
return string.Concat(fileName.Select(c => reservedChars.Contains(c) ? '_' : c));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,13 +28,13 @@ namespace Ryujinx.Common.Utilities
|
||||
ReadCommentHandling = JsonCommentHandling.Skip
|
||||
};
|
||||
|
||||
public static string Serialize<T>(T value, JsonTypeInfo<T> typeInfo)
|
||||
public static string Serialize<T>(T value, JsonTypeInfo<T> typeInfo)
|
||||
=> JsonSerializer.Serialize(value, typeInfo);
|
||||
|
||||
public static T Deserialize<T>(string value, JsonTypeInfo<T> typeInfo)
|
||||
public static T Deserialize<T>(string value, JsonTypeInfo<T> typeInfo)
|
||||
=> JsonSerializer.Deserialize(value, typeInfo);
|
||||
|
||||
public static T Deserialize<T>(ReadOnlySpan<byte> utf8Value, JsonTypeInfo<T> typeInfo)
|
||||
public static T Deserialize<T>(ReadOnlySpan<byte> utf8Value, JsonTypeInfo<T> typeInfo)
|
||||
=> JsonSerializer.Deserialize<T>(utf8Value, typeInfo);
|
||||
|
||||
public static void SerializeToFile<T>(string filePath, T value, JsonTypeInfo<T> typeInfo)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Gommon;
|
||||
using Gommon;
|
||||
using Ryujinx.Common.Helper;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
@@ -31,12 +31,12 @@ namespace Ryujinx.Common.Utilities
|
||||
{
|
||||
CyclingEnabled = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static float Speed { get; set; } = 1;
|
||||
|
||||
private static readonly Lock _lock = new();
|
||||
|
||||
|
||||
private static Color _color = Color.Blue;
|
||||
|
||||
public static ref Color Color
|
||||
@@ -55,7 +55,7 @@ namespace Ryujinx.Common.Utilities
|
||||
lock (_lock)
|
||||
{
|
||||
_color = HsbToRgb((_color.GetHue() + Speed) / 360);
|
||||
|
||||
|
||||
_updatedHandler.Call(ref _color);
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace Ryujinx.Common.Utilities
|
||||
public static void Reset()
|
||||
{
|
||||
_updatedHandler.Clear();
|
||||
|
||||
|
||||
lock (_lock)
|
||||
_color = Color.Blue;
|
||||
}
|
||||
@@ -124,6 +124,7 @@ namespace Ryujinx.Common.Utilities
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Color.FromArgb(Convert.ToByte(255), Convert.ToByte(r), Convert.ToByte(g), Convert.ToByte(b));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Ryujinx.Common.Utilities
|
||||
|
||||
public static async Task<byte[]> StreamToBytesAsync(Stream input, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
|
||||
using RecyclableMemoryStream stream = MemoryStreamManager.Shared.GetStream();
|
||||
|
||||
await input.CopyToAsync(stream, cancellationToken);
|
||||
|
||||
|
||||
@@ -183,7 +183,6 @@ namespace Ryujinx.Common.Utilities
|
||||
{
|
||||
CloseReaders();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -205,7 +204,7 @@ namespace Ryujinx.Common.Utilities
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
|
||||
if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -257,7 +256,7 @@ namespace Ryujinx.Common.Utilities
|
||||
{
|
||||
return OperationOutcome.Cancelled;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
return OperationOutcome.FreeSpaceCheckFailed;
|
||||
}
|
||||
@@ -294,7 +293,7 @@ namespace Ryujinx.Common.Utilities
|
||||
{
|
||||
|
||||
#if !XCI_TRIMMER_READ_ONLY_MODE
|
||||
outfileStream.SetLength(TrimmedFileSizeB);
|
||||
outfileStream.SetLength(TrimmedFileSizeB);
|
||||
#endif
|
||||
return OperationOutcome.Successful;
|
||||
}
|
||||
@@ -367,7 +366,7 @@ namespace Ryujinx.Common.Utilities
|
||||
{
|
||||
return OperationOutcome.Cancelled;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
return OperationOutcome.Successful;
|
||||
}
|
||||
@@ -404,9 +403,9 @@ namespace Ryujinx.Common.Utilities
|
||||
}
|
||||
|
||||
long bytesToWrite = Math.Min(XCIFileTrimmer.BufferSize, bytesLeftToWriteB);
|
||||
|
||||
|
||||
#if !XCI_TRIMMER_READ_ONLY_MODE
|
||||
outfileStream.Write(buffer, 0, (int)bytesToWrite);
|
||||
outfileStream.Write(buffer, 0, (int)bytesToWrite);
|
||||
#endif
|
||||
|
||||
bytesLeftToWriteB -= bytesToWrite;
|
||||
@@ -511,6 +510,7 @@ namespace Ryujinx.Common.Utilities
|
||||
Log?.Write(LogType.Error, $"The source file doesn't look like an XCI file as the Cartridge Size is incorrect (0x{cartSizeId:X2})");
|
||||
return false;
|
||||
}
|
||||
|
||||
_cartSizeB = cartSizeNGB * XCIFileTrimmer.CartSizeMBinFormattedGB * XCIFileTrimmer.BytesInAMegabyte;
|
||||
|
||||
// Read data size
|
||||
|
||||
Reference in New Issue
Block a user