public static void loadSettings() // read settings from XML { if (File.Exists(Application.CommonAppDataPath + "\\YCHAN2.xml")) { XmlDocument doc = new XmlDocument(); doc.Load(Application.CommonAppDataPath + "\\YCHAN2.xml"); XmlNode NodTimer = doc.DocumentElement.SelectSingleNode("/data/timer"); string Time = NodTimer.InnerText; XmlNode NodPath = doc.DocumentElement.SelectSingleNode("/data/path"); string Path = NodPath.InnerText; XmlNode NodLoadhtml = doc.DocumentElement.SelectSingleNode("/data/loadhtml"); bool html = (NodLoadhtml.InnerText == "1"); XmlNode NodSaveOnClose = doc.DocumentElement.SelectSingleNode("/data/saveonclose"); bool sav; if (NodSaveOnClose == null) { sav = false; } else { sav = (NodSaveOnClose.InnerText == "1"); } XmlNode NodWarnOnClose = doc.DocumentElement.SelectSingleNode("/data/warnonclose"); bool warn; if (NodWarnOnClose == null) { warn = true; } else { warn = (NodWarnOnClose.InnerText == "1"); } XmlNode NodMinimizeToTray = doc.DocumentElement.SelectSingleNode("/data/minimizetotray"); bool tray; if (NodMinimizeToTray == null) { tray = true; } else { tray = (NodMinimizeToTray.InnerText == "1"); } int iTime = 10000; if (IsDigitsOnly(Time)) { iTime = int.Parse(Time); } General.setSettings(Path, iTime, html, sav, tray, warn); } else { firstStart = true; // No settings file, General.setSettings("C:\\", 10000, false, false, true, true); // set default values } if (!File.Exists(Application.CommonAppDataPath + "\\2.3")) // Old settings file, new { firstStart = true; // version, first start, File.Create(Application.CommonAppDataPath + "\\2.3").Dispose(); // create file to save version } }
private void scan(object sender, EventArgs e) { /*#if DEBUG * MessageBox.Show("Threads: (" + thrThreads.Count + ") (" + clThreads.Count +")"); * MessageBox.Show("Boards: (" + thrBoards.Count + ") (" + clBoards.Count +")"); #endif*/ if (Scanner == null || !Scanner.IsAlive) { Scanner = new Thread(delegate() { for (int k = 0; k < clThreads.Count; k++) { if (clThreads[k].isGone()) { clThreads.RemoveAt(k); thrThreads.RemoveAt(k); lbThreads.Invoke((MethodInvoker) delegate { lbThreads.Items.RemoveAt(k); }); } } for (int k = 0; k < clBoards.Count; k++) { string[] Threads = { }; try { Threads = clBoards[k].getThreads().Split('\n'); } catch (Exception exep) { } for (int l = 0; l < Threads.Length; l++) { Imageboard newImageboard = General.createNewIMB(Threads[l], false); if (newImageboard != null && isUnique(newImageboard.getURL(), clThreads)) { lbThreads.Invoke((MethodInvoker)(() => { lbThreads.Items.Add(Threads[l]); })); clThreads.Add(newImageboard); Thread nIMB = new Thread(delegate() { newImageboard.download(); }); nIMB.Name = newImageboard.getURL(); thrThreads.Add(nIMB); thrThreads[thrThreads.Count - 1].Start(); } } } for (int k = 0; k < clThreads.Count; k++) { if (!thrThreads[k].IsAlive) { /* MessageBox.Show("Down: " + k); */ thrThreads[k] = new Thread(delegate() { int x = k; try { clThreads[k - 1].download(); // why } catch (Exception exp) { // MessageBox.Show(exp.Message + " k: " + x); } }); thrThreads[k].Name = clThreads[k].getURL(); thrThreads[k].Start(); } } }); Scanner.Start(); } }
private void downloadHTMLPage() { List <string> thumbs = new List <string>(); string htmlPage = ""; string str = ""; string baseURL = "//i.4cdn.org/" + getURL().Split('/')[3] + "/"; string JURL = "http://a.4cdn.org/" + getURL().Split('/')[3] + "/thread/" + getURL().Split('/')[5] + ".json"; try { //Add a UserAgent to prevent 403 WebClient web = new WebClient(); web.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"; htmlPage = web.DownloadString(this.getURL()); //Prevent the html from being destroyed by the anti adblock script htmlPage = htmlPage.Replace("f=\"to\"", "f=\"penis\""); string json = web.DownloadString(JURL); byte[] bytes = Encoding.ASCII.GetBytes(json); using (var stream = new MemoryStream(bytes)) { var quotas = new XmlDictionaryReaderQuotas(); var jsonReader = JsonReaderWriterFactory.CreateJsonReader(stream, quotas); var xml = XDocument.Load(jsonReader); str = xml.ToString(); } XmlDocument doc = new XmlDocument(); doc.LoadXml(str); XmlNodeList xmlTim = doc.DocumentElement.SelectNodes("/root/posts/item/tim"); XmlNodeList xmlExt = doc.DocumentElement.SelectNodes("/root/posts/item/ext"); for (int i = 0; i < xmlExt.Count; i++) { string old = baseURL + xmlTim[i].InnerText + xmlExt[i].InnerText; string rep = xmlTim[i].InnerText + xmlExt[i].InnerText; htmlPage = htmlPage.Replace(old, rep); //Save thumbs for files that need it if (rep.Split('.')[1] == "webm" /*|| rep.Split('.')[1] == ""*/) { old = "//t.4cdn.org/" + getURL().Split('/')[3] + "/" + xmlTim[i].InnerText + "s.jpg"; thumbs.Add("http:" + old); htmlPage = htmlPage.Replace("//i.4cdn.org/" + getURL().Split('/')[3] + "/" + xmlTim[i].InnerText, "thumb/" + xmlTim[i].InnerText); } else { string thumbName = rep.Split('.')[0] + "s"; htmlPage = htmlPage.Replace(thumbName + ".jpg", rep.Split('.')[0] + "." + rep.Split('.')[1]); htmlPage = htmlPage.Replace("/" + thumbName, thumbName); htmlPage = htmlPage.Replace("//i.4cdn.org/" + getURL().Split('/')[3] + "/" + xmlTim[i].InnerText, xmlTim[i].InnerText); } htmlPage = htmlPage.Replace("/" + rep, rep); } htmlPage = htmlPage.Replace("=\"//", "=\"http://"); //Save thumbs for files that need it for (int i = 0; i < thumbs.Count; i++) { General.dlTo(thumbs[i], this.SaveTo + "\\thumb"); } if (!string.IsNullOrWhiteSpace(htmlPage)) { File.WriteAllText(this.SaveTo + "\\Thread.html", htmlPage); } } catch (WebException webEx) { throw webEx; } catch (UnauthorizedAccessException ex) { throw ex; } }