From e58becdefb380b0cbee4a50d5a5de1378cab855e Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Thu, 5 Feb 2026 11:26:00 +0100 Subject: [PATCH] win32: dirs: factorize common code to get VLC folders These functions use the same code on both variants of Windows: - config_GetSysPath() - config_GetLibDir() These functions are not the same: - platform_GetUserDir() They are all internal to the core. --- src/Makefile.am | 1 + src/meson.build | 1 + src/win32/dirs-common.c | 117 ++++++++++++++++++++++++++++++++++++++++ src/win32/dirs-uap.c | 90 ------------------------------- src/win32/dirs.c | 90 ------------------------------- 5 files changed, 119 insertions(+), 180 deletions(-) create mode 100644 src/win32/dirs-common.c diff --git a/src/Makefile.am b/src/Makefile.am index 8fae994898..e964ebbe67 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -448,6 +448,7 @@ libvlccore_la_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS_libvlccore) if HAVE_WIN32 libvlccore_la_SOURCES += \ + win32/dirs-common.c \ win32/error.c \ win32/filesystem.c \ win32/netconf.c \ diff --git a/src/meson.build b/src/meson.build index 24667b53e4..2e64e18649 100644 --- a/src/meson.build +++ b/src/meson.build @@ -341,6 +341,7 @@ if host_system == 'darwin' endif elif host_system == 'windows' libvlccore_sources += [ + 'win32/dirs-common.c', 'win32/error.c', 'win32/filesystem.c', 'win32/netconf.c', diff --git a/src/win32/dirs-common.c b/src/win32/dirs-common.c new file mode 100644 index 0000000000..ea1e1720fc --- /dev/null +++ b/src/win32/dirs-common.c @@ -0,0 +1,117 @@ +/***************************************************************************** + * dirs-common.c: directories configuration + ***************************************************************************** + * Copyright (C) 2001-2010 VLC authors and VideoLAN + * Copyright © 2007-2012 Rémi Denis-Courmont + * + * Authors: Gildas Bazin + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include // FromWide +#include "../config/configuration.h" + +#include +#include + + +char *config_GetLibDir (void) +{ + /* Get our full path */ + MEMORY_BASIC_INFORMATION mbi; + if (!VirtualQuery (config_GetLibDir, &mbi, sizeof(mbi))) + goto error; + + wchar_t wpath[MAX_PATH]; + if (!GetModuleFileNameW ((HMODULE) mbi.AllocationBase, wpath, MAX_PATH)) + goto error; + + wchar_t *file = wcsrchr (wpath, L'\\'); + if (file == NULL) + goto error; + *file = L'\0'; + + return FromWide (wpath); +error: + abort (); +} + +static char *config_GetLibexecDir (void) +{ + wchar_t wpath[MAX_PATH]; + if (!GetModuleFileNameW (NULL, wpath, MAX_PATH)) + goto error; + + wchar_t *file = wcsrchr (wpath, L'\\'); + if (file == NULL) + goto error; + *file = L'\0'; + + return FromWide (wpath); +error: + abort (); +} + +static char *config_GetDataDir(void) +{ + const char *path = getenv ("VLC_DATA_PATH"); + return (path != NULL) ? strdup (path) : config_GetLibDir (); +} + +char *config_GetSysPath(vlc_sysdir_t type, const char *filename) +{ + char *dir = NULL; + + switch (type) + { + case VLC_PKG_DATA_DIR: + dir = config_GetDataDir(); + break; + case VLC_PKG_LIB_DIR: + dir = getenv ("VLC_LIB_PATH"); + if (dir) + return strdup( dir ); + dir = config_GetLibDir(); + break; + case VLC_PKG_LIBEXEC_DIR: + dir = getenv ("VLC_LIBEXEC_PATH"); + if (dir) + return strdup( dir ); + dir = config_GetLibexecDir(); + break; + case VLC_SYSDATA_DIR: + break; + case VLC_LOCALE_DIR: + dir = config_GetSysPath(VLC_PKG_DATA_DIR, "locale"); + break; + default: + vlc_assert_unreachable(); + } + + if (filename == NULL || unlikely(dir == NULL)) + return dir; + + char *path; + if (unlikely(asprintf(&path, "%s\\%s", dir, filename) == -1)) + path = NULL; + free(dir); + return path; +} diff --git a/src/win32/dirs-uap.c b/src/win32/dirs-uap.c index d5e1861a17..ed066ecdf8 100644 --- a/src/win32/dirs-uap.c +++ b/src/win32/dirs-uap.c @@ -28,11 +28,7 @@ #define COBJMACROS #define INITGUID -#ifndef UNICODE -#define UNICODE -#endif #include -#include #include "../config/configuration.h" #include @@ -153,92 +149,6 @@ end_other: return GetFolderName(folder); } -char *config_GetLibDir (void) -{ - /* Get our full path */ - MEMORY_BASIC_INFORMATION mbi; - if (!VirtualQuery (config_GetLibDir, &mbi, sizeof(mbi))) - goto error; - - wchar_t wpath[MAX_PATH]; - if (!GetModuleFileNameW ((HMODULE) mbi.AllocationBase, wpath, MAX_PATH)) - goto error; - - wchar_t *file = wcsrchr (wpath, L'\\'); - if (file == NULL) - goto error; - *file = L'\0'; - - return FromWide (wpath); -error: - abort (); -} - -static char *config_GetLibexecDir (void) -{ - wchar_t wpath[MAX_PATH]; - if (!GetModuleFileNameW (NULL, wpath, MAX_PATH)) - goto error; - - wchar_t *file = wcsrchr (wpath, L'\\'); - if (file == NULL) - goto error; - *file = L'\0'; - - return FromWide (wpath); -error: - abort (); -} - -static char *config_GetDataDir(void) -{ - const char *path = getenv ("VLC_DATA_PATH"); - return (path != NULL) ? strdup (path) : config_GetLibDir (); -} - -char *config_GetSysPath(vlc_sysdir_t type, const char *filename) -{ - char *dir = NULL; - - switch (type) - { - case VLC_PKG_DATA_DIR: - dir = config_GetDataDir(); - break; - case VLC_PKG_LIB_DIR: - dir = getenv ("VLC_LIB_PATH"); - if (dir) - return strdup( dir ); - dir = config_GetLibDir(); - break; - case VLC_PKG_LIBEXEC_DIR: - dir = getenv ("VLC_LIBEXEC_PATH"); - if (dir) - return strdup( dir ); - dir = config_GetLibexecDir(); - break; - case VLC_SYSDATA_DIR: - return NULL; - case VLC_LOCALE_DIR: - dir = config_GetSysPath(VLC_PKG_DATA_DIR, "locale"); - break; - default: - vlc_assert_unreachable(); - } - - if (unlikely(dir == NULL)) - return NULL; - - if (filename == NULL) - return dir; - - char *path; - if (unlikely(asprintf(&path, "%s\\%s", dir, filename) == -1)) - path = NULL; - free(dir); - return path; -} - static char *config_GetAppDir (void) { char *psz_dir = NULL; diff --git a/src/win32/dirs.c b/src/win32/dirs.c index 58be1128c1..078b704877 100644 --- a/src/win32/dirs.c +++ b/src/win32/dirs.c @@ -25,105 +25,15 @@ # include "config.h" #endif -#ifndef UNICODE -#define UNICODE -#endif #include -#include #include -#include "../libvlc.h" #include -#include #include "../config/configuration.h" #include -#include - - -char *config_GetLibDir (void) -{ - /* Get our full path */ - MEMORY_BASIC_INFORMATION mbi; - if (!VirtualQuery (config_GetLibDir, &mbi, sizeof(mbi))) - goto error; - - wchar_t wpath[MAX_PATH]; - if (!GetModuleFileName ((HMODULE) mbi.AllocationBase, wpath, MAX_PATH)) - goto error; - - wchar_t *file = wcsrchr (wpath, L'\\'); - if (file == NULL) - goto error; - *file = L'\0'; - - return FromWide (wpath); -error: - abort (); -} - -static char *config_GetLibexecDir (void) -{ - wchar_t wpath[MAX_PATH]; - if (!GetModuleFileNameW (NULL, wpath, MAX_PATH)) - goto error; - - wchar_t *file = wcsrchr (wpath, L'\\'); - if (file == NULL) - goto error; - *file = L'\0'; - - return FromWide (wpath); -error: - abort (); -} - -static char *config_GetDataDir(void) -{ - const char *path = getenv ("VLC_DATA_PATH"); - return (path != NULL) ? strdup (path) : config_GetLibDir (); -} - -char *config_GetSysPath(vlc_sysdir_t type, const char *filename) -{ - char *dir = NULL; - switch (type) - { - case VLC_PKG_DATA_DIR: - dir = config_GetDataDir(); - break; - case VLC_PKG_LIB_DIR: - dir = getenv ("VLC_LIB_PATH"); - if (dir) - return strdup( dir ); - dir = config_GetLibDir(); - break; - case VLC_PKG_LIBEXEC_DIR: - dir = getenv ("VLC_LIBEXEC_PATH"); - if (dir) - return strdup( dir ); - dir = config_GetLibexecDir(); - break; - case VLC_SYSDATA_DIR: - break; - case VLC_LOCALE_DIR: - dir = config_GetSysPath(VLC_PKG_DATA_DIR, "locale"); - break; - default: - vlc_assert_unreachable(); - } - - if (filename == NULL || unlikely(dir == NULL)) - return dir; - - char *path; - if (unlikely(asprintf(&path, "%s\\%s", dir, filename) == -1)) - path = NULL; - free(dir); - return path; -} static char *config_GetKnownFolder (KNOWNFOLDERID id) {