private void GeneratePreviewReal()
 {
     var uknownFormatImporter = new UknownFormatImporter();
     uknownFormatImporter.UseFrames = radioButtonTimeCodeFrames.Checked;
     ImportedSubitle = uknownFormatImporter.AutoGuessImport(textBoxText.Lines);
     groupBoxImportResult.Text = string.Format(Configuration.Settings.Language.ImportText.PreviewLinesModifiedX, ImportedSubitle.Paragraphs.Count);
     SubtitleListview1.Fill(ImportedSubitle);
     if (ImportedSubitle.Paragraphs.Count > 0)
         SubtitleListview1.SelectIndexAndEnsureVisible(0);
 }
        public void OpenSubtitle(string fileName, bool requireSaveAs, Encoding useThisEncoding = null)
        {
            if (System.IO.File.Exists(fileName))
            {
                //    bool videoFileLoaded = false;
                var file = new FileInfo(fileName);
                var ext = file.Extension.ToLowerInvariant();

                _subtitle = new Subtitle();
                Encoding encoding = useThisEncoding;
                if (encoding == null)
                {
                    LanguageAutoDetect.GetEncodingFromFile(fileName);
                }
                SubtitleFormat format = _subtitle.LoadSubtitle(fileName, out encoding, encoding);

                // check for idx file
                if (format == null && file.Length > 100 && ext == ".idx")
                {
                    MessageBox.Show(_language.ErrorLoadIdx);
                    return;
                }

                // check for .rar file
                if (format == null && file.Length > 100 && FileUtil.IsRar(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadRar);
                    return;
                }

                // check for .zip file
                if (format == null && file.Length > 100 && FileUtil.IsZip(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadZip);
                    return;
                }

                // check for .png file
                if (format == null && file.Length > 100 && FileUtil.IsPng(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadPng);
                    return;
                }

                // check for .jpg file
                if (format == null && file.Length > 100 && FileUtil.IsJpg(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadJpg);
                    return;
                }

                // check for .srr file
                if (format == null && file.Length > 100 && ext == ".srr" && FileUtil.IsSrr(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadSrr);
                    return;
                }

                // check for Torrent file
                if (format == null && file.Length > 50 && FileUtil.IsTorrentFile(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadTorrent);
                    return;
                }

                // check for all binary zeroes (I've heard about this a few times... perhaps related to crashes?)
                if (format == null && file.Length > 50 && FileUtil.IsSubtitleFileAllBinaryZeroes(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadBinaryZeroes);
                    return;
                }


                if (format == null && file.Length < 500000)
                {

                    // Try to use a generic subtitle format parser (guessing subtitle format)
                    try
                    {
                        var enc = LanguageAutoDetect.GetEncodingFromFile(fileName);
                        var s = System.IO.File.ReadAllText(fileName, enc);

                        var uknownFormatImporter = new UknownFormatImporter { UseFrames = true };
                        var genericParseSubtitle = uknownFormatImporter.AutoGuessImport(s.SplitToLines());
                        if (genericParseSubtitle.Paragraphs.Count > 1)
                        {
                            _subtitle = genericParseSubtitle;
                            //ShowStatus("Guessed subtitle format via generic subtitle parser!");
                        }
                    }
                    catch
                    {
                    }
                }

                if (format != null && format.IsFrameBased)
                    _subtitle.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
                else
                    _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);

                if (format != null)
                {
                    if (Configuration.Settings.General.RemoveBlankLinesWhenOpening)
                    {
                        _subtitle.RemoveEmptyLines();
                    }

                    foreach (var p in _subtitle.Paragraphs)
                    {
                        // Replace U+0456 (CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I) by U+0069 (LATIN SMALL LETTER I)
                        p.Text = p.Text.Replace("<і>", "<i>").Replace("</і>", "</i>");
                    }
                    _subtitleFileName = fileName;
                    SetSubtitleFormat(format);
                    Window.SetEncoding(encoding.BodyName);
                    SetNewSubtitle(_subtitle);
                    Configuration.Settings.RecentFiles.Add(fileName, null, null);
                    UpdateRecentFiles();

                    TryToFindAndOpenVideoFile(_subtitleFileName);
                    ShowAudioVisualizerIfDataIsReady();

                }
                else
                {
                    //
                }
            }
            else
            {
                MessageBox.Show(string.Format(_language.FileNotFound, fileName));
            }
        }