示例#1
0
 private void ReleaseContext()
 {
     if (FTKernelAPI.FTK_Context_IsInit())
     {
         FTKernelAPI.FTK_Context_Release();
     }
 }
示例#2
0
        private void StartContext()
        {
            Debug.Assert(!FTKernelAPI.FTK_Context_IsInit());

            String sLicenseKey = "7C55ACE177773AC56EB1311FFC716F375ACE9C42BF4AF09B0E900BDBEC1D65765A33521B8636BE3BBC508EC87177BBC";

            sLicenseKey += "E892E392FA33864C702AB55779D9E2B5290C066DC6B0FFDB33B4FFCE6419E82E643DDE3CF1AC8410C25B623D7964F35B1E15C";
            sLicenseKey += "98E8628465A71696FDADD05B5F9F5D12393AA77666B868D369685989FDB7";
            FTKernelAPI.FTK_License_Set(sLicenseKey);


            String sStartPath = Application.StartupPath;

            sStartPath += "\\";

            String sConfigFile = sStartPath + "Config.ini";

            Debug.Assert(FTKernelAPI.FTK_Context_Init(sConfigFile, true));
            FTKernelAPI.FTK_Context_TorrentFile(false, false);
            Debug.Assert(!FTKernelAPI.FTK_FTK_Context_IsRunning());
            FTKernelAPI.FTK_Context_Run();
            Debug.Assert(FTKernelAPI.FTK_FTK_Context_IsRunning());

            FTKernelAPI.FTK_CALLBACK_FUNC ftk_func = new FTKernelAPI.FTK_CALLBACK_FUNC(ftk_cnt_func);
            FTKernelAPI.FTK_Context_NotifyCB(ftk_func);
        }
示例#3
0
        private void button5_Click(object sender, System.EventArgs e)
        {
            uint hTorrentFile = FTKernelAPI.FTK_Torrent_Open(textBox1.Text, 0, null, false, false);

            Debug.Assert(0 != hTorrentFile);
            String sName = FTKernelAPI.FTK_Torrent_GetTorrentName(hTorrentFile);

            FTKernelAPI.FTK_Torrent_Close(hTorrentFile);
            hTorrentFile = 0;
            MessageBox.Show(sName);
        }
示例#4
0
        private void StopDownload()
        {
            if (0 == m_hDownloader)
            {
                return;
            }

            FTKernelAPI.FTK_GlobalVar_RemoveTorrentSHA1(m_sHexInfoVal);

            FTKernelAPI.FTK_Downloader_Release(m_hDownloader);
            FTKernelAPI.FTK_Downloader_Close(m_hDownloader);
            m_hDownloader = 0;
        }
示例#5
0
        private void timer1_Tick(object sender, System.EventArgs e)
        {
            if (0 == m_hDownloader)
            {
                return;
            }

            if (FTKernelAPI.FTK_Downloader_GetState(m_hDownloader) == FTKernelAPI.DLSTATE.DLSTATE_CHECKING)
            {
                textBox4.Text = "Status: checking file...";
            }
            else if (FTKernelAPI.FTK_Downloader_GetState(m_hDownloader) == FTKernelAPI.DLSTATE.DLSTATE_DOWNLOAD)
            {
                textBox4.Text = "Status: downloading...";
            }
            else if (FTKernelAPI.FTK_Downloader_GetState(m_hDownloader) == FTKernelAPI.DLSTATE.DLSTATE_FETALERR)
            {
                textBox4.Text = "Status: downloading error...";
            }
            else if (FTKernelAPI.FTK_Downloader_GetState(m_hDownloader) == FTKernelAPI.DLSTATE.DLSTATE_TERMINATE)
            {
                textBox4.Text = "Status: stopping...";
            }

            int nPos = 0;

            if (FTKernelAPI.FTK_Downloader_GetState(m_hDownloader) == FTKernelAPI.DLSTATE.DLSTATE_CHECKING)
            {
                nPos = ( int )PERCENT((ulong)FTKernelAPI.FTK_Stat_GetCheckPieceCount(m_hDownloader), (ulong)m_nPieceCount);
                progressBar1.Value = nPos;
            }

            if (FTKernelAPI.FTK_Downloader_GetState(m_hDownloader) < FTKernelAPI.DLSTATE.DLSTATE_DOWNLOAD ||
                FTKernelAPI.FTK_Downloader_GetState(m_hDownloader) >= FTKernelAPI.DLSTATE.DLSTATE_FETALERR)
            {
                return;
            }

            P2PAPI.FTKernelAPI._tagPeerData [] PeersData = new P2PAPI.FTKernelAPI._tagPeerData[10];
            int nRetCount = 10;

            int nSize = Marshal.SizeOf(PeersData[0]);

            IntPtr pData = MarshalExt.AllocHGlobal(nSize * 10);

            nRetCount = 10;

            FTKernelAPI.FTK_Stat_GetPeerData(m_hDownloader, pData, ref nRetCount, 10);
            BytePtr_to_Peers_Data(pData, PeersData, nRetCount);
            MarshalExt.FreeHGlobal(pData);

            //P2PAPI.FTKernelAPI._tagAnnounceData [] AnnouncesData = new P2PAPI.FTKernelAPI._tagAnnounceData[10];// = new P2PAPI.FTKernelAPI._tagAnnounceData[ 20 ];

            P2PAPI.FTKernelAPI._tagAnnounceData [] AnnouncesData = new P2PAPI.FTKernelAPI._tagAnnounceData[10];
            nSize = Marshal.SizeOf(AnnouncesData[0]);

            pData     = MarshalExt.AllocHGlobal(nSize * 10);
            nRetCount = 10;

            FTKernelAPI.FTK_Stat_GetAnnounceData(m_hDownloader, pData, ref nRetCount, 10);
            BytePtr_to_Announces_Data(pData, AnnouncesData, nRetCount);
            MarshalExt.FreeHGlobal(pData);

            ulong ulTotalFileHaveSize = FTKernelAPI.FTK_Stat_GetTotalFileHaveSize(m_hDownloader);

            nPos = ( int )PERCENT((ulong)ulTotalFileHaveSize, (ulong)m_ulTotalFileSize);
            progressBar1.Value = nPos;

            String sValue;

            sValue      = FormatBytes(( ulong )FTKernelAPI.FTK_Stat_GetDownloadRate(m_hDownloader));
            label1.Text = "Down Speed: " + sValue + "/s";

            sValue      = FormatBytes(( ulong )FTKernelAPI.FTK_Stat_GetUploadRate(m_hDownloader));
            label2.Text = "Up Speed: " + sValue + "/s";

            sValue         = FormatBytes(ulTotalFileHaveSize);
            textBox4.Text += " | Downloaded: " + sValue;

            if (nPos >= 100)
            {
                textBox4.Text = "Status: Downloaded OK...";
            }
        }
