// // DirectoryArtistImage.cs // // Author: // Jacob Johnston (jacobj@inchoatethoughts.com) // // Copyright (C) 2009 Jacob Johnston // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . using System.IO; using ZenLibrary.RuleBase; namespace ZenLibrary.Rules { /// /// This rule scans a directory for the presence of an artist image /// as specified by a list of file names or file search strings. /// class DirectoryArtistImage : ConfigurableRule { private string artistImageFileCombinedString = "Artist.JPG;Artist.JPEG;Artist.PNG"; public override string Name { get { return "Directory Has Artist Image"; } } public override void Configure() { char[] splitChars = { ';' }; DirectoryArtistImageConfig configWindow = new DirectoryArtistImageConfig(); string[] artFiles = artistImageFileCombinedString.Split(splitChars); foreach (string file in artFiles) configWindow.FileList.Items.Add(file); if (configWindow.ShowDialog() == true) { artistImageFileCombinedString = string.Empty; foreach (string file in configWindow.FileList.Items) { artistImageFileCombinedString += file + ";"; } } Config.Instance.SaveConfig(); } public override TestType TestType { get { return TestType.DirectoryScan; } } protected override void WriteCustomConfigAttributes(System.Xml.XmlWriter writer) { writer.WriteAttributeString("ArtistImageFiles", artistImageFileCombinedString); base.WriteCustomConfigAttributes(writer); } protected override void ReadCustomConfigAttributes(System.Xml.XmlReader reader) { artistImageFileCombinedString = reader["ArtistImageFiles"]; base.ReadCustomConfigAttributes(reader); } public override RuleTestResult RunTest(DirectoryInfo directoryInfo, FileInfo fileInfo) { bool foundImage = false; char[] splitChars = {';'}; string[] imageFiles = artistImageFileCombinedString.Split(splitChars); foreach (string imageFileSearchString in imageFiles) { FileInfo[] files = directoryInfo.GetFiles(imageFileSearchString); if (files.Length > 0) { foundImage = true; } } if (foundImage) { RuleTestResult result = new RuleTestResult(); result.TestPassed = true; return result; } else { RuleTestResult result = new RuleTestResult(); result.TestPassed = false; result.ResultPath = directoryInfo.FullName; result.RuleTestFailedString = string.Format("Directory \"{0}\" does not contain an artist image.", result.ResultPath); return result; } } } }