private void FeedItemButton_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; MCPatchNotesItem item = button.DataContext as MCPatchNotesItem; LoadChangelog(item); }
private void FeedItemButton_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; MCPatchNotesItem item = button.DataContext as MCPatchNotesItem; string header_title = string.Format("{0} {1}", (item.isBeta ? "Beta" : "Release"), item.Version); ConfigManager.MainThread.MainWindowOverlayFrame.Content = new ChangelogPreviewPage(item.Content, header_title, item.Url); }
private void AddPatch(MCPatchNotesItem patch) { if (App.Current == null) { return; } App.Current.Dispatcher.BeginInvoke((Action) delegate() { PatchNotes.Add(patch); PatchNotes.Sort((a, b) => { return(b.Version.CompareTo(a.Version)); }); }); }
public bool Filter_PatchNotes(object obj) { MCPatchNotesItem v = obj as MCPatchNotesItem; if (v != null) { if (!BetasCheckBox.IsChecked.Value && v.isBeta) { return(false); } else if (!ReleasesCheckBox.IsChecked.Value && !v.isBeta) { return(false); } else { return(true); } } else { return(false); } }
public static bool Filter_PatchNotes(object obj) { MCPatchNotesItem v = obj as MCPatchNotesItem; if (v != null) { if (!Properties.LauncherSettings.Default.ShowBetas && v.isBeta) { return(false); } else if (!Properties.LauncherSettings.Default.ShowReleases && !v.isBeta) { return(false); } else { return(true); } } else { return(false); } }
public void DownloadFeedbackPatchNotes() { ClearPatchList(); HtmlWeb web = new HtmlWeb(); web.BrowserTimeout = TimeSpan.FromSeconds(10); string base_url = "https://feedback.minecraft.net"; List <FeedbackParams> checklist = new List <FeedbackParams>() { new FeedbackParams() { _branch = "release", _suburl = "/hc/en-us/sections/360001186971", keyword = "Bedrock" }, new FeedbackParams() { _branch = "beta", _suburl = "/hc/en-us/sections/360001185332", keyword = "Windows 10" } }; foreach (var branch in checklist) { bool isFinished = false; int currentPage = 1; string furl; HtmlDocument tree; IEnumerable <HtmlNode> vers = new List <HtmlNode>(); while (!isFinished) { furl = base_url + branch._suburl + string.Format("?page={0}#articles", currentPage); try { tree = web.Load(furl); } catch { isFinished = true; continue; } vers = NodeSearch(tree.DocumentNode, (x => x.HasClass("article-list-link"))); if (vers == null || vers.Count() == 0) { isFinished = true; continue; } foreach (HtmlNode link in vers) { string text = link.InnerText; if (text.Contains(branch.keyword)) { string item_url = base_url + link.GetAttributeValue("href", string.Empty); try { var current_result = web.Load(item_url); //var stylesheets = GetStylesheets(current_result); var content = OptimizeFeedbackPage(current_result, base_url); bool isBeta = branch._branch == "beta"; if (content != null) { MCPatchNotesItem item = new MCPatchNotesItem() { Version = GetVersion(text), isBeta = isBeta, Url = item_url, ImageUrl = GetPatchNotesCoverImage(content, isBeta), PublishingDateString = GetPublishedDate(current_result).ToString(), Content = string.Format(HTMLFormat, UpdateHTMLHeader(new List <string>()), content.InnerHtml), }; AddPatch(item); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } } } currentPage += 1; } } System.Version GetVersion(string title) { Regex pattern = new Regex("\\d+(\\.\\d+)+"); Match m = pattern.Match(title); string constructed_version = m.Value; bool valid_version = System.Version.TryParse(constructed_version, out System.Version current_version); if (valid_version) { return(current_version); } else { return(null); } } }
public static void LoadChangelog(MCPatchNotesItem item) { string header_title = string.Format("{0} {1}", (item.isBeta ? "Beta" : "Release"), item.Version); ConfigManager.MainThread.SetOverlayFrame(new ChangelogPreviewPage(item.Content, header_title, item.Url)); }
public void DownloadFeedbackPatchNotes() { ClearPatchList(); HtmlWeb web = new HtmlWeb(); string base_url = "https://feedback.minecraft.net/"; List <FeedbackParams> checklist = new List <FeedbackParams>() { new FeedbackParams() { _branch = "release", _suburl = "/hc/en-us/sections/360001186971", keyword = "Bedrock" }, new FeedbackParams() { _branch = "beta", _suburl = "/hc/en-us/sections/360001185332", keyword = "Windows 10" } }; foreach (var branch in checklist) { bool isFinished = false; int currentPage = 1; string furl; HtmlDocument tree; IEnumerable <HtmlNode> vers = new List <HtmlNode>(); while (!isFinished) { furl = base_url + branch._suburl + string.Format("?page={0}", currentPage); try { tree = web.Load(furl); } catch { isFinished = true; continue; } vers = NodeSearch(tree.DocumentNode, (x => x.HasClass("article-list-link"))); if (vers == null || vers.Count() == 0) { isFinished = true; continue; } foreach (HtmlNode link in vers) { string text = link.InnerText; if (text.Contains(branch.keyword)) { string item_url = base_url + link.GetAttributeValue("href", string.Empty); try { var current_result = web.Load(item_url); var content = OptimizeFeedbackPage(current_result, base_url); bool isBeta = branch._branch == "beta"; if (content != null) { MCPatchNotesItem item = new MCPatchNotesItem() { Version = GetVersion(text), isBeta = isBeta, Url = item_url, ImageUrl = (isBeta ? MCPatchNotesItem.FallbackImageURL_Dev : MCPatchNotesItem.FallbackImageURL), PublishingDateString = GetPublishedDate(current_result), Content = string.Format(HTMLFormat, HTMLHeader, content.InnerHtml), }; AddPatch(item); } } catch (Exception ex) { Console.WriteLine(ex); } } } currentPage += 1; } } string GetPublishedDate(HtmlDocument doc) { string postedDate = string.Empty; Func <HtmlNode, bool> description_meta = (x => x.Name == "meta" && x.HasAttributes); foreach (var sub_node in NodeSearch(doc.DocumentNode, description_meta)) { string property = sub_node.GetAttributeValue("property", ""); string content = sub_node.GetAttributeValue("content", ""); if (property == "og:description") { if (content.StartsWith("Posted:")) { string constructed_date = content.Split(new[] { '\r', '\n' }).FirstOrDefault().Replace("Posted:", string.Empty); constructed_date = RemoveDaySuffixes(constructed_date); if (DateTime.TryParse(constructed_date, out DateTime extractedDate)) { postedDate = extractedDate.ToString(); } string RemoveDaySuffixes(string date_string) { string result = Regex.Replace(date_string, @"\b(\d+)(?:st|nd|rd|th)\b", "$1"); return(result); } } } } return(postedDate); } System.Version GetVersion(string title) { Regex pattern = new Regex("\\d+(\\.\\d+)+"); Match m = pattern.Match(title); string constructed_version = m.Value; bool valid_version = System.Version.TryParse(constructed_version, out System.Version current_version); if (valid_version) { return(current_version); } else { return(null); } } }
private void DownloadWikiPatchNotes() { ClearPatchList(); bool first_request = true; string cmcontinue = null; HtmlWeb web = new HtmlWeb(); while (first_request || cmcontinue != null) { try { string ListRequestURL = string.Format("{0}?{1}{2}", MCWikiAPI, string.Join("&", Pages_Params), cmcontinue); string ListRequestResult = GetResult(ListRequestURL); RootObject ListRequestData = JsonConvert.DeserializeObject <RootObject>(ListRequestResult); List <Val> CategoryMembers = ListRequestData.query.categorymembers; foreach (var member in CategoryMembers) { var patch = GetPatchNotesItem(member.title, web); if (patch.Version != null) { AddPatch(patch); } } if (ListRequestData.@continue != null) { cmcontinue = [email protected]; } } catch (Exception ex) { Console.WriteLine(ex); } if (first_request) { first_request = false; } } //Sub-Functions MCPatchNotesItem GetPatchNotesItem(string title, HtmlWeb _web) { string url = MCWiki + title; HtmlNode node = GetPatchNotesNode(url, _web); MCPatchNotesItem item = new MCPatchNotesItem() { Url = url, isBeta = GetPatchNotesBetaState(title), Version = GetPatchNotesVersion(title), ImageUrl = GetWikiPageImage(node), Content = string.Format(HTMLFormat, HTMLHeader, OptimizeWikiPage(node).InnerHtml), }; return(item); } bool GetPatchNotesBetaState(string title) { if (title.Contains("Beta", StringComparison.OrdinalIgnoreCase)) { return(true); } else { return(false); } } System.Version GetPatchNotesVersion(string title) { string BedrockEditionString = "Bedrock Edition "; string BetaString = "Beta "; StringComparison Comparison = StringComparison.OrdinalIgnoreCase; string constructed_version = title; constructed_version = constructed_version.Remove(BedrockEditionString, Comparison); constructed_version = constructed_version.Remove(BetaString, Comparison); bool valid_version = System.Version.TryParse(constructed_version, out System.Version current_version); if (valid_version) { return(current_version); } else { return(null); } } string GetWikiPageImage(HtmlNode current_node) { //Get Image var image_tag = current_node.DescendantsAndSelf().ToList().Where(x => x.HasClass("infobox-imagearea")).FirstOrDefault(); if (image_tag != null) { var image = image_tag.Descendants("img").FirstOrDefault(); if (image != null) { return(image.GetAttributeValue("src", MCPatchNotesItem.FallbackImageURL)); } } return(MCPatchNotesItem.FallbackImageURL); } HtmlNode GetPatchNotesNode(string url, HtmlWeb _web) { var current_result = _web.Load(url); var content_selector = "//*[@id=\"mw-content-text\"]/div"; return(current_result.DocumentNode.SelectNodes(content_selector).FirstOrDefault()); } }
public static void LoadChangelog(MCPatchNotesItem item) { string header_title = string.Format("{0} {1}", (item.isBeta ? "Beta" : "Release"), item.Version); ViewModels.LauncherModel.Default.SetOverlayFrame(new ChangelogPreviewPage(item.Content, header_title, item.Url)); }