/// <inheritdoc />
        public bool IsApplicable(ModKey modKey, FileName archiveFileName)
        {
            if (!archiveFileName.Extension.Equals(_archiveExtensionProvider.Get(), StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }
            var nameWithoutExt = archiveFileName.NameWithoutExtension.AsSpan();

            // See if the name matches straight up
            if (modKey.Name.AsSpan().Equals(nameWithoutExt, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            // Trim ending "type" information and try again
            var delimIndex = nameWithoutExt.LastIndexOf(" - ");

            if (delimIndex == -1)
            {
                return(false);
            }

            return(modKey.Name.AsSpan().Equals(nameWithoutExt.Slice(0, delimIndex), StringComparison.OrdinalIgnoreCase));
        }
Пример #2
0
        private IEnumerable <FilePath> GetInternal(ModKey?modKey, IComparer <FileName>?archiveOrdering)
        {
            if (modKey.HasValue && modKey.Value.IsNull)
            {
                return(Enumerable.Empty <FilePath>());
            }

            var ret = _fileSystem.Directory.EnumerateFilePaths(_dataDirectoryProvider.Path, searchPattern: $"*{_archiveExtension.Get()}");

            if (modKey != null)
            {
                var iniListedArchives = _iniListings.Get().ToHashSet();
                ret = ret
                      .Where(archive =>
                {
                    if (iniListedArchives.Contains(archive.Name))
                    {
                        return(true);
                    }
                    return(_applicability.IsApplicable(modKey.Value, archive.Name));
                });
            }
            if (archiveOrdering != null)
            {
                return(ret.OrderBy(x => x.Name, archiveOrdering));
            }
            return(ret);
        }