Skip to content

Commit

Permalink
misc: More minor code style changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
GreemDev committed Oct 13, 2024
1 parent a989d28 commit df9450d
Show file tree
Hide file tree
Showing 9 changed files with 562 additions and 639 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// ReSharper disable InconsistentNaming

namespace Ryujinx.Common.GraphicsDriver
{
Expand Down
544 changes: 526 additions & 18 deletions src/Ryujinx.Common/Hash128.cs

Large diffs are not rendered by default.

11 changes: 3 additions & 8 deletions src/Ryujinx.Common/Utilities/JsonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,10 @@ public override string ConvertName(string name)

if (char.IsUpper(c))
{
if (i == 0 || char.IsUpper(name[i - 1]))
{
builder.Append(char.ToLowerInvariant(c));
}
else
{
if (!(i == 0 || char.IsUpper(name[i - 1])))
builder.Append('_');
builder.Append(char.ToLowerInvariant(c));
}

builder.Append(char.ToLowerInvariant(c));
}
else
{
Expand Down
548 changes: 0 additions & 548 deletions src/Ryujinx.Common/XXHash128.cs

This file was deleted.

38 changes: 11 additions & 27 deletions src/Ryujinx.HLE/FileSystem/ContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,21 +588,15 @@ public SystemVersion VerifyFirmwarePackage(string firmwarePackage)
// LibHac.NcaHeader's DecryptHeader doesn't check if HeaderKey is empty and throws InvalidDataException instead
// So, we check it early for a better user experience.
if (_virtualFileSystem.KeySet.HeaderKey.IsZeros())
{
throw new MissingKeyException("HeaderKey is empty. Cannot decrypt NCA headers.");
}


Dictionary<ulong, List<(NcaContentType type, string path)>> updateNcas = new();

if (Directory.Exists(firmwarePackage))
{
return VerifyAndGetVersionDirectory(firmwarePackage);
}


if (!File.Exists(firmwarePackage))
{
throw new FileNotFoundException("Firmware file does not exist.");
}

FileInfo info = new(firmwarePackage);

Expand All @@ -612,31 +606,23 @@ public SystemVersion VerifyFirmwarePackage(string firmwarePackage)
{
case ".zip":
using (ZipArchive archive = ZipFile.OpenRead(firmwarePackage))
{
return VerifyAndGetVersionZip(archive);
}
case ".xci":
Xci xci = new(_virtualFileSystem.KeySet, file.AsStorage());

if (xci.HasPartition(XciPartitionType.Update))
{
XciPartition partition = xci.OpenPartition(XciPartitionType.Update);

return VerifyAndGetVersion(partition);
}
else
{
if (!xci.HasPartition(XciPartitionType.Update))
throw new InvalidFirmwarePackageException("Update not found in xci file.");
}
default:
break;
}

SystemVersion VerifyAndGetVersionDirectory(string firmwareDirectory)
{
return VerifyAndGetVersion(new LocalFileSystem(firmwareDirectory));
XciPartition partition = xci.OpenPartition(XciPartitionType.Update);

return VerifyAndGetVersion(partition);
}

return null;

SystemVersion VerifyAndGetVersionDirectory(string firmwareDirectory)
=> VerifyAndGetVersion(new LocalFileSystem(firmwareDirectory));

SystemVersion VerifyAndGetVersionZip(ZipArchive archive)
{
SystemVersion systemVersion = null;
Expand Down Expand Up @@ -925,8 +911,6 @@ SystemVersion VerifyAndGetVersion(IFileSystem filesystem)

return systemVersion;
}

return null;
}

public SystemVersion GetCurrentFirmwareVersion()
Expand Down
21 changes: 8 additions & 13 deletions src/Ryujinx.UI.Common/Helper/SetupValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ public static bool TryFixStartApplication(ContentManager contentManager, string

return true;
}
catch (Exception) { }
catch
{
// ignored
}
}

outError = error;

return false;
}
}

Expand All @@ -96,19 +95,15 @@ public static bool CanStartApplication(ContentManager contentManager, string bas
string baseApplicationExtension = Path.GetExtension(baseApplicationPath).ToLowerInvariant();

// NOTE: We don't force homebrew developers to install a system firmware.
if (baseApplicationExtension == ".nro" || baseApplicationExtension == ".nso")
{
error = UserError.Success;
if (baseApplicationExtension is not (".nro" or ".nso"))
return IsFirmwareValid(contentManager, out error);

return true;
}

return IsFirmwareValid(contentManager, out error);
error = UserError.Success;
}

