From: P. F. Chimento Date: Sun, 30 Jan 2011 17:34:03 +0000 (+0100) Subject: Added hack for opening external Blorb file X-Git-Tag: v0.9~150 X-Git-Url: https://git.stderr.nl/gitweb?p=projects%2Fchimara%2Fchimara.git;a=commitdiff_plain;h=80feedc081ae20491c20123467ef7a72130855ba Added hack for opening external Blorb file However, something is preventing it from working with the old Infocom games. --- diff --git a/libchimara/chimara-glk-private.h b/libchimara/chimara-glk-private.h index 6736670..24d79fa 100644 --- a/libchimara/chimara-glk-private.h +++ b/libchimara/chimara-glk-private.h @@ -91,6 +91,9 @@ struct _ChimaraGlkPrivate { giblorb_map_t *resource_map; /* File stream pointing to the blorb used as current resource map */ strid_t resource_file; + /* Information for opening external blorb file */ + gboolean open_external_blorb; + gchar *external_blorb_pathname; /* Optional callback for loading resource data */ ChimaraResourceLoadFunc resource_load_callback; gpointer resource_load_callback_data; diff --git a/libchimara/chimara-glk.c b/libchimara/chimara-glk.c index ca01f44..aca2f21 100644 --- a/libchimara/chimara-glk.c +++ b/libchimara/chimara-glk.c @@ -180,6 +180,8 @@ chimara_glk_init(ChimaraGlk *self) priv->line_input_queue = g_async_queue_new(); /* Should be g_async_queue_new_full(g_free); but only in GTK >= 2.16 */ priv->resource_map = NULL; + priv->open_external_blorb = FALSE; + priv->external_blorb_pathname = NULL; priv->resource_lock = g_mutex_new(); priv->resource_loaded = g_cond_new(); priv->resource_info_available = g_cond_new(); @@ -1170,6 +1172,18 @@ glk_enter(struct StartupData *startup) if(!result) return NULL; } + + /* Open external Blorb file if specified */ + if(startup->glk_data->open_external_blorb) { + glkunix_set_base_file(startup->glk_data->external_blorb_pathname); + gchar *basename = g_path_get_basename(startup->glk_data->external_blorb_pathname); + frefid_t blorbref = glk_fileref_create_by_name(fileusage_BinaryMode | fileusage_Data, basename, 0); + g_free(basename); + strid_t blorbfile = glk_stream_open_file(blorbref, filemode_Read, 0); + giblorb_set_resource_map(blorbfile); + glk_fileref_destroy(blorbref); + g_printerr("Opening external blorb file\n"); + } /* Run main function */ glk_main_t glk_main = startup->glk_main; diff --git a/libchimara/chimara-if.c b/libchimara/chimara-if.c index 4e8c1d9..76edcf6 100644 --- a/libchimara/chimara-if.c +++ b/libchimara/chimara-if.c @@ -668,6 +668,26 @@ chimara_if_run_game(ChimaraIF *self, gchar *gamefile, GError **error) CHIMARA_GLK_USE_PRIVATE(self, glk_priv); glk_priv->story_name = g_path_get_basename(gamefile); g_object_notify(G_OBJECT(self), "story-name"); + + /* Check if an external blorb file is present */ + /* FIXME: hardcoded path */ + if(format == CHIMARA_IF_FORMAT_Z5 + || format == CHIMARA_IF_FORMAT_Z6 + || format == CHIMARA_IF_FORMAT_Z8 + || format == CHIMARA_IF_FORMAT_GLULX) { + gchar *path = g_path_get_dirname(gamefile); + gchar *scratch = g_path_get_basename(gamefile); + *(strrchr(scratch, '.')) = '\0'; + gchar *blorbfile = g_strconcat(path, "/../Resources/", scratch, ".blb", NULL); + if(g_file_test(blorbfile, G_FILE_TEST_EXISTS)) { + glk_priv->open_external_blorb = TRUE; + glk_priv->external_blorb_pathname = blorbfile; + } else { + g_free(blorbfile); + } + g_free(path); + g_free(scratch); + } gboolean retval = chimara_glk_run(CHIMARA_GLK(self), pluginpath, argc, argv, error); g_free(argv);