From 1b3cbaa98aa47e1fbee716157561459147f940ab Mon Sep 17 00:00:00 2001 From: zingaburga Date: Sat, 5 Feb 2011 10:39:15 +1000 Subject: [PATCH] Patch from Antonio Ospite to install INI files with 'make install' and to scan their location at runtime Modified with Windows version I haven't tested any of this --- Makefile.am | 10 ++++++++++ src/Makefile.am | 3 ++- src/configscan.c | 30 ++++++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 6319ac0..9fc6189 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/src/Makefile.am b/src/Makefile.am index 7d11de6..0cc9d7f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,7 +10,8 @@ include $(top_srcdir)/common.mk AM_CFLAGS = \ $(ERROR_CFLAGS) \ $(ZLIB_CFLAGS) \ - $(LIBXML2_CFLAGS) + $(LIBXML2_CFLAGS) \ + -DDATADIR='"$(pkgdatadir)"' bin_PROGRAMS = rcomage diff --git a/src/configscan.c b/src/configscan.c index d313242..d1c35d5 100644 --- a/src/configscan.c +++ b/src/configscan.c @@ -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 +static int is_dir(char *path) +{ + WIN32_FIND_DATA fd; + CloseHandle(FindFirstFile(path, &fd)); + return (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); +} #else +#include +#include #include +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' }; -- 2.39.5