]> Chaos Git - console/RCOMage.git/commitdiff
Patch from Antonio Ospite to install INI files with 'make install' and to scan their...
authorzingaburga <zingaburga@hotmail.com>
Sat, 5 Feb 2011 00:39:15 +0000 (10:39 +1000)
committerzingaburga <zingaburga@hotmail.com>
Sat, 5 Feb 2011 00:39:15 +0000 (10:39 +1000)
Modified with Windows version
I haven't tested any of this

Makefile.am
src/Makefile.am
src/configscan.c

index 6319ac03f8faa4d0b0c5025e6482bd6a02b527a5..9fc61897dbaa2a0c1f693c507af65eda0b8eb460 100644 (file)
@@ -6,3 +6,13 @@
 
 SUBDIRS = 7z \
           src
+
+rcomagedir = $(pkgdatadir)
+
+rcomage_DATA = \
+       data/animattribdef-ps3.ini \
+       data/animattribdef-psp.ini \
+       data/miscmap.ini \
+       data/objattribdef-ps3.ini \
+       data/objattribdef-psp.ini \
+       data/tagmap.ini
index 7d11de639539225123861587bae17a2d72cfa20d..0cc9d7f0a2853b6573eb3bcd5f369049d044274a 100644 (file)
@@ -10,7 +10,8 @@ include $(top_srcdir)/common.mk
 AM_CFLAGS = \
        $(ERROR_CFLAGS) \
        $(ZLIB_CFLAGS) \
-       $(LIBXML2_CFLAGS)
+       $(LIBXML2_CFLAGS) \
+       -DDATADIR='"$(pkgdatadir)"'
 
 bin_PROGRAMS = rcomage
 
index d313242057d6945639b576e8391eba837ce40e06..d1c35d5b26c179f8ef33eb4bca3b8177a23c7133 100644 (file)
@@ -20,12 +20,36 @@ char *configDir = NULL;
 
 int get_ini_line (FILE * fp, char *buf, char **out1, char **out2);
 
-// always try to load the INI files from the same dir as the executable
 #ifdef WIN32
 #include <windows.h>
+static int is_dir(char *path)
+{
+  WIN32_FIND_DATA fd;
+  CloseHandle(FindFirstFile(path, &fd));
+  return (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
+}
 #else
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <unistd.h>
+static int is_dir(char *path)
+{
+  struct stat st;
+  int ret;
+
+  ret = lstat(path, &st);
+  if (ret < 0)
+    return 0;
+
+  return S_ISDIR(st.st_mode);
+}
 #endif
+
+// Try to load the INI files from different places in this order:
+//   1. from the dir specified with the --ini-dir option
+//   2. from the dir specified in the RCOMAGE_DATADIR environment variable
+//   3. from the dir specified in DATADIR from ./configure if it exists
+//   4. from the same dir as the executable
 FILE *
 fopen_local (char *fn, char *mode)
 {
@@ -33,7 +57,9 @@ fopen_local (char *fn, char *mode)
   int bytes = 0;
   char *p = NULL;
 
-  if (configDir) {
+  if (configDir ||
+      ((configDir = getenv("RCOMAGE_DATADIR")) != NULL) ||
+      (is_dir(DATADIR) && (configDir = DATADIR)) ) {
     strcpy (path, configDir);
     if (path[strlen (path) - 1] != '/' && path[strlen (path) - 1] != '\\') {
       char sepAdd[2] = { DIR_SEPARATOR, '\0' };