コード例 #1
0
        public static BTItem ReadInt(System.IO.FileStream sr)
        {
            long r = 0;
            int  c;
            bool neg = false;

            while ((c = sr.ReadByte()) != 'e')
            {
                if (c == '-')
                {
                    neg = true;
                }
                else if ((c >= '0') && (c <= '9'))
                {
                    r = (r * 10) + c - '0';
                }
            }

            if (neg)
            {
                r = -r;
            }

            BTInteger bti = new BTInteger {
                Value = r
            };

            return(bti);
        }
コード例 #2
0
ファイル: BT.cs プロジェクト: mudboy/tvrename
        public BTItem ReadInt(FileStream sr)
        {
            Int64 r = 0;
            int c;
            bool neg = false;
            while ((c = sr.ReadByte()) != 'e')
            {
                if (c == '-')
                    neg = true;
                else if ((c >= '0') && (c <= '9'))
                    r = (r * 10) + c - '0';
            }
            if (neg)
                r = -r;

            BTInteger bti = new BTInteger();
            bti.Value = r;
            return bti;
        }
コード例 #3
0
        public List <TorrentEntry> AllFilesBeingDownloaded()
        {
            List <TorrentEntry> r = new List <TorrentEntry>();

            BEncodeLoader bel = new BEncodeLoader();

            foreach (BTDictionaryItem dictitem in ResumeDat.GetDict().Items)
            {
                if ((dictitem.Type != BTChunk.kDictionaryItem))
                {
                    continue;
                }

                if ((dictitem.Key == ".fileguard") || (dictitem.Data.Type != BTChunk.kDictionary))
                {
                    continue;
                }

                if (dictitem.Data is BTError err)
                {
                    logger.Error($"Error finding BT items: {err.Message}");
                    return(r);
                }

                BTDictionary d2 = (BTDictionary)(dictitem.Data);

                BTItem p = d2.GetItem("prio");
                if ((p is null) || (p.Type != BTChunk.kString))
                {
                    continue;
                }

                BTString prioString    = (BTString)(p);
                string   directoryName = Path.GetDirectoryName(ResumeDatPath) + System.IO.Path.DirectorySeparatorChar;

                string torrentFile = dictitem.Key;
                if (!File.Exists(torrentFile))                 // if the torrent file doesn't exist
                {
                    torrentFile = directoryName + torrentFile; // ..try prepending the resume.dat folder's path to it.
                }
                if (!File.Exists(torrentFile))
                {
                    continue; // can't find it.  give up!
                }
                BTFile tor = bel.Load(torrentFile);
                if (tor is null)
                {
                    continue;
                }

                List <string> a = tor.AllFilesInTorrent();
                if (a is null)
                {
                    continue;
                }

                int c = 0;

                p = d2.GetItem("path");
                if ((p is null) || (p.Type != BTChunk.kString))
                {
                    continue;
                }

                string defaultFolder = ((BTString)p).AsString();

                BTItem targets    = d2.GetItem("targets");
                bool   hasTargets = ((targets != null) && (targets.Type == BTChunk.kList));
                BTList targetList = (BTList)(targets);

                //foreach (var i in d2.Items)
                //{
                //logger.Info($"   {i.Key}  {i.Data.AsText()}");
                //}

                foreach (string s in a)
                {
                    if ((c < prioString.Data.Length) && (prioString.Data[c] != BTPrio.Skip))
                    {
                        try
                        {
                            string saveTo = FileHelper
                                            .FileInFolder(defaultFolder, TVSettings.Instance.FilenameFriendly(s)).Name;

                            if (hasTargets)
                            {
                                // see if there is a target for this (the c'th) file
                                foreach (BTItem t in targetList.Items)
                                {
                                    BTList    l    = (BTList)(t);
                                    BTInteger n    = (BTInteger)(l.Items[0]);
                                    BTString  dest = (BTString)(l.Items[1]);
                                    if (n.Value == c)
                                    {
                                        saveTo = dest.AsString();
                                        break;
                                    }
                                }
                            }

                            int          percent   = (a.Count == 1) ? PercentBitsOn((BTString)(d2.GetItem("have"))) : -1;
                            bool         completed = ((BTInteger)d2.GetItem("order")).Value == -1;
                            TorrentEntry te        = new TorrentEntry(torrentFile, saveTo, percent, completed, torrentFile);
                            r.Add(te);
                        }
                        catch (System.IO.PathTooLongException ptle)
                        {
                            //this is not the file we are looking for
                            logger.Debug(ptle);
                        }
                    }

                    c++;
                }
            }

            return(r);
        }