Beispiel #1
0
 /// <summary>
 /// ����һ��HASH��¼���ļ��б�
 /// </summary>
 public static int AddNewHashDetail(int thetype, HASHFILEITEM thehash, int thedetailID)
 {
     try
     {
         StringBuilder strSql = new StringBuilder();
         {
             //��ӹ����ƻ�
             string tempstr = string.Format("insert into H31_DHT_DETAIL_{0} (", thedetailID);
             strSql.Append(tempstr);
             strSql.Append("hashID,hashType,recvTime,filename,filesize)");
             strSql.Append(" values (");
             strSql.Append("@hashID,@hashType,@recvTime,@filename,@filesize)");
             DbParameter[] cmdParms = {
             dbsql.CreateInDbParameter("@hashID",DbType.Int32,thehash.hashID),
             dbsql.CreateInDbParameter("@hashType",DbType.Int32,thetype),
             dbsql.CreateInDbParameter("@recvTime", DbType.DateTime,thehash.recvTime),
             dbsql.CreateInDbParameter("@filename", DbType.String,thehash.filename),
             dbsql.CreateInDbParameter("@filesize", DbType.Double,thehash.filesize)
             };
             return dbsql.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
         }
     }
     catch (System.Exception ex)
     {
         H31Debug.PrintLn(ex.StackTrace);
     }
     return -1;
 }
Beispiel #2
0
        /// <summary>
        /// 读取线程 2013-06-16
        /// </summary>
        private int GetHashDetail(string hashname, ref HASHITEM item1, ref HASHFILEITEM[] filelist)
        {
            Int32 ticktime1 = System.Environment.TickCount;
            try
            {
                int res1 = 0;
                TorrentFile myFile = null;
                if (checkBox_Torrent.Checked)
                {
                    res1 = m_downLoad.DownLoadFileByHashToFile(hashname);
                    Application.DoEvents();    //让系统在百忙之中来响应其他事件
                    if (res1 == 1)
                    {
                        string filename = m_localPath+"\\Torrent\\" +hashname.Substring(hashname.Length-1,1)+"\\"+ hashname + ".torrent";
                        myFile = new TorrentFile(filename);
                        Int32 ticktime2 = System.Environment.TickCount;
                        if (myFile == null || myFile.TorrentName.Length == 0)
                        {
                            m_downBadList[hashname] = System.Environment.TickCount / 1000;
                            if (checkBox_Torrent.Checked)
                            {
                                //File.Delete(filename);
                                File.Move(filename, m_localPath + "\\Torrent\\BAD\\" + hashname + ".torrent");
                                LogTheAction(1, 1, hashname + "下载文件不对,删除" + "-" + (ticktime2 - ticktime1).ToString());
                            }
                            return 0;
                        }
                    }

                }
                else
                {
                    byte[] data = m_downLoad.DownLoadFileByHashToByte(hashname);
                    if (data != null)
                        res1 = 1;
                    myFile = new TorrentFile(data);
                }
                if (res1 == 1)
                {
                    if (myFile == null || myFile.TorrentName.Length == 0 || myFile.TorrentFileInfo.Count == 0 || myFile.TorrentFileInfo.Count > MAX_FILEDETAIL_COUNT)
                    {
                        Int32 ticktime2 = System.Environment.TickCount;
                        LogTheAction(1, 2, hashname + ">>下载成功,但使用失败." + "-" + (ticktime2 - ticktime1).ToString());
                        m_downBadList[hashname] = System.Environment.TickCount / 1000;
                        return 0;
                    }
                    else
                    {

                        item1.keyType=(int)GetHashFileKeyType(ref myFile);
                        item1.fileCnt = myFile.TorrentFileInfo.Count;
                        item1.filetotalSize = myFile.TorrentPieceLength;
                        item1.keyContent = GetOneGoodString(myFile.TorrentName);

                        filelist = new HASHFILEITEM[myFile.TorrentFileInfo.Count];
                        for (int m = 0; m < myFile.TorrentFileInfo.Count; m++)
                        {
                            filelist[m].filename = myFile.TorrentFileInfo[m].Path;
                            filelist[m].filesize = myFile.TorrentFileInfo[m].Length;
                        }
                        Int32 ticktime2 = System.Environment.TickCount;
                        LogTheAction(1, 3, myFile.TorrentName + ">>下载成功:" + myFile.TorrentFileInfo.Count + "-" + (ticktime2 - ticktime1).ToString());
                        return 1;
                    }
                }
                else
                {
                    Int32 ticktime2 = System.Environment.TickCount;
                    m_downBadList[hashname] = System.Environment.TickCount / 1000;
                    LogTheAction(1, 4, hashname + ">>下载失败" + "-" + (ticktime2 - ticktime1).ToString());
                }
            }
            catch (System.Exception ex)
            {
                //错误日志记录
                H31Debug.PrintLn("GetHashDetail:" + ex.StackTrace);
            }
            return 0;
        }
