调用迅雷SDK 的问题 希望大佬出手救命

别低头 王冠会掉 2020-02-29 06:16:36

XL.DownTaskParam p = new XL.DownTaskParam()
{
szTaskUrl = URL,
szFilename = “1.rar”,
szSavePath = Application.StartupPath
};
a = XL.XL_CreateTask(p);
var startSuccess = XL.XL_StartTask(a);

问题出在下载大文件的时候 下载几十MB的时候下载就会0KB 10-20秒左右 然后在接着下载 用别人写的工具同样是迅雷SDK 下载同样的文件 就没有这个情况发生 下载0KB期间 硬盘读写很高


只有50分 谢谢大佬
...全文
1739 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
我的资源是直连的 用不了BT啊 还是谢谢您
desperaso 2020-03-01
  • 打赏
  • 举报
回复
不用迅雷的行不,一样下载、bt。Mono开源的,有demo
https://pan.baidu.com/s/186j6ijs82j0mcb7rKF_P1g
提取码:9qf2
  • 打赏
  • 举报
回复
刚才在《迅雷推出新的测试版,不是浏览器了。。。》的帖子里看到不少人喷“ XLServicePlatform ”是个流氓服务。其实这个服务非常重要!只怪我们之前没有解释清楚。 “ XLServicePlatform ”服务具有以下几个功能: 1、在 Windows Vista 引入的 UAC 增加了一种磁盘安全机制。在迅雷进程没有管理员权限的情况下,创建固实文件申请磁盘空间后,迅雷一旦开始写入数据,系统就会将文件所在区块的所有数据写成 0 (相当于“初始化”)。以防没有权限的应用程序访问到磁盘上被标记为删除但尚未擦除的旧数据。 完成初始化的速度取决于磁盘本身的写入性能,在此期间磁盘的 IO 性能几乎全部被占用。因此会造成其它磁盘读写请求被延迟。于是会看到许多应用程序停止响应。而下载的文件越大,完成初始化需要的时间越长。直至文件所在区块全部初始化完成,迅雷才可以写入下载的数据。( uTorrent 在勾选了“提前申请磁盘空间”后,如果也没有管理员权限,那么下载大文件也会出现同样的情况。) 为了避免这个问题,迅雷利用系统服务具有管理员权限这一特性,在迅雷下载大于 100MB 的文件时,由“ XLServicePlatform ”服务来申请磁盘空间,这时系统就不会花时间提前将文件所在区块初始化,迅雷就可以直接写入数据了。 2、目前最新版本的迅雷客户端都增加了“驱动层浏览器支持”功能,用于在不安装任何浏览器扩展的条件下,支持“ Edge、Chrome、Firefox ”等浏览器。该功能依赖“ XLServicePlatform ”服务进行初始化。 3、迅雷下载 JS-SDK 需要通过“ XLServicePlatform ”服务跟网页中的 JS 进行交互,比如判断是否安装迅雷,以及传递下载链接等信息,如果这个服务被停止,当你点击网页中使用迅雷下载 JS-SDK 实现的下载按钮时,会认为你没有安装迅雷,从而提示你安装迅雷。 鉴于以上功能对于大多数用户的下载体验都十分重要,所以我们没有提供关闭此服务的选项。如果你用不着这些功能,是可以手动停止服务的。 看了 上面的文章我 抱着试试的态度 项目里设置了管理员模式 问题没有了
  • 打赏
  • 举报
回复
有点难
  • 打赏
  • 举报
回复
using System;
using System.Runtime.InteropServices;

public static class XL
{
    [DllImport("xldl.dll", CharSet = CharSet.Unicode)]
    public static extern  bool XL_Init();

    [DllImport("xldl.dll", CharSet = CharSet.Unicode)]
    public static extern  bool XL_UnInit();

    [DllImport("xldl.dll", CallingConvention  = CallingConvention.Cdecl)]
    public static extern  IntPtr XL_CreateTask([In()]DownTaskParam stParam);

