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> /// 初始化数据 /// </summary> private void Init() { try { // 初始化sql连接 string fileName = Path.Combine(Application.StartupPath, "AutoExport.ini"); string content = FileFolderHelper.FileToString(fileName); IniStructure m_inis = new IniStructure(); m_inis = IniStructure.ReadIniWithContent(content); string connectString = m_inis.GetValue("General", "ConnString"); conn = new SqlConnection(connectString); // 读取根目录路径 rootPath = m_inis.GetValue("General", "RootDir"); // 读取导出表列表 string[] autoTableArray = m_inis.GetKeys("AutoExport"); autoTableList.AddRange(autoTableArray); string[] customTableArray = m_inis.GetKeys("CustomExport"); customTableList.AddRange(customTableArray); // 读取资源文件列表 string[] fileArray = m_inis.GetKeys("Resource"); fileList.AddRange(fileArray); // 读取自动导出表的配置信息 string sqlString = string.Format("SELECT * FROM sys_export_table_cfg"); configTable = GetDataTable(sqlString); // 更新资源文件 DownLoadResource(); // 初始化lua虚拟机 exportLua = new Lua(); exportLua["Conn"] = conn; exportLua["RootDir"] = rootPath; string luaFile = Path.Combine(Application.StartupPath, "export.lua"); exportLua.DoFile(luaFile); postExportLua = new Lua(); postExportLua["Conn"] = conn; postExportLua["RootDir"] = rootPath; postExportLua["___GIsServer"] = true; luaFile = Path.Combine(Application.StartupPath, "post_export.lua"); postExportLua.DoFile(luaFile); } catch (Exception ex) { logText.Append(string.Format("{0} —— 产生异常:{1}\r\n", DateTime.Now, ex.Message)); } }
/// <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); }
/// <summary> /// 初始化数据 /// </summary> private bool Init() { try { outputDebugString(string.Format("{0} —— 开始Init初始化...", DateTime.Now)); outputDebugString(string.Format("{0} —— 正在初始化sql连接...", DateTime.Now)); // 初始化sql连接 string fileName = Path.Combine(Application.StartupPath, "AutoExport.ini"); string content = FileFolderHelper.FileToString(fileName); IniStructure m_inis = new IniStructure(); m_inis = IniStructure.ReadIniWithContent(content); string connectString = m_inis.GetValue("General", "ConnString"); conn = new SqlConnection(connectString); // 读取根目录路径 outputDebugString(string.Format("{0} —— 正在初始化外部设置...", DateTime.Now)); rootPath = m_inis.GetValue("General", "RootDir"); // 读取导出表列表 string[] autoTableArray = m_inis.GetKeys("AutoExport"); autoTableList.AddRange(autoTableArray); string[] customTableArray = m_inis.GetKeys("CustomExport"); customTableList.AddRange(customTableArray); outputDebugString(string.Format("{0} —— 正在更新资源文件...", DateTime.Now)); // 读取资源文件列表 string[] fileArray = m_inis.GetKeys("Resource"); fileList.AddRange(fileArray); // 读取自动导出表的配置信息 string sqlString = string.Format("SELECT * FROM sys_export_table_cfg"); configTable = GetDataTable(sqlString); // 更新资源文件 if (Program.GSTEP != 2) DownLoadResource(); outputDebugString(string.Format("{0} —— 正在设置path...", DateTime.Now)); // path更新 EV ev = new EV(); ev.evPath(Path.GetDirectoryName(Application.ExecutablePath)); outputDebugString(string.Format("{0} —— 正在初始化lua虚拟机...", DateTime.Now)); // 初始化lua虚拟机 exportLua = new Lua(); exportLua["Conn"] = conn; exportLua["RootDir"] = rootPath; string luaFile = Path.Combine(Application.StartupPath, "export.lua"); exportLua.DoFile(luaFile); postExportLua = new Lua(); postExportLua["___GIsServer"] = true; postExportLua["RootDir"] = rootPath; postExportLua["Conn"] = conn; postExportLua.RegisterFunction("GetDataTableRow", this, typeof(ExportManager).GetMethod("GetDataTableRow")); luaFile = Path.Combine(Application.StartupPath, "post_export.lua"); postExportLua.DoFile(luaFile); outputDebugString(string.Format("{0} —— 完成所有初始化工作!", DateTime.Now)); return true; } catch (Exception ex) { outputDebugStringError(string.Format("{0} —— 初始化init产生异常:{1}", DateTime.Now, ex.Message)); return false; } }
// 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> /// 初始化数据 /// </summary> private bool Init() { try { outputDebugString(string.Format("{0} —— 开始Init初始化...", DateTime.Now)); outputDebugString(string.Format("{0} —— 正在初始化sql连接...", DateTime.Now)); // 初始化sql连接 string fileName = Path.Combine(Application.StartupPath, "AutoExport.ini"); string content = FileFolderHelper.FileToString(fileName); IniStructure m_inis = new IniStructure(); m_inis = IniStructure.ReadIniWithContent(content); string connectString = m_inis.GetValue("General", "ConnString"); conn = new SqlConnection(connectString); // 读取根目录路径 outputDebugString(string.Format("{0} —— 正在初始化外部设置...", DateTime.Now)); rootPath = m_inis.GetValue("General", "RootDir"); // 读取导出表列表 string[] autoTableArray = m_inis.GetKeys("AutoExport"); autoTableList.AddRange(autoTableArray); string[] customTableArray = m_inis.GetKeys("CustomExport"); customTableList.AddRange(customTableArray); outputDebugString(string.Format("{0} —— 正在更新资源文件...", DateTime.Now)); // 读取资源文件列表 string[] fileArray = m_inis.GetKeys("Resource"); fileList.AddRange(fileArray); // 读取自动导出表的配置信息 string sqlString = string.Format("SELECT * FROM sys_export_table_cfg"); configTable = GetDataTable(sqlString); // 更新资源文件 if (Program.GSTEP != 2) { DownLoadResource(); } outputDebugString(string.Format("{0} —— 正在设置path...", DateTime.Now)); // path更新 EV ev = new EV(); ev.evPath(Path.GetDirectoryName(Application.ExecutablePath)); outputDebugString(string.Format("{0} —— 正在初始化lua虚拟机...", DateTime.Now)); // 初始化lua虚拟机 exportLua = new Lua(); exportLua["Conn"] = conn; exportLua["RootDir"] = rootPath; string luaFile = Path.Combine(Application.StartupPath, "export.lua"); exportLua.DoFile(luaFile); postExportLua = new Lua(); postExportLua["___GIsServer"] = true; postExportLua["RootDir"] = rootPath; postExportLua["Conn"] = conn; postExportLua.RegisterFunction("GetDataTableRow", this, typeof(ExportManager).GetMethod("GetDataTableRow")); luaFile = Path.Combine(Application.StartupPath, "post_export.lua"); postExportLua.DoFile(luaFile); outputDebugString(string.Format("{0} —— 完成所有初始化工作!", DateTime.Now)); return(true); } catch (Exception ex) { outputDebugStringError(string.Format("{0} —— 初始化init产生异常:{1}", DateTime.Now, ex.Message)); return(false); } }