src/windows/native/java/lang/java_props_md.c

Print this page




 198         return NULL;
 199     }
 200     RegCloseKey(key);
 201     /* Get the parent of Desktop directory */
 202     p = wcsrchr(path, L'\\');
 203     if (p == NULL) {
 204         return NULL;
 205     }
 206     *p = L'\0';
 207     return _wcsdup(path);
 208 }
 209 
 210 /*
 211  * Code to figure out the user's home directory using shell32.dll
 212  */
 213 WCHAR*
 214 getHomeFromShell32()
 215 {
 216     HRESULT rc;
 217     LPITEMIDLIST item_list = 0;
 218     WCHAR *p;
 219     WCHAR path[MAX_PATH+1];
 220     int size = MAX_PATH+1;
 221 
 222     rc = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOPDIRECTORY, &item_list);
 223     if (!SUCCEEDED(rc)) {
 224         // we can't find the shell folder.
 225         return NULL;
 226     }
 227 
 228     path[0] = 0;
 229     SHGetPathFromIDListW(item_list, (LPWSTR)path);
 230 
 231     /* Get the parent of Desktop directory */
 232     p = wcsrchr(path, L'\\');
 233     if (p) {
 234         *p = 0;
 235     }
 236 
 237     /*
 238      * We've been successful.  Note that we don't free the memory allocated
 239      * by ShGetSpecialFolderLocation.  We only ever come through here once,
 240      * and only if the registry lookup failed, so it's just not worth it.
 241      *
 242      * We also don't unload the SHELL32 DLL.  We've paid the hit for loading
 243      * it and we may need it again later.
 244      */
 245     return _wcsdup(path);
 246 }
 247 
 248 static boolean
 249 haveMMX(void)
 250 {
 251     return IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE);
 252 }
 253 
 254 static const char *
 255 cpu_isalist(void)
 256 {


 523         } else {
 524             DWORD buflen = 0;
 525             if (GetUserNameW(NULL, &buflen) == 0 &&
 526                 GetLastError() == ERROR_INSUFFICIENT_BUFFER)
 527             {
 528                 uname = (WCHAR*)malloc(buflen * sizeof(WCHAR));
 529                 if (uname != NULL && GetUserNameW(uname, &buflen) == 0) {
 530                     free(uname);
 531                     uname = NULL;
 532                 }
 533             } else {
 534                 uname = NULL;
 535             }
 536             sprops.user_name = (uname != NULL) ? uname : L"unknown";
 537         }
 538     }
 539 
 540     /*
 541      * Home directory/
 542      *
 543      * We first look under a standard registry key.  If that fails we
 544      * fall back on using a SHELL32.DLL API.  If that fails we use a
 545      * default value.
 546      *
 547      * Note: To save space we want to avoid loading SHELL32.DLL
 548      * unless really necessary.  However if we do load it, we leave it
 549      * in memory, as it may be needed again later.
 550      *
 551      * The normal result is that for a given user name XXX:
 552      *     On multi-user NT, user.home gets set to c:\winnt\profiles\XXX.
 553      *     On multi-user Win95, user.home gets set to c:\windows\profiles\XXX.
 554      *     On single-user Win95, user.home gets set to c:\windows.
 555      */
 556     {
 557         WCHAR *homep = getHomeFromRegistry();
 558         if (homep == NULL) {
 559             homep = getHomeFromShell32();
 560             if (homep == NULL)
 561                 homep = L"C:\\";
 562         }
 563         sprops.user_home = _wcsdup(homep);
 564     }
 565 
 566     /*
 567      *  user.language
 568      *  user.script, user.country, user.variant (if user's environment specifies them)
 569      *  file.encoding
 570      *  file.encoding.pkg
 571      */
 572     {
 573         /*
 574          * query the system for the current system default locale
 575          * (which is a Windows LCID value),
 576          */
 577         LCID userDefaultLCID = GetUserDefaultLCID();
 578         LCID systemDefaultLCID = GetSystemDefaultLCID();
 579         LCID userDefaultUILang = GetUserDefaultUILanguage();
 580 




 198         return NULL;
 199     }
 200     RegCloseKey(key);
 201     /* Get the parent of Desktop directory */
 202     p = wcsrchr(path, L'\\');
 203     if (p == NULL) {
 204         return NULL;
 205     }
 206     *p = L'\0';
 207     return _wcsdup(path);
 208 }
 209 
 210 /*
 211  * Code to figure out the user's home directory using shell32.dll
 212  */
 213 WCHAR*
 214 getHomeFromShell32()
 215 {
 216     HRESULT rc;
 217     LPITEMIDLIST item_list = 0;

 218     WCHAR path[MAX_PATH+1];
 219     int size = MAX_PATH+1;
 220 
 221     rc = SHGetFolderLocation (NULL, CSIDL_PROFILE, NULL, NULL, &item_list);
 222     if (!SUCCEEDED(rc)) {
 223         // we can't find the shell folder.
 224         return NULL;
 225     }
 226 
 227     path[0] = 0;
 228     SHGetPathFromIDListW(item_list, (LPWSTR)path);
 229 






 230     /*
 231      * We've been successful.  Note that we don't free the memory allocated
 232      * by ShGetSpecialFolderLocation.  We only ever come through here once,
 233      * and only if the registry lookup failed, so it's just not worth it.
 234      *
 235      * We also don't unload the SHELL32 DLL.  We've paid the hit for loading
 236      * it and we may need it again later.
 237      */
 238     return _wcsdup(path);
 239 }
 240 
 241 static boolean
 242 haveMMX(void)
 243 {
 244     return IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE);
 245 }
 246 
 247 static const char *
 248 cpu_isalist(void)
 249 {


 516         } else {
 517             DWORD buflen = 0;
 518             if (GetUserNameW(NULL, &buflen) == 0 &&
 519                 GetLastError() == ERROR_INSUFFICIENT_BUFFER)
 520             {
 521                 uname = (WCHAR*)malloc(buflen * sizeof(WCHAR));
 522                 if (uname != NULL && GetUserNameW(uname, &buflen) == 0) {
 523                     free(uname);
 524                     uname = NULL;
 525                 }
 526             } else {
 527                 uname = NULL;
 528             }
 529             sprops.user_name = (uname != NULL) ? uname : L"unknown";
 530         }
 531     }
 532 
 533     /*
 534      * Home directory/
 535      *
 536      * Use user profile directory as home directory. If that is not found,
 537      * use C:\\ .










 538      */
 539     {
 540         WCHAR *homep = getHomeFromShell32();
 541         if (homep == NULL) {


 542             homep = L"C:\\";
 543         }
 544         sprops.user_home = _wcsdup(homep);
 545     }
 546 
 547     /*
 548      *  user.language
 549      *  user.script, user.country, user.variant (if user's environment specifies them)
 550      *  file.encoding
 551      *  file.encoding.pkg
 552      */
 553     {
 554         /*
 555          * query the system for the current system default locale
 556          * (which is a Windows LCID value),
 557          */
 558         LCID userDefaultLCID = GetUserDefaultLCID();
 559         LCID systemDefaultLCID = GetSystemDefaultLCID();
 560         LCID userDefaultUILang = GetUserDefaultUILanguage();
 561