private void frmMain_Load(object sender, EventArgs e) { Properties.Settings.Default.runningUpdate = false; tcApp.TabPages.RemoveAt(1); if (YCSettings.Default.updaterEnabled) { checkUpdates = new Thread(() => { var cV = Updater.getCloudVersion(); if (Updater.isUpdateAvailable(cV)) { if (MessageBox.Show("An update is available. \nNew verison: " + cV.ToString() + " | Your version: " + Properties.Settings.Default.currentVersion.ToString() + "\n\nWould you like to update?", "YChanEx", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { Updater.createUpdaterStub(cV); Updater.runUpdater(); } this.Invoke((MethodInvoker)(() => mUpdateAvailable.Enabled = true)); this.Invoke((MethodInvoker)(() => mUpdateAvailable.Visible = true)); } this.Invoke((MethodInvoker)(() => checkUpdates.Abort())); }); checkUpdates.Start(); } if (YCSettings.Default.firstStart) { FirstStart tFirstStart = new FirstStart(); // if first start, show first start message if (tFirstStart.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Settings tSettings = new Settings(); tSettings.ShowDialog(); tSettings.Close(); tSettings.Dispose(); } else { Environment.Exit(0); } tFirstStart.Close(); tFirstStart.Dispose(); GC.Collect(); } nfTray.ContextMenu = mTray; if (File.Exists(System.Windows.Forms.Application.StartupPath + @"\ycxu.bat")) { hasUpdated = true; File.Delete(System.Windows.Forms.Application.StartupPath + @"\ycxu.bat"); } else { hasUpdated = false; } if (YCSettings.Default.trayIcon) { nfTray.Visible = true; } else { nfTray.Visible = false; } scnTimer.Enabled = false; // disable timer scnTimer.Interval = YCSettings.Default.scannerTimer; // set interval scnTimer.Tick += new EventHandler(this.scan); // when Timer ticks call scan() if (YCSettings.Default.saveOnClose) // if enabled load URLs from file { string[] URLs; string boards = Controller.loadURLs(true); if (boards != "") { URLs = boards.Split('\n'); for (int i = 0; i < URLs.Length - 1; i++) { ImageBoard newImageboard = Controller.createNewIMB(URLs[i], true); // and add them lbBoards.Items.Add(URLs[i]); clBoards.Add(newImageboard); } scnTimer.Enabled = true; // activate the timer scan(null, null); // and start scanning } string threads = Controller.loadURLs(false); // load threads if (threads != "") { URLs = threads.Split('\n'); for (int i = 0; i < URLs.Length - 1; i++) { ImageBoard newImageboard = Controller.createNewIMB(URLs[i], false); if (newImageboard == null) { MessageBox.Show(URLs[i]); } else { lbThreads.Items.Add(URLs[i]); clThreads.Add(newImageboard); Thread nIMB = new Thread(delegate() { newImageboard.download(); }); thrThreads.Add(nIMB); thrThreads.Last().Start(); if (!scnTimer.Enabled) { scnTimer.Enabled = true; scan(null, null); } } } } } }
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()) { DeadThreadURL = new UriBuilder(lbThreads.Items[k].ToString()).Uri; string ReturnID = DeadThreadURL.Segments[3]; string ReturnBoard = DeadThreadURL.Segments[1].Replace("/", ""); // MessageBox.Show(ReturnID); string deadAction = ""; if (YCSettings.Default.threadDeadAction == 1) { deadAction = "\nClick here to copy archive link"; } else if (YCSettings.Default.threadDeadAction == 2) { deadAction = "\nClick here to open archive link"; } else if (YCSettings.Default.threadDeadAction == 3) { deadAction = "\nClick here to copy original link"; } else if (YCSettings.Default.threadDeadAction == 4) { deadAction = "\nClick here to open original link"; } else if (YCSettings.Default.threadDeadAction == 5) { deadAction = "\nClick here to copy thread ID"; } else if (YCSettings.Default.threadDeadAction == 6) { deadAction = "\nClick here to copy download folder path"; } else if (YCSettings.Default.threadDeadAction == 7) { deadAction = "\nClick here to open download folder path"; } is404 = true; nfTray.BalloonTipTitle = "Thread 404'd"; nfTray.BalloonTipText = "Thread " + ReturnID.Replace(".html", "") + " on /" + ReturnBoard + "/ has 404'd." + deadAction; nfTray.BalloonTipIcon = ToolTipIcon.Error; nfTray.Icon = Properties.Resources.YChanEx404; nfTray.ShowBalloonTip(15000); 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) { Debug.Print(exep.ToString()); } for (int l = 0; l < Threads.Length; l++) { ImageBoard newImageboard = Controller.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) { Debug.Print(exp.ToString()); // MessageBox.Show(exp.Message + " k: " + x); } }); thrThreads[k].Name = clThreads[k].getURL(); thrThreads[k].Start(); } } GC.Collect(); }); Scanner.Start(); } }
private void downloadURL(string url, bool silentDownload) { if (!Controller.isSupported(url)) { MessageBox.Show("Please enter a supported site URL (Check the Github page for a list)"); return; } bool board = (tcApp.SelectedIndex == 1); // Board Tab is open -> board=true; Thread tab -> board=false ImageBoard newImageboard = Controller.createNewIMB(url.Trim(), board); if (url.StartsWith("fchan.us/")) { url = url.Replace("fchan.us/", "http://fchan.us/"); } if (newImageboard != null) { if (isUnique(newImageboard.getURL(), clThreads)) { if (board) { lbBoards.Items.Add(url); clBoards.Add(newImageboard); } else { lbThreads.Items.Add(url); clThreads.Add(newImageboard); addToHistory(url); } } else { MessageBox.Show("URL is already in queue!"); return; } } else { MessageBox.Show("Corrupt URL, unsupported website or not a board/thread!"); return; } if (!board) { Thread nIMB = new Thread(delegate() { newImageboard.download(); }); nIMB.Name = newImageboard.getURL(); thrThreads.Add(nIMB); thrThreads[thrThreads.Count - 1].Start(); } if (!scnTimer.Enabled) { scnTimer.Enabled = true; } scan(null, null); if (YCSettings.Default.saveOnClose) { Controller.saveURLs(clBoards, clThreads); } }