/// <summary> /// Handles the Unchecked event of the SearchEngineMenuItem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void SearchEngineMenuItemUnchecked(object sender, RoutedEventArgs e) { if (Actives.Contains((sender as MenuItem).Tag as string)) { Actives.Remove((sender as MenuItem).Tag as string); Settings.Set("Active Subtitle Sites", Actives); } }
/// <summary> /// Loads the engines. /// </summary> /// <param name="reload">if set to <c>true</c> it will reload all variables; otherwise, it will just load the variables which are null.</param> public void LoadEngines(bool reload = false) { if (reload || availableEngines.Items.Count == 0) { availableEngines.Items.Clear(); foreach (var engine in SearchEngines) { var mi = new MenuItem { Header = new StackPanel { Orientation = Orientation.Horizontal }, IsCheckable = true, IsChecked = Actives.Contains(engine.Name), StaysOpenOnClick = true, Tag = engine.Name }; (mi.Header as StackPanel).Children.Add(new Image { Source = new BitmapImage(engine.Icon != null ? new Uri(engine.Icon) : new Uri("/RSTVShowTracker;component/Images/navigation.png", UriKind.Relative), new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.CacheIfAvailable)), Width = 16, Height = 16, Margin = new Thickness(3, -2, 0, 0) }); (mi.Header as StackPanel).Children.Add(new Label { Content = engine.Name, Padding = new Thickness(5, 0, 0, 0), Width = 105 }); if (engine.Private) { var login = Settings.Get(engine.Name + " Login", string.Empty); var cookies = Settings.Get(engine.Name + " Cookies", string.Empty); var tooltip = string.Empty; if (string.IsNullOrWhiteSpace(login) && string.IsNullOrWhiteSpace(cookies)) { if (engine.CanLogin) { tooltip = "Go to Settings, click on the Parsers tab, then select this site and enter the username and password."; } else { tooltip = "Go to Settings, click on the Parsers tab, then select this site and enter the extracted cookies."; } } if (!string.IsNullOrWhiteSpace(login)) { try { var ua = Utils.Decrypt(engine, login); tooltip = "You have supplied login credentials for " + ua[0] + "."; } catch (Exception ex) { tooltip = "Error while decrypting login credentials: " + ex.Message; } } else if (!string.IsNullOrWhiteSpace(cookies)) { try { var cs = Utils.Decrypt(engine, cookies)[0]; tooltip = "You have supplied the following cookies:"; foreach (var cookie in cs.Split(';')) { if (cookie.TrimStart().StartsWith("pass")) { tooltip += "\r\n - " + Regex.Replace(cookie.Trim(), "(?<=pass=.{4})(.+)", m => new string('▪', m.Groups[1].Value.Length)).CutIfLonger(60); } else { tooltip += "\r\n - " + cookie.Trim().CutIfLonger(60); } } } catch (Exception ex) { tooltip = "Error while decrypting cookies: " + ex.Message; } } (mi.Header as StackPanel).Children.Add(new Image { Source = new BitmapImage(new Uri("/RSTVShowTracker;component/Images/" + (string.IsNullOrWhiteSpace(login) && string.IsNullOrWhiteSpace(cookies) ? "lock" : "key") + ".png", UriKind.Relative)), Width = 16, Height = 16, Margin = new Thickness(3, -2, -100, 0), ToolTip = "This is a private site and therefore a valid account is required to search on it.\r\n" + tooltip }); } mi.Checked += SearchEngineMenuItemChecked; mi.Unchecked += SearchEngineMenuItemUnchecked; availableEngines.Items.Add(mi); } } }