diff --git a/osdep/path-win.c b/osdep/path-win.c index a735fad069..d9042ee0e7 100644 --- a/osdep/path-win.c +++ b/osdep/path-win.c @@ -17,6 +17,7 @@ #include #include +#include #include #include "osdep/path.h" @@ -52,20 +53,21 @@ static char *mp_get_win_exe_subdir(void *ta_ctx, const char *name) return talloc_asprintf(ta_ctx, "%s/%s", mp_get_win_exe_dir(ta_ctx), name); } -static char *mp_get_win_shell_dir(void *talloc_ctx, int folder) +static char *mp_get_win_shell_dir(void *talloc_ctx, REFKNOWNFOLDERID folder) { - wchar_t w_appdir[MAX_PATH + 1] = {0}; + wchar_t *w_appdir = NULL; - if (SHGetFolderPathW(NULL, folder|CSIDL_FLAG_CREATE, NULL, - SHGFP_TYPE_CURRENT, w_appdir) != S_OK) + if (FAILED(SHGetKnownFolderPath(folder, KF_FLAG_CREATE, NULL, &w_appdir))) return NULL; - return mp_to_utf8(talloc_ctx, w_appdir); + char *appdir = mp_to_utf8(talloc_ctx, w_appdir); + CoTaskMemFree(w_appdir); + return appdir; } static char *mp_get_win_app_dir(void *talloc_ctx) { - char *path = mp_get_win_shell_dir(talloc_ctx, CSIDL_APPDATA); + char *path = mp_get_win_shell_dir(talloc_ctx, &FOLDERID_RoamingAppData); return path ? mp_path_join(talloc_ctx, path, "mpv") : NULL; } @@ -95,6 +97,6 @@ const char *mp_get_platform_path_win(void *talloc_ctx, const char *type) return mp_get_win_exe_subdir(talloc_ctx, "mpv"); } if (strcmp(type, "desktop") == 0) - return mp_get_win_shell_dir(talloc_ctx, CSIDL_DESKTOPDIRECTORY); + return mp_get_win_shell_dir(talloc_ctx, &FOLDERID_Desktop); return NULL; }