Changeset 7401 in vbox
- Timestamp:
- Mar 10, 2008 1:48:33 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/path-win.cpp
r5999 r7401 54 54 { 55 55 /* 56 * Convert to U CS2, call Win32 APIs, convert back.56 * Convert to UTF-16, call Win32 APIs, convert back. 57 57 */ 58 58 PRTUTF16 pwszPath; 59 int rc = RTStr Utf8ToUcs2(&pwszPath, pszPath);59 int rc = RTStrToUtf16(pszPath, &pwszPath); 60 60 if (!RT_SUCCESS(rc)) 61 61 return (rc); … … 69 69 DWORD dwAttr = GetFileAttributesW(wsz); 70 70 if (dwAttr != INVALID_FILE_ATTRIBUTES) 71 rc = RT StrUcs2ToUtf8Ex(&pszRealPath, cchRealPath, (PRTUTF16)&wsz[0]);71 rc = RTUtf16ToUtf8Ex((PRTUTF16)&wsz[0], RTSTR_MAX, &pszRealPath, cchRealPath, NULL); 72 72 else 73 73 rc = RTErrConvertFromWin32(GetLastError()); … … 78 78 rc = VERR_FILENAME_TOO_LONG; 79 79 80 RT StrUcs2Free(pwszPath);80 RTUtf16Free(pwszPath); 81 81 82 82 return rc; … … 95 95 { 96 96 /* 97 * Convert to U CS2, call Win32 API, convert back.98 */ 99 LPWSTR lpwPath;100 int rc = RTStr Utf8ToUcs2(&lpwPath, pszPath);97 * Convert to UTF-16, call Win32 API, convert back. 98 */ 99 LPWSTR pwszPath; 100 int rc = RTStrToUtf16(pszPath, &pwszPath); 101 101 if (!RT_SUCCESS(rc)) 102 102 return (rc); 103 103 104 LPWSTR lpFile;105 RTU CS2 ucsz[RTPATH_MAX];106 rc = GetFullPathNameW( lpwPath, ELEMENTS(ucsz), &ucsz[0], &lpFile);107 if (rc > 0 && rc < ELEMENTS(ucsz))108 rc = RT StrUcs2ToUtf8Ex(&pszAbsPath, cchAbsPath, &ucsz[0]);104 LPWSTR pwszFile; /* Ignored */ 105 RTUTF16 wsz[RTPATH_MAX]; 106 rc = GetFullPathNameW(pwszPath, RT_ELEMENTS(wsz), &wsz[0], &pwszFile); 107 if (rc > 0 && rc < RT_ELEMENTS(wsz)) 108 rc = RTUtf16ToUtf8Ex(&wsz[0], RTSTR_MAX, &pszAbsPath, cchAbsPath, NULL); 109 109 else if (rc <= 0) 110 110 rc = RTErrConvertFromWin32(GetLastError()); … … 112 112 rc = VERR_FILENAME_TOO_LONG; 113 113 114 RT StrUcs2Free(lpwPath);114 RTUtf16Free(pwszPath); 115 115 116 116 return rc; … … 165 165 RTDECL(int) RTPathUserHome(char *pszPath, unsigned cchPath) 166 166 { 167 RTU CS2 ucszPath[RTPATH_MAX];167 RTUTF16 wszPath[RTPATH_MAX]; 168 168 DWORD dwAttr; 169 169 … … 171 171 * There are multiple definitions for what WE think of as user home... 172 172 */ 173 if ( !GetEnvironmentVariableW(L"HOME", & ucszPath[0], RTPATH_MAX)174 || (dwAttr = GetFileAttributesW(& ucszPath[0])) == INVALID_FILE_ATTRIBUTES173 if ( !GetEnvironmentVariableW(L"HOME", &wszPath[0], RTPATH_MAX) 174 || (dwAttr = GetFileAttributesW(&wszPath[0])) == INVALID_FILE_ATTRIBUTES 175 175 || !(dwAttr & FILE_ATTRIBUTE_DIRECTORY)) 176 176 { 177 if ( !GetEnvironmentVariableW(L"USERPROFILE", & ucszPath[0], RTPATH_MAX)178 || (dwAttr = GetFileAttributesW(& ucszPath[0])) == INVALID_FILE_ATTRIBUTES177 if ( !GetEnvironmentVariableW(L"USERPROFILE", &wszPath[0], RTPATH_MAX) 178 || (dwAttr = GetFileAttributesW(&wszPath[0])) == INVALID_FILE_ATTRIBUTES 179 179 || !(dwAttr & FILE_ATTRIBUTE_DIRECTORY)) 180 180 { 181 if (!GetEnvironmentVariableW(L"HOMEDRIVE", &ucszPath[0], RTPATH_MAX)) 181 /* %HOMEDRIVE%%HOMEPATH% */ 182 if (!GetEnvironmentVariableW(L"HOMEDRIVE", &wszPath[0], RTPATH_MAX)) 182 183 return VERR_PATH_NOT_FOUND; 183 PRTUCS2 pucsz = &ucszPath[RTStrUcs2Len(&ucszPath[0])];184 if ( !GetEnvironmentVariableW(L"HOMEPATH", & ucszPath[0], RTPATH_MAX)185 || (dwAttr = GetFileAttributesW(& ucszPath[0])) == INVALID_FILE_ATTRIBUTES184 size_t const cwc = RTUtf16Len(&wszPath[0]); 185 if ( !GetEnvironmentVariableW(L"HOMEPATH", &wszPath[cwc], RTPATH_MAX - cwc) 186 || (dwAttr = GetFileAttributesW(&wszPath[0])) == INVALID_FILE_ATTRIBUTES 186 187 || !(dwAttr & FILE_ATTRIBUTE_DIRECTORY)) 187 188 return VERR_PATH_NOT_FOUND; … … 192 193 * Convert and return. 193 194 */ 194 return RTStrUcs2ToUtf8Ex(&pszPath, cchPath, & ucszPath[0]);195 return RTStrUcs2ToUtf8Ex(&pszPath, cchPath, &wszPath[0]); 195 196 } 196 197 … … 223 224 WIN32_FILE_ATTRIBUTE_DATA Data; 224 225 #ifndef RT_DONT_CONVERT_FILENAMES 225 PRTU CS2 puszPath;226 int rc = RTStrUtf8ToUcs2(&p uszPath, pszPath);226 PRTUTF16 pwszPath; 227 int rc = RTStrUtf8ToUcs2(&pwszPath, pszPath); 227 228 if (RT_FAILURE(rc)) 228 229 return rc; 229 if (!GetFileAttributesExW(p uszPath, GetFileExInfoStandard, &Data))230 if (!GetFileAttributesExW(pwszPath, GetFileExInfoStandard, &Data)) 230 231 { 231 232 rc = RTErrConvertFromWin32(GetLastError()); 232 RT StrUcs2Free(puszPath);233 RTUtf16Free(pwszPath); 233 234 return rc; 234 235 } 235 RT StrUcs2Free(puszPath);236 RTUtf16Free(pwszPath); 236 237 #else 237 238 if (!GetFileAttributesExA(pszPath, GetFileExInfoStandard, &Data)) … … 457 458 /** 458 459 * Checks if the path exists. 459 * 460 * 460 461 * Symbolic links will all be attempted resolved. 461 * 462 * 462 463 * @returns true if it exists and false if it doesn't 463 464 * @param pszPath The path to check. … … 475 476 */ 476 477 #ifndef RT_DONT_CONVERT_FILENAMES 477 PRT UCS2 puszPath;478 int rc = RTStrUtf8ToUcs2(&p uszPath, pszPath);478 PRT16UTF pwszPath; 479 int rc = RTStrUtf8ToUcs2(&pwszPath, pszPath); 479 480 if (RT_SUCCESS(rc)) 480 481 { 481 if (GetFileAttributesW(p uszPath) == INVALID_FILE_ATTRIBUTES)482 if (GetFileAttributesW(pwszPath) == INVALID_FILE_ATTRIBUTES) 482 483 rc = VERR_GENERAL_FAILURE; 483 RT StrUcs2Free(puszPath);484 RTUtf16Free(pwszPath); 484 485 } 485 486 #else
Note:
See TracChangeset
for help on using the changeset viewer.