From 2b23463daa01226c5569d8e61d1d0959570354cf Mon Sep 17 00:00:00 2001 From: Andrew Glaze Date: Thu, 29 Dec 2022 10:52:30 -0500 Subject: [PATCH] Filter hidden game files from the Game List (#4051) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Filter “._” files from the game list * Filter all hidden files from the game list * Fix style Co-authored-by: gdkchan * merge OR expression into a pattern * migrate from GetFiles/Directories to Enumerate * Remove GetFilesInDirectory() * Update Ryujinx.Ui.Common/App/ApplicationLibrary.cs Co-authored-by: Ac_K * add error handeling * code cleanup Co-authored-by: gdkchan Co-authored-by: Ac_K --- Ryujinx.Ui.Common/App/ApplicationLibrary.cs | 81 +++++---------------- 1 file changed, 18 insertions(+), 63 deletions(-) diff --git a/Ryujinx.Ui.Common/App/ApplicationLibrary.cs b/Ryujinx.Ui.Common/App/ApplicationLibrary.cs index 1af7dc064..b1a8026e5 100644 --- a/Ryujinx.Ui.Common/App/ApplicationLibrary.cs +++ b/Ryujinx.Ui.Common/App/ApplicationLibrary.cs @@ -68,53 +68,6 @@ namespace Ryujinx.Ui.App.Common _cancellationToken?.Cancel(); } - public IEnumerable GetFilesInDirectory(string directory) - { - Stack stack = new Stack(); - - stack.Push(directory); - - while (stack.Count > 0) - { - string dir = stack.Pop(); - string[] content = Array.Empty(); - - try - { - content = Directory.GetFiles(dir, "*"); - } - catch (UnauthorizedAccessException) - { - Logger.Warning?.Print(LogClass.Application, $"Failed to get access to directory: \"{dir}\""); - } - - if (content.Length > 0) - { - foreach (string file in content) - { - yield return file; - } - } - - try - { - content = Directory.GetDirectories(dir); - } - catch (UnauthorizedAccessException) - { - Logger.Warning?.Print(LogClass.Application, $"Failed to get access to directory: \"{dir}\""); - } - - if (content.Length > 0) - { - foreach (string subdir in content) - { - stack.Push(subdir); - } - } - } - } - public void ReadControlData(IFileSystem controlFs, Span outProperty) { using var controlFile = new UniqueRef(); @@ -151,26 +104,28 @@ namespace Ryujinx.Ui.App.Common continue; } - foreach (string app in GetFilesInDirectory(appDir)) + try { - if (_cancellationToken.Token.IsCancellationRequested) + foreach (string app in Directory.EnumerateFiles(appDir, "*", SearchOption.AllDirectories)) { - return; - } - - string extension = Path.GetExtension(app).ToLower(); - - if ((extension == ".nsp") || - (extension == ".pfs0") || - (extension == ".xci") || - (extension == ".nca") || - (extension == ".nro") || - (extension == ".nso")) - { - applications.Add(app); - numApplicationsFound++; + if (_cancellationToken.Token.IsCancellationRequested) + { + return; + } + + string extension = Path.GetExtension(app).ToLower(); + + if (!File.GetAttributes(app).HasFlag(FileAttributes.Hidden) && extension is ".nsp" or ".pfs0" or ".xci" or ".nca" or ".nro" or ".nso") + { + applications.Add(app); + numApplicationsFound++; + } } } + catch (UnauthorizedAccessException) + { + Logger.Warning?.Print(LogClass.Application, $"Failed to get access to directory: \"{appDir}\""); + } } // Loops through applications list, creating a struct and then firing an event containing the struct for each application