Пример #1
0
        public PyRevitConfig(string cfgFilePath)
        {
            if (cfgFilePath != null)
            {
                if (CommonUtils.VerifyFile(cfgFilePath))
                {
                    CommonUtils.VerifyFileAccessible(cfgFilePath);
                    ConfigFilePath = cfgFilePath;

                    // INI formatting
                    var cfgOps = new IniOptions();
                    cfgOps.KeySpaceAroundDelimiter = true;
                    cfgOps.Encoding = CommonUtils.GetUTF8NoBOMEncoding();
                    _config         = new IniFile(cfgOps);

                    _config.Load(cfgFilePath);
                }
                else
                {
                    throw new PyRevitException("Can not access config file path.");
                }
            }
            else
            {
                throw new PyRevitException("Config file path can not be null.");
            }
        }
Пример #2
0
        public void ReadCustomTest()
        {
            string iniFileContent = "#Section's trailing comment." + Environment.NewLine +
                                    "{Section's name}#Section's leading comment." + Environment.NewLine +
                                    "#Key's trailing comment." + Environment.NewLine +
                                    "Key's name : Key's value#Key's leading comment.";

            IniOptions options = new IniOptions()
            {
                CommentStarter = IniCommentStarter.Hash,
                SectionWrapper = IniSectionWrapper.CurlyBrackets,
                KeyDelimiter   = IniKeyDelimiter.Colon
            };
            IniFile file = IniUtilities.LoadIniFileContent(iniFileContent, options);

            Assert.AreEqual(1, file.Sections.Count);
            Assert.AreEqual("Section's trailing comment.", file.Sections[0].TrailingComment.Text);
            Assert.AreEqual("Section's name", file.Sections[0].Name);
            Assert.AreEqual("Section's leading comment.", file.Sections[0].LeadingComment.Text);

            Assert.AreEqual(1, file.Sections[0].Keys.Count);
            Assert.AreEqual("Key's trailing comment.", file.Sections[0].Keys[0].TrailingComment.Text);
            Assert.AreEqual("Key's name", file.Sections[0].Keys[0].Name);
            Assert.AreEqual("Key's value", file.Sections[0].Keys[0].Value);
            Assert.AreEqual("Key's leading comment.", file.Sections[0].Keys[0].LeadingComment.Text);
        }
Пример #3
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);
                }
            }
        }
Пример #4
0
        public void WriteLeftIndentionTest()
        {
            IniOptions options = new IniOptions()
            {
                Encoding = Encoding.UTF8
            };
            IniFile file = new IniFile(options);

            file.Sections.Add(
                new IniSection(file, "Section",
                               new IniKey(file, "Key")
            {
                LeftIndentation = 2,
                TrailingComment = { Text = string.Empty, LeftIndentation = 4 },
                LeadingComment  = { Text = string.Empty, LeftIndentation = 2 }
            })
            {
                LeftIndentation = 2,
                TrailingComment = { Text = string.Empty, LeftIndentation = 4 },
                LeadingComment  = { Text = string.Empty, LeftIndentation = 2 }
            });

            string[] lines = IniUtilities.SaveIniFileContent(file, options);
            Assert.AreEqual("    ;", lines[0]);
            Assert.AreEqual("  [Section]  ;", lines[1]);
            Assert.AreEqual("    ;", lines[2]);
            Assert.AreEqual("  Key=  ;", lines[3]);
        }
Пример #5
0
        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);
        }
Пример #6
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);
        }
