Ejemplo n.º 1
0
        bool check(HisTorrent trt, bool ifCheckHis)
        {
            bool flag = true;

            if (trt.Size > 15 * 1024 * 1024 && !trt.File.ToLower().Contains("sample"))
            {
                if (fileDic.ContainsKey(Tool.filterName(trt.File)))
                {
                    Tool.moveFile("duplicate", trt.Path);
                    return(false);
                }
                if (ifCheckHis)
                {
                    HisTorrent t;
                    try
                    {
                        t = dic[Tool.filterName(trt.File)];
                    }
                    catch (KeyNotFoundException e)
                    {
                        try
                        {
                            t = torrentNameDic[trt.FilteredFileName];
                        }
                        catch (KeyNotFoundException ex)
                        {
                            t = null;
                        }
                    }
                    if (t != null)
                    {
                        if (t.Size >= trt.Size || t.CreateTime < startTime)
                        {
                            Tool.moveFile("duplicate", trt.Path);
                            flag = false;
                        }
                        else
                        {
                            Tool.moveFile("duplicate", t.Path);
                        }
                    }
                    return(flag);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 2
0
        public void process(string directoryStr, bool ifCheckHis)
        {
            string md5;

            if (md5Set.Count == 0)
            {
                getList();
            }
            startTime = DateTime.Now;
            String[] path = Directory.GetFiles(directoryStr, "*", SearchOption.TopDirectoryOnly);
            foreach (String p in path)
            {
                if (p.EndsWith(".torrent"))
                {
                    if (Path.GetFileNameWithoutExtension(p).ToLower().Contains(".sd."))
                    {
                        Tool.moveFile("SD", p);
                        continue;
                    }
                    md5 = GetMd5(p);
                    if (md5Set.Contains(md5))
                    {
                        Tool.moveFile("Md5Duplicate", p);
                        continue;
                    }
                    if (!Path.GetFileNameWithoutExtension(p).Replace("rarbg.to", "").Contains("."))
                    {
                        Tool.moveFile("invalid", p);
                    }
                    BDict torrentFile = null;
                    bool  hasBigFile  = false;
                    try
                    {
                        torrentFile = BencodingUtils.DecodeFile(p) as BDict;
                    }
                    catch (Exception e)
                    {
                        Tool.moveFile("decodeErr", p);
                    }
                    if (torrentFile != null)
                    {
                        bool              flag = true;
                        BList             b;
                        List <HisTorrent> listTorrent = new List <HisTorrent>();
                        if ((torrentFile["info"] as BDict).ContainsKey("files"))
                        {
                            b = (BList)(torrentFile["info"] as BDict)["files"];



                            for (int i = 0; i < b.Count; i++)
                            {
                                BDict bd     = (BDict)b[i];
                                long  length = ((BInt)bd["length"]).Value;
                                if (length > 25 * 1024 * 1024)
                                {
                                    hasBigFile = true;
                                }
                                BList      list = (BList)bd["path"];
                                string     s    = ((BString)list[list.Count - 1]).Value;
                                HisTorrent trt  = new HisTorrent();
                                trt.CreateTime = DateTime.Now;
                                trt.Path       = p;
                                trt.Size       = length;
                                if (s.LastIndexOf('.') > 0)
                                {
                                    trt.File = s.Substring(0, s.LastIndexOf('.'));
                                    trt.Ext  = s.Substring(s.LastIndexOf('.'));
                                }
                                else
                                {
                                    trt.File = s;
                                }
                                listTorrent.Add(trt);
                                if (!check(trt, ifCheckHis))
                                {
                                    flag = false;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            hasBigFile = true;
                            HisTorrent trt = new HisTorrent();
                            trt.CreateTime = DateTime.Now;
                            trt.Path       = p;
                            trt.Size       = ((BInt)(torrentFile["info"] as BDict)["length"]).Value;
                            string name = ((BString)(torrentFile["info"] as BDict)["name"]).Value;
                            if (name.LastIndexOf('.') > 0)
                            {
                                trt.File = name.Substring(0, name.LastIndexOf('.'));
                                trt.Ext  = name.Substring(name.LastIndexOf('.'));
                            }
                            else
                            {
                                trt.File = name;
                            }
                            listTorrent.Add(trt);
                            if (!check(trt, ifCheckHis))
                            {
                                flag = false;
                            }
                        }
                        if (!hasBigFile)
                        {
                            Tool.moveFile("noBigFile", p);
                        }
                        if (flag && hasBigFile)
                        {
                            foreach (HisTorrent his in listTorrent)
                            {
                                if (his.Size > 60 * 1024 * 1024)
                                {
                                    if (ifCheckHis)
                                    {
                                        his.Md5 = md5;
                                        DBHelper.insertTorrent(his);
                                    }
                                    try
                                    {
                                        md5Set.Add(md5);
                                        dic.Add(Tool.filterName(his.File), his);
                                        torrentNameDic.Add(his.FilteredFileName, his);
                                    }catch (ArgumentException e)
                                    {
                                        dic.Remove(Tool.filterName(his.File));
                                        dic.Add(Tool.filterName(his.File), his);
                                        torrentNameDic.Remove(his.FilteredFileName);
                                        torrentNameDic.Add(his.FilteredFileName, his);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Tool.moveFile("decodeErr", p);
                    }
                }
            }
        }