[gnome-games] utils: Add Directory
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] utils: Add Directory
- Date: Fri, 12 Aug 2016 10:29:39 +0000 (UTC)
commit 71b30aa1acc302839265e6a8be64eb3167462946
Author: Adrien Plazas <kekun plazas laposte net>
Date: Fri Aug 12 11:37:24 2016 +0200
utils: Add Directory
This will be used in the next commit to loop through files in a
directory.
https://bugzilla.gnome.org/show_bug.cgi?id=769676
src/Makefile.am | 1 +
src/utils/directory.vala | 29 +++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 17a9c79..be548d6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -112,6 +112,7 @@ gnome_games_SOURCES = \
utils/cue-sheet/cue-sheet-file-node.vala \
utils/cue-sheet/cue-sheet-track-mode.vala \
utils/cue-sheet/cue-sheet-track-node.vala \
+ utils/directory.vala \
utils/filename-title.vala \
utils/fingerprint.vala \
utils/grep.vala \
diff --git a/src/utils/directory.vala b/src/utils/directory.vala
new file mode 100644
index 0000000..583fc79
--- /dev/null
+++ b/src/utils/directory.vala
@@ -0,0 +1,29 @@
+// This file is part of GNOME Games. License: GPLv3
+
+public class Games.Directory : Object {
+ public delegate bool FileInfoTest (FileInfo file_info) throws Error;
+
+ private GLib.File file;
+
+ public Directory (GLib.File file) {
+ this.file = file;
+ }
+
+ public void @foreach (string attributes, FileInfoTest file_info_test) throws Error {
+ var enumerator = file.enumerate_children (attributes, FileQueryInfoFlags.NONE);
+ for (var file_info = enumerator.next_file () ; file_info != null ; file_info =
enumerator.next_file ())
+ if (file_info_test (file_info))
+ return;
+ }
+
+ private FileInfo? try_next_file (FileEnumerator enumerator) {
+ try {
+ return enumerator.next_file ();
+ }
+ catch (Error e) {
+ debug (e.message);
+
+ return null;
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]