Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        private void Init()
        {
            tree = treePh;
            this.m_lua["this"] = this;
            tabStrip1.MdiForm = this;            

            // 读取策划工具的配置信息
            Helper.ClientPath = IniIO.IniReadValue("General", "RootDir", "./GameDesingerTools.ini");
            string filename = Application.StartupPath + "/GameDesingerTools_Public.ini";
            string content = FileFolderHelper.FileToString(filename);
            SymmetricMethod sm = new SymmetricMethod();
            content = sm.Decrypto(content);
            IniStructure m_inis = new IniStructure();
            m_inis = IniStructure.ReadIniWithContent(content);
            Helper.ConnectionString = m_inis.GetValue("General", "ConnString");

            string configFileName = Path.Combine(Application.StartupPath, "LuaEditor.ini");

            // 读取本机配置信息
            if (File.Exists(configFileName))
            {
                string serverPath = IniIO.IniReadValue("General", "ServerFolder", configFileName);

                if (!string.IsNullOrEmpty(serverPath))
                {
                    Helper.ServerPath = serverPath;
                }

                /* 调试相关的参数暂时不允许自定义
                string receiveMessageDelay = IniIO.IniReadValue("General", "ReceiveMessageDelay", configFileName);
                
                if (!string.IsNullOrEmpty(receiveMessageDelay))
                {
                    Helper.ReceiveMessageDelay = int.Parse(receiveMessageDelay);
                }

                string receiveMessageRetryTime = IniIO.IniReadValue("General", "ReceiveMessageRetryTime", configFileName);

                if (!string.IsNullOrEmpty(receiveMessageRetryTime))
                {
                    Helper.ReceiveMessageRetryTime = int.Parse(receiveMessageRetryTime);
                }

                string breakPointWaitCircle = IniIO.IniReadValue("General", "BreakPointWaitCircle", configFileName);

                if (!string.IsNullOrEmpty(breakPointWaitCircle))
                {
                    Helper.BreakPointWaitCircle = int.Parse(breakPointWaitCircle);
                }
                */ 

                string serverIP = IniIO.IniReadValue("General", "ServerIP", configFileName);

                if (!string.IsNullOrEmpty(serverIP))
                {
                    Helper.ServerIP = serverIP;
                }

                string fontName = IniIO.IniReadValue("General", "ScriptFontName", configFileName);
                string fontSize = IniIO.IniReadValue("General", "ScriptFontSize", configFileName);

                if (!string.IsNullOrEmpty(fontName) && !string.IsNullOrEmpty(fontSize))
                {
                    Helper.ScriptFont = new Font(fontName, float.Parse(fontSize), FontStyle.Regular);
                }

                string fontColor = IniIO.IniReadValue("General", "ScriptForeColor", configFileName);

                if (!string.IsNullOrEmpty(fontColor))
                {
                    Helper.ScriptForeColor = Color.FromName(fontColor);
                }                
            }

            // 读取_setting.cfg
            string strCfgFile = System.IO.Directory.GetCurrentDirectory().TrimEnd(new char[] { '\\' });
            strCfgFile += @"\Plugins\LuaCheck\_setting.cfg";
            Helper.GameLuaEditorSetting = Helper.FileToString(strCfgFile);

            // 如果setting读不到,就取默认setting
            if (Helper.GameLuaEditorSetting == "")
            {
                string strFolder = System.IO.Directory.GetCurrentDirectory().TrimEnd(new char[] { '\\' });
                string strCfg = Helper.FileToString(strFolder + @"\Plugins\LuaCheck\setting.cfg");
                // strCfg = "哈哈,int,123,|是否允许开启,list,false;true,|";
                string[] as_item = strCfg.Split(new string[] { ",", "|" }, StringSplitOptions.None);
                string strUserCfg = "";
                for (int i = 0; i < as_item.Length - 1; i += 4)
                {
                    strUserCfg += as_item[i + 2].Split(new char[] { ';' })[0] + ",";
                }
                Helper.GameLuaEditorSetting = strUserCfg.TrimEnd(new char[]{','});
            }

            // 注册debug相关的按钮
            debugButtonList.Add(bStepInto);
            debugButtonList.Add(bContinueDebug);
            debugButtonList.Add(bRefreshVar);
            debugButtonList.Add(bStepOver);

            // 清理锁
            DataBaseManager dbm = DataBaseManager.GetDataBaseManager();
            dbm.Init(Helper.ConnectionString);
            dbm.ClearRecordLocks();
            Conn = dbm.conn;

            bar4.Items[1].Text = dbm.GetDataBaseName();
            bar4.Items[2].Text = dbm.GetHostName();

            // 生成数据库脚本树
            LoadDataBaseScriptTree();

            // 生成本地脚本树
            LoadLocalScriptTree();

            this.m_lua.RegisterFunction("GetDataTableRow", this, typeof(MainForm).GetMethod("GetDataTableRow"));
            CurrentMainForm = this;

            // 初始化调试计时器
            debugWaitTimer.Tick += new EventHandler(OnTimerExpired);
        }
Exemplo n.º 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;
		}
Exemplo n.º 6
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;
		}
Exemplo n.º 7
0
		private static string CreateData(IniStructure IniData)
		{
			return CreateData(IniData,"");
		}
Exemplo n.º 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);
		}
Exemplo n.º 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);
		}
Exemplo n.º 10
0
        // add by kuangsihao
        public static IniStructure ReadIniWithContent(string content)
        {
            IniStructure data = InterpretIni(content);

            return(data);
        }
Exemplo n.º 11
0
 private static string CreateData(IniStructure IniData)
 {
     return(CreateData(IniData, ""));
 }
Exemplo n.º 12
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));
        }
Exemplo n.º 13
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));
        }