Example #1
0
        private LegacyIniFiles()
        {
            // Get the paths:
            this.iniParentPath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                @"My Games\Fallout 76\"
                );

            this.configPath = Path.Combine(Shared.AppConfigFolder, "config.ini");

            // Configuring INI parser
            IniParserConfiguration iniParserConfig = new IniParserConfiguration();

            iniParserConfig.AllowCreateSectionsOnFly = true;
            iniParserConfig.AssigmentSpacer          = "";
            iniParserConfig.CaseInsensitive          = true;
            iniParserConfig.CommentRegex             = new System.Text.RegularExpressions.Regex(@"^;.*");

            // Be very generous, allow everything:
            iniParserConfig.AllowDuplicateKeys      = true;
            iniParserConfig.AllowDuplicateSections  = true;
            iniParserConfig.AllowKeysWithoutSection = true;
            iniParserConfig.OverrideDuplicateKeys   = true;

            // Initialize INI parser
            this.iniParser = new FileIniDataParser(new IniDataParser(iniParserConfig));
        }
Example #2
0
        private void SetScreenSizeInPrefs()
        {
            var config = new IniParserConfiguration {
                AllowDuplicateKeys = true, AllowDuplicateSections = true
            };

            foreach (var file in Directory.EnumerateFiles(Path.Combine(OutputFolder, "profiles"), "*refs.ini",
                                                          DirectoryEnumerationOptions.Recursive))
            {
                try
                {
                    var parser = new FileIniDataParser(new IniDataParser(config));
                    var data   = parser.ReadFile(file);
                    if (data.Sections["Display"] == null)
                    {
                        return;
                    }

                    if (data.Sections["Display"]["iSize W"] != null && data.Sections["Display"]["iSize H"] != null)
                    {
                        data.Sections["Display"]["iSize W"] = SystemParameters.ScreenWidth.ToString(CultureInfo.CurrentCulture);
                        data.Sections["Display"]["iSize H"] = SystemParameters.ScreenHeight.ToString(CultureInfo.CurrentCulture);
                    }

                    parser.WriteFile(file, data);
                }
                catch (Exception ex)
                {
                    Utils.Log($"Skipping screen size remap for {file} due to parse error.");
                    continue;
                }
            }
        }
Example #3
0
        /// <summary>
        /// INIFile Constructor.
        /// </summary>
        /// <PARAM name="INIPath"></PARAM>
        public IniFile(string iniPath)
        {
            _path = iniPath;

            Directory.CreateDirectory(Path.GetDirectoryName(_path));
            if (!File.Exists(_path))
            {
                File.WriteAllText(_path, string.Empty, Encoding.Unicode);
            }

            _config = new IniParserConfiguration
            {
                AllowCreateSectionsOnFly = true,
                AllowDuplicateKeys       = true,
                AllowDuplicateSections   = true,
                OverrideDuplicateKeys    = true,
                SkipInvalidLines         = true,
                ThrowExceptionsOnError   = true,
                AllowKeysWithoutSection  = true
            };

            _dataParser = new IniDataParser(_config);
            _parser     = new FileIniDataParser(_dataParser);
            Data        = _parser.ReadFile(_path);
        }
