public Preferences() : base(Gtk.WindowType.Toplevel) { this.Build (); IniFile file = new IniFile(new IniOptions()); if (File.Exists ("preferences.ini")) { file.Load("preferences.ini"); foreach (var section in file.Sections) { foreach (var key in section.Keys) { if (key.Name == "MameExe") edtMameAppLocation.Text = key.Value; else if (key.Name == "Snap") edtSnapLocation.Text = key.Value; else if (key.Name == "Roms") edtRomsLocation.Text = key.Value; else if (key.Name == "Flyer") edtFlyerLocation.Text = key.Value; } } } else { file.Sections.Add( new IniSection(file, "MameUI Config", new IniKey(file, "MameExe", ""), new IniKey(file, "Snap", ""), new IniKey(file, "Roms", ""), new IniKey(file, "Flyer", "") )); file.Save("preferences.ini"); } }
private void SavePreferences() { IniFile file = new IniFile(new IniOptions()); file.Sections.Add( new IniSection(file, "MameUI Config", new IniKey(file, "MameExe", edtMameAppLocation.Text), new IniKey(file, "Snap", edtSnapLocation.Text), new IniKey(file, "Roms", edtRomsLocation.Text), new IniKey(file, "Flyer", edtFlyerLocation.Text) )); file.Save("preferences.ini"); }
private static void Custom() { // Create new file with custom formatting. IniFile file = new IniFile( new IniOptions() { CommentStarter = IniCommentStarter.Hash, KeyDelimiter = IniKeyDelimiter.Colon, KeySpaceAroundDelimiter = true, SectionWrapper = IniSectionWrapper.CurlyBrackets, Encoding = Encoding.UTF8 }); // Load file. file.Load(@"..\..\..\MadMilkman.Ini.Samples.Files\Custom Example Input.ini"); // Change first section's fourth key's value. file.Sections[0].Keys[3].Value = "NEW VALUE"; // Save file. file.Save(@"..\..\..\MadMilkman.Ini.Samples.Files\Custom Example Output.ini"); }
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); } }
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); }