public void LoadDeviceConfiguration(IDeviceRegistry deviceRegistry)
        {
            var config = new IniDataParser().Parse(File.ReadAllText(kDeviceConfigurationFileName));

            foreach (var section in config.Sections)
            {
                var type   = section.Keys["type"];
                var device = deviceLoadersByType[type](section);
                deviceRegistry.AddDevice(section.SectionName, device);
            }
        }
Пример #2
0
        private static async Task DetectMegaAsync(List <CloudProvider> providerList)
        {
            try
            {
                //var sidstring = System.Security.Principal.WindowsIdentity.GetCurrent().User.ToString();
                //using var sid = AdvApi32.ConvertStringSidToSid(sidstring);
                var infoPath   = @"Mega Limited\MEGAsync\MEGAsync.cfg";
                var configPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, infoPath);
                var configFile = await StorageFile.GetFileFromPathAsync(configPath);

                var    parser        = new IniDataParser();
                var    data          = parser.Parse(await FileIO.ReadTextAsync(configFile));
                byte[] fixedSeed     = Encoding.UTF8.GetBytes("$JY/X?o=h·&%v/M(");
                byte[] localKey      = GetLocalStorageKey(); /*sid.GetBinaryForm()*/
                byte[] xLocalKey     = XOR(fixedSeed, localKey);
                var    sh            = SHA1.Create();
                byte[] hLocalKey     = sh.ComputeHash(xLocalKey);
                var    encryptionKey = hLocalKey;

                var    mainSection  = data.Sections.First(s => s.SectionName == "General");
                string currentGroup = "";

                var currentAccountKey       = Hash("currentAccount", currentGroup, encryptionKey);
                var currentAccountStr       = mainSection.Keys.First(s => s.KeyName == currentAccountKey);
                var currentAccountDecrypted = Decrypt(currentAccountKey, currentAccountStr.Value.Replace("\"", ""), currentGroup);

                var currentAccountSectionKey = Hash(currentAccountDecrypted, "", encryptionKey);
                var currentAccountSection    = data.Sections.First(s => s.SectionName == currentAccountSectionKey);

                var syncKey    = Hash("Syncs", currentAccountSectionKey, encryptionKey);
                var syncGroups = currentAccountSection.Keys.Where(s => s.KeyName.StartsWith(syncKey)).Select(x => x.KeyName.Split('\\')[1]).Distinct();
                foreach (var sync in syncGroups)
                {
                    currentGroup = string.Join("/", currentAccountSectionKey, syncKey, sync);
                    var syncNameKey          = Hash("syncName", currentGroup, encryptionKey);
                    var syncNameStr          = currentAccountSection.Keys.First(s => s.KeyName == string.Join("\\", syncKey, sync, syncNameKey));
                    var syncNameDecrypted    = Decrypt(syncNameKey, syncNameStr.Value.Replace("\"", ""), currentGroup);
                    var localFolderKey       = Hash("localFolder", currentGroup, encryptionKey);
                    var localFolderStr       = currentAccountSection.Keys.First(s => s.KeyName == string.Join("\\", syncKey, sync, localFolderKey));
                    var localFolderDecrypted = Decrypt(localFolderKey, localFolderStr.Value.Replace("\"", ""), currentGroup);
                    providerList.Add(new CloudProvider()
                    {
                        ID         = KnownCloudProviders.Mega,
                        SyncFolder = localFolderDecrypted,
                        Name       = $"MEGA ({syncNameDecrypted})"
                    });
                }
            }
            catch
            {
                // Not detected
            }
        }
Пример #3
0
        public void loadWorldConfig(string world_ini)
        {
            var parser = new IniDataParser();

            parser.Configuration.AllowDuplicateKeys     = true;
            parser.Configuration.OverrideDuplicateKeys  = true;
            parser.Configuration.CaseInsensitive        = true;
            parser.Configuration.AllowDuplicateSections = true;
            parser.Configuration.SkipInvalidLines       = true;
            this.INIData = parser.Parse(world_ini);
            this.Info    = new KnyttWorldInfo(INIData["World"]);
        }
