Exemplo n.º 1
0
 public DownloadCallbackParam(WebDownloader web, string url, string localPath, string tmpPath)
 {
     this.web       = web;
     this.url       = url;
     this.localPath = localPath;
     this.tmpPath   = tmpPath;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Remove already downloaded files from file list if files are read-only
        /// </summary>
        /// <param name="files">Source list relative to cdn</param>
        private void SetFiles(IEnumerable<string> files, bool preserveFileCount)
        {
            this.webException = null;
#if !UNITY_WEBGL
            this.unzipException = null;
#endif
            filesDownloaded = new List<string>();
            filesToDownload = new Queue<string>();
            foreach (string f in files)
            {
                string file = f.Trim();
                if (readOnly && IsPathTagged(file))
                {
                    filesDownloaded.Add(file);
                }
                else if (!file.IsEmpty())
                {
                    filesToDownload.Enqueue(file);
                }
            }
            tags.Save();

            if (!preserveFileCount)
            {
                filesDownloaded.Clear();
            }
            initialDownloadSize = filesDownloaded.Count;
            totalDownloadSize = filesToDownload.Count + filesDownloaded.Count;

#if UNITY_WEBGL
            webGL.DownloadFileCompleted += OnWWWFileCallback;
            webGL.DownloadProgressChanged += OnWWWProgressCallback;
#else
            web = new WebDownloader();
            web.DownloadFileCompleted += OnDownloadFileCallback;
            web.DownloadProgressChanged += OnProgress;
            web.Timeout = timeoutSec * 1000;

            if (unzipMethod != null)
            {
                this.unzipQueue = new UnzipQueue(unzipMethod);
            }
            else
            {
                this.unzipQueue = null;
            }
#endif
        }
Exemplo n.º 3
0
        /// <summary>
        /// Cleanup connections.
        /// </summary>
        public void Cleanup()
        {
            filesToDownload.Clear();
            filesDownloaded.Clear();
#if UNITY_WEBGL
			if (_webGL != null)
            {
                _webGL.Dispose();
            }
#else
            if (unzipQueue != null)
            {
                unzipQueue.Stop();
                unzipQueue = null;
            }
            if (web != null)
            {
                web.Dispose();
                web = null;
            }
#endif
        }
Exemplo n.º 4
0
        /// <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));
            }
        }