aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-02-23 17:58:34 -0800
committerChris Robinson <[email protected]>2014-02-23 17:58:34 -0800
commit0e51becd58743ac0ed252220e2d5cf2ee56a1b84 (patch)
treecdfa67ba7e9adecd42b9a6380886c11867b8e842 /Alc
parent46b2115bfbf514648331401312f50b15395af1fa (diff)
Search system-dependant data paths for relative hrtf table filenames
Diffstat (limited to 'Alc')
-rw-r--r--Alc/hrtf.c127
1 files changed, 126 insertions, 1 deletions
diff --git a/Alc/hrtf.c b/Alc/hrtf.c
index 49bb97a3..7f8ae4ce 100644
--- a/Alc/hrtf.c
+++ b/Alc/hrtf.c
@@ -18,10 +18,23 @@
* Or go to http://www.gnu.org/copyleft/lgpl.html
*/
+#ifdef _WIN32
+#ifdef __MINGW32__
+#define _WIN32_IE 0x501
+#else
+#define _WIN32_IE 0x400
+#endif
+#endif
+
#include "config.h"
#include <stdlib.h>
#include <ctype.h>
+#include <limits.h>
+
+#ifdef _WIN32_IE
+#include <shlobj.h>
+#endif
#include "AL/al.h"
#include "AL/alc.h"
@@ -31,8 +44,12 @@
#ifndef PATH_MAX
+#ifdef MAX_PATH
+#define PATH_MAX MAX_PATH
+#else
#define PATH_MAX 4096
#endif
+#endif
/* Current data set limits defined by the makehrtf utility. */
@@ -661,6 +678,114 @@ static struct Hrtf *LoadHrtf01(FILE *f, ALuint deviceRate)
return NULL;
}
+static FILE *OpenDataFile(const char *fname, const char *subdir)
+{
+ char buffer[PATH_MAX] = "";
+ FILE *f;
+
+#ifdef _WIN32
+ /* If the path is absolute, open it directly. */
+ if(fname[0] != '\0' && fname[1] == ':' && (fname[2] == '\\' || fname[2] == '/'))
+ {
+ if((f=fopen(fname, "rb")) != NULL)
+ {
+ TRACE("Opened %s\n", fname);
+ return f;
+ }
+ WARN("Could not open %s\n", fname);
+ }
+ else
+ {
+ static const int ids[2] = { CSIDL_APPDATA, CSIDL_COMMON_APPDATA };
+ int i;
+
+ for(i = 0;i < 2;i++)
+ {
+ size_t len;
+
+ if(SHGetSpecialFolderPathA(NULL, buffer, ids[i], FALSE) == FALSE)
+ continue;
+
+ len = strlen(buffer);
+ if(len > 0 && (buffer[len-1] == '\\' || buffer[len-1] == '/'))
+ buffer[--len] = '\0';
+ snprintf(buffer+len, sizeof(buffer)-len, "/%s/%s", subdir, fname);
+ len = strlen(buffer);
+ while(len > 0)
+ {
+ --len;
+ if(buffer[len] == '/')
+ buffer[len] = '\\';
+ }
+
+ if((f=fopen(buffer, "rb")) != NULL)
+ {
+ TRACE("Opened %s\n", buffer);
+ return f;
+ }
+ WARN("Could not open %s\n", buffer);
+ }
+ }
+#else
+ const char *str, *next;
+
+ if(fname[0] == '/')
+ {
+ if((f=fopen(fname, "rb")) != NULL)
+ {
+ TRACE("Opened %s\n", fname);
+ return f;
+ }
+ WARN("Could not open %s\n", fname);
+ }
+ if((str=getenv("XDG_DATA_HOME")) != NULL && str[0] != '\0')
+ snprintf(buffer, sizeof(buffer), "%s/%s/%s", str, subdir, fname);
+ else if((str=getenv("HOME")) != NULL && str[0] != '\0')
+ snprintf(buffer, sizeof(buffer), "%s/.local/share/%s/%s", str, subdir, fname);
+ if(buffer[0])
+ {
+ if((f=fopen(buffer, "rb")) != NULL)
+ {
+ TRACE("Opened %s\n", buffer);
+ return f;
+ }
+ WARN("Could not open %s\n", buffer);
+ }
+
+ if((str=getenv("XDG_DATA_DIRS")) == NULL || str[0] == '\0')
+ str = " /usr/local/share/:/usr/share/";
+
+ next = str;
+ while((str=next) != NULL && str[0] != '\0')
+ {
+ size_t len;
+ next = strchr(str, ':');
+
+ if(!next)
+ len = strlen(str);
+ else
+ {
+ len = next - str;
+ next++;
+ }
+
+ if(len > sizeof(buffer)-1)
+ len = sizeof(buffer)-1;
+ strncpy(buffer, str, len);
+ buffer[len] = '\0';
+ snprintf(buffer+len, sizeof(buffer)-len, "/%s/%s", subdir, fname);
+
+ if((f=fopen(buffer, "rb")) != NULL)
+ {
+ TRACE("Opened %s\n", buffer);
+ return f;
+ }
+ WARN("Could not open %s\n", buffer);
+ }
+#endif
+
+ return NULL;
+}
static struct Hrtf *LoadHrtf(ALuint deviceRate)
{
@@ -716,7 +841,7 @@ static struct Hrtf *LoadHrtf(ALuint deviceRate)
continue;
TRACE("Loading %s...\n", fname);
- f = fopen(fname, "rb");
+ f = OpenDataFile(fname, "openal/hrtf");
if(f == NULL)
{
ERR("Could not open %s\n", fname);