libaacs | branch: master | npzacs <npz...@gmail.com> | Fri Nov 15 10:09:40 2013 +0200| [bf5cf76fc145ed452e4d1cb439b3be3204543e64] | committer: npzacs
Merge file/dirs* from libbluray > http://git.videolan.org/gitweb.cgi/libaacs.git/?a=commit;h=bf5cf76fc145ed452e4d1cb439b3be3204543e64 --- src/file/dirs.h | 19 ++++++++++++------- src/file/dirs_darwin.c | 32 ++++++++++++++++++++++++++++---- src/file/dirs_win32.c | 42 ++++++++++++++++++++++++++---------------- src/file/dirs_xdg.c | 39 ++++++++++++++++++++++++++++++++++----- src/file/keydbcfg.c | 8 ++++---- 5 files changed, 104 insertions(+), 36 deletions(-) diff --git a/src/file/dirs.h b/src/file/dirs.h index 6b21fbd..ad60f33 100644 --- a/src/file/dirs.h +++ b/src/file/dirs.h @@ -1,6 +1,6 @@ /* - * This file is part of libaacs - * Copyright (C) 2011 VideoLAN + * This file is part of libbluray + * Copyright (C) 2011-2013 VideoLAN * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -17,8 +17,8 @@ * <http://www.gnu.org/licenses/>. */ -#ifndef AACS_DIRS_H -#define AACS_DIRS_H +#ifndef BLURAY_DIRS_H +#define BLURAY_DIRS_H #include <util/attributes.h> @@ -26,8 +26,13 @@ AACS_PRIVATE int win32_mkdir(const char *dir); #endif -AACS_PRIVATE const char *get_config_home(void); -AACS_PRIVATE const char *get_config_system(const char *dir); -AACS_PRIVATE const char *get_cache_home(void); +/* + * Config, cache and data dirs + */ + +AACS_PRIVATE const char *file_get_config_home(void); +AACS_PRIVATE const char *file_get_config_system(const char *dir); +AACS_PRIVATE const char *file_get_cache_home(void); +AACS_PRIVATE const char *file_get_data_home(void); #endif diff --git a/src/file/dirs_darwin.c b/src/file/dirs_darwin.c index a92dd5c..f28baf6 100644 --- a/src/file/dirs_darwin.c +++ b/src/file/dirs_darwin.c @@ -1,5 +1,5 @@ /* - * This file is part of libaacs + * This file is part of libbluray * Copyright (C) 2012 Konstantin Pavlov * * This library is free software; you can redistribute it and/or @@ -17,6 +17,10 @@ * <http://www.gnu.org/licenses/>. */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include "dirs.h" #include <CoreFoundation/CoreFoundation.h> @@ -30,10 +34,11 @@ #define USER_CFG_DIR "Library/Preferences" #define USER_CACHE_DIR "Library/Caches" +#define USER_DATA_DIR "Library" #define SYSTEM_CFG_DIR "/Library/Preferences" -const char *get_config_home(void) +const char *file_get_config_home(void) { static char *dir = NULL; static int init_done = 0; @@ -52,7 +57,26 @@ const char *get_config_home(void) return dir; } -const char *get_cache_home(void) +const char *file_get_data_home(void) +{ + static char *dir = NULL; + static int init_done = 0; + + if (!init_done) { + init_done = 1; + + const char *user_home = getenv("HOME"); + if (user_home && *user_home) { + return dir = str_printf("%s/%s", user_home, USER_DATA_DIR); + } + + DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n"); + } + + return dir; +} + +const char *file_get_cache_home(void) { static char *dir = NULL; static int init_done = 0; @@ -71,7 +95,7 @@ const char *get_cache_home(void) return dir; } -const char *get_config_system(const char *dir) +const char *file_get_config_system(const char *dir) { static char *dirs = NULL; // "dir1\0dir2\0...\0dirN\0\0" diff --git a/src/file/dirs_win32.c b/src/file/dirs_win32.c index 7646616..0a223f1 100644 --- a/src/file/dirs_win32.c +++ b/src/file/dirs_win32.c @@ -1,5 +1,5 @@ /* - * This file is part of libaacs + * This file is part of libbluray * Copyright (C) 2011 VideoLAN * * This library is free software; you can redistribute it and/or @@ -17,22 +17,23 @@ * <http://www.gnu.org/licenses/>. */ -#include "dirs.h" - -#include "util/logging.h" - #ifdef HAVE_CONFIG_H # include "config.h" #endif +#include "dirs.h" + +#include "util/logging.h" + #include <stdio.h> #include <string.h> #include <shlobj.h> -#include <w32api.h> +#include <windows.h> #include <limits.h> #include <direct.h> + int win32_mkdir(const char *dir) { wchar_t wdir[MAX_PATH]; @@ -41,23 +42,25 @@ int win32_mkdir(const char *dir) return _wmkdir(wdir); } -const char *get_cache_home(void) +const char *file_get_config_home(void) { - return get_config_home(); + return file_get_data_home(); } -const char *get_config_home(void) +const char *file_get_data_home(void) { - static char appdir[PATH_MAX] = ""; + static char *appdir = NULL; wchar_t wdir[MAX_PATH]; - if (*appdir) + 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); + NULL, SHGFP_TYPE_CURRENT, wdir)) { + int len = WideCharToMultiByte (CP_UTF8, 0, wdir, -1, NULL, 0, NULL, NULL); + appdir = malloc(len); + WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, len, NULL, NULL); return appdir; } @@ -65,9 +68,14 @@ const char *get_config_home(void) return NULL; } -const char *get_config_system(const char *dir) +const char *file_get_cache_home(void) +{ + return file_get_data_home(); +} + +const char *file_get_config_system(const char *dir) { - static char appdir[PATH_MAX] = ""; + static char *appdir = NULL; wchar_t wdir[MAX_PATH]; if (!dir) { @@ -79,7 +87,9 @@ const char *get_config_system(const char *dir) /* 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); + int len = WideCharToMultiByte (CP_UTF8, 0, wdir, -1, NULL, 0, NULL, NULL); + appdir = malloc(len); + WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, len, NULL, NULL); return appdir; } else { DEBUG(DBG_FILE, "Can't find common configuration directory !\n"); diff --git a/src/file/dirs_xdg.c b/src/file/dirs_xdg.c index b7bf76f..64bd8d1 100644 --- a/src/file/dirs_xdg.c +++ b/src/file/dirs_xdg.c @@ -1,6 +1,6 @@ /* - * This file is part of libaacs - * Copyright (C) 2010 npzacs + * This file is part of libbluray + * Copyright (C) 2013 Petri Hintukainen <phint...@users.sourceforge.net> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -17,6 +17,10 @@ * <http://www.gnu.org/licenses/>. */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include "dirs.h" #include "util/strutl.h" @@ -33,10 +37,11 @@ #define USER_CFG_DIR ".config" #define USER_CACHE_DIR ".cache" +#define USER_DATA_DIR ".local/share" #define SYSTEM_CFG_DIR "/etc/xdg" -const char *get_config_home(void) +const char *file_get_config_home(void) { static char *dir = NULL; static int init_done = 0; @@ -60,7 +65,31 @@ const char *get_config_home(void) return dir; } -const char *get_cache_home(void) +const char *file_get_data_home(void) +{ + static char *dir = NULL; + static int init_done = 0; + + if (!init_done) { + init_done = 1; + + const char *xdg_home = getenv("XDG_DATA_HOME"); + if (xdg_home && *xdg_home) { + return dir = str_printf("%s", xdg_home); + } + + const char *user_home = getenv("HOME"); + if (user_home && *user_home) { + return dir = str_printf("%s/%s", user_home, USER_DATA_DIR); + } + + DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n"); + } + + return dir; +} + +const char *file_get_cache_home(void) { static char *dir = NULL; static int init_done = 0; @@ -84,7 +113,7 @@ const char *get_cache_home(void) return dir; } -const char *get_config_system(const char *dir) +const char *file_get_config_system(const char *dir) { static char *dirs = NULL; // "dir1\0dir2\0...\0dirN\0\0" diff --git a/src/file/keydbcfg.c b/src/file/keydbcfg.c index de3a9e2..abdefe2 100644 --- a/src/file/keydbcfg.c +++ b/src/file/keydbcfg.c @@ -106,7 +106,7 @@ static char *_load_file(FILE *fp) static char *_config_file_user(const char *file_name) { - const char *cfg_dir = get_config_home(); + const char *cfg_dir = file_get_config_home(); if (!cfg_dir) { return NULL; @@ -147,7 +147,7 @@ static FILE *_open_cfg_file_system(const char *file_name, char **path) { const char *dir = NULL; - while (NULL != (dir = get_config_system(dir))) { + while (NULL != (dir = file_get_config_system(dir))) { char *cfg_file = str_printf("%s/%s/%s", dir, CFG_DIR, file_name); @@ -333,7 +333,7 @@ static int _load_cert_file(config_file *cf) static char *_keycache_file(const char *type, const uint8_t *disc_id) { - const char *cache_dir = get_cache_home(); + const char *cache_dir = file_get_cache_home(); char disc_id_str[41]; if (!cache_dir) { @@ -418,7 +418,7 @@ int keycache_find(const char *type, const uint8_t *disc_id, uint8_t *key, unsign static char *_cache_file(const char *name) { - const char *cache_dir = get_cache_home(); + const char *cache_dir = file_get_cache_home(); if (!cache_dir) { return NULL; _______________________________________________ libaacs-devel mailing list libaacs-devel@videolan.org https://mailman.videolan.org/listinfo/libaacs-devel