gnome-games r7933 - trunk/libgames-support



Author: chpe
Date: Sat Sep 27 13:11:29 2008
New Revision: 7933
URL: http://svn.gnome.org/viewvc/gnome-games?rev=7933&view=rev

Log:
Add runtime directory provider.

Added:
   trunk/libgames-support/games-runtime.c
   trunk/libgames-support/games-runtime.h
Modified:
   trunk/libgames-support/Makefile.am
   trunk/libgames-support/games-card-theme.c
   trunk/libgames-support/games-card.h
   trunk/libgames-support/games-files.c
   trunk/libgames-support/games-files.h
   trunk/libgames-support/games-sound.c
   trunk/libgames-support/games-stock.c

Modified: trunk/libgames-support/Makefile.am
==============================================================================
--- trunk/libgames-support/Makefile.am	(original)
+++ trunk/libgames-support/Makefile.am	Sat Sep 27 13:11:29 2008
@@ -36,6 +36,8 @@
 	games-files.h			\
 	games-pixbuf-utils.c		\
 	games-pixbuf-utils.h		\
+	games-runtime.c			\
+	games-runtime.h			\
 	games-sound.c			\
 	games-sound.h			\
 	games-stock.c			\
@@ -87,10 +89,7 @@
 	-DPKGDATADIR="\"$(pkgdatadir)\""			\
 	-DDATADIR="\"$(datadir)\""				\
 	-DCOMMON_DATADIR="\"$(datadir)/gnome-games-common\""	\
-	-DCARDDIR="\"$(carddir)\""				\
-	-DICONDIR="\"$(pkgdatadir)/icons\""			\
 	-DSCORESDIR="\"$(scoredir)\""				\
-	-DSOUNDDIR="\"$(pkgdatadir)/sounds\""			\
 	$(NULL)
 
 libgames_support_la_CFLAGS = 	\

Modified: trunk/libgames-support/games-card-theme.c
==============================================================================
--- trunk/libgames-support/games-card-theme.c	(original)
+++ trunk/libgames-support/games-card-theme.c	Sat Sep 27 13:11:29 2008
@@ -28,6 +28,7 @@
 #include "games-find-file.h"
 #include "games-files.h"
 #include "games-preimage.h"
+#include "games-runtime.h"
 
 #include "games-card-theme.h"
 
@@ -84,9 +85,6 @@
 
 static guint signals[LAST_SIGNAL];
 
-/* FIXMEchpe: use uninstalled data dir for rendering the card theme! */
-#define SLOTDIR  PKGDATADIR "/pixmaps"
-
 #define N_ROWS ((double) 5.0)
 #define N_COLS ((double) 13.0)
 
@@ -158,7 +156,7 @@
                                       const gchar * theme_name)
 {
   GamesPreimage *preimage;
-  const char *theme_dir, *env;
+  const char *theme_dir, *slot_dir, *env;
   gchar *filename, *path;
 
 #ifdef INSTRUMENT_LOADING
@@ -170,12 +168,13 @@
   if (theme->theme_data.scalable.cards_preimage != NULL)
     return TRUE;
 
-  theme_dir =
-    theme->theme_dir != NULL ? theme->theme_dir : SCALABLE_CARDS_DIR;
+  theme_dir = theme->theme_dir;
+  if (!theme_dir)
+    return FALSE;
 
   /* First try and load the given file. */
   filename = g_strdup_printf ("%s.svg", theme_name);
-  path = games_build_filename (theme_dir, filename);
+  path = g_build_filename (theme_dir, filename, NULL);
   preimage = games_preimage_new_from_file (path, NULL);
   g_free (path);
 
@@ -210,7 +209,9 @@
   }
 
   /* And the slot image */
-  path = games_build_filename (SLOTDIR, "slot.svg");
+  /* FIXMEchpe: use uninstalled data dir for rendering the card theme! */
+  slot_dir = games_runtime_get_directory (GAMES_RUNTIME_PIXMAP_DIRECTORY);
+  path = g_build_filename (slot_dir, "slot.svg", NULL);
   theme->theme_data.scalable.slot_preimage = games_preimage_new_from_file (path, NULL);
   g_free (path);
   g_return_val_if_fail (theme->theme_data.scalable.slot_preimage != NULL, FALSE);
