Beispiel #1
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));
        }
Beispiel #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());
            }
        }
Beispiel #3
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));
        }
Beispiel #4
0
 public WebSocketHandler()
 {
     isLocal        = LittleWeebInit.isLocal;
     irc            = SharedData.irc;
     utilityMethods = new UtitlityMethods();
     SharedData.AddToMessageList("HELLO LITTLE WEEB");
     checkMessagesToSend = new Thread(new ThreadStart(messagesToSend));
     checkMessagesToSend.Start();
 }
Beispiel #5
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));
        }
Beispiel #6
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));
            }
        }
Beispiel #7
0
        private void setDownloadDirectoryV2(string path)
        {
            try
            {
                // Debug.WriteLine("DEBUG-WEBSOCKETHANDLER: opening file dialog.");
                SharedData.currentDownloadLocation = path;
                SharedData.irc.setCustomDownloadDir(SharedData.currentDownloadLocation);
                SharedData.settings.saveSettings();

                SharedData.httpserver.downloadDir = SharedData.currentDownloadLocation;

                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));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("DEBUG-WEBSOCKETHANDLER:ERROR: " + ex.ToString());
            }
        }
Beispiel #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));
        }
Beispiel #9
0
        public void startIrc(string address, string username, string channels)
        {
            SharedData.joinedChannel = false;
            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
                {
                    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;
        }