/// <summary> /// Проверка входит ли процесс в список запрещенных к закрытию /// </summary> /// <param name="process">Имя процесса</param> /// <returns>Применяемый визуальный стиль</returns> /*private string Style(string process) * { * try * { * if (ProccessLibrary.Search(process)) return "ProcessesCheckedGlobal"; * if (CheckUserProcess(process)) return "ProcessesChecked"; * return "ProcessesUnChecked"; * } * catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("SettingsProcesses.xaml", "Style()", "Process: " + process, ex.Message, ex.StackTrace)); } * * return "ProcessesUnChecked"; * }*/ private void ProcessChanged(object sender, RoutedEventArgs e) { CheckBox cb = sender as CheckBox; ListBoxItem el = (((sender as CheckBox).Parent as Grid).Parent as ListBoxItem); string processName = cb.Name.Remove(0, 2); try { if (cb.IsEnabled) { if (cb.IsChecked == true) { MainWindow.JsonSettingsSet("processes", processName, "array"); el.SetResourceReference(ListBoxItem.StyleProperty, "lbiProcessCheck"); } else { MainWindow.JsonSettingsRemove("processes." + processName, "array"); el.SetResourceReference(ListBoxItem.StyleProperty, "lbiProcessUnCheck"); } } } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("SettingsProcesses.xaml", "ProcessChanged()", ex.Message, ex.StackTrace)); } }
private void bClearCache_Click(object sender, RoutedEventArgs e) { Task.Factory.StartNew(() => { try { if (MainWindow.MessageShow(Lang.Set("PageSettings", "ClearCacheSure", lang), "", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { if (MainWindow.JsonSettingsRemove("token")) { MainWindow.JsonSettingsSet("info.user_email", ""); MainWindow.JsonSettingsSet("info.user_name", ""); new Classes.WargamingAPI().Logout(); Dispatcher.BeginInvoke(new ThreadStart(delegate { bClearAutorization.IsEnabled = false; })); MainWindow.MessageShow(Lang.Set("PageSettings", "ClearCacheSuccess", lang)); } else { MainWindow.MessageShow(Lang.Set("PageSettings", "ClearCacheError", lang)); } } } catch (Exception ex) { Debugging.Save("Settings.xaml", "bClearCache_Click()", ex.Message, ex.StackTrace); } }); }
private void Idisagree_Click(object sender, RoutedEventArgs e) { try { MainWindow.JsonSettingsSet("info.user_accept", false, "bool"); MainWindow.Navigator(); } catch (Exception ex) { Debugging.Save("GiveEmail.xaml", "Idisagree_Click()", ex.Message, ex.StackTrace); } }
/// <summary> ////Открываем гиперссылку /// </summary> /// <param name="sender"></param> /// <param name="e">Параметры</param> private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) { try { Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri)); e.Handled = true; MainWindow.JsonSettingsSet("stats.donate_link", 1 + (int)MainWindow.JsonSettingsGet("stats.donate_link"), "int"); } catch (Exception ex) { Task.Factory.StartNew(() => new Classes.Debugging().Save("General.xaml", "Hyperlink_RequestNavigate()", "Link: " + e.Uri.AbsoluteUri, ex.Message, ex.StackTrace)); } }
private void Page_Loaded(object sender, RoutedEventArgs e) { Dispatcher.BeginInvoke(new ThreadStart(delegate { try { MainWindow.LoadPage.Visibility = Visibility.Hidden; MainWindow.JsonSettingsSet("stats.donate", 1 + (int)MainWindow.JsonSettingsGet("stats.donate"), "int"); } catch (Exception) { } })); }
/// <summary> /// /// </summary> private void ClosingPage() { Dispatcher.BeginInvoke(new ThreadStart(delegate { MainWindow.LoadPage.Visibility = System.Windows.Visibility.Visible; })); Thread.Sleep(Convert.ToInt16(Properties.Resources.Default_Navigator_Sleep)); Dispatcher.BeginInvoke(new ThreadStart(delegate { try { if (cbNotify.IsChecked == true) { MainWindow.JsonSettingsSet("info.notification", MainWindow.JsonSettingsGet("multipack.new_version")); } MainWindow.JsonSettingsSet("info.session", System.Diagnostics.Process.GetCurrentProcess().Id, "int"); MainWindow.Navigator(); } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("Update.xaml", "bUpdate_Click()", ex.Message, ex.StackTrace)); } })); }
/// <summary> /// Считываем email при подтверждении отправки формы /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WB_Navigating(object sender, System.Windows.Navigation.NavigatingCancelEventArgs e) { try { Task.Factory.StartNew(() => { Dispatcher.BeginInvoke(new ThreadStart(delegate { try { var doc = WB.Document as HTMLDocument; if ( doc != null && WB.Source.ToString() != Properties.Resources.API_DEV_Address + Properties.Resources.API_DEV_OpenID && WB.Source.ToString().IndexOf("AUTH_CANCEL") == -1 ) { Regex regex = new Regex(@"\w+[a-zA-Z0-9-_.]+@+\w+[a-zA-Z0-9-]+.[a-zA-Z]{2,10}"); IHTMLElementCollection nodes = doc.getElementsByTagName("html"); foreach (IHTMLElement elem in nodes) { var body = (HTMLHeadElement)elem; Match match = regex.Match(body.innerHTML); while (match.Success) { try { MainWindow.JsonSettingsSet("info.user_email", match.Value.Trim()); } catch (Exception) { } match = match.NextMatch(); } } } } catch (Exception) { } })); }).Wait(); } catch (Exception ex) { Debugging.Save("WarApiOpenID.xaml", "WB_Navigating()", WB.Source.ToString(), ex.Message, ex.StackTrace); } }
private void GetLangNow() { try { switch ((string)MainWindow.JsonSettingsGet("info.language")) { case "en": cbLang.SelectedIndex = 1; break; case "de": cbLang.SelectedIndex = 2; break; case "ua": cbLang.SelectedIndex = 3; break; default: cbLang.SelectedIndex = 0; break; } if (IsManual) { cbLangPriority.SelectedIndex = 2; MainWindow.JsonSettingsSet("info.locale", cbLangPriority.SelectedIndex, "int"); } } catch (Exception) { } }
private void cbLang_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { switch (cbLang.SelectedIndex) { case 1: MainWindow.JsonSettingsSet("info.language", "en"); break; case 2: MainWindow.JsonSettingsSet("info.language", "de"); break; case 3: MainWindow.JsonSettingsSet("info.language", "ua"); break; default: MainWindow.JsonSettingsSet("info.language", "ru"); break; } } catch (Exception) { } finally { //if (IsManual) // //MainWindow.JsonSettingsSet("info.locale", cbLangPriority.SelectedIndex, "int"); } }
private void cbLangPriority_SelectionChanged(object sender, SelectionChangedEventArgs e) { string newLang = String.Empty; switch (cbLangPriority.SelectedIndex) { // Мультипак 0 case 0: newLang = (string)MainWindow.JsonSettingsGet("multipack.language"); IsManual = false; break; // Клиент игры 1 case 1: newLang = (string)MainWindow.JsonSettingsGet("game.language"); IsManual = false; break; // Вручную 2 case 2: newLang = (string)MainWindow.JsonSettingsGet("info.language"); IsManual = true; break; default: newLang = Properties.Resources.Default_Lang; IsManual = true; break; } MainWindow.JsonSettingsSet("info.locale", cbLangPriority.SelectedIndex, "int"); MainWindow.JsonSettingsSet("info.language", newLang); GetLangNow(); }
private void lbLocales_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem); MainWindow.JsonSettingsSet("info.language", lbi.Name); MainWindow.JsonSettingsSet("info.locale", 2, "int"); Dispatcher.BeginInvoke(new ThreadStart(delegate { try { bClose.Content = Lang.Set("PageSettings", "bClose", lbi.Name); MainWindow.PlayBtn.Text = Lang.Set("MainProject", "bPlay", lbi.Name); MainWindow.Flag.Source = new BitmapImage(new Uri(String.Format(@"pack://application:,,,/{0};component/Resources/flag_{1}.png", (string)MainWindow.JsonSettingsGet("info.ProductName"), lbi.Name))); MainWindow.LoadPage.Visibility = Visibility.Hidden; } catch (Exception ex) { Debugging.Save("ChangeLocale.xaml", "lbLocales_SelectionChanged", "Innter Catch", ex.Message, ex.StackTrace); } })); } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("ChangeLocale.xaml", "lbLocales_SelectionChanged", ex.Message, ex.StackTrace)); } }
private void cbWeak_Click(object sender, RoutedEventArgs e) { MainWindow.JsonSettingsSet("settings.weak", cbWeak.IsChecked, "bool"); }
private void cbNotifyNews_Click(object sender, RoutedEventArgs e) { MainWindow.JsonSettingsSet("info.news", cbNotifyNews.IsChecked, "bool"); MainWindow.JsonSettingsSet("info.manual_info", true, "bool"); }
private void SendData() { Task.Factory.StartNew(() => { LoaderShow(); }); Dispatcher.BeginInvoke(new ThreadStart(delegate { MainWindow.JsonSettingsSet("info.user_email", tbEmail.Text.Trim()); })); pageParsed = false; Dispatcher.BeginInvoke(new ThreadStart(delegate { string inputData = "function inputData() {" + "$('#id_login').val('" + tbEmail.Text.Trim() + "');" + "$('#id_password').val('" + pbPassword.Password + "');" + "$('#id_captcha').val('" + tbCaptcha.Text.Trim() + "');" + "$('#js-auth-form').submit();" + "} " + "inputData();"; var doc = WB.Document as HTMLDocument; if (doc != null) { var scriptErrorSuppressed = (IHTMLScriptElement)doc.createElement("SCRIPT"); scriptErrorSuppressed.type = "text/javascript"; scriptErrorSuppressed.text = inputData; IHTMLElementCollection nodes = doc.getElementsByTagName("head"); foreach (IHTMLElement elem in nodes) { (elem as HTMLHeadElement).appendChild((IHTMLDOMNode)scriptErrorSuppressed); } } })); Thread.Sleep(3000); Dispatcher.BeginInvoke(new ThreadStart(delegate { try { /* * Проверка корректности ввода капчи */ var doc = WB.Document as HTMLDocument; IHTMLElementCollection nodes = doc.getElementsByTagName("body"); foreach (IHTMLElement elem in nodes) { var body = (HTMLHeadElement)elem; if (body.innerHTML.IndexOf("Символы указаны неверно") > -1) { UpdateCaptcha(); Dispatcher.BeginInvoke(new ThreadStart(delegate { try { CaptionStatus.Text = "Error"; tbCaptcha.Text = ""; resultErrors = "error"; Task.Factory.StartNew(() => { LoaderShow(false); }); } catch (Exception) { } })); } /* * Проверка не вышла ли другая ошибка */ if (resultErrors == "") { Thread.Sleep(5000); Regex regexErrors = new Regex("<P class=js-form-errors-content>(.*)</P>", RegexOptions.IgnoreCase); Match matchErrors = regexErrors.Match(body.innerHTML); while (matchErrors.Success) { resultErrors = matchErrors.Value.Trim(); resultErrors = resultErrors .Replace("<P class=js-form-errors-content>", "") .Replace("<p class=js-form-errors-content>", "") .Replace("</P>", "") .Replace("</p>", ""); if (resultErrors == "") { matchErrors = matchErrors.NextMatch(); } else { CaptionStatus.Text = "Error"; tbCaptcha.Text = ""; UpdateCaptcha(); Task.Factory.StartNew(() => { LoaderShow(false); }); break; } } } /* * Если ошибка НЕ найдена */ if (resultErrors == "") { Thread.Sleep(3000); foreach (IHTMLElement elemInput in (WB.Document as HTMLDocument).getElementsByName("allow")) { if (elemInput.tagName == "INPUT" && elemInput.className == "b-big-orange-button_right") { elemInput.click(); break; } } } else { Task.Factory.StartNew(() => { LoaderShow(); }); } } } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("WgOpenIdAIRUS.xaml", "CheckCaptcha()", ex.Message, ex.StackTrace)); } })); }
private void WB_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { try { Task.Factory.StartNew(() => { Dispatcher.BeginInvoke(new ThreadStart(delegate { try { if (WB.Source.ToString().IndexOf("status=ok") > -1) { JObject Token = WarAPI.Token(WB.Source.ToString()); MainWindow.JsonSettingsSet("token.access_token", (string)Token.SelectToken("access_token")); MainWindow.JsonSettingsSet("token.expires_at", (string)Token.SelectToken("expires_at")); MainWindow.JsonSettingsSet("token.nickname", (string)Token.SelectToken("nickname")); MainWindow.JsonSettingsSet("token.account_id", (string)Token.SelectToken("account_id")); MainWindow.JsonSettingsSet("info.user_name", (string)Token.SelectToken("nickname")); try { Dispatcher.BeginInvoke(new ThreadStart(delegate { MainWindow.LoadPage.Visibility = System.Windows.Visibility.Visible; })); Thread.Sleep(Convert.ToInt16(Properties.Resources.Default_Navigator_Sleep)); Dispatcher.BeginInvoke(new ThreadStart(delegate { MainWindow.Navigator("UserProfile"); })); } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("WarApiOpenID.xaml", "WB_LoadCompleted()", ex.Message, ex.StackTrace)); } this.Close(); } if (WB.Source.ToString().IndexOf("AUTH_CANCEL") > -1) { MessageBoxResult mbr = MessageBox.Show(Lang.Set("PageUser", "ActivateWarID", (string)MainWindow.JsonSettingsGet("info.language")) + Environment.NewLine + Lang.Set("PageUser", "RepeatActivation", (string)MainWindow.JsonSettingsGet("info.language")), (string)MainWindow.JsonSettingsGet("info.ProductName"), MessageBoxButton.YesNo, MessageBoxImage.Information); if (mbr == MessageBoxResult.Yes) { string uri = WarAPI.OpenID(); if (uri != null) { WB.Source = new Uri(WarAPI.OpenID()); } else { Debugging.Save("WarApiOpenID.xaml", "WB_LoadCompleted()", "WarAPI.OpenID() == null"); this.Close(); } } else { this.Close(); } } } catch (Exception) { } /* * Парсим форму * * * form | IgnoreCase | Singleline * <form id=js-auth-form(.*)form> * * csrfmiddlewaretoken | IgnoreCase * value=(.*) name=csrfmiddlewaretoken * * next | IgnoreCase * value=(.*) name=next * * captcha | IgnoreCase * <img class=js-captcha-image src="(.*)"> */ try { if (!pageParsed) { Regex regexForm = new Regex("<form id=js-auth-form(.*)form>", RegexOptions.IgnoreCase | RegexOptions.Singleline); Regex regexCsrf = new Regex("value=(.*) name=csrfmiddlewaretoken", RegexOptions.IgnoreCase); Regex regexNext = new Regex("value=(.*) name=next", RegexOptions.IgnoreCase); Regex regexCaptcha = new Regex("<img class=js-captcha-image src=\"(.*)\"> </div>", RegexOptions.IgnoreCase); var doc = WB.Document as HTMLDocument; string resultCsrf = "", resultNext = "", resultCaptcha = ""; IHTMLElementCollection nodes = doc.getElementsByTagName("html"); foreach (IHTMLElement elem in nodes) { var form = (HTMLHeadElement)elem; // Ищем форму Match match = regexForm.Match(form.innerHTML); while (match.Success) { // Ищем Csrf Match matchCsrf = regexCsrf.Match(match.Value.Trim()); while (matchCsrf.Success) { resultCsrf = matchCsrf.Value.Trim(); resultCsrf = resultCsrf .Replace("value=", "") .Replace(" name=csrfmiddlewaretoken", ""); matchCsrf = matchCsrf.NextMatch(); } // Ищем Next Match matchNext = regexNext.Match(match.Value.Trim()); while (matchNext.Success) { resultNext = matchNext.Value.Trim(); resultNext = resultNext .Replace("value=", "") .Replace(" name=next", ""); matchNext = matchNext.NextMatch(); } // Ищем Captcha Match matchCaptcha = regexCaptcha.Match(match.Value.Trim()); while (matchCaptcha.Success) { resultCaptcha = matchCaptcha.Value.Trim(); resultCaptcha = resultCaptcha .Replace("<IMG class=js-captcha-image src=\"", "") .Replace("<img class=js-captcha-image src=\"", "") .Replace("\"> </div>", "") .Replace("\"> </DIV>", ""); if (resultCaptcha == "") { matchCaptcha = matchCaptcha.NextMatch(); } else { break; } } match = match.NextMatch(); } } string resourcesForm = Properties.Resources.index; /* * if (!System.IO.File.Exists(@"c:\Users\Helldar\AppData\Roaming\Wargaming.net\WorldOfTanks\multipack_launcher\2.txt")) * System.IO.File.WriteAllText(@"c:\Users\Helldar\AppData\Roaming\Wargaming.net\WorldOfTanks\multipack_launcher\2.txt", WB.Source.ToString()); */ resourcesForm = resourcesForm .Replace("{{TOKEN}}", resultCsrf) .Replace("{{NEXT}}", resultNext) .Replace("{{CAPTCHA}}", resultCaptcha); WB.NavigateToString(resourcesForm); pageParsed = true; } } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("WarApiOpenID.xaml", "WB_LoadCompleted()", "Parse form", ex.Message, ex.StackTrace)); } })); }).Wait(); if (!loaded) { Dispatcher.BeginInvoke(new ThreadStart(delegate { try { DoubleAnimation da = new DoubleAnimation(); da.From = WOIloading.Height; da.To = 0; da.Duration = TimeSpan.FromSeconds(1); WOIloading.BeginAnimation(Button.HeightProperty, da); } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("WarApiOpenID.xaml", "WB_LoadCompleted()", "DoubleAnimation da = new DoubleAnimation();", ex.Message, ex.StackTrace)); } })); loaded = true; } } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("WarApiOpenID.xaml", "WebBrowser_LoadCompleted()", ex.Message, ex.StackTrace)); } }
private void cbLauncher_SelectionChanged(object sender, SelectionChangedEventArgs e) { MainWindow.JsonSettingsSet("settings.launcher", cbLauncher.SelectedIndex, "int"); }
/// <summary> /// Получаем информацию по аккаунту. /// Если токен активен, сразу выводим. /// Если нет, вначале запрашиваем авторизацию, после чего получаем информацию. /// </summary> private void AccountInfo() { // Копируем ник юзера в блок Info XML try { string user_name = (string)MainWindow.JsonSettingsGet("token.nickname"); if (user_name != null && user_name != "") { MainWindow.JsonSettingsSet("info.user_name", user_name); } } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("UserProfile.xaml", "AccountInfo()", "Set username", ex.Message, ex.StackTrace)); } // Apply language try { Dispatcher.BeginInvoke(new ThreadStart(delegate { bClose.Content = Lang.Set("PageSettings", "bClose", lang); gbSostav.Header = Lang.Set("PageUser", "tbPersonnel", lang); dataonTitle.Text = Lang.Set("PageUser", "tbDataOn", lang); })); } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("UserProfile.xaml", "AccountInfo()", "Apply language", ex.Message, ex.StackTrace)); } try { Dispatcher.BeginInvoke(new ThreadStart(delegate { try { MainWindow.LoadPage.Visibility = System.Windows.Visibility.Visible; Thread.Sleep(Convert.ToInt16(Properties.Resources.Default_Navigator_Sleep)); if (!(CheckElement("access_token") && CheckElement("expires_at") && CheckElement("nickname") && CheckElement("account_id"))) { try { MainWindow.JsonSettingsRemove("token"); MainWindow.Navigator(); } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("UserProfile.xaml", "AccountInfo()", "Token is FAIL", ex.Message, ex.StackTrace)); } } else { Dispatcher.BeginInvoke(new ThreadStart(delegate { try { nickname = (string)MainWindow.JsonSettingsGet("token.nickname"); account_id = (string)MainWindow.JsonSettingsGet("token.account_id"); access_token = (string)MainWindow.JsonSettingsGet("token.access_token"); PlayerName.Text = nickname; JObject JAccountInfo = WarAPI.AccountInfo(account_id, access_token); JObject Clan = null, Battles = null, Provinces = null; if ((string)JAccountInfo.SelectToken("status") == "ok") { /* ========================================= * Проверяем клан * Если параметр пуст - деактивируем вкладки * =========================================*/ try { if (JAccountInfo.SelectToken(String.Format("data.{0}.clan_id", account_id)) == null) { tiClanInfo.IsEnabled = false; tiClanBattles.IsEnabled = false; tiClanProvinces.IsEnabled = false; } else { //obj["data"]["2732865"]["clan_id"] = 60118; // Подставной клан clan_id = (string)JAccountInfo.SelectToken(String.Format("data.{0}.clan_id", account_id)); Clan = WarAPI.ClanInfo(clan_id, access_token); Battles = WarAPI.ClanBattles(clan_id, access_token); Provinces = WarAPI.ClanProvinces(clan_id, access_token, "type,name,arena_i18n,prime_time,revenue,occupancy_time,attacked"); } } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("UserProfile.xaml", "AccountInfo()", "Check Clan", ex.Message, ex.StackTrace)); } /* ========================================= * Общая информация о пользователе * =========================================*/ try { if ((string)Clan.SelectToken("status") == "ok") { DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); dt = dt.AddSeconds((double)Clan.SelectToken(String.Format("data.{0}.members.{1}.created_at", clan_id, account_id))); TimeSpan ts = DateTime.Now - dt; PlayerClan.Text = "[" + (string)Clan.SelectToken(String.Format("data.{0}.abbreviation", clan_id)) + "]"; PlayerClan2.Text = (string)Clan.SelectToken(String.Format("data.{0}.name", clan_id)); ClanFullname.Text = PlayerClan2.Text; PlayerZvanie.Text = Lang.Set("Rank", (string)Clan.SelectToken(String.Format("data.{0}.members.{1}.role", clan_id, account_id)), lang); BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri((string)Clan.SelectToken(String.Format("data.{0}.emblems.medium", clan_id)), UriKind.Absolute); bitmap.EndInit(); ClanEmblem.Source = bitmap; ClanEmblem2.Source = bitmap; } else { PlayerClan2.Text = Lang.Set("PageUser", "NotClan", lang); PlayerZvanie.Text = String.Empty; } // Процент побед PercWins.Text = Lang.Set("PageUser", "tbPercentWins", lang); PercWinsPerc.Text = (Math.Round(((double)JAccountInfo.SelectToken(String.Format("data.{0}.statistics.all.wins", account_id)) / (double)JAccountInfo.SelectToken(String.Format("data.{0}.statistics.all.battles", account_id))) * 100, 2)).ToString(); // Личный рейтинг MyRating.Text = Lang.Set("PageUser", "tbMyRating", lang); MyRatingPerc.Text = SetSumm((string)JAccountInfo.SelectToken(String.Format("data.{0}.global_rating", account_id))); // Средний опыт за бой AvgXP.Text = Lang.Set("PageUser", "tbAvgXP", lang); AvgXPPerc.Text = SetSumm((string)JAccountInfo.SelectToken(String.Format("data.{0}.statistics.all.battle_avg_xp", account_id))); // Количество боев BattleCount.Text = Lang.Set("PageUser", "tbCountWars", lang); BattleCountPerc.Text = SetSumm((string)JAccountInfo.SelectToken(String.Format("data.{0}.statistics.all.battles", account_id))); // Средний нанесенный урон за бой AvgDamage.Text = Lang.Set("PageUser", "tbAvgDamage", lang); AvgDamagePerc.Text = SetSumm((string)JAccountInfo.SelectToken(String.Format("data.{0}.statistics.all.avg_damage_assisted", account_id))); } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("UserProfile.xaml", "AccountInfo()", "User Info", ex.Message, ex.StackTrace)); } try { PlayerGold.Text = SetSumm((string)JAccountInfo.SelectToken(String.Format("data.{0}.private.gold", account_id))); PlayerCredit.Text = SetSumm((string)JAccountInfo.SelectToken(String.Format("data.{0}.private.credits", account_id))); PlayerXP.Text = SetSumm((string)JAccountInfo.SelectToken(String.Format("data.{0}.private.free_xp", account_id))); iAccountType.Source = new BitmapImage(new Uri(String.Format(@"pack://application:,,,/{0};component/Resources/{1}", (string)MainWindow.JsonSettingsGet("info.ProductName"), (bool)JAccountInfo.SelectToken(String.Format("data.{0}.private.is_premium", account_id)) ? "ico-account-premium.png" : "ico-account-base.png"))); iAccountType.ToolTip = Lang.Set("Global", (bool)JAccountInfo.SelectToken(String.Format("data.{0}.private.is_premium", account_id)) ? "IsPremium" : "IsBase", lang); } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("UserProfile.xaml", "AccountInfo()", "User Credits", ex.Message, ex.StackTrace)); } /*Batles.Text = SelectToken(obj, "statistics.all.battles"); * Wins.Text = SelectToken(obj, "statistics.all.wins"); * Loss.Text = SelectToken(obj, "statistics.all.losses"); * * WinsPercent.Text = (Math.Round(((Convert.ToDouble(SelectToken(obj, "statistics.all.wins")) / Convert.ToDouble(SelectToken(obj, "statistics.all.battles"))) * 100), 2)).ToString(); * LossPercent.Text = (Math.Round(((Convert.ToDouble(SelectToken(obj, "statistics.all.losses")) / Convert.ToDouble(SelectToken(obj, "statistics.all.battles"))) * 100), 2)).ToString(); * WhoPercent.Text = (Math.Round(((Convert.ToDouble(SelectToken(obj, "statistics.all.draws")) / Convert.ToDouble(SelectToken(obj, "statistics.all.battles"))) * 100), 2)).ToString(); * * AvgXP.Text = SelectToken(obj, "statistics.all.battle_avg_xp");*/ /* * ГРАФИК */ /*try * { * this.DataContext = new ObservableCollection<AssetClass>(AssetClass.ConstructTestData(new JObject( * new JProperty("wins", * new JObject( * new JProperty("name", "Победы"), * new JProperty("total", Convert.ToInt16(SelectToken(obj, "statistics.all.wins"))) * ) * ), * new JProperty("losses", * new JObject( * new JProperty("name", "Поражения"), * new JProperty("total", Convert.ToInt16(SelectToken(obj, "statistics.all.losses"))) * ) * ), * new JProperty("draws", * new JObject( * new JProperty("name", "Ничьи"), * new JProperty("total", Convert.ToInt16(SelectToken(obj, "statistics.all.draws"))) * ) * ) * ))); * } * catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("UserProfile.xaml", "AccountInfo()", "Graphic", ex.Message, ex.StackTrace)); } */ /* ========================================= * Общая информация о клане * =========================================*/ if (Clan != null) { try { ClanDesc.Text = (string)Clan.SelectToken(String.Format("data.{0}.motto", clan_id)); ClanCount.Text = (string)Clan.SelectToken(String.Format("data.{0}.members_count", clan_id)); dataonTitle.Text = Lang.Set("PageUser", "tbDataOn", lang); dataon.Text = DateFormat((double)Clan.SelectToken(String.Format("data.{0}.updated_at", clan_id))); } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("UserProfile.xaml", "AccountInfo()", "Clan", ex.Message, ex.StackTrace)); } /* ========================================= * Члены клана * =========================================*/ try { ClanMembers.Items.Clear(); int i = 1; foreach (var member in (JObject)Clan.SelectToken(String.Format("data.{0}.members", clan_id))) { Grid gr = new Grid(); gr.SetResourceReference(Grid.StyleProperty, "GridW470"); ColumnDefinition cd1 = new ColumnDefinition(); ColumnDefinition cd2 = new ColumnDefinition(); ColumnDefinition cd3 = new ColumnDefinition(); ColumnDefinition cd4 = new ColumnDefinition(); cd1.Width = new GridLength(30, GridUnitType.Auto); cd2.Width = new GridLength(1, GridUnitType.Star); cd3.Width = new GridLength(130, GridUnitType.Auto); cd4.Width = new GridLength(80, GridUnitType.Auto); gr.ColumnDefinitions.Add(cd1); gr.ColumnDefinitions.Add(cd2); gr.ColumnDefinitions.Add(cd3); gr.ColumnDefinitions.Add(cd4); TextBlock tbID = new TextBlock(); tbID.Text = (i++).ToString(); tbID.SetResourceReference(TextBlock.StyleProperty, "CmID"); Grid.SetColumn(tbID, 0); TextBlock CmName = new TextBlock(); CmName.Text = (string)member.Value["account_name"]; CmName.SetResourceReference(TextBlock.StyleProperty, "CmName"); Grid.SetColumn(CmName, 1); TextBlock CmTitle = new TextBlock(); CmTitle.Text = Lang.Set("Rank", (string)member.Value["role"], lang); CmTitle.SetResourceReference(TextBlock.StyleProperty, "CmTitle"); Grid.SetColumn(CmTitle, 2); TextBlock CmDate = new TextBlock(); CmDate.Text = DateFormat((double)member.Value["created_at"]); CmDate.SetResourceReference(TextBlock.StyleProperty, "CmDate"); Grid.SetColumn(CmDate, 3); gr.Children.Add(tbID); gr.Children.Add(CmName); gr.Children.Add(CmTitle); gr.Children.Add(CmDate); ListBoxItem lbi = new ListBoxItem(); lbi.SetResourceReference(ListBoxItem.StyleProperty, "lbiProcess"); lbi.Content = gr; ClanMembers.Items.Add(lbi); } } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("UserProfile.xaml", "AccountInfo()", "Clan members", ex.Message, ex.StackTrace)); } /* ========================================= * Бои клана * =========================================*/ try { tbBattles.Text = Lang.Set("PageUser", "tbBattles", lang); if ((string)Battles.SelectToken("status") == "ok") { JArray arr = (JArray)Battles.SelectToken("data." + clan_id); if (arr.Count > 0) { ClanBattles.Items.Clear(); foreach (var battle in arr) { /* * Тип * Время * Провинция * Игровая карта * * Тип боя: * for_province — бой за провинцию; * meeting_engagement — встречный бой; * landing — бой за высадку. */ //JObject GlobalProvinces = WarAPI.GlobalProvinces((string)battle["provinces"][0]); Grid gr = new Grid(); gr.SetResourceReference(Grid.StyleProperty, "ClanBattlesGrid"); ColumnDefinition cd1 = new ColumnDefinition(); ColumnDefinition cd2 = new ColumnDefinition(); ColumnDefinition cd3 = new ColumnDefinition(); ColumnDefinition cd4 = new ColumnDefinition(); cd1.Width = new GridLength(1, GridUnitType.Auto); //cd2.Width = new GridLength(250, GridUnitType.Pixel); cd3.Width = new GridLength(1, GridUnitType.Auto); cd4.Width = new GridLength(1, GridUnitType.Auto); gr.ColumnDefinitions.Add(cd1); gr.ColumnDefinitions.Add(cd2); gr.ColumnDefinitions.Add(cd3); gr.ColumnDefinitions.Add(cd4); Image im = new Image(); im.SetResourceReference(Image.StyleProperty, "Icon_" + (string)battle["type"]); TextBlock tbID = new TextBlock(); tbID.Text = DateFormat((double)battle["time"], "HH:mm"); tbID.SetResourceReference(TextBlock.StyleProperty, "CmTIME"); Grid.SetColumn(tbID, 3); TextBlock CmName = new TextBlock(); //CmName.Text = SelectTokenNoClan(GlobalProvinces, (string)battle["provinces"][0] + ".province_i18n"); CmName.Text = (string)battle["provinces_i18n"][0]["name_i18n"]; CmName.SetResourceReference(TextBlock.StyleProperty, "CmName"); Grid.SetColumn(CmName, 1); TextBlock CmTitle = new TextBlock(); CmTitle.Text = (string)battle["arenas"][0]["name_i18n"]; CmTitle.SetResourceReference(TextBlock.StyleProperty, "CmTitle"); Grid.SetColumn(CmTitle, 2); gr.Children.Add(im); gr.Children.Add(tbID); gr.Children.Add(CmName); gr.Children.Add(CmTitle); ListBoxItem lbi = new ListBoxItem(); lbi.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; lbi.SetResourceReference(Grid.StyleProperty, "ClanBattles"); lbi.Content = gr; ClanBattles.Items.Add(lbi); } } else { //ClanBattlesNoRecords.Text = Lang.Set("PageUser", "ClanBattlesNoRecords", lang); ListBoxItem lbi = new ListBoxItem(); lbi.SetResourceReference(ListBoxItem.StyleProperty, "rec_not_found"); TextBlock tb = new TextBlock(); tb.Text = Lang.Set("PageUser", "ClanBattlesNoRecords", lang); lbi.Content = tb; ClanBattles.Items.Clear(); ClanBattles.Items.Add(lbi); } } } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("UserProfile.xaml", "AccountInfo()", "Clan battles", ex.Message, ex.StackTrace)); } /* * Провинции клана * * Тип: * Стартовая * Обычная * Ключевая * Название * Игровая карта * Прайм-тайм * Доход * Время владения * Провинция атакована * * type * name * arena_i18n * prime_time * revenue * occupancy_time * attacked */ try { tbProvinces.Text = Lang.Set("PageUser", "tbProvinces", lang); if ((string)Provinces.SelectToken("status") == "ok") { JObject arr = (JObject)Provinces["data"]; if (arr.Count > 0) { ClanProvinces.Items.Clear(); foreach (var province in arr) { Grid gr = new Grid(); gr.SetResourceReference(Grid.StyleProperty, "ClanBattlesGrid"); ColumnDefinition cd1 = new ColumnDefinition(); ColumnDefinition cd2 = new ColumnDefinition(); ColumnDefinition cd3 = new ColumnDefinition(); ColumnDefinition cd4 = new ColumnDefinition(); ColumnDefinition cd5 = new ColumnDefinition(); ColumnDefinition cd6 = new ColumnDefinition(); ColumnDefinition cd7 = new ColumnDefinition(); cd1.Width = new GridLength(1, GridUnitType.Auto); //cd2.Width = new GridLength(1, GridUnitType.Auto); cd3.Width = new GridLength(1, GridUnitType.Auto); cd4.Width = new GridLength(50, GridUnitType.Pixel); cd5.Width = new GridLength(1, GridUnitType.Auto); cd6.Width = new GridLength(50, GridUnitType.Pixel); gr.ColumnDefinitions.Add(cd1); gr.ColumnDefinitions.Add(cd2); gr.ColumnDefinitions.Add(cd3); gr.ColumnDefinitions.Add(cd4); gr.ColumnDefinitions.Add(cd5); gr.ColumnDefinitions.Add(cd6); Image im = new Image(); im.SetResourceReference(Image.StyleProperty, "province_types_" + (string)province.Value["type"]); TextBlock t1 = new TextBlock(); t1.Text = (string)province.Value["name"]; t1.SetResourceReference(TextBlock.StyleProperty, "t1"); Grid.SetColumn(t1, 1); TextBlock t2 = new TextBlock(); t2.Text = (string)province.Value["arena_i18n"]; t2.SetResourceReference(TextBlock.StyleProperty, "t2"); Grid.SetColumn(t2, 2); TextBlock t3 = new TextBlock(); t3.Text = DateFormat((double)province.Value["prime_time"], "HH:mm"); t3.SetResourceReference(TextBlock.StyleProperty, "t3"); Grid.SetColumn(t3, 3); TextBlock t4 = new TextBlock(); t4.Text = (string)province.Value["revenue"]; t4.SetResourceReference(TextBlock.StyleProperty, "t4"); Grid.SetColumn(t4, 4); TextBlock t5 = new TextBlock(); t5.Text = (string)province.Value["occupancy_time"]; t5.SetResourceReference(TextBlock.StyleProperty, "t5"); Grid.SetColumn(t5, 5); gr.Children.Add(im); gr.Children.Add(t1); gr.Children.Add(t2); gr.Children.Add(t3); gr.Children.Add(t4); gr.Children.Add(t5); ListBoxItem lbi = new ListBoxItem(); lbi.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; lbi.SetResourceReference(ListBoxItem.StyleProperty, (bool)province.Value["attacked"] ? "ClanProvincesAttacked" : "ClanProvincesNonAttacked"); lbi.Content = gr; ClanProvinces.Items.Add(lbi); } } else { //ClanProvincesNoRecords.Text = Lang.Set("PageUser", "ClanProvincesNoRecords", lang); ListBoxItem lbi = new ListBoxItem(); lbi.SetResourceReference(ListBoxItem.StyleProperty, "rec_not_found"); TextBlock tb = new TextBlock(); tb.Text = Lang.Set("PageUser", "ClanProvincesNoRecords", lang); lbi.Content = tb; ClanProvinces.Items.Clear(); ClanProvinces.Items.Add(lbi); } } } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("UserProfile.xaml", "AccountInfo()", "Clan provincies", ex.Message, ex.StackTrace)); } } } else { MainWindow.JsonSettingsRemove("token"); switch ((string)JAccountInfo.SelectToken("error.message")) { case "INVALID_ACCESS_TOKEN": MessageBox.Show(Lang.Set("PageUser", "ActivateWarID", lang)); break; default: MessageBox.Show(Lang.Set("PageUser", "ErrorDataJson", lang)); break; } try { MainWindow.Navigator(); } catch (Exception) { } } } catch (Exception e) { Task.Factory.StartNew(() => Debugging.Save("UserProfile.xaml", "AccountInfo()", "if (!active)", e.Message, e.StackTrace)); } })); } } catch (Exception e) { Task.Factory.StartNew(() => Debugging.Save("UserProfile.xaml", "AccountInfo()", e.Message, e.StackTrace)); } finally { MainWindow.LoadPage.Visibility = System.Windows.Visibility.Hidden; Thread.Sleep(Convert.ToInt16(Properties.Resources.Default_Navigator_Sleep)); } })); } catch (Exception) { } }
private void cbForce_Click(object sender, RoutedEventArgs e) { MainWindow.JsonSettingsSet("settings.force", cbForce.IsChecked, "bool"); }
private void WB_LoadCompleted(object sender, NavigationEventArgs e) { try { Task.Factory.StartNew(() => { Dispatcher.BeginInvoke(new ThreadStart(delegate { try { if (WB.Source.ToString().IndexOf("status=ok") > -1) { JObject Token = WarAPI.Token(WB.Source.ToString()); MainWindow.JsonSettingsSet("token.access_token", (string)Token.SelectToken("access_token")); MainWindow.JsonSettingsSet("token.expires_at", (string)Token.SelectToken("expires_at")); MainWindow.JsonSettingsSet("token.nickname", (string)Token.SelectToken("nickname")); MainWindow.JsonSettingsSet("token.account_id", (string)Token.SelectToken("account_id")); MainWindow.JsonSettingsSet("info.user_name", (string)Token.SelectToken("nickname")); try { Task.Factory.StartNew(() => { LoaderShow(); }); Dispatcher.BeginInvoke(new ThreadStart(delegate { MainWindow.Navigator("UserProfile"); })); } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("WgOpenIdAIRUS.xaml", "WB_LoadCompleted()", ex.Message, ex.StackTrace)); } ClosePage("UserProfile"); } if (WB.Source.ToString().IndexOf("AUTH_CANCEL") > -1) { MessageBoxResult mbr = MessageBox.Show(Lang.Set("PageUser", "ActivateWarID", (string)MainWindow.JsonSettingsGet("info.language")) + Environment.NewLine + Lang.Set("PageUser", "RepeatActivation", (string)MainWindow.JsonSettingsGet("info.language")), (string)MainWindow.JsonSettingsGet("info.ProductName"), MessageBoxButton.YesNo, MessageBoxImage.Information); if (mbr == MessageBoxResult.Yes) { string uri = WarAPI.OpenID(); if (uri != null) { WB.Source = new Uri(WarAPI.OpenID()); } else { Debugging.Save("WgOpenIdAIRUS.xaml", "WB_LoadCompleted()", "WarAPI.OpenID() == null"); ClosePage(); } } else { ClosePage(); } } } catch (Exception) { } /* * Парсим форму * * * form | IgnoreCase | Singleline * <form id=js-auth-form(.*)form> * * csrfmiddlewaretoken | IgnoreCase * value=(.*) name=csrfmiddlewaretoken * * next | IgnoreCase * value=(.*) name=next * * captcha | IgnoreCase * <img class=js-captcha-image src="(.*)"> * * errors * <P class=js-form-errors-content>(.*)</P> */ try { if (!pageParsed) { Regex regexForm = new Regex("<form id=js-auth-form(.*)form>", RegexOptions.IgnoreCase | RegexOptions.Singleline); Regex regexCsrf = new Regex("value=(.*) name=csrfmiddlewaretoken", RegexOptions.IgnoreCase); Regex regexNext = new Regex("value=(.*) name=next", RegexOptions.IgnoreCase); var doc = WB.Document as HTMLDocument; IHTMLElementCollection nodes = doc.getElementsByTagName("html"); foreach (IHTMLElement elem in nodes) { var form = (HTMLHeadElement)elem; // Ищем форму Match match = regexForm.Match(form.innerHTML); while (match.Success) { // Ищем Csrf Match matchCsrf = regexCsrf.Match(match.Value.Trim()); while (matchCsrf.Success) { resultCsrf = matchCsrf.Value.Trim(); resultCsrf = resultCsrf .Replace("value=", "") .Replace(" name=csrfmiddlewaretoken", ""); matchCsrf = matchCsrf.NextMatch(); } // Ищем Next Match matchNext = regexNext.Match(match.Value.Trim()); while (matchNext.Success) { resultNext = matchNext.Value.Trim(); resultNext = resultNext .Replace("value=", "") .Replace(" name=next", ""); matchNext = matchNext.NextMatch(); } match = match.NextMatch(); } } // Подгружаем изображение UpdateCaptcha(); pageParsed = true; Task.Factory.StartNew(() => { LoaderShow(false); }); } } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("WgOpenIdAIRUS.xaml", "WB_LoadCompleted()", "Parse form", ex.Message, ex.StackTrace)); } })); }).Wait(); } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("WgOpenIdAIRUS.xaml", "WB_LoadCompleted()", ex.Message, ex.StackTrace)); } }
private void Notify() { /* * Видео */ try { if ((bool)MainWindow.JsonSettingsGet("info.video") && MainWindow.JsonSettingsGet("info.video") != null) { if (YoutubeClass.Count() > 0) { DeleteOldVideo(); // Перед выводом уведомлений проверяем даты. Все лишние удаляем foreach (var el in YoutubeClass.List) { if (show_notify) { bool show_this = true; string id_md5 = Variables.Md5(el.ID); try { string elem = MainWindow.JsonSettingsGet("youtube").ToString(); if (elem.IndexOf(id_md5) > -1) { show_this = false; } } catch (Exception) { } if (show_this) { Thread.Sleep(Convert.ToInt16(Properties.Resources.Default_Sleeping_Notify)); for (int i = 0; i < 2; i++) // Если цикл прерван случайно, то выжидаем еще 5 секунд перед повторным запуском { try { // Если запущен клиент игры - ждем 5 секунд до следующей проверки while (Process.GetProcessesByName("WorldOfTanks").Length > 0 || Process.GetProcessesByName("WoTLauncher").Length > 0) { Thread.Sleep(5000); } Thread.Sleep(Convert.ToInt16(Properties.Resources.Default_Sleeping_Notify)); } catch (Exception) { } } try { MainWindow.JsonSettingsSet("info.notify_link", el.Link); Task.Factory.StartNew(() => ShowNotify(Lang.Set("PageGeneral", "ShowVideo", lang), el.Title)); string elem = MainWindow.JsonSettingsGet("youtube").ToString(); if (elem.IndexOf(id_md5) == -1) { MainWindow.JsonSettingsSet("youtube", id_md5, "array"); } else { Thread.Sleep(Convert.ToInt16(Properties.Resources.Default_Sleeping_Notify)); } } catch (Exception ex0) { Task.Factory.StartNew(() => Debugging.Save("General.xaml", "Notify()", "YOUTUBE (Inner)", el.ToString(), ex0.Message, ex0.StackTrace, ex0.Source)); } } } } } } } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("General.xaml", "Notify()", "YOUTUBE", ex.Message, ex.StackTrace, ex.Source)); } /* * Новости */ try { if ((bool)MainWindow.JsonSettingsGet("info.news") && MainWindow.JsonSettingsGet("info.news") != null) { if (WargamingClass.Count() > 0) { foreach (var el in WargamingClass.List) { if (show_notify) { bool show_this = true; string id_md5 = Variables.Md5(el.Link); try { string elem = MainWindow.JsonSettingsGet("wargaming").ToString(); if (elem.IndexOf(id_md5) > -1) { show_this = false; } } catch (Exception) { } if (show_this) { Thread.Sleep(Convert.ToInt16(Properties.Resources.Default_Sleeping_Notify)); for (int i = 0; i < 2; i++) // Если цикл прерван случайно, то выжидаем еще 5 секунд перед повторным запуском { try { // Если запущен клиент игры - ждем 5 секунд до следующей проверки while (Process.GetProcessesByName("WorldOfTanks").Length > 0 || Process.GetProcessesByName("WoTLauncher").Length > 0) { Thread.Sleep(5000); } Thread.Sleep(Convert.ToInt16(Properties.Resources.Default_Sleeping_Notify)); } catch (Exception) { } } try { MainWindow.JsonSettingsSet("info.notify_link", el.Link); Task.Factory.StartNew(() => ShowNotify(Lang.Set("PageGeneral", "ShowNews", lang), el.Title)); string elem = MainWindow.JsonSettingsGet("wargaming").ToString(); if (elem.IndexOf(id_md5) == -1) { MainWindow.JsonSettingsSet("wargaming", Variables.Md5(el.Link), "array"); } else { Thread.Sleep(Convert.ToInt16(Properties.Resources.Default_Sleeping_Notify)); } } catch (Exception ex0) { Task.Factory.StartNew(() => Debugging.Save("General.xaml", "Notify()", "WARGAMING", el.ToString(), ex0.Message, ex0.StackTrace)); } } } } } } } catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("General.xaml", "Notify()", "WARGAMING", ex.Message, ex.StackTrace)); } }
private void cbKill_Click(object sender, RoutedEventArgs e) { MainWindow.JsonSettingsSet("settings.kill", cbKill.IsChecked, "bool"); }
private void cbAero_Click(object sender, RoutedEventArgs e) { MainWindow.JsonSettingsSet("settings.aero", cbAero.IsChecked, "bool"); }