コード例 #1
0
ファイル: XQIni.cs プロジェクト: happylays/tbb2
        void _RebuildIni()
        {
            if (File.Exists(m_strIniPath))
            {
                using (StreamWriter sw = new StreamWriter(m_strIniPath, false, CommonFunc.GetCharsetEncoding()))
                {
                    for (int i = 0; i < m_OriginContent.Count; ++i)
                    {
                        string temp = (m_bXQConvert ? XQConvert.Encrypt(m_OriginContent[i]) : m_OriginContent[i]);

                        if (i != m_OriginContent.Count - 1)
                        {
                            sw.WriteLine(temp);
                        }
                        else
                        {
                            sw.Write(temp);
                        }
                    }

                    sw.Close();
                }
            }
            else
            {
                Debug.LogError("ini file is not exist " + m_strIniPath);
            }
        }
コード例 #2
0
ファイル: XQIni.cs プロジェクト: happylays/tbb2
        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();
            }
        }