Ejemplo n.º 1
0
        private void getDownloads()
        {
            string[] filePaths = Directory.GetFiles(SharedData.currentDownloadLocation);
            int      a         = 0;
            JsonAlreadyDownloaded alreadyDownloadedList = new JsonAlreadyDownloaded();

            List <JsonDownloadUpdate> listWithFiles = new List <JsonDownloadUpdate>();

            foreach (string filePath in filePaths)
            {
                if (utilityMethods.IsMediaFile(filePath))
                {
                    string   filename = Path.GetFileName(filePath);
                    FileInfo info     = new FileInfo(filePath);
                    int      filesize = (int)(info.Length / 1048576);

                    JsonDownloadUpdate alreadyDownloaded = new JsonDownloadUpdate();
                    alreadyDownloaded.id       = a.ToString();
                    alreadyDownloaded.progress = "100";
                    alreadyDownloaded.speed    = "0";
                    alreadyDownloaded.status   = "ALREADYDOWNLOADED";
                    alreadyDownloaded.filename = filename;
                    alreadyDownloaded.filesize = filesize.ToString();
                    listWithFiles.Add(alreadyDownloaded);

                    a++;
                }
            }
            alreadyDownloadedList.alreadyDownloaded = listWithFiles;

            SharedData.AddToMessageList(JsonConvert.SerializeObject(alreadyDownloadedList, Formatting.Indented));
        }
Ejemplo n.º 2
0
        private void getDirectories(string path)
        {
            Debug.WriteLine("DEBUG-WEBSOCKETHANDLER: GETTING DIRECTORIES FROM PATH: " + path);
            try
            {
                string[] dirs = Directory.GetDirectories(path);

                List <JsonDirectory> directorieswithpath = new List <JsonDirectory>();
                foreach (string directory in dirs)
                {
                    JsonDirectory directorywithpath = new JsonDirectory();
                    directorywithpath.dirname = directory.Replace(Path.GetDirectoryName(directory) + Path.DirectorySeparatorChar, "");
                    directorywithpath.path    = directory;
                    directorieswithpath.Add(directorywithpath);
                }
                JsonDirectories tosendover = new JsonDirectories();
                tosendover.directories = directorieswithpath;
                SharedData.AddToMessageList(JsonConvert.SerializeObject(tosendover, Formatting.Indented));
            }
            catch (Exception e)
            {
                Debug.WriteLine("DEBUG-WEBSOCKETHANDLER: COULD NOT FIND DIRS IN  : " + path);
                Debug.WriteLine("DEBUG-WEBSOCKETHANDLER: " + e.ToString());
            }
        }
Ejemplo n.º 3
0
        private void downloadStatusCallback() //see below for definition of each index in this array
        {
            Object progress     = irc.getDownloadProgress("progress");
            Object speedkbps    = irc.getDownloadProgress("kbps");
            Object status       = irc.getDownloadProgress("status");
            Object filename     = irc.getDownloadProgress("filename");
            Object filesize     = irc.getDownloadProgress("size");
            long   filesizeinmb = (long.Parse(filesize.ToString().Trim()) / 1048576);

            if (status.ToString().Contains("DOWNLOADING") && status.ToString().Contains("WAITING"))
            {
                SharedData.currentlyDownloading = true;
            }
            else if (status.ToString().Contains("FAILED") || status.ToString().Contains("COMPLETED") || status.ToString().Contains("ABORTED"))
            {
                SharedData.currentlyDownloading = false;
            }

            JsonDownloadUpdate update = new JsonDownloadUpdate();

            update.id       = SharedData.currentDownloadId;
            update.progress = progress.ToString();
            update.speed    = speedkbps.ToString();
            update.status   = status.ToString();
            update.filename = filename.ToString();
            update.filesize = filesizeinmb.ToString();


            SharedData.AddToMessageList(JsonConvert.SerializeObject(update, Formatting.Indented));

            Debug.WriteLine("DEBUG-IRCHANDLER: Download upsate: " + JsonConvert.SerializeObject(update, Formatting.Indented));
        }
