Пример #1
0
    public void LoadConfig(string strOutFilePath, string strInFilePath)
    {
        string destPath = strOutFilePath;

        if (!File.Exists(strOutFilePath))
        {
            destPath = strInFilePath;
        }

        if (File.Exists(destPath))
        {
            using (StreamReader sr = new StreamReader(destPath, CommonFunc.GetCharsetEncoding()))
            {
                string strLine   = null;
                char[] trimStart = { ' ', '\t' };
                char[] trimEnd   = { ' ', '\r', '\n', '\t' };

                List <string>[] sectionData = null;
                List <string>   subData     = null;

                while ((strLine = sr.ReadLine()) != null)
                {
                    string strContent = XQConvert.Decrypt(strLine);

                    strContent = strContent.TrimEnd(trimEnd);
                    strContent = strContent.TrimStart(trimStart);

                    if (IsSection(ref strContent))
                    {
                        sectionData = GetSection(strContent);
                    }
                    else
                    {
                        if (IsTextureSub(strContent))
                        {
                            subData = GetSubData(sectionData, UISubSection.UI_Texture);
                        }
                        else if (IsSoundSub(strContent))
                        {
                            subData = GetSubData(sectionData, UISubSection.UI_Sound);
                        }
                        else if (subData != null)
                        {
                            subData.Add(strContent);
                        }
                    }
                }

                sr.Close();
            }
        }
        else
        {
            Debug.LogError("UI config file not exist: " + destPath);
        }
    }
Пример #2
0
    public void SaveConfig(string strFilePath)
    {
        using (StreamWriter sw = new StreamWriter(strFilePath, false, CommonFunc.GetCharsetEncoding()))
        {
            foreach (KeyValuePair <string, List <string>[]> curSection in m_ConfigData)
            {
                string strContent = "[" + curSection.Key + "]";
                string strLine    = XQConvert.Encrypt(strContent);
                sw.WriteLine(strLine);

                strContent = "\tTexture:";
                strLine    = XQConvert.Encrypt(strContent);
                sw.WriteLine(strLine);

                List <string> textureData = GetSubData(curSection.Value, UISubSection.UI_Texture);
                foreach (string textureName in textureData)
                {
                    strContent = "\t\t" + textureName;
                    strLine    = XQConvert.Encrypt(strContent);
                    sw.WriteLine(strLine);
                }

                strContent = "\tSound:";
                strLine    = XQConvert.Encrypt(strContent);
                sw.WriteLine(strLine);

                List <string> soundData = GetSubData(curSection.Value, UISubSection.UI_Sound);
                foreach (string soundName in soundData)
                {
                    strContent = "\t\t" + soundName;
                    strLine    = XQConvert.Encrypt(strContent);
                    sw.WriteLine(strLine);
                }
            }

            sw.Close();
        }
    }