IEnumerator DownloadNecessaryData()
    {
        //check data is ok
        //if (strServerVer == null || GameData.Version().CompareTo(strServerVer) != -1)
        //	yield break;

        //check last download is interrupt
        if (MainLoader.config != null && MainLoader.config.mlst.Count != 0)
        {
            string strTargetV = MainLoader.config.strTargetVer;
            //target ver == server ver restore from last state
            if (strTargetV == strServerVer)
            {
                foreach (var item in MainLoader.config.mlst)
                {
                    if (!string.IsNullOrEmpty(item.strLoadbytes) && item.strTotalbytes == item.strLoadbytes && item.strTotalbytes != "0")
                    {
                        if (item.bHashChecked)
                        {
                            continue;
                        }
                    }
                    if (!string.IsNullOrEmpty(item.strFile) && item.bForceUpdate)
                    {
                        UpdateClient.AddRequest(item.strFile, strUpdatePath + "/" + item.strFile, new HttpClient.cb(UpdateTableProgress), System.Convert.ToInt64(item.strLoadbytes), item);
                    }
                }

                AllCount = HttpClient.RequestMap.Count;
                if (AllCount != 0)
                {
                    MainLoader.ChangeStep(LoadStep.NeedUpdate);
                    errorCount    = 0;
                    DownloadCount = 0;
                    HttpClient.StartDownload();
                }
                else
                {
                    MainLoader.ChangeStep(LoadStep.NotNeedUpdate);
                }
                yield break;
            }
        }
        //download 0.0.0.0-0.0.0.1.xml
        string strUrl       = string.Format(strVFile, strHost, strPort, strProjectUrl, strPlatform, strUpdateFile);
        string strLocalFile = strUpdatePath + "/" + strUpdateFile;

        using (WWW updateXml = new WWW(strUrl))
        {
            yield return(updateXml);

            File.WriteAllBytes(strLocalFile, updateXml.bytes);
            DeCompressFile(strLocalFile, strUpdatePath + "/" + "update.xml");
            XmlDocument xmlVer = new XmlDocument();
            xmlVer.Load(strUpdatePath + "/" + "update.xml");
            XmlElement updateFilelst = xmlVer.DocumentElement;
            if (updateFilelst != null)
            {
                string            strFileNum = updateFilelst.GetAttribute("Filenum");
                List <UpdateFile> data       = new List <UpdateFile>();
                foreach (XmlElement each in updateFilelst)
                {
                    string strFileName = each.GetAttribute("name");
                    string strMD5      = each.GetAttribute("MD5");

                    bool       bFind = false;
                    UpdateFile res   = null;
                    foreach (var item in MainLoader.config.mlst)
                    {
                        if (item.strFile == strFileName)
                        {
                            bFind = true;
                            break;
                        }
                    }

                    if (bFind && res != null)
                    {
                        res.strMd5        = strMD5;
                        res.bHashChecked  = false;
                        res.strLoadbytes  = "0";
                        res.strTotalbytes = "0";

                        //下载的必要数据包括在Resources目录内的文件,以及以.zip结束的文件(表格或者数据或脚本)
                        string[] strResourceDirectory = strFileName.Split('/');
                        bool     bForce = false;
                        foreach (var eachDir in strResourceDirectory)
                        {
                            if (eachDir == "Resources")
                            {
                                bForce = true;
                                break;
                            }
                        }
                        if (strFileName.EndsWith(".zip"))
                        {
                            bForce = true;
                        }
                        res.bForceUpdate = bForce;
                        data.Add(res);
                    }
                    else
                    {
                        string[] strResourceDirectory = strFileName.Split('/');
                        bool     bForce = false;
                        foreach (var eachDir in strResourceDirectory)
                        {
                            if (eachDir == "Resources")
                            {
                                bForce = true;
                                break;
                            }
                        }
                        if (strFileName.EndsWith(".zip"))
                        {
                            bForce = true;
                        }

                        UpdateFile file = new UpdateFile(strFileName, strMD5, "0", "0", bForce);
                        data.Add(file);
                    }
                }

                MainLoader.config.mlst         = data;
                MainLoader.config.strTargetVer = strServerVer;
                foreach (var item in MainLoader.config.mlst)
                {
                    if (!UpdateConfig.keySearch.ContainsKey(item.strFile))
                    {
                        UpdateConfig.keySearch.Add(item.strFile, item);
                    }
                    if (item.strLoadbytes != "0" && item.strLoadbytes == item.strTotalbytes)
                    {
                        continue;
                    }
                    if (item.bForceUpdate)
                    {
                        UpdateClient.AddRequest(item.strFile, strUpdatePath + "/" + item.strFile, new HttpClient.cb(UpdateTableProgress), Convert.ToInt64(item.strLoadbytes), item);
                    }
                }

                AllCount = HttpClient.RequestMap.Count;
                if (AllCount != 0)
                {
                    int nUnNecessCount = Convert.ToInt32(strFileNum) - AllCount;
                    MainLoader.ChangeStep(LoadStep.NeedUpdate);
                    errorCount    = 0;
                    DownloadCount = 0;
                    HttpClient.StartDownload();
                }
                else
                {
                    MainLoader.ChangeStep(LoadStep.NotNeedUpdate);
                }
            }
        }
    }
    IEnumerator RestoreUpdate()
    {
        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            Log.LogInfo("connect time out");
            MainLoader.ChangeStep(LoadStep.NotNeedUpdate);
            yield break;
        }
        else if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
        {
            //3G Tip
        }
        //Restore DownLoad From Progress.xml
        System.Net.Sockets.Socket         sClient     = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.IP);
        System.Net.EndPoint               server      = new System.Net.IPEndPoint(Dns.GetHostAddresses(GameData.Domain)[0], System.Convert.ToInt32(strPort));
        System.Threading.ManualResetEvent connectDone = new System.Threading.ManualResetEvent(false);
        try
        {
            connectDone.Reset();
            sClient.BeginConnect(server, delegate(IAsyncResult ar) {
                try
                {
                    System.Net.Sockets.Socket client = (System.Net.Sockets.Socket)ar.AsyncState;
                    client.EndConnect(ar);
                }
                catch (System.Exception e)
                {
                    Log.LogInfo(e.Message + "|" + e.StackTrace);
                }
                finally
                {
                    connectDone.Set();
                }
            }
                                 , sClient);
            //timeout
            if (!connectDone.WaitOne(2000))
            {
                Log.LogInfo("connect time out");
                MainLoader.ChangeStep(LoadStep.CannotConnect);
                yield break;
            }
            else
            {
                if (!sClient.Connected)
                {
                    Log.LogInfo("connect disabled by server");
                    MainLoader.ChangeStep(LoadStep.CannotConnect);
                    yield break;
                }
            }
        }
        catch
        {
            sClient.Close();
            MainLoader.ChangeStep(LoadStep.CannotConnect);
            yield break;
        }
        finally
        {
            connectDone.Close();
        }
        //Log.LogInfo("download:" + string.Format(strVFile, strHost, strPort, strProjectUrl, strPlatform, strVFileName));
        using (WWW vFile = new WWW(string.Format(strVFile, strHost, strPort, strProjectUrl, strPlatform, strVFileName)))
        {
            //Log.LogInfo("error:" + vFile.error);
            yield return(vFile);

            if (vFile.error != null && vFile.error.Length != 0)
            {
                //Log.LogInfo("error " + vFile.error);
                vFile.Dispose();
                //not have new version file
                //can continue game
                MainLoader.ChangeStep(LoadStep.NotNeedUpdate);
                yield break;
            }
            if (vFile.bytes != null && vFile.bytes.Length != 0)
            {
                File.WriteAllBytes(strUpdatePath + "/" + "v.zip", vFile.bytes);
                DeCompressFile(strUpdatePath + "/" + "v.zip", strUpdatePath + "/" + "v.xml");
                vFile.Dispose();
            }
            else
            {
                MainLoader.ChangeStep(LoadStep.NotNeedUpdate);
                yield break;
            }
        }

        XmlDocument xmlVer = new XmlDocument();

        xmlVer.Load(strUpdatePath + "/" + "v.xml");
        XmlElement ServerVer = xmlVer.DocumentElement;

        if (ServerVer != null)
        {
            string strServer = ServerVer.GetAttribute("ServerV");
            UpdateClient = HttpManager.AllocClient(string.Format(strDirectoryBase, strHost, strPort, strProjectUrl, strPlatform, strServer, ""));
            //if (strServer != null && GameData.Version().CompareTo(strServer) == -1)
            //{
            //	strServerVer = strServer;
            //	foreach (XmlElement item in ServerVer)
            //	{
            //		string strClientV = item.GetAttribute("ClientV");
            //		if (strClientV == GameData.Version())
            //		{
            //			strUpdateFile = item.GetAttribute("File");
            //			break;
            //		}
            //	}

            //	if (strUpdateFile != null && strUpdateFile.Length != 0)
            //		StartCoroutine("DownloadNecessaryData");
            //}
            //else
            //{
            //	Log.LogInfo("not need update");
            //             MainLoader.ChangeStep(LoadStep.NotNeedUpdate);
            //}
        }
    }