Esempio n. 1
0
 void DownLoadFileCompleted(object sender, AsyncCompletedEventArgs e)
 {
     lock (handler)
     {
         handler.Add(() =>
         {
             if (processingCtrl != null)
             {
                 processingCtrl.DownLoadFileCompleted(sender, e);
             }
             if (client != null)
             {
                 client.Dispose();
                 client = null;
             }
             lock (DownloadTask)
             {
                 if (DownloadTask.Contains(processingCtrl))
                 {
                     DownloadTask.Remove(processingCtrl);
                 }
             }
             processingCtrl = null;
             processing     = false;
         });
     }
 }
Esempio n. 2
0
 public void RemovePreviewTask(PluginCtrl uiCtrl)
 {
     lock (PreviewTask)
     {
         if (processingCtrl == uiCtrl)
         {
             if (uiCtrl.Target != null)
             {
                 cancelPreviewTask = uiCtrl.Target.Preview;
             }
             else if (uiCtrl.Chapter != null)
             {
                 cancelPreviewTask = uiCtrl.Chapter.Preview;
             }
             if (client != null)
             {
                 client.CancelAsync();
                 client.Dispose();
                 client = null;
             }
         }
         if (PreviewTask.Contains(uiCtrl))
         {
             PreviewTask.Remove(uiCtrl);
         }
     }
 }
Esempio n. 3
0
 public void AddDownloadTask(PluginCtrl uiCtrl)
 {
     lock (DownloadTask)
     {
         if (!DownloadTask.Contains(uiCtrl))
         {
             DownloadTask.Insert(0, uiCtrl);
         }
     }
 }
Esempio n. 4
0
 List <string> PreviewTaskCache = new List <string>();//已经下载过预览图的,下次翻页不要再下载.单次运行APP下载一次
 public void AddPreviewTask(PluginCtrl uiCtrl)
 {
     lock (PreviewTask)
     {
         if (!PreviewTask.Contains(uiCtrl))
         {
             PreviewTask.Add(uiCtrl);
         }
     }
 }
Esempio n. 5
0
 public void RemoveDownloadTask(PluginCtrl uiCtrl)
 {
     lock (DownloadTask)
     {
         if (processingCtrl == uiCtrl)
         {
             if (client != null)
             {
                 client.CancelAsync();
                 client.Dispose();
                 client = null;
             }
         }
         if (DownloadTask.Contains(uiCtrl))
         {
             DownloadTask.Remove(uiCtrl);
         }
     }
 }
Esempio n. 6
0
    void InsertDlc(Chapter item)
    {
        if (prefabPluginWnd == null)
        {
            prefabPluginWnd = Resources.Load("PluginWnd") as GameObject;
        }
        GameObject insert = GameObject.Instantiate(prefabPluginWnd);

        insert.transform.SetParent(PluginRoot.transform);
        insert.transform.localPosition = Vector3.zero;
        insert.transform.localScale    = Vector3.one;
        insert.transform.localRotation = Quaternion.identity;
        PluginCtrl ctrl = insert.GetComponent <PluginCtrl>();

        if (ctrl != null)
        {
            ctrl.AttachDlc(item);
        }
        pluginList.Add(ctrl);
    }
    void InsertDlc(Chapter item)
    {
        if (prefabPluginWnd == null)
        {
            prefabPluginWnd = ResMng.Load("PluginWnd") as GameObject;
        }
        GameObject insert = GameObject.Instantiate(prefabPluginWnd);

        insert.transform.SetParent(PluginRoot.transform);
        insert.transform.localPosition = Vector3.zero;
        insert.transform.localScale    = Vector3.one;
        insert.transform.localRotation = Quaternion.identity;
        PluginCtrl ctrl = insert.GetComponent <PluginCtrl>();

        if (ctrl != null)
        {
            ctrl.AttachDlc(item);
            if (!Main.Ins.GameStateMgr.gameStatus.IsDlcInstalled(item))
            {
                Main.Ins.DlcMng.AddPreviewTask(ctrl);
            }
        }
        pluginList.Add(ctrl);
    }
 public UnzipCallbackEx(PluginCtrl ctrl)
 {
     Target = ctrl;
 }
