示例#1
0
 void Instance_DownloadRemoved(object sender, DownloaderEventArgs e)
 {
     this.Dispatcher.BeginInvoke(new Action(() =>
     {
         DownLoadFileInfo item = mapDownloadToObj[e.Downloader] as DownLoadFileInfo;
         if (item != null)
         {
             DownloadingList.Remove(item);
             mapDownloadToObj[e.Downloader] = null;
             mapObjToDownload[item]         = null;
         }
     }
                                            ));
 }
示例#2
0
        private void AddDownload(Downloader d)
        {
            string ext = System.IO.Path.GetExtension(d.LocalFile);

            DownLoadFileInfo dInfo = new DownLoadFileInfo();

            dInfo.FileName              = System.IO.Path.GetFileName(d.LocalFile);
            dInfo.FileSize              = ByteFormatter.ToString(d.FileSize);
            dInfo.DownloadProcess       = d.Progress;
            dInfo.FileLink              = d.ResourceLocation.URL;
            dInfo.FileAlbum             = d.ResourceLocation.Password;
            dInfo.DownloadState         = d.State;
            mapDownloadToObj[d]         = dInfo;
            mapObjToDownload[dInfo]     = d;
            mapObjToCurrentState[dInfo] = d.State;
            DownloadingList.Add(dInfo);
        }
        /// <summary>
        /// 下载完成
        /// </summary>
        void DownloadSucceed(string file_name)
        {
            lock (lock_obj_)
            {
                bool   is_compress     = Compress.IsCompressFile(file_name);
                string assetbundlename = is_compress ?  Compress.GetDefaultFileName(file_name) : file_name;
                CompleteDownloadList.Add(assetbundlename);
                DownloadingList.Remove(assetbundlename);

                //判断是否需要解压文件
                if (is_compress)
                {
                    // 解压文件
                    string in_file  = Root + "/" + file_name;
                    string out_file = Root + "/" + assetbundlename;
                    Compress.DecompressFile(in_file, out_file);
                    // 删除压缩包
                    System.IO.File.Delete(in_file);
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        void _DownloadError(HttpAsyDownload d)
        {
            lock (lock_obj_)
            {
                //加入失败列表
                string file_name       = d.LocalName;
                bool   is_compress     = Compress.IsCompressFile(file_name);
                string assetbundlename = is_compress ? Compress.GetDefaultFileName(file_name) : file_name;
                FailedDownloadList.Add(assetbundlename);
                DownloadingList.Remove(assetbundlename);

                if (d.ErrorCode == HttpAsyDownload.emErrorCode.DiskFull)
                {
                    Error(emErrorCode.DiskFull, assetbundlename);
                }
                else
                {
                    Error(emErrorCode.DownloadFailed, assetbundlename);
                }
            }
        }
        /// <summary>
        ///   下载
        /// </summary>
        bool Download(HttpAsyDownload d, string assetbundlename)
        {
            lock (lock_obj_)
            {
                if (string.IsNullOrEmpty(assetbundlename))
                {
                    return(false);
                }
                var ab = resources_manifest_.Find(assetbundlename);
                if (ab == null)
                {
                    Debug.LogWarning("AssetBundleDownloader.Download - AssetBundleName is invalid.");
                    return(true);
                }

                DownloadingList.Add(assetbundlename);

                string file_name = ab.IsCompress ? Compress.GetCompressFileName(assetbundlename) : assetbundlename;
                d.Start(Root, file_name, _DownloadNotify, _DownloadError);
                return(true);
            }
        }