示例#1
0
        /// <summary>
        /// 获取文件
        /// </summary>
        /// <param name="sAuthor"></param>
        /// <param name="sProjectName"></param>
        /// <param name="sOnlineFileName"></param>
        /// <param name="sOutputPath"></param>
        /// <returns></returns>
        public static bool getLastReleaseFile(string sAuthor, string sProjectName, string sOnlineFileName, string sOutputPath)
        {
            string sVer = getLastReleaseVersion(sAuthor, sProjectName);

            if (sVer.IsBlank())
            {
                return(false);
            }

            string sUrl = string.Format("https://github.com/{0}/{1}/releases/download/{2}/{3}", sAuthor, sProjectName, sVer, sOnlineFileName);
            bool   bRet = (bool)DownloadFileHepler.Start(sUrl, sOutputPath, RetryNum: 5);

            return(bRet);
        }
示例#2
0
        /// <summary>
        /// 启动
        /// </summary>
        public async Task <double> Start(UpdateProgressNotify pFunc = null)
        {
            Prepare(pFunc);
            string sFilePath = GetTmpFilePath();

            if (sFilePath.IsBlank())
            {
                return(-1);
            }

            await DownloadFileHepler.StartAsync(TEST_URL, sFilePath, null, UpdateDownloadNotify, CompleteDownloadNotify, null, 3);

            RemoveTmpFile();
            return(DownloadSpeed);
        }
示例#3
0
        public static bool Download(string[] pTsUrls, string sOutFile, ProgressNotify pFunc, HttpHelper.ProxyInfo Proxy = null)
        {
            if (pTsUrls == null || pTsUrls.Count() <= 0)
            {
                return(false);
            }

            if (System.IO.File.Exists(sOutFile))
            {
                System.IO.File.Delete(sOutFile);
            }

            int iCount = pTsUrls.Count();

            for (int i = 0; i < iCount; i++)
            {
                if (!pFunc(i, iCount))
                {
                    return(false);
                }

                bool bRet = true;
                for (int j = 0; j < 100; j++)
                {
                    bRet = (bool)DownloadFileHepler.Start(pTsUrls[i], sOutFile, bAppendFile: true, Timeout: 3 * 1000, Proxy: Proxy);
                    if (!pFunc(i, iCount))
                    {
                        return(false);
                    }
                    if (bRet)
                    {
                        break;
                    }
                }
                if (!bRet)
                {
                    return(false);
                }
            }
            pFunc(iCount, iCount);
            return(true);
        }
示例#4
0
        public static bool Download(string[] pTsUrls, string sOutFile, ProgressNotify pFunc, ref string errmsg, HttpHelper.ProxyInfo Proxy = null)
        {
            if (pTsUrls == null || pTsUrls.Count() <= 0)
            {
                return(false);
            }

            if (System.IO.File.Exists(sOutFile))
            {
                System.IO.File.Delete(sOutFile);
            }

            int iCount = pTsUrls.Count();

            long [] fileLengths = DownloadFileHepler.GetAllFileLengths(pTsUrls);
            long    allSize     = 0;

            foreach (long item in fileLengths)
            {
                allSize += item;
                if (item <= 0)
                {
                    allSize = 0;
                    break;
                }
            }
            if (allSize <= 0)
            {
                errmsg = "Get file length failed.";
                return(false);
            }

            if (!pFunc(allSize, 0, 0, null))
            {
                return(false);
            }

            DownloadData data = new DownloadData();

            data.AllSize             = allSize;
            data.AlreadyDownloadSize = 0;
            data.Func = pFunc;

            for (int i = 0; i < iCount; i++)
            {
                bool bRet = true;
                for (int j = 0; j < 3; j++)
                {
                    bRet = (bool)DownloadFileHepler.Start(pTsUrls[i], sOutFile, data, bAppendFile: true, Timeout: 3 * 1000, Proxy: Proxy, RetryNum: 3, UpdateFunc: UpdateDownloadNotify);
                    if (!bRet)
                    {
                        continue;
                    }

                    data.AlreadyDownloadSize += fileLengths[i];
                    break;
                }
                if (!bRet)
                {
                    errmsg = "Download some part-files failed.";
                    return(false);
                }
            }
            pFunc(allSize, allSize, 0, null);
            return(true);
        }