From d1e24ba5c247bb9cfdeca7251bf5f8951c927576 Mon Sep 17 00:00:00 2001
From: mageven <62494521+mageven@users.noreply.github.com>
Date: Tue, 26 Jan 2021 23:15:07 +0530
Subject: Initial Setup: Reload keys before verifying firmware (#1955)

* Initial Setup: Reload keys before verifying firmware

Also, display the NoKeys dialog if keyset is empty when verifying
firmware.

* LoadApplications: Remove the lone debug log and print the error directly
---
 Ryujinx.HLE/FileSystem/Content/ContentManager.cs | 9 +++++++++
 1 file changed, 9 insertions(+)

(limited to 'Ryujinx.HLE/FileSystem/Content/ContentManager.cs')

diff --git a/Ryujinx.HLE/FileSystem/Content/ContentManager.cs b/Ryujinx.HLE/FileSystem/Content/ContentManager.cs
index 4c4f3c86..1630835d 100644
--- a/Ryujinx.HLE/FileSystem/Content/ContentManager.cs
+++ b/Ryujinx.HLE/FileSystem/Content/ContentManager.cs
@@ -653,6 +653,15 @@ namespace Ryujinx.HLE.FileSystem.Content
 
         public SystemVersion VerifyFirmwarePackage(string firmwarePackage)
         {
+            _virtualFileSystem.Reload();
+
+            // 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.IsEmpty())
+            {
+                throw new MissingKeyException("HeaderKey is empty. Cannot decrypt NCA headers.");
+            }
+
             Dictionary<ulong, List<(NcaContentType type, string path)>> updateNcas = new Dictionary<ulong, List<(NcaContentType, string)>>();
 
             if (Directory.Exists(firmwarePackage))
-- 
cgit v1.2.3-70-g09d2