Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/java.base/windows/native/libjava/java_props_md.c
67769 views
1
/*
2
* Copyright (c) 1998, 2021, 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 = 0;
67
char * ret = malloc(16);
68
if (ret == NULL) {
69
return NULL;
70
}
71
72
if (lcid == 0) { // for sun.jnu.encoding
73
codepage = GetACP();
74
_itoa_s(codepage, ret + 2, 14, 10);
75
} else if (GetLocaleInfo(lcid,
76
LOCALE_IDEFAULTANSICODEPAGE,
77
ret + 2, 14) != 0) {
78
codepage = atoi(ret + 2);
79
}
80
81
switch (codepage) {
82
case 0:
83
case 65001:
84
strcpy(ret, "UTF-8");
85
break;
86
case 874: /* 9:Thai */
87
case 932: /* 10:Japanese */
88
case 949: /* 12:Korean Extended Wansung */
89
case 950: /* 13:Chinese (Taiwan, Hongkong, Macau) */
90
case 1361: /* 15:Korean Johab */
91
ret[0] = 'M';
92
ret[1] = 'S';
93
break;
94
case 936:
95
strcpy(ret, "GBK");
96
break;
97
case 54936:
98
strcpy(ret, "GB18030");
99
break;
100
default:
101
ret[0] = 'C';
102
ret[1] = 'p';
103
break;
104
}
105
106
//Traditional Chinese Windows should use MS950_HKSCS_XP as the
107
//default encoding, if HKSCS patch has been installed.
108
// "old" MS950 0xfa41 -> u+e001
109
// "new" MS950 0xfa41 -> u+92db
110
if (strcmp(ret, "MS950") == 0) {
111
TCHAR mbChar[2] = {(char)0xfa, (char)0x41};
112
WCHAR unicodeChar;
113
MultiByteToWideChar(CP_ACP, 0, mbChar, 2, &unicodeChar, 1);
114
if (unicodeChar == 0x92db) {
115
strcpy(ret, "MS950_HKSCS_XP");
116
}
117
} else {
118
//SimpChinese Windows should use GB18030 as the default
119
//encoding, if gb18030 patch has been installed (on windows
120
//2000/XP, (1)Codepage 54936 will be available
121
//(2)simsun18030.ttc will exist under system fonts dir )
122
if (strcmp(ret, "GBK") == 0 && IsValidCodePage(54936)) {
123
char systemPath[MAX_PATH + 1];
124
char* gb18030Font = "\\FONTS\\SimSun18030.ttc";
125
FILE *f = NULL;
126
if (GetWindowsDirectory(systemPath, MAX_PATH + 1) != 0 &&
127
strlen(systemPath) + strlen(gb18030Font) < MAX_PATH + 1) {
128
strcat(systemPath, "\\FONTS\\SimSun18030.ttc");
129
if ((f = fopen(systemPath, "r")) != NULL) {
130
fclose(f);
131
strcpy(ret, "GB18030");
132
}
133
}
134
}
135
}
136
137
return ret;
138
}
139
140
static char* getConsoleEncoding()
141
{
142
char* buf = malloc(16);
143
int cp;
144
if (buf == NULL) {
145
return NULL;
146
}
147
cp = GetConsoleCP();
148
if (cp >= 874 && cp <= 950)
149
sprintf(buf, "ms%d", cp);
150
else if (cp == 65001)
151
sprintf(buf, "UTF-8");
152
else
153
sprintf(buf, "cp%d", cp);
154
return buf;
155
}
156
157
// Exported entries for AWT
158
DllExport const char *
159
getEncodingFromLangID(LANGID langID)
160
{
161
return getEncodingInternal(MAKELCID(langID, SORT_DEFAULT));
162
}
163
164
// Returns BCP47 Language Tag
165
DllExport const char *
166
getJavaIDFromLangID(LANGID langID)
167
{
168
char * elems[5]; // lang, script, ctry, variant, encoding
169
char * ret;
170
int index;
171
172
ret = malloc(SNAMESIZE);
173
if (ret == NULL) {
174
return NULL;
175
}
176
177
for (index = 0; index < 5; index++) {
178
elems[index] = NULL;
179
}
180
181
if (SetupI18nProps(MAKELCID(langID, SORT_DEFAULT),
182
&(elems[0]), &(elems[1]), &(elems[2]), &(elems[3]), &(elems[4]))) {
183
184
// there always is the "language" tag
185
strcpy(ret, elems[0]);
186
187
// append other elements, if any
188
for (index = 1; index < 4; index++) {
189
if ((elems[index])[0] != '\0') {
190
strcat(ret, "-");
191
strcat(ret, elems[index]);
192
}
193
}
194
} else {
195
free(ret);
196
ret = NULL;
197
}
198
199
for (index = 0; index < 5; index++) {
200
if (elems[index] != NULL) {
201
free(elems[index]);
202
}
203
}
204
205
return ret;
206
}
207
208
/*
209
* Code to figure out the user's home directory using shell32.dll
210
*/
211
WCHAR*
212
getHomeFromShell32()
213
{
214
/*
215
* Note that we don't free the memory allocated
216
* by getHomeFromShell32.
217
*/
218
static WCHAR *u_path = NULL;
219
if (u_path == NULL) {
220
HRESULT hr;
221
222
/*
223
* SHELL32 DLL is delay load DLL and we can use the trick with
224
* __try/__except block.
225
*/
226
__try {
227
/*
228
* For Windows Vista and later (or patched MS OS) we need to use
229
* [SHGetKnownFolderPath] call to avoid MAX_PATH length limitation.
230
* Shell32.dll (version 6.0.6000 or later)
231
*/
232
hr = SHGetKnownFolderPath(&FOLDERID_Profile, KF_FLAG_DONT_VERIFY, NULL, &u_path);
233
} __except(EXCEPTION_EXECUTE_HANDLER) {
234
/* Exception: no [SHGetKnownFolderPath] entry */
235
hr = E_FAIL;
236
}
237
238
if (FAILED(hr)) {
239
WCHAR path[MAX_PATH+1];
240
241
/* fallback solution for WinXP and Windows 2000 */
242
hr = SHGetFolderPathW(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, path);
243
if (FAILED(hr)) {
244
/* we can't find the shell folder. */
245
u_path = NULL;
246
} else {
247
/* Just to be sure about the path length until Windows Vista approach.
248
* [S_FALSE] could not be returned due to [CSIDL_FLAG_DONT_VERIFY] flag and UNICODE version.
249
*/
250
path[MAX_PATH] = 0;
251
u_path = _wcsdup(path);
252
}
253
}
254
}
255
return u_path;
256
}
257
258
static boolean
259
haveMMX(void)
260
{
261
return IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE);
262
}
263
264
static const char *
265
cpu_isalist(void)
266
{
267
SYSTEM_INFO info;
268
GetSystemInfo(&info);
269
switch (info.wProcessorArchitecture) {
270
#ifdef PROCESSOR_ARCHITECTURE_IA64
271
case PROCESSOR_ARCHITECTURE_IA64: return "ia64";
272
#endif
273
#ifdef PROCESSOR_ARCHITECTURE_AMD64
274
case PROCESSOR_ARCHITECTURE_AMD64: return "amd64";
275
#endif
276
case PROCESSOR_ARCHITECTURE_INTEL:
277
switch (info.wProcessorLevel) {
278
case 6: return haveMMX()
279
? "pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86"
280
: "pentium_pro pentium i486 i386 i86";
281
case 5: return haveMMX()
282
? "pentium+mmx pentium i486 i386 i86"
283
: "pentium i486 i386 i86";
284
case 4: return "i486 i386 i86";
285
case 3: return "i386 i86";
286
}
287
}
288
return NULL;
289
}
290
291
static boolean
292
SetupI18nProps(LCID lcid, char** language, char** script, char** country,
293
char** variant, char** encoding) {
294
/* script */
295
char tmp[SNAMESIZE];
296
*script = malloc(PROPSIZE);
297
if (*script == NULL) {
298
return FALSE;
299
}
300
if (GetLocaleInfo(lcid,
301
LOCALE_SNAME, tmp, SNAMESIZE) == 0 ||
302
sscanf(tmp, "%*[a-z\\-]%1[A-Z]%[a-z]", *script, &((*script)[1])) == 0 ||
303
strlen(*script) != 4) {
304
(*script)[0] = '\0';
305
}
306
307
/* country */
308
*country = malloc(PROPSIZE);
309
if (*country == NULL) {
310
return FALSE;
311
}
312
if (GetLocaleInfo(lcid,
313
LOCALE_SISO3166CTRYNAME, *country, PROPSIZE) == 0 &&
314
GetLocaleInfo(lcid,
315
LOCALE_SISO3166CTRYNAME2, *country, PROPSIZE) == 0) {
316
(*country)[0] = '\0';
317
}
318
319
/* language */
320
*language = malloc(PROPSIZE);
321
if (*language == NULL) {
322
return FALSE;
323
}
324
if (GetLocaleInfo(lcid,
325
LOCALE_SISO639LANGNAME, *language, PROPSIZE) == 0 &&
326
GetLocaleInfo(lcid,
327
LOCALE_SISO639LANGNAME2, *language, PROPSIZE) == 0) {
328
/* defaults to en_US */
329
strcpy(*language, "en");
330
strcpy(*country, "US");
331
}
332
333
/* variant */
334
*variant = malloc(PROPSIZE);
335
if (*variant == NULL) {
336
return FALSE;
337
}
338
(*variant)[0] = '\0';
339
340
/* handling for Norwegian */
341
if (strcmp(*language, "nb") == 0) {
342
strcpy(*language, "no");
343
strcpy(*country , "NO");
344
} else if (strcmp(*language, "nn") == 0) {
345
strcpy(*language, "no");
346
strcpy(*country , "NO");
347
strcpy(*variant, "NY");
348
}
349
350
/* encoding */
351
*encoding = getEncodingInternal(lcid);
352
if (*encoding == NULL) {
353
return FALSE;
354
}
355
return TRUE;
356
}
357
358
// GetVersionEx is deprecated; disable the warning until a replacement is found
359
#pragma warning(disable : 4996)
360
java_props_t *
361
GetJavaProperties(JNIEnv* env)
362
{
363
static java_props_t sprops = {0};
364
int majorVersion;
365
int minorVersion;
366
int buildNumber = 0;
367
368
if (sprops.line_separator) {
369
return &sprops;
370
}
371
372
/* tmp dir */
373
{
374
WCHAR tmpdir[MAX_PATH + 1];
375
/* we might want to check that this succeed */
376
GetTempPathW(MAX_PATH + 1, tmpdir);
377
sprops.tmp_dir = _wcsdup(tmpdir);
378
}
379
380
/* OS properties */
381
{
382
char buf[100];
383
boolean is_workstation;
384
boolean is_64bit;
385
DWORD platformId;
386
{
387
OSVERSIONINFOEX ver;
388
ver.dwOSVersionInfoSize = sizeof(ver);
389
GetVersionEx((OSVERSIONINFO *) &ver);
390
majorVersion = ver.dwMajorVersion;
391
minorVersion = ver.dwMinorVersion;
392
/* distinguish Windows Server 2016+ by build number */
393
buildNumber = ver.dwBuildNumber;
394
is_workstation = (ver.wProductType == VER_NT_WORKSTATION);
395
platformId = ver.dwPlatformId;
396
sprops.patch_level = _strdup(ver.szCSDVersion);
397
}
398
399
{
400
SYSTEM_INFO si;
401
ZeroMemory(&si, sizeof(SYSTEM_INFO));
402
GetNativeSystemInfo(&si);
403
404
is_64bit = (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64);
405
}
406
do {
407
// Read the major and minor version number from kernel32.dll
408
VS_FIXEDFILEINFO *file_info;
409
WCHAR kernel32_path[MAX_PATH];
410
DWORD version_size;
411
LPTSTR version_info;
412
UINT len, ret;
413
414
// Get the full path to \Windows\System32\kernel32.dll and use that for
415
// determining what version of Windows we're running on.
416
len = MAX_PATH - (UINT)strlen("\\kernel32.dll") - 1;
417
ret = GetSystemDirectoryW(kernel32_path, len);
418
if (ret == 0 || ret > len) {
419
break;
420
}
421
wcsncat(kernel32_path, L"\\kernel32.dll", MAX_PATH - ret);
422
423
version_size = GetFileVersionInfoSizeW(kernel32_path, NULL);
424
if (version_size == 0) {
425
break;
426
}
427
428
version_info = (LPTSTR)malloc(version_size);
429
if (version_info == NULL) {
430
break;
431
}
432
433
if (!GetFileVersionInfoW(kernel32_path, 0, version_size, version_info)) {
434
free(version_info);
435
break;
436
}
437
438
if (!VerQueryValueW(version_info, L"\\", (LPVOID*)&file_info, &len)) {
439
free(version_info);
440
break;
441
}
442
majorVersion = HIWORD(file_info->dwProductVersionMS);
443
minorVersion = LOWORD(file_info->dwProductVersionMS);
444
buildNumber = HIWORD(file_info->dwProductVersionLS);
445
free(version_info);
446
} while (0);
447
448
/*
449
* From msdn page on OSVERSIONINFOEX, current as of this
450
* writing, decoding of dwMajorVersion and dwMinorVersion.
451
*
452
* Operating system dwMajorVersion dwMinorVersion
453
* ================== ============== ==============
454
*
455
* Windows 95 4 0
456
* Windows 98 4 10
457
* Windows ME 4 90
458
* Windows 3.51 3 51
459
* Windows NT 4.0 4 0
460
* Windows 2000 5 0
461
* Windows XP 32 bit 5 1
462
* Windows Server 2003 family 5 2
463
* Windows XP 64 bit 5 2
464
* where ((&ver.wServicePackMinor) + 2) = 1
465
* and si.wProcessorArchitecture = 9
466
* Windows Vista family 6 0 (VER_NT_WORKSTATION)
467
* Windows Server 2008 6 0 (!VER_NT_WORKSTATION)
468
* Windows 7 6 1 (VER_NT_WORKSTATION)
469
* Windows Server 2008 R2 6 1 (!VER_NT_WORKSTATION)
470
* Windows 8 6 2 (VER_NT_WORKSTATION)
471
* Windows Server 2012 6 2 (!VER_NT_WORKSTATION)
472
* Windows Server 2012 R2 6 3 (!VER_NT_WORKSTATION)
473
* Windows 10 10 0 (VER_NT_WORKSTATION)
474
* Windows 11 10 0 (VER_NT_WORKSTATION)
475
* where (buildNumber >= 22000)
476
* Windows Server 2016 10 0 (!VER_NT_WORKSTATION)
477
* Windows Server 2019 10 0 (!VER_NT_WORKSTATION)
478
* where (buildNumber > 17762)
479
* Windows Server 2022 10 0 (!VER_NT_WORKSTATION)
480
* where (buildNumber > 20347)
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:
550
/* Windows 11 21H2 (original release) build number is 22000 */
551
if (buildNumber >= 22000) {
552
sprops.os_name = "Windows 11";
553
} else {
554
sprops.os_name = "Windows 10";
555
}
556
break;
557
default: sprops.os_name = "Windows NT (unknown)";
558
}
559
} else {
560
switch (minorVersion) {
561
case 0:
562
/* Windows server 2019 GA 10/2018 build number is 17763 */
563
/* Windows server 2022 build number is 20348 */
564
if (buildNumber > 20347) {
565
sprops.os_name = "Windows Server 2022";
566
} else if (buildNumber > 17676) {
567
sprops.os_name = "Windows Server 2019";
568
} else {
569
sprops.os_name = "Windows Server 2016";
570
}
571
break;
572
default: sprops.os_name = "Windows NT (unknown)";
573
}
574
}
575
} else {
576
sprops.os_name = "Windows NT (unknown)";
577
}
578
break;
579
default:
580
sprops.os_name = "Windows (unknown)";
581
break;
582
}
583
sprintf(buf, "%d.%d", majorVersion, minorVersion);
584
sprops.os_version = _strdup(buf);
585
#if defined(_M_AMD64)
586
sprops.os_arch = "amd64";
587
#elif defined(_X86_)
588
sprops.os_arch = "x86";
589
#elif defined(_M_ARM64)
590
sprops.os_arch = "aarch64";
591
#else
592
sprops.os_arch = "unknown";
593
#endif
594
}
595
596
/* Endianness of platform */
597
{
598
unsigned int endianTest = 0xff000000;
599
if (((char*)(&endianTest))[0] != 0) {
600
sprops.cpu_endian = "big";
601
} else {
602
sprops.cpu_endian = "little";
603
}
604
}
605
606
/* CPU ISA list */
607
sprops.cpu_isalist = cpu_isalist();
608
609
/*
610
* User name
611
* We try to avoid calling GetUserName as it turns out to
612
* be surprisingly expensive on NT. It pulls in an extra
613
* 100 K of footprint.
614
*/
615
{
616
WCHAR *uname = _wgetenv(L"USERNAME");
617
if (uname != NULL && wcslen(uname) > 0) {
618
sprops.user_name = _wcsdup(uname);
619
} else {
620
DWORD buflen = 0;
621
if (GetUserNameW(NULL, &buflen) == 0 &&
622
GetLastError() == ERROR_INSUFFICIENT_BUFFER)
623
{
624
uname = (WCHAR*)malloc(buflen * sizeof(WCHAR));
625
if (uname != NULL && GetUserNameW(uname, &buflen) == 0) {
626
free(uname);
627
uname = NULL;
628
}
629
} else {
630
uname = NULL;
631
}
632
sprops.user_name = (uname != NULL) ? uname : L"unknown";
633
}
634
}
635
636
/*
637
* Home directory
638
*
639
* The normal result is that for a given user name XXX:
640
* On multi-user NT, user.home gets set to c:\winnt\profiles\XXX.
641
* On multi-user Win95, user.home gets set to c:\windows\profiles\XXX.
642
* On single-user Win95, user.home gets set to c:\windows.
643
*/
644
{
645
WCHAR *homep = getHomeFromShell32();
646
if (homep == NULL) {
647
homep = L"C:\\";
648
}
649
sprops.user_home = homep;
650
}
651
652
/*
653
* user.language
654
* user.script, user.country, user.variant (if user's environment specifies them)
655
* file.encoding
656
*/
657
{
658
/*
659
* query the system for the current system default locale
660
* (which is a Windows LCID value),
661
*/
662
LCID userDefaultLCID = GetUserDefaultLCID();
663
LANGID userDefaultUILang = GetUserDefaultUILanguage();
664
LCID userDefaultUILCID = MAKELCID(userDefaultUILang, SORTIDFROMLCID(userDefaultLCID));
665
666
{
667
char * display_encoding;
668
HANDLE hStdOutErr;
669
670
// Windows UI Language selection list only cares "language"
671
// information of the UI Language. For example, the list
672
// just lists "English" but it actually means "en_US", and
673
// the user cannot select "en_GB" (if exists) in the list.
674
// So, this hack is to use the user LCID region information
675
// for the UI Language, if the "language" portion of those
676
// two locales are the same.
677
if (PRIMARYLANGID(LANGIDFROMLCID(userDefaultLCID)) ==
678
PRIMARYLANGID(userDefaultUILang)) {
679
userDefaultUILCID = userDefaultLCID;
680
}
681
682
SetupI18nProps(userDefaultLCID,
683
&sprops.format_language,
684
&sprops.format_script,
685
&sprops.format_country,
686
&sprops.format_variant,
687
&sprops.encoding);
688
SetupI18nProps(userDefaultUILCID,
689
&sprops.display_language,
690
&sprops.display_script,
691
&sprops.display_country,
692
&sprops.display_variant,
693
&display_encoding);
694
695
sprops.sun_jnu_encoding = getEncodingInternal(0);
696
if (sprops.sun_jnu_encoding == NULL) {
697
sprops.sun_jnu_encoding = "UTF-8";
698
}
699
if (LANGIDFROMLCID(userDefaultLCID) == 0x0c04 && majorVersion == 6) {
700
// MS claims "Vista has built-in support for HKSCS-2004.
701
// All of the HKSCS-2004 characters have Unicode 4.1.
702
// PUA code point assignments". But what it really means
703
// is that the HKSCS-2004 is ONLY supported in Unicode.
704
// Test indicates the MS950 in its zh_HK locale is a
705
// "regular" MS950 which does not handle HKSCS-2004 at
706
// all. Set encoding to MS950_HKSCS.
707
sprops.encoding = "MS950_HKSCS";
708
sprops.sun_jnu_encoding = "MS950_HKSCS";
709
}
710
711
hStdOutErr = GetStdHandle(STD_OUTPUT_HANDLE);
712
if (hStdOutErr != INVALID_HANDLE_VALUE &&
713
GetFileType(hStdOutErr) == FILE_TYPE_CHAR) {
714
sprops.sun_stdout_encoding = getConsoleEncoding();
715
}
716
hStdOutErr = GetStdHandle(STD_ERROR_HANDLE);
717
if (hStdOutErr != INVALID_HANDLE_VALUE &&
718
GetFileType(hStdOutErr) == FILE_TYPE_CHAR) {
719
if (sprops.sun_stdout_encoding != NULL)
720
sprops.sun_stderr_encoding = sprops.sun_stdout_encoding;
721
else
722
sprops.sun_stderr_encoding = getConsoleEncoding();
723
}
724
}
725
}
726
727
sprops.unicode_encoding = "UnicodeLittle";
728
729
/* User TIMEZONE
730
* We defer setting up timezone until it's actually necessary.
731
* Refer to TimeZone.getDefault(). The system property
732
* is able to be set by the command line interface -Duser.timezone.
733
*/
734
735
/* Current directory */
736
{
737
WCHAR buf[MAX_PATH];
738
if (GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR), buf) != 0)
739
sprops.user_dir = _wcsdup(buf);
740
}
741
742
sprops.file_separator = "\\";
743
sprops.path_separator = ";";
744
sprops.line_separator = "\r\n";
745
746
return &sprops;
747
}
748
749
jstring
750
GetStringPlatform(JNIEnv *env, nchar* wcstr)
751
{
752
return (*env)->NewString(env, wcstr, (jsize)wcslen(wcstr));
753
}
754
755