public void WriteString2(string strIn) { byte[] bytes = CommonFunc.GetCharsetEncoding().GetBytes(strIn); int nLength = bytes.Length; if (nLength > 0) { WriteUShort((UInt16)nLength); m_fsSource.Write(bytes, 0, nLength); } else { WriteUShort(0); } }
public void ReadString(ref string strOut, UInt16 nSize) { strOut = ""; if (nSize > 0) { byte[] bytes = new byte[nSize]; if (m_fsSource != null && (m_fsSource.Read(bytes, 0, nSize) == nSize)) { try { strOut = CommonFunc.GetCharsetEncoding().GetString(bytes, 0, bytes.Length); } catch (System.ArgumentException e) { // Debug.LogError(e); Debug.LogException(e); } } } }
public void LoadIni(string strPath, bool bCaseSensitive, bool bXQConvert) { m_bCaseSensitive = bCaseSensitive; m_bXQConvert = bXQConvert; m_strIniPath = strPath; m_AllSetting.Clear(); m_OriginContent.Clear(); m_AssistContent.Clear(); if (strPath != null && File.Exists(strPath)) { try { using (StreamReader sr = new StreamReader(strPath, CommonFunc.GetCharsetEncoding())) { char[] trimStart = { ' ', '\t' }; char[] trimEnd = { ' ', '\r', '\n', '\t' }; string strSection = ""; Dictionary <string, string> sectionSetting = null; string strLine = null; while ((strLine = sr.ReadLine()) != null) { if (m_bXQConvert) { strLine = XQConvert.Decrypt(strLine); } m_OriginContent.Add(strLine); string strAssist = strLine; strAssist = strAssist.TrimStart(trimStart); strAssist = strAssist.TrimEnd(trimEnd); if (_ParseSection(strAssist, ref strSection)) { if (m_AllSetting.ContainsKey(strSection)) { sectionSetting = m_AllSetting[strSection]; } else { sectionSetting = new Dictionary <string, string>(); m_AllSetting.Add(strSection, sectionSetting); } m_AssistContent.Add(_BuildAssistSection(strSection)); } else { string key = ""; string value = ""; if (_ParseSetting(strAssist, ref key, ref value) && sectionSetting != null) { if (sectionSetting.ContainsKey(key)) { Debug.LogError("key already exist, will be replaced: " + strSection + " -- " + key); sectionSetting[key] = value; } else { sectionSetting.Add(key, value); } m_AssistContent.Add(_BuildAssistSetting(key, value)); } else { m_AssistContent.Add(strAssist); } } } sr.Close(); } } catch (System.IO.FileNotFoundException e) { Debug.LogException(e); //Debug.LogError( e.ToString() ); } catch (System.IO.DirectoryNotFoundException e) { Debug.LogException(e); //Debug.LogError( e.ToString() ); } } else { StreamWriter sw = File.CreateText(strPath); sw.Dispose(); } }