private void DownloadNext() { webException = null; #if !UNITY_WEBGL unzipException = null; #endif if (filesToDownload.Count > 0) { string filename = filesToDownload.Peek(); downloadSrcPath = PathUtil.Combine(srcRoot, filename); fileProgress = 0; SetStep(DownloadStep.Downloading); try { #if UNITY_WEBGL log.Debug("Download {0}", downloadSrcPath); webGL.DownloadFile(downloadSrcPath, new FileCallbackParam(downloadSrcPath, null)); #else LogDebug("Download {0}\n\tAt {1}", downloadSrcPath, downloadDstPath); downloadDstPath = GetAbsolutePath(filename); SetNoBackUpFlag(downloadDstPath); web.DownloadFileAsyncEx(new Uri(downloadSrcPath), downloadDstPath, new FileCallbackParam(downloadSrcPath, downloadDstPath)); #endif } catch (Exception ex) { WebDownloadFails(ex); } } #if UNITY_WEBGL else { Complete(DownloadStep.Done); }
/// <summary> /// Gets the file from remote /// </summary> /// <param name="url">URL.</param> /// <param name="callback">Callback. fileinfo is null if file doesn't exist locally</param> private void GetRemote(string url, Action <FileInfo> callback) { lock (callbacks) { callbacks.Add(url, callback); if (callbacks.GetCount(url) > 1) { return; } } string localPath = pathConv.Convert(url); FileInfo localFile = new FileInfo(localPath); if (localFile.Exists) { List <Action <FileInfo> > clist = null; lock (callbacks) { clist = callbacks.GetSlot(url); callbacks.Remove(url); } foreach (Action <FileInfo> c in clist) { c(localFile); } } else { log.Debug("Access remote asset {0}", url); string tmpPath = localPath + ".tmp"; WebDownloader web = new WebDownloader(); web.Timeout = AssetCache.TIMEOUT; web.DownloadFileCompleted += OnDownloadFileCallback; web.DownloadFileAsyncEx(new Uri(url), tmpPath, new DownloadCallbackParam(web, url, localPath, tmpPath)); } }