Exemple #1
0
        /// <summary>
        /// xml转二进制
        /// </summary>
        /// <param name="name"></param>
        private static void XmlToBinary(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            try
            {
                Type type = null;
                foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
                {
                    Type tempType = asm.GetType(name);
                    if (tempType != null)
                    {
                        type = tempType;
                        break;
                    }
                }
                if (type != null)
                {
                    string xmlPath    = XmlPath + name + ".xml";
                    string binaryPath = BinaryPath + name + ".bytes";
                    object obj        = BinarySerializeOpt.XmlDeserialize(xmlPath, type);
                    BinarySerializeOpt.BinarySerilize(binaryPath, obj);
                    Debug.Log(name + "xml转二进制成功,二进制路径为:" + binaryPath);
                }
            }
            catch
            {
                Debug.LogError(name + "xml转二进制失败!");
            }
        }
        /// <summary>
        /// 从服务器端读取Server.xml数据
        /// </summary>
        /// <param name="xmlUrl"></param>
        /// <param name="callBack"></param>
        /// <returns></returns>
        private IEnumerator ReadServerInfoXml(string xmlUrl, Action callBack)
        {
            Debug.Log("ReadServerInfoXml " + xmlUrl);
            UnityWebRequest webRequest = UnityWebRequest.Get(xmlUrl);

            yield return(webRequest.SendWebRequest());

            if (webRequest.isNetworkError)
            {
                Debug.Log("Download Error" + webRequest.error);
            }
            else
            {
                yield return(FileUtil.Instance.CreateFile(m_serverXmlPath, webRequest.downloadHandler.data, null));

                yield return(new WaitForEndOfFrame());

                if (File.Exists(m_serverXmlPath))
                {
                    m_serverInfo = BinarySerializeOpt.XmlDeserialize(m_serverXmlPath, typeof(ServerInfo)) as ServerInfo;
                }
                else
                {
                    Debug.LogError("热更配置读取错误!");
                }
            }
            yield return(WaitProgressAdd(0.02f));

            callBack?.Invoke();
        }
        private IEnumerator ReadUnpackMd5File()
        {
#if XML
            string checkFilePath = m_downLoadPath + "/UnpackMd5_" + CurVersion + "_" + CurrentPatches.Version + ".xml";
            Debug.Log("checkFilePath :" + checkFilePath);
            yield return(ReadUnpackMd5Inifo(m_currentPatches.Files[0].Url, checkFilePath));

            m_zipMd5Data = BinarySerializeOpt.XmlDeserialize(checkFilePath, typeof(ZipMd5Data)) as ZipMd5Data;
#elif JSON
            m_zipMd5Data = new UnpackMd5InfoDataModule();
            foreach (Patches patches in m_needUpdatePatchesInfos)
            {
                string checkFilePath = m_downLoadPath + "/UnpackMd5_" + CurVersion + "_" + patches.Version + ".json";
                Debug.Log("checkFilePath :" + checkFilePath);
                //if (patches.Files[0].Name.StartsWith("UnpackMd5_"))
                //{
                yield return(ReadUnpackMd5Inifo(patches.Files[0].Url, checkFilePath));

                StreamReader sr              = new StreamReader(checkFilePath);
                var          content         = sr.ReadToEnd();
                var          zipMd5DataCache = new UnpackMd5InfoDataModule(JsonMapper.ToObject(content));
                m_zipMd5Data.ZipMd5List = m_zipMd5Data.ZipMd5List.Concat(zipMd5DataCache.ZipMd5List).ToList();
                sr.Close();
                //}
            }
#endif
            yield return(null);
        }
Exemple #4
0
 static void XmlToBinary(string name)
 {
     try
     {
         Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
         Type       type       = null;
         foreach (Assembly assembly in assemblies)
         {
             type = assembly.GetType(name);
             if (type != null)
             {
                 break;
             }
         }
         if (type != null)
         {
             string xmlPath    = XML_DATA_PATH + name + ".xml";
             object obj        = BinarySerializeOpt.XmlDeserialize(type, xmlPath);
             string binaryPath = BINARY_DATA_PATH + name + ".bytes";
             BinarySerializeOpt.BinarySerialize(binaryPath, obj);
             Debug.Log("Xml转Binary成功 path:" + binaryPath);
         }
     }
     catch (System.Exception)
     {
         Debug.LogError("XmlToBinary 转换失败 name:" + name);
     }
 }
Exemple #5
0
    /// <summary>
    /// 加载data
    /// </summary>
    /// <param name="path">路径</param>
    /// <typeparam name="T">ExcelBase类</typeparam>
    /// <returns></returns>
    public T LoadData <T>(string path) where T : ExcelBase
    {
        if (string.IsNullOrEmpty(path))
        {
            return(null);
        }
        if (m_ExcelDataDic.ContainsKey(path))
        {
            return(m_ExcelDataDic[path] as T);
        }
        T data = null;

        data = BinarySerializeOpt.BinaryDeserialize <T>(path);
        //如果在编译器中 未生成二进制 转为xml读取
#if UNITY_EDITOR
        if (data == null)
        {
            Debug.LogWarning("LoadData 未生成Binary文件 path:" + path);
            path = path.Replace("Binary", "Xml").Replace(".bytes", ".xml");
            data = BinarySerializeOpt.XmlDeserialize <T>(path);
        }
#endif
        if (data != null)
        {
            data.Init();
        }
        return(data);
    }
Exemple #6
0
    //xml反序列化转成类
    private static object XmlToObject(string name)
    {
        Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
        Type       type       = null;

        foreach (Assembly assembly in assemblies)
        {
            type = assembly.GetType(name);
            if (type != null)
            {
                break;
            }
        }
        if (type != null)
        {
            string xmlPath = XML_DATA_PATH + name + ".xml";
            return(BinarySerializeOpt.XmlDeserialize(type, xmlPath));
        }
        return(null);
    }