Ejemplo n.º 4
0
        private void chatOutputCallback(string user, string message)
        {
            try
            {
                using (StreamWriter sw = File.AppendText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ircchatlog.txt")))
                {
                    try
                    {
                        sw.WriteLine(user + " | " + message);
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }

            JsonIRCChatMessage chatmessageobj = new JsonIRCChatMessage();

            chatmessageobj.user    = user;
            chatmessageobj.message = message;
            if (SharedData.enableIrcChat)
            {
                SharedData.AddToMessageList(JsonConvert.SerializeObject(chatmessageobj, Formatting.Indented));
            }
        }
Ejemplo n.º 5
0
 public WebSocketHandler()
 {
     isLocal        = SunIRCInit.isLocal;
     irc            = SharedData.irc;
     utilityMethods = new UtitlityMethods();
     SharedData.AddToMessageList("HELLO LITTLE WEEB");
     checkMessagesToSend = new Thread(new ThreadStart(messagesToSend));
     checkMessagesToSend.Start();
 }
Ejemplo n.º 6
0
        private void getDrives()
        {
            DriveInfo[]          allDrives           = DriveInfo.GetDrives();
            List <JsonDirectory> directorieswithpath = new List <JsonDirectory>();

            foreach (DriveInfo drive in allDrives)
            {
                JsonDirectory directorywithpath = new JsonDirectory();
                directorywithpath.dirname = drive.Name;
                directorywithpath.path    = drive.Name;
                directorieswithpath.Add(directorywithpath);
            }
            JsonDirectories tosendover = new JsonDirectories();

            tosendover.directories = directorieswithpath;
            SharedData.AddToMessageList(JsonConvert.SerializeObject(tosendover, Formatting.Indented));
        }
Ejemplo n.º 7
0
        private void createDirectory(string path)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);


                string[]             dirs = Directory.GetDirectories(path);
                List <JsonDirectory> directorieswithpath = new List <JsonDirectory>();
                foreach (string dir in dirs)
                {
                    JsonDirectory directorywithpath = new JsonDirectory();
                    directorywithpath.dirname = dir.Split('\\')[dir.Split('\\').Length - 1];
                    directorywithpath.path    = dir;
                    directorieswithpath.Add(directorywithpath);
                }
                JsonDirectories tosendover = new JsonDirectories();
                tosendover.directories = directorieswithpath;
                SharedData.AddToMessageList(JsonConvert.SerializeObject(tosendover, Formatting.Indented));
            }
        }
Ejemplo n.º 8
0
        private void getIrcData()
        {
            JsonIrcUpdate update = new JsonIrcUpdate();

            update.connected        = SharedData.irc.isClientRunning();
            update.downloadlocation = SharedData.currentDownloadLocation;
            try
            {
                update.server  = SharedData.irc.newIP + ":" + SharedData.irc.newPort;
                update.user    = SharedData.irc.newUsername;
                update.channel = SharedData.irc.newChannel;
            }
            catch (Exception e)
            {
                Debug.WriteLine("WSDEBUG-WEBSOCKETHANDLER: no irc connection yet.");
                update.server  = "";
                update.user    = "";
                update.channel = "";
            }

            update.local = isLocal;
            SharedData.AddToMessageList(JsonConvert.SerializeObject(update, Formatting.Indented));
        }
