Exemplo n.º 1
0
    /// <summary>
    /// 根据PropertiesList文件,获取配置文件名的List
    /// </summary>
    /// <param name="filePath"></param>
    /// <param name="fileType"></param>
    /// <returns></returns>
    private string[] GetPropertiesList(string filePath, string fileType)
    {
        string text = FileOpt.ReadFile(filePath);

        text = text.Replace("\r", "");
        string[] lists = text.Split('\n');
        int      index = 0;

        while (!lists[index].Contains(fileType))
        {
            index++;
        }

        List <string> result = new List <string>();

        for (int i = index + 1; i < lists.Length; i++)
        {
            if (String.IsNullOrEmpty(lists[i]))
            {
                continue;
            }
            if (lists[i].Contains("["))
            {
                break;
            }
            result.Add(lists[i]);
        }
        return(result.ToArray());
    }
Exemplo n.º 2
0
    public static void AddItemToXml <T>(T[] infos)
    {
        Type t = typeof(T);

        FieldInfo[] fields = t.GetFields();

        string insertTag = "</Table>";

        string filePath    = "Resources/xml/" + t.Name + ".xml";
        string content     = FileOpt.ReadFile(filePath);
        int    insertIndex = content.IndexOf(insertTag);
        string s_pre       = content.Substring(0, insertIndex);
        string s_tail      = content.Substring(insertIndex, content.Length - insertIndex);

        //<Row ss:AutoFitHeight="0">
        //    <Cell><Data ss:Type="String">int</Data></Cell>
        //    <Cell><Data ss:Type="String">Vector3</Data></Cell>
        //    <Cell><Data ss:Type="String">string</Data></Cell>
        //</Row>

        string insertStr = "";

        for (int k = 0; k < infos.Length; k++)
        {
            T info = infos[k];
            insertStr += "   <Row>\n";
            for (int i = 0; i < fields.Length; i++)
            {
                FieldInfo fi = fields[i];
                insertStr += "    <Cell><Data ss:Type=\"String\">" + fi.GetValue(info) + "</Data></Cell>\n";
            }
            insertStr += "   </Row>\n";
        }
        content = s_pre + insertStr + s_tail;

        int fixIndex = content.IndexOf("ss:ExpandedRowCount");

        if (fixIndex >= 0)
        {
            int endFixInde = content.IndexOf(" ", fixIndex);
            content = content.Substring(0, fixIndex) + content.Substring(endFixInde, content.Length - endFixInde);
        }

        FileOpt.WriteFile(filePath, content);
    }
Exemplo n.º 3
0
    public static void ClearXmlData <T>()
    {
        Type   t        = typeof(T);
        string filePath = "Resources/Properties/" + t.Name + ".xml";
        string content  = FileOpt.ReadFile(filePath);
        int    index    = 0;

        for (int i = 0; i < 3; i++)
        {
            if (index >= 0)
            {
                index = content.IndexOf("</Row>", index + 6);
            }
        }
        if (index >= 0)
        {
            index += 7;
            int lastIndex = content.IndexOf("</Table>", index);
            content = content.Substring(0, index) + content.Substring(lastIndex, content.Length - lastIndex);
        }
        FileOpt.WriteFile(filePath, content);
    }
Exemplo n.º 4
0
    /// <summary>
    /// 加载xml文本
    /// </summary>
    /// <returns></returns>
    public string LoadXmlText(string path)
    {
        string text = FileOpt.ReadFile(path).Replace(":", replaceTag);

        return(text);
    }