mirror of
https://git.743378673.xyz/MeloNX/MeloNX.git
synced 2025-07-30 18:47:10 +02:00
[Ryujinx.Common] Address dotnet-format issues (#5358)
* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0059 warnings * Address or silence dotnet format IDE1006 warnings * Address dotnet format CA1816 warnings * Address or silence dotnet format CA2211 warnings * Silence CA1806 and CA1834 issues * Fix formatting for switch expressions * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Revert formatting changes for while and for-loops * Format if-blocks correctly * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format analyzers after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Add comments to disabled warnings * Remove a few unused parameters * Replace MmeShadowScratch with Array256<uint> * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Run dotnet format after rebase * Address IDE0251 warnings * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Second dotnet format pass * Fix build issues * Fix StructArrayHelpers.cs * Apply suggestions from code review Co-authored-by: Ac_K <Acoustik666@gmail.com> * Fix return statements * Fix naming rule violations * Update src/Ryujinx.Common/Utilities/StreamUtils.cs Co-authored-by: Ac_K <Acoustik666@gmail.com> * Add trailing commas * Address review feedback * Address review feedback * Rename remaining type parameters to TKey and TValue * Fix manual formatting for logging levels * Fix spacing before comments --------- Co-authored-by: Ac_K <Acoustik666@gmail.com>
This commit is contained in:
parent
0a75b73fa4
commit
fc20d9b925
96 changed files with 965 additions and 969 deletions
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Ryujinx.Common
|
||||
|
@ -27,10 +26,10 @@ namespace Ryujinx.Common
|
|||
{
|
||||
value--;
|
||||
|
||||
value |= (value >> 1);
|
||||
value |= (value >> 2);
|
||||
value |= (value >> 4);
|
||||
value |= (value >> 8);
|
||||
value |= (value >> 1);
|
||||
value |= (value >> 2);
|
||||
value |= (value >> 4);
|
||||
value |= (value >> 8);
|
||||
value |= (value >> 16);
|
||||
|
||||
return ++value;
|
||||
|
@ -48,10 +47,10 @@ namespace Ryujinx.Common
|
|||
|
||||
private static ulong ReverseBits64(ulong value)
|
||||
{
|
||||
value = ((value & 0xaaaaaaaaaaaaaaaa) >> 1 ) | ((value & 0x5555555555555555) << 1 );
|
||||
value = ((value & 0xcccccccccccccccc) >> 2 ) | ((value & 0x3333333333333333) << 2 );
|
||||
value = ((value & 0xf0f0f0f0f0f0f0f0) >> 4 ) | ((value & 0x0f0f0f0f0f0f0f0f) << 4 );
|
||||
value = ((value & 0xff00ff00ff00ff00) >> 8 ) | ((value & 0x00ff00ff00ff00ff) << 8 );
|
||||
value = ((value & 0xaaaaaaaaaaaaaaaa) >> 1) | ((value & 0x5555555555555555) << 1);
|
||||
value = ((value & 0xcccccccccccccccc) >> 2) | ((value & 0x3333333333333333) << 2);
|
||||
value = ((value & 0xf0f0f0f0f0f0f0f0) >> 4) | ((value & 0x0f0f0f0f0f0f0f0f) << 4);
|
||||
value = ((value & 0xff00ff00ff00ff00) >> 8) | ((value & 0x00ff00ff00ff00ff) << 8);
|
||||
value = ((value & 0xffff0000ffff0000) >> 16) | ((value & 0x0000ffff0000ffff) << 16);
|
||||
|
||||
return (value >> 32) | (value << 32);
|
||||
|
|
|
@ -54,4 +54,4 @@ namespace Ryujinx.Common.Utilities
|
|||
return (value & ~mask) | ((toInsert << lsb) & mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ namespace Ryujinx.Common.Utilities
|
|||
[StructLayout(LayoutKind.Sequential, Size = 16)]
|
||||
public struct Buffer16
|
||||
{
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] private ulong _dummy0;
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] private ulong _dummy1;
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy0;
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy1;
|
||||
|
||||
public byte this[int i]
|
||||
{
|
||||
|
|
|
@ -8,4 +8,4 @@ namespace Ryujinx.Common.Utilities
|
|||
public partial class CommonJsonContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
@ -10,11 +9,11 @@ namespace Ryujinx.Common
|
|||
{
|
||||
public static class EmbeddedResources
|
||||
{
|
||||
private readonly static Assembly ResourceAssembly;
|
||||
private readonly static Assembly _resourceAssembly;
|
||||
|
||||
static EmbeddedResources()
|
||||
{
|
||||
ResourceAssembly = Assembly.GetAssembly(typeof(EmbeddedResources));
|
||||
_resourceAssembly = Assembly.GetAssembly(typeof(EmbeddedResources));
|
||||
}
|
||||
|
||||
public static byte[] Read(string filename)
|
||||
|
@ -33,28 +32,24 @@ namespace Ryujinx.Common
|
|||
|
||||
public static byte[] Read(Assembly assembly, string filename)
|
||||
{
|
||||
using (var stream = GetStream(assembly, filename))
|
||||
using var stream = GetStream(assembly, filename);
|
||||
if (stream == null)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return StreamUtils.StreamToBytes(stream);
|
||||
return null;
|
||||
}
|
||||
|
||||
return StreamUtils.StreamToBytes(stream);
|
||||
}
|
||||
|
||||
public async static Task<byte[]> ReadAsync(Assembly assembly, string filename)
|
||||
{
|
||||
using (var stream = GetStream(assembly, filename))
|
||||
using var stream = GetStream(assembly, filename);
|
||||
if (stream == null)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return await StreamUtils.StreamToBytesAsync(stream);
|
||||
return null;
|
||||
}
|
||||
|
||||
return await StreamUtils.StreamToBytesAsync(stream);
|
||||
}
|
||||
|
||||
public static string ReadAllText(string filename)
|
||||
|
@ -73,34 +68,26 @@ namespace Ryujinx.Common
|
|||
|
||||
public static string ReadAllText(Assembly assembly, string filename)
|
||||
{
|
||||
using (var stream = GetStream(assembly, filename))
|
||||
using var stream = GetStream(assembly, filename);
|
||||
if (stream == null)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
using var reader = new StreamReader(stream);
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
|
||||
public async static Task<string> ReadAllTextAsync(Assembly assembly, string filename)
|
||||
{
|
||||
using (var stream = GetStream(assembly, filename))
|
||||
using var stream = GetStream(assembly, filename);
|
||||
if (stream == null)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
return await reader.ReadToEndAsync();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
using var reader = new StreamReader(stream);
|
||||
return await reader.ReadToEndAsync();
|
||||
}
|
||||
|
||||
public static Stream GetStream(string filename)
|
||||
|
@ -112,8 +99,8 @@ namespace Ryujinx.Common
|
|||
|
||||
public static Stream GetStream(Assembly assembly, string filename)
|
||||
{
|
||||
var namespace_ = assembly.GetName().Name;
|
||||
var manifestUri = namespace_ + "." + filename.Replace('/', '.');
|
||||
var @namespace = assembly.GetName().Name;
|
||||
var manifestUri = @namespace + "." + filename.Replace('/', '.');
|
||||
|
||||
var stream = assembly.GetManifestResourceStream(manifestUri);
|
||||
|
||||
|
@ -142,7 +129,7 @@ namespace Ryujinx.Common
|
|||
}
|
||||
}
|
||||
|
||||
return (ResourceAssembly, filename);
|
||||
return (_resourceAssembly, filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace Ryujinx.Common
|
|||
{
|
||||
public static class HexUtils
|
||||
{
|
||||
private static readonly char[] HexChars = "0123456789ABCDEF".ToCharArray();
|
||||
private static readonly char[] _hexChars = "0123456789ABCDEF".ToCharArray();
|
||||
|
||||
private const int HexTableColumnWidth = 8;
|
||||
private const int HexTableColumnSpace = 3;
|
||||
|
@ -39,20 +39,20 @@ namespace Ryujinx.Common
|
|||
|
||||
int expectedLines = (bytesLength + bytesPerLine - 1) / bytesPerLine;
|
||||
|
||||
StringBuilder result = new StringBuilder(expectedLines * lineLength);
|
||||
StringBuilder result = new(expectedLines * lineLength);
|
||||
|
||||
for (int i = 0; i < bytesLength; i += bytesPerLine)
|
||||
{
|
||||
line[0] = HexChars[(i >> 28) & 0xF];
|
||||
line[1] = HexChars[(i >> 24) & 0xF];
|
||||
line[2] = HexChars[(i >> 20) & 0xF];
|
||||
line[3] = HexChars[(i >> 16) & 0xF];
|
||||
line[4] = HexChars[(i >> 12) & 0xF];
|
||||
line[5] = HexChars[(i >> 8) & 0xF];
|
||||
line[6] = HexChars[(i >> 4) & 0xF];
|
||||
line[7] = HexChars[(i >> 0) & 0xF];
|
||||
line[0] = _hexChars[(i >> 28) & 0xF];
|
||||
line[1] = _hexChars[(i >> 24) & 0xF];
|
||||
line[2] = _hexChars[(i >> 20) & 0xF];
|
||||
line[3] = _hexChars[(i >> 16) & 0xF];
|
||||
line[4] = _hexChars[(i >> 12) & 0xF];
|
||||
line[5] = _hexChars[(i >> 8) & 0xF];
|
||||
line[6] = _hexChars[(i >> 4) & 0xF];
|
||||
line[7] = _hexChars[(i >> 0) & 0xF];
|
||||
|
||||
int hexColumn = firstHexColumn;
|
||||
int hexColumn = firstHexColumn;
|
||||
int charColumn = firstCharColumn;
|
||||
|
||||
for (int j = 0; j < bytesPerLine; j++)
|
||||
|
@ -64,17 +64,17 @@ namespace Ryujinx.Common
|
|||
|
||||
if (i + j >= bytesLength)
|
||||
{
|
||||
line[hexColumn] = ' ';
|
||||
line[hexColumn] = ' ';
|
||||
line[hexColumn + 1] = ' ';
|
||||
line[charColumn] = ' ';
|
||||
line[charColumn] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
byte b = bytes[i + j];
|
||||
|
||||
line[hexColumn] = HexChars[(b >> 4) & 0xF];
|
||||
line[hexColumn + 1] = HexChars[b & 0xF];
|
||||
line[charColumn] = (b < 32 ? '·' : (char)b);
|
||||
line[hexColumn] = _hexChars[(b >> 4) & 0xF];
|
||||
line[hexColumn + 1] = _hexChars[b & 0xF];
|
||||
line[charColumn] = (b < 32 ? '·' : (char)b);
|
||||
}
|
||||
|
||||
hexColumn += 3;
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace Ryujinx.Common.Utilities
|
|||
{
|
||||
public class JsonHelper
|
||||
{
|
||||
private static readonly JsonNamingPolicy SnakeCasePolicy = new SnakeCaseNamingPolicy();
|
||||
private static readonly JsonNamingPolicy _snakeCasePolicy = new SnakeCaseNamingPolicy();
|
||||
private const int DefaultFileWriteBufferSize = 4096;
|
||||
|
||||
/// <summary>
|
||||
|
@ -21,11 +21,11 @@ namespace Ryujinx.Common.Utilities
|
|||
{
|
||||
JsonSerializerOptions options = new()
|
||||
{
|
||||
DictionaryKeyPolicy = SnakeCasePolicy,
|
||||
PropertyNamingPolicy = SnakeCasePolicy,
|
||||
WriteIndented = indented,
|
||||
AllowTrailingCommas = true,
|
||||
ReadCommentHandling = JsonCommentHandling.Skip
|
||||
DictionaryKeyPolicy = _snakeCasePolicy,
|
||||
PropertyNamingPolicy = _snakeCasePolicy,
|
||||
WriteIndented = indented,
|
||||
AllowTrailingCommas = true,
|
||||
ReadCommentHandling = JsonCommentHandling.Skip,
|
||||
};
|
||||
|
||||
return options;
|
||||
|
@ -95,4 +95,4 @@ namespace Ryujinx.Common.Utilities
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,8 @@ namespace Ryujinx.Common.Utilities
|
|||
{
|
||||
return Format(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
return obj.ToString();
|
||||
}
|
||||
|
||||
return obj.ToString();
|
||||
}
|
||||
|
||||
public static string Format(MessagePackObject obj)
|
||||
|
@ -179,19 +177,17 @@ namespace Ryujinx.Common.Utilities
|
|||
{
|
||||
return unchecked((char)('0' + b));
|
||||
}
|
||||
else
|
||||
{
|
||||
return unchecked((char)('A' + (b - 10)));
|
||||
}
|
||||
|
||||
return unchecked((char)('A' + (b - 10)));
|
||||
}
|
||||
|
||||
internal class IndentedStringBuilder
|
||||
{
|
||||
const string DefaultIndent = " ";
|
||||
|
||||
private int _indentCount = 0;
|
||||
private int _newLineIndex = 0;
|
||||
private StringBuilder _builder;
|
||||
private int _indentCount;
|
||||
private int _newLineIndex;
|
||||
private readonly StringBuilder _builder;
|
||||
|
||||
public string IndentString { get; set; } = DefaultIndent;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace Ryujinx.Common.Utilities
|
|||
return (null, null);
|
||||
}
|
||||
|
||||
IPInterfaceProperties targetProperties = null;
|
||||
IPInterfaceProperties targetProperties = null;
|
||||
UnicastIPAddressInformation targetAddressInfo = null;
|
||||
|
||||
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
|
||||
|
@ -63,4 +63,4 @@ namespace Ryujinx.Common.Utilities
|
|||
return (targetProperties, targetAddressInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using Microsoft.IO;
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Common.Memory;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -10,22 +9,21 @@ namespace Ryujinx.Common.Utilities
|
|||
{
|
||||
public static byte[] StreamToBytes(Stream input)
|
||||
{
|
||||
using (MemoryStream stream = MemoryStreamManager.Shared.GetStream())
|
||||
{
|
||||
input.CopyTo(stream);
|
||||
using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
|
||||
|
||||
return stream.ToArray();
|
||||
}
|
||||
|
||||
input.CopyTo(stream);
|
||||
|
||||
return stream.ToArray();
|
||||
}
|
||||
|
||||
public static async Task<byte[]> StreamToBytesAsync(Stream input, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using (MemoryStream stream = MemoryStreamManager.Shared.GetStream())
|
||||
{
|
||||
await input.CopyToAsync(stream, cancellationToken);
|
||||
using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
|
||||
|
||||
return stream.ToArray();
|
||||
}
|
||||
await input.CopyToAsync(stream, cancellationToken);
|
||||
|
||||
return stream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,4 +34,4 @@ namespace Ryujinx.Common.Utilities
|
|||
writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,4 +15,4 @@ namespace Ryujinx.Common.Utilities
|
|||
return new UInt128((ulong)Random.Shared.NextInt64(), (ulong)Random.Shared.NextInt64());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue