summaryrefslogtreecommitdiffstats
path: root/mpvcore
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-09-18 18:42:18 +0200
committerwm4 <wm4@nowhere>2013-09-18 19:08:51 +0200
commit1cb55cebf981af3983efbddccfeedc2b776ee5fd (patch)
tree548a318da53190814618ede22f3d68ca34fc1a1c /mpvcore
parent12372298a2a5fd7cd2274fcb2427581f35a6a2c1 (diff)
downloadmpv-1cb55cebf981af3983efbddccfeedc2b776ee5fd.tar.bz2
mpv-1cb55cebf981af3983efbddccfeedc2b776ee5fd.tar.xz
path, win32: redo user configfile path handling
Remove the ifdef hell from mp_find_user_config_file(). Move the win32 specific code (for MinGW and Cygwin) to path-win.c. The behavior should be about the same, but I can't be sure due to lack of testing and because the old path.c code was hard to follow. (I expect those who care about windows will fix things, should issues pop up - sorry.) One difference is that the new code will always force MPV_HOME. It looks like the old code preferred the mpv config dir in the exe dir if it exists. Also, make sure MP_PATH_MAX has enough space, even if the equivalent wchar_t string is not 0-terminated with PATH_MAX (because apparently the winapi doesn't require this). (Actually, maybe we should just kill all uses of PATH_MAX/MP_PATH_MAX.)
Diffstat (limited to 'mpvcore')
-rw-r--r--mpvcore/path.c85
1 files changed, 15 insertions, 70 deletions
diff --git a/mpvcore/path.c b/mpvcore/path.c
index f0c8525b21..73eee15567 100644
--- a/mpvcore/path.c
+++ b/mpvcore/path.c
@@ -37,14 +37,7 @@
#include "mpvcore/path.h"
#include "talloc.h"
#include "osdep/io.h"
-
-#if defined(__MINGW32__)
-#include <windows.h>
-#include <shlobj.h>
-#elif defined(__CYGWIN__)
-#include <windows.h>
-#include <sys/cygwin.h>
-#endif
+#include "osdep/path.h"
#ifdef CONFIG_COCOA
#include "osdep/macosx_bundle.h"
@@ -77,75 +70,27 @@ char *mp_find_config_file(const char *filename)
char *mp_find_user_config_file(const char *filename)
{
- char *homedir = NULL, *buff = NULL;
- char *homepath = NULL;
-#ifdef __MINGW32__
- char *config_dir = "mpv";
- char buf[MAX_PATH];
-
- if (homepath == NULL) {
- if (SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, NULL,
- SHGFP_TYPE_CURRENT, buf) == S_OK) {
-
- homepath = buf;
- }
- }
-#else
- char *config_dir = ".mpv";
+ char *homedir = getenv("MPV_HOME");
+ char *configdir = NULL;
+ char *result = NULL;
- if (homepath == NULL) {
- homepath = getenv("HOME");
- }
+ if (!homedir) {
+#ifdef _WIN32
+ result = mp_get_win_config_path(filename);
#endif
-#if defined(__MINGW32__) || defined(__CYGWIN__)
- char *temp = NULL;
- char exedir[260];
- /* Hack to get fonts etc. loaded outside of Cygwin environment. */
- int i, imax = 0;
- int len = (int)GetModuleFileNameA(NULL, exedir, 260);
-
- for (i = 0; i < len; i++) {
- if (exedir[i] == '\\') {
- exedir[i] = '/';
- imax = i;
- }
+ homedir = getenv("HOME");
+ configdir = ".mpv";
}
- exedir[imax] = '\0';
-
- if (filename) {
- temp = mp_path_join(NULL, bstr0(exedir), bstr0(filename));
- }
-
- if (temp && mp_path_exists(temp) && !mp_path_isdir(temp)) {
- homedir = exedir;
- config_dir = "";
- }
- else
-#endif
- if ((homedir = getenv("MPV_HOME")) != NULL) {
- config_dir = "";
- } else if ((homedir = homepath) == NULL) {
-#if defined(__MINGW32__) || defined(__CYGWIN__)
- homedir = exedir;
-#else
- return NULL;
-#endif
- }
-#if defined(__MINGW32__) || defined(__CYGWIN__)
- talloc_free(temp);
-#endif
-
- if (filename) {
- char * temp = mp_path_join(NULL, bstr0(homedir), bstr0(config_dir));
- buff = mp_path_join(NULL, bstr0(temp), bstr0(filename));
+ if (!result && homedir) {
+ char *temp = mp_path_join(NULL, bstr0(homedir), bstr0(configdir));
+ result = mp_path_join(NULL, bstr0(temp), bstr0(filename));
talloc_free(temp);
- } else {
- buff = mp_path_join(NULL, bstr0(homedir), bstr0(config_dir));
}
- mp_msg(MSGT_GLOBAL, MSGL_V, "get_path('%s') -> '%s'\n", filename, buff);
- return buff;
+ mp_msg(MSGT_GLOBAL, MSGL_V, "mp_find_user_config_file('%s') -> '%s'\n",
+ filename ? filename : "(NULL)", result ? result : "(NULL)");
+ return result;
}
char *mp_find_global_config_file(const char *filename)