/// <summary> /// Füllt das Hauptfenster mit Voreinstellungen. /// </summary> /// <param name="sender">Wird ignoriert.</param> /// <param name="e">Wird ignoriert.</param> private void CutMain_Load(object sender, System.EventArgs e) { // Ask for project file if (DialogResult.OK != openCuttermaran.ShowDialog(this)) { // Finish Close(); // Done return; } // Ask for result file if (DialogResult.OK != saveCut.ShowDialog(this)) { // Finish Close(); // Done return; } // Create the project reader m_ProjectFile = new CPFReader(openCuttermaran.FileName); // All frame rates for (int i = 0; i < 9; i++) { // Load FrameRateInfo info = FrameRateInfo.FindFrameRate(i); // Report to list selRate.Items.Add(info); // Select if (info.Rate == Properties.Settings.Default.Framerate) { selRate.SelectedIndex = i; } } // Load other defaults udMinimum.Value = Properties.Settings.Default.Threshold; // Prepare UI ckDVB.Enabled = false; // Load pages foreach (int?page in m_ProjectFile.GetAvailableSubtitles(Path.GetExtension(saveCut.FileName).Substring(1))) { if (page.HasValue) { // Add to list selPage.Items.Add(page.Value); // Select it if (page.Value == Properties.Settings.Default.SubtitlePage) { selPage.SelectedItem = page.Value; } } else { ckDVB.Enabled = true; } } // Finish selection if (selPage.Items.Count > 0) { if (selPage.SelectedItem == null) { selPage.SelectedIndex = 0; } } // Disable selection selPage.Enabled = (selPage.Items.Count > 1); // Disable command cmdRun.Enabled = (selPage.Items.Count > 0) || ckDVB.Enabled; // Special if (cmdRun.Enabled) { if (selPage.Items.Count < 1) { // Force DVB subtitles ckDVB.Checked = true; ckDVB.Enabled = false; } } }
/// <summary> /// Der Anwender wünscht den Schnitt auszuführen. /// </summary> /// <param name="sender">Wird ignoriert.</param> /// <param name="e">Wird ignoriert.</param> private void cmdRun_Click(object sender, System.EventArgs e) { // Update settings Properties.Settings.Default.Framerate = FrameRateInfo.FindFrameRate(selRate.SelectedIndex).Rate; Properties.Settings.Default.Threshold = udMinimum.Value; Properties.Settings.Default.Save(); // Check selection of page if (selPage.SelectedItem != null) { Properties.Settings.Default.SubtitlePage = (int)selPage.SelectedItem; } // With error handling try { // Load file FileInfo outFile = new FileInfo(saveCut.FileName); // Get the type string suffix = outFile.Extension; // Check if ((null == suffix) || (suffix.Length < 2)) { throw new ApplicationException(Properties.Resources.Error_Format); } // Cut off suffix = suffix.Substring(1); // Load type name string typeName = ConfigurationManager.AppSettings[suffix.ToUpper()]; // Check if ((null == typeName) || (typeName.Length < 1)) { throw new ApplicationException(Properties.Resources.Error_Format); } // Find the type Type cutType = Type.GetType(typeName, true); // Create extractor using (ICutter cutter = (ICutter)Activator.CreateInstance(cutType)) { // Configure cutter.Framerate = FrameRateInfo.FindFrameRate(selRate.SelectedIndex).Rate; cutter.MinDuration = (double)udMinimum.Value; // Check for VCR.NET 3.1 or later ICutter2 cutter31 = cutter as ICutter2; if (null != cutter31) { cutter31.TimeCorrection = (double)udCorrect.Value; } // Position in output file long pos = 0; // Process all cuts foreach (CutElement cut in m_ProjectFile.CutElements) { // Get the core name string coreName = Path.GetFileNameWithoutExtension(cut.VideoFile.FullName); // Append page number if (!ckDVB.Checked) { coreName += "[" + Properties.Settings.Default.SubtitlePage.ToString() + "]"; } // Replace suffix FileInfo ttxFile = new FileInfo(cut.VideoFile.DirectoryName + @"\" + coreName + "." + suffix); // Must exist if (!ttxFile.Exists) { continue; } // Validate if (cut.Start > cut.End) { continue; } // Process cutter.Cut(ttxFile.FullName, cut.Start, cut.End, pos); // Adjust frame counter pos += cut.End - cut.Start + 1; } // Finish cutter.Save(saveCut.FileName); } // Done on success Close(); } catch (Exception ex) { // Report MessageBox.Show(this, ex.Message, Properties.Resources.Error_Failed); } }