    [DllImport("xldl.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern  bool XL_StartTask(IntPtr hTask);

    [DllImport("xldl.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern  bool XL_StopTask(IntPtr hTask);

    [DllImport("xldl.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern  object XL_SetSpeedLimit(Int32 nKBps);

    [DllImport("xldl.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern int XL_CreateTaskByThunder(string pszUrl, string pszFileName, string pszReferUrl, string pszCharSet, string pszCookie);
    //LONG XL_CreateTaskByThunder(wchar_t *pszUrl, wchar_t *pszFileName, wchar_t *pszReferUrl, wchar_t *pszCharSet, wchar_t *pszCookie)
    [DllImport("xldl.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern  object XL_SetUploadSpeedLimit(Int32 nTcpKBps, Int32 nOtherKBps);

    [DllImport("xldl.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern  object XL_SetProxy(DOWN_PROXY_INFO stProxyInfo);

    [DllImport("xldl.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern  object XL_DelTempFile(DownTaskParam stParam);
 
    [DllImport("xldl.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern  bool XL_DeleteTask(IntPtr hTask);

    [DllImport("xldl.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern  bool XL_GetBtDataFileList(string szFilePath, string szSeedFileFullPath);

    [DllImport("xldl.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern  bool XL_SetUserAgent(string pszUserAgent);

    [DllImport("xldl.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern  bool XL_GetFileSizeWithUrl(string lpURL, Int64 iFileSize);

    [DllImportAttribute("xldl.dll", EntryPoint = "XL_QueryTaskInfoEx", CallingConvention = CallingConvention.Cdecl)]
    [return: MarshalAsAttribute(UnmanagedType.Bool)]
    public static extern  bool XL_QueryTaskInfoEx(IntPtr hTask, [Out()]DownTaskInfo stTaskInfo);

    [DllImportAttribute("xldl.dll", EntryPoint = "XL_QueryTaskInfoEx", CallingConvention = CallingConvention.Cdecl)]
    public static extern  IntPtr XL_CreateBTTask(DownBTTaskParam stParam);

    [DllImportAttribute("xldl.dll", EntryPoint = "XL_QueryTaskInfoEx", CallingConvention = CallingConvention.Cdecl)]
    public static extern  long XL_QueryBTFileInfo(IntPtr hTask, UIntPtr dwFileIndex, ulong ullFileSize, ulong ullCompleteSize, UIntPtr dwStatus);

    [DllImportAttribute("xldl.dll", EntryPoint = "XL_QueryTaskInfoEx", CallingConvention = CallingConvention.Cdecl)]
    public static extern  long XL_QueryBTFileInfo(IntPtr hTask, BTTaskInfo pTaskInfo);


    [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)]
    public class DownTaskParam
    {
        public int nReserved;
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 2084)]
        public string szTaskUrl;
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 2084)]
        public string szRefUrl;
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 4096)]
        public string szCookies;
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 260)]
        public string szFilename;
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 260)]
        public string szReserved0;
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 260)]
        public string szSavePath;
        public IntPtr hReserved;
        public int bReserved = 0;
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 64)]
        public string szReserved1;
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 64)]
        public string szReserved2;
        public int IsOnlyOriginal = 0;
        public uint nReserved1 = 5;
        public int DisableAutoRename = 0;
        public int IsResume = 1;
        [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 2048, ArraySubType = UnmanagedType.U4)]
        public uint[] reserved;
    }

    [StructLayoutAttribute(LayoutKind.Sequential)]
    public struct BTTaskInfo
    {

        ///LONG->int

        public int lTaskStatus;
        ///DWORD->unsigned int

        public uint dwUsingResCount;
        ///DWORD->unsigned int

        public uint dwSumResCount;
        ///ULONGLONG->unsigned __int64

        public ulong ullRecvBytes;
        ///ULONGLONG->unsigned __int64

        public ulong ullSendBytes;
        ///BOOL->int
        [MarshalAsAttribute(UnmanagedType.Bool)]

        public bool bFileCreated;
        ///DWORD->unsigned int

        public uint dwSeedCount;
        ///DWORD->unsigned int

        public uint dwConnectedBTPeerCount;
        ///DWORD->unsigned int

        public uint dwAllBTPeerCount;
        ///DWORD->unsigned int
        public uint dwHealthyGrade;
    }

    [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public class DownTaskInfo
    {
        public DOWN_TASK_STATUS stat;
        public TASK_ERROR_TYPE fail_code;
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 260)]
        public string szFilename;
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 260)]
        public string szReserved0;
        public long nTotalSize;
        public long nTotalDownload;
        public float fPercent;
        public int nReserved0;
        public int nSrcTotal;
        public int nSrcUsing;
        public int nReserved1;
        public int nReserved2;

        public int nReserved3;
        ///int

        public int nReserved4;
        ///__int64

        public long nReserved5;
        ///__int64

        public long nDonationP2P;
        ///__int64

        public long nReserved6;
        ///__int64

        public long nDonationOrgin;
        ///__int64

        public long nDonationP2S;
        ///__int64

        public long nReserved7;
        ///__int64

        public long nReserved8;
        ///int

        public int nSpeed;
        ///int

        public int nSpeedP2S;
        ///int

        public int nSpeedP2P;
        ///boolean

        public bool bIsOriginUsable;
        ///float

        public float fHashPercent;
        ///int

        public int IsCreatingFile;
        ///DWORD[64]
        [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 64, ArraySubType = UnmanagedType.U4)]
        public uint[] reserved;
    }

