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); }
/// <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; }
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> /// 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); }
private static bool InitSettings() { m_strrootdir = string.Empty; m_strconnstr = string.Empty; m_strEngineDir = string.Empty; StringBuilder sb = new StringBuilder(255); bool bRet = false; while (m_strrootdir.Length <= 0) { FileFolderHelper.ReadIniFile("General", "RootDir", "", sb, 255, Application.StartupPath + "/GameDesingerTools.ini"); m_strrootdir = sb.ToString(); m_strrootdir = m_strrootdir.Trim(); if (m_strrootdir.Length <= 0) { MessageBox.Show("设置文件根目录不能为空,请设置您的本地设置文件存在的根目录。如:E:\\work\\Sword3\\sword3DesignBase\\commit_swap)", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); AppOptionsForm fm = null; fm = new AppOptionsForm(); if (fm.ShowDialog() == DialogResult.OK) { fm.Update(); } else { break; } } bRet = true; } if (EnableRemoting) { while (Database == string.Empty) { FileFolderHelper.ReadIniFile("Remote", "DataBase", "", sb, 255, Application.StartupPath + "/GameDesingerTools_remote.ini"); Database = sb.ToString().Trim(); if (Database == string.Empty && Database.Length == 0) { AppOptionsForm frm = new AppOptionsForm(); if (frm.ShowDialog() == DialogResult.OK) { Database = frm.DataBase; frm.Update(); break; } else { bRet = false; MessageBox.Show("连接数据库名不能为空,请设置数据库。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } bRet = true; } m_strconnstr = Database; while (m_strconnstr.Length <= 0 && bRet) { // // crypt // string myString = @"[General] // ConnString=Server = jx3web; DataBase = s3design_debug; Uid = s3design; Password = davidbowie; // "; // // Misc.SymmetricMethod _sm = new Misc.SymmetricMethod(); // string c = _sm.Encrypto(myString); // c = _sm.Decrypto(c); bRet = false; if (!System.IO.File.Exists(Application.StartupPath + "\\GameDesingerTools_Public.ini")) { MessageBox.Show("GameDesingerTools_Public.ini 不存在,程序不能启动!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } string filename = Application.StartupPath + "/GameDesingerTools_Public.ini"; string content = FileFolderHelper.FileToString(filename); Misc.SymmetricMethod sm = new Misc.SymmetricMethod(); content = sm.Decrypto(content); Misc.IniStructure m_inis = new Misc.IniStructure(); m_inis = Misc.IniStructure.ReadIniWithContent(content); m_strconnstr = m_inis.GetValue("General", "ConnString"); if (m_bLoadBackupDB) // 强制读取策划备份库的信息 { m_strconnstr = "Server = jx3web; DataBase = s3design-1-0-8-1380-new; Uid = s3design; Password = davidbowie;"; } if (m_bSkillBranch) // 技能系统组分支2009-5-11 { m_strconnstr = "Server = jx3web; DataBase = s3design_skill_branch; Uid = s3design; Password = davidbowie;"; } if (m_strconnstr.Length <= 0) { MessageBox.Show("连接字符串不能为空,请设置数据库连接。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); AppOptionsForm fm = null; fm = new AppOptionsForm(); if (fm.ShowDialog() == DialogResult.OK) { fm.Update(); } else { break; } } bRet = true; } while (m_strEngineDir.Length <= 0 && bRet) { bRet = false; FileFolderHelper.ReadIniFile("General", "3DEnginePath", "", sb, 255, Application.StartupPath + "/GameDesingerTools.ini"); m_strEngineDir = sb.ToString(); m_strEngineDir = m_strEngineDir.Trim(); if (m_strEngineDir.Length <= 0) { MessageBox.Show("3DEngine 路径设置不能为空,请设置 KG3DEngine.DLL 所在的路径", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); AppOptionsForm fm = null; fm = new AppOptionsForm(); if (fm.ShowDialog() == DialogResult.OK) { fm.Update(); } else { break; } } bRet = true; } if (bRet) { MainForm.InitConn(); m_rightmgr.Init(); } // 读3d时钟参数 FileFolderHelper.ReadIniFile("Advance", "tmrRenderInterval", "50", sb, 255, Application.StartupPath + "/GameDesingerTools.ini"); int iInterval = 50; if (int.TryParse(sb.ToString(), out iInterval)) { Program.m_3d_tmrRender = iInterval; } return(bRet); }
// 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)); }
private static bool InitSettings() { m_strrootdir = string.Empty; m_strconnstr = string.Empty; m_strEngineDir = string.Empty; StringBuilder sb = new StringBuilder(255); bool bRet = false; while (m_strrootdir.Length <= 0) { FileFolderHelper.ReadIniFile("General", "RootDir", "", sb, 255, Application.StartupPath + "/GameDesingerTools.ini"); m_strrootdir = sb.ToString(); m_strrootdir = m_strrootdir.Trim(); if (m_strrootdir.Length <= 0) { MessageBox.Show("设置文件根目录不能为空,请设置您的本地设置文件存在的根目录。如:E:\\work\\Sword3\\sword3DesignBase\\commit_swap)", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); AppOptionsForm fm = null; fm = new AppOptionsForm(); if (fm.ShowDialog() == DialogResult.OK) fm.Update(); else break; } bRet = true; } if (EnableRemoting) { while (Database == string.Empty) { FileFolderHelper.ReadIniFile("Remote", "DataBase", "", sb, 255, Application.StartupPath + "/GameDesingerTools_remote.ini"); Database = sb.ToString().Trim(); if (Database == string.Empty && Database.Length == 0) { AppOptionsForm frm = new AppOptionsForm(); if (frm.ShowDialog() == DialogResult.OK) { Database = frm.DataBase; frm.Update(); break; } else { bRet = false; MessageBox.Show("连接数据库名不能为空,请设置数据库。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } bRet = true; } m_strconnstr = Database; while (m_strconnstr.Length <= 0 && bRet) { // // crypt // string myString = @"[General] // ConnString=Server = jx3web; DataBase = s3design_debug; Uid = s3design; Password = davidbowie; // "; // // Misc.SymmetricMethod _sm = new Misc.SymmetricMethod(); // string c = _sm.Encrypto(myString); // c = _sm.Decrypto(c); bRet = false; if (!System.IO.File.Exists(Application.StartupPath + "\\GameDesingerTools_Public.ini")) { MessageBox.Show("GameDesingerTools_Public.ini 不存在,程序不能启动!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } string filename = Application.StartupPath + "/GameDesingerTools_Public.ini"; string content = FileFolderHelper.FileToString(filename); Misc.SymmetricMethod sm = new Misc.SymmetricMethod(); content = sm.Decrypto(content); Misc.IniStructure m_inis = new Misc.IniStructure(); m_inis = Misc.IniStructure.ReadIniWithContent(content); m_strconnstr = m_inis.GetValue("General", "ConnString"); if (m_bLoadBackupDB) // 强制读取策划备份库的信息 { m_strconnstr = "Server = jx3web; DataBase = s3design-1-0-8-1380-new; Uid = s3design; Password = davidbowie;"; } if (m_bSkillBranch) // 技能系统组分支2009-5-11 { m_strconnstr = "Server = jx3web; DataBase = s3design_skill_branch; Uid = s3design; Password = davidbowie;"; } if (m_strconnstr.Length <= 0) { MessageBox.Show("连接字符串不能为空,请设置数据库连接。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); AppOptionsForm fm = null; fm = new AppOptionsForm(); if (fm.ShowDialog() == DialogResult.OK) fm.Update(); else break; } bRet = true; } while (m_strEngineDir.Length <= 0 && bRet) { bRet = false; FileFolderHelper.ReadIniFile("General", "3DEnginePath", "", sb, 255, Application.StartupPath + "/GameDesingerTools.ini"); m_strEngineDir = sb.ToString(); m_strEngineDir = m_strEngineDir.Trim(); if (m_strEngineDir.Length <= 0) { MessageBox.Show("3DEngine 路径设置不能为空,请设置 KG3DEngine.DLL 所在的路径", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); AppOptionsForm fm = null; fm = new AppOptionsForm(); if (fm.ShowDialog() == DialogResult.OK) fm.Update(); else break; } bRet = true; } if (bRet) { MainForm.InitConn(); m_rightmgr.Init(); } // 读3d时钟参数 FileFolderHelper.ReadIniFile("Advance", "tmrRenderInterval", "50", sb, 255, Application.StartupPath + "/GameDesingerTools.ini"); int iInterval = 50; if (int.TryParse(sb.ToString(), out iInterval)) Program.m_3d_tmrRender = iInterval; return bRet; }