Exemplo n.º 1
0
 void CheckFinish()
 {
     if (m_downloadSuccFile.Count == m_downloadFile.Count)
     {
         LogUtils.Log("all res have done!");
         m_mgr.ChangeNextStatus();
     }
 }
Exemplo n.º 2
0
        public void DoDownload(string cfg, string temp, string signature, string url, Action <bool> callback)
        {
            LogUtils.Log("download:", url);
            try
            {
                {
                    Uri            requestUrl = new Uri(url);
                    HttpWebRequest request    = (HttpWebRequest)WebRequest.Create(requestUrl);
                    request.Method  = "HEAD";
                    request.Timeout = 2000;
                    HttpWebResponse respone = (HttpWebResponse)request.GetResponse();
                    m_totalSize = respone.ContentLength;
                    respone.Close();
                    request.Abort();
                }
                Check(cfg, temp, m_totalSize, signature);
                while (m_currentPos < m_totalSize && !m_isStop)
                {
                    Thread.Sleep(3);

                    if (m_currentPos < m_totalSize)
                    {
                        Uri            requestUrl = new Uri(url);
                        HttpWebRequest request    = (HttpWebRequest)WebRequest.Create(requestUrl);
                        request.Method  = "GET";
                        request.Timeout = 2000;
                        int endPos = (int)m_currentPos + downLoadblockSize;
                        if (endPos >= m_totalSize)
                        {
                            endPos = (int)m_totalSize - 1;
                        }
                        request.AddRange((int)m_currentPos, endPos);
                        HttpWebResponse respone = (HttpWebResponse)request.GetResponse();
                        WriteData(respone);
                        respone.Close();
                        request.Abort();
                    }
                }
                this.Close();
                if (callback != null)
                {
                    callback(true);
                }
            }
            catch (System.Exception ex)
            {
                this.Close();
                LogUtils.LogError(ex.ToString());

                if (callback != null)
                {
                    callback(false);
                }
            }
        }
        public void Uninit()
        {
            if (Inst == null)
            {
                return;
            }

            LogUtils.Log("CoroutineTaskMgr.Uninit()");
            Clean();
            Inst = null;
        }
Exemplo n.º 4
0
 public void Uninit()
 {
     if (!isInit)
     {
         return;
     }
     isInit = false;
     ForceRelease();
     m_bundleMgr.Uninit();
     LogUtils.Log("AssetsMgr.Uninit()...");
     LoopUpdateMgr.GetInst().Remove(this);
 }
Exemplo n.º 5
0
 public void Init()
 {
     if (isInit)
     {
         return;
     }
     isInit = true;
     LogUtils.Log("AssetsMgr.Init()...");
     LoopUpdateMgr.GetInst().Add(this);
     m_assetsConfig.ReloadConfig();
     m_bundleMgr.Init(m_assetsConfig);
 }
Exemplo n.º 6
0
        public override void OnEnter(Status oldStatus)
        {
            AssetsMgr.GetInst().Init();
            LogUtils.Log("enter game status!");

            //sync
            //UnityEngine.Object obj = AssetsUtils.LoadAssetSync("character/models/human/1210001/1210001_2");
            //GameObject o = GameObject.Instantiate(obj) as GameObject;

            //async
            AssetsUtils.LoadAssetAync("character/models/human/1230008/1230008_1", OnAssetLoaded);
        }
Exemplo n.º 7
0
        public void OnAssetBundleLoaded(string bundleName, BundleCache bundle)
        {
            LogUtils.Log("bundle loaded!:", bundleName);
            m_status = AssetLoadStatus.Loaded;
            if (bundle == null)
            {
                OnAssetLoaded(null);
                return;
            }

            if (m_refBundle != null)
            {
                m_refBundle.ReduceRef();
            }
            m_refBundle = bundle;
            m_refBundle.AddRef();
        }
Exemplo n.º 8
0
        void OnFinishedCallback(bool succ)
        {
            m_succesed = succ;
            if (m_succesed)
            {
                LogUtils.Log(m_name + " download succ!");

                try
                {
                    //todo...move or decrompress
                    string desName = PathUtils.GetPersistentPath() + m_name;
                    PathUtils.MakeSureDirExist(desName);

                    if (File.Exists(desName))
                    {
                        File.Delete(desName);
                    }

                    File.Copy(m_tempFile.GetTempFileName(), desName);
                    m_tempFile.Delete();

                    //check
                    if (m_signature.Length > 0)
                    {
                        bool vaild = FileChecker.VerifyFileSignature(desName, m_signature);
                        if (vaild == false)
                        {
                            File.Delete(desName);
                            LogUtils.LogError(m_name + " VerifyFileSignature faild!");
                        }
                        m_succesed = vaild;
                    }
                }
                catch (System.Exception ex)
                {
                    m_succesed = false;
                    LogUtils.LogError(ex.ToString());
                }
            }
            else
            {
                LogUtils.LogError(m_name + " download faild!");
            }
            m_status = DownLoadTaskStatus.Finished;
        }
