From 2ca673cca2205271fc1198e9bbf04695960cf25d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 28 Mar 2014 01:21:05 -0700 Subject: Properly handle special folder names with extended characters --- Alc/alcConfig.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'Alc/alcConfig.c') diff --git a/Alc/alcConfig.c b/Alc/alcConfig.c index 41416a18..34cf4d8f 100644 --- a/Alc/alcConfig.c +++ b/Alc/alcConfig.c @@ -291,27 +291,45 @@ static void LoadConfigFromFile(FILE *f) free(buffer); } +#ifdef _WIN32 void ReadALConfig(void) { - char buffer[PATH_MAX]; - const char *str; + WCHAR buffer[PATH_MAX]; + const WCHAR *str; FILE *f; -#ifdef _WIN32 - if(SHGetSpecialFolderPathA(NULL, buffer, CSIDL_APPDATA, FALSE) != FALSE) + if(SHGetSpecialFolderPathW(NULL, buffer, CSIDL_APPDATA, FALSE) != FALSE) { - size_t p = strlen(buffer); - snprintf(buffer+p, sizeof(buffer)-p, "\\alsoft.ini"); + size_t p = lstrlenW(buffer); + _snwprintf(buffer+p, PATH_MAX-p, L"\\alsoft.ini"); - TRACE("Loading config %s...\n", buffer); - f = al_fopen(buffer, "rt"); + TRACE("Loading config %ls...\n", buffer); + f = _wfopen(buffer, L"rt"); + if(f) + { + LoadConfigFromFile(f); + fclose(f); + } + } + + if((str=_wgetenv(L"ALSOFT_CONF")) != NULL && *str) + { + TRACE("Loading config %ls...\n", str); + f = _wfopen(str, L"rt"); if(f) { LoadConfigFromFile(f); fclose(f); } } +} #else +void ReadALConfig(void) +{ + char buffer[PATH_MAX]; + const char *str; + FILE *f; + str = "/etc/openal/alsoft.conf"; TRACE("Loading config %s...\n", str); @@ -388,7 +406,6 @@ void ReadALConfig(void) fclose(f); } } -#endif if((str=getenv("ALSOFT_CONF")) != NULL && *str) { @@ -401,6 +418,7 @@ void ReadALConfig(void) } } } +#endif void FreeALConfig(void) { -- cgit v1.2.3