/// <summary> /// 画像ファイルの情報を読み込み、新規or変更されたレコードに追加 /// </summary> /// <param name="file"></param> /// <param name="library"></param> /// <param name="prospectedTags"></param> private void CheckImage(ImageFileInformation file, IReadOnlyDictionary <string, Record> library, ConcurrentDictionary <string, ConcurrentBag <TagManager> > prospectedTags) { if (file == null || file.IsNotFound) { return; } var newItemId = file.Path; this.DetectedFiles.Add(newItemId); Record existingItem; var itemExists = library.TryGetValue(newItemId, out existingItem); if (!itemExists || existingItem.DateModified < file.DateModified || existingItem.Size != file.Size) { var newItem = new Record(file.Path) { DateModified = file.DateModified, DateCreated = file.DateCreated, Height = file.Height, Rating = file.Rating, Width = file.Width, Size = file.Size, }; if (!itemExists || existingItem == null) { //新規 this.AddedFiles[newItemId] = newItem; } else { newItem.CopyAdditionalInformation(existingItem); //更新 this.UpdatedFiles[newItemId] = newItem; Debug.WriteLine($"updated : {newItemId}"); } if (file.Keywords != null) { foreach (var tag in file.Keywords) { var bag = prospectedTags.GetOrAdd(tag, new ConcurrentBag <TagManager>()); bag.Add(newItem.TagSet); } } } else { this.SkippedFiles.Add(newItemId); } }
/// <summary> /// 画像ファイルの情報を取得 /// </summary> /// <param name="fullPath"></param> /// <param name="level"></param> /// <returns></returns> public ImageFileInformation GetImage(string fullPath, PropertiesLevel level) { ImageFileInformation image = null; var hasDecoration = true; try { var name = System.IO.Path.GetFileName(fullPath); var isUnknownType = false; var width = 0; var height = 0; var length = 0L; //画像ファイルのヘッダからサイズを抽出 if (level >= PropertiesLevel.Size) { var graphicInfo = new GraphicInformation(fullPath); width = graphicInfo.GraphicSize.Width; height = graphicInfo.GraphicSize.Height; length = graphicInfo.FileSize; isUnknownType = graphicInfo.Type == GraphicFileType.Unknown; //タグ・評価を付加できないファイルの場合は情報読み取りをスキップ if (graphicInfo.Type != GraphicFileType.Jpeg && graphicInfo.Type != GraphicFileType.Tiff && graphicInfo.Type != GraphicFileType.Psd && graphicInfo.Type != GraphicFileType.Unknown) { hasDecoration = false; } } var creationTime = defaultDateTime; var lastWriteTime = defaultDateTime; //日付情報 if (level >= PropertiesLevel.Basic) { try { var file = new System.IO.FileInfo(fullPath); creationTime = ImageFileUtility.ConvertDateTime(file.CreationTime); lastWriteTime = ImageFileUtility.ConvertDateTime(file.LastWriteTime); } catch { //No operation } } image = new ImageFileInformation() { DateCreated = creationTime, DateModified = lastWriteTime, Name = name, Path = fullPath, Height = height, Width = width, Size = length, Rating = 0, Keywords = null, IsNotFound = isUnknownType, }; } catch { return(null); } if (image == null) { return(null); } var rating = 0; HashSet <string> tags = null; //画像の評価・キーワード(時間かかる) if (level >= PropertiesLevel.Shell && hasDecoration) { try { var fileAccesser = this.GetFile(fullPath, image.Name); var kw = fileAccesser.GetDetailsOf(18); if (kw != null) { tags = new HashSet <string>(kw .Split(';') .Select(x => x.Trim()) .Where(x => x != null && x.Length > 0) .Distinct()); } rating = 0; var rateText = fileAccesser.GetDetailsOf(19); var rateArray = rateText? .Select(x => x - '0') .Where(x => x > 0 && x <= 5) .ToArray(); if (rateArray != null && rateArray.Length == 1) { rating = RateConvertingHelper.Reverse(rateArray[0]); } } catch { return(null); } } image.Rating = rating; image.Keywords = tags; return(image); }