Ejemplo n.º 9
0
        protected override void OnMessage(MessageEventArgs e)
        {
            var json = JsonConvert.DeserializeObject <dynamic>(e.Data);

            Debug.WriteLine("DEBUG-WEBSOCKETHANDLER: " + ((object)JsonConvert.SerializeObject(json)).ToString());

            switch (json.action.ToString())
            {
            case "get_irc_data":
                getIrcData();
                break;

            case "get_downloads":
                getDownloads();
                break;

            case "add_download":
                addDownload(json.extra);
                break;

            case "abort_download":
                abortDownload();
                break;

            case "delete_file":
                deleteDownload(json.extra);
                break;

            case "open_download_directory":
                openDownloadDirectory();
                break;

            case "set_download_directory":
                string path = json.extra.path;
                setDownloadDirectoryV2(path);
                break;

            case "open_file":
                openFile(json.extra);
                break;

            case "get_directories":
                if (json.extra.path != null)
                {
                    if (json.extra.path.ToString() == "DRIVES" || json.extra.path.ToString() == "/")
                    {
                        Debug.WriteLine("DEBUG-WEBSOCKETHANDLER: GETTING DRIVES");
                        getDrives();
                    }
                    else
                    {
                        Debug.WriteLine("DEBUG-WEBSOCKETHANDLER: GETTING DIRECTORIES");
                        string pathtoset = json.extra.path.ToString();
                        getDirectories(pathtoset);
                    }
                }
                else
                {
                    Debug.WriteLine("DEBUG-WEBSOCKETHANDLER: GETTING DRIVES");
                    getDrives();
                }
                break;

            case "create_directory":
                string pathtocreate = json.extra.path;
                createDirectory(pathtocreate);
                break;

            case "connect_irc":
                connectIrc(json.extra);
                break;

            case "disconnect_irc":
                disconnectIrc();
                break;

            case "enablechat_irc":
                SharedData.enableIrcChat = true;
                break;

            case "disablechat_irc":
                SharedData.enableIrcChat = false;
                break;

            case "getuserlist_irc":
                JsonIRCUsersList newuserlist = new JsonIRCUsersList();
                newuserlist.users = SharedData.userList;
                SharedData.AddToMessageList(JsonConvert.SerializeObject(newuserlist, Formatting.Indented));
                break;

            case "sendmessage_irc":
                SharedData.ircHandler.sendMessage(json.extra.message);
                break;

            case "close":
                closeEverything();
                break;

            default:
                Debug.WriteLine("DEBUG-WEBSOCKETHANDLER: RECEIVED UNKNOWN JSON ACTION: " + ((object)json.action).ToString());
                break;
            }
        }
Ejemplo n.º 10
0
        public void startIrc(string address, string username, string channels)
        {
            channelcount             = channels.Split(',').Length;
            shouldStopClient         = false;
            SharedData.joinedChannel = false;
            SharedData.userList.Clear();
            Debug.WriteLine("IRCDEBUG-IRCHANDLER: STARTING CONNECTION TO IRC SERVER!");
            int i = 0;

            while (!SharedData.joinedChannel && !isBussyConnecting)
            {
                isBussyConnecting = true;
                try
                {
                    irc.stopXDCCDownload();
                    irc.stopClient();
                }
                catch (Exception e) { Debug.WriteLine("DEBUG-IRCHANDLER: ERROR: Could not shut down IRC client: " + e.ToString()); }
                if (username == "")
                {
                    username = "******" + usefullstuff.RandomString(6);
                }
                irc.setupIrc(address, 6667, username, "", channels, chatOutputCallback);
                irc.setDebugCallback(debugOutputCallback);
                irc.setDownloadStatusChangeCallback(downloadStatusCallback);
                irc.setUserListReceivedCallback(userListReceivedCallback);
                irc.setCustomDownloadDir(SharedData.currentDownloadLocation);
                irc.startClient();

                int x = 3;
                while (x > 0)
                {
                    if (shouldStopClient)
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                    x--;
                }

                if (shouldStopClient)
                {
                    Debug.WriteLine("DEBUG-IRCHANDLER: SHOULD STOP RETRYING!");
                    shouldStopClient = false;
                    break;
                }


                if (!SharedData.joinedChannel)
                {
                    Debug.WriteLine("DEBUG-IRCHANDLER: DID NOT JOIN CHANNEL, RETRY!");
                }
                else
                {
                    isConnected = true;
                    JsonIrcUpdate update = new JsonIrcUpdate();
                    update.connected        = true;
                    update.downloadlocation = SharedData.currentDownloadLocation;
                    update.server           = irc.newIP + ":" + irc.newPort;
                    update.user             = irc.newUsername;
                    update.channel          = irc.newChannel;
                    update.local            = isLocal;
                    SharedData.AddToMessageList(JsonConvert.SerializeObject(update, Formatting.Indented));
                    break;
                }
                i++;
                if (i > 10)
                {
                    Debug.WriteLine("DEBUG-IRCHANDLER: I AM DONE TRYING TO CONNECT!");
                    break;
                }
                else
                {
                    Debug.WriteLine("DEBUG-IRCHANDLER: NOT CONNECTED TO IRC SERVER");
                }
            }
            isBussyConnecting = false;
        }