libaacs | branch: master | John Doe <j...@doe.org> | Wed Jun 22 16:56:51 2011 +0200| [964342fbf3ed6099dcf513f1ac8b01f8901f5453] | committer: npzacs
Win32 configuration directories support > http://git.videolan.org/gitweb.cgi/libaacs.git/?a=commit;h=964342fbf3ed6099dcf513f1ac8b01f8901f5453 --- configure.ac | 3 ++ src/Makefile.am | 13 +++++++- src/file/keydbcfg.c | 14 +++++++-- src/file/win32.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/file/win32.h | 28 ++++++++++++++++++ 5 files changed, 133 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 34bfe76..b5e23d7 100644 --- a/configure.ac +++ b/configure.ac @@ -19,6 +19,7 @@ case "${host_os}" in *mingw32*) SYS=mingw32 AC_DEFINE([_WIN32_WINNT], 0x0501, [Define to '0x0500' for Windows XP APIs.]) + AC_DEFINE([_WIN32_IE], 0x0501, [Define to '0x0501' for IE 5.01.]) ;; esac ;; @@ -27,6 +28,8 @@ case "${host_os}" in ;; esac +AM_CONDITIONAL(HAVE_WIN32, test "${SYS}" = "mingw32") + # messages library_not_found="Could not find required library!" function_not_found="Could not find required function!" diff --git a/src/Makefile.am b/src/Makefile.am index 8d9dba3..6b5f254 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,8 +30,6 @@ libaacs_la_SOURCES=libaacs/aacs.h \ file/file.h \ file/filesystem.h \ file/file_posix.c \ - file/xdg.c \ - file/xdg.h \ file/keydbcfg.c \ file/keydbcfg.h \ file/keydbcfg-parser.y \ @@ -42,6 +40,17 @@ libaacs_la_SOURCES=libaacs/aacs.h \ util/logging.h \ util/strutl.c \ util/strutl.h + +if HAVE_WIN32 +libaacs_la_SOURCES+= \ + file/win32.c \ + file/win32.h +else +libaacs_la_SOURCES+= \ + file/xdg.c \ + file/xdg.h +endif + libaacs_ladir= $(includedir)/libaacs libaacs_la_HEADERS= libaacs/aacs.h file/filesystem.h libaacs_la_LDFLAGS= $(LIBGCRYPT_LIBS) -version-info $(LIB_VERSION_INFO) diff --git a/src/file/keydbcfg.c b/src/file/keydbcfg.c index f8aec37..d7b663e 100644 --- a/src/file/keydbcfg.c +++ b/src/file/keydbcfg.c @@ -19,7 +19,15 @@ #include "keydbcfg.h" -#include "xdg.h" +#ifndef _WIN32 +# include "xdg.h" +# define get_config_home xdg_get_config_home +# define get_config_system xdg_get_config_system +#else +# include "win32.h" +# define get_config_home win32_get_config_home +# define get_config_system win32_get_config_system +#endif #include "util/strutl.h" #include "util/logging.h" @@ -70,7 +78,7 @@ static char *_load_file(FILE *fp) static FILE *_open_cfg_file_user(const char *file_name, char **path) { - const char *cfg_dir = xdg_get_config_home(); + const char *cfg_dir = get_config_home(); if (!cfg_dir) { return NULL; @@ -94,7 +102,7 @@ static FILE *_open_cfg_file_system(const char *file_name, char **path) { const char *dir = NULL; - while (NULL != (dir = xdg_get_config_system(dir))) { + while (NULL != (dir = get_config_system(dir))) { char *cfg_file = str_printf("%s/%s/%s", dir, CFG_DIR, file_name); diff --git a/src/file/win32.c b/src/file/win32.c new file mode 100644 index 0000000..a855796 --- /dev/null +++ b/src/file/win32.c @@ -0,0 +1,80 @@ +/* + * This file is part of libaacs + * Copyright (C) 2011 VideoLAN + * + * This library 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 library 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 library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#include "win32.h" + +#include "util/logging.h" + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <stdio.h> +#include <string.h> + +#include <shlobj.h> +#include <w32api.h> +#include <limits.h> + +const char *win32_get_config_home(void) +{ + static char appdir[PATH_MAX] = ""; + wchar_t wdir[MAX_PATH]; + + if (*appdir) + return appdir; + + /* Get the "Application Data" folder for the user */ + if (S_OK == SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, + NULL, SHGFP_TYPE_CURRENT, wdir)) { + WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, PATH_MAX, NULL, NULL); + return appdir; + } + + DEBUG(DBG_FILE, "Can't find user configuration directory !\n"); + return NULL; +} + +const char *win32_get_config_system(const char *dir) +{ + static char appdir[PATH_MAX] = ""; + wchar_t wdir[MAX_PATH]; + + if (!dir) { + // first call + + if (*appdir) + return appdir; + + /* Get the "Application Data" folder for all users */ + if (S_OK == SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, + NULL, SHGFP_TYPE_CURRENT, wdir)) { + WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, PATH_MAX, NULL, NULL); + return appdir; + } else { + DEBUG(DBG_FILE, "Can't find common configuration directory !\n"); + return NULL; + } + } else { + // next call + return NULL; + } + + return dir; +} diff --git a/src/file/win32.h b/src/file/win32.h new file mode 100644 index 0000000..a6654bf --- /dev/null +++ b/src/file/win32.h @@ -0,0 +1,28 @@ +/* + * This file is part of libaacs + * Copyright (C) 2011 VideoLAN + * + * This library 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 library 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 library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#ifndef AACS_WIN32_H +#define AACS_WIN32_H + +#include <util/attributes.h> + +AACS_PRIVATE const char *win32_get_config_home(void); +AACS_PRIVATE const char *win32_get_config_system(const char *dir); + +#endif _______________________________________________ libaacs-devel mailing list libaacs-devel@videolan.org http://mailman.videolan.org/listinfo/libaacs-devel