Esempio n. 1
0
    void StartDownload()
    {
        //string url = "http://woda.jijiagames.com/cdn/wod_android_1.0.0.227915_200321_1804_pr2v6_update/";
        string url = "https://down.qq.com/wod/cdn/wod_android_1.0.0.227915_200321_1804_pr2v6_update/";

        Debug.Log(Application.persistentDataPath);
        List <string> files = new List <string>()
        {
            "0e3b671686680b573737c89a6f2c251f.zip",
            "0f4f049806f0e5f6f4ba2583ae7efb07.zip",
            "1c81d60584f69db4c294699421c84549.zip",
            "1c67094f3671f16a636c77636e979a98.zip",
            "1ccfb16671d241eaacc145f55b923252.zip",
            "2a26c158c6c4533dcfd04285a77f8369.zip",
            "2d472e915235e8174e1a1f3fc74b0656.zip",
            "2f631b41f6f31db87da7d941fb0027fe.zip",
            "6a6783933b4a8d5de63a3bdc53878289.zip"
        };

        for (int i = 0; i < files.Count; ++i)
        {
            DownLoadTask task = new DownLoadTask();
            task.url  = url + files[i];
            task.path = task.url.Replace(url, Application.persistentDataPath + "/");
            DownLoadManager.GetInstance().DoTask(task);
        }

        StartCoroutine(WaitDownLoad());
        SetState(DownloadState.Download);
    }
    /// <summary>
    /// 开始下载
    /// </summary>
    public static void StartDown()
    {
        int count = GetDownLoadingTaskCount();

        if (count >= MaxDownLoadCount)
        {
            return;
        }

        for (int i = 0; i < s_DownLoadTasks.Count; ++i)
        {
            DownLoadTask task = s_DownLoadTasks[i];
            if (null == task)
            {
                continue;
            }

            if (task.IsStartDown == false)
            {
                if (count < MaxDownLoadCount)
                {
                    task.StartDown();
                    ++count;
                }
                else
                {
                    break;
                }
            }
        }
    }
Esempio n. 3
0
    public static void AddDownLoadTask(string path, Action <WWW, int> callback, int udata = 0)
    {
        path = remoteurl + path;
        DownLoadTask task = new DownLoadTask(path, false, callback, udata);

        GameEnter.instance.queue.Enqueue(task);
    }
Esempio n. 4
0
    public void AddDownLoadTask(string path, Action <WWW, int> callback, int udata = 0)
    {
        DownLoadTask task = new DownLoadTask(path, false, callback, udata);

        GameEnter.instance.queue.Enqueue(task);
        GameEnter.NeedDownLoadCount++;
    }
Esempio n. 5
0
 /// <summary>
 /// 设置下载参数
 /// </summary>
 public void SetDownLoadTask(DownLoadTask task)
 {
     if (task == null)
     {
         return;
     }
     m_task = task;
 }
Esempio n. 6
0
    /// <summary>
    /// 下载文件
    /// </summary>
    /// <param name="url"></param>
    /// <param name="file"></param>
    /// <returns></returns>
    public DownLoadTask DownLoad(string url, string file)
    {
        DownLoadTask downLoadTask = new DownLoadTask();

        downLoadTask.url  = url;
        downLoadTask.path = file;
        DoTask(downLoadTask);
        return(downLoadTask);
    }
Esempio n. 7
0
 /// <summary>
 /// 执行任务
 /// </summary>
 /// <param name="downLoadTask"></param>
 /// <returns></returns>
 public DownLoadTask DoTask(DownLoadTask downLoadTask)
 {
     lock (_object)
     {
         _taskQueue.Enqueue(downLoadTask);
     }
     Resume();
     return(downLoadTask);
 }
Esempio n. 8
0
    // 下载服务器列表
    private void DownLoadServerList()
    {
        DownLoadQueue.SetFinishNotify(DownLoadServerListFinish);
        DownLoadTask task = new DownLoadTask(ConstantData.ServerListServerPath,
                                             ConstantData.ServerListSavePath,
                                             ConstantData.ServerListFile, null);

        DownLoadQueue.AddDownTask(task);
        DownLoadQueue.StartDown();
    }
    public static void AddDownTaskImmediate(string serverPath, string localPath, string name, DownLoadFinishNotify onFinish, DownLoadProgress onProgress = null)
    {
        SetFinishNotify(onFinish);

        DownLoadTask task = new DownLoadTask(serverPath, localPath, name, onProgress);

        AddDownTask(task);

        StartDown();
    }
