Skip to content

Commit

Permalink
Fix FileNotFoundException in TryGetApplicationsFromFile() and improve…
Browse files Browse the repository at this point in the history
… loading applications (#7145)

* Don't load files from hidden subdirectories

* Catch FileNotFoundException in TryGetApplicationsFromFile()

* Skip non-existent files and bad symlinks when loading applications
  • Loading branch information
TSRBerry authored Aug 3, 2024
1 parent d97e995 commit 83fda10
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/Ryujinx.UI.Common/App/ApplicationLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,18 @@ private List<ApplicationData> GetApplicationsFromPfs(IFileSystem pfs, string fil
public bool TryGetApplicationsFromFile(string applicationPath, out List<ApplicationData> applications)
{
applications = [];
long fileSize;

long fileSize = new FileInfo(applicationPath).Length;
try
{
fileSize = new FileInfo(applicationPath).Length;
}
catch (FileNotFoundException)
{
Logger.Warning?.Print(LogClass.Application, $"The file was not found: '{applicationPath}'");

return false;
}

BlitStruct<ApplicationControlProperty> controlHolder = new(1);

Expand Down Expand Up @@ -502,7 +512,13 @@ public void LoadApplications(List<string> appDirs, Language desiredTitleLanguage

try
{
IEnumerable<string> files = Directory.EnumerateFiles(appDir, "*", SearchOption.AllDirectories).Where(file =>
EnumerationOptions options = new()
{
RecurseSubdirectories = true,
IgnoreInaccessible = false,
};

IEnumerable<string> files = Directory.EnumerateFiles(appDir, "*", options).Where(file =>
{
return
(Path.GetExtension(file).ToLower() is ".nsp" && ConfigurationState.Instance.UI.ShownFileTypes.NSP.Value) ||
Expand All @@ -521,14 +537,18 @@ public void LoadApplications(List<string> appDirs, Language desiredTitleLanguage
}

var fileInfo = new FileInfo(app);
string extension = fileInfo.Extension.ToLower();

if (!fileInfo.Attributes.HasFlag(FileAttributes.Hidden) && extension is ".nsp" or ".pfs0" or ".xci" or ".nca" or ".nro" or ".nso")
try
{
var fullPath = fileInfo.ResolveLinkTarget(true)?.FullName ?? fileInfo.FullName;

applicationPaths.Add(fullPath);
numApplicationsFound++;
}
catch (IOException exception)
{
Logger.Warning?.Print(LogClass.Application, $"Failed to resolve the full path to file: \"{app}\" Error: {exception}");
}
}
}
catch (UnauthorizedAccessException)
Expand Down

0 comments on commit 83fda10

Please sign in to comment.