diff options
author | wm4 <wm4@nowhere> | 2013-09-18 18:42:18 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-09-18 19:08:51 +0200 |
commit | 1cb55cebf981af3983efbddccfeedc2b776ee5fd (patch) | |
tree | 548a318da53190814618ede22f3d68ca34fc1a1c /osdep/path-win.c | |
parent | 12372298a2a5fd7cd2274fcb2427581f35a6a2c1 (diff) | |
download | mpv-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 'osdep/path-win.c')
-rw-r--r-- | osdep/path-win.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/osdep/path-win.c b/osdep/path-win.c new file mode 100644 index 0000000000..80a2bb5e41 --- /dev/null +++ b/osdep/path-win.c @@ -0,0 +1,74 @@ +/* + * This file is part of mpv. + * + * mpv is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * mpv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with mpv. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <windows.h> +#include <shlobj.h> + +#include "osdep/path.h" +#include "osdep/io.h" +#include "mpvcore/path.h" + +// Warning: do not use PATH_MAX. Cygwin messed it up. + +static void get_exe_dir(wchar_t path[MAX_PATH + 1]) +{ + int len = (int)GetModuleFileNameW(NULL, path, MAX_PATH); + int imax = 0; + for (int i = 0; i < len; i++) { + if (path[i] == '\\') { + path[i] = '/'; + imax = i; + } + } + + path[imax] = '\0'; +} + +char *mp_get_win_config_path(const char *filename) +{ + wchar_t w_appdir[MAX_PATH + 1] = {0}; + wchar_t w_exedir[MAX_PATH + 1] = {0}; + char *res = NULL; + void *tmp = talloc_new(NULL); + +#ifndef __CYGWIN__ + if (SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, NULL, + SHGFP_TYPE_CURRENT, w_appdir) != S_OK) + w_appdir[0] = '\0'; +#endif + + get_exe_dir(w_exedir); + + if (filename && filename[0] && w_exedir[0]) { + char *dir = mp_to_utf8(tmp, w_exedir); + char *temp = mp_path_join(tmp, bstr0(dir), bstr0("mpv")); + res = mp_path_join(NULL, bstr0(temp), bstr0(filename)); + if (!mp_path_exists(res) || mp_path_isdir(res)) { + talloc_free(res); + res = NULL; + } + } + + if (!res && w_appdir[0]) { + char *dir = mp_to_utf8(tmp, w_appdir); + char *temp = mp_path_join(tmp, bstr0(dir), bstr0("mpv")); + res = mp_path_join(NULL, bstr0(temp), bstr0(filename)); + } + + talloc_free(tmp); + return res; +} |