2025-05-12 06:55:09 +03:00
|
|
|
|
/*
|
|
|
|
|
* Author: Nikolay Dvurechensky
|
|
|
|
|
* Site: https://www.dvurechensky.pro/
|
|
|
|
|
* Gmail: dvurechenskysoft@gmail.com
|
|
|
|
|
* Last Updated: 12 мая 2025 06:51:53
|
|
|
|
|
* Version: 1.0.7
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using FileSearch.Logic.Model.Contexts;
|
2024-10-05 10:06:04 +03:00
|
|
|
|
using FileSearch.Logic.Model.Engine;
|
|
|
|
|
using Ionic.Zip;
|
|
|
|
|
|
|
|
|
|
namespace FileSearch.Logic.Model.CriterionSchemas
|
|
|
|
|
{
|
|
|
|
|
internal class NameAndZipCriterion : NameCriterion
|
|
|
|
|
{
|
|
|
|
|
public NameAndZipCriterion(string value, bool ignoreCasing, bool matchFullPath)
|
|
|
|
|
: base(value, ignoreCasing, matchFullPath)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override CriterionWeight Weight
|
|
|
|
|
{
|
|
|
|
|
get { return CriterionWeight.Light; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool IsMatch(FileSystemInfo fileSystemInfo, ICriterionContext context)
|
|
|
|
|
{
|
|
|
|
|
// базовое сравнение
|
|
|
|
|
if (base.IsMatch(fileSystemInfo, context))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// Должно заканчиваться на .ZIP.
|
|
|
|
|
if (string.IsNullOrEmpty(fileSystemInfo.Extension) || !fileSystemInfo.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Все найденные записи в ZIP-файле.
|
|
|
|
|
var myContext = (ZipCriterionContext)context;
|
|
|
|
|
|
|
|
|
|
using (var zip = ZipFile.Read(fileSystemInfo.FullName))
|
|
|
|
|
{
|
|
|
|
|
foreach (var entry in zip.EntryFileNames.Select(e => e.Replace('/', '\\')))
|
|
|
|
|
{
|
|
|
|
|
if (IsMatch(this.MatchFullPath ? Path.Combine(fileSystemInfo.FullName, entry) : Path.GetFileName(entry)))
|
|
|
|
|
{
|
|
|
|
|
myContext.Childs.Add(entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return myContext.Childs.Count > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override ICriterionContext BuildContext()
|
|
|
|
|
{
|
|
|
|
|
return new ZipCriterionContext();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|