private string FixLink(string myLink) { string link = myLink.Trim(); if (myLink == "/keeperrl_wiki/Gameplay_Guide") { link = myLink.Trim(); //Catch cases here! } if (link == "/keeperrl_wiki/") { return(""); } if (!link.EndsWith("/")) { link = link + "/"; } if (ValidLinks.Count == 0) { LoadValidLinks("C:\\keeperrl_wiki\\", ValidLinks); } link = Strings.Replace(link, " ", "_"); link = Strings.Replace(link, ":", ""); if (link == "") { return(""); } if (link == "/") { return(""); } if (link.StartsWith("/")) { link = Strings.Right(link, Strings.Len(link) - 1); } if (ValidLinks.ContainsKey(link)) { return(link); } if (link.Contains("/")) { link = Strings.Split(link, "/")[Strings.Split(link, "/").Count() - 2]; } if (ValidLinks.ContainsKey(link)) { return(link); } if (link.Contains("#")) { link = Strings.Split(link, "#")[1]; } if (ValidLinks.ContainsKey(link)) { return(link); } if (link.Contains("Category%3A_")) { link = Strings.Replace(link, "Category%3A_", "") + "_Guide"; } if (ValidLinks.ContainsKey(link)) { return(link); } if (link.Contains("Category%3A")) { link = Strings.Replace(link, "Category%3A", "") + "_Guide"; } if (ValidLinks.ContainsKey(link)) { return(link); } if (link.Contains("User%3A")) { link = "Player_" + Strings.Replace(link, "User%3A", ""); } if (ValidLinks.ContainsKey(link)) { return(link); } link = Strings.Left(link, 1).ToUpper() + Strings.Right(link, Strings.Len(link) - 1); if (ValidLinks.ContainsKey(link)) { return(link); } if (link.EndsWith("s") && !link.EndsWith("ss")) { link = Strings.Left(link, Strings.Len(link) - 1); } else if (!link.EndsWith("ss")) { link = link + "s"; } if (ValidLinks.ContainsKey(link)) { return(link); } if (link.EndsWith("s") && !link.EndsWith("ss")) { link = Strings.Left(link, Strings.Len(link) - 1); } else if (!link.EndsWith("ss")) { link = link + "s"; } if (ValidLinks.ContainsKey(link)) { return(link); } string caps = Capitalize(link); string newHeader = "---\r\ntitle: " + Strings.Replace(caps, "_", " ") + "\r\npermalink: " + caps + "/\r\nlayout: wiki\r\n" + "---" + "\r\n\nThis article has gone missing.\r\n"; if (SuggestedLinks.ContainsKey(link)) { System.IO.File.Copy("C:\\keeperrl_wiki_suggestions\\" + link + ".md", "C:\\keeperrl_wiki\\Unfinished\\" + link + ".md"); ValidLinks.Add(link, "C:\\keeperrl_wiki\\Unfinished\\" + link + ".md"); return(caps); } if (caps != link) { newHeader = newHeader + "The capitalisation of the existing article is wrong: " + link + "\r\n"; } System.IO.File.WriteAllText("C:\\keeperrl_wiki\\Missing\\" + caps + ".md", newHeader); return(caps); }
public void NewArticles() { LoadValidLinks("C:\\keeperrl_wiki\\", ValidLinks); string fil = System.IO.File.ReadAllText("C:\\keeperrl_wiki_dump\\wiki_dump.xml"); List <String> fils = Strings.Split(fil, "=", -1, CompareMethod.Text).ToList(); int f = -1; while (f < fils.Count - 1) { string nam = ""; while (nam.Contains("\n") || nam.Trim().Count() == 0 && (f < fils.Count - 1)) { try { nam = fils[f + 1]; } catch { } f++; } try { nam = "C:\\keeperrl_wiki\\" + nam.Trim(); nam = nam + ".md"; } catch { } nam = Strings.Replace(nam, "]", ""); nam = Strings.Replace(nam, "[", ""); string entry = ""; while (entry.Trim().Count() < 20) { entry = fils[f + 1]; f++; } entry = Strings.Replace(entry, "*", "\r\n-"); entry = Strings.Replace(entry, "''", "\r\n''"); try { string text = ""; if (System.IO.File.Exists(nam)) { text = System.IO.File.ReadAllText(nam); } int count = 0; while (count < Strings.Split(entry, "\r\n").Count()) { try { Application.DoEvents(); if (!text.Contains(Strings.Split(entry, "\r\n")[count])) { text = text + "\r\n" + Strings.Split(entry, "\r\n")[count]; } } catch { } count++; } string ValidLink = System.IO.Path.GetFileNameWithoutExtension(nam).Trim(); ValidLink = Strings.Join(Strings.Split(ValidLink, " "), "_"); ValidLink = Capitalize(ValidLink); if (!ValidLinks.ContainsKey(ValidLink)) { string newHeader = "---\r\ntitle: " + Strings.Replace(ValidLink, "_", " ") + "\r\npermalink: " + ValidLink + "/\r\nlayout: wiki\r\n---\r\n"; System.IO.File.WriteAllText("C:\\keeperrl_wiki_suggestions\\" + ValidLink + ".md", newHeader + "\r\n" + text); } } catch { } f++; } }