private void UpdateMsgPool(CMessages messages, string path) { //foreach (var cMes in messages.messages) { string filePath = path + @"\MessagePool.java"; if (File.Exists(filePath)) { FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(stream); string content = reader.ReadToEnd(); reader.Close(); stream.Close(); string[] cts = content.Split('\n'); List <string> names = new List <string>(); List <string> ids = new List <string>(); List <MessgaeField> mfList = new List <MessgaeField>(); foreach (var ct in cts) { if (ct.Contains("import") && ct.Contains("com")) { int beginIndex = ct.LastIndexOf("."); int endIndex = ct.IndexOf("Buff"); names.Add(ct.Trim().Substring(beginIndex + 1, endIndex - beginIndex - 1)); } if (ct.Contains("register(") && ct.Contains(");")) { ids.Add(ct.Trim().Substring(9, 6)); } } if (names.Count > 0 && ids.Count > 0) { for (int i = 0; i < ids.Count; i++) { MessgaeField mf = new MessgaeField(); mf.name = names[i * 2]; mf.id = ids[i]; mfList.Add(mf); } } if (mfList.Count > 0) { WriteToMsgPool(messages, filePath, mfList); Debug.Log("MessagePool.java文件更新完毕"); } else { WriteToMsgPool(messages, filePath, null); Debug.Log("MessagePool.java文件更新完毕"); } } else { WriteToMsgPool(messages, filePath, null); Debug.Log("MessagePool.java文件更新完毕"); } } }
private void WriteToMsgPool(CMessages messages, string filePath, List <MessgaeField> fieldList) { string templatePath = @".\Templates\Java\temp_java_message_messagepool.vm"; List <string> needReplace = new List <string>(); ArrayList replace = new ArrayList(); needReplace.Add("MessageList"); List <MessgaeField> mf = new List <MessgaeField>(); if (fieldList != null) { foreach (var messgaeField in fieldList) { mf.Add(messgaeField); } } foreach (var cMessage in messages.messages) { MessgaeField mft = new MessgaeField(); mft.name = cMessage.name; mft.id = messages.ID + cMessage.ID; if (fieldList != null) { bool flag = false; foreach (var messgaeField in fieldList) { if (messgaeField.id == mft.id) { flag = true; break; } } if (!flag) { mf.Add(mft); } } else { mf.Add(mft); } } replace.Add(mf); CNVelociryHelp.CreateFileByTemplate(filePath, templatePath, needReplace, replace); }