private async void MenuFlyoutItem_Click(object sender, RoutedEventArgs e) { string path = ((MenuFlyoutItem)sender).Tag.ToString(); Debug.WriteLine(((MenuFlyoutItem)sender).Tag); StorageFile file = await StorageFile.GetFileFromPathAsync(path); if (file != null) { string hex; double length; Stream stream = await file.OpenStreamForReadAsync(); byte[] result = ComputeMovieHash(stream); hex = ToHexadecimal(result); var properties = await file.GetBasicPropertiesAsync(); length = properties.Size; await Task.Run(() => this.messenger.OSLogIn()); SearchSubtitlesResponse ssre = null; await Task.Run(() => this.messenger.SearchOS(hex, length, "all", ref ssre)); //List<string> subtitles = new List<string>(); List <SubInfo> subtitles = new List <SubInfo>(); List <string> subInfo = new List <string>(); foreach (SubInfo info in ssre.data) { subtitles.Add(info); } SubtitleComparator c = new SubtitleComparator(); subtitles.Sort(c); SubtitleList.Items.Clear(); foreach (var x in subtitles) { SubtitleList.Items.Add(x); } SubtitleDialog.IsPrimaryButtonEnabled = false; ContentDialogResult DialogResult = await SubtitleDialog.ShowAsync(); if (DialogResult == ContentDialogResult.Primary) { SubInfo selectedSubtitle = (SubInfo)SubtitleList.SelectedItem; byte[] subtitleStream = null; if (selectedSubtitle != null) { await Task.Run(() => this.messenger.DownloadSubtitle(int.Parse(selectedSubtitle.IDSubtitleFile), ref subtitleStream)); StorageFolder sf = await file.GetParentAsync(); string subtitlename = file.Name.Substring(0, file.Name.LastIndexOf('.')); StorageFile sfile = await sf.CreateFileAsync(subtitlename + ".srt", CreationCollisionOption.ReplaceExisting); await FileIO.WriteBytesAsync(sfile, subtitleStream); } else { Debug.WriteLine("Subtitle not found"); } } } }
private Window PrepareWindow(ViewModelBase viewModel, ViewModelBase owner) { Window windowToOpen = null; if (viewModel is MainViewModel) { windowToOpen = new MainWindow(); } else if (viewModel is EncodingViewModel) { windowToOpen = new EncodingWindow(); } else if (viewModel is SubtitleDialogViewModel) { windowToOpen = new SubtitleDialog(); } else if (viewModel is ChoosePresetNameViewModel) { windowToOpen = new ChoosePresetName(); } else if (viewModel is OptionsDialogViewModel) { windowToOpen = new OptionsDialog(); } else if (viewModel is ChapterMarkersDialogViewModel) { windowToOpen = new ChapterMarkersDialog(); } else if (viewModel is PreviewViewModel) { windowToOpen = new PreviewWindow(); } else if (viewModel is AboutDialogViewModel) { windowToOpen = new AboutDialog(); } else if (viewModel is LogViewModel) { windowToOpen = new LogWindow(); } else if (viewModel is QueueColumnsViewModel) { windowToOpen = new QueueColumnsDialog(); } else if (viewModel is ScanMultipleDialogViewModel) { windowToOpen = new ScanMultipleDialog(); } else if (viewModel is QueueTitlesDialogViewModel) { windowToOpen = new QueueTitlesDialog(); } else if (viewModel is AddAutoPauseProcessDialogViewModel) { windowToOpen = new AddAutoPauseProcessDialog(); } else if (viewModel is FileConflictDialogViewModel) { windowToOpen = new FileConflictDialog(); } else if (viewModel is EncodeDetailsViewModel) { windowToOpen = new EncodeDetailsWindow(); } else if (viewModel is ShutdownWarningViewModel) { windowToOpen = new ShutdownWarningWindow(); } if (owner != null) { windowToOpen.Owner = openWindows[owner]; } windowToOpen.DataContext = viewModel; windowToOpen.Closing += this.OnClosing; this.openWindows.Add(viewModel, windowToOpen); return(windowToOpen); }