Exemple #7
0
    /// <summary>
    /// 反序列化xml到类
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    private static object GetObjectFromXml(string name)
    {
        Type type = null;

        foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
        {
            Type tempType = asm.GetType(name);
            if (tempType != null)
            {
                type = tempType;
                break;
            }
        }
        if (type != null)
        {
            string xmlPath = XmlPath + name + ".xml";
            return(BinarySerializeOpt.XmlDeserialize(xmlPath, type));
        }
        return(null);
    }
Exemple #8
0
        /// <summary>
        /// 检查本地热更信息与服务器热更信息比较
        /// </summary>
        /// <returns></returns>
        private bool CheckLocalAndServerPatch()
        {
            if (!File.Exists(m_LocalXmlPath))
            {
                return(true);
            }
            m_LocalInfo = BinarySerializeOpt.XmlDeserialize(m_LocalXmlPath, typeof(ServerInfo)) as ServerInfo;
            VersionInfo versionInfo1 = (VersionInfo)null;

            if (m_LocalInfo != null)
            {
                foreach (VersionInfo versionInfo2 in m_LocalInfo.GameVersion)
                {
                    if (versionInfo2.Version == m_CurVersion)
                    {
                        versionInfo1 = versionInfo2;
                        break;
                    }
                }
            }
            return(versionInfo1 != null && m_GameVersion.Patches != null && (versionInfo1.Patches != null && m_GameVersion.Patches.Length != 0) && m_GameVersion.Patches[m_GameVersion.Patches.Length - 1].Version != versionInfo1.Patches[versionInfo1.Patches.Length - 1].Version);
        }
        /// <summary>
        /// 检查本地热更信息与服务器热更信息比较
        /// </summary>
        /// <returns> false 不需要更新, true 需要更新</returns>
        private bool CheckLocalAndServerPatch()
        {
#if JSON
            //if (!File.Exists(m_localJsonPath))
            //    return true;

            Branches branch = null;

            var branches = m_serverInfoDataModule.GameVersionInfos.FirstOrDefault(i => i.GameVersion == m_curVersion);
            Debug.Assert(null != branches, "未找到与当前App Version 所匹配的更新信息 : App Version " + m_curVersion);

            branch = branches.Branches.FirstOrDefault(i => i.BranchName == m_branchName);
            Debug.Assert(null != branches, "未找到与当前Branch Name 所匹配的更新信息 : Branch Name " + m_branchName);


            var assetVersion = LocalVersionInfoManager.Instance.GetVersionInfo(m_curVersion, m_branchName);
            if (null != assetVersion && "" != assetVersion)
            {
                // 获取与本地版本相匹配的版本序号
                var localPatch = branch.Patches.FirstOrDefault(i => i.Version == assetVersion);
                m_localVersionIndex = branch.Patches.IndexOf(localPatch) + 1;
                m_localVersion      = branch.Patches[m_localVersionIndex - 1].Version;

                Debug.Log("当前本地资源版本 : " + m_localVersion);
            }

            m_targetVersion = branch.Patches[m_currentBranch.Patches.Count - 1].Version;

            return("" != assetVersion &&
                   null != m_currentBranch.Patches &&
                   assetVersion != m_currentBranch.Patches[m_currentBranch.Patches.Count - 1].Version);

            //   // 读取本地版本信息
            //   StreamReader sr = new StreamReader(m_localJsonPath);
            //   var content = sr.ReadToEnd();
            //   m_localInfoDataModule = new ServerInfoDataModule(JsonMapper.ToObject(content));
            //   sr.Close();

            //   // 匹配与当前APP Version所匹配的资源信息
            //   //GameVersionInfo matchInfo = null;
            //   if (null != m_localInfoDataModule)
            //   {
            //       var info = m_localInfoDataModule.GameVersionInfos.FirstOrDefault(i => i.GameVersion == m_curVersion);
            //       if (null != info)
            //       {
            //           // 获取当前本地资源版本

            //           branch = info.Branches.FirstOrDefault(i => i.BranchName == m_branchName);


            //           m_localVersionIndex = branch.Patches.Count;
            //           m_localVersion = branch.Patches[m_localVersionIndex - 1].Version;
            //           Debug.Log("当前本地资源版本 : " + m_localVersion);
            //       }
            //}

            //   // 与服务端对应的APP Version相关信息进行比对, 如果当前的热更好与服务器端最新的一样就返回true;
            //   return null != branch &&
            //          null != m_currentBranch.Patches &&
            //          (null != branch.Patches && m_currentBranch.Patches.Count != 0) &&
            //          m_currentBranch.Patches[m_currentBranch.Patches.Count - 1].Version != m_localVersion;
#elif XML
            if (!File.Exists(m_localXmlPath))
            {
                return(true);
            }
            m_localInfo = BinarySerializeOpt.XmlDeserialize(m_localXmlPath, typeof(ServerInfo)) as ServerInfo;
            VersionInfo versionInfo1 = null;
            if (m_localInfo != null)
            {
                foreach (VersionInfo versionInfo2 in m_localInfo.GameVersion)
                {
                    if (versionInfo2.Version == m_curVersion)
                    {
                        versionInfo1 = versionInfo2;
                        break;
                    }
                }
            }
            return(versionInfo1 != null &&
                   m_gameVersion.Patches != null &&
                   (versionInfo1.Patches != null && m_gameVersion.Patches.Length != 0) &&
                   m_gameVersion.Patches[m_gameVersion.Patches.Length - 1].Version != versionInfo1.Patches[versionInfo1.Patches.Length - 1].Version);
#endif
        }