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); } }
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 } }
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"]); }
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; }
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")); }
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")); }
/// <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(); }
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); }
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")); }
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))); }
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 } }
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())); }
/// <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")); }
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(); }
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")); }
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")); }
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")); }
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); } } }
public bool SaveConfigString(string config) { IniDataParser parser = new IniDataParser(); try { parser.Parse(config); ConfigString = config; return(true); } catch (ParsingException e) { return(false); } }
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")); }
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); }
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")); }
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")); }
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))); }
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, '/'))); } }
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); }