Commit bf5cf76f authored by npzacs's avatar npzacs
Browse files

Merge file/dirs* from libbluray

parent 1e808321
/*
* 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
/*
* 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"
......
/*
* 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");
......
/*
* This file is part of libaacs
* Copyright (C) 2010 npzacs
* This file is part of libbluray
* Copyright (C) 2013 Petri Hintukainen <phintuka@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"
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment