예제 #1
0
    // Start is called before the first frame update
    void Start()
    {
        //steam下载地址
        string url        = @"https://media.st.dl.eccdnx.com/client/installer/steam.dmg";
        string pathFormat = Application.dataPath + "/StreamingAssets/steam_{0}.dmg";

        //单个下载
        HTTPParamIndie paramIndie = new HTTPParamIndie(url, string.Format(pathFormat, 1), "", 1);

        indie = new HTTPDownloadIndie(paramIndie);
        indie.DownLoad();
        //----------

        ////批量下载
        List <string> urls  = new List <string>();
        List <string> paths = new List <string>();
        List <string> md5s  = new List <string>();

        for (int i = 2; i <= 40; i++)
        {
            urls.Add(url);
            paths.Add(string.Format(pathFormat, i));
            md5s.Add(i.ToString());
        }

        HTTPParamBatch paramBatch = new HTTPParamBatch();

        paramBatch.Urls      = urls;
        paramBatch.Paths     = paths;
        paramBatch.MD5S      = md5s;
        paramBatch.MaxThread = 10;

        batch = new HTTPDownloadBatch(paramBatch);
        batch.DownLoad();
        //--------------

        //信息打印
        t          = new Timer();
        t.Elapsed += timeCallBack;
        t.Interval = 1000;
        t.Start();
    }
    /// <summary>
    /// 初始化下载器
    /// </summary>
    private void SetDlders()
    {
        _dlders.Clear();
        int urlCnt         = _param.Urls.Count;
        int indieMaxThread = _param.MaxThread / urlCnt;

        indieMaxThread = Math.Max(indieMaxThread, 1);
        for (int i = 0; i < urlCnt; i++)
        {
            string url  = _param.Urls[i];
            string path = _param.Paths[i];
            string md5  = _param.MD5S[i];

            HTTPParamIndie indieParam = new HTTPParamIndie(url, path, md5, indieMaxThread);
            indieParam.TimeOut   = _param.TimeOut;
            indieParam.RetryTime = _param.RetryTime;

            HTTPDownloadIndie dlder = new HTTPDownloadIndie(indieParam);
            _dlders.Add(dlder);

            dlder.DownLoad();
        }
    }