private void btnLocateToolnix_Click(object sender, RoutedEventArgs e) { using (var dialog = new FolderBrowserDialog()) { DialogResult result = dialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { var selectedPath = dialog.SelectedPath; if (File.Exists(selectedPath + "\\" + "mkvinfo.exe") && File.Exists(selectedPath + "\\" + "mkvextract.exe")) { SettingsHelper.SetToolnixPath(selectedPath); } else { MessageBoxResult message = MessageBox.Show(this, "Selected folder doesn't contain MKVToolnix utils! Please, specify the correct MKVToolnix folder", "Wrong", MessageBoxButton.OK, MessageBoxImage.Exclamation); } } } }
private void btnAddFile_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = true; dialog.Filter = "MKV Files (*.mkv)|*.mkv"; ObservableCollection <MkvFile> items = new ObservableCollection <MkvFile>(); List <Track> intersection = new List <Track>(); if (dialog.ShowDialog() == true) { foreach (var fileName in dialog.FileNames) { // start process var proc = new Process { StartInfo = new ProcessStartInfo { FileName = SettingsHelper.GetMkvInfoPath(), Arguments = "--ui-language en \"" + fileName + "\"", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true } }; proc.StartInfo.StandardOutputEncoding = Encoding.UTF8; proc.Start(); String output = null; // get output while (!proc.StandardOutput.EndOfStream) { output += proc.StandardOutput.ReadLine(); } proc.Close(); var item = new MkvFile(); item.Path = fileName; item.Name = Path.GetFileName(fileName); item.Tracks = new EbmlParser().Parse(output); item.Tracks.ForEach(x => x.Parent = item); items.Add(item); } } intersection.AddRange(items.First().Tracks); foreach (var mkvFile in items) { intersection = intersection.Intersect(mkvFile.Tracks, new TrackComparer()).ToList(); } tvFiles.ItemsSource = items; ObservableCollection <BatchTrack> batchTracks = new ObservableCollection <BatchTrack>(); foreach (var track in intersection) { batchTracks.Add(new BatchTrack { Name = string.Format("{0}, {1} ({2})", track.Type, track.Language, track.Name), Track = track }); } lbBatchTracksToExtract.ItemsSource = batchTracks; ToggleButtonState(); }
//here bad student work private void btnExtract_Click(object sender, RoutedEventArgs e) { int CountTrack = 0; foreach (MKVCleaver2.MkvFile file in this.tvFiles.Items) { string commandstr = string.Empty; if (file.IsSelected == true) { foreach (MKVCleaver2.BatchTrack track in this.lbBatchTracksToExtract.Items) { if (track.IsSelected == true) { CountTrack++; if (tboutputDir.Text == string.Empty) { string standartPath = file.Path.Substring(0, file.Path.Length - file.Name.Length); commandstr += track.Track.Number.ToString() + ":\"" + standartPath + file.Name + "_" + track.Track.Type + "_" + track.Track.Language + "." + SettingsHelper.GetCodecContainerExtension(track.Track.Codec) + "\""; } else { commandstr += track.Track.Number.ToString() + ":\"" + tboutputDir.Text + "\\" + file.Name + "_" + track.Track.Type + "_" + track.Track.Language + "." + SettingsHelper.GetCodecContainerExtension(track.Track.Codec) + "\""; } } } var proc = new Process { StartInfo = new ProcessStartInfo { FileName = SettingsHelper.GetMkvExtractPath(), UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, Arguments = " tracks \"" + file.Path + "\" " + commandstr, StandardOutputEncoding = Encoding.UTF8 } }; proc.Start(); //for progressbar StreamReader sr = proc.StandardOutput; string buffstr; while ((buffstr = sr.ReadLine()) != null) { if (buffstr.Contains("Progress: ")) { if (buffstr.Length == 12) { pbCurrentFile.Value = int.Parse(buffstr.Substring(10, 1)); } if (buffstr.Length == 13) { pbCurrentFile.Value = int.Parse(buffstr.Substring(10, 2)); } } } } } }