Esempio n. 9
0
    private void OnDownloadPreviewComplete(object sender, DownloadDataCompletedEventArgs e)
    {
        lock (handler)
        {
            handler.Add(() => {
                if (e.Error != null)
                {
                    if (processingCtrl != null)
                    {
                        if (processingCtrl.retryNum >= 1)
                        {
                            //跳过这个任务,开始下载下一个的预览图
                            lock (PreviewTask)
                            {
                                if (PreviewTask.Contains(processingCtrl))
                                {
                                    PreviewTask.Remove(processingCtrl);
                                }
                            }
                        }
                        else
                        {
                            processingCtrl.retryNum++;
                        }
                    }

                    if (client != null)
                    {
                        client.Dispose();
                        client = null;
                    }
                    processingCtrl = null;
                    processing     = false;
                }
                else
                {
                    if (processingCtrl == null)
                    {
                        //保存到本地,下次直接从本地读取.
                        //中断得下载预览图任务存储路径
                        if (!string.IsNullOrEmpty(cancelPreviewTask))
                        {
                            byte[] bitPrev = e.Result;
                            if (bitPrev != null && bitPrev.Length != 0)
                            {
                                System.IO.FileStream fs = new System.IO.FileStream(cancelPreviewTask, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None);
                                fs.Write(bitPrev, 0, bitPrev.Length);
                                fs.SetLength(bitPrev.Length);
                                fs.Flush();
                                fs.Close();
                                lock (PreviewTaskCache)
                                {
                                    PreviewTaskCache.Add(cancelPreviewTask);
                                }
                            }
                        }
                        processing = false;
                        return;
                    }
                    byte[] bitIcon = e.Result;
                    if (bitIcon != null && bitIcon.Length != 0)
                    {
                        if (processingCtrl.Target != null)
                        {
                            try
                            {
                                lock (PreviewTask)
                                {
                                    if (PreviewTask.Contains(processingCtrl))
                                    {
                                        System.IO.FileStream fs = new System.IO.FileStream(processingCtrl.Target.Preview, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None);
                                        fs.Write(bitIcon, 0, bitIcon.Length);
                                        fs.SetLength(bitIcon.Length);
                                        fs.Flush();
                                        fs.Close();
                                        PreviewTask.Remove(processingCtrl);
                                    }
                                }
                            }
                            catch (System.Exception exp)
                            {
                                Debug.Log(exp.Message);
                            }
                            Texture2D tex = new Texture2D(200, 150);
                            tex.LoadImage(bitIcon);
                            processingCtrl.Preview.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
                            lock (PreviewTaskCache)
                            {
                                PreviewTaskCache.Add(processingCtrl.Target.Preview);
                            }
                            client.Dispose();
                            client         = null;
                            processingCtrl = null;
                            processing     = false;
                        }
                        else if (processingCtrl.Chapter != null)
                        {
                            lock (PreviewTask)
                            {
                                if (PreviewTask.Contains(processingCtrl))
                                {
                                    if (bitIcon != null && bitIcon.Length != 0)
                                    {
                                        System.IO.File.WriteAllBytes(processingCtrl.Chapter.Preview, bitIcon);
                                        Texture2D tex = new Texture2D(200, 150);
                                        tex.LoadImage(bitIcon);
                                        processingCtrl.Preview.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
                                    }
                                    PreviewTask.Remove(processingCtrl);
                                }
                            }

                            lock (PreviewTaskCache)
                            {
                                PreviewTaskCache.Add(processingCtrl.Chapter.Preview);
                            }
                            client.Dispose();
                            client         = null;
                            processingCtrl = null;
                            processing     = false;
                        }
                    }
                }
            });
        }
    }
