Exemple #1
0
        /// <summary>
        /// 下载完成
        /// </summary>
        void DownloadSucceed(string file_name)
        {
            lock (lock_obj_)
            {
                bool   is_compress = Compress.IsCompressFile(file_name);
                string assetbundle = is_compress ?
                                     Compress.GetDefaultFileName(file_name) : file_name;

                if (ImcompleteDownloads.Contains(assetbundle))
                {
                    ImcompleteDownloads.Remove(assetbundle);
                }
                CompleteDownloads.Add(assetbundle);

                //判断是否需要解压文件
                if (is_compress)
                {
                    // 解压文件
                    string in_file  = Root + "/" + file_name;
                    string out_file = Root + "/" + assetbundle;
                    Compress.DecompressFile(in_file, out_file);
                    // 删除压缩包
                    System.IO.File.Delete(in_file);
                }
            }
        }
Exemple #2
0
    /// <summary>
    /// 获得或创建一个闲置的下载
    /// </summary>
    HttpAsyDownload GetIdleDownload(bool is_create)
    {
        lock (lock_obj_)
        {
            for (int i = 0; i < downloads_.Count; ++i)
            {
                //还在下载队列列的 httpload(状态虽然可用 但逻辑还没处理完)
                if (downloads_[i].IsDone && !ImcompleteDownloads.Contains(downloads_[i].LocalName))
                {
                    return(downloads_[i]);
                }
            }

            if (is_create)
            {
                if (downloads_.Count < System.Net.ServicePointManager.DefaultConnectionLimit)
                {
                    HttpAsyDownload d = new HttpAsyDownload(URL);
                    downloads_.Add(d);
                    return(d);
                }
            }
            return(null);
        }
    }
Exemple #3
0
 /// <summary>
 ///
 /// </summary>
 void _DownloadError(HttpAsyDownload d)
 {
     lock (lock_obj_)
     {
         //从未下载列表中移除
         if (ImcompleteDownloads.Contains(d.LocalName))
         {
             ImcompleteDownloads.Remove(d.LocalName);
         }
         //加入失败列表
         FailedDownloads.Add(d.LocalName);
         DownloadAll();
         UpdateState();
     }
 }