public void OnDropDownSelectionChanged(SelectablePackage spc, bool value) { for (int i = 0; i < Items.Count; i++) { ComboBoxItem cbi = (ComboBoxItem)Items[i]; if (cbi.Package.Equals(spc) && value && cbi.Package.Enabled) { if (handler != null) { SelectionChanged -= handler; } SelectedItem = cbi; if (handler != null) { SelectionChanged += handler; } continue; }//if value is false it will uncheck all the packages if (cbi.Package.Enabled && cbi.Package.Checked) { cbi.Package.Checked = false; } } if (!value) { SelectionChanged -= handler; SelectedIndex = 0; SelectionChanged += handler; } }
/// <summary> /// Called from the database object to update the UI on a combobox selection change /// </summary> /// <param name="spc">The SelectablePakage that caused the update</param> /// <param name="value">The checked value</param> public void OnDropDownSelectionChanged(SelectablePackage spc, bool value) { for (int i = 0; i < Items.Count; i++) { ComboBoxItem cbi = (ComboBoxItem)Items[i]; if (cbi.Package.Equals(spc) && value && cbi.Package.Enabled) { //unsubscribe before changing the selected item if (Handler != null) { SelectionChanged -= Handler; } //change it SelectedItem = cbi; //re-subscribe if (Handler != null) { SelectionChanged += Handler; } //continue as to not uncheck this value, now that it's checked continue; } //if value is false it will uncheck all the packages if (cbi.Package.Enabled && cbi.Package.Checked) { cbi.Package.Checked = false; } } if (!value) { SelectionChanged -= Handler; SelectedIndex = 0; SelectionChanged += Handler; } }
/// <summary> /// Called from the database object to update the UI on a combobox selection change /// </summary> /// <param name="spc">The SelectablePakage that caused the update</param> /// <param name="value">The checked value</param> public void OnDropDownSelectionChanged(SelectablePackage spc, bool value) { for (int i = 0; i < Items.Count; i++) { RelhaxComboBoxItem cbi = (RelhaxComboBoxItem)Items[i]; if (cbi.Package.Equals(spc) && value && cbi.Package.Enabled) { //change it this.SelectedIndex = i; //continue as to not uncheck this value, now that it's checked continue; } //if value is false it will uncheck all the packages if (cbi.Package.Enabled && cbi.Package.Checked) { cbi.Package.Checked = false; } } if (!value) { //reset to first selection option this.SelectedIndex = 0; } }
private void ApplyIcons() { RelhaxComboBoxItem relhaxComboBoxItem = (RelhaxComboBoxItem)this.SelectedItem; SelectablePackage package = relhaxComboBoxItem.Package; while (thePanel.Children.Count > 1) { thePanel.Children.RemoveAt(thePanel.Children.Count - 1); } if (package.ObfuscatedMod) { Image img = new Image() { VerticalAlignment = VerticalAlignment.Top, Width = 16, Height = 16, Source = new BitmapImage(new Uri(@"/RelhaxModpack;component/Resources/Images/obfuscated_package_icon.png", UriKind.Relative)) }; thePanel.Children.Add(img); } if (package.GreyAreaMod) { Image img = new Image() { VerticalAlignment = VerticalAlignment.Top, Width = 16, Height = 16, Source = new BitmapImage(new Uri(@"/RelhaxModpack;component/Resources/Images/grey_area_mod.png", UriKind.Relative)) }; thePanel.Children.Add(img); } if (package.PopularMod) { Image img = new Image() { VerticalAlignment = VerticalAlignment.Top, Width = 16, Height = 16, Source = new BitmapImage(new Uri(@"/RelhaxModpack;component/Resources/Images/popular_icon.png", UriKind.Relative)) }; thePanel.Children.Add(img); } if (package.FromWGmods) { Image img = new Image() { VerticalAlignment = VerticalAlignment.Top, Width = 16, Height = 16, Source = new BitmapImage(new Uri(@"/RelhaxModpack;component/Resources/Images/wgmods_package.png", UriKind.Relative)) }; } }
/// <summary> /// Refresh the window to display new preview elements /// </summary> public void Refresh(bool init) { //check that all components have the package parent reference set foreach (Media media in Medias) { bool anyMediaErrors = false; if (media.SelectablePackageParent == null) { Logging.Error("A media component does not have its SelectablePackageParent set"); Logging.Error(media.ToString()); anyMediaErrors = true; } if (anyMediaErrors) { MessageBox.Show(Translations.GetTranslatedString("previewEncounteredError")); Close(); return; } } CurrentDisplaySP = InvokedPackage; if (Medias.Count > 0) { DisplayMedia(Medias[0], true); } else { DisplayMedia(null, true); } //start the focus timer to bring focus to this window if (init && ModpackSettings.ModSelectionView == SelectionView.Legacy) { OMCViewLegacyFocusTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(10), DispatcherPriority.Normal, Timer_Tick, this.Dispatcher) { IsEnabled = true }; } else if (OMCViewLegacyFocusTimer == null) { OMCViewLegacyFocusTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(10), DispatcherPriority.Normal, Timer_Tick, this.Dispatcher) { IsEnabled = true }; } else { OMCViewLegacyFocusTimer.Start(); } }
public void Test04_CreateRandomSelectionListTest() { SelectionList.OnSelectionListReturn += SelectionList_OnSelectionListReturn; log.Write("Selecting 100 components"); SelectionList.Dispatcher.Invoke(() => { List <SelectablePackage> flatList = DatabaseUtils.GetFlatSelectablePackageList(SelectionList.ParsedCategoryList); Random random = new Random(); for (int i = 0; i < 100; i++) { int selectIndex = random.Next(0, flatList.Count); SelectablePackage package = flatList[selectIndex]; log.Write(string.Format("Index {0} selects package {1}", selectIndex, package.PackageName)); package.Checked = true; } //click the continue button List <FrameworkElement> elements = UiUtils.GetAllWindowComponentsLogical(SelectionList, false); FrameworkElement buttonElement = elements.Find(element => element.Tag != null && element.Tag.Equals("ContinueButton")); Button clearSelectionsButton = buttonElement as Button; clearSelectionsButton.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); }); }
private void OnPreviewWindowLoad(object sender, RoutedEventArgs e) { //make sure Medias is a valid entry if (Medias == null || InvokedPackage == null) { Logging.Error("Preview Medias list or InvokedPackage null: MediasNull?={0}, InvokedPacakgeNull?={1}", Medias == null, InvokedPackage == null); MessageBox.Show(Translations.GetTranslatedString("previewEncounteredError")); Close(); return; } //check that all components have the package parent reference set foreach (Media media in Medias) { bool anyMediaErrors = false; if (media.SelectablePackageParent == null) { Logging.Error("A media component does not have its SelectablePackageParent set"); Logging.Error(media.ToString()); anyMediaErrors = true; } if (anyMediaErrors) { MessageBox.Show(Translations.GetTranslatedString("previewEncounteredError")); Close(); return; } } //translate 3 components DevUrlHeader.Text = Translations.GetTranslatedString(DevUrlHeader.Name); PreviewNextPicButton.Content = Translations.GetTranslatedString(PreviewNextPicButton.Name); PreviewPreviousPicButton.Content = Translations.GetTranslatedString(PreviewPreviousPicButton.Name); //make the linked labels in the link box for (int i = 0; i < Medias.Count; i++) { TextBlock block = new TextBlock(); block.Inlines.Clear(); Hyperlink h = new Hyperlink(new Run(i.ToString())) { Tag = Medias[i], //dummy URI just to make the request navigate work NavigateUri = new Uri("http://google.com") }; h.RequestNavigate += OnMediaHyperlinkClick; block.Inlines.Add(h); MediaIndexer.Children.Add(block); } if (EditorMode) { Logging.Debug("EditorMode = true, ignoring setting for startup location"); WindowStartupLocation = WindowStartupLocation.Manual; } else { //if the saved preview window point is within the screen, then load it to there if (Utils.PointWithinScreen(ModpackSettings.PreviewX, ModpackSettings.PreviewY)) { //set for manual window location setting WindowStartupLocation = WindowStartupLocation.Manual; //set starting location //https://stackoverflow.com/questions/2734810/how-to-set-the-location-of-a-wpf-window Left = ModpackSettings.PreviewX; Top = ModpackSettings.PreviewY; } else { Logging.Info("[{0}]: Position {1}x{2} is outside screen dimensions, use center of window owner", Logfiles.Application, nameof(Preview), ModpackSettings.PreviewX, ModpackSettings.PreviewY); WindowStartupLocation = WindowStartupLocation.CenterOwner; } //set width and height Width = ModpackSettings.PreviewWidth; Height = ModpackSettings.PreviewHeight; //set if full screen if (ModpackSettings.PreviewFullscreen) { WindowState = WindowState.Maximized; } } //invoke displaying the first element if (Medias.Count > 0) { DisplayMedia(Medias[0]); } else { if (ComboBoxItemsInsideMode) { Title = string.Format("{0}: ({1})", Translations.GetTranslatedString("dropDownItemsInside"), Translations.GetTranslatedString("none")); } else { Title = InvokedPackage.NameFormatted; } PreviewDescriptionBox.Text = InvokedPackage.DescriptionFormatted; PreviewUpdatesBox.Text = InvokedPackage.UpdateCommentFormatted; CurrentDisplaySP = InvokedPackage; } //set the timer if the view is OMC if (ModpackSettings.ModSelectionView == SelectionView.Legacy) { OMCViewLegacyFocusTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(10), DispatcherPriority.Normal, Timer_Tick, this.Dispatcher) { IsEnabled = true }; } }
private async void DisplayMedia(Media media) { //the devURL, description and update notes only need to be //re-parsed if the package has changed if (CurrentDispalyMedia == null || (!CurrentDispalyMedia.Equals(media))) { //check if devurl, desciption, update notes need to be changed if selectablePackage changed as well if (CurrentDisplaySP == null || (!CurrentDisplaySP.Equals(media.SelectablePackageParent))) { //check if devURL element should be enabled or not if (string.IsNullOrWhiteSpace(media.SelectablePackageParent.DevURL)) { DevUrlHeader.IsEnabled = false; DevUrlHeader.Visibility = Visibility.Hidden; DevUrlHolder.IsEnabled = false; DevUrlHolder.Visibility = Visibility.Hidden; } else { //devURL is now array of elements separated by newline //load the stack with textblocks with tooltips for the URLs string[] devURLS = media.SelectablePackageParent.DevURLList; //clear last list of URL links DevUrlHolder.Children.Clear(); for (int i = 0; i < devURLS.Count(); i++) { //make a URI to hold the goto devurl link Uri goTo = null; try { goTo = new Uri(devURLS[i].Trim()); } catch (UriFormatException) { Logging.Error("Invalid URI string, skipping: {0}", devURLS[i].Trim()); } if (goTo == null) { continue; } //make a textbox to hold the hyperlink object TextBlock block = new TextBlock() { ToolTip = devURLS[i].Trim() }; //https://stackoverflow.com/questions/21214450/how-to-add-a-hyperlink-in-a-textblock-in-code?noredirect=1&lq=1 block.Inlines.Clear(); //make a run to display the number of the link Run inline = new Run(i.ToString()); //and the hyperlink will display the run Hyperlink h = new Hyperlink(inline) { NavigateUri = goTo }; h.RequestNavigate += OnHyperLinkClick; //add hyperlink to textbox block.Inlines.Add(h); //add to developer url textbox DevUrlHolder.Children.Add(block); } } //set the name of the window to be the package name if (EditorMode) { Title = "EDITOR_TEST_MODE"; } else if (ComboBoxItemsInsideMode) { Title = string.Format("{0}: {1}", Translations.GetTranslatedString("dropDownItemsInside"), media.SelectablePackageParent.NameFormatted); } else { Title = media.SelectablePackageParent.NameFormatted; } //set description PreviewDescriptionBox.Text = media.SelectablePackageParent.DescriptionFormatted; //set update notes PreviewUpdatesBox.Text = media.SelectablePackageParent.UpdateCommentFormatted; //update the last currentDisplayedSP CurrentDisplaySP = media.SelectablePackageParent; } } CurrentDispalyMedia = media; //if the child is our media player, then stop and dispose if (MainPreviewBorder.Child != null && MainPreviewBorder.Child is RelhaxMediaPlayer player) { player.StopPlaybackIfPlaying(); player.Dispose(); } //null the child element and make it again MainPreviewBorder.Child = null; Logging.Debug("loading preview of MediaType {0}, URL={1}", media.MediaType.ToString(), media.URL); Image pictureViewer; switch (media.MediaType) { case MediaType.Unknown: default: Logging.Error("Invalid MediaType: {0}", media.MediaType.ToString()); return; case MediaType.HTML: if (browser != null) { browser.Dispose(); browser = null; } browser = new WebBrowser(); //https://stackoverflow.com/questions/2585782/displaying-html-from-string-in-wpf-webbrowser-control browser.NavigateToString(media.URL); MainPreviewBorder.Child = browser; break; case MediaType.MediaFile: //show progress first MainPreviewBorder.Child = new ProgressBar() { Minimum = 0, Maximum = 1, Value = 0, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(0, 20, 0, 0), Height = 20 }; using (WebClient client = new WebClient() { }) { client.DownloadProgressChanged += Client_DownloadProgressChanged; //now load the media try { byte[] data = await client.DownloadDataTaskAsync(media.URL); MainPreviewBorder.Child = new RelhaxMediaPlayer(media.URL, data); } catch (Exception ex) { Logging.Exception("failed to load audio data"); Logging.Exception(ex.ToString()); pictureViewer = new Image { ClipToBounds = true }; pictureViewer.Source = Utils.BitmapToImageSource(Properties.Resources.error_loading_picture); MainPreviewBorder.Child = pictureViewer; } } break; case MediaType.Picture: //https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.image?view=netframework-4.7.2 pictureViewer = new Image { ClipToBounds = true }; MainContentControl.MouseRightButtonDown += MainContentControl_MouseRightButtonDown; MainContentControl.PreviewMouseDoubleClick += MainContentControl_PreviewMouseDoubleClick; MainPreviewBorder.Child = new ProgressBar() { Minimum = 0, Maximum = 1, Value = 0, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(0, 20, 0, 0), Height = 20 }; //https://stackoverflow.com/questions/9173904/byte-array-to-image-conversion //https://stackoverflow.com/questions/18134234/how-to-convert-system-io-stream-into-an-image using (WebClient client = new WebClient() { }) { client.DownloadProgressChanged += Client_DownloadProgressChanged; try { byte[] image = await client.DownloadDataTaskAsync(media.URL); ImageStream = new MemoryStream(image); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = ImageStream; bitmapImage.EndInit(); pictureViewer.Source = bitmapImage; } catch (Exception ex) { Logging.Exception("failed to load picture"); Logging.Exception(ex.ToString()); pictureViewer.Source = Utils.BitmapToImageSource(Properties.Resources.error_loading_picture); } } //put the zoom border inside the main preview one. already set, might as well use it zoomBorder = new ZoomBorder() { Child = pictureViewer, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, BorderThickness = new Thickness(1.0), BorderBrush = Brushes.Black, ClipToBounds = true }; zoomBorder.SizeChanged += ZoomBorder_SizeChanged; MainPreviewBorder.ClipToBounds = true; MainPreviewBorder.BorderThickness = new Thickness(0.0); MainPreviewBorder.Child = zoomBorder; break; case MediaType.Webpage: if (browser != null) { browser.Dispose(); browser = null; } browser = new WebBrowser(); //https://stackoverflow.com/questions/2585782/displaying-html-from-string-in-wpf-webbrowser-control browser.Navigate(media.URL); MainPreviewBorder.Child = browser; break; } }
private bool ResetApplicationMacros(AutomationSequence sequence) { Logging.Debug(Logfiles.AutomationRunner, LogOptions.ClassName, "Resetting application macros"); //check that required automation settings are set for being able to reset macaros if (string.IsNullOrEmpty(AutomationRunnerSettings.WoTClientInstallLocation)) { Logging.Error("WoTClientInstallLocation is not set in settings tab!"); return(false); } if (!File.Exists(AutomationRunnerSettings.WoTClientInstallLocation)) { Logging.Error("WoTClientInstallLocation file does not exist!"); return(false); } DatabasePackage package = sequence.Package; SelectablePackage selectablePackage = package as SelectablePackage; ApplicationMacros.Clear(); ApplicationMacros.Add(new AutomationMacro() { Name = "date", Value = DateTime.UtcNow.ToString("yyyy-MM-dd"), MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "category.name", Value = (selectablePackage != null) ? selectablePackage.ParentCategory.Name : "null", MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "name", Value = (selectablePackage != null) ? selectablePackage.NameFormatted : "null", MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "packageName", Value = package.PackageName, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "packageUID", Value = package.UID, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "zipfile", Value = package.ZipFile, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "level", Value = (selectablePackage != null) ? selectablePackage.Level.ToString() : "null", MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "patchGroup", Value = package.PatchGroup.ToString(), MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "installGroup", Value = package.InstallGroupWithOffset.ToString(), MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "clientVersion", Value = WoTClientVersion, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "onlineFolderVersion", Value = WoTModpackOnlineFolderVersion, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "author", Value = package.Author, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "version", Value = package.Version, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "applicationPath", Value = ApplicationConstants.ApplicationStartupPath, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "relhaxTemp", Value = ApplicationConstants.RelhaxTempFolderPath, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "workDirectory", Value = string.Format("{0}\\{1}", ApplicationConstants.RelhaxTempFolderPath, package.PackageName), MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "automationRepoRoot", Value = AutomationRepoPathEscaped, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "clientPath", Value = Path.GetDirectoryName(AutomationRunnerSettings.WoTClientInstallLocation) }); return(true); }
private async void DisplayMedia(Media media, bool fullRedraw) { //don't need to update if it's the same as what is currently displayed if (media != null && CurrentDispalyMedia != null && CurrentDispalyMedia.Equals(media)) { Logging.Debug(LogOptions.ClassName, "No need to display media, is the same"); return; } CurrentDispalyMedia = media; //devurl, description, update notes need to be changed if the parent package being displayed changed //this would happen only if we are in combobox mode (displaying medias of multiple packages) if (ComboBoxItemsInsideMode && media != null && (!CurrentDisplaySP.Equals(media.SelectablePackageParent))) { fullRedraw = true; CurrentDisplaySP = media.SelectablePackageParent; } if (fullRedraw) { ToggleDevUrlList(media, media == null? false : string.IsNullOrWhiteSpace(media.SelectablePackageParent.DevURL)); //set the name of the window to be the package name if (EditorMode) { Title = "EDITOR_TEST_MODE"; } else if (ComboBoxItemsInsideMode) { Title = string.Format("{0}: {1}", Translations.GetTranslatedString("dropDownItemsInside"), CurrentDisplaySP.NameFormatted); } else { Title = CurrentDisplaySP.NameFormatted; } //set description PreviewDescriptionBox.Text = CurrentDisplaySP.DescriptionFormatted; //set update notes PreviewUpdatesBox.Text = CurrentDisplaySP.UpdateCommentFormatted; } //clear media url list and re-build it if (MediaIndexer.Children.Count > 0) { MediaIndexer.Children.Clear(); } //make the linked labels in the link box for (int i = 0; i < Medias.Count; i++) { TextBlock block = new TextBlock(); block.Inlines.Clear(); Hyperlink h = new Hyperlink(new Run(i.ToString())) { Tag = Medias[i], //dummy URI just to make the request navigate work NavigateUri = new Uri("https://google.com") }; h.RequestNavigate += OnMediaHyperlinkClick; block.Inlines.Add(h); MediaIndexer.Children.Add(block); } HandlePlayerDisposal(); //null the child element and make it again MainPreviewBorder.Child = null; if (media != null) { Logging.Debug(LogOptions.ClassName, "Loading preview of MediaType {0}, URL={1}", media.MediaType.ToString(), media.URL); Image pictureViewer; switch (media.MediaType) { case MediaType.Unknown: default: Logging.Error("Invalid MediaType: {0}", media.MediaType.ToString()); return; case MediaType.HTML: if (browser != null) { browser.Dispose(); browser = null; } browser = new WebBrowser(); //https://stackoverflow.com/questions/2585782/displaying-html-from-string-in-wpf-webbrowser-control browser.NavigateToString(media.URL); MainPreviewBorder.Child = browser; break; case MediaType.MediaFile: //show progress first MainPreviewBorder.Child = new ProgressBar() { Minimum = 0, Maximum = 1, Value = 0, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(0, 20, 0, 0), Height = 20 }; using (WebClient client = new WebClient() { }) { client.DownloadProgressChanged += Client_DownloadProgressChanged; //now load the media try { byte[] data = await client.DownloadDataTaskAsync(media.URL); MainPreviewBorder.Child = new RelhaxMediaPlayer(media.URL, data); } catch (Exception ex) { Logging.Exception("failed to load audio data"); Logging.Exception(ex.ToString()); pictureViewer = new Image { ClipToBounds = true }; pictureViewer.Source = CommonUtils.BitmapToImageSource(Properties.Resources.error_loading_picture); MainPreviewBorder.Child = pictureViewer; } } break; case MediaType.Picture: //https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.image?view=netframework-4.7.2 pictureViewer = new Image { ClipToBounds = true }; MainContentControl.MouseRightButtonDown += MainContentControl_MouseRightButtonDown; MainContentControl.PreviewMouseDoubleClick += MainContentControl_PreviewMouseDoubleClick; MainPreviewBorder.Child = new ProgressBar() { Minimum = 0, Maximum = 1, Value = 0, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(0, 20, 0, 0), Height = 20 }; //https://stackoverflow.com/questions/9173904/byte-array-to-image-conversion //https://stackoverflow.com/questions/18134234/how-to-convert-system-io-stream-into-an-image using (WebClient client = new WebClient() { }) { client.DownloadProgressChanged += Client_DownloadProgressChanged; try { byte[] image = await client.DownloadDataTaskAsync(media.URL); ImageStream = new MemoryStream(image); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = ImageStream; bitmapImage.EndInit(); pictureViewer.Source = bitmapImage; } catch (Exception ex) { Logging.Exception("failed to load picture"); Logging.Exception(ex.ToString()); pictureViewer.Source = CommonUtils.BitmapToImageSource(Properties.Resources.error_loading_picture); } } //put the zoom border inside the main preview one. already set, might as well use it zoomBorder = new ZoomBorder() { Child = pictureViewer, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, BorderThickness = new Thickness(1.0), BorderBrush = Brushes.Black, ClipToBounds = true }; zoomBorder.SizeChanged += ZoomBorder_SizeChanged; MainPreviewBorder.ClipToBounds = true; MainPreviewBorder.BorderThickness = new Thickness(0.0); MainPreviewBorder.Child = zoomBorder; break; case MediaType.Webpage: if (browser != null) { browser.Dispose(); browser = null; } browser = new WebBrowser(); //https://stackoverflow.com/questions/2585782/displaying-html-from-string-in-wpf-webbrowser-control browser.Navigate(media.URL); MainPreviewBorder.Child = browser; break; } } }
/// <summary> /// Creates an instance of the ComboBoxItem class /// </summary> /// <param name="package">The package to wrap around</param> /// <param name="display">The text to display in the Combobox</param> public ComboBoxItem(SelectablePackage package, string display) { Package = package; DisplayName = display; }
/// <summary> /// Creates an instance of the RelhaxComboBoxItem class /// </summary> /// <param name="package">The package to wrap around</param> /// <param name="display">The text to display in the Combobox</param> public RelhaxComboBoxItem(SelectablePackage package, string display) { InitializeComponent(); Package = package; DisplayName = display; }
public ComboBoxItem(SelectablePackage cfg, string display) { Package = cfg; DisplayName = display; }
public async Task Test01_LoadModSelectionListTest() { PackageSelectionList selectionList = null; Logging.Info("Creating a ModSelectionList Window"); //create the window and run it on its own thread and dispatcher //this can avoid problems with the unit test dispatcher not running the window the way it should //it's still an STA thread so WPF can use it as a UI thread //https://www.c-sharpcorner.com/uploadfile/suchit_84/creating-wpf-windows-on-dedicated-threads/ Thread thread = new Thread(() => { selectionList = new PackageSelectionList(modpackSettings, commandLineSettings, databaseManager) { ApplyColorSettings = false, //not cross-thread safe ApplyScaling = false, ApplyToolTips = true, AutoInstallMode = false, LocalizeWindow = true, OriginalHeight = 720.0, OriginalWidth = 1280.0, //WotClientVersionFromMainWindow is for UI display only WotClientVersionFromMainWindow = "TESTING", //WoTDirectoryFromMainWindow is for UI display only WoTDirectoryFromMainWindow = "TESTING", //DatabaseVersionFromMainWindow is for UI display and when saving a selection DatabaseVersionFromMainWindow = "TESTING" }; selectionList.Closed += (sender, e) => selectionList.Dispatcher.BeginInvokeShutdown(DispatcherPriority.ApplicationIdle); selectionList.WindowState = WindowState.Normal; selectionList.Show(); //start the windows message pump Dispatcher.Run(); }); thread.SetApartmentState(ApartmentState.STA); thread.IsBackground = true; thread.Start(); //wait for selection list to finish loading while (selectionList == null) { await Task.Delay(100); } while (!selectionList.LoadingUI) { await Task.Delay(100); } while (selectionList.LoadingUI) { await Task.Delay(1000); } selectionList.OnSelectionListReturn += (sender, e) => args = e; Logging.Info("Selecting 100 components"); selectionList.Dispatcher.Invoke(() => { List <SelectablePackage> flatListRandomSelection = DatabaseUtils.GetFlatSelectablePackageList(selectionList.ParsedCategoryList); flatListRandomSelection = flatListRandomSelection.FindAll(package => package.Enabled); Random random = new Random(); for (int i = 0; i < 100; i++) { int selectIndex = random.Next(0, flatListRandomSelection.Count); SelectablePackage package = flatListRandomSelection[selectIndex]; Logging.Info("Index {0} selects package {1}", selectIndex, package.PackageName); package.Checked = true; } //click the continue button List <FrameworkElement> elements = UiUtils.GetAllWindowComponentsLogical(selectionList, false); FrameworkElement buttonElement = elements.Find(element => element.Tag != null && element.Tag.Equals("ContinueButton")); Button clearSelectionsButton = buttonElement as Button; clearSelectionsButton.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); }); //run some base tests on the return args Assert.IsTrue(args.ContinueInstallation); Assert.IsTrue(args.GlobalDependencies.Count > 0); Assert.IsTrue(args.Dependencies.Count > 0); Assert.IsTrue(args.ParsedCategoryList.Count > 0); //below this message is copy-modify-paste from the MainWindow's install and OnBeginInstall methods. Some of this should be moved into some sort of re-usable implementation. TODO //setup for install string wotExeFilepath = RegistryUtils.AutoFindWoTDirectoryFirst(); string wotExeFolderpath = Path.GetDirectoryName(wotExeFilepath); //get version folders to install as string versionXml = Path.Combine(wotExeFolderpath, ApplicationConstants.WoTVersionXml); string versionTemp = XmlUtils.GetXmlStringFromXPath(versionXml, ApplicationConstants.WoTVersionXmlXpath); string WoTClientVersion = versionTemp.Split('#')[0].Trim().Substring(2).Trim(); Logging.Info("Detected client version: {0}", WoTClientVersion); //build macro hash for install MacroUtils.BuildFilepathMacroList(WoTClientVersion, databaseManager.WoTOnlineFolderVersion, wotExeFolderpath); //perform dependency calculations List <DatabasePackage> flatList = DatabaseUtils.GetFlatList(null, null, selectionList.ParsedCategoryList); List <SelectablePackage> flatListSelect = DatabaseUtils.GetFlatSelectablePackageList(selectionList.ParsedCategoryList); List <Dependency> dependneciesToInstall = new List <Dependency>(DatabaseUtils.CalculateDependencies(selectionList.Dependencies, selectionList.ParsedCategoryList, false, false)); //create install list List <DatabasePackage> packagesToInstall = new List <DatabasePackage>(); packagesToInstall.AddRange(selectionList.GlobalDependencies.FindAll(globalDep => globalDep.Enabled && !string.IsNullOrWhiteSpace(globalDep.ZipFile))); packagesToInstall.AddRange(dependneciesToInstall.FindAll(dep => dep.Enabled && !string.IsNullOrWhiteSpace(dep.ZipFile))); List <SelectablePackage> selectablePackagesToInstall = flatListSelect.FindAll(fl => fl.Enabled && fl.Checked && !string.IsNullOrWhiteSpace(fl.ZipFile)); packagesToInstall.AddRange(selectablePackagesToInstall); List <SelectablePackage> userModsToInstall = args.UserMods.FindAll(mod => mod.Checked); //while we're at it let's make a list of packages that need to be downloaded List <DatabasePackage> packagesToDownload = packagesToInstall.FindAll(pack => pack.DownloadFlag); //and check if we need to actually install anything if (selectablePackagesToInstall.Count == 0 && userModsToInstall.Count == 0) { Assert.Fail("No packages to install"); } //perform list install order calculations List <DatabasePackage>[] orderedPackagesToInstall = DatabaseUtils.CreateOrderedInstallList(packagesToInstall); //first, if we have downloads to do, then start processing them CancellationToken nullToken; if (packagesToDownload.Count > 0) { DownloadManager downloadManager = new DownloadManager() { CancellationToken = nullToken, RetryCount = 3, DownloadLocationBase = ApplicationConstants.RelhaxDownloadsFolderPath, UrlBase = ApplicationConstants.DownloadMirrors[selectionList.ModpackSettings.DownloadMirror].Replace("{onlineFolder}", databaseManager.WoTOnlineFolderVersion) }; Logging.Info("Download while install = false and packages to download, processing downloads with await"); Progress <RelhaxDownloadProgress> downloadProgress = new Progress <RelhaxDownloadProgress>(); downloadManager.Progress = downloadProgress; await downloadManager.DownloadPackagesAsync(packagesToDownload); downloadManager.Dispose(); } else { Logging.Info("No packages to download, continue"); } InstallEngine installEngine = new InstallEngine(selectionList.ModpackSettings, selectionList.CommandLineSettings) { FlatListSelectablePackages = flatListSelect, OrderedPackagesToInstall = orderedPackagesToInstall, PackagesToInstall = packagesToInstall, ParsedCategoryList = args.ParsedCategoryList, Dependencies = args.Dependencies, GlobalDependencies = args.GlobalDependencies, UserPackagesToInstall = userModsToInstall, CancellationToken = nullToken, DownloadingPackages = (packagesToDownload.Count > 0), DisableTriggersForInstall = true, DatabaseVersion = "TESTING", WoTDirectory = wotExeFolderpath, WoTClientVersion = WoTClientVersion }; Progress <RelhaxInstallerProgress> progress = new Progress <RelhaxInstallerProgress>(); RelhaxInstallFinishedEventArgs results = await installEngine.RunInstallationAsync(progress); Logging.Debug("Installation has finished"); Assert.IsTrue(results.ExitCode == InstallerExitCodes.Success); installEngine.Dispose(); installEngine = null; }
public void ResetApplicationMacros(AutomationSequence sequence) { Logging.Debug(Logfiles.AutomationRunner, LogOptions.ClassName, "Resetting application macros"); DatabasePackage package = sequence.Package; SelectablePackage selectablePackage = package as SelectablePackage; ApplicationMacros.Clear(); ApplicationMacros.Add(new AutomationMacro() { Name = "date", Value = DateTime.UtcNow.ToString("yyyy-MM-dd"), MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "category.name", Value = (selectablePackage != null)? selectablePackage.ParentCategory.Name : "null", MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "name", Value = (selectablePackage != null)? selectablePackage.NameFormatted : "null", MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "packageName", Value = package.PackageName, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "zipfile", Value = package.ZipFile, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "level", Value = (selectablePackage != null)? selectablePackage.Level.ToString() : "null", MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "patchGroup", Value = package.PatchGroup.ToString(), MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "installGroup", Value = package.InstallGroupWithOffset.ToString(), MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "clientVersion", Value = WoTClientVersion, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "onlineFolderVersion", Value = WoTModpackOnlineFolderVersion, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "author", Value = package.Author, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "version", Value = package.Version, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "applicationPath", Value = ApplicationConstants.ApplicationStartupPath, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "relhaxTemp", Value = ApplicationConstants.RelhaxTempFolderPath, MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "workDirectory", Value = string.Format("{0}\\{1}", ApplicationConstants.RelhaxTempFolderPath, package.PackageName), MacroType = MacroType.ApplicationDefined }); ApplicationMacros.Add(new AutomationMacro() { Name = "automationRepoRoot", Value = AutomationXmlRepoFilebaseEscaped, MacroType = MacroType.ApplicationDefined }); }