misc: chore: Use explicit types in common project
This commit is contained in:
@@ -19,21 +19,21 @@ namespace Ryujinx.Common
|
||||
|
||||
public static byte[] Read(string filename)
|
||||
{
|
||||
var (assembly, path) = ResolveManifestPath(filename);
|
||||
(Assembly assembly, string path) = ResolveManifestPath(filename);
|
||||
|
||||
return Read(assembly, path);
|
||||
}
|
||||
|
||||
public static Task<byte[]> ReadAsync(string filename)
|
||||
{
|
||||
var (assembly, path) = ResolveManifestPath(filename);
|
||||
(Assembly assembly, string path) = ResolveManifestPath(filename);
|
||||
|
||||
return ReadAsync(assembly, path);
|
||||
}
|
||||
|
||||
public static byte[] Read(Assembly assembly, string filename)
|
||||
{
|
||||
using var stream = GetStream(assembly, filename);
|
||||
using Stream stream = GetStream(assembly, filename);
|
||||
if (stream == null)
|
||||
{
|
||||
return null;
|
||||
@@ -44,14 +44,14 @@ namespace Ryujinx.Common
|
||||
|
||||
public static MemoryOwner<byte> ReadFileToRentedMemory(string filename)
|
||||
{
|
||||
var (assembly, path) = ResolveManifestPath(filename);
|
||||
(Assembly assembly, string path) = ResolveManifestPath(filename);
|
||||
|
||||
return ReadFileToRentedMemory(assembly, path);
|
||||
}
|
||||
|
||||
public static MemoryOwner<byte> ReadFileToRentedMemory(Assembly assembly, string filename)
|
||||
{
|
||||
using var stream = GetStream(assembly, filename);
|
||||
using Stream stream = GetStream(assembly, filename);
|
||||
|
||||
return stream is null
|
||||
? null
|
||||
@@ -60,7 +60,7 @@ namespace Ryujinx.Common
|
||||
|
||||
public async static Task<byte[]> ReadAsync(Assembly assembly, string filename)
|
||||
{
|
||||
using var stream = GetStream(assembly, filename);
|
||||
using Stream stream = GetStream(assembly, filename);
|
||||
if (stream == null)
|
||||
{
|
||||
return null;
|
||||
@@ -71,55 +71,55 @@ namespace Ryujinx.Common
|
||||
|
||||
public static string ReadAllText(string filename)
|
||||
{
|
||||
var (assembly, path) = ResolveManifestPath(filename);
|
||||
(Assembly assembly, string path) = ResolveManifestPath(filename);
|
||||
|
||||
return ReadAllText(assembly, path);
|
||||
}
|
||||
|
||||
public static Task<string> ReadAllTextAsync(string filename)
|
||||
{
|
||||
var (assembly, path) = ResolveManifestPath(filename);
|
||||
(Assembly assembly, string path) = ResolveManifestPath(filename);
|
||||
|
||||
return ReadAllTextAsync(assembly, path);
|
||||
}
|
||||
|
||||
public static string ReadAllText(Assembly assembly, string filename)
|
||||
{
|
||||
using var stream = GetStream(assembly, filename);
|
||||
using Stream stream = GetStream(assembly, filename);
|
||||
if (stream == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var reader = new StreamReader(stream);
|
||||
using StreamReader reader = new StreamReader(stream);
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
|
||||
public async static Task<string> ReadAllTextAsync(Assembly assembly, string filename)
|
||||
{
|
||||
using var stream = GetStream(assembly, filename);
|
||||
using Stream stream = GetStream(assembly, filename);
|
||||
if (stream == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var reader = new StreamReader(stream);
|
||||
using StreamReader reader = new StreamReader(stream);
|
||||
return await reader.ReadToEndAsync();
|
||||
}
|
||||
|
||||
public static Stream GetStream(string filename)
|
||||
{
|
||||
var (assembly, path) = ResolveManifestPath(filename);
|
||||
(Assembly assembly, string path) = ResolveManifestPath(filename);
|
||||
|
||||
return GetStream(assembly, path);
|
||||
}
|
||||
|
||||
public static Stream GetStream(Assembly assembly, string filename)
|
||||
{
|
||||
var @namespace = assembly.GetName().Name;
|
||||
var manifestUri = @namespace + "." + filename.Replace('/', '.');
|
||||
string @namespace = assembly.GetName().Name;
|
||||
string manifestUri = @namespace + "." + filename.Replace('/', '.');
|
||||
|
||||
var stream = assembly.GetManifestResourceStream(manifestUri);
|
||||
Stream stream = assembly.GetManifestResourceStream(manifestUri);
|
||||
|
||||
return stream;
|
||||
}
|
||||
@@ -133,11 +133,11 @@ namespace Ryujinx.Common
|
||||
|
||||
private static (Assembly, string) ResolveManifestPath(string filename)
|
||||
{
|
||||
var segments = filename.Split('/', 2, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] segments = filename.Split('/', 2, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (segments.Length >= 2)
|
||||
{
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
if (assembly.GetName().Name == segments[0])
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Ryujinx.Common.Utilities
|
||||
public static void CopyDirectory(string sourceDir, string destinationDir, bool recursive)
|
||||
{
|
||||
// Get information about the source directory
|
||||
var dir = new DirectoryInfo(sourceDir);
|
||||
DirectoryInfo dir = new DirectoryInfo(sourceDir);
|
||||
|
||||
// Check if the source directory exists
|
||||
if (!dir.Exists)
|
||||
@@ -49,7 +49,7 @@ namespace Ryujinx.Common.Utilities
|
||||
|
||||
public static string SanitizeFileName(string fileName)
|
||||
{
|
||||
var reservedChars = new HashSet<char>(Path.GetInvalidFileNameChars());
|
||||
HashSet<char> reservedChars = new HashSet<char>(Path.GetInvalidFileNameChars());
|
||||
return string.Concat(fileName.Select(c => reservedChars.Contains(c) ? '_' : c));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using MsgPack;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.Common.Utilities
|
||||
@@ -18,7 +19,7 @@ namespace Ryujinx.Common.Utilities
|
||||
|
||||
public static string Format(MessagePackObject obj)
|
||||
{
|
||||
var builder = new IndentedStringBuilder();
|
||||
IndentedStringBuilder builder = new IndentedStringBuilder();
|
||||
|
||||
FormatMsgPackObj(obj, builder);
|
||||
|
||||
@@ -41,7 +42,7 @@ namespace Ryujinx.Common.Utilities
|
||||
}
|
||||
else
|
||||
{
|
||||
var literal = obj.ToObject();
|
||||
object literal = obj.ToObject();
|
||||
|
||||
if (literal is String)
|
||||
{
|
||||
@@ -88,7 +89,7 @@ namespace Ryujinx.Common.Utilities
|
||||
{
|
||||
builder.Append("[ ");
|
||||
|
||||
foreach (var b in arr)
|
||||
foreach (byte b in arr)
|
||||
{
|
||||
builder.Append("0x");
|
||||
builder.Append(ToHexChar(b >> 4));
|
||||
@@ -111,7 +112,7 @@ namespace Ryujinx.Common.Utilities
|
||||
builder.Append("0x");
|
||||
}
|
||||
|
||||
foreach (var b in arr)
|
||||
foreach (byte b in arr)
|
||||
{
|
||||
builder.Append(ToHexChar(b >> 4));
|
||||
builder.Append(ToHexChar(b & 0xF));
|
||||
@@ -122,7 +123,7 @@ namespace Ryujinx.Common.Utilities
|
||||
|
||||
private static void FormatMsgPackMap(MessagePackObject obj, IndentedStringBuilder builder)
|
||||
{
|
||||
var map = obj.AsDictionary();
|
||||
MessagePackObjectDictionary map = obj.AsDictionary();
|
||||
|
||||
builder.Append('{');
|
||||
|
||||
@@ -130,7 +131,7 @@ namespace Ryujinx.Common.Utilities
|
||||
builder.IncreaseIndent()
|
||||
.AppendLine();
|
||||
|
||||
foreach (var item in map)
|
||||
foreach (KeyValuePair<MessagePackObject, MessagePackObject> item in map)
|
||||
{
|
||||
FormatMsgPackObj(item.Key, builder);
|
||||
|
||||
@@ -154,11 +155,11 @@ namespace Ryujinx.Common.Utilities
|
||||
|
||||
private static void FormatMsgPackArray(MessagePackObject obj, IndentedStringBuilder builder)
|
||||
{
|
||||
var arr = obj.AsList();
|
||||
IList<MessagePackObject> arr = obj.AsList();
|
||||
|
||||
builder.Append("[ ");
|
||||
|
||||
foreach (var item in arr)
|
||||
foreach (MessagePackObject item in arr)
|
||||
{
|
||||
FormatMsgPackObj(item, builder);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.IO;
|
||||
using Ryujinx.Common.Memory;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -27,7 +28,7 @@ namespace Ryujinx.Common.Utilities
|
||||
|
||||
MemoryOwner<byte> ownedMemory = MemoryOwner<byte>.Rent(checked((int)bytesExpected));
|
||||
|
||||
var destSpan = ownedMemory.Span;
|
||||
Span<byte> destSpan = ownedMemory.Span;
|
||||
|
||||
int totalBytesRead = 0;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Ryujinx.Common.Utilities
|
||||
{
|
||||
public override TEnum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var enumValue = reader.GetString();
|
||||
string? enumValue = reader.GetString();
|
||||
|
||||
if (Enum.TryParse(enumValue, out TEnum value))
|
||||
{
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Ryujinx.Common.Utilities
|
||||
{
|
||||
if (Path.GetExtension(filename).Equals(".XCI", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
var trimmer = new XCIFileTrimmer(filename, log);
|
||||
XCIFileTrimmer trimmer = new XCIFileTrimmer(filename, log);
|
||||
return trimmer.CanBeTrimmed;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Ryujinx.Common.Utilities
|
||||
{
|
||||
if (Path.GetExtension(filename).Equals(".XCI", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
var trimmer = new XCIFileTrimmer(filename, log);
|
||||
XCIFileTrimmer trimmer = new XCIFileTrimmer(filename, log);
|
||||
return trimmer.CanBeUntrimmed;
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ namespace Ryujinx.Common.Utilities
|
||||
{
|
||||
long maxReads = readSizeB / XCIFileTrimmer.BufferSize;
|
||||
long read = 0;
|
||||
var buffer = new byte[BufferSize];
|
||||
byte[] buffer = new byte[BufferSize];
|
||||
|
||||
while (true)
|
||||
{
|
||||
@@ -267,7 +267,7 @@ namespace Ryujinx.Common.Utilities
|
||||
|
||||
try
|
||||
{
|
||||
var info = new FileInfo(Filename);
|
||||
FileInfo info = new FileInfo(Filename);
|
||||
if ((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
|
||||
{
|
||||
try
|
||||
@@ -288,7 +288,7 @@ namespace Ryujinx.Common.Utilities
|
||||
return OperationOutcome.FileSizeChanged;
|
||||
}
|
||||
|
||||
var outfileStream = new FileStream(_filename, FileMode.Open, FileAccess.Write, FileShare.Write);
|
||||
FileStream outfileStream = new FileStream(_filename, FileMode.Open, FileAccess.Write, FileShare.Write);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -327,7 +327,7 @@ namespace Ryujinx.Common.Utilities
|
||||
{
|
||||
Log?.Write(LogType.Info, "Untrimming...");
|
||||
|
||||
var info = new FileInfo(Filename);
|
||||
FileInfo info = new FileInfo(Filename);
|
||||
if ((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
|
||||
{
|
||||
try
|
||||
@@ -348,7 +348,7 @@ namespace Ryujinx.Common.Utilities
|
||||
return OperationOutcome.FileSizeChanged;
|
||||
}
|
||||
|
||||
var outfileStream = new FileStream(_filename, FileMode.Append, FileAccess.Write, FileShare.Write);
|
||||
FileStream outfileStream = new FileStream(_filename, FileMode.Append, FileAccess.Write, FileShare.Write);
|
||||
long bytesToWriteB = UntrimmedFileSizeB - FileSizeB;
|
||||
|
||||
try
|
||||
@@ -393,7 +393,7 @@ namespace Ryujinx.Common.Utilities
|
||||
|
||||
try
|
||||
{
|
||||
var buffer = new byte[BufferSize];
|
||||
byte[] buffer = new byte[BufferSize];
|
||||
Array.Fill<byte>(buffer, XCIFileTrimmer.PaddingByte);
|
||||
|
||||
while (bytesLeftToWriteB > 0)
|
||||
|
||||
Reference in New Issue
Block a user