private void Export_Click(object sender, EventArgs e)
        {
            // Get file to save as
            var form = new SaveFileDialog();

            form.AddExtension = true;
            form.Filter       = "SubRip Files (*.srt)|*.srt|All files (*.*)|*.*";

            var result   = form.ShowDialog();
            var fileName = form.FileName;

            form.Dispose();

            if (result != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            // Fetch fps
            var system = _selectedMovie.HeaderEntries[HeaderKeys.PLATFORM];
            var pal    = _selectedMovie.HeaderEntries.ContainsKey(HeaderKeys.PAL) &&
                         _selectedMovie.HeaderEntries[HeaderKeys.PAL] == "1";
            var    pfr = new PlatformFrameRates();
            double fps = 1;

            try
            {
                fps = pfr[system, pal];
            }
            catch
            {
                MessageBox.Show(
                    "Could not determine movie fps, export failed.",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );

                return;
            }

            // Create string and write to file
            var str = _selectedMovie.Subtitles.ToSubRip(fps);

            File.WriteAllText(fileName, str);

            // Display success
            MessageBox.Show(
                string.Format("Subtitles succesfully exported to {0}.", fileName),
                "Success"
                );
        }
Пример #2
0
        private void Export_Click(object sender, EventArgs e)
        {
            // Get file to save as
            using var form = new SaveFileDialog
                  {
                      AddExtension = true,
                      Filter       = new FilesystemFilterSet(new FilesystemFilter("SubRip Files", new[] { "srt" })).ToString()
                  };

            var result   = form.ShowDialog();
            var fileName = form.FileName;

            form.Dispose();

            if (result != DialogResult.OK)
            {
                return;
            }

            // Fetch fps
            var system = _selectedMovie.HeaderEntries[HeaderKeys.Platform];
            var pal    = _selectedMovie.HeaderEntries.ContainsKey(HeaderKeys.Pal) &&
                         _selectedMovie.HeaderEntries[HeaderKeys.Pal] == "1";
            var    pfr = new PlatformFrameRates();
            double fps;

            try
            {
                fps = pfr[system, pal];
            }
            catch
            {
                MessageBox.Show(
                    "Could not determine movie fps, export failed.",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                return;
            }

            // Create string and write to file
            var str = _selectedMovie.Subtitles.ToSubRip(fps);

            File.WriteAllText(fileName, str);

            // Display success
            MessageBox.Show($"Subtitles successfully exported to {fileName}.", "Success");
        }