VirtualBox

Changeset 25944 in vbox for trunk/src


Ignore:
Timestamp:
Jan 20, 2010 5:42:26 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56786
Message:

*: RTEnv usage cleanup - avoid RTEnvGet() as it doesn't necessarily return UTF-8 encoded strings.

File:
1 edited

Legend:

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

    r25942 r25944  
    11/* $Id$ */
    2 
    32/** @file
    43 * MS COM / XPCOM Abstraction Layer
     
    2322#if !defined (VBOX_WITH_XPCOM)
    2423
    25 #include <objbase.h>
     24# include <objbase.h>
    2625
    2726#else /* !defined (VBOX_WITH_XPCOM) */
    2827
    29 #include <stdlib.h>
     28# include <stdlib.h>
    3029
    31 #include <nsCOMPtr.h>
    32 #include <nsIServiceManagerUtils.h>
     30# include <nsCOMPtr.h>
     31# include <nsIServiceManagerUtils.h>
    3332
    34 #include <nsIInterfaceInfo.h>
    35 #include <nsIInterfaceInfoManager.h>
     33# include <nsIInterfaceInfo.h>
     34# include <nsIInterfaceInfoManager.h>
    3635
    3736#endif /* !defined (VBOX_WITH_XPCOM) */
     
    5251
    5352#ifdef RT_OS_DARWIN
    54 #define VBOX_USER_HOME_SUFFIX   "Library/VirtualBox"
     53# define VBOX_USER_HOME_SUFFIX   "Library/VirtualBox"
    5554#else
    56 #define VBOX_USER_HOME_SUFFIX   ".VirtualBox"
     55# define VBOX_USER_HOME_SUFFIX   ".VirtualBox"
    5756#endif
    5857
     
    6261{
    6362
    64 void GetInterfaceNameByIID (const GUID &aIID, BSTR *aName)
     63void GetInterfaceNameByIID(const GUID &aIID, BSTR *aName)
    6564{
    66     Assert (aName);
     65    Assert(aName);
    6766    if (!aName)
    6867        return;
     
    7069    *aName = NULL;
    7170
    72 #if !defined (VBOX_WITH_XPCOM)
     71#if !defined(VBOX_WITH_XPCOM)
    7372
    7473    LONG rc;
    7574    LPOLESTR iidStr = NULL;
    76     if (StringFromIID (aIID, &iidStr) == S_OK)
     75    if (StringFromIID(aIID, &iidStr) == S_OK)
    7776    {
    7877        HKEY ifaceKey;
    79         rc = RegOpenKeyExW (HKEY_CLASSES_ROOT, L"Interface",
    80                             0, KEY_QUERY_VALUE, &ifaceKey);
     78        rc = RegOpenKeyExW(HKEY_CLASSES_ROOT, L"Interface",
     79                           0, KEY_QUERY_VALUE, &ifaceKey);
    8180        if (rc == ERROR_SUCCESS)
    8281        {
    8382            HKEY iidKey;
    84             rc = RegOpenKeyExW (ifaceKey, iidStr, 0, KEY_QUERY_VALUE, &iidKey);
     83            rc = RegOpenKeyExW(ifaceKey, iidStr, 0, KEY_QUERY_VALUE, &iidKey);
    8584            if (rc == ERROR_SUCCESS)
    8685            {
    8786                /* determine the size and type */
    8887                DWORD sz, type;
    89                 rc = RegQueryValueExW (iidKey, NULL, NULL, &type, NULL, &sz);
     88                rc = RegQueryValueExW(iidKey, NULL, NULL, &type, NULL, &sz);
    9089                if (rc == ERROR_SUCCESS && type == REG_SZ)
    9190                {
    9291                    /* query the value to BSTR */
    93                     *aName = SysAllocStringLen (NULL, (sz + 1) /
    94                                                       sizeof (TCHAR) + 1);
    95                     rc = RegQueryValueExW (iidKey, NULL, NULL, NULL,
    96                                            (LPBYTE) *aName, &sz);
     92                    *aName = SysAllocStringLen(NULL, (sz + 1) / sizeof(TCHAR) + 1);
     93                    rc = RegQueryValueExW(iidKey, NULL, NULL, NULL, (LPBYTE) *aName, &sz);
    9794                    if (rc != ERROR_SUCCESS)
    9895                    {
    99                         SysFreeString (*aName);
     96                        SysFreeString(*aName);
    10097                        aName = NULL;
    10198                    }
    10299                }
    103                 RegCloseKey (iidKey);
     100                RegCloseKey(iidKey);
    104101            }
    105             RegCloseKey (ifaceKey);
     102            RegCloseKey(ifaceKey);
    106103        }
    107         CoTaskMemFree (iidStr);
     104        CoTaskMemFree(iidStr);
    108105    }
    109106
     
    111108
    112109    nsresult rv;
    113     nsCOMPtr <nsIInterfaceInfoManager> iim =
    114         do_GetService (NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID, &rv);
     110    nsCOMPtr<nsIInterfaceInfoManager> iim =
     111        do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID, &rv);
    115112    if (NS_SUCCEEDED(rv))
    116113    {
    117         nsCOMPtr <nsIInterfaceInfo> iinfo;
    118         rv = iim->GetInfoForIID (&aIID, getter_AddRefs (iinfo));
     114        nsCOMPtr<nsIInterfaceInfo> iinfo;
     115        rv = iim->GetInfoForIID(&aIID, getter_AddRefs(iinfo));
    119116        if (NS_SUCCEEDED(rv))
    120117        {
    121118            const char *iname = NULL;
    122             iinfo->GetNameShared (&iname);
     119            iinfo->GetNameShared(&iname);
    123120            char *utf8IName = NULL;
    124             if (RT_SUCCESS(RTStrCurrentCPToUtf8 (&utf8IName, iname)))
     121            if (RT_SUCCESS(RTStrCurrentCPToUtf8(&utf8IName, iname)))
    125122            {
    126123                PRTUTF16 utf16IName = NULL;
    127                 if (RT_SUCCESS(RTStrToUtf16 (utf8IName, &utf16IName)))
     124                if (RT_SUCCESS(RTStrToUtf16(utf8IName, &utf16IName)))
    128125                {
    129                     *aName = SysAllocString ((OLECHAR *) utf16IName);
    130                     RTUtf16Free (utf16IName);
     126                    *aName = SysAllocString((OLECHAR *) utf16IName);
     127                    RTUtf16Free(utf16IName);
    131128                }
    132                 RTStrFree (utf8IName);
     129                RTStrFree(utf8IName);
    133130            }
    134131        }
     
    146143    *aDir = 0;
    147144
    148     const char *VBoxUserHome = RTEnvGet("VBOX_USER_HOME");
    149 
    150     char path [RTPATH_MAX];
    151     int vrc = VINF_SUCCESS;
    152 
    153     if (VBoxUserHome)
     145    char szTmp[RTPATH_MAX];
     146    int vrc = RTEnvGetEx(RTENV_DEFAULT, "VBOX_USER_HOME", szTmp, sizeof(szTmp), NULL);
     147    if (RT_SUCCESS(vrc) || vrc == VERR_ENV_VAR_NOT_FOUND)
    154148    {
    155         /* get the full path name */
    156         char *VBoxUserHomeUtf8 = NULL;
    157         vrc = RTStrCurrentCPToUtf8(&VBoxUserHomeUtf8, VBoxUserHome);
    158149        if (RT_SUCCESS(vrc))
    159150        {
    160             vrc = RTPathAbs(VBoxUserHomeUtf8, path, sizeof (path));
     151            /* get the full path name */
     152            vrc = RTPathAbs(szTmp, aDir, aDirLen);
     153        }
     154        else
     155        {
     156            /* compose the config directory (full path) */
     157            /** @todo r=bird: RTPathUserHome doesn't necessarily return a full (abs) path
     158             *        like the comment above seems to indicate. */
     159            vrc = RTPathUserHome(aDir, aDirLen);
    161160            if (RT_SUCCESS(vrc))
    162             {
    163                 if (aDirLen < strlen(path) + 1)
    164                     vrc = VERR_BUFFER_OVERFLOW;
    165                 else
    166                     strcpy(aDir, path);
    167             }
    168             RTStrFree(VBoxUserHomeUtf8);
     161                vrc = RTPathAppend(aDir, aDirLen, VBOX_USER_HOME_SUFFIX);
    169162        }
     163
     164        /* ensure the home directory exists */
     165        if (RT_SUCCESS(vrc))
     166            if (!RTDirExists(aDir))
     167                vrc = RTDirCreateFullPath(aDir, 0777);
    170168    }
    171     else
    172     {
    173         /* compose the config directory (full path) */
    174         vrc = RTPathUserHome(path, sizeof(path));
    175         if (RT_SUCCESS(vrc))
    176         {
    177             size_t len = RTStrPrintf(aDir, aDirLen, "%s%c%s",
    178                                      path, RTPATH_DELIMITER, VBOX_USER_HOME_SUFFIX);
    179             if (len != strlen(path) + 1 + strlen (VBOX_USER_HOME_SUFFIX))
    180                 vrc = VERR_BUFFER_OVERFLOW;
    181         }
    182     }
    183 
    184     /* ensure the home directory exists */
    185     if (RT_SUCCESS(vrc))
    186         if (!RTDirExists(aDir))
    187             vrc = RTDirCreateFullPath(aDir, 0777);
    188169
    189170    return vrc;
     
    196177
    197178/* static */
    198 const nsID *SafeGUIDArray::nsIDRef::Empty = (const nsID *) Guid::Empty.raw();
     179const nsID *SafeGUIDArray::nsIDRef::Empty = (const nsID *)Guid::Empty.raw();
    199180
    200181#endif /* (VBOX_WITH_XPCOM) */
Note: See TracChangeset for help on using the changeset viewer.

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