private static void Load() { IniOptions options = new IniOptions(); IniFile iniFile = new IniFile(options); // Load file from path. iniFile.Load(@"..\..\..\MadMilkman.Ini.Samples.Files\Load Example.ini"); // Load file from stream. using (Stream stream = File.OpenRead(@"..\..\..\MadMilkman.Ini.Samples.Files\Load Example.ini")) iniFile.Load(stream); // Load file's content from string. string iniContent = "[Section 1]" + Environment.NewLine + "Key 1.1 = Value 1.1" + Environment.NewLine + "Key 1.2 = Value 1.2" + Environment.NewLine + "Key 1.3 = Value 1.3" + Environment.NewLine + "Key 1.4 = Value 1.4"; iniFile.Load(new StringReader(iniContent)); // Read file's content. foreach (var section in iniFile.Sections) { Console.WriteLine("SECTION: {0}", section.Name); foreach (var key in section.Keys) Console.WriteLine("KEY: {0}, VALUE: {1}", key.Name, key.Value); } }
public IniReader(IniOptions options) { this.options = options; this.currentEmptyLinesBefore = 0; this.currentTrailingComment = null; this.currentSection = null; }
/// <summary> /// Initializes a new instance of <see cref="IniFile"/> class. /// </summary> /// <param name="options"><see cref="IniOptions"/> object that defines INI file's format, settings for both <see cref="O:MadMilkman.Ini.IniFile.Load">Load</see> and <see cref="O:MadMilkman.Ini.IniFile.Save">Save</see> methods.</param> public IniFile(IniOptions options) { if (options == null) throw new ArgumentNullException("options"); this.options = new IniOptions(options); this.sections = new IniSectionCollection(this, options.SectionDuplicate, options.SectionNameCaseSensitive); }
/// <summary> /// Initializes a new instance of <see cref="IniFile"/> class. /// </summary> /// <param name="options"><see cref="IniOptions"/> object that defines INI file's format, settings for both <see cref="O:MadMilkman.Ini.IniFile.Load">Load</see> and <see cref="O:MadMilkman.Ini.IniFile.Save">Save</see> methods.</param> public IniFile(IniOptions options) { if (options == null) { throw new ArgumentNullException("options"); } this.options = new IniOptions(options); this.sections = new IniSectionCollection(this, options.SectionDuplicate, options.SectionNameCaseSensitive); }
/// <summary> /// Interprets the ScpControl.ini configuration file. /// </summary> private IniConfig() { var iniOpts = new IniOptions() { CommentStarter = IniCommentStarter.Semicolon, KeyDuplicate = IniDuplication.Allowed }; var ini = new IniFile(iniOpts); var fullPath = Path.Combine(WorkingDirectory, CfgFile); if (!File.Exists(fullPath)) { Log.FatalFormat("Configuration file {0} not found!", fullPath); return; } // parse data from INI try { ini.Load(fullPath); Hci = new HciCfg() { SupportedNames = ini.Sections["Host Controller Interface"].Keys.Where(k => k.Name == "SupportedName").Select(v => v.Value), GenuineMacAddresses = ini.Sections["Host Controller Interface"].Keys.Where(k => k.Name == "GenuineMacAddress").Select(v => v.Value) }; Ds3Driver = new Ds3DriverCfg() { DeviceGuid = ini.Sections["DualShock 3 Controllers"].Keys["DeviceGuid"].Value, HardwareIds = ini.Sections["DualShock 3 Controllers"].Keys.Where(k => k.Name == "HardwareId").Select(v => v.Value) }; Ds4Driver = new Ds4DriverCfg() { DeviceGuid = ini.Sections["DualShock 4 Controllers"].Keys["DeviceGuid"].Value, HardwareIds = ini.Sections["DualShock 4 Controllers"].Keys.Where(k => k.Name == "HardwareId").Select(v => v.Value) }; BthDongleDriver = new BthDongleDriverCfg() { DeviceGuid = ini.Sections["Bluetooth Dongles"].Keys["DeviceGuid"].Value, HardwareIds = ini.Sections["Bluetooth Dongles"].Keys.Where(k => k.Name == "HardwareId").Select(v => v.Value) }; } catch (Exception ex) { Log.FatalFormat("Error while parsing configuration file: {0}", ex); } }
// Deep copy constructor. internal IniOptions(IniOptions options) { this.encoding = options.encoding; this.CommentStarter = options.CommentStarter; this.Compression = options.Compression; this.EncryptionPassword = options.EncryptionPassword; this.KeyDelimiter = options.KeyDelimiter; this.KeyDuplicate = options.KeyDuplicate; this.KeyNameCaseSensitive = options.KeyNameCaseSensitive; this.KeySpaceAroundDelimiter = options.KeySpaceAroundDelimiter; this.SectionDuplicate = options.SectionDuplicate; this.SectionNameCaseSensitive = options.SectionNameCaseSensitive; this.SectionWrapper = options.SectionWrapper; }
private static void Encrypt() { // Enable file's protection by providing an encryption password. IniOptions options = new IniOptions() { EncryptionPassword = "******" }; IniFile file = new IniFile(options); IniSection section = file.Sections.Add("User's Account"); section.Keys.Add("Username", "John Doe"); section.Keys.Add("Password", @"P@55\/\/0|2D"); // Save and encrypt the file. file.Save(@"..\..\..\MadMilkman.Ini.Samples.Files\Encrypt Example.ini"); file.Sections.Clear(); // Load and dencrypt the file. file.Load(@"..\..\..\MadMilkman.Ini.Samples.Files\Encrypt Example.ini"); Console.WriteLine("User Name: {0}", file.Sections[0].Keys["Username"].Value); Console.WriteLine("Password: {0}", file.Sections[0].Keys["Password"].Value); }
private static void Save() { IniOptions options = new IniOptions(); IniFile iniFile = new IniFile(options); iniFile.Sections.Add( new IniSection(iniFile, "Section 1", new IniKey(iniFile, "Key 1.1", "Value 1.1"), new IniKey(iniFile, "Key 1.2", "Value 1.2"), new IniKey(iniFile, "Key 1.3", "Value 1.3"), new IniKey(iniFile, "Key 1.4", "Value 1.4"))); // Save file to path. iniFile.Save(@"..\..\..\MadMilkman.Ini.Samples.Files\Save Example.ini"); // Save file to stream. using (Stream stream = File.Create(@"..\..\..\MadMilkman.Ini.Samples.Files\Save Example.ini")) iniFile.Save(stream); // Save file's content to string. StringWriter contentWriter = new StringWriter(); iniFile.Save(contentWriter); string iniContent = contentWriter.ToString(); Console.WriteLine(iniContent); }
private void XInputModToggleButton_OnChecked(object sender, RoutedEventArgs e) { var rootDir = _config.Pcsx2RootPath; var pluginsDir = Path.Combine(rootDir, "Plugins"); const string modFileName = "LilyPad-Scp-r5875.dll"; try { var lilypadOrig = Directory.GetFiles(pluginsDir, "*.dll").FirstOrDefault(f => f.Contains("lilypad")); var lilypadMod = Path.Combine(GlobalConfiguration.AppDirectory, "LilyPad", modFileName); var xinputMod = Path.Combine(GlobalConfiguration.AppDirectory, @"XInput\x86"); var xinputIni = Path.Combine(xinputMod, "ScpXInput.ini"); var iniOpts = new IniOptions { CommentStarter = IniCommentStarter.Semicolon }; var ini = new IniFile(iniOpts); ini.Load(xinputIni); ini.Sections["ScpControl"].Keys["BinPath"].Value = GlobalConfiguration.AppDirectory; ini.Save(xinputIni); // copy modded XInput DLL and dependencies foreach (var file in Directory.GetFiles(xinputMod)) { File.Copy(file, Path.Combine(rootDir, Path.GetFileName(file)), true); } // back up original plugin if (!string.IsNullOrEmpty(lilypadOrig)) { File.Move(lilypadOrig, Path.ChangeExtension(lilypadOrig, ".orig")); } // copy modded lilypad plugin File.Copy(lilypadMod, Path.Combine(pluginsDir, modFileName), true); XInputModToggleButton.Content = "Disable"; } catch (Exception ex) { MessageBox.Show("Couldn't mod PCSX2!", "Mod install failed", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show(ex.Message, "Error details", MessageBoxButton.OK, MessageBoxImage.Error); } }
public IniWriter(IniOptions options) { this.options = options; }
private static void Compress() { // Enable file's size reduction. IniOptions options = new IniOptions() { Compression = true }; IniFile file = new IniFile(options); for (int i = 1; i <= 100; i++) file.Sections.Add("Section " + i).Keys.Add("Key " + i, "Value " + i); // Save and compress the file. file.Save(@"..\..\..\MadMilkman.Ini.Samples.Files\Compress Example.ini"); file.Sections.Clear(); // Load and decompress the file. file.Load(@"..\..\..\MadMilkman.Ini.Samples.Files\Compress Example.ini"); Console.WriteLine(file.Sections.Count); }