Esempio n. 1
0
        /// <summary>
        /// 获得或创建一个闲置的下载
        /// </summary>
        HttpAsyDownload GetIdleDownload(bool is_create)
        {
            lock (lock_obj_)
            {
                for (int i = 0; i < downloads_.Count; ++i)
                {
                    if (downloads_[i].IsDone)
                    {
                        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);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///   下载
        /// </summary>
        bool Download(string assetbundlename)
        {
            lock (lock_obj_)
            {
                var ab = resources_manifest_.Find(assetbundlename);
                if (ab == null)
                {
                    Debug.LogWarning("AssetBundleDownloader.Download - AssetBundleName is invalid.");
                    return(true);
                }

                string file_name = ab.IsCompress ?
                                   Compress.GetCompressFileName(assetbundlename) : assetbundlename;
                if (!IsDownLoading(file_name))
                {
                    HttpAsyDownload d = GetIdleDownload(true);
                    if (d == null)
                    {
                        return(false);
                    }

                    d.Start(Root, file_name, _DownloadNotify, _DownloadError);
                }

                return(true);
            }
        }
Esempio n. 3
0
    /// <summary>
    ///   下载
    /// </summary>
    bool Download(string file_name)
    {
        download_ = new HttpAsyDownload(URL);
        download_.Start(RootPath, file_name, _OnDownloadNotifyCallback, _OnDownloadErrorCallback);

        return(true);
    }
        /// <summary>
        ///
        /// </summary>
        void _DownloadNotify(HttpAsyDownload d, long size)
        {
            lock (lock_obj_)
            {
                CompletedSize += size;

                if (d.IsDone)
                {
                    DownloadSucceed(d.LocalName);

                    if (UncompleteDownloadList.Count == 0 && DownloadingList.Count == 0)
                    {
                        IsDone = true;
                    }
                    else
                    {
                        var assetbundlename = GetImcomplete();
                        if (!string.IsNullOrEmpty(assetbundlename))
                        {
                            Download(d, assetbundlename);
                        }
                    }
                }
            }
        }
Esempio n. 5
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);
        }
    }
        /// <summary>
        ///   开始下载
        /// </summary>
        public bool Start(string root
                          , List <string> assetbundles
                          , ResourcesManifest resources_manifest)
        {
            Abort();

            if (resources_manifest == null)
            {
                Error(emErrorCode.ParameterError);
                return(false);
            }
            if (assetbundles == null || assetbundles.Count == 0)
            {
                IsDone = true;
                return(true);
            }

            IsDone    = false;
            ErrorCode = emErrorCode.None;

            Root = root;
            resources_manifest_    = resources_manifest;
            UncompleteDownloadList = assetbundles;
            CompleteDownloadList.Clear();
            FailedDownloadList.Clear();

            //统计下载数据
            TotalSize     = 0;
            CompletedSize = 0;
            for (int i = 0; i < UncompleteDownloadList.Count; ++i)
            {
                var ab = resources_manifest_.Find(UncompleteDownloadList[i]);
                if (ab != null)
                {
                    if (ab.IsCompress)
                    {
                        TotalSize += ab.CompressSize;
                    }
                    else
                    {
                        TotalSize += ab.Size;
                    }
                }
            }

            //开始下载
            for (int i = 0; i < System.Net.ServicePointManager.DefaultConnectionLimit; ++i)
            {
                HttpAsyDownload d = new HttpAsyDownload(URL);
                downloads_.Add(d);
                var assetbundlename = GetImcomplete();
                if (!string.IsNullOrEmpty(assetbundlename))
                {
                    Download(downloads_[i], assetbundlename);
                }
            }

            return(true);
        }
Esempio n. 7
0
        /// <summary>
        ///   是否正在下载
        /// </summary>
        public bool IsDownLoading(string file_name)
        {
            HttpAsyDownload ad = downloads_.Find(delegate(HttpAsyDownload d)
            {
                return(d.LocalName == file_name);
            });

            return(ad != null);
        }
Esempio n. 8
0
 /// <summary>
 ///
 /// </summary>
 void _DownloadNotify(HttpAsyDownload d, long size)
 {
     lock (lock_obj_)
     {
         if (d.IsDone)
         {
             DownloadSucceed(d.LocalName);
             DownloadAll();
         }
         CompletedSize += size;
         UpdateState();
     }
 }
Esempio n. 9
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();
     }
 }
        /// <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);
            }
        }
Esempio n. 12
0
 /// <summary>
 ///   下载错误回调
 /// </summary>
 void _OnDownloadErrorCallback(HttpAsyDownload d)
 {
     IsDone    = true;
     ErrorCode = d.ErrorCode;
 }
Esempio n. 13
0
 /// <summary>
 ///   下载进度通知回调
 /// </summary>
 void _OnDownloadNotifyCallback(HttpAsyDownload d, long size)
 {
     CompletedSize = d.CompletedLength;
     TotalSize     = d.Length;
     UpdateState();
 }
Esempio n. 14
0
 void OnDownloadnotifyCallback(HttpAsyDownload l, long size)
 {
     completeSize = l.completeLength;
     totalSize    = l.length;
     OnUpdateState();
 }
Esempio n. 15
0
 private void OnDownload(string fileName)
 {
     m_Download = new HttpAsyDownload(url);
     m_Download.Start(path, fileName, OnDownloadnotifyCallback, OnDownloadErrorCallback);
 }
Esempio n. 16
0
 void OnDownloadErrorCallback(HttpAsyDownload l)
 {
     isDone    = false;
     errorCode = l.errorCode;
 }