STARTUP_INIT_PLUGIN(plugin_info, gs, FALSE, TRUE)
gchar* current_rom_file = 0;
+gboolean current_rom_file_exists = FALSE;
+
static GtkLabel* rom_label;
static GtkCheckButton* audio_check;
static GtkCheckButton* turbo_check;
if (!rom_file) return;
if (current_rom_file) g_free(current_rom_file);
+ gchar * utf8_filename = g_filename_display_name(rom_file);
+
current_rom_file = g_strdup(rom_file);
- gtk_label_set_text(GTK_LABEL(rom_label), rom_file); // TODO UTF-8
+ gtk_label_set_text(GTK_LABEL(rom_label), utf8_filename);
+
+ g_free(utf8_filename);
+
+ current_rom_file_exists = g_file_test(current_rom_file,
+ G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR);
game_state_update();
save_clear();
{
GtkWidget * dialog;
GtkFileFilter * filter;
- const gchar * current_filename = gtk_label_get_text(rom_label);
gchar * filename = NULL;
filter = gtk_file_filter_new();
dialog = hildon_file_chooser_dialog_new_with_properties(
get_parent_window(),
- "action", GTK_FILE_CHOOSER_ACTION_OPEN, "filter", filter, NULL);
-
- if (current_filename && strlen(current_filename) > 1) {
+ "action", GTK_FILE_CHOOSER_ACTION_OPEN,
+ "local-only", TRUE,
+ "filter", filter,
+ NULL);
+ hildon_file_chooser_dialog_set_show_upnp(HILDON_FILE_CHOOSER_DIALOG(dialog),
+ FALSE);
+
+ if (current_rom_file_exists) {
// By default open showing the last selected file
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),
- current_filename);
+ current_rom_file);
}
gtk_widget_show_all(GTK_WIDGET(dialog));
if (current_rom_file) {
gconf_client_set_string(gcc, kGConfRomFile, current_rom_file, NULL);
} else {
- GtkWidget* note = hildon_note_new_information(get_parent_window(),
- "No ROM selected");
- gtk_dialog_run(GTK_DIALOG(note));
- gtk_widget_destroy(note);
+ gconf_client_unset(gcc, kGConfRomFile, NULL);
}
controls_setup();
case 22: // ME_GAME_SAVE_AS
save_save_as(get_parent_window());
break;
+ case 30: // MA_GAME_PLAYING_START
+ if (!menu_item) {
+ // Avoid duplicate message
+ break;
+ }
+ if (!current_rom_file) {
+ GtkWidget* note = hildon_note_new_information(get_parent_window(),
+ "No ROM selected");
+ gtk_dialog_run(GTK_DIALOG(note));
+ gtk_widget_destroy(note);
+ } else if (!current_rom_file_exists) {
+ GtkWidget* note = hildon_note_new_information(get_parent_window(),
+ "ROM file does not exist");
+ gtk_dialog_run(GTK_DIALOG(note));
+ gtk_widget_destroy(note);
+ }
+ break;
}
}
#define FRZ_FILE_EXT ".frz.gz"
+/** Caches the freeze file of the current loaded rom, or NULL if it does not
+ * have any.
+ * It is updated from the game_state_update() and game_state_clear() functions.
+ */
static gchar * cur_frz_file = NULL;
+/** Updates cur_frz_file.
+ * @return TRUE if cur_frz_file is now not NULL (so a freeze file is present).
+ */
static gboolean rom_get_freeze_file()
{
- char * ext = strrchr(current_rom_file, '.');
+ char * ext;
char * rom_base;
char * frz_file;
- gboolean rom_exists, frz_exists;
+ gboolean frz_exists;
if (cur_frz_file) g_free(cur_frz_file);
+ if (!current_rom_file_exists) {
+ cur_frz_file = NULL;
+ return FALSE;
+ }
+
+ ext = strrchr(current_rom_file, '.');
if (!ext) {
rom_base = g_strdup(current_rom_file);
} else {
rom_base = g_strndup(current_rom_file, ext - current_rom_file);
}
- rom_exists = g_file_test(current_rom_file,
- G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR);
- frz_file = g_strconcat(rom_base, FRZ_FILE_EXT);
- frz_exists =
- g_file_test(frz_file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR);
-
- g_free(rom_base);
-
- if (rom_exists & frz_exists) {
- cur_frz_file = frz_file;
+ if (current_rom_file_exists) {
+ frz_file = g_strconcat(rom_base, FRZ_FILE_EXT);
+ frz_exists =
+ g_file_test(frz_file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR);
+
+ if (frz_exists) {
+ cur_frz_file = frz_file;
+ } else {
+ cur_frz_file = NULL;
+ g_free(frz_file);
+ }
} else {
cur_frz_file = NULL;
- g_free(frz_file);
}
- return rom_exists && frz_exists;
+ g_free(rom_base);
+
+ return cur_frz_file ? TRUE : FALSE;
}
// More uglyness. If you know a better way to do this please tell.