error = UserError.ApplicationNotFound;

return false;
return error is UserError.Success;
}
}
}
4 changes: 2 additions & 2 deletions src/Ryujinx.UI.Common/Helper/ShortcutHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ private static string GetArgsString(string appFilePath, string applicationId)

argsList.Add($"\"{appFilePath}\"");

return String.Join(" ", argsList);
return string.Join(" ", argsList);
}

/// <summary>
/// Creates a Icon (.ico) file using the source bitmap image at the specified file path.
/// Creates an Icon (.ico) file using the source bitmap image at the specified file path.
/// </summary>
/// <param name="source">The source bitmap image that will be saved as an .ico file</param>
/// <param name="filePath">The location that the new .ico file will be saved too (Make sure to include '.ico' in the path).</param>
Expand Down
28 changes: 8 additions & 20 deletions src/Ryujinx.UI.Common/Helper/TitleUpdatesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ public static void SaveTitleUpdatesJson(VirtualFileSystem vfs, ulong application

foreach (string path in titleUpdateMetadata.Paths)
{
if (!File.Exists(path))
{
continue;
}
if (!File.Exists(path)) continue;

try
{
Expand All @@ -99,22 +96,15 @@ public static void SaveTitleUpdatesJson(VirtualFileSystem vfs, ulong application
Dictionary<ulong, ContentMetaData> updates =
pfs.GetContentData(ContentMetaType.Patch, vfs, checkLevel);

Nca patchNca = null;
Nca controlNca = null;

if (!updates.TryGetValue(applicationIdBase, out ContentMetaData content))
{
continue;
}

patchNca = content.GetNcaByType(vfs.KeySet, ContentType.Program);
controlNca = content.GetNcaByType(vfs.KeySet, ContentType.Control);
Nca patchNca = content.GetNcaByType(vfs.KeySet, ContentType.Program);
Nca controlNca = content.GetNcaByType(vfs.KeySet, ContentType.Control);

if (controlNca == null || patchNca == null)
{
if (controlNca is null || patchNca is null)
continue;
}


ApplicationControlProperty controlData = new();

using UniqueRef<IFile> nacpFile = new();
Expand All @@ -138,7 +128,7 @@ public static void SaveTitleUpdatesJson(VirtualFileSystem vfs, ulong application
catch (InvalidDataException)
{
Logger.Warning?.Print(LogClass.Application,
$"The header key is incorrect or missing and therefore the NCA header content type check has failed. Errored File: {path}");
$"The header key is incorrect or missing and therefore the NCA header content type check has failed. Malformed File: {path}");
}
catch (IOException exception)
{
Expand All @@ -154,9 +144,7 @@ public static void SaveTitleUpdatesJson(VirtualFileSystem vfs, ulong application
return result;
}

private static string PathToGameUpdatesJson(ulong applicationIdBase)
{
return Path.Combine(AppDataManager.GamesDirPath, applicationIdBase.ToString("x16"), "updates.json");
}
private static string PathToGameUpdatesJson(ulong applicationIdBase)
=> Path.Combine(AppDataManager.GamesDirPath, applicationIdBase.ToString("x16"), "updates.json");
}
}
6 changes: 3 additions & 3 deletions src/Ryujinx/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,12 @@ private void Renderer_ScreenCaptured(object sender, ScreenCaptureImageInfo e)
}

var colorType = e.IsBgra ? SKColorType.Bgra8888 : SKColorType.Rgba8888;
using SKBitmap bitmap = new SKBitmap(new SKImageInfo(e.Width, e.Height, colorType, SKAlphaType.Premul));
using SKBitmap bitmap = new(new SKImageInfo(e.Width, e.Height, colorType, SKAlphaType.Premul));

Marshal.Copy(e.Data, 0, bitmap.GetPixels(), e.Data.Length);

using SKBitmap bitmapToSave = new SKBitmap(bitmap.Width, bitmap.Height);
using SKCanvas canvas = new SKCanvas(bitmapToSave);
using SKBitmap bitmapToSave = new(bitmap.Width, bitmap.Height);
using SKCanvas canvas = new(bitmapToSave);

canvas.Clear(SKColors.Black);

Expand Down

0 comments on commit df9450d

Please sign in to comment.