diff options
Diffstat (limited to 'osdep/path-win.c')
-rw-r--r-- | osdep/path-win.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/osdep/path-win.c b/osdep/path-win.c index 8f289ff83a..3b104cac03 100644 --- a/osdep/path-win.c +++ b/osdep/path-win.c @@ -18,23 +18,21 @@ #include <windows.h> #include <shlobj.h> #include <knownfolders.h> -#include <pthread.h> -#include "osdep/path.h" -#include "osdep/io.h" #include "options/path.h" +#include "osdep/io.h" +#include "osdep/path.h" +#include "osdep/threads.h" -// Warning: do not use PATH_MAX. Cygwin messed it up. - -static pthread_once_t path_init_once = PTHREAD_ONCE_INIT; +static mp_once path_init_once = MP_STATIC_ONCE_INITIALIZER; static char *portable_path; static char *mp_get_win_exe_dir(void *talloc_ctx) { - wchar_t w_exedir[MAX_PATH + 1] = {0}; + wchar_t *w_exedir = talloc_array(NULL, wchar_t, MP_PATH_MAX); - int len = (int)GetModuleFileNameW(NULL, w_exedir, MAX_PATH); + int len = (int)GetModuleFileNameW(NULL, w_exedir, MP_PATH_MAX); int imax = 0; for (int i = 0; i < len; i++) { if (w_exedir[i] == '\\') { @@ -42,10 +40,11 @@ static char *mp_get_win_exe_dir(void *talloc_ctx) imax = i; } } - w_exedir[imax] = '\0'; - return mp_to_utf8(talloc_ctx, w_exedir); + char *ret = mp_to_utf8(talloc_ctx, w_exedir); + talloc_free(w_exedir); + return ret; } static char *mp_get_win_exe_subdir(void *ta_ctx, const char *name) @@ -71,6 +70,11 @@ static char *mp_get_win_app_dir(void *talloc_ctx) return path ? mp_path_join(talloc_ctx, path, "mpv") : NULL; } +static char *mp_get_win_local_app_dir(void *talloc_ctx) +{ + char *path = mp_get_win_shell_dir(talloc_ctx, &FOLDERID_LocalAppData); + return path ? mp_path_join(talloc_ctx, path, "mpv") : NULL; +} static void path_init(void) { @@ -83,14 +87,20 @@ static void path_init(void) const char *mp_get_platform_path_win(void *talloc_ctx, const char *type) { - pthread_once(&path_init_once, path_init); + mp_exec_once(&path_init_once, path_init); if (portable_path) { if (strcmp(type, "home") == 0) return portable_path; + if (strcmp(type, "cache") == 0) + return mp_path_join(talloc_ctx, portable_path, "cache"); } else { if (strcmp(type, "home") == 0) return mp_get_win_app_dir(talloc_ctx); - if (strcmp(type, "old_home") == 0) + if (strcmp(type, "cache") == 0) + return mp_path_join(talloc_ctx, mp_get_win_local_app_dir(talloc_ctx), "cache"); + if (strcmp(type, "state") == 0) + return mp_get_win_local_app_dir(talloc_ctx); + if (strcmp(type, "exe_dir") == 0) return mp_get_win_exe_dir(talloc_ctx); // Not really true, but serves as a way to return a lowest-priority dir. if (strcmp(type, "global") == 0) |