@@ -260,14 +261,16 @@
                                          const gchar * theme_name)
 {
   GKeyFile *key_file;
+  const char *theme_dir;
   char *filename, *path;
   GError *error = NULL;
   int *sizes = NULL;
   gsize n_sizes, i;
   gboolean retval = FALSE;
 
+  theme_dir = games_runtime_get_directory (GAMES_RUNTIME_PRERENDERED_CARDS_DIRECTORY);
   filename = g_strdup_printf ("%s.card-theme", theme_name);
-  path = games_build_filename (PRERENDERED_CARDS_DIR, filename);
+  path = g_build_filename (theme_dir, filename, NULL);
   g_free (filename);
 
   key_file = g_key_file_new ();
@@ -511,7 +514,7 @@
 
   games_card_get_name_by_id_snprintf (name, sizeof (name), card_id);
   g_snprintf (filename, sizeof (filename), "%s.png", name);
-  path = games_build_filename (theme->theme_data.prerendered.themesizepath, filename);
+  path = g_build_filename (theme->theme_data.prerendered.themesizepath, filename, NULL);
 
   pixbuf = gdk_pixbuf_new_from_file (path, &error);
   if (!pixbuf) {
@@ -588,6 +591,10 @@
   }
   case PROP_THEME_DIRECTORY:
     theme->theme_dir = g_value_dup_string (value);
+    if (!theme->theme_dir)
+      theme->theme_dir = g_strdup (games_runtime_get_directory (theme->use_scalable ? GAMES_RUNTIME_SCALABLE_CARDS_DIRECTORY
+                                                                                    : GAMES_RUNTIME_PRERENDERED_CARDS_DIRECTORY));
+
     break;
   }
 }
@@ -626,7 +633,8 @@
                            G_PARAM_WRITABLE |
                            G_PARAM_STATIC_NAME |
                            G_PARAM_STATIC_NICK |
-                           G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY));
+                           G_PARAM_STATIC_BLURB |
+                           G_PARAM_CONSTRUCT_ONLY));
   g_object_class_install_property
     (gobject_class,
      PROP_THEME_DIRECTORY,
@@ -635,7 +643,8 @@
                           G_PARAM_WRITABLE |
                           G_PARAM_STATIC_NAME |
                           G_PARAM_STATIC_NICK |
-                          G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY));
+                          G_PARAM_STATIC_BLURB |
+                          G_PARAM_CONSTRUCT_ONLY));
 }
 
 /* public API */
@@ -652,8 +661,8 @@
 games_card_theme_new (const char *theme_dir, gboolean scalable)
 {
   return g_object_new (GAMES_TYPE_CARD_THEME,
-                       "theme-directory", theme_dir,
                        "scalable", scalable,
+                       "theme-directory", theme_dir,
                        NULL);
 }
 
