| 599 | | |
|---|
| 600 | | /** |
|---|
| 601 | | * config_GetDataDir: find directory where shared data is installed |
|---|
| 602 | | * |
|---|
| 603 | | * @return a string (always succeeds). |
|---|
| 604 | | */ |
|---|
| 605 | | const char *config_GetDataDir( void ) |
|---|
| 606 | | { |
|---|
| 607 | | #if defined (WIN32) || defined (UNDER_CE) |
|---|
| 608 | | return vlc_global()->psz_vlcpath; |
|---|
| 609 | | #elif defined(__APPLE__) || defined (SYS_BEOS) |
|---|
| 610 | | static char path[PATH_MAX] = ""; |
|---|
| 611 | | |
|---|
| 612 | | if( *path == '\0' ) |
|---|
| 613 | | { |
|---|
| 614 | | snprintf( path, sizeof( path ), "%s/share", |
|---|
| 615 | | vlc_global()->psz_vlcpath ); |
|---|
| 616 | | path[sizeof( path ) - 1] = '\0'; |
|---|
| 617 | | } |
|---|
| 618 | | return path; |
|---|
| 619 | | #else |
|---|
| 620 | | return DATA_PATH; |
|---|
| 621 | | #endif |
|---|
| 622 | | } |
|---|
| 623 | | |
|---|
| 624 | | /** |
|---|
| 625 | | * Determines the system configuration directory. |
|---|
| 626 | | * |
|---|
| 627 | | * @return a string (always succeeds). |
|---|
| 628 | | */ |
|---|
| 629 | | const char *config_GetConfDir( void ) |
|---|
| 630 | | { |
|---|
| 631 | | #if defined (WIN32) || defined (UNDER_CE) |
|---|
| 632 | | return vlc_global()->psz_vlcpath; |
|---|
| 633 | | #elif defined(__APPLE__) || defined (SYS_BEOS) |
|---|
| 634 | | static char path[PATH_MAX] = ""; |
|---|
| 635 | | |
|---|
| 636 | | if( *path == '\0' ) |
|---|
| 637 | | { |
|---|
| 638 | | snprintf( path, sizeof( path ), "%s/share", /* FIXME: Duh? */ |
|---|
| 639 | | vlc_global()->psz_vlcpath ); |
|---|
| 640 | | path[sizeof( path ) - 1] = '\0'; |
|---|
| 641 | | } |
|---|
| 642 | | return path; |
|---|
| 643 | | #else |
|---|
| 644 | | return SYSCONFDIR; |
|---|
| 645 | | #endif |
|---|
| 646 | | } |
|---|
| 647 | | |
|---|
| 648 | | static char *GetDir( bool b_appdata ) |
|---|
| 649 | | { |
|---|
| 650 | | const char *psz_localhome = NULL; |
|---|
| 651 | | |
|---|
| 652 | | #if defined(WIN32) && !defined(UNDER_CE) |
|---|
| 653 | | wchar_t whomedir[MAX_PATH]; |
|---|
| 654 | | /* Get the "Application Data" folder for the current user */ |
|---|
| 655 | | if( S_OK == SHGetFolderPathW( NULL, |
|---|
| 656 | | (b_appdata ? CSIDL_APPDATA : CSIDL_PROFILE) | CSIDL_FLAG_CREATE, |
|---|
| 657 | | NULL, SHGFP_TYPE_CURRENT, whomedir ) ) |
|---|
| 658 | | return FromWide( whomedir ); |
|---|
| 659 | | |
|---|
| 660 | | #elif defined(UNDER_CE) |
|---|
| 661 | | (void)b_appdata; |
|---|
| 662 | | #ifndef CSIDL_APPDATA |
|---|
| 663 | | # define CSIDL_APPDATA 0x1A |
|---|
| 664 | | #endif |
|---|
| 665 | | |
|---|
| 666 | | wchar_t whomedir[MAX_PATH]; |
|---|
| 667 | | |
|---|
| 668 | | /* get the "Application Data" folder for the current user */ |
|---|
| 669 | | if( SHGetSpecialFolderPath( NULL, whomedir, CSIDL_APPDATA, 1 ) ) |
|---|
| 670 | | return FromWide( whomedir ); |
|---|
| 671 | | #else |
|---|
| 672 | | (void)b_appdata; |
|---|
| 673 | | #endif |
|---|
| 674 | | |
|---|
| 675 | | psz_localhome = getenv( "HOME" ); |
|---|
| 676 | | #if defined(HAVE_GETPWUID_R) |
|---|
| 677 | | char buf[sysconf (_SC_GETPW_R_SIZE_MAX)]; |
|---|
| 678 | | if( psz_localhome == NULL ) |
|---|
| 679 | | { |
|---|
| 680 | | struct passwd pw, *res; |
|---|
| 681 | | |
|---|
| 682 | | if (!getpwuid_r (getuid (), &pw, buf, sizeof (buf), &res) && res) |
|---|
| 683 | | psz_localhome = pw.pw_dir; |
|---|
| 684 | | } |
|---|
| 685 | | #endif |
|---|
| 686 | | if (psz_localhome == NULL) |
|---|
| 687 | | psz_localhome = getenv( "TMP" ); |
|---|
| 688 | | if (psz_localhome == NULL) |
|---|
| 689 | | psz_localhome = "/tmp"; |
|---|
| 690 | | |
|---|
| 691 | | return FromLocaleDup( psz_localhome ); |
|---|
| 692 | | } |
|---|
| 693 | | |
|---|
| 694 | | /** |
|---|
| 695 | | * Get the user's home directory |
|---|
| 696 | | */ |
|---|
| 697 | | char *config_GetHomeDir( void ) |
|---|
| 698 | | { |
|---|
| 699 | | return GetDir( false ); |
|---|
| 700 | | } |
|---|
| 701 | | |
|---|
| 702 | | static char *config_GetFooDir (const char *xdg_name, const char *xdg_default) |
|---|
| 703 | | { |
|---|
| 704 | | char *psz_dir; |
|---|
| 705 | | #if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS) |
|---|
| 706 | | char *psz_parent = GetDir (true); |
|---|
| 707 | | |
|---|
| 708 | | if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 ) |
|---|
| 709 | | psz_dir = NULL; |
|---|
| 710 | | |
|---|
| 711 | | free (psz_parent); |
|---|
| 712 | | (void)xdg_name; (void)xdg_default; |
|---|
| 713 | | #else |
|---|
| 714 | | char var[sizeof ("XDG__HOME") + strlen (xdg_name)]; |
|---|
| 715 | | |
|---|
| 716 | | /* XDG Base Directory Specification - Version 0.6 */ |
|---|
| 717 | | snprintf (var, sizeof (var), "XDG_%s_HOME", xdg_name); |
|---|
| 718 | | char *psz_home = getenv( var ); |
|---|
| 719 | | psz_home = psz_home ? FromLocaleDup( psz_home ) : NULL; |
|---|
| 720 | | if( psz_home ) |
|---|
| 721 | | { |
|---|
| 722 | | if( asprintf( &psz_dir, "%s/vlc", psz_home ) == -1 ) |
|---|
| 723 | | psz_dir = NULL; |
|---|
| 724 | | goto out; |
|---|
| 725 | | } |
|---|
| 726 | | |
|---|
| 727 | | /* Try HOME, then fallback to non-XDG dirs */ |
|---|
| 728 | | psz_home = config_GetHomeDir(); |
|---|
| 729 | | if( asprintf( &psz_dir, "%s/%s/vlc", psz_home, xdg_default ) == -1 ) |
|---|
| 730 | | psz_dir = NULL; |
|---|
| 731 | | |
|---|
| 732 | | out: |
|---|
| 733 | | free (psz_home); |
|---|
| 734 | | #endif |
|---|
| 735 | | return psz_dir; |
|---|
| 736 | | } |
|---|
| 737 | | |
|---|
| 738 | | /** |
|---|
| 739 | | * Get the user's VLC configuration directory |
|---|
| 740 | | */ |
|---|
| 741 | | char *config_GetUserConfDir( void ) |
|---|
| 742 | | { |
|---|
| 743 | | return config_GetFooDir ("CONFIG", ".config"); |
|---|
| 744 | | } |
|---|
| 745 | | |
|---|
| 746 | | /** |
|---|
| 747 | | * Get the user's VLC data directory |
|---|
| 748 | | * (used for stuff like the skins, custom lua modules, ...) |
|---|
| 749 | | */ |
|---|
| 750 | | char *config_GetUserDataDir( void ) |
|---|
| 751 | | { |
|---|
| 752 | | return config_GetFooDir ("DATA", ".local/share"); |
|---|
| 753 | | } |
|---|
| 754 | | |
|---|
| 755 | | /** |
|---|
| 756 | | * Get the user's VLC cache directory |
|---|
| 757 | | * (used for stuff like the modules cache, the album art cache, ...) |
|---|
| 758 | | */ |
|---|
| 759 | | char *config_GetCacheDir( void ) |
|---|
| 760 | | { |
|---|
| 761 | | return config_GetFooDir ("CACHE", ".cache"); |
|---|
| 762 | | } |
|---|