Beispiel #3
0
        /// <summary>
        /// 下载种子文件并进行解析读取
        /// </summary>
        private int GetDownAndReaHashDetail(string hashname, ref HASHITEM item1, ref HASHFILEITEM[] filelist)
        {
            Int32 ticktime1 = System.Environment.TickCount;

            try
            {
                int         res1   = 0;
                TorrentFile myFile = null;
                if (checkBox_Torrent.Checked)
                {
                    res1 = m_downLoad.DownLoadFileByHashToFile(hashname);
                    Application.DoEvents();    //让系统在百忙之中来响应其他事件
                    if (res1 == 1)
                    {
                        string filename = Path.Combine(Path.Combine(Path.Combine(m_localPath, "Torrent"), hashname.Substring(hashname.Length - 2, 2)), hashname + ".torrent");
                        myFile = new TorrentFile(filename);
                        Int32 ticktime2 = System.Environment.TickCount;
                        if (myFile == null || myFile.TorrentName.Length == 0)
                        {
                            m_downBadList[hashname] = System.Environment.TickCount / 1000;
                            //解析不了的文件就直接备份
                            if (checkBox_Torrent.Checked)
                            {
                                File.Move(filename, Path.Combine(Path.Combine(m_localPath, "Torrent\\BAD"), hashname + ".torrent"));
                                LogTheAction(1, 1, hashname + "下载文件不对,删除" + "-" + (ticktime2 - ticktime1).ToString());
                            }
                            return(0);
                        }
                    }
                }
                else
                {
                    //不用存储文件,直接在内存中操作
                    byte[] data = m_downLoad.DownLoadFileByHashToByte(hashname);
                    if (data != null)
                    {
                        res1 = 1;
                    }
                    myFile = new TorrentFile(data);
                }
                //如果解析成功就进行赋值返回
                if (res1 == 1)
                {
                    if (myFile == null || myFile.TorrentName.Length == 0 || myFile.TorrentFileInfo.Count == 0 || myFile.TorrentFileInfo.Count > MAX_FILEDETAIL_COUNT)
                    {
                        Int32 ticktime2 = System.Environment.TickCount;
                        LogTheAction(1, 2, hashname + ">>下载成功,但使用失败." + "-" + (ticktime2 - ticktime1).ToString());
                        m_downBadList[hashname] = System.Environment.TickCount / 1000;
                        return(0);
                    }
                    else
                    {
                        //通过文件列表对文件是哪类进行分析判断
                        item1.keyType       = (int)GetHashFileKeyType(ref myFile);
                        item1.fileCnt       = myFile.TorrentFileInfo.Count;
                        item1.filetotalSize = myFile.TorrentPieceLength;
                        //提取正确的文件名字,过滤一些网址信息
                        item1.keyContent = GetOneGoodString(myFile.TorrentName);


                        filelist = new HASHFILEITEM[myFile.TorrentFileInfo.Count];
                        for (int m = 0; m < myFile.TorrentFileInfo.Count; m++)
                        {
                            filelist[m].filename = myFile.TorrentFileInfo[m].Path;
                            filelist[m].filesize = myFile.TorrentFileInfo[m].Length;
                        }
                        Int32 ticktime2 = System.Environment.TickCount;
                        LogTheAction(1, 3, myFile.TorrentName + ">>下载成功:" + myFile.TorrentFileInfo.Count + "-" + (ticktime2 - ticktime1).ToString());
                        return(1);
                    }
                }
                else
                {
                    Int32 ticktime2 = System.Environment.TickCount;
                    m_downBadList[hashname] = System.Environment.TickCount / 1000;
                    LogTheAction(1, 4, hashname + ">>下载失败" + "-" + (ticktime2 - ticktime1).ToString());
                }
            }
            catch (System.Exception ex)
            {
                H31Debug.PrintLn("GetHashDetail:" + ex.StackTrace);
            }
            return(0);
        }