1 /* 2 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /* Access APIs for Windows Vista and above */ 27 #ifndef _WIN32_WINNT 28 #define _WIN32_WINNT 0x0601 29 #endif 30 31 #include "jni.h" 32 #include "jni_util.h" 33 34 #include <windows.h> 35 #include <shlobj.h> 36 #include <objidl.h> 37 #include <locale.h> 38 #include <sys/types.h> 39 #include <sys/timeb.h> 40 #include <tchar.h> 41 42 #include <stdlib.h> 43 #include <Wincon.h> 44 45 #include "locale_str.h" 46 #include "java_props.h" 47 48 #ifndef VER_PLATFORM_WIN32_WINDOWS 49 #define VER_PLATFORM_WIN32_WINDOWS 1 50 #endif 51 52 #ifndef PROCESSOR_ARCHITECTURE_AMD64 53 #define PROCESSOR_ARCHITECTURE_AMD64 9 54 #endif 55 56 typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); 57 static boolean SetupI18nProps(LCID lcid, char** language, char** script, char** country, 58 char** variant, char** encoding); 59 60 #define PROPSIZE 9 // eight-letter + null terminator 61 #define SNAMESIZE 86 // max number of chars for LOCALE_SNAME is 85 62 63 static char * 64 getEncodingInternal(LCID lcid) 65 { 66 int codepage; 67 char * ret = malloc(16); 68 if (ret == NULL) { 69 return NULL; 70 } 71 72 if (GetLocaleInfo(lcid, 73 LOCALE_IDEFAULTANSICODEPAGE, 74 ret+2, 14) == 0) { 75 codepage = 1252; 76 } else { 77 codepage = atoi(ret+2); 78 } 79 80 switch (codepage) { 81 case 0: 82 strcpy(ret, "UTF-8"); 83 break; 84 case 874: /* 9:Thai */ 85 case 932: /* 10:Japanese */ 86 case 949: /* 12:Korean Extended Wansung */ 87 case 950: /* 13:Chinese (Taiwan, Hongkong, Macau) */ 88 case 1361: /* 15:Korean Johab */ 89 ret[0] = 'M'; 90 ret[1] = 'S'; 91 break; 92 case 936: 93 strcpy(ret, "GBK"); 94 break; 95 case 54936: 96 strcpy(ret, "GB18030"); 97 break; 98 default: 99 ret[0] = 'C'; 100 ret[1] = 'p'; 101 break; 102 } 103 104 //Traditional Chinese Windows should use MS950_HKSCS_XP as the 105 //default encoding, if HKSCS patch has been installed. 106 // "old" MS950 0xfa41 -> u+e001 107 // "new" MS950 0xfa41 -> u+92db 108 if (strcmp(ret, "MS950") == 0) { 109 TCHAR mbChar[2] = {(char)0xfa, (char)0x41}; 110 WCHAR unicodeChar; 111 MultiByteToWideChar(CP_ACP, 0, mbChar, 2, &unicodeChar, 1); 112 if (unicodeChar == 0x92db) { 113 strcpy(ret, "MS950_HKSCS_XP"); 114 } 115 } else { 116 //SimpChinese Windows should use GB18030 as the default 117 //encoding, if gb18030 patch has been installed (on windows 118 //2000/XP, (1)Codepage 54936 will be available 119 //(2)simsun18030.ttc will exist under system fonts dir ) 120 if (strcmp(ret, "GBK") == 0 && IsValidCodePage(54936)) { 121 char systemPath[MAX_PATH + 1]; 122 char* gb18030Font = "\\FONTS\\SimSun18030.ttc"; 123 FILE *f = NULL; 124 if (GetWindowsDirectory(systemPath, MAX_PATH + 1) != 0 && 125 strlen(systemPath) + strlen(gb18030Font) < MAX_PATH + 1) { 126 strcat(systemPath, "\\FONTS\\SimSun18030.ttc"); 127 if ((f = fopen(systemPath, "r")) != NULL) { 128 fclose(f); 129 strcpy(ret, "GB18030"); 130 } 131 } 132 } 133 } 134 135 return ret; 136 } 137 138 static char* getConsoleEncoding() 139 { 140 char* buf = malloc(16); 141 int cp; 142 if (buf == NULL) { 143 return NULL; 144 } 145 cp = GetConsoleCP(); 146 if (cp >= 874 && cp <= 950) 147 sprintf(buf, "ms%d", cp); 148 else 149 sprintf(buf, "cp%d", cp); 150 return buf; 151 } 152 153 // Exported entries for AWT 154 DllExport const char * 155 getEncodingFromLangID(LANGID langID) 156 { 157 return getEncodingInternal(MAKELCID(langID, SORT_DEFAULT)); 158 } 159 160 // Returns BCP47 Language Tag 161 DllExport const char * 162 getJavaIDFromLangID(LANGID langID) 163 { 164 char * elems[5]; // lang, script, ctry, variant, encoding 165 char * ret; 166 int index; 167 168 ret = malloc(SNAMESIZE); 169 if (ret == NULL) { 170 return NULL; 171 } 172 173 for (index = 0; index < 5; index++) { 174 elems[index] = NULL; 175 } 176 177 if (SetupI18nProps(MAKELCID(langID, SORT_DEFAULT), 178 &(elems[0]), &(elems[1]), &(elems[2]), &(elems[3]), &(elems[4]))) { 179 180 // there always is the "language" tag 181 strcpy(ret, elems[0]); 182 183 // append other elements, if any 184 for (index = 1; index < 4; index++) { 185 if ((elems[index])[0] != '\0') { 186 strcat(ret, "-"); 187 strcat(ret, elems[index]); 188 } 189 } 190 } else { 191 free(ret); 192 ret = NULL; 193 } 194 195 for (index = 0; index < 5; index++) { 196 if (elems[index] != NULL) { 197 free(elems[index]); 198 } 199 } 200 201 return ret; 202 } 203 204 /* 205 * Code to figure out the user's home directory using shell32.dll 206 */ 207 WCHAR* 208 getHomeFromShell32() 209 { 210 /* 211 * Note that we don't free the memory allocated 212 * by getHomeFromShell32. 213 */ 214 static WCHAR *u_path = NULL; 215 if (u_path == NULL) { 216 HRESULT hr; 217 218 /* 219 * SHELL32 DLL is delay load DLL and we can use the trick with 220 * __try/__except block. 221 */ 222 __try { 223 /* 224 * For Windows Vista and later (or patched MS OS) we need to use 225 * [SHGetKnownFolderPath] call to avoid MAX_PATH length limitation. 226 * Shell32.dll (version 6.0.6000 or later) 227 */ 228 hr = SHGetKnownFolderPath(&FOLDERID_Profile, KF_FLAG_DONT_VERIFY, NULL, &u_path); 229 } __except(EXCEPTION_EXECUTE_HANDLER) { 230 /* Exception: no [SHGetKnownFolderPath] entry */ 231 hr = E_FAIL; 232 } 233 234 if (FAILED(hr)) { 235 WCHAR path[MAX_PATH+1]; 236 237 /* fallback solution for WinXP and Windows 2000 */ 238 hr = SHGetFolderPathW(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, path); 239 if (FAILED(hr)) { 240 /* we can't find the shell folder. */ 241 u_path = NULL; 242 } else { 243 /* Just to be sure about the path length until Windows Vista approach. 244 * [S_FALSE] could not be returned due to [CSIDL_FLAG_DONT_VERIFY] flag and UNICODE version. 245 */ 246 path[MAX_PATH] = 0; 247 u_path = _wcsdup(path); 248 } 249 } 250 } 251 return u_path; 252 } 253 254 static boolean 255 haveMMX(void) 256 { 257 return IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE); 258 } 259 260 static const char * 261 cpu_isalist(void) 262 { 263 SYSTEM_INFO info; 264 GetSystemInfo(&info); 265 switch (info.wProcessorArchitecture) { 266 #ifdef PROCESSOR_ARCHITECTURE_IA64 267 case PROCESSOR_ARCHITECTURE_IA64: return "ia64"; 268 #endif 269 #ifdef PROCESSOR_ARCHITECTURE_AMD64 270 case PROCESSOR_ARCHITECTURE_AMD64: return "amd64"; 271 #endif 272 case PROCESSOR_ARCHITECTURE_INTEL: 273 switch (info.wProcessorLevel) { 274 case 6: return haveMMX() 275 ? "pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86" 276 : "pentium_pro pentium i486 i386 i86"; 277 case 5: return haveMMX() 278 ? "pentium+mmx pentium i486 i386 i86" 279 : "pentium i486 i386 i86"; 280 case 4: return "i486 i386 i86"; 281 case 3: return "i386 i86"; 282 } 283 } 284 return NULL; 285 } 286 287 static boolean 288 SetupI18nProps(LCID lcid, char** language, char** script, char** country, 289 char** variant, char** encoding) { 290 /* script */ 291 char tmp[SNAMESIZE]; 292 *script = malloc(PROPSIZE); 293 if (*script == NULL) { 294 return FALSE; 295 } 296 if (GetLocaleInfo(lcid, 297 LOCALE_SNAME, tmp, SNAMESIZE) == 0 || 298 sscanf(tmp, "%*[a-z\\-]%1[A-Z]%[a-z]", *script, &((*script)[1])) == 0 || 299 strlen(*script) != 4) { 300 (*script)[0] = '\0'; 301 } 302 303 /* country */ 304 *country = malloc(PROPSIZE); 305 if (*country == NULL) { 306 return FALSE; 307 } 308 if (GetLocaleInfo(lcid, 309 LOCALE_SISO3166CTRYNAME, *country, PROPSIZE) == 0 && 310 GetLocaleInfo(lcid, 311 LOCALE_SISO3166CTRYNAME2, *country, PROPSIZE) == 0) { 312 (*country)[0] = '\0'; 313 } 314 315 /* language */ 316 *language = malloc(PROPSIZE); 317 if (*language == NULL) { 318 return FALSE; 319 } 320 if (GetLocaleInfo(lcid, 321 LOCALE_SISO639LANGNAME, *language, PROPSIZE) == 0 && 322 GetLocaleInfo(lcid, 323 LOCALE_SISO639LANGNAME2, *language, PROPSIZE) == 0) { 324 /* defaults to en_US */ 325 strcpy(*language, "en"); 326 strcpy(*country, "US"); 327 } 328 329 /* variant */ 330 *variant = malloc(PROPSIZE); 331 if (*variant == NULL) { 332 return FALSE; 333 } 334 (*variant)[0] = '\0'; 335 336 /* handling for Norwegian */ 337 if (strcmp(*language, "nb") == 0) { 338 strcpy(*language, "no"); 339 strcpy(*country , "NO"); 340 } else if (strcmp(*language, "nn") == 0) { 341 strcpy(*language, "no"); 342 strcpy(*country , "NO"); 343 strcpy(*variant, "NY"); 344 } 345 346 /* encoding */ 347 *encoding = getEncodingInternal(lcid); 348 if (*encoding == NULL) { 349 return FALSE; 350 } 351 return TRUE; 352 } 353 354 // GetVersionEx is deprecated; disable the warning until a replacement is found 355 #pragma warning(disable : 4996) 356 java_props_t * 357 GetJavaProperties(JNIEnv* env) 358 { 359 static java_props_t sprops = {0}; 360 int majorVersion; 361 int minorVersion; 362 363 if (sprops.line_separator) { 364 return &sprops; 365 } 366 367 /* AWT properties */ 368 sprops.awt_toolkit = "sun.awt.windows.WToolkit"; 369 370 /* tmp dir */ 371 { 372 WCHAR tmpdir[MAX_PATH + 1]; 373 /* we might want to check that this succeed */ 374 GetTempPathW(MAX_PATH + 1, tmpdir); 375 sprops.tmp_dir = _wcsdup(tmpdir); 376 } 377 378 /* Printing properties */ 379 sprops.printerJob = "sun.awt.windows.WPrinterJob"; 380 381 /* Java2D properties */ 382 sprops.graphics_env = "sun.awt.Win32GraphicsEnvironment"; 383 384 { /* This is used only for debugging of font problems. */ 385 WCHAR *path = _wgetenv(L"JAVA2D_FONTPATH"); 386 sprops.font_dir = (path != NULL) ? _wcsdup(path) : NULL; 387 } 388 389 /* OS properties */ 390 { 391 char buf[100]; 392 boolean is_workstation; 393 boolean is_64bit; 394 DWORD platformId; 395 { 396 OSVERSIONINFOEX ver; 397 ver.dwOSVersionInfoSize = sizeof(ver); 398 GetVersionEx((OSVERSIONINFO *) &ver); 399 majorVersion = ver.dwMajorVersion; 400 minorVersion = ver.dwMinorVersion; 401 is_workstation = (ver.wProductType == VER_NT_WORKSTATION); 402 platformId = ver.dwPlatformId; 403 sprops.patch_level = _strdup(ver.szCSDVersion); 404 } 405 406 { 407 SYSTEM_INFO si; 408 ZeroMemory(&si, sizeof(SYSTEM_INFO)); 409 GetNativeSystemInfo(&si); 410 411 is_64bit = (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64); 412 } 413 do { 414 // Read the major and minor version number from kernel32.dll 415 VS_FIXEDFILEINFO *file_info; 416 WCHAR kernel32_path[MAX_PATH]; 417 DWORD version_size; 418 LPTSTR version_info; 419 UINT len, ret; 420 421 // Get the full path to \Windows\System32\kernel32.dll and use that for 422 // determining what version of Windows we're running on. 423 len = MAX_PATH - (UINT)strlen("\\kernel32.dll") - 1; 424 ret = GetSystemDirectoryW(kernel32_path, len); 425 if (ret == 0 || ret > len) { 426 break; 427 } 428 wcsncat(kernel32_path, L"\\kernel32.dll", MAX_PATH - ret); 429 430 version_size = GetFileVersionInfoSizeW(kernel32_path, NULL); 431 if (version_size == 0) { 432 break; 433 } 434 435 version_info = (LPTSTR)malloc(version_size); 436 if (version_info == NULL) { 437 break; 438 } 439 440 if (!GetFileVersionInfoW(kernel32_path, 0, version_size, version_info)) { 441 free(version_info); 442 break; 443 } 444 445 if (!VerQueryValueW(version_info, L"\\", (LPVOID*)&file_info, &len)) { 446 free(version_info); 447 break; 448 } 449 majorVersion = HIWORD(file_info->dwProductVersionMS); 450 minorVersion = LOWORD(file_info->dwProductVersionMS); 451 free(version_info); 452 } while (0); 453 454 /* 455 * From msdn page on OSVERSIONINFOEX, current as of this 456 * writing, decoding of dwMajorVersion and dwMinorVersion. 457 * 458 * Operating system dwMajorVersion dwMinorVersion 459 * ================== ============== ============== 460 * 461 * Windows 95 4 0 462 * Windows 98 4 10 463 * Windows ME 4 90 464 * Windows 3.51 3 51 465 * Windows NT 4.0 4 0 466 * Windows 2000 5 0 467 * Windows XP 32 bit 5 1 468 * Windows Server 2003 family 5 2 469 * Windows XP 64 bit 5 2 470 * where ((&ver.wServicePackMinor) + 2) = 1 471 * and si.wProcessorArchitecture = 9 472 * Windows Vista family 6 0 (VER_NT_WORKSTATION) 473 * Windows Server 2008 6 0 (!VER_NT_WORKSTATION) 474 * Windows 7 6 1 (VER_NT_WORKSTATION) 475 * Windows Server 2008 R2 6 1 (!VER_NT_WORKSTATION) 476 * Windows 8 6 2 (VER_NT_WORKSTATION) 477 * Windows Server 2012 6 2 (!VER_NT_WORKSTATION) 478 * Windows Server 2012 R2 6 3 (!VER_NT_WORKSTATION) 479 * Windows 10 10 0 (VER_NT_WORKSTATION) 480 * Windows Server 2016 10 0 (!VER_NT_WORKSTATION) 481 * 482 * This mapping will presumably be augmented as new Windows 483 * versions are released. 484 */ 485 switch (platformId) { 486 case VER_PLATFORM_WIN32_WINDOWS: 487 if (majorVersion == 4) { 488 switch (minorVersion) { 489 case 0: sprops.os_name = "Windows 95"; break; 490 case 10: sprops.os_name = "Windows 98"; break; 491 case 90: sprops.os_name = "Windows Me"; break; 492 default: sprops.os_name = "Windows 9X (unknown)"; break; 493 } 494 } else { 495 sprops.os_name = "Windows 9X (unknown)"; 496 } 497 break; 498 case VER_PLATFORM_WIN32_NT: 499 if (majorVersion <= 4) { 500 sprops.os_name = "Windows NT"; 501 } else if (majorVersion == 5) { 502 switch (minorVersion) { 503 case 0: sprops.os_name = "Windows 2000"; break; 504 case 1: sprops.os_name = "Windows XP"; break; 505 case 2: 506 /* 507 * From MSDN OSVERSIONINFOEX and SYSTEM_INFO documentation: 508 * 509 * "Because the version numbers for Windows Server 2003 510 * and Windows XP 6u4 bit are identical, you must also test 511 * whether the wProductType member is VER_NT_WORKSTATION. 512 * and si.wProcessorArchitecture is 513 * PROCESSOR_ARCHITECTURE_AMD64 (which is 9) 514 * If it is, the operating system is Windows XP 64 bit; 515 * otherwise, it is Windows Server 2003." 516 */ 517 if (is_workstation && is_64bit) { 518 sprops.os_name = "Windows XP"; /* 64 bit */ 519 } else { 520 sprops.os_name = "Windows 2003"; 521 } 522 break; 523 default: sprops.os_name = "Windows NT (unknown)"; break; 524 } 525 } else if (majorVersion == 6) { 526 /* 527 * See table in MSDN OSVERSIONINFOEX documentation. 528 */ 529 if (is_workstation) { 530 switch (minorVersion) { 531 case 0: sprops.os_name = "Windows Vista"; break; 532 case 1: sprops.os_name = "Windows 7"; break; 533 case 2: sprops.os_name = "Windows 8"; break; 534 case 3: sprops.os_name = "Windows 8.1"; break; 535 default: sprops.os_name = "Windows NT (unknown)"; 536 } 537 } else { 538 switch (minorVersion) { 539 case 0: sprops.os_name = "Windows Server 2008"; break; 540 case 1: sprops.os_name = "Windows Server 2008 R2"; break; 541 case 2: sprops.os_name = "Windows Server 2012"; break; 542 case 3: sprops.os_name = "Windows Server 2012 R2"; break; 543 default: sprops.os_name = "Windows NT (unknown)"; 544 } 545 } 546 } else if (majorVersion == 10) { 547 if (is_workstation) { 548 switch (minorVersion) { 549 case 0: sprops.os_name = "Windows 10"; break; 550 default: sprops.os_name = "Windows NT (unknown)"; 551 } 552 } else { 553 switch (minorVersion) { 554 case 0: sprops.os_name = "Windows Server 2016"; break; 555 default: sprops.os_name = "Windows NT (unknown)"; 556 } 557 } 558 } else { 559 sprops.os_name = "Windows NT (unknown)"; 560 } 561 break; 562 default: 563 sprops.os_name = "Windows (unknown)"; 564 break; 565 } 566 sprintf(buf, "%d.%d", majorVersion, minorVersion); 567 sprops.os_version = _strdup(buf); 568 #if _M_AMD64 569 sprops.os_arch = "amd64"; 570 #elif _X86_ 571 sprops.os_arch = "x86"; 572 #else 573 sprops.os_arch = "unknown"; 574 #endif 575 sprops.desktop = "windows"; 576 } 577 578 /* Endianness of platform */ 579 { 580 unsigned int endianTest = 0xff000000; 581 if (((char*)(&endianTest))[0] != 0) { 582 sprops.cpu_endian = "big"; 583 } else { 584 sprops.cpu_endian = "little"; 585 } 586 } 587 588 /* CPU ISA list */ 589 sprops.cpu_isalist = cpu_isalist(); 590 591 /* 592 * User name 593 * We try to avoid calling GetUserName as it turns out to 594 * be surprisingly expensive on NT. It pulls in an extra 595 * 100 K of footprint. 596 */ 597 { 598 WCHAR *uname = _wgetenv(L"USERNAME"); 599 if (uname != NULL && wcslen(uname) > 0) { 600 sprops.user_name = _wcsdup(uname); 601 } else { 602 DWORD buflen = 0; 603 if (GetUserNameW(NULL, &buflen) == 0 && 604 GetLastError() == ERROR_INSUFFICIENT_BUFFER) 605 { 606 uname = (WCHAR*)malloc(buflen * sizeof(WCHAR)); 607 if (uname != NULL && GetUserNameW(uname, &buflen) == 0) { 608 free(uname); 609 uname = NULL; 610 } 611 } else { 612 uname = NULL; 613 } 614 sprops.user_name = (uname != NULL) ? uname : L"unknown"; 615 } 616 } 617 618 /* 619 * Home directory 620 * 621 * The normal result is that for a given user name XXX: 622 * On multi-user NT, user.home gets set to c:\winnt\profiles\XXX. 623 * On multi-user Win95, user.home gets set to c:\windows\profiles\XXX. 624 * On single-user Win95, user.home gets set to c:\windows. 625 */ 626 { 627 WCHAR *homep = getHomeFromShell32(); 628 if (homep == NULL) { 629 homep = L"C:\\"; 630 } 631 sprops.user_home = homep; 632 } 633 634 /* 635 * user.language 636 * user.script, user.country, user.variant (if user's environment specifies them) 637 * file.encoding 638 */ 639 { 640 /* 641 * query the system for the current system default locale 642 * (which is a Windows LCID value), 643 */ 644 LCID userDefaultLCID = GetUserDefaultLCID(); 645 LCID systemDefaultLCID = GetSystemDefaultLCID(); 646 LCID userDefaultUILang = GetUserDefaultUILanguage(); 647 648 { 649 char * display_encoding; 650 HANDLE hStdOutErr; 651 652 // Windows UI Language selection list only cares "language" 653 // information of the UI Language. For example, the list 654 // just lists "English" but it actually means "en_US", and 655 // the user cannot select "en_GB" (if exists) in the list. 656 // So, this hack is to use the user LCID region information 657 // for the UI Language, if the "language" portion of those 658 // two locales are the same. 659 if (PRIMARYLANGID(LANGIDFROMLCID(userDefaultLCID)) == 660 PRIMARYLANGID(LANGIDFROMLCID(userDefaultUILang))) { 661 userDefaultUILang = userDefaultLCID; 662 } 663 664 SetupI18nProps(userDefaultUILang, 665 &sprops.language, 666 &sprops.script, 667 &sprops.country, 668 &sprops.variant, 669 &display_encoding); 670 SetupI18nProps(userDefaultLCID, 671 &sprops.format_language, 672 &sprops.format_script, 673 &sprops.format_country, 674 &sprops.format_variant, 675 &sprops.encoding); 676 SetupI18nProps(userDefaultUILang, 677 &sprops.display_language, 678 &sprops.display_script, 679 &sprops.display_country, 680 &sprops.display_variant, 681 &display_encoding); 682 683 sprops.sun_jnu_encoding = getEncodingInternal(systemDefaultLCID); 684 if (LANGIDFROMLCID(userDefaultLCID) == 0x0c04 && majorVersion == 6) { 685 // MS claims "Vista has built-in support for HKSCS-2004. 686 // All of the HKSCS-2004 characters have Unicode 4.1. 687 // PUA code point assignments". But what it really means 688 // is that the HKSCS-2004 is ONLY supported in Unicode. 689 // Test indicates the MS950 in its zh_HK locale is a 690 // "regular" MS950 which does not handle HKSCS-2004 at 691 // all. Set encoding to MS950_HKSCS. 692 sprops.encoding = "MS950_HKSCS"; 693 sprops.sun_jnu_encoding = "MS950_HKSCS"; 694 } 695 696 hStdOutErr = GetStdHandle(STD_OUTPUT_HANDLE); 697 if (hStdOutErr != INVALID_HANDLE_VALUE && 698 GetFileType(hStdOutErr) == FILE_TYPE_CHAR) { 699 sprops.sun_stdout_encoding = getConsoleEncoding(); 700 } 701 hStdOutErr = GetStdHandle(STD_ERROR_HANDLE); 702 if (hStdOutErr != INVALID_HANDLE_VALUE && 703 GetFileType(hStdOutErr) == FILE_TYPE_CHAR) { 704 if (sprops.sun_stdout_encoding != NULL) 705 sprops.sun_stderr_encoding = sprops.sun_stdout_encoding; 706 else 707 sprops.sun_stderr_encoding = getConsoleEncoding(); 708 } 709 } 710 } 711 712 sprops.unicode_encoding = "UnicodeLittle"; 713 /* User TIMEZONE */ 714 { 715 /* 716 * We defer setting up timezone until it's actually necessary. 717 * Refer to TimeZone.getDefault(). However, the system 718 * property is necessary to be able to be set by the command 719 * line interface -D. Here temporarily set a null string to 720 * timezone. 721 */ 722 sprops.timezone = ""; 723 } 724 725 /* Current directory */ 726 { 727 WCHAR buf[MAX_PATH]; 728 if (GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR), buf) != 0) 729 sprops.user_dir = _wcsdup(buf); 730 } 731 732 sprops.file_separator = "\\"; 733 sprops.path_separator = ";"; 734 sprops.line_separator = "\r\n"; 735 736 return &sprops; 737 } 738 739 jstring 740 GetStringPlatform(JNIEnv *env, nchar* wcstr) 741 { 742 return (*env)->NewString(env, wcstr, (jsize)wcslen(wcstr)); 743 }