Exemplo n.º 1
0
        private void LoadUpdateXMLOK(Dictionary <string, UpdateFileInfo> _dic, int _remoteVersion, Func <string, string> _fixFun, Action _callBack)
        {
            int loadNum = _dic.Count;

            foreach (KeyValuePair <string, UpdateFileInfo> pair in _dic)
            {
                string         path = pair.Key;
                UpdateFileInfo info = pair.Value;

                string url = _fixFun(info.path + path);

                Action <WWW> callBack = delegate(WWW obj) {
                    if (obj.error != null)
                    {
                        SuperDebug.Log("文件热更新失败 文件名:" + obj.url);

                        return;
                    }

                    UInt32 crc = CRC32.Compute(obj.bytes);

                    if (crc != info.crc)
                    {
                        SuperDebug.Log("文件热更新CRC比对错误 文件名:" + obj.url);

                        return;
                    }

                    SystemIO.SaveFile(Application.persistentDataPath + "/" + path, obj.bytes);

                    if (data.dic.ContainsKey(path))
                    {
                        data.dic[path] = info.version;
                    }
                    else
                    {
                        data.dic.Add(path, info.version);
                    }

                    loadNum--;

                    if (loadNum == 0)
                    {
                        UpdateOver(_remoteVersion, _callBack);
                    }
                };

                WWWManager.Instance.LoadRemote(url, callBack);
            }
        }
Exemplo n.º 2
0
        private void LoadUpdateXML(int _allFileSize, Dictionary <string, UpdateFileInfo> _dic, int _remoteVersion, int _version, Func <int, string> _fixFun, Func <string, string> _fixFun2, Action _callBack, Action <string> _setTextCallBack, Action <float> _setPercentCallBack, int _updateWarningSize, Action <string, Action> _showWarningCallBack)
        {
            if (_version > data.version)
            {
                string url = _fixFun(_version);

                Action <WWW> callBack = delegate(WWW obj) {
                    if (obj.error != null)
                    {
                        _setTextCallBack("热更新列表加载失败");

                        SuperDebug.Log("文件热更新失败 文件名:" + obj.url);

                        return;
                    }

                    XmlDocument xmlDoc = new XmlDocument();

                    xmlDoc.LoadXml(PublicTools.XmlFix(obj.text));

                    XmlNodeList hhh = xmlDoc.ChildNodes[0].ChildNodes;

                    foreach (XmlNode node in hhh)
                    {
                        string nodeUrl = node.InnerText;

                        if (!_dic.ContainsKey(nodeUrl))
                        {
                            int fileSize = int.Parse(node.Attributes["size"].Value);

                            if (fileSize == -1)
                            {
                                if (data.dic.ContainsKey(nodeUrl))
                                {
                                    data.dic.Remove(nodeUrl);
                                }
                            }
                            else
                            {
                                _allFileSize += fileSize;

                                UpdateFileInfo fileInfo = new UpdateFileInfo();

                                fileInfo.version = _version;

                                fileInfo.size = fileSize;

                                fileInfo.path = node.Attributes["path"].Value;

                                fileInfo.crc = Convert.ToUInt32(node.Attributes["crc"].Value, 16);

                                _dic.Add(nodeUrl, fileInfo);
                            }
                        }
                    }

                    LoadUpdateXML(_allFileSize, _dic, _remoteVersion, _version - 1, _fixFun, _fixFun2, _callBack, _setTextCallBack, _setPercentCallBack, _updateWarningSize, _showWarningCallBack);
                };

                WWWManager.Instance.LoadRemote(url, callBack);
            }
            else
            {
                if (_allFileSize >= _updateWarningSize && _showWarningCallBack != null)
                {
                    Action callBack = delegate() {
                        LoadUpdateXMLOK(_dic, _remoteVersion, _fixFun2, _callBack, _setTextCallBack, _setPercentCallBack, _allFileSize);
                    };

                    float tempnum = (float)Math.Round(((float)_allFileSize) / 1024 / 1024, 2);

                    string msg = "需要更新" + tempnum.ToString() + "MB大小的新文件,确认更新吗?";

                    _showWarningCallBack(msg, callBack);
                }
                else
                {
                    LoadUpdateXMLOK(_dic, _remoteVersion, _fixFun2, _callBack, _setTextCallBack, _setPercentCallBack, _allFileSize);
                }
            }
        }
