VirtualBox

Changeset 44545 in vbox


Ignore:
Timestamp:
Feb 5, 2013 2:19:49 PM (12 years ago)
Author:
vboxsync
Message:

Main: prefer <HOME>/.config/VirtualBox over <HOME>/.VirtualBox for new users on platforms where XDG is relevant.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/com.cpp

    r44528 r44545  
    5555#include <VBox/version.h>
    5656
     57const char *apcszUserHome[] =
    5758#ifdef RT_OS_DARWIN
    58 # define VBOX_USER_HOME_SUFFIX   "Library/VirtualBox"
     59{ "Library/VirtualBox" };
     60#elif defined RT_OS_WINDOWS
     61{ ".VirtualBox" };
    5962#else
    60 # define VBOX_USER_HOME_SUFFIX   ".VirtualBox"
     63{ ".config/VirtualBox", ".VirtualBox" };
    6164#endif
    6265
     
    182185#endif // VBOX_WITH_XPCOM
    183186
     187static int composeHomePath(char *aDir, size_t aDirLen,
     188                           const char *pcszBase)
     189{
     190    int vrc;
     191    if (RTPathStartsWithRoot(pcszBase))
     192        vrc = RTStrCopy(aDir, aDirLen, pcszBase);
     193    else
     194    {
     195        /* compose the config directory (full path) */
     196        /** @todo r=bird: RTPathUserHome doesn't necessarily return a
     197         * full (abs) path like the comment above seems to indicate. */
     198        vrc = RTPathUserHome(aDir, aDirLen);
     199        if (RT_SUCCESS(vrc))
     200            vrc = RTPathAppend(aDir, aDirLen, pcszBase);
     201    }
     202    return vrc;
     203}
     204
    184205int GetVBoxUserHomeDirectory(char *aDir, size_t aDirLen, bool fCreateDir)
    185206{
     
    194215    if (RT_SUCCESS(vrc) || vrc == VERR_ENV_VAR_NOT_FOUND)
    195216    {
     217        bool fFound = false;
    196218        if (RT_SUCCESS(vrc))
    197219        {
     
    201223        else
    202224        {
    203             /* compose the config directory (full path) */
    204             /** @todo r=bird: RTPathUserHome doesn't necessarily return a full (abs) path
    205              *        like the comment above seems to indicate. */
    206             vrc = RTPathUserHome(aDir, aDirLen);
    207             if (RT_SUCCESS(vrc))
    208                 vrc = RTPathAppend(aDir, aDirLen, VBOX_USER_HOME_SUFFIX);
     225#if !defined(RT_OS_WINDOWS) && !defined(RT_OS_DARWIN)
     226            const char *pcszConfigHome = RTEnvGet("XDG_CONFIG_HOME");
     227            if (pcszConfigHome && pcszConfigHome[0])
     228                apcszUserHome[0] = pcszConfigHome;
     229#endif
     230            for (unsigned i = 0; i < RT_ELEMENTS(apcszUserHome); ++i)
     231            {
     232                vrc = composeHomePath(aDir, aDirLen, apcszUserHome[i]);
     233                if (RTDirExists(aDir))
     234                {
     235                    fFound = true;
     236                    break;
     237                }
     238            }
     239            if (!fFound)
     240                vrc = composeHomePath(aDir, aDirLen, apcszUserHome[0]);
    209241        }
    210242
    211243        /* ensure the home directory exists */
    212244        if (RT_SUCCESS(vrc))
    213             if (!RTDirExists(aDir) && fCreateDir)
     245            if (!fFound && fCreateDir)
    214246                vrc = RTDirCreateFullPath(aDir, 0700);
    215247    }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette