dirs.c 2.72 KB
Newer Older
1 2 3
/*****************************************************************************
 * dirs.c: OS/2 directories configuration
 *****************************************************************************
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2010 VLC authors and VideoLAN
5 6 7
 *
 * Authors: KO Myung-Hun <komh@chollian.net>
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
8 9 10
 * This program 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
11 12 13 14
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
15 16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
17
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
18 19 20
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 22 23 24 25 26 27 28 29 30 31 32
 *****************************************************************************/

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

#include <vlc_common.h>

#include "../libvlc.h"
#include <vlc_charset.h>
#include "config/configuration.h"

33
char *config_GetLibDir (void)
34
{
35 36 37 38 39 40 41 42 43 44 45 46
    HMODULE hmod;
    CHAR    psz_path[CCHMAXPATH + 4];

    DosQueryModFromEIP( &hmod, NULL, 0, NULL, NULL, ( ULONG )system_Init );
    DosQueryModuleName( hmod, sizeof( psz_path ), psz_path );

    /* remove the DLL name */
    char *slash = strrchr( psz_path, '\\');
    if( slash == NULL )
        abort();
    strcpy(slash + 1, PACKAGE);
    return FromLocaleDup(psz_path);
47 48 49 50 51 52 53
}

/**
 * Determines the shared data directory
 *
 * @return a nul-terminated string or NULL. Use free() to release it.
 */
54
char *config_GetDataDir (void)
55
{
56 57 58
    const char *path = getenv ("VLC_DATA_PATH");
    if (path)
        return strdup (path);
59

60
    char *datadir = config_GetLibDir();
61 62 63 64 65 66
    if (datadir)
        /* replace last lib\vlc with share */
        strcpy ( datadir + strlen (datadir) - 7, "share");
    return datadir;
}

67 68 69 70 71 72 73 74 75
static char *config_GetHomeDir (void)
{
    const char *home = getenv ("HOME");
    if (home != NULL)
        return FromLocaleDup (home);

    return config_GetLibDir();
}

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
char *config_GetUserDir (vlc_userdir_t type)
{
    switch (type)
    {
        case VLC_HOME_DIR:
        case VLC_CONFIG_DIR:
        case VLC_DATA_DIR:
        case VLC_CACHE_DIR:
        case VLC_DESKTOP_DIR:
        case VLC_DOWNLOAD_DIR:
        case VLC_TEMPLATES_DIR:
        case VLC_PUBLICSHARE_DIR:
        case VLC_DOCUMENTS_DIR:
        case VLC_MUSIC_DIR:
        case VLC_PICTURES_DIR:
        case VLC_VIDEOS_DIR:
            break;
    }
94
    return config_GetHomeDir ();
95
}