2 * This file is part of DrNokSnes
4 * Copyright (C) 2005 INdT - Instituto Nokia de Tecnologia
5 * http://www.indt.org/maemo
6 * Copyright (C) 2009 Javier S. Pedro <maemo@javispedro.com>
8 * This software is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
13 * This software is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this software; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 #include <dbus/dbus.h>
31 #define FRZ_FILE_EXT ".frz.gz"
33 /** Caches the freeze file of the current loaded rom, or NULL if it does not
35 * It is updated from the game_state_update() and game_state_clear() functions.
37 static gchar * cur_frz_file = NULL;
39 /** Updates cur_frz_file.
40 * @return TRUE if cur_frz_file is now not NULL (so a freeze file is present).
42 static gboolean rom_get_freeze_file()
49 if (cur_frz_file) g_free(cur_frz_file);
51 if (!current_rom_file_exists) {
56 ext = strrchr(current_rom_file, '.');
58 rom_base = g_strdup(current_rom_file);
60 rom_base = g_strndup(current_rom_file, ext - current_rom_file);
63 if (current_rom_file_exists) {
64 frz_file = g_strconcat(rom_base, FRZ_FILE_EXT);
66 g_file_test(frz_file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR);
69 cur_frz_file = frz_file;
80 return cur_frz_file ? TRUE : FALSE;
83 // More uglyness. If you know a better way to do this please tell.
84 void game_state_update()
90 gboolean has_freeze = rom_get_freeze_file();
93 m_name = "game_pause";
95 m_name = "game_close";
98 dbus_error_init(&err);
100 bus = dbus_bus_get(DBUS_BUS_SESSION, &err);
101 if (dbus_error_is_set(&err)) {
102 dbus_error_free(&err);
106 m = dbus_message_new_method_call("com.javispedro.drnoksnes.startup",
107 "/com/javispedro/drnoksnes/startup",
108 "com.javispedro.drnoksnes.startup",
111 dbus_connection_send(bus, m, NULL);
112 dbus_connection_flush(bus);
114 dbus_message_unref(m);
117 void game_state_clear()
120 g_free(cur_frz_file);
125 gboolean game_state_is_paused()
127 return cur_frz_file ? TRUE : FALSE;
130 const gchar * game_state_get_frz_file()