Exemple #1
0
        public bool GetFileListOld(string hash, ref List <TorrentFile> torFiles)
        {
            torFiles = new List <TorrentFile>();

            if (!ValidCredentials())
            {
                BaseConfig.MyAnimeLog.Write("Credentials are not valid for uTorrent");
                return(false);
            }

            try
            {
                string url    = string.Format(urlTorrentFileList, address, port, token, hash);
                string output = GetWebResponse(url);
                if (output.Length == 0)
                {
                    return(false);
                }

                TorrentFileList fileList = JSONHelper.Deserialize <TorrentFileList>(output);

                // find the 2nd instance of the "["
                int pos = output.IndexOf("[", 0);
                if (pos > 0)
                {
                    pos = output.IndexOf("[", pos + 1);
                }
                if (pos > 0)
                {
                    string output2 = output;
                    output2 = output2.Substring(pos, output2.Length - pos);
                    //BaseConfig.MyAnimeLog.Write("output2: {0}", output2);
                    output2 = output2.Replace("[", "");
                    output2 = output2.Replace("]", "");
                    output2 = output2.Replace("{", "");
                    output2 = output2.Replace("}", "");
                    output2 = output2.Replace("\r", "");
                    output2 = output2.Replace("\n", "");
                    BaseConfig.MyAnimeLog.Write("output2: {0}", output2);

                    DataTable dtDetails = CsvParser.Parse(output2);
                    // there will be 4 columns per row

                    //BaseConfig.MyAnimeLog.Write("dtDetails.Columns.Count: {0}", dtDetails.Columns.Count.ToString());
                    //BaseConfig.MyAnimeLog.Write("dtDetails.Rows.Count: {0}", dtDetails.Rows.Count.ToString());

                    int i = 0;
                    while (i < dtDetails.Columns.Count)
                    {
                        TorrentFile tf = new TorrentFile();
                        tf.FileName   = dtDetails.Rows[0][i].ToString();
                        tf.FileSize   = long.Parse(dtDetails.Rows[0][i + 1].ToString());
                        tf.Downloaded = long.Parse(dtDetails.Rows[0][i + 2].ToString());
                        tf.Priority   = long.Parse(dtDetails.Rows[0][i + 3].ToString());

                        torFiles.Add(tf);

                        i += 4;
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write("Error in GetTorrentList: {0}", ex.ToString());
                return(false);
            }
        }
Exemple #2
0
        public bool GetFileListOld(string hash, ref List<TorrentFile> torFiles)
        {
            torFiles = new List<TorrentFile>();

            if (!ValidCredentials())
            {
                BaseConfig.MyAnimeLog.Write("Credentials are not valid for uTorrent");
                return false;
            }

            try
            {
                string url = string.Format(urlTorrentFileList, address, port, token, hash);
                string output = GetWebResponse(url);
                if (output.Length == 0) return false;

                TorrentFileList fileList = JSONHelper.Deserialize<TorrentFileList>(output);

                // find the 2nd instance of the "["
                int pos = output.IndexOf("[", 0);
                if (pos > 0) pos = output.IndexOf("[", pos + 1);
                if (pos > 0)
                {
                    string output2 = output;
                    output2 = output2.Substring(pos, output2.Length - pos);
                    //BaseConfig.MyAnimeLog.Write("output2: {0}", output2);
                    output2 = output2.Replace("[", "");
                    output2 = output2.Replace("]", "");
                    output2 = output2.Replace("{", "");
                    output2 = output2.Replace("}", "");
                    output2 = output2.Replace("\r", "");
                    output2 = output2.Replace("\n", "");
                    BaseConfig.MyAnimeLog.Write("output2: {0}", output2);

                    DataTable dtDetails = CsvParser.Parse(output2);
                    // there will be 4 columns per row

                    //BaseConfig.MyAnimeLog.Write("dtDetails.Columns.Count: {0}", dtDetails.Columns.Count.ToString());
                    //BaseConfig.MyAnimeLog.Write("dtDetails.Rows.Count: {0}", dtDetails.Rows.Count.ToString());

                    int i = 0;
                    while (i < dtDetails.Columns.Count)
                    {
                        TorrentFile tf = new TorrentFile();
                        tf.FileName = dtDetails.Rows[0][i].ToString();
                        tf.FileSize = long.Parse(dtDetails.Rows[0][i + 1].ToString());
                        tf.Downloaded = long.Parse(dtDetails.Rows[0][i + 2].ToString());
                        tf.Priority = long.Parse(dtDetails.Rows[0][i + 3].ToString());

                        torFiles.Add(tf);

                        i += 4;
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write("Error in GetTorrentList: {0}", ex.ToString());
                return false;
            }
        }
Exemple #3
0
        private void ShowContextMenuTorrentFiles(TorrentFile tor, int idx)
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (dlg == null)
                return;

            dlg.Reset();
            dlg.SetHeading(tor.FileName);

            dlg.Add("Priority - High");
            dlg.Add("Priority - Medium");
            dlg.Add("Priority - Low");
            dlg.Add("Priority - Don't Download");
            dlg.DoModal(GUIWindowManager.ActiveWindow);

            switch (dlg.SelectedLabel)
            {
                case 0:
                    MainWindow.uTorrent.FileSetPriority(curTorrent.Hash, idx, TorrentFilePriority.High);
                    ShowPageTorrentFiles();
                    break;

                case 1:
                    MainWindow.uTorrent.FileSetPriority(curTorrent.Hash, idx, TorrentFilePriority.Medium);
                    ShowPageTorrentFiles();
                    break;

                case 2:
                    MainWindow.uTorrent.FileSetPriority(curTorrent.Hash, idx, TorrentFilePriority.Low);
                    ShowPageTorrentFiles();
                    break;

                case 3:
                    MainWindow.uTorrent.FileSetPriority(curTorrent.Hash, idx, TorrentFilePriority.DontDownload);
                    ShowPageTorrentFiles();
                    break;

            }
        }
Exemple #4
0
        public bool GetFileList(string hash, ref List<TorrentFile> torFiles)
        {
            torFiles = new List<TorrentFile>();

            if (!ValidCredentials())
            {
                BaseConfig.MyAnimeLog.Write("Credentials are not valid for uTorrent");
                return false;
            }

            try
            {
                string url = string.Format(urlTorrentFileList, address, port, token, hash);
                string output = GetWebResponse(url);
                if (output.Length == 0) return false;

                TorrentFileList fileList = JSONHelper.Deserialize<TorrentFileList>(output);

                if (fileList != null && fileList.files != null && fileList.files.Length > 1)
                {
                    object[] actualFiles = fileList.files[1] as object[];
                    if (actualFiles == null) return false;

                    foreach (object obj in actualFiles)
                    {
                        object[] actualFile = obj as object[];
                        if (actualFile == null) continue;

                        TorrentFile tf = new TorrentFile();
                        tf.FileName = actualFile[0].ToString();
                        tf.FileSize = long.Parse(actualFile[1].ToString());
                        tf.Downloaded = long.Parse(actualFile[2].ToString());
                        tf.Priority = long.Parse(actualFile[3].ToString());

                        torFiles.Add(tf);
                    }

                }

                return true;
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write("Error in GetTorrentList: {0}", ex.ToString());
                return false;
            }
        }
Exemple #5
0
        private void DisplayTorrentFileDetails(TorrentFile tor)
        {
            clearGUIProperty("TorrentFile.Name");
            clearGUIProperty("TorrentFile.Size");
            clearGUIProperty("TorrentFile.Downloaded");
            clearGUIProperty("TorrentFile.Priority");

            setGUIProperty("TorrentFile.Name", tor.FileName);
            setGUIProperty("TorrentFile.Size", tor.FileSizeFormatted);
            setGUIProperty("TorrentFile.Downloaded", tor.DownloadedFormatted);

            string pri = "";
            switch ((TorrentFilePriority)tor.Priority)
            {
                case TorrentFilePriority.DontDownload: pri = "Don't Download"; break;
                case TorrentFilePriority.High: pri = "High"; break;
                case TorrentFilePriority.Low: pri = "Low"; break;
                case TorrentFilePriority.Medium: pri = "Medium"; break;
            }
            setGUIProperty("TorrentFile.Priority", pri);
        }