public ChatOptions() { RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", true); m_reg = key.CreateSubKey("TwitchChatClient"); m_iniReader = new IniReader("options.ini"); IniSection section = m_iniReader.GetSectionByName("stream"); if (section == null) throw new InvalidOperationException("Options file missing [Stream] section."); m_stream = section.GetValue("stream"); m_user = section.GetValue("twitchname") ?? section.GetValue("user") ?? section.GetValue("username"); m_oath = section.GetValue("oauth") ?? section.GetValue("pass") ?? section.GetValue("password"); section = m_iniReader.GetSectionByName("highlight"); List<string> highlights = new List<string>(); if (section != null) foreach (string line in section.EnumerateRawStrings()) highlights.Add(DoReplacements(line.ToLower())); m_highlightList = highlights.ToArray(); section = m_iniReader.GetSectionByName("ignore"); if (section != null) m_ignore = new HashSet<string>((from s in section.EnumerateRawStrings() where !string.IsNullOrWhiteSpace(s) select s.ToLower())); }
public FogService() { InitializeComponent(); maxLogSize = 102400; strLogPath = @".\fog.log"; ini = null; this.CanHandlePowerEvent = true; this.CanShutdown = true; }
public void NoSectionsOrKeys() { StringWriter writer = new StringWriter(); writer.WriteLine(""); IniReader reader = new IniReader(new StringReader(writer.ToString())); reader.Read(); Assert.IsTrue(true); }
public void KeyWithNoEquals() { StringWriter writer = new StringWriter(); writer.WriteLine("[Nini]"); writer.WriteLine(" some key "); IniReader reader = new IniReader(new StringReader(writer.ToString())); Assert.IsTrue(reader.Read()); Assert.IsTrue(reader.Read()); }
public void NoEndingQuote() { StringWriter writer = new StringWriter(); writer.WriteLine("[Nini]"); writer.WriteLine(" some key = \" something "); IniReader reader = new IniReader(new StringReader(writer.ToString())); Assert.IsTrue(reader.Read()); Assert.IsTrue(reader.Read()); }
public void Load_HandlesMultipleEqualsOnDataLines() { var contents = "[Header]\nTestdata=aaaa=something #some other comment\n\n#this is a comment line\nTest2=bbbb"; CreateTestFileWithData(contents); var reader = new IniReader(FullPath); var result = reader.Load(); Assert.IsTrue(result); }
public void Load_HandlesCommentsOnHeaderLines() { var contents = "[Header]#some header comment\nTestdata=aaaa\n\n#this is a comment line\nTest2=bbbb"; CreateTestFileWithData(contents); var reader = new IniReader(FullPath); var result = reader.Load(); Assert.IsTrue(result); }
public void Load_HandlesEmptyLines() { var contents = "[Header]\nTestdata=aaaa\n\nTest2=bbbb"; CreateTestFileWithData(contents); var reader = new IniReader(FullPath); var result = reader.Load(); Assert.IsTrue(result); }
public void SectionWithNoEndBracket() { Assert.Throws <IniException>(() => { var writer = new StringWriter(); writer.WriteLine("[Nini"); writer.WriteLine(""); var reader = new IniReader(new StringReader(writer.ToString())); Assert.IsTrue(reader.Read()); }); }
/// <summary> /// Loads all settings from the specified reader and replaces all present sections. /// </summary> /// <param name="reader">The reader to obtain the config from.</param> public void Load(IniReader reader) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } foreach (var section in reader.GetSectionNames()) { data[section] = new List <string>(reader.ReadSection(section, false)); } }
public static string GetTrigramFromPa() { // default values string paIniPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ProgressAssist", "pa.ini"); if (File.Exists(paIniPath)) { IniReader ini = new IniReader(paIniPath); return(ini.GetValue("Trigram", "")); } return(""); }
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")); } }
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")); } }
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")); } }
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")); } }
/// <summary> /// Loads control bindings from a specified path. /// </summary> /// <param name="filename">The path to load from. Note: This does NOT automatically use Game.PathTo()</param> public void LoadConfiguration(String filename) { using (FileStream fs = new FileStream(filename, FileMode.Open)) { using (IniReader r = new IniReader(fs)) { while (true) { if (r.Type != IniType.Section) { if (!r.MoveToNextSection()) { break; } } String[] parts = r.Name.Split(' '); if (parts[0] == "KeyBindings") { if (parts.Length > 1) { CommandControls cs = Command.commands.GetChild(parts[1], true); cs.ReadIni(r); } else { Command.commands.ReadIni(r); } } /*else if (parts[0] == "MouseButtons") * { * }*/ else if (parts[0] == "WindowEvents") { while (r.Read()) { if (r.Type == IniType.Section) { break; } if (r.Type == IniType.Key) { winEvents[r.Name] = r.Value; } } } else { r.MoveToNextSection(); } } } } }
public static bool readARGB(IniReader reader, string section, string name, out ARGB color) { color = ARGB.Transparent; string value = ""; if (reader.GetValue(section, name, ref value)) { color = ARGB.FromString(value); return(true); } return(false); }
public void NoEndOfLineKeyNoValue() { StringWriter writer = new StringWriter(); writer.WriteLine("[Nini Thing]"); writer.Write(" somekey = "); IniReader reader = new IniReader(new StringReader(writer.ToString())); reader.Read(); Assert.IsTrue(true); }
/// <summary> /// Load control bindings from an arbitrary stream. /// If there are already bindings, the new ones will be added. /// New bindings overwrite old bindings. /// </summary> /// <param name="file">The source of the INI data</param> public void LoadConfiguration(Stream file) { using (IniReader r = new IniReader(file)) { while (true) { if (r.Type != IniType.Section) { if (!r.MoveToNextSection()) { break; } } String[] parts = r.Name.Split(' '); if (parts[0] == "KeyBindings") { if (parts.Length > 1) { ControlState cs = rootcstate.GetChild(parts[1], true); cs.ReadIni(r); } else { rootcstate.ReadIni(r); } } /*else if (parts[0] == "MouseButtons") * { * }*/ else if (parts[0] == "WindowEvents") { while (r.Read()) { if (r.Type == IniType.Section) { break; } if (r.Type == IniType.Key) { winEvents[r.Name] = r.Value; } } } else { r.MoveToNextSection(); } } } }
public void ConsumeAllKeyText() { StringWriter writer = new StringWriter(); writer.WriteLine("email = \"John Smith\"; <*****@*****.**>"); IniReader reader = new IniReader(new StringReader(writer.ToString())); reader.ConsumeAllKeyText = true; Assert.IsTrue(reader.Read()); Assert.AreEqual("email", reader.Name); Assert.AreEqual("\"John Smith\"; <*****@*****.**>", reader.Value); }
public void NoEndingQuote() { Assert.Throws <IniException>(() => { var writer = new StringWriter(); writer.WriteLine("[Nini]"); writer.WriteLine(" some key = \" something "); var reader = new IniReader(new StringReader(writer.ToString())); Assert.IsTrue(reader.Read()); Assert.IsTrue(reader.Read()); }); }
public void IgnoreComments() { StringWriter writer = new StringWriter(); writer.WriteLine("[Nini]"); writer.WriteLine(" some key = something ; my comment 1"); IniReader reader = new IniReader(new StringReader(writer.ToString())); Assert.IsTrue(reader.Read()); reader.IgnoreComments = true; Assert.IsTrue(reader.Read()); Assert.AreEqual(null, reader.Comment); }
public void KeyWithNoEquals() { Assert.Throws <IniException>(() => { var writer = new StringWriter(); writer.WriteLine("[Nini]"); writer.WriteLine(" some key "); var reader = new IniReader(new StringReader(writer.ToString())); Assert.IsTrue(reader.Read()); Assert.IsTrue(reader.Read()); }); }
public void Load_CreatesDirectoryAndFile_IfTheyDoNotExist_AndReturnsFalse() { var reader = new IniReader(FullPath); Assert.IsFalse(Directory.Exists(TestDirectory)); Assert.IsFalse(File.Exists(FullPath)); var result = reader.Load(); Assert.IsFalse(result); Assert.IsTrue(Directory.Exists(TestDirectory)); Assert.IsTrue(File.Exists(FullPath)); }
public void LoadConfigItem(IniReader ini, ConfigItem it) { string Val = ini.IniReadValue(it.Section, it.Key); if (string.IsNullOrEmpty(Val)) { SetVariable(it.Variable, it.Default); } else { SetVariable(it.Variable, ini.IniReadValue(it.Section, it.Key)); } }
public string GetDrive() { string INIFlie = "C:\\Windows\\eBrochure.ini" ; IniReader ini = new IniReader(INIFlie); ini.Section = "DbSetting"; if (ini.ReadString("Drive") != "") { return ini.ReadString("Drive"); } else { return "D"; } }
public void Open_FileWithComments() { // Arrange IniFile file; StringBuilder fileText = new StringBuilder(); using (StringWriter stringWriter = new StringWriter(fileText)) { stringWriter.WriteLine("; Healthy, but full of sugar."); stringWriter.WriteLine("[Fruit]"); stringWriter.WriteLine("apple=red"); stringWriter.WriteLine("orange=orange"); stringWriter.WriteLine(";Why isn't it called a yellow?"); stringWriter.WriteLine(";Probably because that would be weird."); stringWriter.WriteLine("banana=yellow"); stringWriter.WriteLine(); stringWriter.WriteLine("; Key to a balanced lifestyle."); stringWriter.WriteLine("[Veggie]"); stringWriter.WriteLine(";Is it really a vegetable though?"); stringWriter.WriteLine("tomato=red"); stringWriter.WriteLine("zucchini=green"); stringWriter.WriteLine("cucumber=green"); } // Act using (StringReader stringReader = new StringReader(fileText.ToString())) { file = IniReader.Open(stringReader); } // Assert Assert.IsNotNull(file["Fruit"]); Assert.AreEqual("red", file["Fruit"]["apple"]); Assert.AreEqual("orange", file["Fruit"]["orange"]); Assert.AreEqual("yellow", file["Fruit"]["banana"]); Assert.IsNotNull(file["Veggie"]); Assert.AreEqual("red", file["Veggie"]["tomato"]); Assert.AreEqual("green", file["Veggie"]["zucchini"]); Assert.AreEqual("green", file["Veggie"]["cucumber"]); Assert.AreEqual(1, file["Fruit"].Comments.Count); Assert.AreEqual(2, file["Fruit"].KeyValues["banana"].Comments.Count); Assert.AreEqual(1, file["Veggie"].Comments.Count); Assert.AreEqual(1, file["Veggie"].KeyValues["tomato"].Comments.Count); Assert.AreEqual("Healthy, but full of sugar.", file["Fruit"].Comments[0]); Assert.AreEqual("Why isn't it called a yellow?", file["Fruit"].KeyValues["banana"].Comments[0]); Assert.AreEqual("Probably because that would be weird.", file["Fruit"].KeyValues["banana"].Comments[1]); Assert.AreEqual("Key to a balanced lifestyle.", file["Veggie"].Comments[0]); Assert.AreEqual("Is it really a vegetable though?", file["Veggie"].KeyValues["tomato"].Comments[0]); }
public void standardFile_conformationDetection_test1() { var testfile = @"\\protoapps\UserData\Slysz\Standard_Testing\LCMSFeatureFinder\UIMF\Parameter_Files\FF_IMS_UseHardCodedFilters_NoFlags_20ppm_Min3Pts_4MaxLCGap_NoDaCorr_ConfDtn_2011-03-21.ini"; var iniReader = new IniReader(testfile); iniReader.CreateSettings(); var isosReader = new IsosReader(Settings.InputFileName, Settings.OutputDirectory); var controller = new LCIMSMSFeatureFinderController(isosReader); controller.Execute(); }
private void LoadConfig() { IniReader config = IniReader.FromLocation(RootLocation.AllUserConfig); this.LogInfo("Loading {0}", config); imscpConfig = config.ReadStruct <ImscpConfig>("Imscp", true); if (imscpConfig.Hostname == null || imscpConfig.Hostname.EndsWith(".")) { throw new Exception(string.Format("Invalid hostname {0}", imscpConfig.Hostname)); } foreach (string section in config.ReadSection("InternetX", true)) { this.LogDebug("Loading InternetX account <cyan>{0}", section); InternetXConfig internetXConfig = config.ReadStruct <InternetXConfig>(section, true); autodnsAccounts.Add(new Autodns(internetXConfig)); this.LogInfo("Loaded InternetX account <green>{0}", section); } var cs = new ConnectionString("mysql", imscpConfig.UserName, imscpConfig.Password, imscpConfig.Database); var storage = new MySqlStorage(cs, DbConnectionOptions.AllowUnsafeConnections); imscp = storage.GetDatabase("imscp", false); imscpDomain = new ReadCachedTable <Domain>(imscp.GetTable <Domain>()); this.LogDebug("Loaded {0}", imscpDomain); imscpSubdomain = new ReadCachedTable <Subdomain>(imscp.GetTable <Subdomain>()); this.LogDebug("Loaded {0}", imscpSubdomain); imscpDomainDns = new ReadCachedTable <DomainDns>(imscp.GetTable <DomainDns>()); this.LogDebug("Loaded {0}", imscpDomainDns); imscpAdmins = new ReadCachedTable <Admin>(imscp.GetTable <Admin>()); this.LogDebug("Loaded {0}", imscpAdmins); #region MAIL string server = config.ReadSetting("MAIL", "SERVER"); m_MailSender = config.ReadSetting("MAIL", "SENDER"); if (string.IsNullOrEmpty(server)) { server = "localhost"; } m_SmtpClient = new SmtpClient(server); string username = config.ReadSetting("MAIL", "USERNAME"); string password = config.ReadSetting("MAIL", "PASSWORD"); if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) { m_SmtpClient.Credentials = new NetworkCredential(username, password); } m_SmtpClient.Send(m_MailSender, "*****@*****.**", "CaveSystems AutoDNS", "AutoDNS restarted."); #endregion }
public void TestTemplateDeserialize() { String iniContent = String.Join(Environment.NewLine, "intItem=1", "stringItem=2", "PairCount=3", "pairs0.Key=K1", "pairs0.Value=V1", "pairs1.Key=K2", "pairs1.Value=V2", "pairs2.Key=K3", "pairs2.Value=V3"); TestClass clz = IniReader.DeserializeString <TestClass>(iniContent); }
static void Main(string[] args) { string filePath = "D:/org.ini"; string fileContent = File.ReadAllText(filePath); var iniData = IniReader.ReadFromString(fileContent); if (iniData != null) { string content = IniWriter.WriteToString(iniData); File.WriteAllText("D:/test.ini", content); } Console.ReadKey(); }
public ModuleManager(PsybotCore ipsycore) { core = ipsycore; iniReader = new IniReader(INI_CONFIG_FILE_NAME); modulesListData = new List <ModuleData>(); modulesDictData = new Dictionary <string, int>(); runCommandsList = new List <string[]>(); runCommandsList.Add(new[] { PsybotCore.CMD_ADMIN }); if (!Directory.Exists(DEFAULT_MODULE_PATH)) { Directory.CreateDirectory(DEFAULT_MODULE_PATH); } }
public void MoveToNextSection() { StringWriter writer = new StringWriter(); writer.WriteLine("; Test"); writer.WriteLine("; Test 1"); writer.WriteLine("[Nini Thing]"); IniReader reader = new IniReader(new StringReader(writer.ToString())); Assert.IsTrue(reader.MoveToNextSection()); Assert.AreEqual(4, reader.LineNumber); Assert.AreEqual(IniType.Section, reader.Type); Assert.IsFalse(reader.MoveToNextSection()); }
public Program(String strData) { IniReader ini = new IniReader( @"./etc/config.ini" ); if ( ini != null && ini.isFileOk() ) { String passkey = ini.readSetting("main", "passkey"); Console.WriteLine(); Console.WriteLine(" Input string: " + strData ); Console.WriteLine(" Passkey: " + passkey); FOGCrypt c = new FOGCrypt(passkey); Console.WriteLine(" Output: " + c.encryptHex(strData)); Console.WriteLine(); } else { Console.WriteLine( "Error: INI File error!" ); } }
private World() //private: don't allow construction of the world using 'new' { _tryLoadItems(); _tryLoadNPCs(); _tryLoadSpells(); _tryLoadClasses(); //initial capacity of 32: most players won't travel between too many maps in a gaming session MapCache = new Dictionary<int, MapFile>(32); DataFiles = new Dictionary<DataFiles, EDFFile>(12); //12 files total m_player = new Player(); m_config = new IniReader(@"config\settings.ini"); if (!m_config.Load()) throw new WorldLoadException("Unable to load the configuration file!"); //client construction: logging for when packets are sent/received m_client = new EOClient(); ((EOClient) m_client).EventSendData += dte => Logger.Log("SEND thread: Processing {4} packet Family={0,-13} Action={1,-8} sz={2,-5} data={3}", Enum.GetName(typeof (PacketFamily), dte.PacketFamily), Enum.GetName(typeof (PacketAction), dte.PacketAction), dte.RawByteData.Length, dte.ByteDataHexString, dte.Type == DataTransferEventArgs.TransferType.Send ? "ENC" : dte.Type == DataTransferEventArgs.TransferType.SendRaw ? "RAW" : "ERR"); ((EOClient) m_client).EventReceiveData += dte => Logger.Log("RECV thread: Processing {0} packet Family={1,-13} Action={2,-8} sz={3,-5} data={4}", dte.PacketHandled ? " handled" : "UNHANDLED", Enum.GetName(typeof (PacketFamily), dte.PacketFamily), Enum.GetName(typeof (PacketAction), dte.PacketAction), dte.RawByteData.Length, dte.ByteDataHexString); ((EOClient) m_client).EventDisconnect += () => { EOGame.Instance.ShowLostConnectionDialog(); EOGame.Instance.ResetWorldElements(); EOGame.Instance.SetInitialGameState(); }; }
private bool parsePScriptROMGEN(string[] cmdArray, bool debugMode) { string CWDTMP = string.Concat (Application.StartupPath, Path.DirectorySeparatorChar + "papilio" + Path.DirectorySeparatorChar + "_tmp" + Path.DirectorySeparatorChar); string CWDPATCH = string.Concat (Application.StartupPath, Path.DirectorySeparatorChar + "papilio" + Path.DirectorySeparatorChar + "patches" + Path.DirectorySeparatorChar, lblDITPath.Text.Replace ("ROMRoot" + Path.DirectorySeparatorChar, "") + Path.DirectorySeparatorChar); string CWD = string.Concat (Application.StartupPath, Path.DirectorySeparatorChar + "papilio" + Path.DirectorySeparatorChar + "tools" + Path.DirectorySeparatorChar); doLog (" - - Processing `romgen` PScript directive"); Console.WriteLine ("parsePScriptROMGEN"); Console.WriteLine (CWDTMP); Console.WriteLine (CWDPATCH); Console.WriteLine (CWD); try { if (cmdArray.Length == 4 || cmdArray.Length == 5) { if (cmdArray.Length == 5) { string ini_path = Path.Combine (CWDPATCH, cmdArray [4]); Console.WriteLine (ini_path); IniReader my = new IniReader (ini_path); string mode = my.GetValue ("DECRYPT_MODE", "MODE"); Console.WriteLine (mode); string values = my.GetValue ("VALUES", "PICKTABLE"); Console.WriteLine (values); string[] pickTableStr = values.Split (new Char []{ ',' }, 32); if (pickTableStr.GetLength (0) != 32) { doLog (" - PICKTABLE wrong lenght: " + ini_path); return false; } for (int a = 0; a < 32; a++) { picktable [a] = Convert.ToInt32 (pickTableStr [a]); } string table_count = my.GetValue ("TABLE_COUNT", "SWAP_XOR_TABLE"); Console.WriteLine (table_count); int table_count_len = Convert.ToInt32 (table_count); if (table_count_len != 6) { doLog (" - TABLE_COUNT wrong: " + ini_path); return false; } for (int i = 1; i <= table_count_len; i++) { string table = my.GetValue ("TABLE_" + i, "SWAP_XOR_TABLE"); Console.WriteLine (table); string[] XorTabletableStr = table.Split (new Char []{ ',' }, 9); if (XorTabletableStr.GetLength (0) != 9) { doLog (" - WAP_XOR_TABLE wrong " + ini_path); return false; } for (int c = 0; c < 9; c++) { string temp = XorTabletableStr [c].Trim ().Replace ("0x", ""); swap_xor_table [i - 1, c] = Convert.ToByte (temp, 16); } } return romGen (CWDTMP + cmdArray [1], CWDTMP + cmdArray [2] + ".mem", cmdArray [3], true); } else { // no -ini: switch return romGen (CWDTMP + cmdArray [1], CWDTMP + cmdArray [2] + ".mem", cmdArray [3], false); } } else { doLog (" - - Aborting - An error occured processing `romgen` PScript directive (args)"); progressLoadFPGA.Refresh (); return false; } } catch (Exception e) { doLog (" - - Aborting - An error occured processing `romgen` PScript directive"); Console.WriteLine (e.ToString ()); } return false; }
public void setINIReader(IniReader i) { this.ini = i; strLogPath = ini.readSetting("fog_service", "logfile"); String strMaxSize = ini.readSetting("fog_service", "maxlogsize"); long output; if (long.TryParse(strMaxSize, out output)) { try { maxLogSize = long.Parse(strMaxSize); } catch (Exception) { } } }
private Boolean loadIniFile() { try { ini = new IniReader(AppDomain.CurrentDomain.BaseDirectory + @"etc/config.ini"); if (ini.isFileOk()) { strLogPath = ini.readSetting("fog_service", "logfile"); String strMaxSize = ini.readSetting("fog_service", "maxlogsize"); long output; if (long.TryParse(strMaxSize, out output)) { try { maxLogSize = long.Parse(strMaxSize); } catch (Exception) { } } return true; } } catch { } return false; }