private IEnumerator Download(string url, OnDownloadFinish onFinish) { WWW www = new WWW(url); yield return(www); if (onFinish != null) { onFinish(www); } www.Dispose(); }
public void DownloadFile(string url, OnDownloadFinish callback) { Debug.Log("下载文件 " + url); WWW www = new WWW(url + "?time=" + System.DateTime.Now.Ticks + "&r=" + Random.Range(int.MinValue, int.MaxValue)); while (true) { if (www.isDone || !string.IsNullOrEmpty(www.error)) { break; } } if (string.IsNullOrEmpty(www.error)) { callback(www); } }
public IEnumerator DownloadFile(string url, OnDownloadFinish callback) { CheckNetStatus(); string u = FileUtils.url + "/" + url; WWW www = new WWW(u + "?time=" + System.DateTime.Now.Ticks + "&r=" + Random.Range(int.MinValue, int.MaxValue)); tip = "下载文件 " + u + " " + www.progress; #if UNITY_EDITOR Debug.Log(tip); #endif float timeStart = Time.time; yield return(www); networkSpeed = www.bytesDownloaded / (Time.time - timeStart); if (!string.IsNullOrEmpty(www.error)) { Debug.LogError(www.error); if (FileUtils.IsAllCDNCantDownload()) { string msg = string.Format("网络错误(error : 801)\r\n{0}", www.responseHeaders.ContainsKey("STATUS") ? www.responseHeaders["STATUS"] : www.error); UIMessageBoxHelper.Show(msg, () => { ReStart(); } ); yield return(new WaitForSeconds(4f)); } else { FileUtils.ChangeCDNState(); StartCoroutine(DownloadFile(url, callback)); Debug.Log(tip); } } if (www.isDone && string.IsNullOrEmpty(www.error)) { callback(www); } }
public void HideImage() { ImageData = null; OnDownloadFinish?.Invoke(this, new EventArgs()); }
public async Task <bool> DownloadImage(Advert advert, string ssid, int advertID, string advertURL, Cookie PHPSESSIDPcookie) { if (advert == null) { Debug.Write(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + " => advert == null"); return(false); } if ((advert.PhoneImageByteArray?.Length ?? 0) > 0) { Debug.Write(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + " => advert.PhoneImageByteArray exists"); ImageData = ImageSource.FromStream(() => new MemoryStream(advert.PhoneImageByteArray)); OnDownloadFinish?.Invoke(this, new EventArgs()); return(true); } if (ssid == null || advertID == 0 || advertURL.Length == 0 || PHPSESSIDPcookie == null) { Debug.Write(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + " => ssid == null || adrverID == 0 || advertURL.Length == 0"); return(false); } _session = new Guid().ToString(); var localSession = _session; var inputData = new Dictionary <string, string>() { { "oid", advertID.ToString() }, { "ssid", ssid }, }; var BodyResult = await GetWeb.PostWebPage("http://www.rzeszowiak.pl/telefon/", inputData, advertURL, new CookieCollection() { PHPSESSIDPcookie }); if (BodyResult.Length == 0) { Debug.Write("RzeszowiakImageContainer => DownloadImage => BodyResult.Length == 0"); return(false); } Base64ToImage(BodyResult.ToString().Replace("data:image/jpeg;base64,", ""), out ImageSource imageData, out byte[] byteArray); ImageData = imageData; advert.PhoneImageByteArray = byteArray; BodyResult.Clear(); if (localSession == _session) { OnDownloadFinish?.Invoke(this, new EventArgs()); } else { Debug.Write("RzeszowiakImageContainer => DownloadImage() => localSession != _session"); } return(true); }