/// <summary> /// Build a cover from the Jumbo icon of a file/directory /// </summary> /// <param name="path">path to the file</param> /// <returns>Pictures image</returns> public void BuildCover(string path) { LimeMsg.Debug("LimeMetadata BuildCover: path: {0}", path); ImageSource ret = null; try { LimeItem item = new LimeItem(path); using (var bmp = item.Bitmap(256)) { ret = LimeLib.ImageSourceFrom(bmp); } } catch { LimeMsg.Debug("LimeMetadata BuildCover: Failed: path: {0}", path); } Pictures = ret; }
/// <summary> /// Construct and retrieve Metadata from a directory/file path /// </summary> /// <param name="item">The <see cref="LimeItem"/> element to construct Metadata for.</param> /// <param name="coverOnly">Try to load only a cover, not the system icon</param> public LimeMetadata(LimeItem item, bool coverOnly) : this() { LimeLib.LifeTrace(this); // Disable modification detection _Modified = null; LimeMsg.Debug("LimeMetadata: {0}", item.Name); string path = item.Path; if (!coverOnly) { // Add Name Add("Name", item.Name, true, false); if (item.Link != null) { // Link path = item.Link; Add("LinkLabel"); } // Handle tasks if (item.Task) { Add("Task", item.Name, true); } // Display path Add("Path", item, "Path", readOnly: item.Task); } // Retrieve Tags if (!item.Task && !item.Directory && !LimeLib.IsPIDL(path) && !LimeLib.IsSSPD(path)) { LimeMsg.Debug("LimeMetadata: TagLib: {0}", item.Name); try { TagLibFile = TagLib.File.Create(path, TagLib.ReadStyle.Average | TagLib.ReadStyle.PictureLazy); } catch { LimeMsg.Debug("LimeMetadata: {0}: Failed TagLib.File.Create({1})", item.Name, path); } } // Extract Tags if (TagLibFile != null) { LimeMsg.Debug("LimeMetadata: TagLib done: {0}", item.Name); // Retrieve Type if (TagLibFile.Properties != null && TagLibFile.Properties.Codecs != null) { TagLib.MediaTypes[] prioTypes = new TagLib.MediaTypes[] { TagLib.MediaTypes.Video, TagLib.MediaTypes.Audio, TagLib.MediaTypes.Photo, TagLib.MediaTypes.Text }; var codecs = TagLibFile.Properties.Codecs; foreach (var codec in codecs) { if (codec != null) { TagLib.MediaTypes mask = codec.MediaTypes | (TagLib.MediaTypes)Type; foreach (var typ in prioTypes) { if ((mask & typ) != 0) { Type = (MediaType)typ; break; } } } } } else if (TagLibFile is TagLib.Image.NoMetadata.File) { Type = MediaType.Image; } } // Handle Links if (!coverOnly && item.Link != null) { using (var link = new ShellShortcut(item.Path)) { Add("LinkWorkdir", link.WorkingDirectory); //Add("LinkKey", link.Hotkey); Add("LinkWindowStyle", (ShellLinkWindowStyle)link.WindowStyle); if (Type == MediaType.None) { Add("LinkArguments", link.Arguments); } Add("LinkComment", link.Description); } Add("TagLabel"); // Target Path if (LimeLib.IsPIDL(item.Link)) { // Retrieve name of the PIDL try { var dInfo = new DirectoryInfoEx(new ShellDll.PIDL(LimeLib.GetPIDL(item.Link), true)); Add("LinkTarget", dInfo.Label, true); } catch { } } else { Add("LinkTarget", item.Link, LimeLib.IsSSPD(item.Link)); } } if (TagLibFile != null) { LimeMsg.Debug("LimeMetadata: TagLib done 2: {0}", item.Name); // Build the Properties BuildProperties(); // Build the Pictures image BuildCover(coverOnly); } else if (!coverOnly) { // Build the Pictures image from the file icon using (var bmp = item.Bitmap(256)) { Pictures = LimeLib.ImageSourceFrom(bmp); } } if (!coverOnly) { // Finalize BuildToolTip(); } // re-enable modification detection _Modified = false; LimeMsg.Debug("LimeMetadata End: {0}", item.Name); }