| 1 |
/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 2 |
* |
| 3 |
* Copyright © 2016 Michael Catanzaro <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of libgnome-games-support. |
| 6 |
* |
| 7 |
* libgnome-games-support is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU Lesser General Public License as published by |
| 9 |
* the Free Software Foundation, either version 3 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* libgnome-games-support is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public License |
| 18 |
* along with libgnome-games-support. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
namespace Games { |
| 22 |
namespace Scores { |
| 23 |
|
| 24 |
/* Time for a history lesson. Once upon a time, scores were stored under |
| 25 |
* /var/games in a format basically the same as what we use now, split into |
| 26 |
* different files based on category. Games were installed setgid for the games |
| 27 |
* group, allowing scores to be shared between users (fun in a computer lab or |
| 28 |
* shared machine) while preventing cheating, since editing the scores file |
| 29 |
* would require some privilege escalation exploit. |
| 30 |
* |
| 31 |
* When Robert started rewriting games in Vala, he changed the scores format so |
| 32 |
* that all scores for a game would be saved in one file, in the home directory. |
| 33 |
* Placing the file in the home directory has an important advantage in that you |
| 34 |
* do not lose your scores if you copy your home directory to another computer. |
| 35 |
* Of course, this had the one-time cost that scores were lost upon upgrading |
| 36 |
* to the new Vala version of the game, as there was no score importer. It also |
| 37 |
* makes importing a bit tricky, because the columns in the scores file are |
| 38 |
* different for each game. |
| 39 |
* |
| 40 |
* Then, for GNOME 3.12, I (Michael) changed all the remaining C games to store |
| 41 |
* scores in the home directory, without changing the format except for removing |
| 42 |
* the player name column, since it didn't seem relevant if all scores were in |
| 43 |
* the home directory. Again, all users' scores were lost in this transition. |
| 44 |
* Currently, scores use this same format, except the player name column is back |
| 45 |
* because it turns out people share user accounts and want to record scores |
| 46 |
* separately. |
| 47 |
* |
| 48 |
* These importers exist so that we don't delete everyone's scores a second |
| 49 |
* time. |
| 50 |
* |
| 51 |
* Some users have complained that scores are now saved in the home directory. |
| 52 |
* Using /var/games was a clever setup and it's a bit of a shame to see it go; |
| 53 |
* bug #749682 exists to restore that old behavior. It has been suggested that |
| 54 |
* we could hardlink scores files from the home directory to /var/games to get |
| 55 |
* the best of both worlds. I don't see why not, except some distro folks really |
| 56 |
* don't like using the setgid bit. Another possibility would be to make this |
| 57 |
* some configurable option. Few enough people have been complaining that I |
| 58 |
* don't plan to spend more time on this, though. |
| 59 |
*/ |
| 60 |
|
| 61 |
/* Note that importers must operate synchronously. This is fine because the |
| 62 |
* importer is only used before scores are loaded, and we ensure scores are |
| 63 |
* loaded before showing the main window. |
| 64 |
*/ |
| 65 |
|
| 66 |
public abstract class Importer : Object |
| 67 |
{ |
| 68 |
protected abstract void importOldScores (Context context, File new_scores_dir) throws Error; |
| 69 |
|
| 70 |
internal void run (Context context, string new_scores_dir) |
| 71 |
{ |
| 72 |
var new_dir = File.new_for_path (new_scores_dir); |
| 73 |
if (new_dir.query_exists ()) |
| 74 |
return; |
| 75 |
|
| 76 |
try |
| 77 |
{ |
| 78 |
new_dir.make_directory_with_parents (); |
| 79 |
importOldScores (context, new_dir); |
| 80 |
} |
| 81 |
catch (Error e) |
| 82 |
{ |
| 83 |
warning ("Failed to import scores: %s", e.message); |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
} /* namespace Scores */ |
| 89 |
} /* namespace Games */ |