aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTSRBerry <20988865+TSRBerry@users.noreply.github.com>2024-08-03 19:46:59 +0200
committerGitHub <noreply@github.com>2024-08-03 19:46:59 +0200
commit83fda10f6ef68950de395b5f9f6ab0bf58adced4 (patch)
treea429edeeaec12b0c1b76d8604221b5cbb222cacd
parentd97e995e5943aaddd8de88837b2dbfdf4d1616f4 (diff)
Fix FileNotFoundException in TryGetApplicationsFromFile() and improve loading applications (#7145)1.1.1365
* Don't load files from hidden subdirectories * Catch FileNotFoundException in TryGetApplicationsFromFile() * Skip non-existent files and bad symlinks when loading applications
-rw-r--r--src/Ryujinx.UI.Common/App/ApplicationLibrary.cs28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/Ryujinx.UI.Common/App/ApplicationLibrary.cs b/src/Ryujinx.UI.Common/App/ApplicationLibrary.cs
index e7c48162a..cd95c4d87 100644
--- a/src/Ryujinx.UI.Common/App/ApplicationLibrary.cs
+++ b/src/Ryujinx.UI.Common/App/ApplicationLibrary.cs
@@ -266,8 +266,18 @@ namespace Ryujinx.UI.App.Common
266 public bool TryGetApplicationsFromFile(string applicationPath, out List<ApplicationData> applications) 266 public bool TryGetApplicationsFromFile(string applicationPath, out List<ApplicationData> applications)
267 { 267 {
268 applications = []; 268 applications = [];
269 long fileSize;
269 270
270 long fileSize = new FileInfo(applicationPath).Length; 271 try
272 {
273 fileSize = new FileInfo(applicationPath).Length;
274 }
275 catch (FileNotFoundException)
276 {
277 Logger.Warning?.Print(LogClass.Application, $"The file was not found: '{applicationPath}'");
278
279 return false;
280 }
271 281
272 BlitStruct<ApplicationControlProperty> controlHolder = new(1); 282 BlitStruct<ApplicationControlProperty> controlHolder = new(1);
273 283
@@ -502,7 +512,13 @@ namespace Ryujinx.UI.App.Common
502 512
503 try 513 try
504 { 514 {
505 IEnumerable<string> files = Directory.EnumerateFiles(appDir, "*", SearchOption.AllDirectories).Where(file => 515 EnumerationOptions options = new()
516 {
517 RecurseSubdirectories = true,
518 IgnoreInaccessible = false,
519 };
520
521 IEnumerable<string> files = Directory.EnumerateFiles(appDir, "*", options).Where(file =>
506 { 522 {
507 return 523 return
508 (Path.GetExtension(file).ToLower() is ".nsp" && ConfigurationState.Instance.UI.ShownFileTypes.NSP.Value) || 524 (Path.GetExtension(file).ToLower() is ".nsp" && ConfigurationState.Instance.UI.ShownFileTypes.NSP.Value) ||
@@ -521,14 +537,18 @@ namespace Ryujinx.UI.App.Common
521 } 537 }
522 538
523 var fileInfo = new FileInfo(app); 539 var fileInfo = new FileInfo(app);
524 string extension = fileInfo.Extension.ToLower();
525 540
526 if (!fileInfo.Attributes.HasFlag(FileAttributes.Hidden) && extension is ".nsp" or ".pfs0" or ".xci" or ".nca" or ".nro" or ".nso") 541 try
527 { 542 {
528 var fullPath = fileInfo.ResolveLinkTarget(true)?.FullName ?? fileInfo.FullName; 543 var fullPath = fileInfo.ResolveLinkTarget(true)?.FullName ?? fileInfo.FullName;
544
529 applicationPaths.Add(fullPath); 545 applicationPaths.Add(fullPath);
530 numApplicationsFound++; 546 numApplicationsFound++;
531 } 547 }
548 catch (IOException exception)
549 {
550 Logger.Warning?.Print(LogClass.Application, $"Failed to resolve the full path to file: \"{app}\" Error: {exception}");
551 }
532 } 552 }
533 } 553 }
534 catch (UnauthorizedAccessException) 554 catch (UnauthorizedAccessException)