[libgames-support] Split load_scores_from_file from load_scores_from_files
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgames-support] Split load_scores_from_file from load_scores_from_files
- Date: Mon, 21 Sep 2015 00:16:05 +0000 (UTC)
commit 1049cf5e8ff73b3cca384864c15a8dd0a6e34430
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Sep 20 19:15:34 2015 -0500
Split load_scores_from_file from load_scores_from_files
games/scores/context.vala | 71 ++++++++++++++++++++++++---------------------
1 files changed, 38 insertions(+), 33 deletions(-)
---
diff --git a/games/scores/context.vala b/games/scores/context.vala
index eaad77a..e4362ae 100644
--- a/games/scores/context.vala
+++ b/games/scores/context.vala
@@ -193,6 +193,43 @@ public class Context : Object
yield stream.write_all_async (line.data, Priority.DEFAULT, cancellable, null);
}
+ private void load_scores_from_file (FileInfo file_info) throws Error
+ {
+ var category_key = file_info.get_name ();
+ var category = category_request (category_key);
+ var filename = Path.build_filename (user_score_dir, category_key);
+ var scores_of_single_category = new Gee.PriorityQueue<Score> ((owned) scorecmp);
+ var stream = FileStream.open (filename, "r");
+ string line;
+
+ while ((line = stream.read_line ()) != null)
+ {
+ var tokens = line.split (" ", 3);
+ string? user = null;
+
+ if (tokens.length < 2)
+ {
+ throw new FileError.FAILED ("Failed to parse %s for scores.", filename);
+ }
+
+ if (tokens.length < 3)
+ {
+ debug ("Importing old score from %s.", filename);
+ user = Environment.get_real_name ();
+ }
+
+ var score_value = long.parse (tokens[0]);
+ var time = int64.parse (tokens[1]);
+
+ if (user == null)
+ user = tokens[2];
+
+ scores_of_single_category.add (new Score (score_value, time, user));
+ }
+
+ scores_per_category.set (category, scores_of_single_category);
+ }
+
private void load_scores_from_files () throws Error
{
if (game_window != null && game_window.visible)
@@ -214,39 +251,7 @@ public class Context : Object
while ((file_info = enumerator.next_file ()) != null)
{
- var category_key = file_info.get_name ();
- var category = category_request (category_key);
- var filename = Path.build_filename (user_score_dir, category_key);
- var scores_of_single_category = new Gee.PriorityQueue<Score> ((owned) scorecmp);
- var stream = FileStream.open (filename, "r");
- string line;
-
- while ((line = stream.read_line ()) != null)
- {
- var tokens = line.split (" ", 3);
- string? user = null;
-
- if (tokens.length < 2)
- {
- throw new FileError.FAILED ("Failed to parse %s for scores.", filename);
- }
-
- if (tokens.length < 3)
- {
- debug ("Importing old score from %s.", filename);
- user = Environment.get_real_name ();
- }
-
- var score_value = long.parse (tokens[0]);
- var time = int64.parse (tokens[1]);
-
- if (user == null)
- user = tokens[2];
-
- scores_of_single_category.add (new Score (score_value, time, user));
- }
-
- scores_per_category.set (category, scores_of_single_category);
+ load_scores_from_file (file_info);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]