Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace KonachanViewer
- {
- [Serializable]
- public class KonachanCollection
- {
- public ImageCollection Collection { get; }
- private const string Pattern = @"[Kk]onachan.com\s*-\s*(?<number>\d+)\s*-*\s*(?<tags>[\w .-]+)";
- public KonachanCollection(string path)
- {
- if (Directory.Exists(path))
- {
- Collection = new ImageCollection();
- var fileNames = Directory.GetFiles(path).Where(s => s.Contains("Konachan.com")).ToArray();
- var regex = new Regex(Pattern);
- foreach (var fileName in fileNames)
- {
- var match = regex.Match(fileName);
- var groups = match.Groups;
- var id = Int32.Parse(groups["number"].Value);
- var tags = groups["tags"].Value.Split(' ');
- Collection.Add(new Image(id, tags, fileName));
- }
- }
- }
- public static ImageCollection CreateCollection(string path)
- {
- var collection = new ImageCollection();
- if (!Directory.Exists(path)) throw new DirectoryNotFoundException("Не найдена папка с картинками)))");
- var fileNames = Directory.GetFiles(path).Where(s => s.Contains("Konachan.com")).ToArray();
- var regex = new Regex(Pattern);
- foreach (var fileName in fileNames)
- {
- var match = regex.Match(fileName);
- var groups = match.Groups;
- var id = Int32.Parse(groups["number"].Value);
- var tags = groups["tags"].Value.Split(' ');
- collection.Add(new Image(id, tags, fileName));
- }
- return collection;
- }
- public ImageCollection FindImages(params string[] tags)
- {
- return Collection.FindImages(tags);
- }
- public ImageCollection GetImages(int count)
- {
- var col = new ImageCollection();
- for (int i = 0; i <= count; i++)
- {
- col.Add(Collection[i]);
- }
- return col;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement