protected static string?GetAppExecLinkPath()
        {
            string localAppDataPath = Environment.GetEnvironmentVariable("LOCALAPPDATA");

            if (localAppDataPath is null)
            {
                return(null);
            }

            string windowsAppsDir = Path.Join(localAppDataPath, "Microsoft", "WindowsApps");

            if (!Directory.Exists(windowsAppsDir))
            {
                return(null);
            }

            var opts = new EnumerationOptions {
                RecurseSubdirectories = true
            };

            return(new FileSystemEnumerable <string?>(
                       windowsAppsDir,
                       (ref FileSystemEntry entry) => entry.ToFullPath(),
                       opts)
            {
                ShouldIncludePredicate = (ref FileSystemEntry entry) =>
                                         FileSystemName.MatchesWin32Expression("*.exe", entry.FileName) &&
                                         (entry.Attributes & FileAttributes.ReparsePoint) != 0
            }.FirstOrDefault());
        }
Exemple #2
0
        private static bool MatchesPattern(string expression, ReadOnlySpan <char> name, EnumerationOptions options)
        {
            bool ignoreCase = (options.MatchCasing == MatchCasing.PlatformDefault && !PathInternal.IsCaseSensitive) ||
                              options.MatchCasing == MatchCasing.CaseInsensitive;

            return(options.MatchType switch
            {
                MatchType.Simple => FileSystemName.MatchesSimpleExpression(expression.AsSpan(), name, ignoreCase),
                MatchType.Win32 => FileSystemName.MatchesWin32Expression(expression.AsSpan(), name, ignoreCase),
                _ => throw new ArgumentOutOfRangeException(nameof(options)),
            });
 public static void Win32Match(string expression, string name, bool ignoreCase, bool expected)
 {
     Assert.Equal(expected, FileSystemName.MatchesWin32Expression(expression, name.AsSpan(), ignoreCase));
 }
 /// <inheritdoc />
 public bool MatchesWin32Expression(ReadOnlySpan <char> expression, ReadOnlySpan <char> name, bool ignoreCase = true)
 {
     return(FileSystemName.MatchesWin32Expression(expression, name, ignoreCase));
 }