Added hack for opening external Blorb file
authorP. F. Chimento <philip.chimento@gmail.com>
Sun, 30 Jan 2011 17:34:03 +0000 (18:34 +0100)
committerP. F. Chimento <philip.chimento@gmail.com>
Sun, 30 Jan 2011 17:34:03 +0000 (18:34 +0100)
However, something is preventing it from working with the old Infocom
games.

libchimara/chimara-glk-private.h
libchimara/chimara-glk.c
libchimara/chimara-if.c

index 67366707f92af252c0354a97e5dc08041a934ec7..24d79fa0bcf085517dce63b90557aa0592b4b2fa 100644 (file)
@@ -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;
index ca01f44510d7c7dd86a0db2fa9698385cea1197b..aca2f212e8c47d6d02443ff899898c8ecd6cb045 100644 (file)
@@ -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;
index 4e8c1d9490b4fcbc38f0e471703a2fcc35fd5c29..76edcf645c6252d07da503fb4b9895d099c70a73 100644 (file)
@@ -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);