Esempio n. 10
0
    public void Update()
    {
        if (!processing)
        {
            //下载预览图任务
            if (PreviewTask.Count != 0)
            {
                processingCtrl = PreviewTask[0];
                ModelItem it = processingCtrl.Target;
                if (it != null)
                {
                    //如果该封面已经下载过,并且存储到本地了,那么从本地读取
                    if (PreviewTaskCache.Contains(processingCtrl.Target.Preview))
                    {
                        System.IO.FileStream fs = new System.IO.FileStream(processingCtrl.Target.Preview, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None);
                        byte[] bitIcon          = new byte[fs.Length];
                        fs.Read(bitIcon, 0, (int)fs.Length);
                        fs.Close();
                        Texture2D tex = new Texture2D(200, 150);
                        tex.LoadImage(bitIcon);
                        processingCtrl.Preview.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
                        processingCtrl = null;
                        PreviewTask.RemoveAt(0);
                        return;
                    }
                    //如果该封面没有下载过.开始下载
                    processing = true;
                    string urlIconPreview = string.Format("http://{0}/meteor/{1}", Main.strHost, it.webPreview);
                    try
                    {
                        if (client == null)
                        {
                            client = new WebClient();
                            client.DownloadDataCompleted += OnDownloadPreviewComplete;
                        }
                        client.DownloadDataAsync(new Uri(urlIconPreview));
                    }
                    catch
                    {
                        processing = false;
                    }
                    return;
                }
                else
                {
                    //dlc的预览图.
                    Chapter cha = processingCtrl.Chapter;
                    //如果该封面已经下载过,并且存储到本地了,那么从本地读取
                    if (PreviewTaskCache.Contains(processingCtrl.Chapter.Preview))
                    {
                        System.IO.FileStream fs = new System.IO.FileStream(processingCtrl.Chapter.Preview, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None);
                        byte[] bitIcon          = new byte[fs.Length];
                        fs.Read(bitIcon, 0, (int)fs.Length);
                        fs.Close();
                        Texture2D tex = new Texture2D(200, 150);
                        tex.LoadImage(bitIcon);
                        processingCtrl.Preview.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
                        processingCtrl = null;
                        PreviewTask.RemoveAt(0);
                        return;
                    }
                    processing = true;
                    string urlIconPreview = string.Format("http://{0}/meteor/{1}", Main.strHost, cha.webPreview);
                    try
                    {
                        if (client == null)
                        {
                            client = new WebClient();
                            client.DownloadDataCompleted += OnDownloadPreviewComplete;
                        }
                        client.DownloadDataAsync(new Uri(urlIconPreview));
                    }
                    catch
                    {
                    }
                }
            }

            //下载模组zip任务.
            if (DownloadTask.Count != 0)
            {
                processingCtrl = DownloadTask[0];
                ModelItem it = processingCtrl.Target;
                if (it != null)
                {
                    //如果该模组没有
                    processing = true;
                    if (client == null)
                    {
                        client = new WebClient();
                        client.DownloadProgressChanged += this.DownLoadProgressChanged;
                        client.DownloadFileCompleted   += this.DownLoadFileCompleted;

                        string downloadUrl = string.Format("http://{0}/meteor/{1}", Main.strHost, processingCtrl.Target.Path);
                        client.DownloadFileAsync(new System.Uri(downloadUrl), processingCtrl.Target.LocalPath);
                    }
                    return;
                }
                else
                {
                    processing = true;
                    //dlc的下载.
                    if (client == null)
                    {
                        client = new WebClient();
                        client.DownloadProgressChanged += this.DownLoadProgressChanged;
                        client.DownloadFileCompleted   += this.DownLoadFileCompleted;

                        string downloadUrl = string.Format("http://{0}/meteor/{1}", Main.strHost, processingCtrl.Chapter.Path);
                        client.DownloadFileAsync(new System.Uri(downloadUrl), processingCtrl.Chapter.LocalPath);
                    }
                    return;
                }
            }
        }

        lock (handler)
        {
            for (int i = 0; i < handler.Count; i++)
            {
                handler[i].Invoke();
            }
            handler.Clear();
        }
    }