Пример #4
0
        public void allow_duplicated_keys_in_section()
        {
            var parser = new IniDataParser();

            parser.Configuration.AllowDuplicateKeys = true;

            IniData data = parser.Parse(ini_duplicated_keys);

            Assert.That(data, Is.Not.Null);
            Assert.That(data.Sections.GetSectionData("seccion1").Keys.Count, Is.EqualTo(1));
            Assert.That(data.Sections.GetSectionData("seccion1").Keys["value1"], Is.EqualTo("10.6"));
        }
        public OsuProcessor(int categoryId, DirectoryInfo tempDirectory)
        {
            this.categoryId = categoryId;
            this.dataParser = new IniDataParser(new IniParserConfiguration
            {
                SkipInvalidLines      = true,
                KeyValueAssigmentChar = ':',
                CaseInsensitive       = true
            });

            this.tempDirectory = tempDirectory;
        }
Пример #6
0
        public void allow_tilde_in_sections()
        {
            string data =
                @"[section~subsection]
key=value";
            IniDataParser parser = new IniDataParser();

            IniData parsedData = parser.Parse(data);

            Assert.That(parsedData.Sections.ContainsSection("section~subsection"));
            Assert.That(parsedData.Sections["section~subsection"]["key"], Is.EqualTo("value"));
        }
Пример #7
0
        public void escape_comment_regex_special_characters()
        {
            var iniStr = @"[Section]
                \Backslash Bcomment
                Key=Value";

            var parser = new IniDataParser();

            parser.Configuration.CommentString = @"\";

            parser.Parse(iniStr);
        }
        public void check_data_correctly_parsed()
        {
            var     parser = new IniDataParser();
            IniData data   = parser.Parse(iniFileStr);

            Assert.That(data, Is.Not.Null);

            // Check global section

            Assert.That(data.Global["global key"], Is.EqualTo("global value"));

            // global section is not computed when counting the number of sections in the
            // ini
            Assert.That(data.Sections.Count, Is.EqualTo(2), "Expected two (2) sections");
            var section1 = data.Sections.GetSectionData("section1");

            Assert.That(section1, Is.Not.Null);
            Assert.That(section1.SectionName, Is.EqualTo("section1"));
            Assert.That(section1.LeadingComments, Is.Not.Empty);
            Assert.That(section1.LeadingComments.Count, Is.EqualTo(1));

            Assert.That(section1.Keys, Is.Not.Null);
            Assert.That(section1.Keys.Count, Is.EqualTo(2));
            Assert.That(section1.Keys.GetKeyData("key 1"), Is.Not.Null);

            // Check keys / values with spaces. Leading & trailing whitespace ignored
            Assert.That(section1.Keys["key 1"], Is.EqualTo("value 1"));


            Assert.That(section1.Keys.GetKeyData("key;2"), Is.Not.Null);
            // Check special characters as part of the key/value name
            Assert.That(section1.Keys["key;2"], Is.EqualTo("va:lu;e.5"));


            //
            var section2 = data.Sections.GetSectionData("section2");

            // Bad section name
            Assert.That(section2, Is.Null);

            // Beware: leading and trailing whitespaces are ignored!
            section2 = data.Sections.GetSectionData("section 2");
            Assert.That(section2, Is.Not.Null);
            Assert.That(section2.SectionName, Is.EqualTo("section 2"));
            Assert.That(section2.LeadingComments, Is.Empty);
            Assert.That(section2.TrailingComments, Is.Empty);
            Assert.That(section2.Comments, Is.Empty);

            // Check comments at the end of the section are parsed and assigned to the section
            Assert.That(section2.Keys.GetKeyData("mykey1").Comments, Is.Not.Empty);
            Assert.That(section2.Keys.GetKeyData("mykey1").Comments.Count, Is.EqualTo(1));
            Assert.That(section2.Keys.GetKeyData("mykey1").Comments[0], Is.EqualTo("comment for myKey1"));
        }
