From fa16c9c3bd76d96eea6dfee9fc11e50d4243e4cb Mon Sep 17 00:00:00 2001
From: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
Date: Sat, 22 Jul 2023 17:37:27 +0200
Subject: [PATCH] Add more debug information when loading game files

---
 src/LibRyujinx/LibRyujinx.cs | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/LibRyujinx/LibRyujinx.cs b/src/LibRyujinx/LibRyujinx.cs
index c19f5f476..6431efa2e 100644
--- a/src/LibRyujinx/LibRyujinx.cs
+++ b/src/LibRyujinx/LibRyujinx.cs
@@ -142,12 +142,12 @@ namespace LibRyujinx
             }
 
             var gameInfo = new GameInfo
-                {
-                    FileSize = gameStream.Length * 0.000000000931, TitleName = "Unknown", TitleId = "0000000000000000",
-                    Developer = "Unknown",
-                    Version = "0",
-                    Icon = null,
-                };
+            {
+                FileSize = gameStream.Length * 0.000000000931, TitleName = "Unknown", TitleId = "0000000000000000",
+                Developer = "Unknown",
+                Version = "0",
+                Icon = null,
+            };
 
             const Language TitleLanguage = Language.AmericanEnglish;
 
@@ -225,6 +225,12 @@ namespace LibRyujinx
 
                         gameInfo.TitleId = id;
 
+                        if (controlFs == null)
+                        {
+                            Logger.Error?.Print(LogClass.Application, $"No control FS was returned. Unable to process game any further: {gameInfo.TitleName}");
+                            return null;
+                        }
+
                         // Check if there is an update available.
                         if (IsUpdateApplied(gameInfo.TitleId, out IFileSystem? updatedControlFs))
                         {
@@ -376,6 +382,11 @@ namespace LibRyujinx
                 }
                 (_, _, Nca? controlNca) = GetGameData(SwitchDevice.VirtualFileSystem, pfs, 0);
 
+                if (controlNca == null)
+                {
+                    Logger.Warning?.Print(LogClass.Application, "Control NCA is null. Unable to load control FS.");
+                }
+
                 // Return the ControlFS
                 controlFs = controlNca?.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None);
                 titleId = controlNca?.Header.TitleId.ToString("x16");
@@ -447,9 +458,9 @@ namespace LibRyujinx
                     if (patchNca != null && controlNca != null)
                     {
                         updatedControlFs = controlNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None);
-                    }
 
-                    return true;
+                        return true;
+                    }
                 }
                 catch (InvalidDataException)
                 {