[gnome-games/wip/aplazas/781334-refactor-game-sources: 2/6] steam: Add SteamUriIterator
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/aplazas/781334-refactor-game-sources: 2/6] steam: Add SteamUriIterator
- Date: Sat, 6 May 2017 21:43:08 +0000 (UTC)
commit 196d78699d53a2b909973f10b4876c6026f762f4
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sat May 6 11:22:48 2017 +0200
steam: Add SteamUriIterator
This will be used to iterate through the available Steam game resources.
plugins/steam/src/Makefile.am | 1 +
plugins/steam/src/steam-uri-iterator.vala | 58 +++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/plugins/steam/src/Makefile.am b/plugins/steam/src/Makefile.am
index 29b1556..172531d 100644
--- a/plugins/steam/src/Makefile.am
+++ b/plugins/steam/src/Makefile.am
@@ -13,6 +13,7 @@ libgames_steam_plugin_la_SOURCES = \
steam-plugin.vala \
steam-registry.vala \
steam-title.vala \
+ steam-uri-iterator.vala \
$(NULL)
libgames_steam_plugin_la_VALAFLAGS = \
diff --git a/plugins/steam/src/steam-uri-iterator.vala b/plugins/steam/src/steam-uri-iterator.vala
new file mode 100644
index 0000000..c148bfb
--- /dev/null
+++ b/plugins/steam/src/steam-uri-iterator.vala
@@ -0,0 +1,58 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.SteamUriIterator : Object, UriIterator {
+ private string[] directories;
+ private int directory_index;
+ private Uri? uri;
+
+ internal SteamUriIterator (string[] directories) {
+ this.directories = directories;
+ directory_index = 0;
+ uri = null;
+ }
+
+ public new Uri? get () {
+ return uri;
+ }
+
+ public bool next () {
+ while (directory_index < directories.length) {
+ if (try_next_for_directory (directories[directory_index]))
+ return true;
+
+ directory_index++;
+ }
+
+ return false;
+ }
+
+ private bool try_next_for_directory (string directory) {
+ try {
+ if (next_for_directory (directory))
+ return true;
+ }
+ catch (Error e) {
+ debug (e.message);
+ }
+
+ uri = null;
+
+ return false;
+ }
+
+ private bool next_for_directory (string directory) throws Error {
+ var file = File.new_for_path (directory);
+
+ var enumerator = file.enumerate_children (FileAttribute.STANDARD_NAME, 0);
+
+ var info = enumerator.next_file ();
+ if (info == null)
+ return false;
+
+ var filename = Path.build_filename (directory, info.get_name ());
+ var file_uri = Filename.to_uri (filename);
+ uri = new Uri (@"steam+$file_uri");
+
+ return true;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]