From f4ec4a5b0ea1ab7cafcc9b04b2cd3618364396db Mon Sep 17 00:00:00 2001 From: EliseZeroTwo Date: Tue, 24 Mar 2020 18:41:54 +0100 Subject: [PATCH] Fix unhandled UnauthorizedAccessException causing crash while listing directories --- Ryujinx/Ui/ApplicationLibrary.cs | 39 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/Ryujinx/Ui/ApplicationLibrary.cs b/Ryujinx/Ui/ApplicationLibrary.cs index 6cf2a608c1..f7d226686d 100644 --- a/Ryujinx/Ui/ApplicationLibrary.cs +++ b/Ryujinx/Ui/ApplicationLibrary.cs @@ -52,26 +52,31 @@ namespace Ryujinx.Ui List applications = new List(); foreach (string appDir in appDirs) { - if (!Directory.Exists(appDir)) + try { - Logger.PrintWarning(LogClass.Application, $"The \"game_dirs\" section in \"Config.json\" contains an invalid directory: \"{appDir}\""); - - continue; - } - - foreach (string app in Directory.GetFiles(appDir, "*.*", SearchOption.AllDirectories)) - { - if ((Path.GetExtension(app).ToLower() == ".nsp") || - (Path.GetExtension(app).ToLower() == ".pfs0")|| - (Path.GetExtension(app).ToLower() == ".xci") || - (Path.GetExtension(app).ToLower() == ".nca") || - (Path.GetExtension(app).ToLower() == ".nro") || - (Path.GetExtension(app).ToLower() == ".nso")) + if (!Directory.Exists(appDir)) { - applications.Add(app); - numApplicationsFound++; + Logger.PrintWarning(LogClass.Application, $"The \"game_dirs\" section in \"Config.json\" contains an invalid directory: \"{appDir}\""); + + continue; } - } + + foreach (string app in Directory.GetFiles(appDir, "*.*", SearchOption.AllDirectories)) + { + if ((Path.GetExtension(app).ToLower() == ".nsp") || + (Path.GetExtension(app).ToLower() == ".pfs0") || + (Path.GetExtension(app).ToLower() == ".xci") || + (Path.GetExtension(app).ToLower() == ".nca") || + (Path.GetExtension(app).ToLower() == ".nro") || + (Path.GetExtension(app).ToLower() == ".nso")) + { + + applications.Add(app); + numApplicationsFound++; + + } + } + } catch (UnauthorizedAccessException) { } } // Loops through applications list, creating a struct and then firing an event containing the struct for each application