Exemplo n.º 3
0
        private void LoadUpdateXMLOK(Dictionary <string, UpdateFileInfo> _dic, int _remoteVersion, Func <string, string> _fixFun, Action _callBack, Action <string> _setTextCallBack, Action <float> _setPercentCallBack, int _allFileSize)
        {
            int loadNum = _dic.Count;

            int loadSize = 0;

            foreach (KeyValuePair <string, UpdateFileInfo> pair in _dic)
            {
                string path = pair.Key;

                UpdateFileInfo info = pair.Value;

                string url = _fixFun(info.path + path);

                Action <WWW> callBack = delegate(WWW obj) {
                    if (obj.error != null)
                    {
                        _setTextCallBack("文件热更新失败 文件名:" + obj.url);

                        SuperDebug.Log("文件热更新失败 文件名:" + obj.url);

                        return;
                    }

                    UInt32 crc = CRC32.Compute(obj.bytes);

                    if (crc != info.crc)
                    {
                        _setTextCallBack("文件热更新CRC比对错误 文件名:" + obj.url);

                        SuperDebug.Log("文件热更新CRC比对错误 文件名:" + obj.url);

                        return;
                    }

#if PLATFORM_PC || PLATFORM_ANDROID
                    if (path.Equals(CODE_BYTES_NAME))
                    {
                        codeBytes = obj.bytes;
                    }
                    else
                    {
                        SystemIO.SaveFile(Application.persistentDataPath + "/" + path, obj.bytes);
                    }
#else
                    SystemIO.SaveFile(Application.persistentDataPath + "/" + path, obj.bytes);
#endif

                    if (data.dic.ContainsKey(path))
                    {
                        data.dic[path] = info.version;
                    }
                    else
                    {
                        data.dic.Add(path, info.version);
                    }

                    loadNum--;

                    //_setTextCallBack("正在更新:" + (_dic.Count - loadNum) + "/" + _dic.Count);

                    loadSize += info.size;

                    _setTextCallBack("正在更新:" + Math.Round((float)loadSize / (float)_allFileSize * 100) + "%(" + Math.Round((float)loadSize / 1024 / 1024, 1) + "/" + Math.Round((float)_allFileSize / 1024 / 1024, 1) + ")");

                    _setPercentCallBack((float)loadSize / (float)_allFileSize);

                    if (loadNum == 0)
                    {
                        UpdateOver(_remoteVersion, _callBack);
                    }
                };

                WWWManager.Instance.LoadRemote(url, callBack);
            }
        }
Exemplo n.º 4
0
        private void LoadUpdateXML(Dictionary <string, UpdateFileInfo> _dic, int _remoteVersion, int _version, Func <int, string> _fixFun, Func <string, string> _fixFun2, Action _callBack)
        {
            if (_version > data.version)
            {
                string url = _fixFun(_version);

//				url = @"http://192.168.40.240/update_and/versions/update_101_and_facebook.xml";

                Action <WWW> callBack = delegate(WWW obj) {
                    if (obj.error != null)
                    {
                        SuperDebug.Log("文件热更新失败 文件名:" + obj.url);

                        return;
                    }

                    XmlDocument xmlDoc = new XmlDocument();

                    xmlDoc.LoadXml(PublicTools.XmlFix(obj.text));

                    XmlNodeList hhh = xmlDoc.ChildNodes[0].ChildNodes;

                    foreach (XmlNode node in hhh)
                    {
                        string nodeUrl = node.InnerText;

                        if (!_dic.ContainsKey(nodeUrl))
                        {
                            int fileSize = int.Parse(node.Attributes["size"].Value);

                            if (fileSize == -1)
                            {
                                if (data.dic.ContainsKey(nodeUrl))
                                {
                                    data.dic.Remove(nodeUrl);
                                }
                            }
                            else
                            {
                                UpdateFileInfo fileInfo = new UpdateFileInfo();

                                fileInfo.version = _version;

                                fileInfo.size = fileSize;

                                fileInfo.path = node.Attributes["path"].Value;

                                fileInfo.crc = Convert.ToUInt32(node.Attributes["crc"].Value, 16);

                                _dic.Add(nodeUrl, fileInfo);
                            }
                        }
                    }

                    LoadUpdateXML(_dic, _remoteVersion, _version - 1, _fixFun, _fixFun2, _callBack);
                };

                WWWManager.Instance.LoadRemote(url, callBack);
            }
            else
            {
                LoadUpdateXMLOK(_dic, _remoteVersion, _fixFun2, _callBack);
            }
        }