public void IniItemParentsTest() { var file = new IniFile(); var section = new IniSection(file, "Section"); var key = new IniKey(file, "Key"); Assert.AreSame(file, section.ParentFile); Assert.AreSame(file, key.ParentFile); Assert.IsNull(section.ParentCollection); Assert.IsNull(key.ParentCollection); Assert.IsNull(key.ParentSection); section.Keys.Add(key); Assert.AreSame(section.Keys, key.ParentCollection); Assert.AreSame(section, key.ParentSection); file.Sections.Add(section); Assert.AreSame(file.Sections, section.ParentCollection); file.Sections.Remove(section); Assert.IsNull(section.ParentCollection); section.Keys.Remove(key); Assert.IsNull(key.ParentCollection); Assert.IsNull(key.ParentSection); }
public Form1() { InitializeComponent(); progressBar1.Value = 0; button2.Enabled = false; // Load config.ini if (!File.Exists(@"config.ini")) { ini_file = new IniFile(); IniSection section = ini_file.Sections.Add("Configuration"); IniKey key = section.Keys.Add("IP", "192.168.1."); IniKey keyport = section.Keys.Add("Port", "1337"); ini_file.Save("config.ini"); } else { ini_file = new IniFile(); ini_file.Load(@"config.ini"); } ipBox.Text = ini_file.Sections["Configuration"].Keys["IP"].Value; portBox.Text = ini_file.Sections["Configuration"].Keys["Port"].Value; }
public void SetKeyValue(string sectionName, string keyName, string value) { // Get / create section IniSection section = this[sectionName]; if (section == null) { section = new IniSection(sectionName); this.Sections.Add(section); } // Get / create Key IniKey key = section[keyName]; if (key == null) { key = new IniKey(); key.Name = keyName; section.Keys.Add(key); key.OnChange += new EventHandler(this._sections_OnChange); } // Set new Value key.Value = value; this.SetChanged(); }
/// <summary> /// Sets the key name /// </summary> /// <param name="key"></param> /// <returns>Returns true on success, fails if the section name key already exists</returns> public bool SetName(string key) { key = key.Trim(); if (key.Length == 0) { return(false); } IniKey k = _section.GetKey(key); if (k != this && k != null) { return(false); } try { // Remove the current key _section._keys.Remove(Name); // Set the new key name to this object _section._keys[key] = this; // Set the new key name Name = key; return(true); } catch (Exception ex) { Trace.WriteLine(ex.Message); return(false); } }
/// <summary> /// Sets the key name Returns true on success, fails if the /// section name sKey already exists /// </summary> /// <param name="sKey">The s key.</param> /// <returns></returns> public bool SetName(string sKey) { sKey = sKey.Trim(); if (sKey.Length != 0) { IniKey k = m_section.GetKey(sKey); if (!ReferenceEquals(k, this) && k != null) { return(false); } try { // Remove the current key m_section.m_keys.Remove(m_sKey); // Set the new key name to this object m_section.m_keys[sKey] = this; // Set the new key name m_sKey = sKey; return(true); } catch (Exception ex) { Logger.Error <IniSection>(ex.Message); } } return(false); }
// Sets the key name // Returns true on success, fails if the section name sKey already exists public bool SetName(string sKey) { sKey = sKey.Trim(); if (sKey.Length != 0) { IniKey k = m_section.GetKey(sKey); if (k != this && k != null) { return(false); } try { // Remove the current key m_section.m_keys.Remove(m_sKey); // Set the new key name to this object m_section.m_keys[sKey] = this; if (sKey != m_sKey) { m_section.m_pIniFile.changed = true; } // Set the new key name m_sKey = sKey; return(true); } catch (Exception ex) { Trace.WriteLine(ex.Message); } } return(false); }
public void DeleteKey(IniSection section, IniKey key) { lock (_obj) { WritePrivateProfileString(section.ToString(), key.ToString(), null, FilePath); } }
public void Start() { try { IniKey enabled = Preferences["Config"]["Enabled"]; IniKey global = Preferences["Config"]["GlobalEffect"]; if (enabled.Value == "true") { if (global.Value == "true") { StartCoroutine(LoopGlobal()); } else { StartCoroutine(Loop()); } Console.WriteLine("[Moodscape] Loaded correctly!"); } } catch (Exception e) { Console.WriteLine("[Moodscape] There was an error during the configuration loading, disabling the plugin. Error details: " + e.ToString()); } }
private static bool CreateIni() { int Indentation = 4; // Create new file with a default formatting. IniFile file = new IniFile(iniOptions()); // Add new section. IniSection Settings = file.Sections.Add("Settings"); // Add trailing comment. Settings.TrailingComment.Text = "Convars"; // Add new key and its value. IniKey root = Settings.Keys.Add("Root", "./www"); //Add leading comment. root.TrailingComment.Text = "Which port will the server use"; root.LeftIndentation = Indentation; IniKey port = Settings.Keys.Add("Port", "8080"); port.TrailingComment.Text = "Which port will the server use"; port.LeftIndentation = Indentation; IniKey listDirectories = Settings.Keys.Add("ListDirectories", "true"); listDirectories.TrailingComment.Text = "Defines if the directories without files will show it's content"; listDirectories.LeftIndentation = Indentation; IniKey localhostOnly = Settings.Keys.Add("LocalhostOnly", "true"); localhostOnly.TrailingComment.Text = "If true, server will be reachable from localhost only"; localhostOnly.LeftIndentation = Indentation; IniKey logToConsole = Settings.Keys.Add("LogToConsole", "true"); logToConsole.TrailingComment.Text = "If true, server will print activity in the console"; logToConsole.LeftIndentation = Indentation; IniSection Debug = file.Sections.Add("Debug"); Debug.TrailingComment.Text = "Debug Info"; IniKey debugToConsole = Debug.Keys.Add("DebugToConsole", "true"); debugToConsole.TrailingComment.Text = "If true, server will print debuggin info in the console"; debugToConsole.LeftIndentation = Indentation; // Save file. try { file.Save(iniPath); } catch (System.IO.IOException e) { Console.WriteLine(e.Message); } return(true); }
private static void Create() { // Create new file with a default formatting. IniFile file = new IniFile(new IniOptions()); // Add new content. IniSection section = new IniSection(file, IniSection.GlobalSectionName); IniKey key = new IniKey(file, "Key 1", "Value 1"); file.Sections.Add(section); section.Keys.Add(key); // Add new content. file.Sections.Add("Section 2").Keys.Add("Key 2", "Value 2"); // Add new content. file.Sections.Add( new IniSection(file, "Section 3", new IniKey(file, "Key 3.1", "Value 3.1"), new IniKey(file, "Key 3.2", "Value 3.2"))); // Add new content. file.Sections.Add( new IniSection(file, "Section 4", new Dictionary <string, string>() { { "Key 4.1", "Value 4.1" }, { "Key 4.2", "Value 4.2" } })); }
public void SetKeyValue(string sectionName, string keyName, int lineIndex, string value) { // Get / create section IniSection section = this[sectionName]; if (section == null) { section = new IniSection(sectionName); this.Sections.Add(section); } // Get / create Key IniKey key = section[keyName]; if (key == null) { key = new IniKey(); key.Name = keyName; key.OnChange += new EventHandler(this._sections_OnChange); section.Keys.Add(key); } // Calculate new values array int arrayDim = lineIndex + 1; if (key.Multiline) { arrayDim = Math.Max(arrayDim, key.Values.Length); } else { if (arrayDim < 1) { arrayDim = 1; } } string[] array = new string[arrayDim]; // Copy old values if (key.Multiline) { for (int i = 0; i < key.Values.Length; i++) { array[i] = key.Values[i]; } } else { array[0] = key.Value; } // insert new value array[lineIndex] = value; // Keep new values array in Key key.Values = array; this.SetChanged(); }
private void LoadConfig() { try { IniKey key = Preferences["Config"]["ToggleKey"]; IniKey webmode = Preferences["Config"]["WebcamMode"]; IniKey weburl = Preferences["Config"]["WebcamURL"]; IniKey id = Preferences["Config"]["WebcamID"]; IniKey sizex = Preferences["Config"]["WebcamSizeX"]; IniKey sizey = Preferences["Config"]["WebcamSizeY"]; IniKey offsetx = Preferences["Config"]["WebcamOffsetX"]; IniKey offsety = Preferences["Config"]["WebcamOffsetY"]; camsizex = float.Parse(sizex.Value); camsizey = float.Parse(sizey.Value); camoffsetx = float.Parse(offsetx.Value); camoffsety = float.Parse(offsety.Value); WebcamMode = int.Parse(webmode.Value); webcamURL = weburl.Value; togglekey = (KeyCode)Enum.Parse(typeof(KeyCode), key.Value, true); webcamid = int.Parse(id.Value); Console.WriteLine("[VyperCam] Configuration loaded correctly!"); } catch (Exception e) { Console.WriteLine("[VyperCam] There was an error during the configuration loading, default configuration loaded. Error details: " + e.ToString()); } }
internal void Initialize(string placeholderName, IniKey placeholderKey, string value, bool isValueFound) { this.placeholderName = placeholderName; this.placeholderKey = placeholderKey; this.Value = value; this.isValueFound = isValueFound; }
/// <summary> /// Delete a pair of key and value from an .ini file. /// </summary> /// <returns>Returns true if the operation was successful.</returns> public static bool DeleteKey(string filePath, IniKey iniKey) { // Make sure to use full path to avoid disrupting Windows directory. string fullPath = Path.GetFullPath(filePath); return(NativeMethods.WritePrivateProfileStringW(iniKey.Section, iniKey.Key, null, fullPath)); }
public void Write(IniSection section, IniKey key, string value) { lock (_obj) { WritePrivateProfileString(section.ToString(), key.ToString(), value, FilePath); } }
static void Main(string[] args) { // Create new file with a default formatting. IniFile file = new IniFile(); // Add new section. IniSection section = file.Sections.Add("Section name"); // Add trailing comment. section.TrailingComment.Text = "Section trailing comment"; // Add new key and its value. IniKey key = section.Keys.Add("Key name", "Key value "); // Add leading comment. key.LeadingComment.Text = "Key leading comment"; // Save file. file.Save("Sample.ini"); Proxy proxy = new Proxy(@"C:\Users\guogu\Desktop\1.txt", true); while (true) { var proxies = proxy.ProxyList; for (int i = 0; i < proxies.Count; i++) { Console.WriteLine(proxies[i]); } Thread.Sleep(3000); } //Console.ReadLine(); }
public static T GetOrDefault <T>(this IniKey that, T defaultValue, bool allowEmpty = false) { if (!allowEmpty) { var value = that.Value; if (string.IsNullOrEmpty(value)) { that.Value = Convert.ToString(defaultValue, CultureInfo.InvariantCulture); return(defaultValue); } else { return((T)Convert.ChangeType(that.Value, typeof(T), CultureInfo.InvariantCulture)); } } else { var value = that.Value; if (value == null) { that.Value = Convert.ToString(defaultValue, CultureInfo.InvariantCulture); return(defaultValue); } else { return((T)Convert.ChangeType(that.Value, typeof(T), CultureInfo.InvariantCulture)); } } }
private static ClientConfig CreateIni() { int Indentation = 4; // Create new file with a default formatting. IniFile file = new IniFile(IniOptions()); // IniSection Settings = file.Sections.Add("Client"); Settings.TrailingComment.Text = "Client Settings \\:D/"; // IniKey Rows = Settings.Keys.Add("Url", Url); Rows.LeftIndentation = Indentation; Rows.TrailingComment.Text = "This is where the software will send requests"; Rows.TrailingComment.LeftIndentation = Indentation; // Save file. try { file.Save(iniPath); } catch (IOException e) { Console.WriteLine(e.Message); } return(LoadINI.LoadIni(failed: true)); }
private static void Create() { // Create new file with a default formatting. IniFile file = new IniFile(new IniOptions()); // Add new content. IniSection section = new IniSection(file, IniSection.GlobalSectionName); IniKey key = new IniKey(file, "Key 1", "Value 1"); file.Sections.Add(section); section.Keys.Add(key); // Add new content. file.Sections.Add("Section 2").Keys.Add("Key 2", "Value 2"); // Add new content. file.Sections.Add( new IniSection(file, "Section 3", new IniKey(file, "Key 3.1", "Value 3.1"), new IniKey(file, "Key 3.2", "Value 3.2"))); // Add new content. file.Sections.Add( new IniSection(file, "Section 4", new Dictionary<string, string>() { {"Key 4.1", "Value 4.1"}, {"Key 4.2", "Value 4.2"} })); }
public IEnumerator Loop() { String prevbg = ""; while (true) { String newbg = GetBackGroundString(); if (prevbg != newbg && newbg != null) { prevbg = newbg; Console.WriteLine("[Moodscape] Background name: " + prevbg); Console.WriteLine("[Moodscape] Loading background config..."); try { IniKey scenesettings = Preferences[prevbg]["Preset"]; AudioReverbPreset preset = GetPresetFromId(int.Parse(scenesettings.Value)); Console.WriteLine("[Moodscape] Loaded correctly! Applying audio effects..."); GameObject[] objects = Resources.FindObjectsOfTypeAll <GameObject>().Where(obj => obj.name == "AudioVoice(Clone)").ToArray(); for (int i = 0; i < objects.Length; i++) { if (objects[i].GetComponent <AudioReverbFilter>() == null) { objects[i].AddComponent <AudioReverbFilter>(); } objects[i].GetComponent <AudioReverbFilter>().reverbPreset = preset; } Console.WriteLine("[Moodscape] Loaded preset " + preset + ", Done!"); } catch { GameObject[] objects = Resources.FindObjectsOfTypeAll <GameObject>().Where(obj => obj.name == "AudioVoice(Clone)").ToArray(); for (int i = 0; i < objects.Length; i++) { if (objects[i].GetComponent <AudioReverbFilter>() == null) { objects[i].AddComponent <AudioReverbFilter>(); } objects[i].GetComponent <AudioReverbFilter>().reverbPreset = AudioReverbPreset.Off; } Console.WriteLine("[Moodscape] No configuration found for this scene"); } } yield return(null); } }
public string ReadForeignIni(string filepath, IniSection section, IniKey key) { StringBuilder temp = new StringBuilder(255); if (GetPrivateProfileString(section.ToString(), key.ToString(), "", temp, 255, filepath) != 0) { return(temp.ToString()); } return(null); }
private static void SaveBoneDisplay() { IniKey iniKey = IniUtil.preferences["BoneDisplay"]["BoneSelectKey"]; int num = (int)Setting.boneSelectKey; iniKey.Value = num.ToString(); IniUtil.preferences["BoneDisplay"]["NormalBoneColor"].Value = ColorUtil.GetNameFromColor(Setting.normalBoneColor.GetValue()); IniUtil.preferences["BoneDisplay"]["SelectBoneColor"].Value = ColorUtil.GetNameFromColor(Setting.selectBoneColor.GetValue()); IniUtil.preferences["BoneDisplay"]["BodyBoneDisplay"].Value = ((int)Setting.bodyBoneDisplay.GetValue()).ToString(); }
private static void SaveGizmoDisplay() { IniKey iniKey = IniUtil.preferences["GizmoDisplay"]["GizmoSmallKey"]; int num = (int)Setting.gizmoSmallKey; iniKey.Value = num.ToString(); IniKey iniKey2 = IniUtil.preferences["GizmoDisplay"]["GizmoBigKey"]; num = (int)Setting.gizmoBigKey; iniKey2.Value = num.ToString(); }
public void Bug3() { string iniFileContent = "[sektion]" + Environment.NewLine + "key=\"Data Source=server;Initial Catalog=catalog;Integrated Security=SSPI\""; IniFile file = IniUtilities.LoadIniFileContent(iniFileContent, new IniOptions()); IniKey key = file.Sections["sektion"].Keys["key"]; Assert.AreEqual("\"Data Source=server;Initial Catalog=catalog;Integrated Security=SSPI\"", key.Value); Assert.IsNull(key.LeadingComment.Text); }
public void SetKeyValuesDimension(string sectionName, string keyName, int newDimension) { // Get / create section IniSection section = this[sectionName]; if (section == null) { section = new IniSection(sectionName); this.Sections.Add(section); } // Get / create Key IniKey key = section[keyName]; if (key == null) { key = new IniKey(); key.Name = keyName; key.OnChange += new EventHandler(this._sections_OnChange); section.Keys.Add(key); } // Setting dimension 0 - causes to not use multiple values if (newDimension < 1) { key.Values = null; key.Value = null; return; } // Create new array with values string[] array = new string[newDimension]; // Copy old values if (key.Multiline) { for (int i = 0; i < Math.Min(key.Values.Length, newDimension); i++) { array[i] = key.Values[i]; } } else { array[0] = key.Value; } // Keep new values array in Key key.Values = array; this.SetChanged(); }
public string GetKeyValue(string sectionName, string keyName) { IniKey key = this.GetKey(sectionName, keyName); if (key != null && !key.Multiline) { return(key.Value); } else { return(null); } }
public IniKey GetKey(string sectionName, string keyName) { IniSection section = this[sectionName]; if (section != null) { IniKey key = section[keyName]; return(key); } else { return(null); } }
public string Read(IniSection section, IniKey key, string defaultValue) { lock (_obj) { StringBuilder temp = new StringBuilder(255); if (GetPrivateProfileString(section.ToString(), key.ToString(), "", temp, 255, FilePath) != 0) { return(temp.ToString()); } Write(section, key, defaultValue); return(defaultValue); } }
private static void HelloWorld() { // Create new file. IniFile file = new IniFile(); // Add new section. IniSection section = file.Sections.Add("Section Name"); // Add new key and its value. IniKey key = section.Keys.Add("Key Name", "Hello World"); // Read file's specific value. Console.WriteLine(file.Sections["Section Name"].Keys["Key Name"].Value); }
//Salva as Configurações no arquivo Ini private void SaveIniConfig() { IniFile file = new IniFile(options); file.Load(Path); IniSection section = file.Sections.Add("database"); ConfigWeb config = JsonConvert.DeserializeObject <ConfigWeb>(webConfig); IniKey key = section.Keys.Add("Host", config.dbHost); key = section.Keys.Add("User", config.dbUser); key = section.Keys.Add("Pass", config.dbPass); key = section.Keys.Add("Database", config.dbDatabase); file.Save(Path); }
public void WriteString(string strKey, string strName, string strValue) { if (!m_Data.ContainsKey(strKey)) { m_Data[strKey] = new IniKey(strKey, 0); } IniKey key; if (m_Data.TryGetValue(strKey, out key)) { key.WriteString(strName, strValue, 0, null); } }
private static void FillDictionary(Dictionary <string, string> dic, IniSection sec, string[] names) { dic.Clear(); foreach (string name in names) { IniKey key = sec[name]; if (key == null) { throw new ApplicationException("Missing eneumeration key."); } dic.Add(name, key.Value); } }
private void ReadKey(int leftIndention, string line, IniFile file) { int keyDelimiterIndex = line.IndexOf((char)this.options.KeyDelimiter, leftIndention); if (keyDelimiterIndex != -1) { if (this.currentSection == null) this.currentSection = file.Sections.Add(IniSection.GlobalSectionName); var currentKey = new IniKey(file, line.Substring(leftIndention, keyDelimiterIndex - leftIndention).TrimEnd(), this.currentTrailingComment) { LeftIndentation = leftIndention, LeadingComment = { EmptyLinesBefore = this.currentEmptyLinesBefore } }; this.currentSection.Keys.Add(currentKey); this.ReadKeyValueAndLeadingComment(line.Substring(++keyDelimiterIndex).TrimStart(), currentKey); } this.currentTrailingComment = null; }
// Adds a key to the IniSection object, returns a IniKey object to the new or existing object /// <summary> /// The add key. /// </summary> /// <param name="sKey"> /// The s key. /// </param> /// <returns> /// The <see cref="IniKey"/>. /// </returns> public IniKey AddKey(string sKey) { sKey = sKey.Trim(); IniKey k = null; if (sKey.Length != 0) { if (this.m_keys.ContainsKey(sKey)) { k = (IniKey)this.m_keys[sKey]; } else { k = new IniKey(this, sKey); this.m_keys[sKey] = k; } } return k; }
private void ReadKeyValueAndLeadingComment(string lineLeftover, IniKey key) { /* REMARKS: First occurrence of comment's starting character (e.g. ';') defines key's value. * * CONSIDER: Implement a support for quoted values, thus enabling them to contain comment's starting characters. */ int valueEndIndex = lineLeftover.IndexOf((char)this.options.CommentStarter); if (valueEndIndex == -1) key.Value = lineLeftover.TrimEnd(); else if (valueEndIndex == 0) key.Value = key.LeadingComment.Text = string.Empty; else { key.LeadingComment.Text = lineLeftover.Substring(valueEndIndex + 1); // The amount of 'whitespace' characters between key's value and comment's starting character. int leftIndention = 0; while (lineLeftover[--valueEndIndex] == ' ' || lineLeftover[valueEndIndex] == '\t') leftIndention++; key.LeadingComment.LeftIndentation = leftIndention; key.Value = lineLeftover.Substring(0, ++valueEndIndex); } }
/// <summary> /// Adds a key to the IniSection object, returns a IniKey object to the new or existing object /// </summary> /// <param name="key"></param> /// <returns></returns> public IniKey AddKey(string key) { // Trim spaces key = key.Trim(); if (key.Length == 0) return null; if (_keys.ContainsKey(key)) return _keys[key]; IniKey k = new IniKey(this, key); _keys[key] = k; return k; }
private void ExecuteBinding(string placeholder, string placeholderName, IniKey placeholderKey, string targetedValue) { this.args.Initialize(placeholderName, placeholderKey, targetedValue, targetedValue != null); if (this.Binding != null) this.Binding(this, this.args); if (this.args.Value != null) placeholderKey.Value = placeholderKey.Value.Replace(placeholder, this.args.Value); this.args.Reset(); }
/// <summary> /// Removes a single key by IniKey object /// </summary> /// <param name="key">The key to remove.</param> /// <returns>True if succeeded false if an error occured</returns> public bool RemoveKey(IniKey key) { if (key == null) return false; try { _keys.Remove(key.Name); return true; } catch (Exception ex) { Trace.WriteLine(ex.Message); return false; } }
// Removes a single key by IniKey object public bool RemoveKey(IniKey Key) { if (Key != null) { try { m_keys.Remove(Key.Name); return true; } catch (Exception ex) { Trace.WriteLine(ex.Message); } } return false; }
public void UpdateDisallowDuplicatesKeysTest() { var options = new IniOptions() { KeyDuplicate = IniDuplication.Disallowed, }; var file = new IniFile(options); file.Sections.Add("SECTION1").Keys.Add("KEY1"); file.Sections.Add("SECTION1").Keys.Add("KEY1"); Assert.AreEqual(2, file.Sections.Count); Assert.AreEqual(1, file.Sections[0].Keys.Count); Assert.AreEqual(1, file.Sections[1].Keys.Count); var key = new IniKey(file, "KEY1"); file.Sections[0].Keys.Add(key); }