@@ -801,9 +810,7 @@
   {
     guint i;
     int twidth, theight;
-    gchar *spath;
-    CardSize size = { -1, -1 }, fit_size = {
-    -1, -1};
+    CardSize size = { -1, -1 }, fit_size = { -1, -1};
 
     twidth = FLOAT_TO_INT_CEIL (((double) width) * proportion);
     theight = FLOAT_TO_INT_CEIL (((double) height) * proportion);
@@ -828,7 +835,7 @@
       size = fit_size;
 
     if (size.width > 0 && size.height > 0) {
-      char sizestr[32];
+      char sizestr[16];
 
       if (size.width == theme->card_size.width &&
           size.height == theme->card_size.height)
@@ -837,13 +844,8 @@
       g_free (theme->theme_data.prerendered.themesizepath);
 
       g_snprintf (sizestr, sizeof (sizestr), "%d", size.width);
-      spath = g_build_filename (theme->theme_dir !=
-                          NULL ? theme->theme_dir : PRERENDERED_CARDS_DIR,
-                          theme->theme_name, NULL);
-      
-      theme->theme_data.prerendered.themesizepath = 
-	      				games_build_filename (spath, sizestr);
-      g_free (spath);
+      theme->theme_data.prerendered.themesizepath =
+        g_build_filename (theme->theme_dir, theme->theme_name, sizestr, NULL);
 
       theme->size_available = TRUE;
       theme->card_size = size;

Modified: trunk/libgames-support/games-card.h
==============================================================================
--- trunk/libgames-support/games-card.h	(original)
+++ trunk/libgames-support/games-card.h	Sat Sep 27 13:11:29 2008
@@ -65,9 +65,6 @@
 
 /* Some defines */
 
-#define SCALABLE_CARDS_DIR    COMMON_DATADIR G_DIR_SEPARATOR_S "cards"
-#define PRERENDERED_CARDS_DIR COMMON_DATADIR G_DIR_SEPARATOR_S "card-themes"
-
 typedef enum {
   /* Cards */
   GAMES_CARD_JOKER = 0,

Modified: trunk/libgames-support/games-files.c
==============================================================================
--- trunk/libgames-support/games-files.c	(original)
+++ trunk/libgames-support/games-files.c	Sat Sep 27 13:11:29 2008
@@ -40,8 +40,10 @@
 #endif
 #endif
 
-#include "games-files.h"
 #include "games-card.h"
+#include "games-runtime.h"
+
+#include "games-files.h"
 
 G_DEFINE_TYPE (GamesFileList, games_file_list, G_TYPE_OBJECT)
 
@@ -442,29 +444,30 @@
 {
   GamesFileList *files;
   GList *l;
-  const char *glob, *ext, *dir;
+  GamesRuntimeDirectory dir;
+  const char *glob, *path;
 
 #ifdef HAVE_RSVG
   if (scalable) {
     glob = "*.svg";
-    ext = ".svg";
-    dir = SCALABLE_CARDS_DIR;
+    dir = GAMES_RUNTIME_SCALABLE_CARDS_DIRECTORY;
   } else
 #endif /* HAVE_RSVG */
   {
     glob = "*.card-theme";
-    ext = ".card-theme";
-    dir = PRERENDERED_CARDS_DIR;
+    dir = GAMES_RUNTIME_PRERENDERED_CARDS_DIRECTORY;
   }
 
-  files = games_file_list_new (glob, dir, NULL);
+  path = games_runtime_get_directory (dir);
+  files = games_file_list_new (glob, path, NULL);
+
   games_file_list_transform_basename (files);
 
   for (l = files->list; l != NULL; l = l->next) {
     const char *filename = (const char *) l->data;
     char *dot;
 
-    dot = g_strrstr (filename, ext);
+    dot = strrchr (filename, '.');
     if (dot) {
       *dot = '\0';
     }
@@ -472,126 +475,3 @@
 
   return files;
 }
-
-#if defined (G_OS_WIN32) && defined (PREFIX)
-
-static const gchar *
-games_toplevel_directory (void)
-{
-  static gchar *toplevel = NULL;
-
-  if (toplevel)
-    return toplevel;
-
-  {
-    gchar *filename;
-    gchar *sep1, *sep2;
-
-    if (G_WIN32_HAVE_WIDECHAR_API ()) {
-      wchar_t w_filename[MAX_PATH];
-
-      if (GetModuleFileNameW (NULL,
-			      w_filename, G_N_ELEMENTS (w_filename)) == 0)
-	g_error ("GetModuleFilenameW failed");
-
-      filename = g_utf16_to_utf8 (w_filename, -1, NULL, NULL, NULL);
-      if (filename == NULL)
-	g_error ("Converting module filename to UTF-8 failed");
-    } else {
-      gchar cp_filename[MAX_PATH];
-
-      if (GetModuleFileNameA (NULL,
-			      cp_filename, G_N_ELEMENTS (cp_filename)) == 0)
-	g_error ("GetModuleFilenameA failed");
-
-      filename = g_locale_to_utf8 (cp_filename, -1, NULL, NULL, NULL);
-      if (filename == NULL)
-	g_error ("Converting module filename to UTF-8 failed");
-    }
-
-    /* If the executable file name is of the format
-     * <foobar>\bin\*.exe , use <foobar>.
-     * Otherwise, use the directory where the executable is.
-     */
-
-    sep1 = strrchr (filename, '\\');
-    *sep1 = '\0';
-
-    sep2 = strrchr (filename, '\\');
-    if (sep2 != NULL) {
-      *sep2 = '\0';
-    }
-
-    toplevel = filename;
-  }
-
-  return toplevel;
-}
-#endif
-
-/**
- * games_path_runtime_fix_private:
- * @path: A pointer to a string (allocated with g_malloc) that is
- *        (or could be) a pathname.
- *
- * On Windows, this function checks if the string pointed to by @path
- * starts with the compile-time prefix, and in that case, replaces the
- * prefix with the run-time one.  @path should be a pointer to a
- * dynamically allocated (with g_malloc, g_strconcat, etc) string. If
- * the replacement takes place, the original string is deallocated,
- * and * path is replaced with a pointer to a new string with the
- * run-time prefix spliced in.
- *
- * On Linux, it does the same thing, but only if BinReloc support is enabled.
- * On other Unices, it does nothing because those platforms don't have a
- * way to find out where our binary is.
- */
-static void
-games_path_runtime_fix_private (gchar **path)
-{
-#if defined (G_OS_WIN32) && defined (PREFIX)
-  gchar *p;
-
-      /* This is a compile-time entry. Replace the path with the
-       * real one on this machine.
-       */
-      p = *path;
-      *path = g_strconcat (games_toplevel_directory (),
-                           "\\",
-                           *path + strlen (PREFIX "/"),
-                           NULL);
-      g_free (p);
-  /* Replace forward slashes with backslashes, just for
-   * completeness */
-  p = *path;
-  while ((p = strchr (p, '/')) != NULL)
-    {
-      *p = '\\';
-      p++;
-    }
-#endif
-}
-
-
-gchar *
-games_path_runtime_fix (const gchar *path)
-{
-  gchar *p = g_strdup (path);
-  games_path_runtime_fix_private (&p);
-
-  return p;
-}
-
-
-gchar *
-games_build_filename (const gchar * path, const gchar * filename)
-{
-  gchar *p = g_strdup (path);
-	  
-  games_path_runtime_fix_private (&p);
-
-  gchar *result = g_build_filename (p, filename, NULL);
-  g_free (p);
-
-  return result;
-}

Modified: trunk/libgames-support/games-files.h
==============================================================================
--- trunk/libgames-support/games-files.h	(original)
+++ trunk/libgames-support/games-files.h	Sat Sep 27 13:11:29 2008
@@ -69,9 +69,6 @@
 
 GamesFileList *games_file_list_card_themes (gboolean scalable);
 
-gchar *games_build_filename (const gchar *path, const gchar *filename);
-gchar *games_path_runtime_fix (const gchar *path);
-
 G_END_DECLS
 
 #endif /* GAMES_FILES_H */

Added: trunk/libgames-support/games-runtime.c
==============================================================================
--- (empty file)
+++ trunk/libgames-support/games-runtime.c	Sat Sep 27 13:11:29 2008
@@ -0,0 +1,181 @@
+/*
+ * Copyright  2007 Andreas RÃsdal <andreasr gnome org>
+ * Copyright  2007, 2008 Christian Persch
+ *
+ * This game is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This runtime is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this runtime; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ * USA
+ */
+
+#include <config.h>
+
+#if defined (G_OS_WIN32)
+#include <windows.h>
+#include <io.h>
+#define HELP_EXT "xhtml"
+/* FIXME On win32 help is created as html with gnome-doc-tool,
+ * and put manually in the directory below.
+ */
+#define HELPDIR PKGDATADIR "/aisleriot/help"
+#endif /* G_OS_WIN32 */
+
+#include "games-runtime.h"
+
+static char *app_name;
+static char *cached_directories[GAMES_RUNTIME_LAST_DIRECTORY];
+#ifdef G_OS_WIN32
+static char *module_path;
+#endif
+
+typedef struct {
+  GamesRuntimeDirectory base_dir;
+  const char *name;
+} DerivedDirectory;
+
+static const DerivedDirectory derived_directories[] = {
+  /* Keep this in the same order as in the GamesRuntimeDirectory enum! */
+#ifdef G_OS_WIN32
+  { GAMES_RUNTIME_MODULE_DIRECTORY,   "share"              }, /* GAMES_RUNTIME_DATA_DIRECTORY              */
+  { GAMES_RUNTIME_DATA_DIRECTORY,     "gnome-games-common" }, /* GAMES_RUNTIME_COMMON_DATA_DIRECTORY       */
+  { GAMES_RUNTIME_DATA_DIRECTORY,     "gnome-games"        }, /* GAMES_RUNTIME_PKG_DATA_DIRECTORY          */
+#endif /* G_OS_WIN32 */
+  { GAMES_RUNTIME_DATA_DIRECTORY,         "locale"         }, /* GAMES_RUNTIME_LOCALE_DIRECTORY            */
+  { GAMES_RUNTIME_COMMON_DATA_DIRECTORY,  "pixmaps"        }, /* GAMES_RUNTIME_COMMON_PIXMAP_DIRECTORY     */
+  { GAMES_RUNTIME_COMMON_DATA_DIRECTORY,  "card-themes"    }, /* GAMES_RUNTIME_PRERENDERED_CARDS_DIRECTORY */
+  { GAMES_RUNTIME_COMMON_DATA_DIRECTORY,  "cards"          }, /* GAMES_RUNTIME_SCALABLE_CARDS_DIRECTORY    */
+  { GAMES_RUNTIME_PKG_DATA_DIRECTORY,     "icons"          }, /* GAMES_RUNTIME_ICON_THEME_DIRECTORY        */
+  { GAMES_RUNTIME_PKG_DATA_DIRECTORY,     "pixmaps"        }, /* GAMES_RUNTIME_PIXMAP_DIRECTORY            */
+  { GAMES_RUNTIME_PKG_DATA_DIRECTORY,     "sounds"         }, /* GAMES_RUNTIME_SOUNDS_DIRECTORY            */
+  { GAMES_RUNTIME_PKG_DATA_DIRECTORY,     NULL             }, /* GAMES_RUNTIME_GAME_DATA_DIRECTORY         */
+  { GAMES_RUNTIME_GAME_DATA_DIRECTORY,    "games"          }, /* GAMES_RUNTIME_GAME_GAMES_DIRECTORY        */
+  { GAMES_RUNTIME_GAME_DATA_DIRECTORY,    "pixmaps"        }, /* GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY       */
+};
+
+typedef int _assertion[G_N_ELEMENTS (derived_directories) + GAMES_RUNTIME_FIRST_DERIVED_DIRECTORY == GAMES_RUNTIME_LAST_DIRECTORY ? 1 : -1];
+
+/* public API */
+
+/**
+ * games_runtime_init:
+ *
+ * Initialises the runtime file localisator.
+ * 
+ * Returns: %TRUE iff initialisation succeeded
+ */
+gboolean
+games_runtime_init (const char *name)
+{
+  app_name = g_strdup (name);
+
+#ifdef G_OS_WIN32
+  return games_runtime_get_directory (GAMES_RUNTIME_MODULE_DIRECTORY) != NULL;
+#else
+  return TRUE;
+#endif
+}
+
+/**
+ * games_runtime_shutdown:
+ *
+ * Shuts down the runtime file localator.
+ */
+void
+games_runtime_shutdown (void)
+{
+  guint i;
+
+  for (i = 0; i < GAMES_RUNTIME_LAST_DIRECTORY; ++i) {
+    g_free (cached_directories[i]);
+    cached_directories[i] = NULL;
+  }
+
+  g_free (app_name);
+  app_name = NULL;
+}
+
+/**
+ * games_runtime_get_directory:
+ * @runtime: the #GamesProgram instance
+ * @directory:
+ *
+ * Returns: the path to use for @directory
+ */
+const char *
+games_runtime_get_directory (GamesRuntimeDirectory directory)
+{
+
+  char *path = NULL;
+
+  g_return_val_if_fail (app_name != NULL, NULL);
+  g_return_val_if_fail (directory >= 0 && directory < GAMES_RUNTIME_LAST_DIRECTORY, NULL);
+
+  if (cached_directories[directory])
+    return cached_directories[directory];
+
+  switch (directory) {
+#ifndef G_OS_WIN32
+    case GAMES_RUNTIME_DATA_DIRECTORY:
+      path = g_strdup (DATADIR);
+      break;
+
+    case GAMES_RUNTIME_COMMON_DATA_DIRECTORY:
+      path = g_build_filename (DATADIR, "gnome-games-common", NULL);
+      break;
+
+    case GAMES_RUNTIME_PKG_DATA_DIRECTORY:
+      path = g_strdup (PKGDATADIR);
+      break;
+
+#else /* G_OS_WIN32 */
+    case GAMES_RUNTIME_MODULE_DIRECTORY:
+      path = g_win32_get_package_installation_directory_of_module (NULL);
+      break;
+#endif /* !G_OS_WIN32 */
+
+    default: {
+      const DerivedDirectory *base = &derived_directories[directory - GAMES_RUNTIME_FIRST_DERIVED_DIRECTORY];
+
+      path = g_build_filename (games_runtime_get_directory (base->base_dir),
+                               base->name ? base->name : app_name,
+                               NULL);
+    }
+  }
+
+  cached_directories[directory] = path;
+  return path;
+}
+
+/**
+ * games_runtime_get_file:
+ * @runtime: the #GamesProgram instance
+ * @directory:
+ * @name:
+ *
+ * Returns: a newly allocated string containing the path to the file with name @name
+ *   in the directory specicifed by @directory
+ */
+char *
+games_runtime_get_file (GamesRuntimeDirectory directory,
+                        const char *name)
+{
+  const char *dir;
+
+  g_return_val_if_fail (app_name != NULL, NULL);
+
+  dir = games_runtime_get_directory (directory);
+  if (!dir)
+    return NULL;
+
+  return g_build_filename (dir, name, NULL);
+}

Added: trunk/libgames-support/games-runtime.h
==============================================================================
--- (empty file)
+++ trunk/libgames-support/games-runtime.h	Sat Sep 27 13:11:29 2008
@@ -0,0 +1,78 @@
+/*
+ *  Copyright  2007, 2008 Christian Persch
+ *
+ *  This runtime is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation; either version 2.1, or (at your option)
+ *  any later version.
+ *
+ *  This runtime is distributed in the hope runtime it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this runtime; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GAMES_RUNTIME_H
+#define GAMES_RUNTIME_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum {
+  /* Base directories */
+#ifdef G_OS_WIN32
+  GAMES_RUNTIME_MODULE_DIRECTORY,
+#endif
+
+  GAMES_RUNTIME_DATA_DIRECTORY,
+  GAMES_RUNTIME_COMMON_DATA_DIRECTORY,
+  GAMES_RUNTIME_PKG_DATA_DIRECTORY,
+
+  /* Derived directories */
+  GAMES_RUNTIME_LOCALE_DIRECTORY,
+
+  GAMES_RUNTIME_COMMON_PIXMAP_DIRECTORY,
+  GAMES_RUNTIME_PRERENDERED_CARDS_DIRECTORY,
+  GAMES_RUNTIME_SCALABLE_CARDS_DIRECTORY,
+
+  GAMES_RUNTIME_ICON_THEME_DIRECTORY,
+  GAMES_RUNTIME_PIXMAP_DIRECTORY,
+  GAMES_RUNTIME_SOUND_DIRECTORY,
+
+  GAMES_RUNTIME_GAME_DATA_DIRECTORY,
+  GAMES_RUNTIME_GAME_GAMES_DIRECTORY,
+  GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY,
+//   GAMES_RUNTIME__DIRECTORY,
+//   GAMES_RUNTIME__DIRECTORY,
+//   GAMES_RUNTIME__DIRECTORY,
+//   GAMES_RUNTIME__DIRECTORY,
+//   GAMES_RUNTIME__DIRECTORY,
+//   GAMES_RUNTIME__DIRECTORY,
+//   GAMES_RUNTIME__DIRECTORY,
+//   GAMES_RUNTIME__DIRECTORY,
+//   GAMES_RUNTIME__DIRECTORY,
+  GAMES_RUNTIME_LAST_DIRECTORY,
+#ifdef G_OS_WIN32
+  GAMES_RUNTIME_FIRST_DERIVED_DIRECTORY = GAMES_RUNTIME_DATA_DIRECTORY,
+#else
+  GAMES_RUNTIME_FIRST_DERIVED_DIRECTORY = GAMES_RUNTIME_LOCALE_DIRECTORY,
+#endif
+} GamesRuntimeDirectory;
+
+gboolean games_runtime_init (const char *name);
+
+void games_runtime_shutdown (void);
+
+const char * games_runtime_get_directory (GamesRuntimeDirectory directory);
+
+char * games_runtime_get_file (GamesRuntimeDirectory directory,
+                               const char *name);
+
+G_END_DECLS
+
+#endif /* !GAMES_RUNTIME_H */

Modified: trunk/libgames-support/games-sound.c
==============================================================================
--- trunk/libgames-support/games-sound.c	(original)
+++ trunk/libgames-support/games-sound.c	Sat Sep 27 13:11:29 2008
@@ -31,6 +31,8 @@
   #include "SDL_mixer.h"
 #endif 
 
+#include "games-runtime.h"
+
 #include "games-sound.h"
 
 #if defined(HAVE_GSTREAMER) || defined(HAVE_SDL_MIXER)
@@ -46,15 +48,18 @@
 static void
 games_sound_thread_run (gchar * data, gchar * user_data)
 {
-  gchar *fullname = NULL;
-
+  const char *dir;
+  char *uri;
   gboolean done = FALSE;
   GstBus *bus;
 
   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
   /* Set URL for sound to play. */
-  fullname = g_strdup_printf ("file:///%s/%s.ogg", SOUNDDIR, (char *) data);
-  g_object_set (G_OBJECT (pipeline), "uri", fullname, NULL);
+  dir = games_runtime_get_directory (GAMES_RUNTIME_SOUND_DIRECTORY);
+  uri = g_strdup_printf ("file:///%s/%s.ogg", dir, (char *) data);
+  g_object_set (G_OBJECT (pipeline), "uri", uri, NULL);
+  g_free (uri);
+
   /* Set playbin to playing state. */
   gst_element_set_state (pipeline, GST_STATE_PLAYING);
 
@@ -88,7 +93,6 @@
   while (!done);
 
   gst_element_set_state (pipeline, GST_STATE_NULL);
-  g_free (fullname);
 }
 
 #endif /* HAVE_GSTREAMER */
@@ -102,7 +106,7 @@
   gchar *name, *path;
 
   name = g_strdup_printf ("%s.ogg", filename);
-  path = g_build_filename (SOUNDDIR, name, NULL);
+  path = games_runtime_get_file (GAMES_RUNTIME_SOUND_DIRECTORY, name);
   g_free (name);
 
   wave = Mix_LoadWAV (path);

Modified: trunk/libgames-support/games-stock.c
==============================================================================
--- trunk/libgames-support/games-stock.c	(original)
+++ trunk/libgames-support/games-stock.c	Sat Sep 27 13:11:29 2008
@@ -30,6 +30,7 @@
 #include <gtk/gtkversion.h>
 
 #include "games-files.h"
+#include "games-runtime.h"
 
 #include "games-stock.h"
 
@@ -389,7 +390,8 @@
    * for icons as well as the standard search paths.
    */
   /* FIXME: multi-head! */
-  gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), ICONDIR);
+  gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
+                                     games_runtime_get_directory (GAMES_RUNTIME_ICON_THEME_DIRECTORY));
  
   gtk_stock_add_static (games_stock_items, G_N_ELEMENTS (games_stock_items));
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]