示例#6
0
        private bool StartDownload()
        {
            String sStartupPath = Application.StartupPath;
            uint   hTorrentFile = FTKernelAPI.FTK_Torrent_Open(textBox1.Text, 0, null, false, false);

            Debug.Assert(0 != hTorrentFile);
            int nFileCount = FTKernelAPI.FTK_Torrent_GetFilesCount(hTorrentFile);

            Byte[] pPreAllocFile = new Byte[nFileCount];
            for (int i = 0; i < nFileCount; i++)
            {
                pPreAllocFile[i] = 0;
            }

            String sDestPath = textBox2.Text;

            //Debug.Assert( sDestPath.Length > 0 );
            if (sDestPath.Length == 0)
            {
                sDestPath = textBox1.Text;
                int nPos = sDestPath.LastIndexOf("\\", 0, 1);
                Debug.Assert(-1 != nPos);
                sDestPath = sDestPath.Substring(0, nPos);
            }

            m_sHexInfoVal = FTKernelAPI.FTK_Torrent_GetHexInfoHash(hTorrentFile);
            //m_sHexInfoVal.Replace( "%", "" );
            m_sHexInfoVal = m_sHexInfoVal.Replace("%", "");

            m_hDownloader = FTKernelAPI.FTK_Downloader_Open();
            MessageBox.Show(sDestPath + "\\" + FTKernelAPI.FTK_Torrent_GetTorrentName(hTorrentFile));

            bool bRet = false;

            bRet = FTKernelAPI.FTK_Downloader_Init(
                m_hDownloader,
                textBox1.Text,
                pPreAllocFile,
                nFileCount,
                false,
                sDestPath + "\\" + FTKernelAPI.FTK_Torrent_GetTorrentName(hTorrentFile),
                sStartupPath + "\\Config.INI",
                sStartupPath + "\\Log\\" + "Downloader.log",
                sStartupPath + m_sHexInfoVal + ".status",
                false,
                null,
                0);

            if (false == bRet)
            {
                FTKernelAPI.FTK_Downloader_Close(m_hDownloader);
                m_hDownloader = 0;
                return(false);
            }

            bRet = FTKernelAPI.FTK_Downloader_Execute(m_hDownloader);
            if (false == bRet)
            {
                FTKernelAPI.FTK_Downloader_Close(m_hDownloader);
                m_hDownloader = 0;
                return(false);
            }

            FTKernelAPI.FTK_GlobalVar_AddTorrentSHA1(m_sHexInfoVal, m_hDownloader);

            m_ulTotalFileSize = FTKernelAPI.FTK_Torrent_GetFileSize(hTorrentFile);
            m_nPieceCount     = FTKernelAPI.FTK_Torrent_GetPieceCount(hTorrentFile);

            FTKernelAPI.FTK_Torrent_Close(hTorrentFile);
            hTorrentFile = 0;

            return(true);
        }