static void Main() { GKeyFile key_file = new GKeyFile (); key_file.SetComment (null, null, String.Format ("This file was autogenerated by sample.cs on {0}", DateTime.Now)); key_file.SetString ("General", "sKey0", "that's the string value associated to the sKey0"); key_file.SetComment ("General", null, "A comment for the General group"); key_file.SetComment ("General", "sKey0", "A comment for the sKey0 key"); key_file.SetStringList ("Lists", "sList", new string [] {"item0", "item1", "item2", "lastitem"}); key_file.SetBoolean ("SingleValues", "aBool", true); key_file.SetBoolean ("SingleValues", "anotherBool", false); key_file.SetString ("SingleValues", "aString", "this is _not_ a string"); key_file.SetInteger ("SingleValues", "anInt", 42); key_file.SetDouble ("SingleValues", "aDouble", Math.PI); key_file.SetComment ("SingleValues", "aDouble", "Change this at the time the square became the new circle"); key_file.Save ("mysamplefile.ini"); key_file = new GKeyFile ("mysamplefile.ini"); key_file.RemoveComment ("SingleValues", "aDouble"); key_file.SetBooleanList ("Lists", "bools", new bool [] {true, false, false, true}); key_file.SetIntegerList ("Lists", "ints", new int [] {0, 1, 2, -3, -5}); key_file.SetDoubleList ("Lists", "doubles", new double [] {Math.PI, Math.Sqrt (2)}); foreach (string group in key_file.GetGroups()) { Console.WriteLine ("\t"+group); foreach (string key in key_file.GetKeys (group)) Console.WriteLine ("\t\t"+ key); } Console.WriteLine (key_file.HasGroup ("Foo")); Console.WriteLine (key_file.HasGroup ("General")); Console.WriteLine (key_file.HasKey ("General", "sKey0")); Console.WriteLine (key_file.HasKey ("General", "sKey1")); try { key_file.GetValue ("foo", "bar"); } catch (GLib.GException e) { Console.WriteLine (e); } foreach (string val in key_file.GetStringList ("Lists", "sList")) Console.WriteLine (val); foreach (int i in key_file.GetIntegerList ("Lists", "ints")) Console.WriteLine (i); foreach (double d in key_file.GetDoubleList ("Lists", "doubles")) Console.WriteLine (d); foreach (bool b in key_file.GetBooleanList ("Lists", "bools")) Console.WriteLine (b); key_file.Save ("mysamplefile2.ini"); key_file = new GKeyFile ("mysamplefile.ini"); key_file.RemoveGroup ("General"); key_file.Save ("mysamplefile3.ini"); }
public GMpiFileInfo (string mediaPlayerId) { try { mpi_file = new GKeyFile (); mpi_file.ListSeparator = Seperator; mpi_file.LoadFromDirs (String.Format ("{0}.mpi", mediaPlayerId), new string [] {"/usr/share/media-player-info", "/usr/local/share/media-player-info"}, null, Flags.None); } catch (GLib.GException) { Hyena.Log.WarningFormat ("Failed to load media-player-info file for {0}", mediaPlayerId); } LoadProperties (); }
public void GetNonstandardSeperatorStringList() { GKeyFile keyFile = new GKeyFile (test_file_name); string [] expected = new string [] { "one one", "two", "threee", "for" }; keyFile.ListSeparator = ':'; CollectionAssert.AreEqual (expected, keyFile.GetStringList ("Group1", "NonSemicolonStringList")); }
public void Init() { test_file_name = new [] {Environment.CurrentDirectory, "..", "..", "src", TEST_FILE_NAME}.Aggregate (Path.Combine); test_keyfile = new GKeyFile (test_file_name); }