Пример #7
0
        public void WriteEmptyLinesTest()
        {
            IniOptions options = new IniOptions()
            {
                Encoding = Encoding.UTF8
            };
            IniFile file = new IniFile(options);

            file.Sections.Add(
                new IniSection(file, "Section",
                               new IniKey(file, "Key")
            {
                TrailingComment = { Text = string.Empty, EmptyLinesBefore = 2 },
                LeadingComment  = { Text = string.Empty, EmptyLinesBefore = 1 }
            })
            {
                TrailingComment = { Text = string.Empty, EmptyLinesBefore = 2 },
                LeadingComment  = { Text = string.Empty, EmptyLinesBefore = 1 }
            });

            string[] lines = IniUtilities.SaveIniFileContent(file, options);
            Assert.IsEmpty(lines[0]);
            Assert.IsEmpty(lines[1]);
            Assert.AreEqual(";", lines[2]);
            Assert.IsEmpty(lines[3]);
            Assert.AreEqual("[Section];", lines[4]);
            Assert.IsEmpty(lines[5]);
            Assert.IsEmpty(lines[6]);
            Assert.AreEqual(";", lines[7]);
            Assert.IsEmpty(lines[8]);
            Assert.AreEqual("Key=;", lines[9]);
        }
Пример #8
0
        public void ReadCustomTest()
        {
            string iniFileContent = "#Section's trailing comment." + Environment.NewLine +
                                    "{Section's name}#Section's leading comment." + Environment.NewLine +
                                    "#Key's trailing comment." + Environment.NewLine +
                                    "Key's name : Key's value#Key's leading comment.";

            IniOptions options = new IniOptions()
            {
                CommentStarter = IniCommentStarter.Hash,
                SectionWrapper = IniSectionWrapper.CurlyBrackets,
                KeyDelimiter = IniKeyDelimiter.Colon
            };
            IniFile file = IniUtilities.LoadIniFileContent(iniFileContent, options);

            Assert.AreEqual(1, file.Sections.Count);
            Assert.AreEqual("Section's trailing comment.", file.Sections[0].TrailingComment.Text);
            Assert.AreEqual("Section's name", file.Sections[0].Name);
            Assert.AreEqual("Section's leading comment.", file.Sections[0].LeadingComment.Text);

            Assert.AreEqual(1, file.Sections[0].Keys.Count);
            Assert.AreEqual("Key's trailing comment.", file.Sections[0].Keys[0].TrailingComment.Text);
            Assert.AreEqual("Key's name", file.Sections[0].Keys[0].Name);
            Assert.AreEqual("Key's value", file.Sections[0].Keys[0].Value);
            Assert.AreEqual("Key's leading comment.", file.Sections[0].Keys[0].LeadingComment.Text);
        }
Пример #9
0
        /// <summary>
        /// Registers legacy ini-options.
        /// </summary>
        internal static void RegisterLegacyOptions()
        {
            const string          s = ZlibLibraryDescriptor.ExtensionName;
            GetSetRestoreDelegate d = new GetSetRestoreDelegate(GetSetRestore);

            IniOptions.Register("zlib.output_compression", IniFlags.Supported | IniFlags.Global, d, s);
            IniOptions.Register("zlib.output_compression_level", IniFlags.Supported | IniFlags.Global, d, s);
            IniOptions.Register("zlib.output_handler", IniFlags.Supported | IniFlags.Global, d, s);

            //// global:
            //IniOptions.Register("mssql.max_links", IniFlags.Supported | IniFlags.Global, d, s);
            //IniOptions.Register("mssql.secure_connection", IniFlags.Supported | IniFlags.Global, d, s);
            //IniOptions.Register("mssql.allow_persistent", IniFlags.Unsupported | IniFlags.Global, d, s);
            //IniOptions.Register("mssql.max_persistent", IniFlags.Unsupported | IniFlags.Global, d, s);

            //// local:
            //IniOptions.Register("mssql.connect_timeout", IniFlags.Supported | IniFlags.Local, d, s);
            //IniOptions.Register("mssql.timeout", IniFlags.Supported | IniFlags.Local, d, s);
            //IniOptions.Register("mssql.batchsize", IniFlags.Supported | IniFlags.Local, d, s);
            //IniOptions.Register("mssql.min_error_severity", IniFlags.Unsupported | IniFlags.Local, d, s);
            //IniOptions.Register("mssql.min_message_severity", IniFlags.Unsupported | IniFlags.Local, d, s);
            //IniOptions.Register("mssql.compatability_mode", IniFlags.Unsupported | IniFlags.Local, d, s);
            //IniOptions.Register("mssql.textsize", IniFlags.Unsupported | IniFlags.Local, d, s);
            //IniOptions.Register("mssql.textlimit", IniFlags.Unsupported | IniFlags.Local, d, s);
            //IniOptions.Register("mssql.datetimeconvert", IniFlags.Unsupported | IniFlags.Local, d, s);
            //IniOptions.Register("mssql.max_procs", IniFlags.Unsupported | IniFlags.Local, d, s);
        }