Esempio n. 10
0
 private void Update()
 {
     while (_doneQueue.Count > 0)
     {
         DownLoadTask task = _doneQueue.Dequeue();
         if (task.callBack != null)
         {
             task.callBack(task);
         }
     }
 }
Esempio n. 11
0
 /// <summary>
 /// 完成指定下载任务
 /// </summary>
 public static DownLoadTask FindSameTask(DownLoadTask task)
 {
     foreach (DownLoadTask Task in m_lTask)
     {
         if (Task != null && Task.EqualTask(task) == true)
         {
             return(Task);
         }
     }
     return(null);
 }
    /// <summary>
    /// 完成指定下载任务
    /// </summary>
    public static DownLoadTask FindSameTask(DownLoadTask task)
    {
        for (int i = 0; i < s_DownLoadTasks.Count; ++i)
        {
            if (s_DownLoadTasks[i] != null && s_DownLoadTasks[i].EqualTask(task) == true)
            {
                return(s_DownLoadTasks[i]);
            }
        }

        return(null);
    }
Esempio n. 13
0
 public static void AddDownTask(DownLoadTask Task)
 {
     if (Task == null)
     {
         return;
     }
     if (m_lTask.Contains(Task) == true)
     {
         return;
     }
     m_lTask.Add(Task);
 }
    /// <summary>
    /// 完成指定下载任务
    /// </summary>
    private static DownLoadTask FindTask(int downid)
    {
        for (int i = 0; i < s_DownLoadTasks.Count; ++i)
        {
            DownLoadTask task = s_DownLoadTasks[i];
            if (task != null && task.m_DownID == downid)
            {
                return(task);
            }
        }

        return(null);
    }
    public static void AddDownTask(DownLoadTask task)
    {
        if (task == null)
        {
            return;
        }

        if (s_DownLoadTasks.Contains(task))
        {
            return;
        }

        s_DownLoadTasks.Add(task);
    }
Esempio n. 16
0
    private void DownLoadFile()
    {
        Action <HotUpdateRessMgr.DecompressionOrDownInfo> checkFileed = downloadInfo =>
        {
            Debug.Log("检查需要下载的文件个数:" + downloadInfo.comparisonInfo.flag + "个数为:" + downloadInfo.comparisonInfo.needDecompressionList.Count);
            if (downloadInfo.comparisonInfo.flag == 1)
            {
                DeleteAllKey(true);
                Application.OpenURL(HotUpdateRessMgr.Instance.downLoadInfo.FullPackUrl);
                //TODO:下载整包
                //                 if (Application.platform == RuntimePlatform.IPhonePlayer)
                //                 {
                //                     Application.OpenURL(HotUpdateRessMgr.Instance.downLoadInfo.FullPackUrl);
                //                     Application.Quit();
                //                 }
                //                 else
                //                 {
                //                     DownLoadApk();
                //                 }
            }
            else
            {
                DeleteAllKey(false);
                AsynTask task = new AsynTask(true, () =>
                {
                    HotUpdateRessMgr.Instance.Save(downloadInfo, true);
                    SceneMgr.Instance.QueueEvent(AppConst.CoreDef.DOWNED);
                }, DownLoadFailue);

                task.taskItemFinished = it =>
                {
                    DownLoadTask dt     = it as DownLoadTask;
                    ABInfo       downab = dt.downInfo;
                    downloadInfo.localVer.Save(downab);
                    HotUpdateRessMgr.Instance.Save(downloadInfo, false);

                    Debug.Log("开始下载完成:" + downab.fileName);
                };

                foreach (ABInfo ab in downloadInfo.comparisonInfo.needDecompressionList)
                {
                    task.AddTask(new DownLoadTask(ab));
                }
                task.OnExecute();
            }
        };

        HotUpdateRessMgr.Instance.GetDownList(HotUpdateRessMgr.Instance.verInfo, checkFileed);
    }
