[gnome-games] retro: Add RetroOptions



commit 14f540582293124a41bd3e793eb43924c1c69efe
Author: Exalm <exalm7659 gmail com>
Date:   Wed May 2 19:01:16 2018 +0500

    retro: Add RetroOptions
    
    This will be used to load default option values from a file when a
    core starts up.
    
    The file must have a group called 'Options', with the options listed in
    this group.

 src/retro/retro-options.vala | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
---
diff --git a/src/retro/retro-options.vala b/src/retro/retro-options.vala
new file mode 100644
index 0000000..7e48409
--- /dev/null
+++ b/src/retro/retro-options.vala
@@ -0,0 +1,23 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.RetroOptions: Object {
+       public const string OPTIONS_GROUP = "Options";
+
+       private KeyFile keyfile;
+
+       public RetroOptions (string filename) throws Error {
+               keyfile = new KeyFile ();
+               keyfile.load_from_file (filename, KeyFileFlags.NONE);
+       }
+
+       public void apply (Retro.Core core) throws Error {
+               var options_keys = keyfile.get_keys (OPTIONS_GROUP);
+
+               foreach (var key in options_keys) {
+                       var val = keyfile.get_string (OPTIONS_GROUP, key);
+                       var option = core.get_option (key);
+
+                       option.set_value (val);
+               }
+       }
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]