Example #4
0
        private void buttonAdvanced_Click(object sender, EventArgs e)
        {
            var          script = new ScriptInfo(pkgConf.ToString(), "Package Configuration", help.Url, "Details about Package Configuration");
            DialogResult result = Helper.ScriptEditor(script, null, variables);

            if (result == DialogResult.OK)
            {
                {
                    IniParserConfiguration config = new IniParserConfiguration();
                    config.AssigmentSpacer = "";
                    var parser       = new IniDataParser(config);
                    var streamParser = new StreamIniDataParser(parser);
                    try
                    {
                        using (var stream = Helper.GetStreamFromString(script.Code))
                        {
                            using (var streamReader = new StreamReader(stream))
                            {
                                pkgConf = streamParser.ReadData(streamReader);
                            }
                        }
                    }
                    catch
                    {
                        MessageBoxEx.Show(this, "This Package Configuration can't be parsed.", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    }
                }
                DisplayPkgConf();
            }
        }
Example #5
0
 public DefaultIniDataFormatter(IniParserConfiguration configuration)
 {
     if (configuration == null)
     {
         throw new ArgumentNullException("configuration");
     }
     this.Configuration = configuration;
 }
Example #6
0
        public void check_default_values()
        {
            var config = new IniParserConfiguration();

            Assert.That(config, Is.Not.Null);
            Assert.That(config.CommentRegex, Is.Not.Null);
            Assert.That(config.SectionRegex, Is.Not.Null);
        }
Example #7
0
        private static IniDataParser IniParser()
        {
            var config = new IniParserConfiguration {
                AllowDuplicateKeys = true, AllowDuplicateSections = true
            };
            var parser = new IniDataParser(config);

            return(parser);
        }
Example #8
0
        /// <summary>
        ///     Ctor
        /// </summary>
        /// <param name="parserConfiguration">
        ///     Parser's <see cref="IniParserConfiguration" instance.
        /// </param>
        public IniDataParser(IniParserConfiguration parserConfiguration)
        {
            if (parserConfiguration == null)
                throw new ArgumentNullException("parserConfiguration");

            Configuration = parserConfiguration;

            _errorExceptions = new List<Exception>();
        }
        private IniFiles()
        {
            // Get the paths:
            this.iniParentPath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                @"My Games\Fallout 76\"
                );

            /*this.GetIniName(IniFile.F76) = Path.Combine(this.iniParentPath, "Fallout76.ini");
             * this.GetIniName(IniFile.F76Prefs) = Path.Combine(this.iniParentPath, "Fallout76Prefs.ini");
             * this.GetIniName(IniFile.F76Custom) = Path.Combine(this.iniParentPath, "Fallout76Custom.ini");*/
            String pre1point6ConfigPath = Path.Combine(this.iniParentPath, "QuickConfiguration.ini");
            String oldConfigPath        = Path.Combine(Shared.OldAppConfigFolder, "config.ini");

            this.configPath = Path.Combine(Shared.AppConfigFolder, "config.ini");

            // Backwards-compatibility: Move config file to new location:

            // Pre v1.6 location:
            if (File.Exists(pre1point6ConfigPath) && !File.Exists(this.configPath))
            {
                if (!Directory.Exists(Path.GetDirectoryName(this.configPath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(this.configPath));
                }
                File.Move(pre1point6ConfigPath, this.configPath);
            }

            // Pre v1.7.1 location:
            if (File.Exists(oldConfigPath) && !File.Exists(this.configPath))
            {
                if (!Directory.Exists(Path.GetDirectoryName(this.configPath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(this.configPath));
                }
                File.Copy(oldConfigPath, this.configPath);
            }

            // Configuring INI parser
            IniParserConfiguration iniParserConfig = new IniParserConfiguration();

            iniParserConfig.AllowCreateSectionsOnFly = true;
            iniParserConfig.AssigmentSpacer          = "";
            iniParserConfig.CaseInsensitive          = true;
            iniParserConfig.CommentRegex             = new System.Text.RegularExpressions.Regex(@"^;.*");

            // Be very generous, allow everything:
            iniParserConfig.AllowDuplicateKeys      = true;
            iniParserConfig.AllowDuplicateSections  = true;
            iniParserConfig.AllowKeysWithoutSection = true;
            iniParserConfig.OverrideDuplicateKeys   = true;

            // Initialize INI parser
            this.iniParser = new FileIniDataParser(new IniDataParser(iniParserConfig));
        }
Example #10
0
        public IniDataParser(IniParserConfiguration parserConfiguration)
        {
            bool flag = parserConfiguration == null;

            if (flag)
            {
                throw new ArgumentNullException("parserConfiguration");
            }
            this.Configuration    = parserConfiguration;
            this._errorExceptions = new List <Exception>();
        }
Example #11
0
        private void LoadIni()
        {
            IniParserConfiguration iniParserConfig = new IniParserConfiguration();

            iniParserConfig.AllowCreateSectionsOnFly = true;
            iniParserConfig.AssigmentSpacer          = "";
            iniParserConfig.CaseInsensitive          = true;
            iniParserConfig.CommentRegex             = new System.Text.RegularExpressions.Regex(@";.*");

            this.iniParser = new FileIniDataParser(new IniDataParser(iniParserConfig));
            config         = this.iniParser.ReadFile(iniPath, new UTF8Encoding(false));
        }
Example #12
0
        private void SetScreenSizeInPrefs()
        {
            if (SystemParameters == null)
            {
                throw new ArgumentNullException("System Parameters was null.  Cannot set screen size prefs");
            }
            var config = new IniParserConfiguration {
                AllowDuplicateKeys = true, AllowDuplicateSections = true
            };

            foreach (var file in OutputFolder.Combine("profiles").EnumerateFiles()
                     .Where(f => ((string)f.FileName).EndsWith("refs.ini")))
            {
                try
                {
                    var  parser   = new FileIniDataParser(new IniDataParser(config));
                    var  data     = parser.ReadFile((string)file);
                    bool modified = false;
                    if (data.Sections["Display"] != null)
                    {
                        if (data.Sections["Display"]["iSize W"] != null && data.Sections["Display"]["iSize H"] != null)
                        {
                            data.Sections["Display"]["iSize W"] =
                                SystemParameters.ScreenWidth.ToString(CultureInfo.CurrentCulture);
                            data.Sections["Display"]["iSize H"] =
                                SystemParameters.ScreenHeight.ToString(CultureInfo.CurrentCulture);
                            modified = true;
                        }
                    }
                    if (data.Sections["MEMORY"] != null)
                    {
                        if (data.Sections["MEMORY"]["VideoMemorySizeMb"] != null)
                        {
                            data.Sections["MEMORY"]["VideoMemorySizeMb"] =
                                SystemParameters.EnbLEVRAMSize.ToString(CultureInfo.CurrentCulture);
                            modified = true;
                        }
                    }

                    if (modified)
                    {
                        parser.WriteFile((string)file, data);
                    }
                }
                catch (Exception)
                {
                    Utils.Log($"Skipping screen size remap for {file} due to parse error.");
                }
            }
        }
        public void parse_case_insensitive_names_ini_file()
        {
            string iniData = @"[TestSection]
            KEY1 = value1
            KEY2 = value2";

            var config = new IniParserConfiguration();

            config.CaseInsensitive = true;
            var data = new IniDataParser(config).Parse(iniData);

            Assert.That(data["testsection"]["key1"], Is.EqualTo("value1"));
            Assert.That(data["testSection"]["Key2"], Is.EqualTo("value2"));
        }
Example #14
0
        public void simple_configuration()
        {
            var iniStr = @"[section1]
#data = 1
;data = 2";

            var config = new IniParserConfiguration();

            config.CommentString = "#";

            _parser = new IniDataParser(config);

            var iniData = _parser.Parse(iniStr);

            Assert.That(iniData["section1"][";data"], Is.EqualTo("2"));
        }
Example #15
0
        public bool ReadFromFile()
        {
            IniData configData = null;

            // Setup the config file parser.
            IniParserConfiguration parserConfig = new IniParserConfiguration();

            parserConfig.SkipInvalidLines       = false;
            parserConfig.ThrowExceptionsOnError = true;

            IniDataParser     parser     = new IniDataParser(parserConfig);
            FileIniDataParser fileParser = new FileIniDataParser(parser);

            // Check if the file exists, if not return true as if we parsed it.
            if (File.Exists(this.ConfigFilePath) == false)
            {
                return(true);
            }

            try
            {
                // Try to parse the file.
                configData = fileParser.ReadFile(this.ConfigFilePath);
            }
            catch (Exception e)
            {
                // Failed to parse the file, it must be invalid in some way.
                return(false);
            }

            // Read all the values from the ini file.
            this.DebugLog         = GetConfigBool(configData, GameSettingsSection, DebugLogKey);
            this.RecursiveGrenade = GetConfigBool(configData, GameSettingsSection, RecursiveGrenadeKey);

            this.DynamicGraphicsMemory = GetConfigBool(configData, GraphicsSettingsSection, DynamicGraphicsMemoryKey);

            // Parse the mod load order.
            if (configData.Sections.ContainsSection(ModLoadOrderSection) == true)
            {
                // Get the load order based on the order of the keys.
                this.ModFileLoadOrder = configData[ModLoadOrderSection].Select(k => k.Value).ToArray();
            }

            // Successfully parsed the ini file.
            return(true);
        }
Example #16
0
        public void check_cloning()
        {
            IniParserConfiguration config1 = new IniParserConfiguration();

            config1.AllowDuplicateKeys = true;
            config1.CommentString      = "/";

            Assert.That(config1.AllowDuplicateKeys, Is.True);
            Assert.That(config1.CommentString, Is.EqualTo("/"));

            IniParserConfiguration config2 = config1.Clone();

            Assert.That(config2.AllowDuplicateKeys, Is.True);
            Assert.That(config2.CommentString, Is.EqualTo("/"));

            config1.CommentString = "#";
            Assert.That(config2.CommentString, Is.EqualTo("/"));
        }
Example #17
0
        private void SetScreenSizeInPrefs()
        {
            var config = new IniParserConfiguration {
                AllowDuplicateKeys = true, AllowDuplicateSections = true
            };

            foreach (var file in Directory.EnumerateFiles(Path.Combine(OutputFolder, "profiles"), "*refs.ini",
                                                          DirectoryEnumerationOptions.Recursive))
            {
                var parser = new FileIniDataParser(new IniDataParser(config));
                var data   = parser.ReadFile(file);
                if (data.Sections["Display"]["iSize W"] != null && data.Sections["Display"]["iSize H"] != null)
                {
                    data.Sections["Display"]["iSize W"] = SystemParameters.PrimaryScreenWidth.ToString();
                    data.Sections["Display"]["iSize H"] = SystemParameters.PrimaryScreenHeight.ToString();
                }

                parser.WriteFile(file, data);
            }
        }
        private Encoding encoding = new UTF8Encoding(false); // UTF-8 without BOM
        //private static readonly System.Globalization.CultureInfo en_US = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

        public IniFile(String path, String defaultPath = null)
        {
            this.FilePath    = path;
            this.FileName    = Path.GetFileName(path);
            this.DefaultPath = defaultPath;

            // Configuring INI parser
            IniParserConfiguration iniParserConfig = new IniParserConfiguration();

            iniParserConfig.AllowCreateSectionsOnFly = true;
            iniParserConfig.AssigmentSpacer          = "";
            iniParserConfig.CaseInsensitive          = true;
            iniParserConfig.CommentRegex             = new System.Text.RegularExpressions.Regex(@"^;.*");

            // Be very generous, allow everything:
            iniParserConfig.AllowDuplicateKeys      = true;
            iniParserConfig.AllowDuplicateSections  = true;
            iniParserConfig.AllowKeysWithoutSection = true;
            iniParserConfig.OverrideDuplicateKeys   = true;

            // Initialize INI parser
            this.iniParser = new FileIniDataParser(new IniDataParser(iniParserConfig));
        }
Example #19
0
 public DefaultIniDataFormatter(IniParserConfiguration configuration)
 {
     Configuration = configuration ?? throw new ArgumentNullException("configuration");
 }
        protected override Dictionary <string, IEnumerable <Package> > GetModules()
        {
            object modules_lock = new object();
            Dictionary <string, IEnumerable <Package> > modules = new Dictionary <string, IEnumerable <Package> >();
            List <AuditFileInfo>   core_module_files            = this.CoreModulesDirectory.GetFiles("*.info").Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).Select(f => f as AuditFileInfo).ToList();
            List <AuditFileInfo>   contrib_module_files         = this.ContribModulesDirectory.GetFiles("*.info")?.Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).Select(f => f as AuditFileInfo).ToList();
            List <Package>         core_modules    = new List <Package>(core_module_files.Count + 1);
            List <Package>         contrib_modules = contrib_module_files != null ? new List <Package>(contrib_module_files.Count) : new List <Package>(0);
            List <Package>         all_modules     = new List <Package>(core_module_files.Count + 1);
            IniParserConfiguration ini_parser_cfg  = new IniParserConfiguration();

            ini_parser_cfg.CommentString         = ";";
            ini_parser_cfg.AllowDuplicateKeys    = true;
            ini_parser_cfg.OverrideDuplicateKeys = true;
            this.AuditEnvironment.Status("Reading Drupal 7 core module files from environment...", core_module_files.Count);
            Dictionary <AuditFileInfo, string> core_modules_files_text = this.CoreModulesDirectory.ReadFilesAsText(core_module_files);

            Parallel.ForEach(core_modules_files_text, new ParallelOptions()
            {
                MaxDegreeOfParallelism = 20
            }, _kv =>
            {
                IniDataParser ini_parser = new IniDataParser(ini_parser_cfg);
                IniData data             = ini_parser.Parse(_kv.Value);
                foreach (KeyData d in data.Global)
                {
                    if (d.Value.First() == '"')
                    {
                        d.Value = d.Value.Remove(0, 1);
                    }
                    if (d.Value.Last() == '"')
                    {
                        d.Value = d.Value.Remove(d.Value.Length - 1, 1);
                    }
                }
                DrupalModuleInfo m = new DrupalModuleInfo
                {
                    Core        = data.Global["core"],
                    Name        = data.Global["name"],
                    Description = data.Global["description"],
                    Package     = data.Global["package"],
                    Version     = data.Global["version"],
                    Project     = data.Global["project"]
                };
                lock (modules_lock)
                {
                    core_modules.Add(new Package("drupal", m.Name, m.Version == "VERSION" ? m.Core : m.Version, "", string.Empty));
                }
            });
            core_modules.Add(new Package("drupal", "drupal_core", core_modules.First().Version));
            modules.Add("core", core_modules);
            all_modules.AddRange(core_modules);
            if (contrib_module_files != null)
            {
                this.AuditEnvironment.Status("Reading contrib module files from environment...", core_module_files.Count);
                Dictionary <AuditFileInfo, string> contrib_modules_files_text = this.ContribModulesDirectory.ReadFilesAsText(contrib_module_files);
                Parallel.ForEach(contrib_modules_files_text, new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 20
                }, _kv =>
                {
                    IniDataParser ini_parser = new IniDataParser(ini_parser_cfg);
                    IniData data             = ini_parser.Parse(_kv.Value);
                    foreach (KeyData d in data.Global)
                    {
                        if (d.Value.First() == '"')
                        {
                            d.Value = d.Value.Remove(0, 1);
                        }
                        if (d.Value.Last() == '"')
                        {
                            d.Value = d.Value.Remove(d.Value.Length - 1, 1);
                        }
                    }
                    DrupalModuleInfo m = new DrupalModuleInfo
                    {
                        Core        = data.Global["core"],
                        Name        = data.Global["name"],
                        Description = data.Global["description"],
                        Package     = data.Global["package"],
                        Version     = data.Global["version"],
                        Project     = data.Global["project"]
                    };
                    lock (modules_lock)
                    {
                        contrib_modules.Add(new Package("drupal", m.Name, m.Version == "VERSION" ? m.Core : m.Version, "", string.Empty));
                    }
                });
            }
            if (contrib_modules.Count > 0)
            {
                modules.Add("contrib", contrib_modules);
                all_modules.AddRange(contrib_modules);
            }
            List <Package> sites_all_contrib_modules = null;

            if (this.SitesAllModulesDirectory != null)
            {
                List <AuditFileInfo> sites_all_contrib_modules_files = this.SitesAllModulesDirectory.GetFiles("*.info")?.Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).Select(f => f as AuditFileInfo).ToList();
                if (sites_all_contrib_modules_files != null && sites_all_contrib_modules_files.Count > 0)
                {
                    Dictionary <AuditFileInfo, string> sites_all_contrib_modules_files_text = this.SitesAllModulesDirectory.ReadFilesAsText(sites_all_contrib_modules_files);
                    sites_all_contrib_modules = new List <Package>(sites_all_contrib_modules_files.Count);
                    Parallel.ForEach(sites_all_contrib_modules_files_text, new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = 20
                    }, _kv =>
                    {
                        IniDataParser ini_parser = new IniDataParser(ini_parser_cfg);
                        IniData data             = ini_parser.Parse(_kv.Value);
                        foreach (KeyData d in data.Global)
                        {
                            if (d.Value.First() == '"')
                            {
                                d.Value = d.Value.Remove(0, 1);
                            }
                            if (d.Value.Last() == '"')
                            {
                                d.Value = d.Value.Remove(d.Value.Length - 1, 1);
                            }
                        }
                        DrupalModuleInfo m = new DrupalModuleInfo
                        {
                            Core        = data.Global["core"],
                            Name        = data.Global["name"],
                            Description = data.Global["description"],
                            Package     = data.Global["package"],
                            Version     = data.Global["version"],
                        };
                        lock (modules_lock)
                        {
                            sites_all_contrib_modules.Add(new Package("drupal", m.Name, m.Version == "VERSION" ? m.Core : m.Version, "", string.Empty));
                        }
                    });
                }
            }
            if (sites_all_contrib_modules != null && sites_all_contrib_modules.Count > 0)
            {
                modules.Add("sites_all_contrib", sites_all_contrib_modules);
                all_modules.AddRange(sites_all_contrib_modules);
            }
            modules.Add("all", all_modules);
            this.ModulePackages           = modules;
            this.ModulesInitialised       = true;
            this.PackageSourceInitialized = true; //Packages are read from modules.
            return(this.ModulePackages);
        }
 /// <summary>
 ///     Ctor
 /// </summary>
 /// <param name="parserConfiguration">
 ///     Parser's <see cref="IniParserConfiguration"/> instance.
 /// </param>
 public IniStringParser(IniParserConfiguration parserConfiguration)
 {
     Configuration = parserConfiguration ?? throw new ArgumentNullException("parserConfiguration");
 }
Example #22
0
 /// <summary>
 ///     Ctor
 /// </summary>
 public IniDataParser()
 {
     Scheme           = new IniScheme();
     Configuration    = new IniParserConfiguration();
     _errorExceptions = new List <Exception>();
 }