private IEnumerator LoadRawBytesAsync(RawBytesDownloadTask task) { for (int i = 0; i < task.BaseUrls.Length; i++) { using (WWW www = new WWW(task.BaseUrls[i] + task.RelativeUrl)) { yield return(www); if (task.IsCanceled) { yield break; } if (string.IsNullOrEmpty(www.error)) { byte[] bytes = www.bytes; if (bytes != null && bytes.Length > 0) { task.Result(true, bytes); } else { FMLogger.Log("*************raw bytes array error. never should happen"); task.Result(false, null); } this.SendConnectionResume(); yield break; } } } if (!task.IsCanceled) { this.StepFailedPicture(); FMLogger.Log("*************raw bytes dl error .task:" + task.RelativeUrl); task.Result(false, null); } yield break; }
public void LoadRawBytes(RawBytesDownloadTask task) { base.StartCoroutine(this.LoadRawBytesAsync(task)); }
private IEnumerator DownloadPictureWaiter(DownloadPictureTask task) { PictureData pd = task.PictureData; int id = pd.Id; int packId = pd.PackId; int iconState = 0; int lineState = 0; int colorState = 0; int jsonState = 0; string directory = packId.ToString(); string iconPath = id + "i"; string linePath = id.ToString(); string coloredPath = id + "c"; string jsonPath = id + "t"; RawBytesDownloadTask iconTask = null; RawBytesDownloadTask lineTask = null; RawBytesDownloadTask coloredTask = null; WebGetTask jsonTask = null; if (FileHelper.FileExist(directory, iconPath)) { iconState = 1; FMLogger.Log("skip dl icon, already stored"); } else { iconTask = new RawBytesDownloadTask(pd.WebPath.baseUrls, pd.WebPath.icon, delegate(bool success, byte[] bytes) { if (success) { FileHelper.SaveRawBytesToFile(bytes, directory, iconPath); iconState = 1; } else { iconState = -1; } }); } if (FileHelper.FileExist(directory, linePath)) { lineState = 1; FMLogger.Log("skip dl line, already stored"); } else { lineTask = new RawBytesDownloadTask(pd.WebPath.baseUrls, pd.WebPath.lineart, delegate(bool success, byte[] bytes) { if (success) { FileHelper.SaveRawBytesToFile(bytes, directory, linePath); lineState = 1; } else { lineState = -1; } }); } if (pd.FillType == FillAlgorithm.Flood) { if (FileHelper.FileExist(directory, coloredPath)) { colorState = 1; FMLogger.Log("skip dl colormap, already stored"); } else { coloredTask = new RawBytesDownloadTask(pd.WebPath.baseUrls, pd.WebPath.colored, delegate(bool success, byte[] bytes) { if (success) { FileHelper.SaveRawBytesToFile(bytes, directory, coloredPath); colorState = 1; } else { colorState = -1; } }); } } else { colorState = 1; FMLogger.Log("skip dl colormap, not needed anymore"); } if (FileHelper.FileExist(directory, jsonPath)) { jsonState = 1; FMLogger.Log("skip dl json, already stored"); } else { jsonTask = new WebGetTask(pd.WebPath.baseUrls, pd.WebPath.json, delegate(bool success, string tex) { if (success && tex != null) { FileHelper.SaveStringToFile(tex, directory, jsonPath); jsonState = 1; } else { jsonState = -1; } }); } if (iconTask != null) { base.StartCoroutine(this.LoadRawBytesAsync(iconTask)); } if (lineTask != null) { base.StartCoroutine(this.LoadRawBytesAsync(lineTask)); } if (coloredTask != null) { base.StartCoroutine(this.LoadRawBytesAsync(coloredTask)); } if (jsonTask != null) { base.StartCoroutine(this.LoadTextAsync(jsonTask)); } yield return(0); bool wait = true; bool allFilesOk = false; float waitTime = 0f; while (wait) { waitTime += Time.deltaTime; if (waitTime > task.Timeout) { if (colorState == 0 && coloredTask != null) { coloredTask.Cancel(); } if (lineState == 0 && lineTask != null) { lineTask.Cancel(); } if (iconState == 0 && iconTask != null) { iconTask.Cancel(); } if (jsonState == 0 && jsonTask != null) { jsonTask.Cancel(); } wait = false; } else if (iconState == -1 || lineState == -1 || colorState == -1 || jsonState == -1) { allFilesOk = false; wait = false; } else if (iconState == 1 && lineState == 1 && colorState == 1 && jsonState == 1) { allFilesOk = true; wait = false; } yield return(0); } if (allFilesOk) { FMLogger.Log("pic dl complete " + pd.Id); PictureData result = SharedData.Instance.AddPictureToPack(pd); task.Result(true, result); } else { FMLogger.Log("pic dl error " + pd.Id); task.Result(false, null); } yield return(0); yield break; }