Actually handle not having privileges for a directory

This commit is contained in:
EliseZeroTwo 2020-03-25 13:01:42 +01:00
commit 6de83dea9c

View file

@ -39,6 +39,47 @@ namespace Ryujinx.Ui
private static Language _desiredTitleLanguage; private static Language _desiredTitleLanguage;
private static bool _loadingError; private static bool _loadingError;
public static IEnumerable<string> GetFilesInDirectory(string directory)
{
Stack<string> stack = new Stack<string>();
stack.Push(directory);
while (stack.Count > 0)
{
string dir = stack.Pop();
string[] content = { };
try
{
content = Directory.GetFiles(dir, "*");
}
catch (UnauthorizedAccessException)
{
Logger.PrintWarning(LogClass.Application, $"Failed to get access to directory to list files: \"{dir}\"");
}
if (content.Length > 0)
{
foreach (string file in content)
yield return file;
}
try
{
content = Directory.GetDirectories(dir);
}
catch (UnauthorizedAccessException)
{
Logger.PrintWarning(LogClass.Application, $"Failed to get access to directory: \"{dir}\"");
}
if (content.Length > 0)
{
foreach (string subdir in content)
stack.Push(subdir);
}
}
}
public static void LoadApplications(List<string> appDirs, VirtualFileSystem virtualFileSystem, Language desiredTitleLanguage) public static void LoadApplications(List<string> appDirs, VirtualFileSystem virtualFileSystem, Language desiredTitleLanguage)
{ {
int numApplicationsFound = 0; int numApplicationsFound = 0;
@ -52,8 +93,7 @@ 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)
{ {
try
{
if (!Directory.Exists(appDir)) if (!Directory.Exists(appDir))
{ {
Logger.PrintWarning(LogClass.Application, $"The \"game_dirs\" section in \"Config.json\" contains an invalid directory: \"{appDir}\""); Logger.PrintWarning(LogClass.Application, $"The \"game_dirs\" section in \"Config.json\" contains an invalid directory: \"{appDir}\"");
@ -61,8 +101,11 @@ namespace Ryujinx.Ui
continue; continue;
} }
foreach (string app in Directory.GetFiles(appDir, "*.*", SearchOption.AllDirectories))
foreach (string app in GetFilesInDirectory(appDir))
{ {
if ((Path.GetExtension(app).ToLower() == ".nsp") || if ((Path.GetExtension(app).ToLower() == ".nsp") ||
(Path.GetExtension(app).ToLower() == ".pfs0") || (Path.GetExtension(app).ToLower() == ".pfs0") ||
(Path.GetExtension(app).ToLower() == ".xci") || (Path.GetExtension(app).ToLower() == ".xci") ||
@ -76,7 +119,6 @@ namespace Ryujinx.Ui
} }
} }
} 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