    public enum DOWN_TASK_STATUS
    {

        ///NOITEM -> 0
        NOITEM = 0,

        TSC_ERROR,

        TSC_PAUSE,

        TSC_DOWNLOAD,

        TSC_COMPLETE,

        TSC_STARTPENDING,

        TSC_STOPPENDING
    }

    public enum TASK_ERROR_TYPE
    {

        ///TASK_ERROR_UNKNOWN -> 0x00
        TASK_ERROR_UNKNOWN = 0,

        ///TASK_ERROR_DISK_CREATE -> 0x01
        TASK_ERROR_DISK_CREATE = 1,

        ///TASK_ERROR_DISK_WRITE -> 0x02
        TASK_ERROR_DISK_WRITE = 2,

        ///TASK_ERROR_DISK_READ -> 0x03
        TASK_ERROR_DISK_READ = 3,

        ///TASK_ERROR_DISK_RENAME -> 0x04
        TASK_ERROR_DISK_RENAME = 4,

        ///TASK_ERROR_DISK_PIECEHASH -> 0x05
        TASK_ERROR_DISK_PIECEHASH = 5,

        ///TASK_ERROR_DISK_FILEHASH -> 0x06
        TASK_ERROR_DISK_FILEHASH = 6,

        ///TASK_ERROR_DISK_DELETE -> 0x07
        TASK_ERROR_DISK_DELETE = 7,

        ///TASK_ERROR_DOWN_INVALID -> 0x10
        TASK_ERROR_DOWN_INVALID = 16,

        ///TASK_ERROR_PROXY_AUTH_TYPE_UNKOWN -> 0x20
        TASK_ERROR_PROXY_AUTH_TYPE_UNKOWN = 32,

        ///TASK_ERROR_PROXY_AUTH_TYPE_FAILED -> 0x21
        TASK_ERROR_PROXY_AUTH_TYPE_FAILED = 33,

        ///TASK_ERROR_HTTPMGR_NOT_IP -> 0x30
        TASK_ERROR_HTTPMGR_NOT_IP = 48,

        ///TASK_ERROR_TIMEOUT -> 0x40
        TASK_ERROR_TIMEOUT = 64,

        ///TASK_ERROR_CANCEL -> 0x41
        TASK_ERROR_CANCEL = 65,

        ///TASK_ERROR_TP_CRASHED -> 0x42
        TASK_ERROR_TP_CRASHED = 66,

        ///TASK_ERROR_ID_INVALID -> 0x43
        TASK_ERROR_ID_INVALID = 67
    }
    public enum DOWN_PROXY_TYPE
    {

        ///PROXY_TYPE_IE -> 0
        PROXY_TYPE_IE = 0,

        ///PROXY_TYPE_HTTP -> 1
        PROXY_TYPE_HTTP = 1,

        ///PROXY_TYPE_SOCK4 -> 2
        PROXY_TYPE_SOCK4 = 2,

        ///PROXY_TYPE_SOCK5 -> 3
        PROXY_TYPE_SOCK5 = 3,

        ///PROXY_TYPE_FTP -> 4
        PROXY_TYPE_FTP = 4,

        ///PROXY_TYPE_UNKOWN -> 255
        PROXY_TYPE_UNKOWN = 255
    }

    public enum DOWN_PROXY_AUTH_TYPE
    {

        ///PROXY_AUTH_NONE -> 0
        PROXY_AUTH_NONE = 0,

        PROXY_AUTH_AUTO,

        PROXY_AUTH_BASE64,

        PROXY_AUTH_NTLM,

        PROXY_AUTH_DEGEST,

        PROXY_AUTH_UNKOWN
    }

    [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public class DOWN_PROXY_INFO
    {

        ///BOOL->int
        [MarshalAsAttribute(UnmanagedType.Bool)]

        public bool bIEProxy;
        ///BOOL->int
        [MarshalAsAttribute(UnmanagedType.Bool)]

        public bool bProxy;
        ///DOWN_PROXY_TYPE

        public DOWN_PROXY_TYPE stPType;
        ///DOWN_PROXY_AUTH_TYPE

        public DOWN_PROXY_AUTH_TYPE stAType;
        ///wchar_t[2048]
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 2048)]

        public string szHost;
        ///INT32->int

        public int nPort;
        ///wchar_t[50]
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 50)]

        public string szUser;
        ///wchar_t[50]
        [MarshalAsAttribut
清晨曦月 2020-03-01
  • 打赏
  • 举报
回复
没玩过这个东西。看一下下载参数设置是不是有下载的缓存大小、缓存写入硬盘设置等等,函数调用是不是有其它重载
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
论坛任务又来30分

110,546

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