Пример #1
0
    void DownloadOne()
    {
        int id = 1;

        //2.第二步调用下载(批量下载就多次调用)
        DownloadObj downloadObj = UnityDownloadManager.instance.GetDownloadObjByID(id);

        Debug.Log(downloadObj.ToString());
        if (downloadObj == null)
        {
            string parentPath = Environment.CurrentDirectory + "\\下载Data";
            downloadObj = new DownloadObj().SetID(id).SetUrl("https://yoyohan1.gitee.io/logo.ico").SetParentPath(parentPath).SetFileName("example1.ico").AddExtra("videoType", 1).AddExtra("coverUrl", "coverUrl");
            downloadObj.OnProgressAction += OnProgress;
            downloadObj.OnCompleteAction += OnComplete;
        }
        else if (downloadObj.currentDownloadState == DownloadState.pause)
        {
            downloadObj.OnProgressAction += OnProgress;
            downloadObj.OnCompleteAction += OnComplete;
        }

        UnityDownloadManager.instance.StartDownloadOne(downloadObj);


        //TODO..处理开始下载的逻辑
    }
Пример #2
0
 public void DownloadFileSize(DownloadObj downloadObj)
 {
     this.mDownloadObj = downloadObj;
     mDownloadObj.ChangeDownloadState(DownloadState.downloading);
     UnityDownloadManager.instance.UpdateAllDownload();
     StartCoroutine(DownloadFileSizeHandler());
 }
Пример #3
0
    void OnProgress(DownloadObj downloadObj)
    {
        Debug.Log(downloadObj.sDownloadFileResult.downloadedLength + "   " + downloadObj.sDownloadFileResult.contentLength);

        //if (downloadAmount == null)
        //{
        //    downloadObj.OnProgressAction -= OnProgress;
        //    downloadObj.OnCompleteAction -= OnComplete;
        //    return;
        //}

        //downloadAmount.fillAmount = (float)downloadObj.sDownloadFileResult.downloadedLength / downloadObj.sDownloadFileResult.contentLength;
    }
    private void AddDownloadObj(DownloadObj downloadingDetail)
    {
        DownloadObj temp = GetDownloadObjByID(downloadingDetail.id);

        if (temp == null)
        {
            lisDownloadObj.Add(downloadingDetail);
        }
        else
        {
            temp = downloadingDetail;
        }
        this.UpdateAllDownload();
    }
Пример #5
0
    void OnComplete(int code, DownloadObj downloadObj)
    {
        Debug.Log("收到下载完成回调!   code:" + code + "  localPath:" + downloadObj.parentPath);
        if (code == 200 || code == 0)
        {
        }
        else
        {
            //downloadAmount.gameObject.SetActive(false);
        }

        downloadObj.OnProgressAction -= OnProgress;
        downloadObj.OnCompleteAction -= OnComplete;
    }
        public UnityDownloadFileHandler(DownloadObj downloadObj) : base(new byte[1024 * 200])
        {
            this.mDownloadObj = downloadObj;

            string dir = Path.GetDirectoryName(mDownloadObj.fullPath);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            _fileStream = new FileStream(downloadObj.fullPath + ".tmp", FileMode.Append, FileAccess.Write);

            mDownloadObj.ChangeDownloadLength((int)_fileStream.Length);
        }
Пример #7
0
        public static void ProxyRe()
        {
            DownloadObj downloadCfg = Config.MainConfig.Download;

            if (!string.IsNullOrWhiteSpace(downloadCfg.DownloadProxyAddress))
            {
                WebProxy proxy = new WebProxy(downloadCfg.DownloadProxyAddress, downloadCfg.DownloadProxyPort);
                if (!string.IsNullOrWhiteSpace(downloadCfg.ProxyUserName))
                {
                    NetworkCredential credential = new(downloadCfg.ProxyUserName, downloadCfg.ProxyUserPassword);
                    proxy.Credentials = credential;
                }
                HttpRequesterAPI.Proxy = proxy;
            }
        }
    private void RemoveDownloadObj(DownloadObj downloadObj)
    {
        DownloadObj temp = GetDownloadObjByID(downloadObj.id);

        if (temp == null)
        {
            return;
        }

        lisDownloadObj.Remove(downloadObj);
        if (downloadObj.currentDownloadState == DownloadState.downloading)
        {
            downloadObj.webDownload.Close();
        }
        this.UpdateAllDownload();
    }
    public void DeleteOneDownload(DownloadObj downloadObj, bool isDeleteLoaclFile)
    {
        RemoveDownloadObj(downloadObj);
        if (isDeleteLoaclFile == true)
        {
            if (File.Exists(downloadObj.parentPath))
            {
                File.Delete(downloadObj.parentPath);
            }

            if (File.Exists(downloadObj.parentPath + ".tmp"))
            {
                File.Delete(downloadObj.parentPath + ".tmp");
            }
        }
    }
    public void StartDownloadOne(DownloadObj downloadObj)
    {
        UnityWeb unityWeb = unityDownloadPool.GetOneGo().GetComponent <UnityWeb>();

        downloadObj.SetWebDownload(unityWeb);
        if (downloadObj.sDownloadFileResult.contentLength == 0)
        {
            downloadObj.OnGetFileSizeAction = (int code, DownloadObj obj) =>
            {
                Debug.Log("获取下载的文件大小成功!code:" + code + " size:" + obj.sDownloadFileResult.contentLengthStr);
                if (code == 200 || code == 0)
                {
                    this.AddDownloadObj(downloadObj);
                    unityWeb.DownloadFile(obj);
                }
            };
            unityWeb.DownloadFileSize(downloadObj);
        }
        else
        {
            Debug.Log("有下载过,直接开始下载,已下载:" + downloadObj.sDownloadFileResult.downloadedLengthStr);
            unityWeb.DownloadFile(downloadObj);
        }
    }
Пример #11
0
 public void DownloadFile(DownloadObj downloadObj)
 {
     this.mDownloadObj = downloadObj;
     StartCoroutine(DownloadFileHandler());
 }