Esempio n. 17
0
            public static bool DownLoadFileAsync(UpdateObjectVector _owner, string _appname, string _sourceurl, string _destination, bool _IsClear, Action <string, string> _finished, Action <long, long, float> _progress)
            {
                if (sDownLoadMap.ContainsKey(_sourceurl))
                {
                    DLog.LogError("有相同URL文件正在下载当中.URL = " + _sourceurl);
                    return(false);
                }
                DownLoadTask ttaskdown = new DownLoadTask(_owner, _appname, _sourceurl, _destination, _IsClear, _finished, _progress);
                bool         isstart   = ttaskdown.StartDownloadAsync();

                if (!isstart)
                {
                    ttaskdown.Dispose();
                }
                return(isstart);
            }
Esempio n. 18
0
    /// <summary>
    /// 线程池执行任务
    /// </summary>
    /// <param name="task"></param>
    /// <returns></returns>
    private bool DoWorkTaskInThreadPool(DownLoadTask task)
    {
        int workIndex = GetWorkIndex();

        if (workIndex != -1 && task != null)
        {
            task.isDone          = false;
            _workList[workIndex] = task;
            ThreadPool.QueueUserWorkItem(ThreadPoolFunc, workIndex);
            return(true);
        }
        else
        {
            return(false);
        }
    }
    /// <summary>
    /// 完成指定下载任务
    /// </summary>
    public static void FinishTask(int downid)
    {
        DownLoadTask task = FindTask(downid);

        if (task == null)
        {
            return;
        }
        string ResourceName = task.m_ResName;

        s_DownLoadTasks.Remove(task);
        if (m_funNotifyFinish != null)
        {
            m_funNotifyFinish(ResourceName, s_DownLoadTasks.Count);
        }
        StartDown();
    }
Esempio n. 20
0
        static public void DownLoadFileAsync(string _AppName, string _sourceurl, string _destination, bool _IsClear, Action <string, string> _finished, Action <long, long, float> _progress)
        {
            if (sInstance == null)
            {
                CreatInstance();
            }
            string tdeleappname = GameCore.GetDelegateAppName(_finished);

            if (!string.IsNullOrEmpty(tdeleappname))
            {
                _AppName = tdeleappname;
            }
            if (DownLoadTask.DownLoadFileAsync(sInstance.UpdateList, _AppName, _sourceurl, _destination, _IsClear, _finished, _progress))
            {
                sInstance.SetActive(true);
            }
        }
Esempio n. 21
0
    /// <summary>
    /// 是否正在执行任务
    /// </summary>
    /// <returns></returns>
    private bool IsWorkDoing()
    {
        long doingSize = 0;
        long doneSize  = 0;
        bool isDoing   = false;

        for (int i = 0; i < _workList.Count; ++i)
        {
            DownLoadTask task = _workList[i];
            if (task != null)
            {
                if (task.isDone)
                {
                    _workList[i] = null;
                    if (task.isSuccess)
                    {
                        doneSize += task.downLoadSize;
                    }
                    else
                    {
                        _failedList.Add(task);
                    }
                    _doneQueue.Enqueue(task);
                }
                else
                {
                    doingSize += task.downLoadSize;
                    isDoing    = true;
                }
            }
        }
        _downLoadSize  = doingSize;
        _downDoneSize += doneSize;

        CalcSpeed(GetDownLoadSize());

        return(isDoing);
    }
    /// <summary>
    ///  下载任务相同
    /// </summary>
    public bool EqualTask(DownLoadTask task)
    {
        if (task == null)
        {
            return(false);
        }
        if (string.Compare(this.m_ResName, task.m_ResName) != 0)
        {
            return(false);
        }

        if (string.Compare(this.m_localPath, task.m_localPath) != 0)
        {
            return(false);
        }

        if (string.Compare(this.m_ServerPath, task.m_ServerPath) != 0)
        {
            return(false);
        }

        return(true);
    }