Пример #9
0
        /// <summary>
        /// Set AppVersion of KEngineConfig.txt
        /// </summary>
        /// <param name="appVersion"></param>
        //public static void SaveAppVersion(AppVersion appVersion)
        //{
        //    EnsureConfigFile();

        //    SetConfValue(KEngineDefaultConfigs.AppVersion.ToString(), appVersion.ToString());

        //    Log.DoLog("Save AppVersion to KEngineConfig.txt: {0}", appVersion.ToString());
        //}

        /// <summary>
        /// Set KEngineConfig.txt file,  and reload AppEngine's instance of EngineConfigs, (Editor only)
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void SetConfValue(string section, string key, string value)
        {
            //AppEngine.SetConfig(key, value);
            var filePath = "Assets/Resources/AppConfigs.txt";
            var parser   = new IniDataParser();
            var iniData  = parser.Parse(System.IO.File.ReadAllText(filePath));

            iniData.Sections[section][key] = value;

            System.IO.File.WriteAllText(filePath, iniData.ToString());
            Log.Warning("Set: [{0}:{1}] to {2}", section, key, value);
            AssetDatabase.Refresh();
        }
Пример #10
0
        public void allow_quotes_in_sections()
        {
            var parser = new IniDataParser();

            var     iniDataString = @"[W101 0.5"" wc]
key = value
[W103 0.5' wc]
key2 = value2";
            IniData parsedData    = parser.Parse(iniDataString);

            Assert.That(parsedData.Sections["W101 0.5\" wc"], Is.Not.Empty);
            Assert.That(parsedData.Sections["W103 0.5' wc"], Is.Not.Empty);
        }
Пример #11
0
        public void not_reproduced_error_tests()
        {
            string test = "[ExampleSection]\nkey = value;value\n";

            IniDataParser strParser = new IniDataParser();

            IniData data = strParser.Parse(test);

            Assert.That(data.Sections.Count, Is.EqualTo(1));
            Assert.That(data.Sections["ExampleSection"], Is.Not.Null);
            Assert.That(data.Sections["ExampleSection"].Count, Is.EqualTo(1));
            Assert.That(data.Sections["ExampleSection"]["key"], Is.EqualTo("value;value"));
        }
Пример #12
0
        public IniData Config()
        {
            IniDataParser i = new IniDataParser();

            //intern?
            if (Intern())
            {
                TextAsset t = UnityEngine.Resources.Load <TextAsset>(folder.Substring(1) + "/map");
                return(i.Parse(t.text));
            }

            return(i.Parse(File.ReadAllText(folder)));
        }
Пример #13
0
        public async Task DetectAsync(List <CloudProvider> cloudProviders)
        {
            try
            {
                var infoPath   = @"Mega Limited\MEGAsync\MEGAsync.cfg";
                var configPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, infoPath);
                var configFile = await StorageFile.GetFileFromPathAsync(configPath);

                var    parser        = new IniDataParser();
                var    data          = parser.Parse(await FileIO.ReadTextAsync(configFile));
                byte[] fixedSeed     = Encoding.UTF8.GetBytes("$JY/X?o=h·&%v/M(");
                byte[] localKey      = GetLocalStorageKey();
                byte[] xLocalKey     = XOR(fixedSeed, localKey);
                var    sh            = SHA1.Create();
                byte[] encryptionKey = sh.ComputeHash(xLocalKey);

                var    mainSection  = data.Sections.First(s => s.SectionName == "General");
                string currentGroup = "";

                var currentAccountKey       = Hash("currentAccount", currentGroup, encryptionKey);
                var currentAccountStr       = mainSection.Keys.First(s => s.KeyName == currentAccountKey);
                var currentAccountDecrypted = Decrypt(currentAccountKey, currentAccountStr.Value.Replace("\"", ""), currentGroup);

                var currentAccountSectionKey = Hash(currentAccountDecrypted, "", encryptionKey);
                var currentAccountSection    = data.Sections.First(s => s.SectionName == currentAccountSectionKey);

                var syncKey    = Hash("Syncs", currentAccountSectionKey, encryptionKey);
                var syncGroups = currentAccountSection.Keys.Where(s => s.KeyName.StartsWith(syncKey)).Select(x => x.KeyName.Split('\\')[1]).Distinct();
                foreach (var sync in syncGroups)
                {
                    currentGroup = string.Join("/", currentAccountSectionKey, syncKey, sync);
                    var syncNameKey          = Hash("syncName", currentGroup, encryptionKey);
                    var syncNameStr          = currentAccountSection.Keys.First(s => s.KeyName == string.Join("\\", syncKey, sync, syncNameKey));
                    var syncNameDecrypted    = Decrypt(syncNameKey, syncNameStr.Value.Replace("\"", ""), currentGroup);
                    var localFolderKey       = Hash("localFolder", currentGroup, encryptionKey);
                    var localFolderStr       = currentAccountSection.Keys.First(s => s.KeyName == string.Join("\\", syncKey, sync, localFolderKey));
                    var localFolderDecrypted = Decrypt(localFolderKey, localFolderStr.Value.Replace("\"", ""), currentGroup);

                    cloudProviders.Add(new CloudProvider()
                    {
                        ID         = CloudProviders.Mega,
                        Name       = $"MEGA ({syncNameDecrypted})",
                        SyncFolder = localFolderDecrypted
                    });
                }
            }
            catch
            {
                // Not detected
            }
        }