Пример #10
0
        public void Bug1()
        {
            string iniFileContent = "[Segment [A]]" + Environment.NewLine +
                                    "[Segment [A]];[Comment];" + Environment.NewLine +

                                    "[Segment [A][1]]" + Environment.NewLine +
                                    "[Segment [A][1]]  ;[Comment][1];" + Environment.NewLine +

                                    "[Segment;A]" + Environment.NewLine +
                                    "[Segment[A;B]]" + Environment.NewLine +
                                    "[Segment[A;B]];" + Environment.NewLine +
                                    "[Segment[A;B]]    ;[Comment];" + Environment.NewLine +

                                    "[Segment[A;B]]AB;Invalid comment" + Environment.NewLine +
                                    "[Segment[A;B]][[;Invalid comment" + Environment.NewLine +
                                    "[Segment[A;B;]";

            IniOptions options = new IniOptions();
            IniFile    file    = IniUtilities.LoadIniFileContent(iniFileContent, options);

            Assert.AreEqual("Segment [A]", file.Sections[0].Name);
            Assert.AreEqual("Segment [A]", file.Sections[1].Name);
            Assert.AreEqual("[Comment];", file.Sections[1].LeadingComment.Text);

            Assert.AreEqual("Segment [A][1]", file.Sections[2].Name);
            Assert.AreEqual("Segment [A][1]", file.Sections[3].Name);
            Assert.AreEqual("[Comment][1];", file.Sections[3].LeadingComment.Text);
            Assert.AreEqual(2, file.Sections[3].LeadingComment.LeftIndentation);

            Assert.AreEqual("Segment;A", file.Sections[4].Name);
            Assert.AreEqual(null, file.Sections[4].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B]", file.Sections[5].Name);
            Assert.AreEqual(null, file.Sections[5].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B]", file.Sections[6].Name);
            Assert.AreEqual(string.Empty, file.Sections[6].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B]", file.Sections[7].Name);
            Assert.AreEqual("[Comment];", file.Sections[7].LeadingComment.Text);
            Assert.AreEqual(4, file.Sections[7].LeadingComment.LeftIndentation);

            Assert.AreEqual("Segment[A;B]", file.Sections[8].Name);
            Assert.AreEqual(null, file.Sections[8].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B]", file.Sections[9].Name);
            Assert.AreEqual(null, file.Sections[9].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B;", file.Sections[10].Name);

            string[] lines = IniUtilities.SaveIniFileContent(file, options);

            Assert.AreEqual("[Segment [A]]", lines[0]);
            Assert.AreEqual("[Segment [A]];[Comment];", lines[1]);
            Assert.AreEqual("[Segment [A][1]]", lines[2]);
            Assert.AreEqual("[Segment [A][1]]  ;[Comment][1];", lines[3]);
            Assert.AreEqual("[Segment;A]", lines[4]);
            Assert.AreEqual("[Segment[A;B]]", lines[5]);
            Assert.AreEqual("[Segment[A;B]];", lines[6]);
            Assert.AreEqual("[Segment[A;B]]    ;[Comment];", lines[7]);
            Assert.AreEqual("[Segment[A;B]]", lines[8]);
            Assert.AreEqual("[Segment[A;B]]", lines[9]);
            Assert.AreEqual("[Segment[A;B;]", lines[10]);
        }
Пример #11
0
        public void Bug1()
        {
            string iniFileContent = "[Segment [A]]" + Environment.NewLine +
                                    "[Segment [A]];[Comment];" + Environment.NewLine +

                                    "[Segment [A][1]]" + Environment.NewLine +
                                    "[Segment [A][1]]  ;[Comment][1];" + Environment.NewLine +

                                    "[Segment;A]" + Environment.NewLine +
                                    "[Segment[A;B]]" + Environment.NewLine +
                                    "[Segment[A;B]];" + Environment.NewLine +
                                    "[Segment[A;B]]    ;[Comment];" + Environment.NewLine +

                                    "[Segment[A;B]]AB;Invalid comment" + Environment.NewLine +
                                    "[Segment[A;B]][[;Invalid comment" + Environment.NewLine +
                                    "[Segment[A;B;]";

            IniOptions options = new IniOptions();
            IniFile file = IniUtilities.LoadIniFileContent(iniFileContent, options);

            Assert.AreEqual("Segment [A]", file.Sections[0].Name);
            Assert.AreEqual("Segment [A]", file.Sections[1].Name);
            Assert.AreEqual("[Comment];", file.Sections[1].LeadingComment.Text);

            Assert.AreEqual("Segment [A][1]", file.Sections[2].Name);
            Assert.AreEqual("Segment [A][1]", file.Sections[3].Name);
            Assert.AreEqual("[Comment][1];", file.Sections[3].LeadingComment.Text);
            Assert.AreEqual(2, file.Sections[3].LeadingComment.LeftIndentation);

            Assert.AreEqual("Segment;A", file.Sections[4].Name);
            Assert.AreEqual(null, file.Sections[4].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B]", file.Sections[5].Name);
            Assert.AreEqual(null, file.Sections[5].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B]", file.Sections[6].Name);
            Assert.AreEqual(string.Empty, file.Sections[6].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B]", file.Sections[7].Name);
            Assert.AreEqual("[Comment];", file.Sections[7].LeadingComment.Text);
            Assert.AreEqual(4, file.Sections[7].LeadingComment.LeftIndentation);

            Assert.AreEqual("Segment[A;B]", file.Sections[8].Name);
            Assert.AreEqual(null, file.Sections[8].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B]", file.Sections[9].Name);
            Assert.AreEqual(null, file.Sections[9].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B;", file.Sections[10].Name);

            string[] lines = IniUtilities.SaveIniFileContent(file, options);

            Assert.AreEqual("[Segment [A]]", lines[0]);
            Assert.AreEqual("[Segment [A]];[Comment];", lines[1]);
            Assert.AreEqual("[Segment [A][1]]", lines[2]);
            Assert.AreEqual("[Segment [A][1]]  ;[Comment][1];", lines[3]);
            Assert.AreEqual("[Segment;A]", lines[4]);
            Assert.AreEqual("[Segment[A;B]]", lines[5]);
            Assert.AreEqual("[Segment[A;B]];", lines[6]);
            Assert.AreEqual("[Segment[A;B]]    ;[Comment];", lines[7]);
            Assert.AreEqual("[Segment[A;B]]", lines[8]);
            Assert.AreEqual("[Segment[A;B]]", lines[9]);
            Assert.AreEqual("[Segment[A;B;]", lines[10]);
        }
Пример #12
0
        private static void InitParameters()
        {
            IniOptions options = new IniOptions
            {
                KeyDuplicate     = IniDuplication.Allowed,
                SectionDuplicate = IniDuplication.Allowed
            };

            IniFile ini = new IniFile(options);

            ini.Load("config.ini");

            foreach (IniSection section in ini.Sections)
            {
                foreach (IniKey key in section.Keys)
                {
                    switch (key.Name)
                    {
                    case "debug":
                        Properties.Settings.Default.debug = Convert.ToBoolean(key.Value);
                        break;

                    case "area":
                        Properties.Settings.Default.area = Convert.ToInt32(key.Value);
                        break;

                    case "boxSizeWidthMin":
                        Properties.Settings.Default.boxSizeWidthMin = Convert.ToInt32(key.Value);
                        break;

                    case "boxSizeWidthMax":
                        Properties.Settings.Default.boxSizeWidthMax = Convert.ToInt32(key.Value);
                        break;

                    case "boxSizeHeightMin":
                        Properties.Settings.Default.boxSizeHeightMin = Convert.ToInt32(key.Value);
                        break;

                    case "boxSizeHeightMax":
                        Properties.Settings.Default.boxSizeHeightMax = Convert.ToInt32(key.Value);
                        break;

                    case "boundingRectangleHeightMin":
                        Properties.Settings.Default.boundingRectangleHeightMin = Convert.ToInt32(key.Value);
                        break;

                    case "boundingRectangleHeightMax":
                        Properties.Settings.Default.boundingRectangleHeightMax = Convert.ToInt32(key.Value);
                        break;

                    case "boundingRectangleWidthMax":
                        Properties.Settings.Default.boundingRectangleWidthMax = Convert.ToInt32(key.Value);
                        break;
                    }
                }
            }

            Properties.Settings.Default.Save();
        }
Пример #13
0
 protected SectionCollection(IniOptions options)
 {
     Sections = new Dictionary <string, Section> {
         { Section.DefaultSectionName, Section.CreateDefault(options) }
     };
     CurrentSection = Section.DefaultSectionName;
     Options        = options;
 }
Пример #14
0
        public static IniFile LoadIniFileContent(string iniFileContent, IniOptions options)
        {
            IniFile file = new IniFile(options);

            using (var stream = new MemoryStream(options.Encoding.GetBytes(iniFileContent)))
                file.Load(stream);

            return file;
        }
Пример #15
0
 private static IniBlock CreateBlock(string name, IniOptions options, string comments)
 {
     return(new IniBlock
     {
         Name = name,
         Options = options,
         Comments = comments,
     });
 }
Пример #16
0
        public static IniFile LoadIniFileContent(string iniFileContent, IniOptions options)
        {
            IniFile file = new IniFile(options);

            using (var stream = new MemoryStream(options.Encoding.GetBytes(iniFileContent)))
                file.Load(stream);

            return(file);
        }
Пример #17
0
        /// <summary>
        /// Registers legacy ini-options.
        /// </summary>
        internal static void RegisterLegacyOptions()
        {
            const string          s = "iconv";
            GetSetRestoreDelegate d = new GetSetRestoreDelegate(GetSetRestore);

            IniOptions.Register("iconv.input_encoding", IniFlags.Supported | IniFlags.Local, d, s);
            IniOptions.Register("iconv.internal_encoding", IniFlags.Supported | IniFlags.Local, d, s);
            IniOptions.Register("iconv.output_encoding", IniFlags.Supported | IniFlags.Local, d, s);
        }
Пример #18
0
        private static IniOptions iniOptions()
        {
            IniOptions options = new IniOptions();

            options.CommentStarter     = IniCommentStarter.Hash;
            options.Compression        = false;
            options.Encoding           = Encoding.UTF8;
            options.EncryptionPassword = null;
            return(options);
        }
Пример #19
0
        /// <summary>
        /// Registers legacy ini-options.
        /// </summary>
        internal static void RegisterLegacyOptions()
        {
            const string          s = SQLiteLibraryDescriptor.ExtensionName;
            GetSetRestoreDelegate d = new GetSetRestoreDelegate(GetSetRestore);

            // local:

            // global:
            IniOptions.Register("sqlite.assoc_case", IniFlags.Supported | IniFlags.Global, d, s);
        }
Пример #20
0
        public void TestNewlineInAssignmentFlexibleParsing()
        {
            var options = new IniOptions(propertyParsing: PropertyParsing.Flexible);

            using (var reader = new StringReader("value=\n10"))
                using (var parser = new Parser.Parser(reader, options))
                {
                    Assert.Throws <InvalidTokenException>(() => parser.ParseUnit());
                }
        }
Пример #21
0
        public static string[] SaveIniFileContent(IniFile file, IniOptions options)
        {
            string iniFileContent;
            using (var stream = new MemoryStream())
            {
                file.Save(stream);
                iniFileContent = new StreamReader(stream, options.Encoding).ReadToEnd();
            }

            return iniFileContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
        }
Пример #22
0
        public void GetSectionCaseInsensitiveParsing()
        {
            var options = new IniOptions(caseSensitive: false);

            using (var reader = new StringReader("[SECTION]"))
                using (var parser = new Parser.Parser(reader, options))
                    using (var doc = new ParsedSectionCollection(parser, options))
                    {
                        Assert.NotNull(doc.GetSection("section"));
                    }
        }
Пример #23
0
        public Property(string name, object value, IniOptions options) : base(options)
        {
            Name = CaseSensitiviseString(name);

            if (!AcceptedTypes.Contains(value.GetType()))
            {
                throw new ArgumentException($"value is of invalid type ({value.GetType().Name})");
            }

            this.value = value;
        }
Пример #24
0
        public void GetSectionCaseSensitiveParsing()
        {
            var options = new IniOptions(caseSensitive: true);

            using (var reader = new StringReader("[SECTION]"))
                using (var parser = new Parser.Parser(reader, options))
                    using (var doc = new ParsedSectionCollection(parser, options))
                    {
                        Assert.Throws <ArgumentException>(() => doc.GetSection("section"));
                    }
        }
Пример #25
0
        public void WriteUTF8EncodingTest()
        {
            IniOptions options = new IniOptions() { Encoding = Encoding.UTF8 };
            IniFile file = new IniFile(options);

            file.Sections.Add(new IniSection(file, "Καλημέρα κόσμε"));
            file.Sections.Add(new IniSection(file, "こんにちは 世界"));

            string[] lines = IniUtilities.SaveIniFileContent(file, options);
            Assert.AreEqual("[Καλημέρα κόσμε]", lines[0]);
            Assert.AreEqual("[こんにちは 世界]", lines[1]);
        }
Пример #26
0
        public void TestReadImplicitCastToStringNotAllowed(
            [Values] bool caseSensitive)
        {
            var options = new IniOptions(
                caseSensitive: caseSensitive,
                allowValueConversion: false);

            using (var reader = new IniReader("basic.ini", options))
            {
                Assert.Throws <InvalidCastException>(() => reader.GetString("Section.int"));
            }
        }
Пример #27
0
        public void TestParseSingleQuotedString()
        {
            var options = new IniOptions();

            using (var reader = new StringReader("'Hello, World!'"))
                using (var parser = new Parser.Parser(reader, IniOptions.Default))
                {
                    var unit = parser.ParseUnitOfType <ValueUnit>();
                    Assert.AreEqual("'Hello, World!'", unit.SourceTokenString());
                    Assert.AreEqual("Hello, World!", unit.Value);
                }
        }
Пример #28
0
        public void TestReadParseFromStringAllowed(
            [Values] bool caseSensitive)
        {
            var options = new IniOptions(
                caseSensitive: caseSensitive,
                allowValueConversion: true);

            using (var reader = new IniReader("special.ini", options))
            {
                Assert.AreEqual(10L, reader.GetInt64("int_in_string"));
            }
        }
Пример #29
0
        public void TestNoSkipLeadingNewlineFlexibleParsing()
        {
            var options = new IniOptions(propertyParsing: PropertyParsing.Flexible);

            using (var reader = new StringReader("\na"))
                using (var parser = new Parser.Parser(reader, options))
                {
                    var unit = parser.ParseUnitOfType <ValueUnit>(skipNewline: false);
                    Assert.AreEqual("\na", unit.SourceTokenString());
                    Assert.AreEqual("\na", unit.Value);
                }
        }
Пример #30
0
        public static string[] SaveIniFileContent(IniFile file, IniOptions options)
        {
            string iniFileContent;

            using (var stream = new MemoryStream())
            {
                file.Save(stream);
                iniFileContent = new StreamReader(stream, options.Encoding).ReadToEnd();
            }

            return(iniFileContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.None));
        }
Пример #31
0
        public void TestReadImplicitCastToStringAllowed(
            [Values] bool caseSensitive)
        {
            var options = new IniOptions(
                caseSensitive: caseSensitive,
                allowValueConversion: true);

            using (var reader = new IniReader("basic.ini", options))
            {
                Assert.AreEqual("10", reader.GetString("Section.int"));
            }
        }
Пример #32
0
        public void TestReadParseFromStringNotAllowed(
            [Values] bool caseSensitive)
        {
            var options = new IniOptions(
                caseSensitive: caseSensitive,
                allowValueConversion: false);

            using (var reader = new IniReader("special.ini", options))
            {
                Assert.Throws <InvalidCastException>(() => reader.GetInt64("int_in_string"));
            }
        }
Пример #33
0
        internal static bool LoadIni(out IniFile iniFile, IniOptions iniOptions, string iniPath)
        {
            if (!File.Exists(iniPath))
            {
                iniFile = null;
                return(false);
            }

            iniFile = new IniFile(iniOptions);
            iniFile.Load(iniPath);

            return(true);
        }
Пример #34
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);
            }
        }
        public void UpdateDisallowDuplicatesSectionsTest()
        {
            var options = new IniOptions()
            {
                SectionDuplicate = IniDuplication.Disallowed
            };

            var file = new IniFile(options);

            file.Sections.Add("SECTION1").Keys.Add("KEY1");
            var section = new IniSection(file, "SECTION1");

            file.Sections.Add(section);
        }
