private WPFTranscription ImportTranscription(string filepath = null) { string[] masks = _ImportPlugins.Select(p => p.Mask).ToArray(); string[] filetypes = masks.SelectMany(m => m.Split('|').Where((p, i) => i % 2 == 1).SelectMany(ex => ex.Split(';'))).Distinct().ToArray(); string allfilesMask = string.Format(Properties.Strings.FileDialogLoadImportFilter, string.Join(";", filetypes)); OpenFileDialog opf = new OpenFileDialog(); opf.CheckFileExists = true; opf.CheckPathExists = true; opf.Filter = string.Join("|", new[] { allfilesMask }.Concat(masks)); opf.Title = Properties.Strings.FileDialogLoadImportTitle; bool filedialogopened = false; if (filepath != null) { opf.FilterIndex = 1; filedialogopened = true; opf.FileName = filepath; } else { filedialogopened = opf.ShowDialog() == true; } WPFTranscription trans = null; if (filedialogopened) { if (opf.FilterIndex == 1) //all files { var plugins = _ImportPlugins.Where( p => p.Mask.Split('|') .Where((s, i) => i % 2 == 1) .Any(s => Regex.IsMatch(System.IO.Path.GetExtension(opf.FileName), string.Join("|", s.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(r => r.Replace("*", "").Replace(".", "\\.").Replace('?', '.') + "$"))))).ToArray(); if (plugins.Length != 1) { PickOneDialog pd = new PickOneDialog(plugins.Select(p => p.Name).ToList(), Properties.Strings.ImportSelectImportPlugin); if (pd.ShowDialog() == true) { trans = plugins[pd.SelectedIndex].ExecuteImport(opf.FileName); } } else { trans = plugins[0].ExecuteImport(opf.FileName); } } else { trans = _ImportPlugins[opf.FilterIndex - 2].ExecuteImport(opf.FileName); } if (trans != null) { trans.FileName += ".trsx"; } } return(trans); }
private void CImportFile(object sender, ExecutedRoutedEventArgs e) { if (!Settings.Default.FeatureEnabler.LocalEdit) return; string[] masks = _ImportPlugins.Select(p => p.Mask).ToArray(); string[] filetypes = masks.SelectMany(m => m.Split('|').Where((p, i) => i % 2 == 1).SelectMany(ex => ex.Split(';'))).Distinct().ToArray(); string allfilesMask = string.Format(Properties.Strings.FileDialogLoadImportFilter, string.Join(";", filetypes)); OpenFileDialog opf = new OpenFileDialog(); opf.CheckFileExists = true; opf.CheckPathExists = true; opf.Filter = string.Join("|", new[] { allfilesMask }.Concat(masks)); opf.Title = Properties.Strings.FileDialogLoadImportTitle; bool filedialogopened = false; if (e.Parameter is string) { filedialogopened = true; opf.FilterIndex = 1; opf.FileName = (string)e.Parameter; } else filedialogopened = opf.ShowDialog() == true; if (filedialogopened) { if (opf.FilterIndex == 1) //vsechny soubory { var plugins = _ImportPlugins.Where( p => p.Mask.Split('|') .Where((s, i) => i % 2 == 1) .Any(s => Regex.IsMatch(System.IO.Path.GetExtension(opf.FileName), string.Join("|", s.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(r => r.Replace("*", "").Replace(".", "\\.").Replace('?', '.') + "$"))))).ToArray(); if (plugins.Length != 1) { PickOneDialog pd = new PickOneDialog(plugins.Select(p => p.Name).ToList(), Properties.Strings.ImportSelectImportPlugin); if (pd.ShowDialog() == true) { LoadSubtitlesData(plugins[pd.SelectedIndex].ExecuteImport(opf.FileName)); } } else { LoadSubtitlesData(plugins[0].ExecuteImport(opf.FileName)); } } else { LoadSubtitlesData(_ImportPlugins[opf.FilterIndex - 2].ExecuteImport(opf.FileName)); } if (Transcription != null) { Transcription.FileName += ".trsx"; } } }
private WPFTranscription ImportTranscription(string filepath = null) { string[] masks = _ImportPlugins.Select(p => p.Mask).ToArray(); string[] filetypes = masks.SelectMany(m => m.Split('|').Where((p, i) => i % 2 == 1).SelectMany(ex => ex.Split(';'))).Distinct().ToArray(); string allfilesMask = string.Format(Properties.Strings.FileDialogLoadImportFilter, string.Join(";", filetypes)); OpenFileDialog opf = new OpenFileDialog(); opf.CheckFileExists = true; opf.CheckPathExists = true; opf.Filter = string.Join("|", new[] { allfilesMask }.Concat(masks)); opf.Title = Properties.Strings.FileDialogLoadImportTitle; bool filedialogopened = false; if (filepath != null) { opf.FilterIndex = 1; filedialogopened = true; opf.FileName = filepath; } else filedialogopened = opf.ShowDialog() == true; WPFTranscription trans = null; if (filedialogopened) { if (opf.FilterIndex == 1) //all files { var plugins = _ImportPlugins.Where( p => p.Mask.Split('|') .Where((s, i) => i % 2 == 1) .Any(s => Regex.IsMatch(System.IO.Path.GetExtension(opf.FileName), string.Join("|", s.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(r => r.Replace("*", "").Replace(".", "\\.").Replace('?', '.') + "$"))))).ToArray(); if (plugins.Length != 1) { PickOneDialog pd = new PickOneDialog(plugins.Select(p => p.Name).ToList(), Properties.Strings.ImportSelectImportPlugin); if (pd.ShowDialog() == true) { trans = plugins[pd.SelectedIndex].ExecuteImport(opf.FileName); } } else { trans = plugins[0].ExecuteImport(opf.FileName); } } else { trans = _ImportPlugins[opf.FilterIndex - 2].ExecuteImport(opf.FileName); } if (trans != null) { trans.FileName += ".trsx"; } } return trans; }