private void editMetadataToolStripMenuItem_Click(object sender, EventArgs e) { var node = contextMenuStripFileTree.Tag as CUEControls.FileSystemTreeNode; string path = null; if (node != null && node is FileSystemTreeNodeLocalDBEntry) path = node.Path; if (node != null && node is FileSystemTreeNodeLocalDBCollision) path = (node as FileSystemTreeNodeLocalDBCollision).Group[0].Path; if (path == null) return; var CueSheet = new CUESheet(_profile._config); CueSheet.PasswordRequired += new EventHandler<CompressionPasswordRequiredEventArgs>(PasswordRequired); CueSheet.CUEToolsProgress += new EventHandler<CUEToolsProgressEventArgs>(SetStatus); //cueSheet.CUEToolsSelection += new EventHandler<CUEToolsSelectionEventArgs>(MakeSelection); try { CueSheet.Open(path); } catch (Exception ex) { ShowErrorMessage(ex); return; } CueSheet.UseLocalDB(_localDB); frmChoice dlg = new frmChoice(); if (_choiceWidth != 0 && _choiceHeight != 0) dlg.Size = new Size(_choiceWidth, _choiceHeight); if (_choiceMaxed) dlg.WindowState = FormWindowState.Maximized; dlg.CUE = CueSheet; dlg.LookupAlbumInfo(true, node is FileSystemTreeNodeLocalDBEntry, true, CTDBMetadataSearch.Default); var dlgRes = dlg.ShowDialog(this); _choiceMaxed = dlg.WindowState == FormWindowState.Maximized; if (!_choiceMaxed) { _choiceHeight = dlg.Height; _choiceWidth = dlg.Width; } if (dlgRes == DialogResult.OK && dlg.ChosenRelease != null) { if (node is FileSystemTreeNodeLocalDBCollision) { var group = (node as FileSystemTreeNodeLocalDBCollision).Group; foreach (var item in group) item.Metadata.CopyMetadata(dlg.ChosenRelease.metadata); } else if (node is FileSystemTreeNodeLocalDBEntry) { var item = (node as FileSystemTreeNodeLocalDBEntry).Item; item.Metadata.CopyMetadata(dlg.ChosenRelease.metadata); } node.Text = node.DisplayName; _localDB.Dirty = true; SaveDatabase(); } CueSheet.Close(); }
public void ScanLocalDB(string folder) { // Delete missing files string norm = CUEToolsLocalDBEntry.NormalizePath(folder); if (norm.Length != 0 && norm[norm.Length - 1] != System.IO.Path.DirectorySeparatorChar) norm = norm + System.IO.Path.DirectorySeparatorChar; ReportProgress("Checking known files", 0.0); int oldi = 0, oldn = _localDB.Count; foreach (var item in _localDB.ToArray()) { bool matches = false; oldi++; if (item.AudioPaths != null) { foreach (var f in item.AudioPaths) if (f.StartsWith(norm)) { matches = true; CheckStop(); if (!File.Exists(f)) { _localDB.Remove(item); _localDB.Dirty = true; continue; } } } if (item.InputPaths != null) { foreach (var f in item.InputPaths.ToArray()) if (f.StartsWith(norm)) { CheckStop(); ReportProgress("Checking " + f, (double)oldi / oldn); matches = true; if (!File.Exists(f)) { item.InputPaths.Remove(f); _localDB.Dirty = true; } else { var cueSheet = new CUESheet(_config); cueSheet.UseLocalDB(_localDB); try { cueSheet.Open(f); List<string> fullAudioPaths = cueSheet._sourcePaths == null ? null : cueSheet._sourcePaths.ConvertAll(p => CUEToolsLocalDBEntry.NormalizePath(p)); if (!item.Equals(cueSheet._toc, fullAudioPaths)) { item.InputPaths.Remove(f); _localDB.Dirty = true; } } catch (Exception) { item.InputPaths.Remove(f); _localDB.Dirty = true; } cueSheet.Close(); } } if (matches && item.InputPaths.Count == 0) { _localDB.Remove(item); _localDB.Dirty = true; continue; } } } // Add new files ReportProgress("Scanning for new files", 0.0); var results = new List<string>(); int n = 2, j = 0; foreach (var fmt in _config.formats) if (fmt.Value.allowLossless) n++; CheckStop(); ReportProgress("Scanning *.cue", (double)(j++) / n); results.AddRange(Directory.GetFiles(folder, "*.cue", SearchOption.AllDirectories)); CheckStop(); ReportProgress("Scanning *.m3u", (double)(j++) / n); results.AddRange(Directory.GetFiles(folder, "*.m3u", SearchOption.AllDirectories)); foreach (var fmt in _config.formats) if (fmt.Value.allowLossless) { CheckStop(); ReportProgress("Scanning *." + fmt.Key, (double)(j++) / n); results.AddRange(Directory.GetFiles(folder, "*." + fmt.Key, SearchOption.AllDirectories)); } ReportProgress("Checking new files", 0.0); int i = 0; foreach (var result in results) { CheckStop(); var path = CUEToolsLocalDBEntry.NormalizePath(result); var pathextension = Path.GetExtension(path).ToLower(); bool skip = false; if (_localDB.Find( item => item.HasPath(path) || (item.AudioPaths != null && item.AudioPaths.Count > 1 && item.AudioPaths.Contains(path)) ) != null) skip = true; if (!skip && pathextension == ".m3u") { var contents = new List<string>(); using (StreamReader m3u = new StreamReader(path)) { do { string line = m3u.ReadLine(); if (line == null) break; if (line == "" || line[0] == '#') continue; //if (line.IndexOfAny(Path.GetInvalidPathChars()) >= 0) // continue; try { string extension = Path.GetExtension(line); CUEToolsFormat fmt1; if (!extension.StartsWith(".") || !_config.formats.TryGetValue(extension.ToLower().Substring(1), out fmt1) || !fmt1.allowLossless) { skip = true; break; } string fullpath = CUEToolsLocalDBEntry.NormalizePath(Path.Combine(Path.GetDirectoryName(path), line)); if (!File.Exists(fullpath)) { skip = true; break; } contents.Add(fullpath); } catch { skip = true; break; } } while (!skip); } if (!skip && _localDB.Find(item => item.EqualAudioPaths(contents)) != null) skip = true; } if (!skip && pathextension != ".cue" && pathextension != ".m3u") { if (_localDB.Find(item => item.AudioPaths != null && item.AudioPaths.Count == 1 && item.AudioPaths[0] == path ) != null) { CUEToolsFormat fmt; if (!pathextension.StartsWith(".") || !_config.formats.TryGetValue(pathextension.Substring(1), out fmt) || !fmt.allowLossless || !fmt.allowEmbed) skip = true; else { TagLib.File fileInfo; TagLib.UserDefined.AdditionalFileTypes.Config = _config; TagLib.File.IFileAbstraction file = new TagLib.File.LocalFileAbstraction(path); fileInfo = TagLib.File.Create(file); NameValueCollection tags = Tagging.Analyze(fileInfo); if (tags.Get("CUESHEET") == null) skip = true; } } } if (skip) { ReportProgress("Skipping " + path, (double)(i++) / results.Count); } else { ReportProgress("Checking " + path, (double)(i++) / results.Count); var cueSheet = new CUESheet(_config); cueSheet.UseLocalDB(_localDB); //cueSheet.PasswordRequired += new EventHandler<CompressionPasswordRequiredEventArgs>(PasswordRequired); //cueSheet.CUEToolsProgress += new EventHandler<CUEToolsProgressEventArgs>(SetStatus); //cueSheet.CUEToolsSelection += new EventHandler<CUEToolsSelectionEventArgs>(MakeSelection); try { cueSheet.Open(path); cueSheet.OpenLocalDBEntry(); } catch (Exception) { } cueSheet.Close(); } } _localDB.Save(); }
private void listViewTracks_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (files.Length == 1) { string path = files[0]; try { CUESheet cue = new CUESheet(_config); cue.Open(path); for (int iTrack = 0; iTrack < cue.TrackCount; iTrack++) { DataSet1.PlaylistRow row = dataSet.Playlist.AddPlaylistRow( path, cue.Metadata.Artist, cue.Metadata.Tracks[iTrack].Title, cue.Metadata.Title, (int)cue.TOC[cue.TOC.FirstAudio + iTrack].Length / 75, iTrack + 1); listViewTracks.Items.Add(ToItem(row)); } cue.Close(); return; } catch (Exception ex) { Trace.WriteLine(ex.Message); } FileInfo fi = new FileInfo(path); if (fi.Extension != ".cue") { DataSet1.PlaylistRow row = dataSet.Playlist.AddPlaylistRow( path, null, // cue.Artist, null, // cue.Tracks[iTrack].Title, null, // cue.Title, 0, // (int)cue.TOC[cue.TOC.FirstAudio + iTrack].Length / 75, 0); listViewTracks.Items.Add(ToItem(row)); } } } }