VirtualBox

source: vbox/trunk/src/VBox/Main/glue/com.cpp@ 2981

Last change on this file since 2981 was 2981, checked in by vboxsync, 17 years ago

InnoTek -> innotek: all the headers and comments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1/** @file
2 * MS COM / XPCOM Abstraction Layer
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * If you received this file as part of a commercial VirtualBox
17 * distribution, then only the terms of your commercial VirtualBox
18 * license agreement apply instead of the previous paragraph.
19 */
20
21#if !defined (VBOX_WITH_XPCOM)
22
23#include <objbase.h>
24
25#else /* !defined (VBOX_WITH_XPCOM) */
26
27#include <stdlib.h>
28
29#include <nsCOMPtr.h>
30#include <nsIServiceManagerUtils.h>
31
32#include <nsIInterfaceInfo.h>
33#include <nsIInterfaceInfoManager.h>
34
35#endif /* !defined (VBOX_WITH_XPCOM) */
36
37#include <iprt/param.h>
38#include <iprt/path.h>
39#include <iprt/dir.h>
40#include <iprt/env.h>
41#include <iprt/string.h>
42
43#include <VBox/err.h>
44
45#include "VBox/com/com.h"
46#include "VBox/com/assert.h"
47
48
49#ifdef __DARWIN__
50#define VBOX_USER_HOME_SUFFIX "Library/VirtualBox"
51#else
52#define VBOX_USER_HOME_SUFFIX ".VirtualBox"
53#endif
54
55
56namespace com
57{
58
59void GetInterfaceNameByIID (const GUID &aIID, BSTR *aName)
60{
61 Assert (aName);
62 if (!aName)
63 return;
64
65 *aName = NULL;
66
67#if !defined (VBOX_WITH_XPCOM)
68
69 LONG rc;
70 LPOLESTR iidStr = NULL;
71 if (StringFromIID (aIID, &iidStr) == S_OK)
72 {
73 HKEY ifaceKey;
74 rc = RegOpenKeyExW (HKEY_CLASSES_ROOT, L"Interface",
75 0, KEY_QUERY_VALUE, &ifaceKey);
76 if (rc == ERROR_SUCCESS)
77 {
78 HKEY iidKey;
79 rc = RegOpenKeyExW (ifaceKey, iidStr, 0, KEY_QUERY_VALUE, &iidKey);
80 if (rc == ERROR_SUCCESS)
81 {
82 /* determine the size and type */
83 DWORD sz, type;
84 rc = RegQueryValueExW (iidKey, NULL, NULL, &type, NULL, &sz);
85 if (rc == ERROR_SUCCESS && type == REG_SZ)
86 {
87 /* query the value to BSTR */
88 *aName = SysAllocStringLen (NULL, (sz + 1) /
89 sizeof (TCHAR) + 1);
90 rc = RegQueryValueExW (iidKey, NULL, NULL, NULL,
91 (LPBYTE) *aName, &sz);
92 if (rc != ERROR_SUCCESS)
93 {
94 SysFreeString (*aName);
95 aName = NULL;
96 }
97 }
98 RegCloseKey (iidKey);
99 }
100 RegCloseKey (ifaceKey);
101 }
102 CoTaskMemFree (iidStr);
103 }
104
105#else /* !defined (VBOX_WITH_XPCOM) */
106
107 nsresult rv;
108 nsCOMPtr <nsIInterfaceInfoManager> iim =
109 do_GetService (NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID, &rv);
110 if (NS_SUCCEEDED (rv))
111 {
112 nsCOMPtr <nsIInterfaceInfo> iinfo;
113 rv = iim->GetInfoForIID (&aIID, getter_AddRefs (iinfo));
114 if (NS_SUCCEEDED (rv))
115 {
116 const char *iname = NULL;
117 iinfo->GetNameShared (&iname);
118 char *utf8IName = NULL;
119 if (VBOX_SUCCESS (RTStrCurrentCPToUtf8 (&utf8IName, iname)))
120 {
121 PRTUCS2 ucs2IName = NULL;
122 if (VBOX_SUCCESS (RTStrUtf8ToUcs2 (&ucs2IName, utf8IName)))
123 {
124 *aName = SysAllocString ((OLECHAR *) ucs2IName);
125 RTStrUcs2Free (ucs2IName);
126 }
127 RTStrFree (utf8IName);
128 }
129 }
130 }
131
132#endif /* !defined (VBOX_WITH_XPCOM) */
133}
134
135int GetVBoxUserHomeDirectory (Utf8Str &aDir)
136{
137 /* start with null */
138 aDir.setNull();
139
140 const char *VBoxUserHome = RTEnvGet ("VBOX_USER_HOME");
141
142 char path [RTPATH_MAX];
143 int vrc = VINF_SUCCESS;
144
145 if (VBoxUserHome)
146 {
147 /* get the full path name */
148 char *VBoxUserHomeUtf8 = NULL;
149 vrc = RTStrCurrentCPToUtf8 (&VBoxUserHomeUtf8, VBoxUserHome);
150 if (RT_SUCCESS (vrc))
151 {
152 vrc = RTPathAbs (VBoxUserHomeUtf8, path, sizeof (path));
153 if (RT_SUCCESS (vrc))
154 aDir = path;
155 RTStrFree (VBoxUserHomeUtf8);
156 }
157 }
158 else
159 {
160 /* compose the config directory (full path) */
161 vrc = RTPathUserHome (path, sizeof (path));
162 aDir = Utf8StrFmt ("%s%c%s", path, RTPATH_DELIMITER,
163 VBOX_USER_HOME_SUFFIX);
164 }
165
166 /* ensure the home directory exists */
167 if (RT_SUCCESS (vrc))
168 if (!RTDirExists (aDir))
169 vrc = RTDirCreateFullPath (aDir, 0777);
170
171 return vrc;
172}
173
174}; // namespace com
Note: See TracBrowser for help on using the repository browser.

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