Пример #14
0
        public INIFile(string filename)
        {
            IniDataParser parser = new IniDataParser();

            parser.Configuration.SkipInvalidLines = true;
            try
            {
                IniData = parser.Parse(File.ReadAllText(filename));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void check_ini_writing()
        {
            IniData data = new IniDataParser().Parse(iniFileStr);

            // ini file string with not-needed whitespace trimmed
            var dataAsString = data.ToString();

            // Generates a valid data file
            IniData data2 = new IniDataParser().Parse(dataAsString);


            // check all strings are equal
            Assert.That(dataAsString, Is.EqualTo(data2.ToString()));
        }
Пример #16
0
 /// <summary>
 /// INIFile Constructor.
 /// </summary>
 /// <PARAM name="INIPath"></PARAM>
 public IniFile(string INIPath)
 {
     this.Path = INIPath;
     config.AllowCreateSectionsOnFly = true;
     config.AllowDuplicateKeys       = true;
     config.AllowDuplicateSections   = true;
     config.OverrideDuplicateKeys    = true;
     config.SkipInvalidLines         = true;
     config.ThrowExceptionsOnError   = true;
     config.AllowKeysWithoutSection  = true;
     dataParser = new IniDataParser(config);
     parser     = new FileIniDataParser(dataParser);
     data       = parser.ReadFile(Path);
 }
        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"));
        }
Пример #18
0
        public IniProvider(string directory, string name) : base(directory, name)
        {
            _config.OverrideDuplicateKeys   = true;
            _config.SkipInvalidLines        = true;
            _config.ThrowExceptionsOnError  = true;
            _config.AllowKeysWithoutSection = true;

            _dataParser = new IniDataParser(_config);
            _parser     = new FileIniDataParser(_dataParser);

            _watcher.Filter = "*.ini";

            Load();
        }
Пример #19
0
        public void allow_skiping_unparsable_lines()
        {
            string data =
                @"win] 
key1 = value1";

            var parser = new IniDataParser();

            parser.Configuration.SkipInvalidLines = true;

            IniData newData = parser.Parse(data);

            Assert.That(newData.Global["key1"], Is.EqualTo("value1"));
        }
Пример #20
0
        public void allow_whitespace_in_section_names()
        {
            string data =
                @"[Web Colaboration]
key = value";

            var parser = new IniDataParser();

            IniData iniData = parser.Parse(data);

            Assert.That(iniData.Sections.Count, Is.EqualTo(1));
            Assert.That(iniData.Sections.ContainsSection("Web Colaboration"), Is.True);
            Assert.That(iniData.Sections["Web Colaboration"].ContainsKey("key"), Is.True);
            Assert.That(iniData.Sections["Web Colaboration"]["key"], Is.EqualTo("value"));
        }
Пример #21
0
        public void check_can_parse_special_characters_in_section_names()
        {
            string data =
                @"[{E3729302-74D1-11D3-B43A-00AA00CAD128}]
key = value";

            var parser = new IniDataParser();

            IniData iniData = parser.Parse(data);

            Assert.That(iniData.Sections.Count, Is.EqualTo(1));
            Assert.That(iniData.Sections.ContainsSection("{E3729302-74D1-11D3-B43A-00AA00CAD128}"), Is.True);
            Assert.That(iniData.Sections["{E3729302-74D1-11D3-B43A-00AA00CAD128}"].ContainsKey("key"), Is.True);
            Assert.That(iniData.Sections["{E3729302-74D1-11D3-B43A-00AA00CAD128}"]["key"], Is.EqualTo("value"));
        }
Пример #22
0
        public ConfigData(string customConfigs)
        {
            var parser = new IniDataParser();

            _iniData = parser.Parse(DefaultConfigs);

            if (!string.IsNullOrEmpty(customConfigs))
            {
                if (customConfigs.Trim() != "")
                {
                    var userIniData = parser.Parse(customConfigs);
                    _iniData.Merge(userIniData);
                }
            }
        }
Пример #23
0
        public bool SaveConfigString(string config)
        {
            IniDataParser parser = new IniDataParser();

            try
            {
                parser.Parse(config);
                ConfigString = config;
                return(true);
            }
            catch (ParsingException e)
            {
                return(false);
            }
        }
Пример #24
0
        public void escape_section_regex_special_characters()
        {
            var iniStr = @"\section\
                ;comment
                key=value";

            var parser = new IniDataParser();

            parser.Configuration.SectionStartChar = '\\';
            parser.Configuration.SectionEndChar   = '\\';

            var iniData = parser.Parse(iniStr);

            Assert.That(iniData["section"]["key"], Is.EqualTo("value"));
        }
Пример #25
0
        public void SaveSettings(string fileName)
        {
            if (ParsedConfig == null)
            {
                ParsedConfig = new IniData();
            }
            // Note that this will persist the merged global & user configurations, not the original global config.
            // Since we don't call this method from production code, this is not an issue.
            var parserConfig = CreateIniParserConfiguration();
            var parser       = new IniDataParser(parserConfig);
            var fileParser   = new FileIniDataParser(parser);
            var utf8         = new UTF8Encoding(false);

            fileParser.WriteFile(fileName, ParsedConfig, utf8);
        }
Пример #26
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"));
        }
