- Timestamp:
- Jul 3, 2007 11:36:37 AM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 22585
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/com.h
r2981 r3387 25 25 26 26 #include "VBox/com/defs.h" 27 #include "VBox/com/string.h"28 27 29 28 namespace com … … 59 58 * Returns the VirtualBox user home directory. 60 59 * 61 * On failure, this function will return a path that caused a failure (or a62 * null stringif the faiulre is not path-related).60 * On failure, this function will return a path that caused a failure (or 61 * NULL if the faiulre is not path-related). 63 62 * 64 63 * On success, this function will try to create the returned directory if it 65 64 * doesn't exist yet. This may also fail with the corresponding status code. 66 * 67 * @param aDir Where to return the directory to. 65 * 66 * If @a aDirLen is smaller than RTPATH_MAX then there is a great chance that 67 * this method will return VERR_BUFFER_OVERFLOW. 68 * 69 * @param aDir Buffer to store the directory string in UTF-8 encoding. 70 * @param aDirLen Length of the supplied buffer including space for the 71 * terminating null character, in bytes. 68 72 * @return VBox status code. 69 73 */ 70 int GetVBoxUserHomeDirectory ( Utf8Str &aDir);74 int GetVBoxUserHomeDirectory (char *aDir, size_t aDirLen); 71 75 72 76 }; // namespace com -
trunk/include/VBox/com/string.h
r2981 r3387 43 43 * implementation details. 44 44 * 45 * @note 46 * This class follows the common ownership transfer rule, Regarding to passing 47 * strings as method parameters, this means that the instance data is always 48 * owned by the caller. 45 * This class uses COM/XPCOM-provided memory management routines to allocate 46 * and free string buffers. This makes it possible to: 47 * - use it as a type of member variables of COM/XPCOM components and pass 48 * their values to callers through component methods' output parameters 49 * using the #cloneTo() operation; 50 * - adopt (take ownership of) string buffers returned in output parameters 51 * of COM methods using the #asOutParam() operation and correctly free them 52 * afterwards. 49 53 */ 50 54 class Bstr … … 243 247 * conjunction with Bstr to simplify conversions beetween UCS2 (|BSTR|) 244 248 * and UTF8. 249 * 250 * This class uses COM/XPCOM-provided memory management routines to allocate 251 * and free string buffers. This makes it possible to: 252 * - use it as a type of member variables of COM/XPCOM components and pass 253 * their values to callers through component methods' output parameters 254 * using the #cloneTo() operation; 255 * - adopt (take ownership of) string buffers returned in output parameters 256 * of COM methods using the #asOutParam() operation and correctly free them 257 * afterwards. 245 258 */ 246 259 class Utf8Str -
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r3231 r3387 6124 6124 else 6125 6125 { 6126 Utf8Str homeDir; 6127 GetVBoxUserHomeDirectory (homeDir); 6128 6129 RTPrintf ("Updating settings files in the following VirtualBox Home Directory:\n" 6130 "\n %s\n\n", homeDir.raw()); 6131 6132 vrc = handleUpdateSettings_processDir (homeDir, mode, skipinvalid); 6126 char homeDir [RTPATH_MAX]; 6127 vrc = GetVBoxUserHomeDirectory (homeDir, sizeof (homeDir)); 6128 6129 AssertRC (vrc); 6130 if (VBOX_SUCCESS (vrc)) 6131 { 6132 RTPrintf ("Updating settings files in the following VirtualBox Home Directory:\n" 6133 "\n %s\n\n", homeDir); 6134 6135 vrc = handleUpdateSettings_processDir (homeDir, mode, skipinvalid); 6136 } 6133 6137 } 6134 6138 -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r3330 r3387 139 139 140 140 /* Get the VirtualBox home directory. */ 141 int vrc = com::GetVBoxUserHomeDirectory (unconst (mData.mHomeDir)); 142 if (VBOX_FAILURE (vrc)) 143 return setError (E_FAIL, 144 tr ("Could not create the VirtualBox home directory '%s'" 145 "(%Vrc)"), 146 mData.mHomeDir.raw(), vrc); 141 { 142 char homeDir [RTPATH_MAX]; 143 int vrc = com::GetVBoxUserHomeDirectory (homeDir, sizeof (homeDir)); 144 if (VBOX_FAILURE (vrc)) 145 return setError (E_FAIL, 146 tr ("Could not create the VirtualBox home directory '%s'" 147 "(%Vrc)"), 148 homeDir, vrc); 149 150 unconst (mData.mHomeDir) = homeDir; 151 } 147 152 148 153 /* compose the global config file name (always full path) */ -
trunk/src/VBox/Main/glue/com.cpp
r3191 r3387 133 133 } 134 134 135 int GetVBoxUserHomeDirectory ( Utf8Str &aDir)135 int GetVBoxUserHomeDirectory (char *aDir, size_t aDirLen) 136 136 { 137 AssertReturn (aDir, VERR_INVALID_POINTER); 138 AssertReturn (aDirLen > 0, VERR_BUFFER_OVERFLOW); 139 137 140 /* start with null */ 138 aDir.setNull();141 *aDir = 0; 139 142 140 143 const char *VBoxUserHome = RTEnvGet ("VBOX_USER_HOME"); … … 152 155 vrc = RTPathAbs (VBoxUserHomeUtf8, path, sizeof (path)); 153 156 if (RT_SUCCESS (vrc)) 154 aDir = path; 157 { 158 if (aDirLen < strlen (path) + 1) 159 vrc = VERR_BUFFER_OVERFLOW; 160 else 161 strcpy (aDir, path); 162 } 155 163 RTStrFree (VBoxUserHomeUtf8); 156 164 } … … 161 169 vrc = RTPathUserHome (path, sizeof (path)); 162 170 if (RT_SUCCESS (vrc)) 163 aDir = Utf8StrFmt ("%s%c%s", path, RTPATH_DELIMITER, 164 VBOX_USER_HOME_SUFFIX); 171 { 172 size_t len = 173 RTStrPrintf (aDir, aDirLen, "%s%c%s", 174 path, RTPATH_DELIMITER, VBOX_USER_HOME_SUFFIX); 175 if (len != strlen (path) + 1 + strlen (VBOX_USER_HOME_SUFFIX)) 176 vrc = VERR_BUFFER_OVERFLOW; 177 } 165 178 } 166 179 -
trunk/src/VBox/Main/glue/initterm.cpp
r2981 r3387 184 184 185 185 /* prepare paths for registry files */ 186 Utf8Str homeDir;187 int vrc = GetVBoxUserHomeDirectory (homeDir );186 char homeDir [RTPATH_MAX]; 187 int vrc = GetVBoxUserHomeDirectory (homeDir, sizeof (homeDir)); 188 188 if (RT_SUCCESS (vrc)) 189 189 { 190 Utf8Str compReg = Utf8StrFmt ("%s%c%s", homeDir.raw(), 191 RTPATH_DELIMITER, "compreg.dat"); 192 Utf8Str xptiDat = Utf8StrFmt ("%s%c%s", homeDir.raw(), 193 RTPATH_DELIMITER, "xpti.dat"); 190 char compReg [RTPATH_MAX]; 191 char xptiDat [RTPATH_MAX]; 192 193 RTStrPrintf (compReg, sizeof (compReg), "%s%c%s", 194 homeDir, RTPATH_DELIMITER, "compreg.dat"); 195 RTStrPrintf (xptiDat, sizeof (xptiDat), "%s%c%s", 196 homeDir, RTPATH_DELIMITER, "xpti.dat"); 197 194 198 dsProv = new DirectoryServiceProvider(); 195 199 if (dsProv) … … 230 234 if (RT_SUCCESS (vrc)) 231 235 { 232 nsCOMPtr <nsILocalFile> file;236 nsCOMPtr <nsILocalFile> file; 233 237 rc = NS_NewNativeLocalFile (nsEmbedCString (appDirCP), 234 238 PR_FALSE, getter_AddRefs (file)); -
trunk/src/VBox/Main/testcase/tstAPI.cpp
r2981 r3387 202 202 HRESULT rc; 203 203 204 { 205 char homeDir [RTPATH_MAX]; 206 GetVBoxUserHomeDirectory (homeDir, sizeof (homeDir)); 207 printf ("VirtualBox Home Directory = '%s'\n", homeDir); 208 } 209 204 210 printf ("Initializing COM...\n"); 205 211 … … 213 219 ComPtr <IVirtualBox> virtualBox; 214 220 ComPtr <ISession> session; 221 222 #if 0 223 // Utf8Str test 224 //////////////////////////////////////////////////////////////////////////// 225 226 Utf8Str nullUtf8Str; 227 printf ("nullUtf8Str='%s'\n", nullUtf8Str.raw()); 228 229 Utf8Str simpleUtf8Str = "simpleUtf8Str"; 230 printf ("simpleUtf8Str='%s'\n", simpleUtf8Str.raw()); 231 232 Utf8Str utf8StrFmt = Utf8StrFmt ("[0=%d]%s[1=%d]", 233 0, "utf8StrFmt", 1); 234 printf ("utf8StrFmt='%s'\n", utf8StrFmt.raw()); 235 236 #endif 215 237 216 238 printf ("Creating VirtualBox object...\n"); … … 454 476 #endif 455 477 456 #if 1478 #if 0 457 479 // find a registered hard disk by location 458 480 ///////////////////////////////////////////////////////////////////////////
Note:
See TracChangeset
for help on using the changeset viewer.