private static void processCompreResultVo(CompreResultVo cr) { StringBuilder packHead = new StringBuilder(); StringBuilder packConstant = new StringBuilder(); foreach (var item in xmlMapping.Keys) { StringBuilder sb = xmlMapping[item]; packHead.Append(item).Append("|").Append(sb.ToString().Length).Append(";"); packConstant.Append(sb.ToString()); } ByteArray myByteArr = new ByteArray(); myByteArr.Seek(0, SeekOrigin.Begin); myByteArr.WriteString(packHead.ToString()); myByteArr.WriteString(packConstant.ToString()); myByteArr.Seek(0, SeekOrigin.Begin); byte[] resultArr = new byte[myByteArr.Length]; myByteArr.Read(resultArr, 0, (int)myByteArr.Length); myByteArr.Close(); // 压缩 后 加密 EncryptionManager encryptionManager = new EncryptionManager(); encryptionManager.Awake(); byte[] encryptionAndComressByteArr = encryptionManager.encryption(resultArr); // 写入Resources中 File.WriteAllBytes(Application.dataPath + "/" + cr.filePath.Replace("\r\n", "").Trim(), encryptionAndComressByteArr); }
private static void convertionXmlToBytes() { GameConfigVo vo = GameTools.createGameConfigVoByXml(); string[] resultInfoArr = vo.packageArrRef.Split(new char[] { ':' }); CompreResultVo cr = new CompreResultVo(); cr.filePath = resultInfoArr[0]; cr.childFileArr = resultInfoArr[1].Split(new char[] { ',' }); processCompreXmlVo(cr); processCompreResultVo(cr); removeXmlNodeLst.RemoveAll(delegate(XmlNode node) { return(true); }); }
private static void processCompreXmlVo(CompreResultVo cr) { foreach (string path in cr.childFileArr) { string currFilePath = path.Replace("\r\n", "").Trim(); // 将文件读取出来了 FileStream fs = File.OpenRead(Application.dataPath + currFilePath); // 写入到byte[]中 byte[] resultByteArr = new byte[fs.Length]; fs.Read(resultByteArr, 0, (int)fs.Length); fs.Close(); // 文件中的字符串保存在sb中,然后将文件名作为key , 文件内容作为 val string[] s = currFilePath.Split(new char[] { '/' }); string fileName = s[s.Length - 1].Split(new char[] { '.' })[0]; if (xmlMapping.ContainsKey(fileName)) { throw new Exception(fileName + " 重复打包了!"); } if (currFilePath.IndexOf("I18N") >= 0) { i18nFileCount += 1; } if (i18nFileCount > 1) { throw new Exception("I18N配置只能有一种!"); } string xmlStr = Encoding.UTF8.GetString(resultByteArr); xmlStr = clearXml(fileName, xmlStr); xmlMapping[fileName] = new StringBuilder(xmlStr); } }