Exemplo n.º 1
0
        private void DownloadCompleted(WWW www)
        {
            if (www == null)
            {
                if (failCount == GameConfig.download_Fail_Count)
                {
                    if (callback != null)
                    {
                        callback(null);
                    }
                    return;
                }
                Download(GameConfig.download_Fail_Retry_Delay);
                failCount++;
                return;
            }

            localMd5Dict  = Md5FileHelp.LocalFileForDict(module);
            remoteMd5Dict = Md5FileHelp.ForDict(www.text);
            Dictionary <string, string> .Enumerator e = remoteMd5Dict.GetEnumerator();
            Queue <DownloadConfig> DownloadList       = new Queue <DownloadConfig>();

            while (e.MoveNext())
            {
                string md5 = null;
                localMd5Dict.TryGetValue(e.Current.Key, out md5);
                string file = string.Format("{0}/{1}", Util.DeviceResPath, e.Current.Key);
                if (md5 == null || md5.Trim() != e.Current.Value.Trim() || !File.Exists(file))
                {
                    DownloadConfig fileConfig = new DownloadConfig();
                    fileConfig.key           = e.Current.Key;
                    fileConfig.download_url  = string.Format("{0}/{1}/{2}", version.res_download_url, GameConfig.module_name, e.Current.Key);
                    fileConfig.localPath_url = string.Format("{0}/{1}", Util.DeviceResPath, e.Current.Key);
                    DownloadList.Enqueue(fileConfig);

                    if (!e.Current.Key.EndsWith(".txt"))
                    {
                        DownloadConfig manifestConfig = new DownloadConfig();
                        fileConfig.key = null;
                        manifestConfig.download_url  = string.Format("{0}.{1}", fileConfig.download_url, "manifest");
                        manifestConfig.localPath_url = string.Format("{0}.{1}", fileConfig.localPath_url, "manifest");
                        DownloadList.Enqueue(manifestConfig);
                    }
                }
            }
            e.Dispose();
            if (callback != null)
            {
                callback(DownloadList);
            }
        }
Exemplo n.º 2
0
 private void StartThread(object obj)
 {
     while (_DownloadList.Count > 0)
     {
         if (isWait == false)
         {
             DownloadConfig config = _DownloadList.Dequeue();
             Download       dw     = new Download(config);
             dw.onProgress  = OnProgress;
             dw.onCompleted = OnCompleted;
             dw.onError     = OnError;
             dw.Start();
             isWait = true;
         }
         Thread.Sleep(1);
     }
 }
Exemplo n.º 3
0
 private void OnError(DownloadConfig config)
 {
     _DownloadList.Enqueue(config);
     _EventQueue.Enqueue(new DownloadEvent(DownloadEventType.Error, config));
     isWait = false;
 }
Exemplo n.º 4
0
 private void OnCompleted(DownloadConfig config)
 {
     _EventQueue.Enqueue(new DownloadEvent(DownloadEventType.Completed, config));
     isWait = false;
 }
Exemplo n.º 5
0
 private void OnProgress(DownloadConfig config, int progress)
 {
     _EventQueue.Enqueue(new DownloadEvent(DownloadEventType.Progress, config, progress));
 }
Exemplo n.º 6
0
 public DownloadEvent(DownloadEventType eventType, DownloadConfig config, object param = null)
 {
     this.eventType = eventType;
     this.config    = config;
     this.param     = param;
 }
Exemplo n.º 7
0
 public Download(DownloadConfig config)
 {
     _downloadConfig = config;
 }