- Timestamp:
- Jan 20, 2010 5:42:26 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56786
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/com.cpp
r25942 r25944 1 1 /* $Id$ */ 2 3 2 /** @file 4 3 * MS COM / XPCOM Abstraction Layer … … 23 22 #if !defined (VBOX_WITH_XPCOM) 24 23 25 # include <objbase.h>24 # include <objbase.h> 26 25 27 26 #else /* !defined (VBOX_WITH_XPCOM) */ 28 27 29 # include <stdlib.h>28 # include <stdlib.h> 30 29 31 # include <nsCOMPtr.h>32 # include <nsIServiceManagerUtils.h>30 # include <nsCOMPtr.h> 31 # include <nsIServiceManagerUtils.h> 33 32 34 # include <nsIInterfaceInfo.h>35 # include <nsIInterfaceInfoManager.h>33 # include <nsIInterfaceInfo.h> 34 # include <nsIInterfaceInfoManager.h> 36 35 37 36 #endif /* !defined (VBOX_WITH_XPCOM) */ … … 52 51 53 52 #ifdef RT_OS_DARWIN 54 # define VBOX_USER_HOME_SUFFIX "Library/VirtualBox"53 # define VBOX_USER_HOME_SUFFIX "Library/VirtualBox" 55 54 #else 56 # define VBOX_USER_HOME_SUFFIX ".VirtualBox"55 # define VBOX_USER_HOME_SUFFIX ".VirtualBox" 57 56 #endif 58 57 … … 62 61 { 63 62 64 void GetInterfaceNameByIID 63 void GetInterfaceNameByIID(const GUID &aIID, BSTR *aName) 65 64 { 66 Assert 65 Assert(aName); 67 66 if (!aName) 68 67 return; … … 70 69 *aName = NULL; 71 70 72 #if !defined 71 #if !defined(VBOX_WITH_XPCOM) 73 72 74 73 LONG rc; 75 74 LPOLESTR iidStr = NULL; 76 if (StringFromIID 75 if (StringFromIID(aIID, &iidStr) == S_OK) 77 76 { 78 77 HKEY ifaceKey; 79 rc = RegOpenKeyExW 80 78 rc = RegOpenKeyExW(HKEY_CLASSES_ROOT, L"Interface", 79 0, KEY_QUERY_VALUE, &ifaceKey); 81 80 if (rc == ERROR_SUCCESS) 82 81 { 83 82 HKEY iidKey; 84 rc = RegOpenKeyExW 83 rc = RegOpenKeyExW(ifaceKey, iidStr, 0, KEY_QUERY_VALUE, &iidKey); 85 84 if (rc == ERROR_SUCCESS) 86 85 { 87 86 /* determine the size and type */ 88 87 DWORD sz, type; 89 rc = RegQueryValueExW 88 rc = RegQueryValueExW(iidKey, NULL, NULL, &type, NULL, &sz); 90 89 if (rc == ERROR_SUCCESS && type == REG_SZ) 91 90 { 92 91 /* 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); 97 94 if (rc != ERROR_SUCCESS) 98 95 { 99 SysFreeString 96 SysFreeString(*aName); 100 97 aName = NULL; 101 98 } 102 99 } 103 RegCloseKey 100 RegCloseKey(iidKey); 104 101 } 105 RegCloseKey 102 RegCloseKey(ifaceKey); 106 103 } 107 CoTaskMemFree 104 CoTaskMemFree(iidStr); 108 105 } 109 106 … … 111 108 112 109 nsresult rv; 113 nsCOMPtr 114 do_GetService 110 nsCOMPtr<nsIInterfaceInfoManager> iim = 111 do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID, &rv); 115 112 if (NS_SUCCEEDED(rv)) 116 113 { 117 nsCOMPtr 118 rv = iim->GetInfoForIID (&aIID, getter_AddRefs(iinfo));114 nsCOMPtr<nsIInterfaceInfo> iinfo; 115 rv = iim->GetInfoForIID(&aIID, getter_AddRefs(iinfo)); 119 116 if (NS_SUCCEEDED(rv)) 120 117 { 121 118 const char *iname = NULL; 122 iinfo->GetNameShared 119 iinfo->GetNameShared(&iname); 123 120 char *utf8IName = NULL; 124 if (RT_SUCCESS(RTStrCurrentCPToUtf8 121 if (RT_SUCCESS(RTStrCurrentCPToUtf8(&utf8IName, iname))) 125 122 { 126 123 PRTUTF16 utf16IName = NULL; 127 if (RT_SUCCESS(RTStrToUtf16 124 if (RT_SUCCESS(RTStrToUtf16(utf8IName, &utf16IName))) 128 125 { 129 *aName = SysAllocString 130 RTUtf16Free 126 *aName = SysAllocString((OLECHAR *) utf16IName); 127 RTUtf16Free(utf16IName); 131 128 } 132 RTStrFree 129 RTStrFree(utf8IName); 133 130 } 134 131 } … … 146 143 *aDir = 0; 147 144 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) 154 148 { 155 /* get the full path name */156 char *VBoxUserHomeUtf8 = NULL;157 vrc = RTStrCurrentCPToUtf8(&VBoxUserHomeUtf8, VBoxUserHome);158 149 if (RT_SUCCESS(vrc)) 159 150 { 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); 161 160 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); 169 162 } 163 164 /* ensure the home directory exists */ 165 if (RT_SUCCESS(vrc)) 166 if (!RTDirExists(aDir)) 167 vrc = RTDirCreateFullPath(aDir, 0777); 170 168 } 171 else172 {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);188 169 189 170 return vrc; … … 196 177 197 178 /* static */ 198 const nsID *SafeGUIDArray::nsIDRef::Empty = (const nsID *) 179 const nsID *SafeGUIDArray::nsIDRef::Empty = (const nsID *)Guid::Empty.raw(); 199 180 200 181 #endif /* (VBOX_WITH_XPCOM) */
Note:
See TracChangeset
for help on using the changeset viewer.