dirs_win32.c 3.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * This file is part of libbluray
 * 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/>.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

24
#include "dirs.h"
25 26

#include "util/logging.h"
hpi1's avatar
hpi1 committed
27
#include "util/macro.h"
28 29 30 31 32

#include <stdio.h>
#include <string.h>

#include <shlobj.h>
Ian Curtis's avatar
Ian Curtis committed
33
#include <windows.h>
34 35 36 37
#include <limits.h>
#include <direct.h>


hpi1's avatar
hpi1 committed
38 39 40 41 42 43 44 45 46 47 48
char *win32_get_font_dir(const char *font_file)
{
    wchar_t wdir[MAX_PATH];
    if (S_OK != SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, wdir)) {
        GetWindowsDirectoryW(wdir, MAX_PATH);
        wcscat(wdir, L"\\fonts");
    }

    int   len  = WideCharToMultiByte (CP_UTF8, 0, wdir, -1, NULL, 0, NULL, NULL);
    char *path = malloc(len + strlen(font_file) + 2);
    WideCharToMultiByte(CP_UTF8, 0, wdir, -1, path, len, NULL, NULL);
49 50
    path[len - 1] = '\\';
    strcpy(path + len, font_file);
hpi1's avatar
hpi1 committed
51 52 53
    return path;
}

54
char *file_get_config_home(void)
55 56 57 58
{
    return file_get_data_home();
}

59
char *file_get_data_home(void)
60 61 62 63 64
{
    wchar_t wdir[MAX_PATH];

    /* Get the "Application Data" folder for the user */
    if (S_OK == SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
65 66
                                 NULL, SHGFP_TYPE_CURRENT, wdir)) {
        int len = WideCharToMultiByte (CP_UTF8, 0, wdir, -1, NULL, 0, NULL, NULL);
67
        char *appdir = malloc(len);
68
        WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, len, NULL, NULL);
69 70 71 72 73 74 75
        return appdir;
    }

    BD_DEBUG(DBG_FILE, "Can't find user configuration directory !\n");
    return NULL;
}

76
char *file_get_cache_home(void)
77 78 79
{
    return file_get_data_home();
}
80 81 82 83 84 85 86 87 88

const char *file_get_config_system(const char *dir)
{
    static char *appdir = NULL;
    wchar_t wdir[MAX_PATH];

    if (!dir) {
        // first call

89
        if (appdir)
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
            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)) {
            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 {
            BD_DEBUG(DBG_FILE, "Can't find common configuration directory !\n");
            return NULL;
        }
    } else {
        // next call
        return NULL;
    }

    return dir;
}