Пример #36
0
        public void WriteGlobalSectionTest()
        {
            IniOptions options = new IniOptions();
            IniFile file = new IniFile(options);

            file.Sections.Add(
                new IniSection(file, IniSection.GlobalSectionName,
                    new IniKey(file, "Key1", "Value1"),
                    new IniKey(file, "Key2", "Value2")));

            string[] lines = IniUtilities.SaveIniFileContent(file, options);
            Assert.AreEqual("Key1=Value1", lines[0]);
            Assert.AreEqual("Key2=Value2", lines[1]);
        }
Пример #37
0
        public void WriteCustomTest()
        {
            IniOptions options = new IniOptions()
            {
                KeyDelimiter = IniKeyDelimiter.Colon,
                KeySpaceAroundDelimiter = true,
                SectionWrapper = IniSectionWrapper.Parentheses
            };
            IniFile file = new IniFile(options);

            file.Sections.Add(
                new IniSection(file, "Section",
                    new IniKey(file, "Key", "Value")));

            string[] lines = IniUtilities.SaveIniFileContent(file, options);
            Assert.AreEqual("(Section)", lines[0]);
            Assert.AreEqual("Key : Value", lines[1]);
        }
Пример #38
0
        public void WriteDefaultTest()
        {
            IniOptions options = new IniOptions();
            IniFile file = new IniFile(options);

            file.Sections.Add(
                new IniSection(file, "Section",
                    new IniKey(file, "Key", "Value")
                    {
                        TrailingComment = { Text = "Trailing comment" },
                        LeadingComment = { Text = "Leading comment" }
                    })
                {
                    TrailingComment = { Text = "Trailing comment" },
                    LeadingComment = { Text = "Leading comment" }
                });

            string[] lines = IniUtilities.SaveIniFileContent(file, options);
            Assert.AreEqual(";Trailing comment", lines[0]);
            Assert.AreEqual("[Section];Leading comment", lines[1]);
            Assert.AreEqual(";Trailing comment", lines[2]);
            Assert.AreEqual("Key=Value;Leading comment", lines[3]);
        }
        public void UpdateIgnoreDuplicatesTest()
        {
            var options = new IniOptions()
            {
                KeyDuplicate = IniDuplication.Ignored,
                KeyNameCaseSensitive = true,
                SectionDuplicate = IniDuplication.Ignored,
                SectionNameCaseSensitive = false
            };

            var file = new IniFile(options);
            file.Sections.Add(
                new IniSection(file, "SECTION",
                    new IniKey(file, "KEY"),
                    new IniKey(file, "key")));
            file.Sections.Add(
                new IniSection(file, "section"));

            Assert.AreEqual(1, file.Sections.Count);
            Assert.AreEqual(2, file.Sections[0].Keys.Count);
            Assert.IsTrue(file.Sections[0].Keys.Contains("KEY"));
            Assert.IsTrue(file.Sections[0].Keys.Contains("key"));

            Assert.AreEqual("key", file.Sections[0].Keys[1].Name);
            file.Sections[0].Keys[1].Name = "KEY";
            Assert.AreNotEqual("KEY", file.Sections[0].Keys[1].Name);

            file.Sections[0].Keys.Insert(0, "key");
            Assert.AreEqual(2, file.Sections[0].Keys.Count);
            Assert.AreNotEqual("key", file.Sections[0].Keys[0].Name);

            file.Sections[0].Keys.Remove("KEY");
            Assert.IsFalse(file.Sections.Contains("KEY"));

            Assert.AreEqual("key", file.Sections[0].Keys[0].Name);
            file.Sections[0].Keys[0].Name = "KEY";
            Assert.AreEqual("KEY", file.Sections[0].Keys[0].Name);
        }
        public void UpdateDisallowDuplicatesSectionsTest()
        {
            var options = new IniOptions()
            {
                SectionDuplicate = IniDuplication.Disallowed
            };

            var file = new IniFile(options);
            file.Sections.Add("SECTION1").Keys.Add("KEY1");
            var section = new IniSection(file, "SECTION1");
            file.Sections.Add(section);
        }
