misc: chore: Fix numerous NullReferenceExceptions, InvalidOperationExceptions

This commit is contained in:
KeatonTheBot
2025-06-20 16:33:20 -05:00
parent 9b6b9146e2
commit d0abbc6da3
90 changed files with 667 additions and 533 deletions
@@ -88,11 +88,16 @@ namespace Ryujinx.UI.App.Common
private static byte[] GetResourceBytes(string resourceName)
{
Stream resourceStream = Assembly.GetCallingAssembly().GetManifestResourceStream(resourceName);
byte[] resourceByteArray = new byte[resourceStream.Length];
if (resourceStream != null)
{
byte[] resourceByteArray = new byte[resourceStream.Length];
resourceStream.ReadExactly(resourceByteArray);
resourceStream.ReadExactly(resourceByteArray);
return resourceByteArray;
return resourceByteArray;
}
return [];
}
/// <exception cref="Ryujinx.HLE.Exceptions.InvalidNpdmException">The npdm file doesn't contain valid data.</exception>
@@ -1178,7 +1183,7 @@ namespace Ryujinx.UI.App.Common
{
string extension = Path.GetExtension(applicationPath)?.ToLower();
using FileStream file = new(applicationPath, FileMode.Open, FileAccess.Read);
using FileStream file = new(applicationPath ?? string.Empty, FileMode.Open, FileAccess.Read);
if (extension == ".nsp" || extension == ".pfs0" || extension == ".xci")
{
@@ -152,7 +152,7 @@ namespace Ryujinx.UI.Common.Helper
Logger.Debug?.Print(LogClass.Application, $"Adding type association {ext}");
using var openCmd = key.CreateSubKey(@"shell\open\command");
openCmd.SetValue("", $"\"{Environment.ProcessPath}\" \"%1\"");
openCmd?.SetValue("", $"\"{Environment.ProcessPath}\" \"%1\"");
Logger.Debug?.Print(LogClass.Application, $"Added type association {ext}");
}
@@ -36,11 +36,11 @@ namespace Ryujinx.UI.Common.SystemInfo
{
foreach (var cpuObj in cpuObjs)
{
return cpuObj["Name"].ToString().Trim();
return cpuObj["Name"].ToString()?.Trim();
}
}
return Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER").Trim();
return Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER")?.Trim();
}
[StructLayout(LayoutKind.Sequential)]