Example #1
0
        public void StartDownload_CalledWithUrl_ReturnsOperation()
        {
            string url = @"https://www.google.com";
            var    op  = BackgroundDownloads.StartDownload(url);

            Assert.That(op.ID != -1, "DownloadOperation.ID should not be -1!");
        }
Example #2
0
 /// <summary>
 /// 取消下载
 /// </summary>
 public void CancelDownload()
 {
     if (downloadOperation != null)
     {
         BackgroundDownloads.CancelDownload(downloadOperation);
     }
 }
Example #3
0
        public void StartDownload_CalledWithOptions_CorrectDestinationPath()
        {
            string url = @"https://www.google.com/test.bundle";

            var options = new BackgroundDownloadOptions(url);
            var op      = BackgroundDownloads.StartDownload(options);

            Assert.AreEqual(Path.Combine(BackgroundDownloadOptions.DEFAULT_DOWNLOAD_PATH, "test.bundle"), op.DestinationPath);
        }
Example #4
0
        public void StartDownload_CalledWithStringEmpty_DoesntThrow()
        {
            string url = string.Empty;

            Assert.Throws <ArgumentException>(() =>
            {
                BackgroundDownloads.StartDownload(url);
            });
        }
Example #5
0
        public void StartDownload_CalledWithNull_ThrowsArgumentNullException()
        {
            string url = null;

            Assert.Throws <ArgumentException>(() =>
            {
                BackgroundDownloads.StartDownload(url);
            });
        }
 IEnumerator StartCheck()
 {
     for (int i = 1; i <= 3; i++)
     {
         string filePath = Application.persistentDataPath.ToString() + "/" + i.ToString() + ".mp4";
         if (!System.IO.File.Exists(filePath))
         {
             dload = BackgroundDownloads.StartOrContinueDownload(@URL + i.ToString() + ".mp4");
         }
     }
     yield return(new WaitForSeconds(30));
 }
Example #7
0
        public void StartDownload_OptionsWithCustomDestinationPath_CorrectDestinationPath()
        {
            string url = @"https://www.google.com/test.bundle";

            var destinationPath = Path.Combine("D:", "MyPath");

            var options = new BackgroundDownloadOptions(url).SetDestinationPath(destinationPath);
            var op      = BackgroundDownloads.StartDownload(options);

            var expectedPath = Path.Combine(destinationPath, "test.bundle");

            Assert.AreEqual(expectedPath, op.DestinationPath);
        }
Example #8
0
        public void StoragePermission(string s)
        {
            downloadOperation = BackgroundDownloads.GetDownloadOperation("https://qianxi.fahaxiki.cn/AB/OnlineAB/AF-ABForServer/APPInfo.txt");
            BackgroundDownloadOptions backgroundDownloadOptions = new BackgroundDownloadOptions("https://qianxi.fahaxiki.cn/AB/OnlineAB/AF-ABForServer/APPInfo.txt", PathTool.PersistentDataPath + "APPInfo.txt");

            if (downloadOperation == null ||
                (downloadOperation != null && downloadOperation.Status == DownloadStatus.Successful))
            {
                downloadOperation = BackgroundDownloads.StartDownload(backgroundDownloadOptions);
            }
            else if (downloadOperation != null && downloadOperation.Status != DownloadStatus.Successful)
            {
                //断点续存
                downloadOperation = BackgroundDownloads.StartOrContinueDownload(backgroundDownloadOptions);
            }
            Debug.Log("downloadOperation是否为空:" + (downloadOperation == null));
        }
Example #9
0
        /// <summary>
        /// 下载完成
        /// </summary>
        public void DownloadComplete()
        {
            switch (downloadOperation.Status)
            {
            case DownloadStatus.Failed:
                //下载失败
                LastPro = CurPro;
                if (WebRequestCount <= 3)
                {
                    DownManager.Instance.DebugDownError(WebRequestCount, httpInfo.m_srcUrl, downloadOperation.Error);
                    WebRequestCount += 1;
                    CancelDownload();
                    BackgroundDownloadOptions backgroundDownloadOptions = new BackgroundDownloadOptions(httpInfo.m_srcUrl, m_saveFilePath);
                    downloadOperation = BackgroundDownloads.StartDownload(backgroundDownloadOptions);
                }
                else
                {
                    DownManager.Instance.RemoveAndFinish(httpInfo.m_srcUrl);
                    CancelDownload();
                    downResult = DownStatus.Fail;
                    downError  = downloadOperation.Error;
                    httpInfo.processEvent.InvokeGracefully(httpInfo, CurPro, true, downResult, downError);
                    m_isStartDownload = false;
                    DownloadFinish();
                }
                break;

            case DownloadStatus.Successful:
                //下载成功
                //AFLogger.d("下载完成:" + downloadOperation.DestinationPath);
                //AFLogger.d("下载完成后是否存在路径:" + m_saveFilePath + " " + FileHelper.JudgeFilePathExit(m_saveFilePath));
                CurPro  = 1;
                LastPro = CurPro;
                DownManager.Instance.RemoveAndFinish(httpInfo.m_srcUrl);
                downResult        = DownStatus.Sucess;
                downError         = "";
                m_isStartDownload = false;
                DownloadFinish();
                httpInfo.processEvent.InvokeGracefully(httpInfo, CurPro, true, downResult, downError);
                break;
            }
        }
Example #10
0
        public void StartWebRequest()
        {
            WebRequestCount = 1;
            if (string.IsNullOrEmpty(httpInfo.m_srcUrl))
            {
                downResult = DownStatus.Fail;
                downError  = "下载地址为空";
                DownloadFinish();
                return;
            }
            if (string.IsNullOrEmpty(httpInfo.m_savePath))
            {
                downResult = DownStatus.Fail;
                downError  = "保存地址为空";
                DownloadFinish();
                return;
            }
            m_saveFilePath = httpInfo.m_savePath;
            if (WebRequestCount == 1)
            {
                LastPro = GetProcess();
            }

            FileHelper.DeleteFile(m_saveFilePath);
            downloadOperation = BackgroundDownloads.GetDownloadOperation(httpInfo.m_srcUrl);
            BackgroundDownloadOptions backgroundDownloadOptions = new BackgroundDownloadOptions(httpInfo.m_srcUrl, m_saveFilePath);

            if (downloadOperation == null ||
                (downloadOperation != null && downloadOperation.Status != DownloadStatus.Paused))
            {
                downloadOperation = BackgroundDownloads.StartDownload(backgroundDownloadOptions);
            }
            else if (downloadOperation != null && downloadOperation.Status == DownloadStatus.Paused)
            {
                //断点续存
                downloadOperation = BackgroundDownloads.StartOrContinueDownload(backgroundDownloadOptions);
            }
            m_isStartDownload = true;
        }
Example #11
0
 public void CancelDownload_CalledWithNull_DoesntThrow()
 {
     BackgroundDownloads.CancelDownload(null);
 }