mirror of
https://github.com/ldqk/Masuit.Tools.git
synced 2026-10-22 00:43:10 +08:00
42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Xml;
|
|
using Masuit.Tools.Mime;
|
|
|
|
namespace Masuit.Tools.Files.FileDetector.Detectors;
|
|
|
|
[FormatCategory(FormatCategory.Document)]
|
|
internal sealed class ConfigurationDetector : IDetector
|
|
{
|
|
public string Precondition => "txt";
|
|
|
|
public string Extension => "config";
|
|
|
|
public string MimeType => new MimeMapper().GetMimeFromExtension("." + Extension);
|
|
|
|
public List<FormatCategory> FormatCategories => GetType().GetCustomAttributes<FormatCategoryAttribute>().Select(a => a.Category).ToList();
|
|
|
|
public bool Detect(Stream stream)
|
|
{
|
|
try
|
|
{
|
|
var reader = XmlReader.Create(stream, new XmlReaderSettings()
|
|
{
|
|
});
|
|
if (reader.Read() && reader.IsStartElement() && reader.Name == "configuration")
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public override string ToString() => "Microsoft .NET Configuration File Detector";
|
|
}
|