Esempio n. 23
0
    /// <summary>
    /// 执行任务的线程池函数
    /// </summary>
    /// <param name="param"></param>
    private void ThreadPoolFunc(object param)
    {
        DownLoadTask task = null;

        lock (_object)
        {
            int workIndex = (int)param;
            task = _workList[workIndex];
            if (task != null)
            {
                task.buffer = _bufferList[workIndex];
                if (task.buffer == null)
                {
                    task.buffer            = new byte[BUFFER_SIZE];
                    _bufferList[workIndex] = task.buffer;
                }
            }
        }
        if (task != null)
        {
            DoDownLoadTask(task);
        }
    }
Esempio n. 24
0
 public WWWTask(DownLoadTask task)
 {
     www       = new WWW(task.url);
     this.task = task;
 }
Esempio n. 25
0
    /// <summary>
    /// 执行下载任务
    /// </summary>
    /// <param name="task"></param>
    /// <returns></returns>
    private bool DoDownLoadTask(DownLoadTask task)
    {
        if (task == null || task.isDone)
        {
            return(false);
        }
        int             tryCount       = 0;
        HttpWebRequest  httpWebRequest = null;
        HttpWebResponse webResponse    = null;
        FileStream      fs             = null;
        Stream          responseStream = null;

        Byte[] bytes     = task.buffer;
        bool   isSuccess = false;
        bool   timeOut   = false;

        do
        {
            if (task.isCancel)
            {
                break;
            }
            try
            {
                if (task.totalSize <= 0)
                {
                    task.totalSize = GetFileLength(task.url);
                }
                httpWebRequest = CreateWebRequest(task.url);
                long range = 0;
                fs = new FileStream(task.path, FileMode.OpenOrCreate);
                if (fs.Length > 0 && task.totalSize > fs.Length && fs.Length < int.MaxValue)
                {
                    long pos = fs.Seek(0, SeekOrigin.End);
                    task.downLoadSize = pos;
                    range            += pos;
                }
                else
                {
                    fs.Seek(0, SeekOrigin.Begin);
                    fs.SetLength(0);
                    task.downLoadSize = 0;
                }
                httpWebRequest.AddRange((int)range);
                webResponse = httpWebRequest.GetResponse() as HttpWebResponse;
                if (webResponse.StatusCode == HttpStatusCode.OK || webResponse.StatusCode == HttpStatusCode.PartialContent)
                {
                    responseStream             = webResponse.GetResponseStream();
                    responseStream.ReadTimeout = READ_TIMEOUT;
                    int size = 0;
                    while (!task.IsDownLoadDone())
                    {
                        if (task.isCancel)
                        {
                            break;
                        }
                        size = responseStream.Read(bytes, 0, bytes.Length);
                        if (size > 0)
                        {
                            fs.Write(bytes, 0, size);
                            task.downLoadSize += size;
                        }
                        else
                        {
                            break;
                        }
                    }
                    responseStream.Close();
                    responseStream = null;
                    webResponse.Close();
                    webResponse = null;
                    httpWebRequest.Abort();
                    httpWebRequest = null;
                    fs.Close();
                    fs = null;
                    if (task.IsDownLoadDone())
                    {
                        isSuccess = true;
                    }
                }
                else
                {
                    Debug.LogErrorFormat("webResponse code:{0}", webResponse.StatusCode.ToString());
                }
            }
            catch (Exception ex)
            {
                System.Net.WebException webException = ex as WebException;
                if (webException != null && webException.Status == WebExceptionStatus.Timeout && webException.TargetSite.Name == "Read")
                {
                    //timeOut = true;
                }
                else
                {
                    timeOut = false;
                }
                Debug.LogError(ex.StackTrace);
                Debug.LogError(ex.Message);
                if (responseStream != null)
                {
                    responseStream.Close();
                    responseStream = null;
                }
                if (webResponse != null)
                {
                    webResponse.Close();
                    webResponse = null;
                }
                if (httpWebRequest != null)
                {
                    httpWebRequest.Abort();
                    httpWebRequest = null;
                }
                if (fs != null)
                {
                    fs.Close();
                    fs = null;
                }
            }

            if (isSuccess)
            {
                break;
            }
            else
            {
                if (!timeOut)
                {
                    tryCount++;
                }
                Thread.Sleep(50);
            }
        } while (tryCount < TRY_COUNT);

        task.Done(isSuccess);

        return(isSuccess);
    }