Fix unhandled UnauthorizedAccessException causing crash while listing directories

This commit is contained in:
EliseZeroTwo 2020-03-24 18:41:54 +01:00
commit f4ec4a5b0e

View file

@ -52,26 +52,31 @@ namespace Ryujinx.Ui
List<string> applications = new List<string>(); List<string> applications = new List<string>();
foreach (string appDir in appDirs) 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}\""); if (!Directory.Exists(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); Logger.PrintWarning(LogClass.Application, $"The \"game_dirs\" section in \"Config.json\" contains an invalid directory: \"{appDir}\"");
numApplicationsFound++;
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 // Loops through applications list, creating a struct and then firing an event containing the struct for each application