[gnome-games] steam: Add SteamUriSource



commit c4e8dd9d5610dd0a889b699cf8c74090763ea556
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Wed May 3 23:29:43 2017 +0200

    steam: Add SteamUriSource
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781334

 plugins/steam/src/Makefile.am           |    1 +
 plugins/steam/src/steam-uri-source.vala |   57 +++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/plugins/steam/src/Makefile.am b/plugins/steam/src/Makefile.am
index 172531d..2d50867 100644
--- a/plugins/steam/src/Makefile.am
+++ b/plugins/steam/src/Makefile.am
@@ -14,6 +14,7 @@ libgames_steam_plugin_la_SOURCES = \
        steam-registry.vala \
        steam-title.vala \
        steam-uri-iterator.vala \
+       steam-uri-source.vala \
        $(NULL)
 
 libgames_steam_plugin_la_VALAFLAGS = \
diff --git a/plugins/steam/src/steam-uri-source.vala b/plugins/steam/src/steam-uri-source.vala
new file mode 100644
index 0000000..209c76d
--- /dev/null
+++ b/plugins/steam/src/steam-uri-source.vala
@@ -0,0 +1,57 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.SteamUriSource : Object, UriSource {
+       // From the home directory.
+       private const string REGISTRY_PATH = "/.steam/registry.vdf";
+       // From the home directory.
+       private const string DEFAULT_INSTALL_DIR_SYMLINK = "/.steam/steam";
+       // From an install directory.
+       private const string[] STEAMAPPS_DIRS = { "/SteamApps", "/steamapps" };
+       // From the default SteamApp directory.
+       private const string LIBRARY_DIRS_REG = "/libraryfolders.vdf";
+
+       private const string[] INSTALL_PATH_REGISTRY_PATH =
+               { "Registry", "HKLM", "Software", "Valve", "Steam", "InstallPath" };
+
+       private string[] directories;
+
+       public SteamUriSource () throws Error {
+               directories = {};
+
+               // Steam's installation path can be found in its registry.
+               var home = Environment.get_home_dir ();
+               var registry_path = home + REGISTRY_PATH;
+               var registry = new SteamRegistry (registry_path);
+               var install_path = registry.get_data (INSTALL_PATH_REGISTRY_PATH);
+
+               add_library (home + DEFAULT_INSTALL_DIR_SYMLINK);
+               add_library (install_path);
+
+               // `/LibraryFolders/$NUMBER` entries in the libraryfolders.vdf registry
+               // file are library directories.
+               foreach (var steamapps_dir in STEAMAPPS_DIRS) {
+                       var install_steamapps_dir = install_path + steamapps_dir;
+                       var file = File.new_for_path (install_steamapps_dir);
+                       if (!file.query_exists ())
+                               continue;
+
+                       var library_reg_path = install_steamapps_dir + LIBRARY_DIRS_REG;
+                       var library_reg = new SteamRegistry (library_reg_path);
+                       foreach (var child in library_reg.get_children ({ "LibraryFolders" }))
+                               if (/^\d+$/.match (child))
+                                       add_library (library_reg.get_data ({ "LibraryFolders", child }));
+               }
+       }
+
+       public UriIterator iterator () {
+               return new SteamUriIterator (directories);
+       }
+
+       private void add_library (string library) {
+               foreach (var steamapps_dir in STEAMAPPS_DIRS) {
+                       var library_steamapps_dir = library + steamapps_dir;
+                       if (FileUtils.test (library_steamapps_dir, FileTest.EXISTS))
+                               directories += library_steamapps_dir;
+               }
+       }
+}


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