Commit 46783398 authored by John Doe's avatar John Doe Committed by Ano Nymous
Browse files

Win32 configuration directories support

parent 9acda993
......@@ -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!"
......
......@@ -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)
......
......@@ -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);
......
/*
* 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;
}
/*
* 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
Supports Markdown
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