Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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");
            }
        }
Exemplo n.º 3
0
        /// <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);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Interprets the ScpControl.ini configuration file.
        /// </summary>
        private IniConfig()
        {
            var ini = new IniFile();
            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);

                string[] values;

                BthDongle = new BthDongleCfg();
                {
                    ini.Sections["BthDongle"].Keys["SupportedNames"].TryParseValue(out values);
                    BthDongle.SupportedNames = values;

                    ini.Sections["BthDongle"].Keys["SupportedMacs"].TryParseValue(out values);
                    BthDongle.SupportedMacs = values;
                }

                BthDs3 = new BthDs3Cfg();
                {
                    ini.Sections["BthDs3"].Keys["SupportedNames"].TryParseValue(out values);
                    BthDs3.SupportedNames = values;

                    ini.Sections["BthDs3"].Keys["SupportedMacs"].TryParseValue(out values);
                    BthDs3.SupportedMacs = values;
                }
            }
            catch (Exception ex)
            {
                Log.FatalFormat("Error while parsing configuration file: {0}", ex);
            }
        }
Exemplo n.º 5
0
        private static void BindCustomize()
        {
            IniFile file = new IniFile();
            string content = "[Player]" + Environment.NewLine +
                             "Name = @{Name}" + Environment.NewLine +
                             "Surname = @{Surname}" + Environment.NewLine +
                             "Adult = @{Age}" + Environment.NewLine +
                             "Medal = @{Rank}";
            file.Load(new StringReader(content));

            // Customize binding operation.
            file.ValueBinding.Binding += (sender, e) =>
            {
                // Set placeholders that do not have a value in data source to 'UNKNOWN'.
                if (!e.IsValueFound)
                {
                    e.Value = "UNKNOWN";
                    return;
                }

                // Set 'Age' placeholder inside 'Adult' key to an appropriate value.
                if (e.PlaceholderKey.Name.Equals("Adult") && e.PlaceholderName.Equals("Age"))
                {
                    int age;
                    if (int.TryParse(e.Value, out age))
                        e.Value = (age >= 18) ? "YES" : "NO";
                    else
                        e.Value = "UNKNOWN";
                    return;
                }

                // Set 'Rank' placeholder inside 'Medal' key to an appropriate value.
                if (e.PlaceholderKey.Name.Equals("Medal") && e.PlaceholderName.Equals("Rank"))
                {
                    int rank;
                    if (int.TryParse(e.Value, out rank))
                        switch (rank)
                        {
                            case 1:
                                e.Value = "GOLD";
                                break;
                            case 2:
                                e.Value = "SILVER";
                                break;
                            case 3:
                                e.Value = "BRONCE";
                                break;
                            default:
                                e.Value = "NONE";
                                break;
                        }
                    else
                        e.Value = "UNKNOWN";
                    return;
                }
            };

            // Execute binding operation.
            file.ValueBinding.Bind(
                new Dictionary<string, string>
                {
                    {"Name", "John"},
                    {"Age", "20"},
                    {"Rank", "1"}
                });
        }
Exemplo n.º 6
0
        private static void BindExternal()
        {
            IniFile file = new IniFile();
            string content = "[User's Settings]" + Environment.NewLine +
                             "Nickname = @{User Alias}" + Environment.NewLine +
                             "Full Name = @{User Name} @{User Surname}" + Environment.NewLine +
                             "Profile Page = @{Homepage}/Profiles/@{User Alias}";
            file.Load(new StringReader(content));

            // Bind placeholders with user's data, external information.
            file.ValueBinding.Bind(
                new Dictionary<string, string>
                {
                    {"User Alias", "Johny"},
                    {"User Name", "John"},
                    {"User Surname", "Doe"}
                });

            // Bind 'Homepage' placeholder with 'www.example.com' value.
            file.ValueBinding.Bind(
                new KeyValuePair<string, string>("Homepage", "www.example.com"));

            // Retrieve user's full name, value is 'John Doe'.
            string userFullName = file.Sections["User's Settings"].Keys["Full Name"].Value;

            // Retrieve user's profile page, value is 'www.example.com/Profiles/Johny'.
            string userProfilePage = file.Sections["User's Settings"].Keys["Profile Page"].Value;
        }
Exemplo n.º 7
0
        private static void BindInternal()
        {
            IniFile file = new IniFile();
            string content = "[Machine Settings]" + Environment.NewLine +
                             "Program Files = C:\\Program Files" + Environment.NewLine +
                             "[Application Settings]" + Environment.NewLine +
                             "Name = Example App" + Environment.NewLine +
                             "Version = 1.0" + Environment.NewLine +
                             "Full Name = @{Name} v@{Version}" + Environment.NewLine +
                             "Executable Path = @{Machine Settings|Program Files}\\@{Name}.exe";
            file.Load(new StringReader(content));

            // Bind placeholders with file's content, internal information.
            file.ValueBinding.Bind();

            // Retrieve application's full name, value is 'Example App v1.0'.
            string appFullName = file.Sections["Application Settings"].Keys["Full Name"].Value;

            // Retrieve application's executable path, value is 'C:\\Program Files\\Example App.exe'.
            string appExePath = file.Sections["Application Settings"].Keys["Executable Path"].Value;
        }
Exemplo n.º 8
0
        private static void Parse()
        {
            IniFile file = new IniFile();
            string content = "[Player]" + Environment.NewLine +
                             "Full Name = John Doe" + Environment.NewLine +
                             "Birthday = 12/31/1999" + Environment.NewLine +
                             "Married = Yes" + Environment.NewLine +
                             "Score = 9999999" + Environment.NewLine +
                             "Game Time = 00:59:59";
            file.Load(new StringReader(content));

            // Map 'yes' value as 'true' boolean.
            file.ValueMappings.Add("yes", true);
            // Map 'no' value as 'false' boolean.
            file.ValueMappings.Add("no", false);

            IniSection playerSection = file.Sections["Player"];

            // Retrieve player's name.
            string playerName = playerSection.Keys["Full Name"].Value;

            // Retrieve player's birthday as DateTime.
            DateTime playerBirthday;
            playerSection.Keys["Birthday"].TryParseValue(out playerBirthday);

            // Retrieve player's marital status as bool.
            // TryParseValue succeeds due to the mapping of 'yes' value to 'true' boolean.
            bool playerMarried;
            playerSection.Keys["Married"].TryParseValue(out playerMarried);

            // Retrieve player's score as long.
            long playerScore;
            playerSection.Keys["Score"].TryParseValue(out playerScore);

            // Retrieve player's game time as TimeSpan.
            TimeSpan playerGameTime;
            playerSection.Keys["Game Time"].TryParseValue(out playerGameTime);
        }
Exemplo n.º 9
0
        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");
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
-1
        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);
        }