public void WriteFile(AllChatHistoryData data) { if (!Directory.Exists(folderName)) { Directory.CreateDirectory(folderName); } string folderNameWithID = folderName + "//" + data.channel; if (!Directory.Exists(folderNameWithID)) { Directory.CreateDirectory(folderNameWithID); } if (data == null) { return; } System.DateTime dt = EB.Time.FromPosixTime(data.ts).ToLocalTime(); string fileName = dt.ToString("yyyyMMdd"); //Debug.Log("write yyyymmdd format fileName=" + fileName); FileStream fs = new FileStream(folderNameWithID + "//" + fileName, FileMode.Append); BinaryWriter bw = new BinaryWriter(fs); bw.Write(System.Text.Encoding.UTF8.GetByteCount(data.content)); bw.Write(System.Text.Encoding.UTF8.GetBytes(data.content)); bw.Close(); fs.Close(); fs.Dispose(); //Debug.Log("WriteFile targetId=" + data.channel + "--------over"); }
public List <AllChatHistoryData> ReadFile(Queue <string> fileNames) { List <AllChatHistoryData> dataList = new List <AllChatHistoryData>(); while (fileNames.Count > 0) { string fileName = fileNames.Dequeue(); FileStream fs = new FileStream(fileName, FileMode.Open); BinaryReader br = new BinaryReader(fs); if (fs == null) { br.Close(); fs.Close(); fs.Dispose(); EB.Debug.LogError("fs=null filename={0}", fileName); continue; } try { while (true) { AllChatHistoryData data = new AllChatHistoryData(); int contentLength = br.ReadInt32(); data.content = System.Text.Encoding.UTF8.GetString(br.ReadBytes(contentLength)); dataList.Add(data); } } catch (Exception) { EB.Debug.Log("ReadFile:{0}----done!", fileName); } br.Close(); fs.Close(); fs.Dispose(); } return(dataList); }
public void SaveData(EB.Sparx.ChatMessage msg, ChatRule.CHAT_CHANNEL channel) { if (AddChatHistory(msg, channel)) { //世界聊天没必要保存到本地 if (channel == ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_WORLD) { return; } AllChatHistoryData hd = new AllChatHistoryData(); hd.channel = channel; if (msg.json != null) { hd.content = EB.JSON.Stringify(msg.json); } else { hd.content = EB.JSON.Stringify(makeJson(msg)); } hd.ts = msg.ts; SaveData(hd); } }
public void SaveData(AllChatHistoryData data) { m_writeThreadQueue.Enqueue(data); ThreadUpdate(); }