public static void downloaderLogic() { while (!closeBackend) { if (!currentlyDownloading) { if (downloadList.Count > 0) { dlData data = downloadList[0]; currentDownloadId = data.dlId; bool succes = false; try { succes = true; irc.sendMessage("/msg " + data.dlBot + " xdcc send #" + data.dlPack); Thread.Sleep(1000); } catch { currentlyDownloading = false; Console.WriteLine("NOT CONNECTED TO IRC, CAN'T DOWNLOAD FILE :("); } if (succes) { currentlyDownloading = true; downloadList.Remove(data); server.SendGlobalMessage("DOWNLOADSTARTED"); } } } Thread.Sleep(500); } }
public static void WsMessageReceived(object sender, WebSocketEventArgs args) { string msg = args.Message; Console.WriteLine(msg); if (msg.Contains("AreWeJoined")) { if (joinedChannel) { server.SendGlobalMessage("IrcConnected"); } } if (msg.Contains("GetAlreadyDownloadedFiles")) { string[] filePaths = Directory.GetFiles(currentDownloadLocation); string arrayToSend = "ALREADYDOWNLOADED"; int a = 0; foreach (string filePath in filePaths) { string filename = Path.GetFileName(filePath); arrayToSend = arrayToSend + "," + a.ToString() + ":100:0:COMPLETED:" + filename; a++; } server.SendGlobalMessage(arrayToSend); } if (msg.Contains("AddToDownloads")) { Console.WriteLine("DOWNLOAD REQUEST:" + msg); if (msg.Contains(",")) { string[] bulkDownloads = msg.Split(','); foreach (string download in bulkDownloads) { string[] data = download.Split(':'); try { string dlId = data[0]; string dlPack = data[1]; string dlBot = data[2]; Console.WriteLine("ADDING TO DOWLOADS: " + dlId + " /msg " + dlBot + " xdcc send #" + dlPack); dlData d = new dlData(); d.dlId = dlId; d.dlBot = dlBot; d.dlPack = dlPack; downloadList.Add(d); } catch { } } } else { string[] data = msg.Split(':'); string dlId = data[1]; string dlPack = data[2]; string dlBot = data[3]; Console.WriteLine("ADDING TO DOWLOADS: " + dlId + " /msg " + dlBot + " xdcc send #" + dlPack); dlData d = new dlData(); d.dlId = dlId; d.dlBot = dlBot; d.dlPack = dlPack; downloadList.Add(d); } } if (msg.Contains("AbortDownload")) { try { irc.stopXDCCDownload(); } catch { Console.WriteLine("tried to stop download but there isn't anything downloading or no connection to irc"); } } if (msg.Contains("DeleteDownload")) { string dlId = msg.Split(':')[1]; string fileName = msg.Split(':')[2]; if (currentDownloadId == dlId) { try { irc.stopXDCCDownload(); } catch { Console.WriteLine("tried to stop download but there isn't anything downloading or no connection to irc"); } } else { int index = 0; foreach (dlData data in downloadList) { if (data.dlId == dlId) { downloadList.Remove(data); break; } index++; } try { File.Delete(currentDownloadLocation + "\\" + fileName); } catch (IOException e) { Console.WriteLine("We've got a problem :( -> " + e.ToString()); } } } if (msg.Contains("OpenDirectory")) { Process.Start(currentDownloadLocation); } if (msg.Contains("OpenFileDialog")) { Console.WriteLine("OPENING FILE D DIALOG"); Thread openfdwithoutblocking = new Thread(new ThreadStart(delegate { Thread openfd = new Thread(new ThreadStart(setDlDir)); openfd.TrySetApartmentState(ApartmentState.STA); openfd.Start(); openfd.Join(); })); openfdwithoutblocking.Start(); } if (msg.Contains("PlayFile")) { string dlId = msg.Split(':')[1]; string fileName = msg.Split(':')[2].Trim(); string fileLocation = Path.Combine(currentDownloadLocation, fileName); try { Console.WriteLine("Trying to open file: " + fileLocation); Thread player = new Thread(new ThreadStart(delegate { Process.Start(fileLocation); })); player.Start(); } catch (Exception e) { Console.WriteLine("We've got another problem: " + e.ToString()); } } if (msg.Contains("GetCurrentDir")) { server.SendGlobalMessage("CurrentDir^" + currentDownloadLocation); } if (msg.Contains("CLOSE")) { Console.WriteLine("CLOSING SHIT"); closeBackend = true; } }