Exemplo n.º 9
0
        public override void OnEnter(Status oldStatus)
        {
            LogUtils.Log("enter app channel status");
            verAddrCfg.item.Clear();

            try
            {
                Uri            requestUrl = new Uri("http://10.0.0.252:8080/channel_cfg/channel_ver_addr.json");
                HttpWebRequest request    = (HttpWebRequest)WebRequest.Create(requestUrl);
                request.Timeout = 2000;
                HttpWebResponse respone = (HttpWebResponse)request.GetResponse();

                long   blockSize  = respone.ContentLength;
                byte[] blockBuff  = new byte[blockSize];
                var    respStream = respone.GetResponseStream();
                int    rec        = respStream.Read(blockBuff, 0, (int)blockSize);
                respone.Close();
                request.Abort();

                string str = System.Text.Encoding.Default.GetString(blockBuff);
                verAddrCfg = JsonUtility.FromJson <ChannelVerAddrCfg>(str);

                int channelId = VersionUpdate.GetIns().GetChannelID();
                for (int i = 0; i < verAddrCfg.item.Count; ++i)
                {
                    if (verAddrCfg.item[i].id == channelId)
                    {
                        DownloadMgr.GetInst().SetBaseURL(verAddrCfg.item[i].addr);
                        m_mgr.ChangeNextStatus();
                        return;
                    }
                }
                LogUtils.LogError("can not find channel ver addr!");
            }
            catch (System.Exception ex)
            {
                LogUtils.LogError(ex.ToString());
            }
        }
Exemplo n.º 10
0
        public override void OnEnter(Status oldStatus)
        {
            LogUtils.Log("enter res file check and update status");

            //check
            VersionRes verRes = VersionUpdate.GetIns().GetVersionRes();

            DownloadMgr.GetInst().SetBaseURL(verRes.url);
            DownloadMgr.GetInst().SetMaxTaskNum(3);

            m_downloadFile.Clear();
            m_downloadSuccFile.Clear();
            for (int i = 0; i < verRes.versionResFile.Count; ++i)
            {
                VersionResFile resFile = verRes.versionResFile[i];

                if (resFile.resType == VersionResType.PreDownload)
                {
                    string fullPath = PathUtils.GetVaildFullPath(resFile.name);
                    if (fullPath.Length == 0 || !FileChecker.VerifyFileSignature(fullPath, resFile.signature))
                    {
                        m_downloadFile.Add(resFile.name);
                        DownloadMgr.GetInst().CreateTask(resFile.name, verRes.versionResFile[i].signature, DownloadResult);
                    }
                }
                else
                {
                    string fileName = PathUtils.GetPersistentPath() + resFile.name;
                    if (fileName.Length > 0 && File.Exists(fileName))
                    {
                        if (!FileChecker.VerifyFileSignature(fileName, resFile.signature))
                        {
                            File.Delete(fileName);
                        }
                    }
                }
            }
            CheckFinish();
        }
Exemplo n.º 11
0
 public void Update()
 {
     if (m_status == DownLoadTaskStatus.Start)
     {
         LogUtils.Log(m_name + " download begin!");
         m_status = DownLoadTaskStatus.DownLoading;
         m_thread = new Thread(OnTaskStart);
         m_thread.Start();
     }
     if (m_status == DownLoadTaskStatus.Finished)
     {
         if (!m_succesed && m_retryTimes > 0 && !m_isStop)
         {
             --m_retryTimes;
             m_status = DownLoadTaskStatus.Wait;  //try again
             return;
         }
         if (resultCb != null)
         {
             resultCb(m_name, m_succesed);
         }
         resultCb = null;
     }
 }
Exemplo n.º 12
0
 public override void OnEnter(Status oldStatus)
 {
     LogUtils.Log("enter get version info status");
     //string timeNow = System.DateTime.Now.ToLocalTime().ToString();
     DownloadMgr.GetInst().CreateTask("version.json", "", DownloadResult);
 }
 public void RemoveTask(string name, IEnumerator routine)
 {
     LogUtils.Log("RemoveTask(),name:", name);
     StopCoroutine(routine);
 }
 public void AddTask(string name, IEnumerator routine)
 {
     LogUtils.Log("AddTask(),name:", name);
     StartCoroutine(routine);
 }
 public void Init()
 {
     LogUtils.Log("CoroutineTaskMgr.Init()");
 }
Exemplo n.º 16
0
 public void Init()
 {
     LogUtils.Log("LoopUpdateMgr.Init()");
 }