/// <summary> /// When displaying bible verses (on the live screen), the reference shown comes /// from the bible.BibleBooks[?].Long (or .Short) fields. This code sets those /// fields for all bibles in the library to the names found in the user selected /// Sword locales.d file. /// </summary> /// <param name="Bibles"></param> /// <param name="SwordPath"></param> /// <param name="locale"></param> public static void SetBibleLocale(BibleLib Bibles, string SwordPath, string locale) { string localeDir = Path.Combine(SwordPath, "locales.d"); string longFile = Path.Combine(localeDir, locale + ".conf"); string abbrFile = Path.Combine(localeDir, locale + "_abbr.conf"); IniStructure longNames = IniStructure.ReadIni(longFile); IniStructure abbrNames = IniStructure.ReadIni(abbrFile); if (longNames == null) { return; } foreach (string translation in Bibles.Translations()) { BibleVersion bible = Bibles[translation]; int i = 0; foreach (string book in BibleVersion.SwordBookNames) { string localizedName = longNames.GetValue("Text", book); bible.BibleBooks[i].Long = longNames.GetValue("Text", book); if (abbrNames != null) { bible.BibleBooks[i].Short = abbrNames.GetValue("Text", book); } else { bible.BibleBooks[i].Short = longNames.GetValue("Text", book); } i++; } } }
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); }
// ------------------------------------------------------------------------ // Load application private void frmRFID_Load(object sender, EventArgs e) { // -------------------------------------------------------------------- // Load software parameter ini = IniStructure.ReadIni(System.Windows.Forms.Application.StartupPath + "\\RFID.ini"); if (ini == null) { MessageBox.Show("Configuration is missing or corrupt!" + System.Windows.Forms.Application.StartupPath, "Error"); System.Windows.Forms.Application.Exit(); return; } // Load configuration ResponseTimeout = Convert.ToInt16(ini.GetValue("RFID", "ResponseTimeout")); RefreshTimer = Convert.ToInt16(ini.GetValue("RFID", "RefreshTimer")); txtKeyLength.Text = ini.GetValue("RFID", "KeyMinLength"); chkAutoConnect.Checked = Convert.ToBoolean(ini.GetValue("CHK", "AutoConnect")); chkSendKeys.Checked = Convert.ToBoolean(ini.GetValue("CHK", "SendKeys")); chkSendKeysEnter.Checked = Convert.ToBoolean(ini.GetValue("CHK", "SendKeysEnter")); chkSendBallon.Checked = Convert.ToBoolean(ini.GetValue("CHK", "SendBallon")); if (chkAutoConnect.Checked) { btnConnect_Click(null, null); } }
public KeyboardLayout(string name) { try { if (inis == null) { inis = IniStructure.ReadIni("Layouts\\" + name + ".keylayout"); if (inis == null) { inis = IniStructure.ReadIni(name); } this.name = name; } if (inis.filename != "Layouts\\" + name + ".keylayout" && inis.filename != name) { inis = null; inis = IniStructure.ReadIni("Layouts\\" + name + ".keylayout"); if (inis == null) { inis = IniStructure.ReadIni(name); } this.name = name; } } catch { inis = new IniStructure(); } }
public static string ValidateLayout(string path) { IniStructure ini = IniStructure.ReadIni(path); string s = ini.GetValue("MyInputKeyboardFile", "name"); ini = null; return(s); }
public string show(string oldVarIndex, string mapname, string ClientPath) { this.advTree1.Nodes.Clear(); Node node_map = new Node(); node_map.Text = mapname; node_map.Image = imageList1.Images[0]; advTree1.Nodes.Add(node_map); string iniFileName = Path.Combine(ClientPath, @"data\source\maps\" + mapname + "\\" + mapname + ".Map.Logical"); IniStructure m_inis = new IniStructure(); m_inis = IniStructure.ReadIni(iniFileName); if (m_inis == null) { MessageBox.Show("ÕÒ²»µ½" + iniFileName, "´íÎó", MessageBoxButtons.OK, MessageBoxIcon.Error); return(""); } int nNpcNumber = Convert.ToInt32(m_inis.GetValue("MAIN", "NumNPC").ToString()); for (int i = 0; i < nNpcNumber; i++) { string szName = m_inis.GetValue("NPC" + i.ToString(), "szName"); string szNickName = m_inis.GetValue("NPC" + i.ToString(), "szNickName"); string nTempleteID = m_inis.GetValue("NPC" + i.ToString(), "nTempleteID"); string nX = m_inis.GetValue("NPC" + i.ToString(), "nX"); string nY = m_inis.GetValue("NPC" + i.ToString(), "nY"); string nZ = m_inis.GetValue("NPC" + i.ToString(), "nZ"); if (szNickName != null && szNickName != "") { Node node = new Node(); node.Text = szNickName; node.Image = imageList1.Images[1]; node.Tag = szNickName; node.Cells.Add(new Cell(szName == null ? "" : szName)); node.Cells.Add(new Cell(string.Format("{0},{1},{2}", nX, nY, nZ))); node.Cells.Add(new Cell()); node_map.Nodes.Add(node); if (node.Tag.ToString() == oldVarIndex) { advTree1.SelectedNode = node; } } } if (this.ShowDialog() == DialogResult.OK) { return(m_SelectedKey); } return(oldVarIndex); }
// ------------------------------------------------------------------------ // Close application private void frmRFID_FormClosed(object sender, FormClosedEventArgs e) { if (ini == null) { return; } // Save current options ini.ModifyValue("CHK", "AutoConnect", chkAutoConnect.Checked.ToString()); ini.ModifyValue("CHK", "SendKeys", chkSendKeys.Checked.ToString()); ini.ModifyValue("CHK", "SendBallon", chkSendBallon.Checked.ToString()); IniStructure.WriteIni(ini, System.Windows.Forms.Application.StartupPath + "\\RFID.ini"); }
/// <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); }
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); }
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; }
// add by kuangsihao public static IniStructure ReadIniWithContent(string content) { IniStructure data = InterpretIni(content); return(data); }
private static string CreateData(IniStructure IniData) { return(CreateData(IniData, "")); }
/// <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)); }
/// <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); }
/// <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); }
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; }
private static string CreateData(IniStructure IniData) { return CreateData(IniData, ""); }
/// <summary> /// 挂脚本 /// </summary> /// <param name="constExp">表达式对象</param> /// <returns>是否挂接成功</returns> public bool SetScript(ConstExp constExp) { string FileName = ""; StringBuilder Content = new StringBuilder(); string Sql = ""; Content.AppendLine("--" + constExp.ToString()); Content.AppendLine("Include('scripts/flowlib/api.lua')"); Content.AppendLine("Include('scripts/flowlib/event_dispatch.lua')"); Content.AppendLine("using('EventDispatch')"); switch (constExp.ReturnType.DBID) { case 13: //道具模板 #region 道具生成 //生成文件 FileName = Path.Combine(this.m_rootdir, @"scripts\flowlib\catcher\item\" + constExp.DBValue.Replace(",", "_") + ".lua"); Content.Append(string.Format(@" function OnUse(player, item) local sta, err = pcall(function() EventDispatch.AOnUse('{0}', player, item) end) if err then print('err: ' .. err) end return false, false end ", constExp.DBValue)); //写数据库 if (!constExp.DBValue.Contains(",")) { return(false); } string r1 = constExp.DBValue.Split(new char[] { ',' })[0]; string r2 = constExp.DBValue.Split(new char[] { ',' })[1]; string sql = ""; switch (r1) { case "5": { sql = "Other"; break; } case "6": { sql = "item_Custom_Weapon"; break; } case "7": { sql = "item_Custom_Armor"; break; } case "8": { sql = "Custom_Trinket"; break; } } if (!exportTableList.Contains(sql)) { exportTableList.Add(sql); } sql = string.Format("update [{0}] set scriptname='scripts\\flowlib\\catcher\\item\\{1}.lua' where id='{2}'", sql, constExp.DBValue.Replace(",", "_"), r2); Sql = sql; #endregion break; case 20: //NPC模板 #region NPC模板 //生成文件 FileName = Path.Combine(this.m_rootdir, @"scripts\flowlib\catcher\npc\" + constExp.DBValue + ".lua"); Content.Append(string.Format(@" function OnDialogue(npc, player) local gotevent = false local sta, err = pcall(function() gotevent = EventDispatch.AOnDialogue('{0}', npc, player) end) if err then print('err: ' .. err) end if not gotevent then player.OpenWindow(TARGET.NPC, npc.dwID, npc.GetAutoDialogString(player.dwID) ) end end; function OnDeath(npc, killer) local sta, err = pcall(function() EventDispatch.AOnDeath('{0}', npc) end) --任何情况下的死亡 if err then print('err: ' .. err) end if not killer then sta, err = pcall(function() EventDispatch.AOnNaturalDeath('{0}', npc) end) --自然死亡 if err then print('err: ' .. err) end elseif IsPlayer(killer) then sta, err = pcall(function() EventDispatch.AOnDeathByPlayer('{0}', npc, killer) end) --被player杀死的 if err then print('err: ' .. err) end else sta, err = pcall(function() EventDispatch.AOnDeathByNpc('{0}', npc, killer) end) --被NPC杀死的 if err then print('err: ' .. err) end end end; ", constExp.DBValue)); //写数据库 Sql = string.Format("update NpcTemplate set scriptname='scripts\\flowlib\\catcher\\npc\\{0}.lua' where id='{0}'", constExp.DBValue); //检查实体覆盖模板的问题 string strResult = ""; if (this.m_inis == null) { string mapname = this.m_mapname; string iniFileName = Path.Combine(this.m_rootdir, @"data\source\maps\" + mapname + "\\" + mapname + ".Map.Logical"); if (!File.Exists(iniFileName)) { break; } this.m_inis = new IniStructure(); this.m_inis = IniStructure.ReadIni(iniFileName); } if (m_inis == null) { break; } int nNpcNumber = Convert.ToInt32(m_inis.GetValue("MAIN", "NumNPC").ToString()); for (int i = 0; i < nNpcNumber; i++) { string szName = m_inis.GetValue("NPC" + i.ToString(), "szName"); string dwScriptID = m_inis.GetValue("NPC" + i.ToString(), "dwScriptID"); string nTempleteID = m_inis.GetValue("NPC" + i.ToString(), "nTempleteID"); string nX = m_inis.GetValue("NPC" + i.ToString(), "nX"); string nY = m_inis.GetValue("NPC" + i.ToString(), "nY"); string nZ = m_inis.GetValue("NPC" + i.ToString(), "nZ"); if (nTempleteID == constExp.DBValue && dwScriptID != "00000000") { strResult += string.Format("{4} 的 {0}({1},{2},{3}) 在场景编辑器已经挂接了脚本,自动挂接是通过写模板实现的,所以流程图对于这个实体将无效。", szName, nX, nY, nZ, this.m_mapname) + "\r\n"; } } if (strResult != "") { MessageBox.Show(strResult, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (!exportTableList.Contains("NpcTemplate")) { exportTableList.Add("NpcTemplate"); } #endregion break; case 21: //任务模板 #region 任务模板 //生成文件 FileName = Path.Combine(this.m_rootdir, @"scripts\flowlib\catcher\quest\" + constExp.DBValue + ".lua"); Content.Append(string.Format(@" function OnAcceptQuest(player) local sta, err = pcall(function() EventDispatch.AOnAcceptQuest('{0}', player, '{0}') end) if err then print('err: ' .. err) end end; function OnFinishQuest(player) local sta, err = pcall(function() EventDispatch.AOnFinishQuest('{0}', player, '{0}') end) if err then print('err: ' .. err) end end; function OnCancelQuest(player) local sta, err = pcall(function() EventDispatch.AOnCancelQuest('{0}', player, '{0}') end) if err then print('err: ' .. err) end end; ", constExp.DBValue)); //写数据库 Sql = string.Format("update tbl_quests set scriptname='scripts\\flowlib\\catcher\\quest\\{0}.lua' where questid='{0}'", constExp.DBValue); if (!exportTableList.Contains("tbl_quests")) { exportTableList.Add("tbl_quests"); } #endregion break; case 35: //Doodad模板 #region Doodad模板 //生成文件 FileName = Path.Combine(this.m_rootdir, @"scripts\flowlib\catcher\doodad\" + constExp.DBValue + ".lua"); Content.Append(string.Format(@" function OnOpen(doodad, player) local gotevent = false local sta, err = pcall(function() gotevent = EventDispatch.AOnOpen('{0}', doodad, player) end) if err then print('err: ' .. err) end if not gotevent then --做默认的事情 end return false end; function OnBreak(doodad, player) local gotevent = false local sta, err = pcall(function() gotevent = EventDispatch.AOnBreak('{0}', doodad, player) end) if err then print('err: ' .. err) end end; function OnPick(doodad, player) local gotevent = false local sta, err = pcall(function() gotevent = EventDispatch.AOnPick('{0}', doodad, player) end) if err then print('err: ' .. err) end end; ", constExp.DBValue)); //写数据库 Sql = string.Format("update tbl_doodad set script='scripts\\flowlib\\catcher\\doodad\\{0}.lua' where id='{0}'", constExp.DBValue); //实体覆盖模板 strResult = ""; if (this.m_inis == null) { string mapname = this.m_mapname; string iniFileName = Path.Combine(this.m_rootdir, @"data\source\maps\" + mapname + "\\" + mapname + ".Map.Logical"); if (!File.Exists(iniFileName)) { break; } this.m_inis = new IniStructure(); this.m_inis = IniStructure.ReadIni(iniFileName); } if (m_inis == null) { break; } nNpcNumber = Convert.ToInt32(m_inis.GetValue("MAIN", "NumDoodad").ToString()); for (int i = 0; i < nNpcNumber; i++) { string szName = m_inis.GetValue("Doodad" + i.ToString(), "szName"); string dwScriptID = m_inis.GetValue("Doodad" + i.ToString(), "dwScriptID"); string nTempleteID = m_inis.GetValue("Doodad" + i.ToString(), "nTempleteID"); string nX = m_inis.GetValue("Doodad" + i.ToString(), "nX"); string nY = m_inis.GetValue("Doodad" + i.ToString(), "nY"); string nZ = m_inis.GetValue("Doodad" + i.ToString(), "nZ"); if (nTempleteID == constExp.DBValue && dwScriptID != "00000000") { strResult += string.Format("{4} 的 {0}({1},{2},{3}) 在场景编辑器已经挂接了脚本,自动挂接是通过写模板实现的,所以流程图对于这个实体将无效。", szName, nX, nY, nZ, this.m_mapname) + "\r\n"; } } if (strResult != "") { MessageBox.Show(strResult, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (!exportTableList.Contains("tbl_doodad")) { exportTableList.Add("tbl_doodad"); } #endregion break; case 36: //Trap模板 #region Trap模板 string[] list = constExp.DBValue.Split(new char[] { ',' }); //生成文件 FileName = Path.Combine(this.m_rootdir, @"scripts\flowlib\catcher\trap\" + list[0] + ".map." + list[1] + ".lua"); Content.Append(string.Format(@" function OnEnterTrap(player, cell) local sta, err = pcall(function() EventDispatch.AOnEnterTrap('{0}', player, cell, '{0}') end) if err then print('err: ' .. err) end end; function OnLeaveTrap(player, oldCell) local sta, err = pcall(function() EventDispatch.AOnLeaveTrap('{0}', player, oldCell, '{0}') end) if err then print('err: ' .. err) end end; ", constExp.DBValue)); #endregion break; case 39: //地图模板 SetSceneScript(); return(true); default: throw new Exception("目前不支持[" + constExp.ToString() + "]类型的捕获器挂接"); } if (saveFile != null) { saveFile(FileName, Content.ToString()); //导出lua文件 } /* * if (executeSQLCommand != null && Sql != "") * { * executeSQLCommand(Sql); * } */ return(true); }
/// <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)); }