Пример #27
0
        public void check_can_read_keys_with_no_section()
        {
            string data =
                @"key1=value1
key2=value2
key3=value3";

            var parser = new IniDataParser();

            IniData iniData = parser.Parse(data);

            Assert.That(iniData.Global.Count, Is.EqualTo(3));
            Assert.That(iniData.Global["key1"], Is.EqualTo("value1"));
            Assert.That(iniData.Global["key2"], Is.EqualTo("value2"));
            Assert.That(iniData.Global["key3"], Is.EqualTo("value3"));
        }
Пример #28
0
 public static int GetMountPriority(string dlcDirectory, Mod.MEGame game)
 {
     if (game == Mod.MEGame.ME1)
     {
         int idx = 1 + ME1Directory.OfficialDLC.IndexOf(Path.GetFileName(dlcDirectory));
         if (idx > 0)
         {
             return(idx);
         }
         //is mod
         string autoLoadPath = Path.Combine(dlcDirectory, "AutoLoad.ini");
         var    dlcAutoload  = new IniDataParser().Parse(autoLoadPath);
         return(Convert.ToInt32(dlcAutoload["ME1DLCMOUNT"]["ModMount"])); //TODO: Handle errors if this value is not valid.
     }
     return(MountFile.GetMountPriority(GetMountDLCFromDLCDir(dlcDirectory, game)));
 }
Пример #29
0
        public static void ParseNetUserShareList(SharesList dstList, string shareListIniContent)
        {
            var parser  = new IniDataParser();
            var iniData = parser.Parse(shareListIniContent);

            foreach (var shareIniSection in iniData.Sections)
            {
                string shareName = shareIniSection.SectionName;
                if (!shareIniSection.Keys.ContainsKey("path"))
                {
                    throw new Exception(String.Format("share {0} doesn't have local path specified", shareName));
                }

                string shareLocalPath = shareIniSection.Keys["path"];
                dstList.AddOrReplace(new Share(shareName, new TokenizedLocalPath(shareLocalPath, '/')));
            }
        }
Пример #30
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);
        }