コード例 #1
0
        /// <summary>
        /// Download fileList from rootUrl.
        /// if fileList entry is downloaded once, it doesn't retryed even even if the rootUrl changes when readOnly flag is true
        /// </summary>
        /// <param name="srcListRoot">Source list root.</param>
        /// <param name="fileList">File list.</param>
        /// <param name="callback">Callback.</param>
        /// <param name="retryCount">Retry count.</param>
        public void BeginDownload(string rootUrl, IEnumerable<string> fileList, Action<Exception> callback)
        {
            this.srcRoot = rootUrl;
            step = DownloadStep.Null;
#if UNITY_WEBGL
            if (webGL != null && webGL.IsBusy)
            {
                log.Warn("Download is already begun");
                return;
            }
#else
            if (web != null)
            {
                log.Warn("Download is already begun");
                return;
            }
            DirUtil2.CreateDirectory(GetCacheRoot());
#endif
            onComplete = callback;
            InitTags(fileList);
            SetFiles(fileList, preserveProgress);
            DownloadNext();
        }
コード例 #2
0
        private void OnDownloadFileCallback(object sender, AsyncCompletedEventArgs e)
        {
            FileCallbackParam param = e.UserState as FileCallbackParam;
            //      LogDebug ("FileCallback {0}", param.src);
#if TEST
            if (rand.Next(10) < 5) {
                //          DeleteFile (param.dst);
                WebDownloadFails (new System.Exception (param.dst));
            } else
#endif
            if (e.Error != null)
            {
                //          DeleteFile (param.dst);
                log.Error(e.Error, param.src);
                WebDownloadFails(e.Error);
            }
            else if (e.Cancelled)
            {
                //          DeleteFile (param.dst);
                WebDownloadFails(new InvalidOperationException("Download is canceled"));
            }
#if !UNITY_WEBGL
            else if (unzipException != null)
            {
                log.Error(param.src);
                UnzipFails(unzipException);
            }
#endif
            else
            {
                LogDebug("Download complete: {0} ", param.dst);
                try
                {
                    SetNoBackUpFlag(param.dst);
                    string[] split = SplitVersion(param.dst);
#if !UNITY_WEBGL
                    if (split[0].Is(FileType.Zip))
                    {
                        unzipTargetDir = GetCacheRoot();
                        DirUtil2.CreateDirectory(unzipTargetDir);
                        if (unzipQueue != null)
                        {
                            unzipQueue.Add(param.dst, unzipTargetDir, OnUnzipComplete);
                        }
                    }
                    else
                    {
                        File.Move(param.dst, split[0]);
                    }
#endif
                    filesDownloaded.Add(filesToDownload.Dequeue());
                    fileProgress = 0;
                    retryLeft = retry;
                    DownloadNext();
                }
                catch (Exception ex)
                {
                    WebDownloadFails(ex);
                }
            }
        }