Exemple #1
0
        private static string CreateData(IniStructure IniData, string comment)
        {       //Iterates through all categories and keys and appends all data to Data
            int CategoryCount = IniData.GetCategories().Length;

            int[]  KeyCountPerCategory = new int[CategoryCount];
            string Data = comment;

            string[] temp = new string[2];          // will contain key-value pair

            for (int i = 0; i < CategoryCount; i++) // Gets keycount per category
            {
                string CategoryName = IniData.GetCategories()[i];
                KeyCountPerCategory[i] = IniData.GetKeys(CategoryName).Length;
            }

            for (int catcounter = 0; catcounter < CategoryCount; catcounter++)
            {
                Data += "\r\n[" + IniData.GetCategoryName(catcounter) + "]\r\n";
                // writes [Category] to Data
                for (int keycounter = 0; keycounter < KeyCountPerCategory[catcounter]; keycounter++)
                {
                    temp[0] = IniData.GetKeyName(catcounter, keycounter);
                    temp[1] = IniData.GetValue(catcounter, keycounter);
                    Data   += temp[0] + "=" + temp[1] + "\r\n";
                    // writes the key-value pair to Data
                }
            }
            return(Data);
        }
Exemple #2
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        public void Init()
        {
            string   connectString = "Server = 10.20.86.11; DataBase = s3design_rtm; Uid = s3design; Password = davidbowie;"; // 默认连接字符串
            string   filename      = Path.Combine(Application.StartupPath, "GameDesingerTools_Public.ini");
            FileInfo fi            = new FileInfo(filename);

            if (fi.Exists)
            {
                string       content = FileFolderHelper.FileToString(filename);
                IniStructure m_inis  = new IniStructure();
                m_inis        = IniStructure.ReadIniWithContent(content);
                connectString = m_inis.GetValue("General", "ConnString");
            }
            else
            {
                filename = Path.Combine(Application.StartupPath, "GameDesingerTools_Public.ini");
                fi       = new FileInfo(filename);
                if (fi.Exists) // 读取AutoExport.ini文件
                {
                    string          content = FileFolderHelper.FileToString(filename);
                    SymmetricMethod sm      = new SymmetricMethod();
                    content = sm.Decrypto(content);

                    IniStructure m_inis = new IniStructure();
                    m_inis        = IniStructure.ReadIniWithContent(content);
                    connectString = m_inis.GetValue("General", "ConnString");
                }
            }

            conn = new SqlConnection(connectString);

            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                string sqlString = "SELECT * FROM AI_Enum_Define";
                enumTable      = GetDataTable(sqlString);
                sqlString      = "SELECT * FROM AI_TemplateParamTable";
                parameterTable = GetDataTable(sqlString);
                sqlString      = "SELECT ID, FullPath FROM changan.s3diagram_rtm.dbo.diagram WHERE Class = 'AI图'";
                diagramTable   = GetDataTable(sqlString);
            }
            catch (SqlException ex)
            {
                MessageBox.Show("在读取数据表信息时产生sql异常:" + ex.ToString());
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        public void Init()
        {
            string connectString = "Server = 10.20.86.11; DataBase = s3design_rtm; Uid = s3design; Password = davidbowie;"; // 默认连接字符串           
            string filename = Path.Combine(Application.StartupPath, "GameDesingerTools_Public.ini");
            FileInfo fi = new FileInfo(filename);

            if (fi.Exists)
            {
                string content = FileFolderHelper.FileToString(filename);
                IniStructure m_inis = new IniStructure();
                m_inis = IniStructure.ReadIniWithContent(content);
                connectString = m_inis.GetValue("General", "ConnString");
            }
            else
            {
                filename = Path.Combine(Application.StartupPath, "GameDesingerTools_Public.ini");
                fi = new FileInfo(filename);
                if (fi.Exists) // 读取AutoExport.ini文件
                {
                    string content = FileFolderHelper.FileToString(filename);
                    SymmetricMethod sm = new SymmetricMethod();
                    content = sm.Decrypto(content);

                    IniStructure m_inis = new IniStructure();
                    m_inis = IniStructure.ReadIniWithContent(content);
                    connectString = m_inis.GetValue("General", "ConnString"); 
                }
            }

            conn = new SqlConnection(connectString);

            try
            {
                if(conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                string sqlString = "SELECT * FROM AI_Enum_Define";
                enumTable = GetDataTable(sqlString);
                sqlString = "SELECT * FROM AI_TemplateParamTable";
                parameterTable = GetDataTable(sqlString);
                sqlString = "SELECT ID, FullPath FROM changan.s3diagram_rtm.dbo.diagram WHERE Class = 'AI图'";
                diagramTable = GetDataTable(sqlString);
            }
            catch (SqlException ex)
            {
                MessageBox.Show("在读取数据表信息时产生sql异常:" + ex.ToString());
            }
            finally
            {
                if(conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }            
        }
Exemple #4
0
        /// <summary>
        /// Reads an ini file and returns the content as an IniStructure. Returns null if an error occurred.
        /// </summary>
        /// <param name="Filename">The filename to read</param>
        /// <returns></returns>
        public static IniStructure ReadIni(string Filename)
        {
            string Data = ReadFile(Filename);

            if (Data == null)
            {
                return(null);
            }

            IniStructure data = InterpretIni(Data);

            return(data);
        }
Exemple #5
0
        public static IniStructure InterpretIni(string Data)
        {
            IniStructure IniData = new IniStructure();

            string[] Lines = RemoveAndVerifyIni(DivideToLines(Data));
            // Divides the Data in lines, removes comments and empty lines
            // and verifies if the ini is not corrupted
            // Returns null if it is.
            if (Lines == null)
            {
                return(null);
            }

            if (IsLineACategoryDef(Lines[0]) != LineType.Category)
            {
                return(null);
                // Ini is faulty - does not begin with a categorydef
            }
            string CurrentCategory = "";

            foreach (string line in Lines)
            {
                switch (IsLineACategoryDef(line))
                {
                case LineType.Category:          // the line is a correct category definition
                    string NewCat = line.Substring(1, line.Length - 2);
                    IniData.AddCategory(NewCat); // adds the category to the IniData
                    CurrentCategory = NewCat;
                    break;

                case LineType.NotACategory:     // the line is not a category definition
                    string[] keyvalue = GetDataFromLine(line);
                    IniData.AddValue(CurrentCategory, keyvalue[0], keyvalue[1]);
                    // Adds the key-value to the current category
                    break;

                case LineType.Faulty:     // the line is faulty
                    return(null);
                }
            }
            return(IniData);
        }
Exemple #6
0
        // add by kuangsihao
        public static IniStructure ReadIniWithContent(string content)
        {
            IniStructure data = InterpretIni(content);

            return(data);
        }
Exemple #7
0
 private static string CreateData(IniStructure IniData)
 {
     return(CreateData(IniData, ""));
 }
Exemple #8
0
        /// <summary>
        /// Writes an IniStructure to a file without a comment.
        /// </summary>
        /// <param name="IniData">The contents to write</param>
        /// <param name="Filename">The complete path and name of the file</param>
        /// <returns></returns>
        public static bool WriteIni(IniStructure IniData, string Filename)
        {
            string DataToWrite = CreateData(IniData);

            return(WriteFile(Filename, DataToWrite));
        }
Exemple #9
0
        /// <summary>
        /// Writes an IniStructure to a file with a comment.
        /// </summary>
        /// <param name="IniData">The contents to write</param>
        /// <param name="Filename">The complete path and name of the file</param>
        /// <param name="comment">Comment to add</param>
        /// <returns></returns>
        public static bool WriteIni(IniStructure IniData, string Filename, string comment)
        {
            string DataToWrite = CreateData(IniData, BuildComment(comment));

            return(WriteFile(Filename, DataToWrite));
        }
Exemple #10
0
        public static IniStructure InterpretIni(string Data)
        {
            IniStructure IniData = new IniStructure();
            string[] Lines = RemoveAndVerifyIni(DivideToLines(Data));
            // Divides the Data in lines, removes comments and empty lines
            // and verifies if the ini is not corrupted
            // Returns null if it is.
            if (Lines == null)
                return null;

            if (IsLineACategoryDef(Lines[0]) != LineType.Category)
            {
                return null;
                // Ini is faulty - does not begin with a categorydef
            }
            string CurrentCategory = "";
            foreach (string line in Lines)
            {
                switch (IsLineACategoryDef(line))
                {
                    case LineType.Category:	// the line is a correct category definition
                        string NewCat = line.Substring(1, line.Length - 2);
                        IniData.AddCategory(NewCat); // adds the category to the IniData
                        CurrentCategory = NewCat;
                        break;
                    case LineType.NotACategory: // the line is not a category definition
                        string[] keyvalue = GetDataFromLine(line);
                        IniData.AddValue(CurrentCategory, keyvalue[0], keyvalue[1]);
                        // Adds the key-value to the current category
                        break;
                    case LineType.Faulty: // the line is faulty
                        return null;
                }
            }
            return IniData;
        }
Exemple #11
0
        private static string CreateData(IniStructure IniData, string comment)
        {	//Iterates through all categories and keys and appends all data to Data
            int CategoryCount = IniData.GetCategories().Length;
            int[] KeyCountPerCategory = new int[CategoryCount];
            string Data = comment;
            string[] temp = new string[2]; // will contain key-value pair

            for (int i = 0; i < CategoryCount; i++) // Gets keycount per category
            {
                string CategoryName = IniData.GetCategories()[i];
                KeyCountPerCategory[i] = IniData.GetKeys(CategoryName).Length;
            }

            for (int catcounter = 0; catcounter < CategoryCount; catcounter++)
            {
                Data += "\r\n[" + IniData.GetCategoryName(catcounter) + "]\r\n";
                // writes [Category] to Data
                for (int keycounter = 0; keycounter < KeyCountPerCategory[catcounter]; keycounter++)
                {
                    temp[0] = IniData.GetKeyName(catcounter, keycounter);
                    temp[1] = IniData.GetValue(catcounter, keycounter);
                    Data += temp[0] + "=" + temp[1] + "\r\n";
                    // writes the key-value pair to Data
                }
            }
            return Data;
        }
Exemple #12
0
 private static string CreateData(IniStructure IniData)
 {
     return CreateData(IniData, "");
 }
Exemple #13
0
 /// <summary>
 /// Writes an IniStructure to a file without a comment.
 /// </summary>
 /// <param name="IniData">The contents to write</param>
 /// <param name="Filename">The complete path and name of the file</param>
 /// <returns></returns>
 public static bool WriteIni(IniStructure IniData, string Filename)
 {
     string DataToWrite = CreateData(IniData);
     return WriteFile(Filename, DataToWrite);
 }
Exemple #14
0
 /// <summary>
 /// Writes an IniStructure to a file with a comment.
 /// </summary>
 /// <param name="IniData">The contents to write</param>
 /// <param name="Filename">The complete path and name of the file</param>
 /// <param name="comment">Comment to add</param>
 /// <returns></returns>
 public static bool WriteIni(IniStructure IniData, string Filename, string comment)
 {
     string DataToWrite = CreateData(IniData, BuildComment(comment));
     return WriteFile(Filename, DataToWrite);
 }