internal CUEToolsSourceFile ChooseFile(List<CUEToolsSourceFile> sourceFiles, string defaultFileName, bool quietIfSingle) { if (sourceFiles.Count <= 0) return null; if (defaultFileName != null) { CUEToolsSourceFile defaultFile = null; foreach (CUEToolsSourceFile file in sourceFiles) if (Path.GetFileNameWithoutExtension(file.path).ToLower() == defaultFileName.ToLower()) { if (defaultFile != null) { defaultFile = null; break; } defaultFile = file; } if (defaultFile != null) return defaultFile; } if (quietIfSingle && sourceFiles.Count == 1) return sourceFiles[0]; if (CUEToolsSelection == null) return null; CUEToolsSelectionEventArgs e = new CUEToolsSelectionEventArgs(); e.choices = sourceFiles.ToArray(); CUEToolsSelection(this, e); if (e.selection == -1) return null; return sourceFiles[e.selection]; }
public void LoadAlbumArt(TagLib.File fileInfo) { if ((_config.extractAlbumArt || _config.CopyAlbumArt) && fileInfo != null) foreach (TagLib.IPicture picture in fileInfo.Tag.Pictures) if (picture.Type == TagLib.PictureType.FrontCover) if (picture.MimeType == "image/jpeg") { _albumArt.Add(picture); return; } if ((_config.extractAlbumArt || _config.embedAlbumArt) && !_isCD) { foreach (string tpl in _config.advanced.CoverArtFiles) { string name = tpl.Replace("%album%", Metadata.Title).Replace("%artist%", Metadata.Artist); string imgPath = Path.Combine(_isArchive ? _archiveCUEpath : _inputDir, name); bool exists = _isArchive ? _archiveContents.Contains(imgPath) : File.Exists(imgPath); if (exists) { TagLib.File.IFileAbstraction file = _isArchive ? (TagLib.File.IFileAbstraction)new ArchiveFileAbstraction(this, imgPath) : (TagLib.File.IFileAbstraction)new TagLib.File.LocalFileAbstraction(imgPath); TagLib.Picture pic = new TagLib.Picture(file); pic.Description = name; _albumArt.Add(pic); return; } } if (!_isArchive && _config.advanced.CoverArtSearchSubdirs) { List<string> allfiles = new List<string>(Directory.GetFiles(_inputDir, "*.jpg", SearchOption.AllDirectories)); // TODO: archive case foreach (string tpl in _config.advanced.CoverArtFiles) { string name = tpl.Replace("%album%", Metadata.Title).Replace("%artist%", Metadata.Artist); List<string> matching = allfiles.FindAll(s => Path.GetFileName(s) == name); if (matching.Count == 1) { string imgPath = matching[0]; TagLib.File.IFileAbstraction file = _isArchive ? (TagLib.File.IFileAbstraction)new ArchiveFileAbstraction(this, imgPath) : (TagLib.File.IFileAbstraction)new TagLib.File.LocalFileAbstraction(imgPath); TagLib.Picture pic = new TagLib.Picture(file); pic.Description = name; _albumArt.Add(pic); return; } } if (CUEToolsSelection != null && ((Action == CUEAction.Encode && allfiles.Count < 32) || (Action != CUEAction.Encode && allfiles.Count < 2) ) ) { foreach (string imgPath in allfiles) { TagLib.Picture pic = new TagLib.Picture(imgPath); if (imgPath.StartsWith(_inputDir)) pic.Description = imgPath.Substring(_inputDir.Length).Trim(Path.DirectorySeparatorChar); else pic.Description = Path.GetFileName(imgPath); _albumArt.Add(pic); } if (_albumArt.Count > 0) { CUEToolsSelectionEventArgs e = new CUEToolsSelectionEventArgs(); e.choices = _albumArt.ToArray(); CUEToolsSelection(this, e); TagLib.IPicture selected = e.selection == -1 ? null : _albumArt[e.selection]; _albumArt.RemoveAll(t => t != selected); } } } } }
private void MakeSelection(object sender, CUEToolsSelectionEventArgs e) { if (_batchPaths.Count != 0) return; this.Invoke((MethodInvoker)delegate() { frmChoice dlg = new frmChoice(); if (_choiceWidth != 0 && _choiceHeight != 0) dlg.Size = new Size(_choiceWidth, _choiceHeight); if (_choiceMaxed) dlg.WindowState = FormWindowState.Maximized; dlg.Choices = e.choices; if (dlg.ShowDialog(this) == DialogResult.OK) e.selection = dlg.ChosenIndex; _choiceMaxed = dlg.WindowState == FormWindowState.Maximized; if (!_choiceMaxed) { _choiceHeight = dlg.Height; _choiceWidth = dlg.Width; } }); }