Пример #1
0
        private bool needUpdate(VersionResourceFile local, VersionResourceFile server, List <string> update, List <int> updateSize)
        {
            //后期采用先判定版本号
            foreach (KeyValuePair <string, string> file in server.mPathMD5)
            {
                if (local.mPathMD5.ContainsKey(file.Key))
                {
                    if (local.mPathMD5[file.Key] != file.Value)
                    {
                        update.Add(file.Key);
                        mAllNeedDownLoadBytes += server.mSize[file.Key];
                        updateSize.Add(server.mSize[file.Key]);
                    }
                }
                else
                {
                    update.Add(file.Key);
                    mAllNeedDownLoadBytes += server.mSize[file.Key];
                    updateSize.Add(server.mSize[file.Key]);
                }
            }

            //测试
            foreach (string str in update)
            {
                Debug.LogError("need update" + str);
            }
            return(update.Count > 0 ? true : false);
        }
Пример #2
0
        //热更新,更新资源
        public void updateResource()
        {
            mLocalPathMD5         = new VersionResourceFile();
            mServerPathMD5        = new VersionResourceFile();
            mUpdateAssets         = new List <string>();
            mUpdateAssetsSize     = new List <int>();
            mAllNeedDownLoadSize  = 0;
            mCurrentDownLoadSize  = 0;
            mAllNeedDownLoadBytes = 0;
            mCurrentDownLoadBytes = 0;
            mComplete             = false;

            mCurrentDownLoadAsset            = "";
            mCurrentDownLoadAssetFailedTimes = 0;
            mMaxRepeatDownLoadTimes          = 5;
            mForceTermination = false;

            mNetworkConnections              = true;
            mNeedCheckNetWorkConnections     = false;
            mCheckNetWorkConnectionsMaxTimes = 10;

            //1.加载本地资源version.xml信息
            StreamReader localReader = ResourcesManager.OpenText("Version");

            parseResourceVersionFile(localReader.ReadToEnd(), ref mLocalPathMD5);
            localReader.Close();

            //2.加载服务器version.xml信息
            StartCoroutine(downLoad(ResourceCommon.getServerPath("Version.bytes"), delegate(WWW resourceVersion)
            {
                parseResourceVersionFile(resourceVersion.text, ref mServerPathMD5);


                if (needUpdate(mLocalPathMD5, mServerPathMD5, mUpdateAssets, mUpdateAssetsSize))
                {
                    Debug.LogError("need update true");

                    mAllNeedDownLoadSize = mUpdateAssets.Count;

                    //4.下载最新资源
                    downLoadAssets();
                }
                else
                {
                    mComplete = true;
                    OnUpdateComplete();
                    Debug.LogError("Complete update");
                }
            }));
        }
Пример #3
0
        //解析版本资源信息
        private void parseResourceVersionFile(string text, ref VersionResourceFile file)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(text);
            XmlElement root = doc.DocumentElement;

            file.mNumber = root.GetAttribute("Number");
            file.mBig    = Convert.ToBoolean(root.GetAttribute("Big"));
            IEnumerator iter = root.GetEnumerator();

            while (iter.MoveNext())
            {
                XmlElement child = iter.Current as XmlElement;
                file.mPathMD5.Add(child.GetAttribute("fpath"), child.GetAttribute("md5"));
                file.mSize.Add(child.GetAttribute("fpath"), Convert.ToInt32(child.GetAttribute("size")));
            }

            Debug.LogError("paser version fil okk" + text);
        }