public static IEnumerator GetResponse(WWW www, CancellationToken cancellationToken, string expectedHash = null, Action<float> reportProgress = null)
{
var monitor = new WWWConnectionMonitor(www);
var progress = 0.0f;
while (!www.isDone && !cancellationToken.IsCanceled)
{
monitor.AssertLiveliness();
if (reportProgress != null && www.progress != progress)
{
progress = www.progress;
reportProgress(progress);
}
yield return null;
}
if (reportProgress != null)
{
reportProgress(www.progress);
}
if (cancellationToken.IsCanceled) yield break;
if (!string.IsNullOrEmpty(www.error))
{
throw new WwwErrorException(www);
}
if (expectedHash != null)
{
using (var md5 = MD5.Create())
{
if (expectedHash != FileHelper.GetFingerprint(md5.ComputeHash(www.bytes)))
{
throw new WwwErrorException(HttpStatusCode.ExpectationFailed);
}
}
}
}