/// <summary> /// 初始化. /// </summary> /// <param name="iDownloadUrl">下载Url.</param> /// <param name="iOnStart">开始事件委托.</param> /// <param name="iOnSuccessed">成功事件委托.</param> /// <param name="iOnFailed">失败事件委托.</param> /// <param name="iType">下载对象类型.</param> public void Init( string iDownloadUrl, OnStart iOnStart, OnSuccessedByUrl iOnSuccessed, OnFailedByUrl iOnFailed, TargetType iType = TargetType.Bundle) { string urlTmp = iDownloadUrl; int lastIndex = urlTmp.LastIndexOf("/"); this.DownloadBaseUrl = urlTmp.Substring(0, lastIndex); this.FileName = urlTmp.Substring(lastIndex + 1); int index = this.FileName.IndexOf("?"); if (-1 != index) { this.FileName = this.FileName.Substring(0, index); this.FullFileName = string.Format("{0}/{1}", this.DownloadDir, this.FileName); } this.onStart = iOnStart; this.onSuccessedByUrl = iOnSuccessed; this.onFailedByUrl = iOnFailed; this.Retries = ServersConf.GetInstance().NetRetries; this.TimeOut = ServersConf.GetInstance().NetTimeOut * 1000; this.TargetType = iType; if (Directory.Exists(this.DownloadDir) == false) { Directory.CreateDirectory(this.DownloadDir); } }
/// <summary> /// 创建Downloader(Http). /// </summary> /// <param name="iDownloadUrl">下载Url.</param> /// <param name="iOnStart">开始事件委托.</param> /// <param name="iOnSuccessed">成功事件委托.</param> /// <param name="iOnFailed">失败事件委托.</param> /// <param name="iType">下载对象类型.</param> public static HttpDownloader Create( string iDownloadUrl, OnStart iOnStart, OnSuccessedByUrl iOnSuccessed, OnFailedByUrl iOnFailed, TargetType iType = TargetType.Bundle) { HttpDownloader downloader = new HttpDownloader(); if (downloader != null) { downloader.Init(iDownloadUrl, iOnStart, iOnSuccessed, iOnFailed, iType); return(downloader); } else { UtilsLog.Error("Create", "Downloader Create failed!!"); return(null); } }
/// <summary> /// 创建下载器(Url). /// </summary> /// <returns>The downloader by URL.</returns> /// <param name="iDownloadUrl">下载Url.</param> /// <param name="iOnStart">开始事件委托.</param> /// <param name="iOnSuccessed">成功事件委托.</param> /// <param name="iOnFailed">失败事件委托.</param> /// <param name="iType">下载对象类型.</param> public static DownloaderBase CreateDownloaderByUrl(string iUrl, OnStart iOnStart, OnSuccessedByUrl iOnSuccessed, OnFailedByUrl iOnFailed, TargetType iType) { DownloaderBase downloader = null; TDownloadWay downloadWay = ServersConf.GetInstance().DownloadWay; switch (downloadWay) { case TDownloadWay.WWW: { downloader = WWWDownloader.Create( iUrl, iOnStart, iOnSuccessed, iOnFailed, iType); } break; case TDownloadWay.None: case TDownloadWay.Http: default: { downloader = HttpDownloader.Create( iUrl, iOnStart, iOnSuccessed, iOnFailed, iType); } break; } return(downloader); }