179 }
180
181 path[0] = 0;
182 rc = RegQueryValueExW(key, L"Desktop", 0, &type, (LPBYTE)path, &size);
183 if (rc != ERROR_SUCCESS || type != REG_SZ) {
184 return NULL;
185 }
186 RegCloseKey(key);
187 /* Get the parent of Desktop directory */
188 p = wcsrchr(path, L'\\');
189 if (p == NULL) {
190 return NULL;
191 }
192 *p = L'\0';
193 return _wcsdup(path);
194 }
195
196 /*
197 * Code to figure out the user's home directory using shell32.dll
198 */
199 typedef HRESULT (WINAPI *GetSpecialFolderType)(HWND, int, LPITEMIDLIST *);
200 typedef BOOL (WINAPI *GetPathFromIDListType)(LPCITEMIDLIST, LPSTR);
201
202 WCHAR*
203 getHomeFromShell32()
204 {
205 HMODULE lib = LoadLibraryW(L"SHELL32.DLL");
206 GetSpecialFolderType do_get_folder;
207 GetPathFromIDListType do_get_path;
208 HRESULT rc;
209 LPITEMIDLIST item_list = 0;
210 WCHAR *p;
211 WCHAR path[MAX_PATH+1];
212 int size = MAX_PATH+1;
213
214 if (lib == 0) {
215 // We can't load the library !!??
216 return NULL;
217 }
218
219 do_get_folder = (GetSpecialFolderType)GetProcAddress(lib, "SHGetSpecialFolderLocation");
220 do_get_path = (GetPathFromIDListType)GetProcAddress(lib, "SHGetPathFromIDListW");
221
222 if (do_get_folder == 0 || do_get_path == 0) {
223 // the library doesn't hold the right functions !!??
224 return NULL;
225 }
226
227 rc = (*do_get_folder)(NULL, CSIDL_DESKTOPDIRECTORY, &item_list);
228 if (!SUCCEEDED(rc)) {
229 // we can't find the shell folder.
230 return NULL;
231 }
232
233 path[0] = 0;
234 (*do_get_path)(item_list, (LPSTR)path);
235
236 /* Get the parent of Desktop directory */
237 p = wcsrchr(path, L'\\');
238 if (p) {
239 *p = 0;
240 }
241
242 /*
243 * We've been successful. Note that we don't free the memory allocated
244 * by ShGetSpecialFolderLocation. We only ever come through here once,
245 * and only if the registry lookup failed, so it's just not worth it.
246 *
247 * We also don't unload the SHELL32 DLL. We've paid the hit for loading
248 * it and we may need it again later.
249 */
250 return _wcsdup(path);
251 }
252
253 static boolean
254 haveMMX(void)
255 {
256 boolean mmx = 0;
257 HMODULE lib = LoadLibrary("KERNEL32");
258 if (lib != NULL) {
259 BOOL (WINAPI *isProcessorFeaturePresent)(DWORD) =
260 (BOOL (WINAPI *)(DWORD))
261 GetProcAddress(lib, "IsProcessorFeaturePresent");
262 if (isProcessorFeaturePresent != NULL)
263 mmx = isProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE);
264 FreeLibrary(lib);
265 }
266 return mmx;
267 }
268
269 static const char *
270 cpu_isalist(void)
271 {
272 SYSTEM_INFO info;
273 GetSystemInfo(&info);
274 switch (info.wProcessorArchitecture) {
275 #ifdef PROCESSOR_ARCHITECTURE_IA64
276 case PROCESSOR_ARCHITECTURE_IA64: return "ia64";
277 #endif
278 #ifdef PROCESSOR_ARCHITECTURE_AMD64
279 case PROCESSOR_ARCHITECTURE_AMD64: return "amd64";
280 #endif
281 case PROCESSOR_ARCHITECTURE_INTEL:
282 switch (info.wProcessorLevel) {
283 case 6: return haveMMX()
284 ? "pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86"
285 : "pentium_pro pentium i486 i386 i86";
286 case 5: return haveMMX()
515 sprops.cpu_endian = "big";
516 } else {
517 sprops.cpu_endian = "little";
518 }
519 }
520
521 /* CPU ISA list */
522 sprops.cpu_isalist = cpu_isalist();
523
524 /*
525 * User name
526 * We try to avoid calling GetUserName as it turns out to
527 * be surprisingly expensive on NT. It pulls in an extra
528 * 100 K of footprint.
529 */
530 {
531 WCHAR *uname = _wgetenv(L"USERNAME");
532 if (uname != NULL && wcslen(uname) > 0) {
533 sprops.user_name = _wcsdup(uname);
534 } else {
535 WCHAR buf[100];
536 int buflen = sizeof(buf);
537 sprops.user_name =
538 GetUserNameW(buf, &buflen) ? _wcsdup(buf) : L"unknown";
539 }
540 }
541
542 /*
543 * Home directory/
544 *
545 * We first look under a standard registry key. If that fails we
546 * fall back on using a SHELL32.DLL API. If that fails we use a
547 * default value.
548 *
549 * Note: To save space we want to avoid loading SHELL32.DLL
550 * unless really necessary. However if we do load it, we leave it
551 * in memory, as it may be needed again later.
552 *
553 * The normal result is that for a given user name XXX:
554 * On multi-user NT, user.home gets set to c:\winnt\profiles\XXX.
555 * On multi-user Win95, user.home gets set to c:\windows\profiles\XXX.
556 * On single-user Win95, user.home gets set to c:\windows.
557 */
558 {
559 WCHAR *homep = getHomeFromRegistry();
560 if (homep == NULL) {
616 }
617 }
618 }
619
620 sprops.unicode_encoding = "UnicodeLittle";
621 /* User TIMEZONE */
622 {
623 /*
624 * We defer setting up timezone until it's actually necessary.
625 * Refer to TimeZone.getDefault(). However, the system
626 * property is necessary to be able to be set by the command
627 * line interface -D. Here temporarily set a null string to
628 * timezone.
629 */
630 sprops.timezone = "";
631 }
632
633 /* Current directory */
634 {
635 WCHAR buf[MAX_PATH];
636 GetCurrentDirectoryW(sizeof(buf), buf);
637 sprops.user_dir = _wcsdup(buf);
638 }
639
640 sprops.file_separator = "\\";
641 sprops.path_separator = ";";
642 sprops.line_separator = "\r\n";
643
644 return &sprops;
645 }
646
647 jstring
648 GetStringPlatform(JNIEnv *env, nchar* wcstr)
649 {
650 return (*env)->NewString(env, wcstr, wcslen(wcstr));
651 }
|
179 }
180
181 path[0] = 0;
182 rc = RegQueryValueExW(key, L"Desktop", 0, &type, (LPBYTE)path, &size);
183 if (rc != ERROR_SUCCESS || type != REG_SZ) {
184 return NULL;
185 }
186 RegCloseKey(key);
187 /* Get the parent of Desktop directory */
188 p = wcsrchr(path, L'\\');
189 if (p == NULL) {
190 return NULL;
191 }
192 *p = L'\0';
193 return _wcsdup(path);
194 }
195
196 /*
197 * Code to figure out the user's home directory using shell32.dll
198 */
199 WCHAR*
200 getHomeFromShell32()
201 {
202 HRESULT rc;
203 LPITEMIDLIST item_list = 0;
204 WCHAR *p;
205 WCHAR path[MAX_PATH+1];
206 int size = MAX_PATH+1;
207
208 rc = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOPDIRECTORY, &item_list);
209 if (!SUCCEEDED(rc)) {
210 // we can't find the shell folder.
211 return NULL;
212 }
213
214 path[0] = 0;
215 SHGetPathFromIDListW(item_list, (LPWSTR)path);
216
217 /* Get the parent of Desktop directory */
218 p = wcsrchr(path, L'\\');
219 if (p) {
220 *p = 0;
221 }
222
223 /*
224 * We've been successful. Note that we don't free the memory allocated
225 * by ShGetSpecialFolderLocation. We only ever come through here once,
226 * and only if the registry lookup failed, so it's just not worth it.
227 *
228 * We also don't unload the SHELL32 DLL. We've paid the hit for loading
229 * it and we may need it again later.
230 */
231 return _wcsdup(path);
232 }
233
234 static boolean
235 haveMMX(void)
236 {
237 return IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE);
238 }
239
240 static const char *
241 cpu_isalist(void)
242 {
243 SYSTEM_INFO info;
244 GetSystemInfo(&info);
245 switch (info.wProcessorArchitecture) {
246 #ifdef PROCESSOR_ARCHITECTURE_IA64
247 case PROCESSOR_ARCHITECTURE_IA64: return "ia64";
248 #endif
249 #ifdef PROCESSOR_ARCHITECTURE_AMD64
250 case PROCESSOR_ARCHITECTURE_AMD64: return "amd64";
251 #endif
252 case PROCESSOR_ARCHITECTURE_INTEL:
253 switch (info.wProcessorLevel) {
254 case 6: return haveMMX()
255 ? "pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86"
256 : "pentium_pro pentium i486 i386 i86";
257 case 5: return haveMMX()
486 sprops.cpu_endian = "big";
487 } else {
488 sprops.cpu_endian = "little";
489 }
490 }
491
492 /* CPU ISA list */
493 sprops.cpu_isalist = cpu_isalist();
494
495 /*
496 * User name
497 * We try to avoid calling GetUserName as it turns out to
498 * be surprisingly expensive on NT. It pulls in an extra
499 * 100 K of footprint.
500 */
501 {
502 WCHAR *uname = _wgetenv(L"USERNAME");
503 if (uname != NULL && wcslen(uname) > 0) {
504 sprops.user_name = _wcsdup(uname);
505 } else {
506 DWORD buflen = 0;
507 if (GetUserNameW(NULL, &buflen) == 0 &&
508 GetLastError() == ERROR_INSUFFICIENT_BUFFER)
509 {
510 uname = (WCHAR*)malloc(buflen * sizeof(WCHAR));
511 if (uname != NULL && GetUserNameW(uname, &buflen) == 0) {
512 free(uname);
513 uname = NULL;
514 }
515 } else {
516 uname = NULL;
517 }
518 sprops.user_name = (uname != NULL) ? uname : L"unknown";
519 }
520 }
521
522 /*
523 * Home directory/
524 *
525 * We first look under a standard registry key. If that fails we
526 * fall back on using a SHELL32.DLL API. If that fails we use a
527 * default value.
528 *
529 * Note: To save space we want to avoid loading SHELL32.DLL
530 * unless really necessary. However if we do load it, we leave it
531 * in memory, as it may be needed again later.
532 *
533 * The normal result is that for a given user name XXX:
534 * On multi-user NT, user.home gets set to c:\winnt\profiles\XXX.
535 * On multi-user Win95, user.home gets set to c:\windows\profiles\XXX.
536 * On single-user Win95, user.home gets set to c:\windows.
537 */
538 {
539 WCHAR *homep = getHomeFromRegistry();
540 if (homep == NULL) {
596 }
597 }
598 }
599
600 sprops.unicode_encoding = "UnicodeLittle";
601 /* User TIMEZONE */
602 {
603 /*
604 * We defer setting up timezone until it's actually necessary.
605 * Refer to TimeZone.getDefault(). However, the system
606 * property is necessary to be able to be set by the command
607 * line interface -D. Here temporarily set a null string to
608 * timezone.
609 */
610 sprops.timezone = "";
611 }
612
613 /* Current directory */
614 {
615 WCHAR buf[MAX_PATH];
616 if (GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR), buf) != 0)
617 sprops.user_dir = _wcsdup(buf);
618 }
619
620 sprops.file_separator = "\\";
621 sprops.path_separator = ";";
622 sprops.line_separator = "\r\n";
623
624 return &sprops;
625 }
626
627 jstring
628 GetStringPlatform(JNIEnv *env, nchar* wcstr)
629 {
630 return (*env)->NewString(env, wcstr, wcslen(wcstr));
631 }
|