private bool Load_File(string path) { Ini ini = new Ini(path); ClearLoad(); try { Load_file.http.Method = ini.ReadValue("HTTP", "Method"); Load_file.http.URL = ini.ReadValue("HTTP", "URL"); Load_file.http.version = ini.ReadValue("HTTP", "Version"); //Load_file.Config.Used = Convert.ToBoolean(ini.ReadValue("Config", "Used")); //Load_file.Config.proxyip = ini.ReadValue("Config", "Proxy"); //Load_file.Config.Request = Encoding.GetEncoding(ini.ReadValue("Config", "RequestEncoding")); //Load_file.Config.Response = Encoding.GetEncoding(ini.ReadValue("Config", "ResponseEncoding")); //Load_file.Login.Type = ini.ReadValue("Login", "Type"); //Load_file.Login.Used = Convert.ToBoolean(ini.ReadValue("Login", "Used")); //Load_file.Login.Server = Convert.ToInt32(ini.ReadValue("Login", "Server")); //Load_file.Login.Userid = ini.ReadValue("Login", "Userid"); //Load_file.Login.Password = ini.ReadValue("Login", "Password"); key.md5 = ini.ReadValue("KEY", "MD5"); key.AES = ini.ReadValue("KEY", "AES"); key.AuthAES = ini.ReadValue("KEY", "AuthAES"); string[] loadstrings = default_col; Load_file.Param.url_count = Convert.ToInt32(ini.ReadValue("Param_url", "Count")); for (int i = 0; i < Load_file.Param.url_count; i++) { for (int j = 0; j < loadstrings.Length; j++) { Load_file.Param.url[i, j] = ini.ReadValue("Param_url", loadstrings[j] + i.ToString()); } } Load_file.Param.body_count = Convert.ToInt32(ini.ReadValue("Param_body", "Count")); for (int i = 0; i < Load_file.Param.body_count; i++) { for (int j = 0; j < loadstrings.Length; j++) { Load_file.Param.body[i, j] = ini.ReadValue("Param_body", loadstrings[j] + i.ToString()); } } Load_file.Param.header_count = Convert.ToInt32(ini.ReadValue("Param_header", "Count")); for (int i = 0; i < Load_file.Param.header_count; i++) { for (int j = 0; j < loadstrings.Length; j++) { Load_file.Param.header[i, j] = ini.ReadValue("Param_header", loadstrings[j] + i.ToString()); } } //Param_Type = "Param_url"; return true; } catch (Exception e) { MessageBox.Show(path + "\r\n读取失败\r\n" + e.Message + "\r\n" + e.StackTrace); return false; } }
private void Save_File(string path) { Ini ini = new Ini(path); ini.WriteValue("HTTP", "Method", http_Method.SelectedIndex.ToString()); ini.WriteValue("HTTP", "URL", http_url.Text); ini.WriteValue("HTTP", "Version", http_Version.SelectedIndex.ToString()); //ini.WriteValue("Config", "Used", "false"); //ini.WriteValue("Config", "Proxy", Proxyip); //ini.WriteValue("Config", "RequestEncoding", RequestEncoding.ToString()); //ini.WriteValue("Config", "ResponseEncoding", ResponseEncoding.ToString()); //ini.WriteValue("Login", "Type", Login_type); //ini.WriteValue("Login", "Used", tiancity_login.Checked.ToString()); //ini.WriteValue("Login", "Server", tiancity_login_server.SelectedIndex.ToString()); //ini.WriteValue("Login", "Userid", tiancity_userid.Text); //ini.WriteValue("Login", "Password", tiancity_password.Text); ini.WriteValue("KEY", "MD5", key.md5); ini.WriteValue("KEY", "AES", key.AES); ini.WriteValue("KEY", "AuthAES", key.AuthAES); Resquest_data_read(); string[] savestrings = default_col; //data[i, keyx] ini.WriteValue("Param_url", "Count", tab_url_rowcount.ToString()); for (int i = 0; i < tab_url_rowcount; i++) { for (int j = 0; j < savestrings.Length; j++) { ini.WriteValue("Param_url", savestrings[j] + i.ToString(), tab_url_data[i, j]); } } ini.WriteValue("Param_body", "Count", tab_body_rowcount.ToString()); for (int i = 0; i < tab_body_rowcount; i++) { for (int j = 0; j < savestrings.Length; j++) { ini.WriteValue("Param_body", savestrings[j] + i.ToString(), tab_body_data[i, j]); } } ini.WriteValue("Param_header", "Count", tab_header_rowcount.ToString()); for (int i = 0; i < tab_header_rowcount; i++) { for (int j = 0; j < savestrings.Length; j++) { ini.WriteValue("Param_header", savestrings[j] + i.ToString(), tab_header_data[i, j]); } } }
static void Mainini(string[] args) { string Current; Current = Directory.GetCurrentDirectory();//获取当前根目录 Console.WriteLine("Current directory {0}", Current); // 写入ini Ini ini = new Ini(Current + "/config.ini"); ini.WriteValue("Setting", "key1", "hello word!"); ini.WriteValue("Setting", "key2", "hello ini!"); ini.WriteValue("SettingImg", "Path", "IMG.Path"); // 读取ini string stemp = ini.ReadValue("Setting", "key2"); Console.WriteLine(stemp); Console.ReadKey(); }