Пример #41
0
        public void WriteEmptyLinesTest()
        {
            IniOptions options = new IniOptions() { Encoding = Encoding.UTF8 };
            IniFile file = new IniFile(options);

            file.Sections.Add(
                new IniSection(file, "Section",
                    new IniKey(file, "Key")
                    {
                        TrailingComment = { Text = string.Empty, EmptyLinesBefore = 2 },
                        LeadingComment = { Text = string.Empty, EmptyLinesBefore = 1 }
                    })
                {
                    TrailingComment = { Text = string.Empty, EmptyLinesBefore = 2 },
                    LeadingComment = { Text = string.Empty, EmptyLinesBefore = 1 }
                });

            string[] lines = IniUtilities.SaveIniFileContent(file, options);
            Assert.IsEmpty(lines[0]);
            Assert.IsEmpty(lines[1]);
            Assert.AreEqual(";", lines[2]);
            Assert.IsEmpty(lines[3]);
            Assert.AreEqual("[Section];", lines[4]);
            Assert.IsEmpty(lines[5]);
            Assert.IsEmpty(lines[6]);
            Assert.AreEqual(";", lines[7]);
            Assert.IsEmpty(lines[8]);
            Assert.AreEqual("Key=;", lines[9]);
        }
        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);
        }
Пример #43
0
        public void WriteLeftIndentionTest()
        {
            IniOptions options = new IniOptions() { Encoding = Encoding.UTF8 };
            IniFile file = new IniFile(options);

            file.Sections.Add(
                new IniSection(file, "Section",
                    new IniKey(file, "Key")
                    {
                        LeftIndentation = 2,
                        TrailingComment = { Text = string.Empty, LeftIndentation = 4 },
                        LeadingComment = { Text = string.Empty, LeftIndentation = 2 }
                    })
                {
                    LeftIndentation = 2,
                    TrailingComment = { Text = string.Empty, LeftIndentation = 4 },
                    LeadingComment = { Text = string.Empty, LeftIndentation = 2 }
                });

            string[] lines = IniUtilities.SaveIniFileContent(file, options);
            Assert.AreEqual("    ;", lines[0]);
            Assert.AreEqual("  [Section]  ;", lines[1]);
            Assert.AreEqual("    ;", lines[2]);
            Assert.AreEqual("  Key=  ;", lines[3]);
        }