Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/windows/native/libjava/java_props_md.c
41119 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;
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
strcpy(ret+2, "1252");
77
} else {
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 and 2019 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 Server 2016 10 0 (!VER_NT_WORKSTATION)
475
* Windows Server 2019 10 0 (!VER_NT_WORKSTATION)
476
* where (buildNumber > 17762)
477
*
478
* This mapping will presumably be augmented as new Windows
479
* versions are released.
480
*/
481
switch (platformId) {
482
case VER_PLATFORM_WIN32_WINDOWS:
483
if (majorVersion == 4) {
484
switch (minorVersion) {
485
case 0: sprops.os_name = "Windows 95"; break;
486
case 10: sprops.os_name = "Windows 98"; break;
487
case 90: sprops.os_name = "Windows Me"; break;
488
default: sprops.os_name = "Windows 9X (unknown)"; break;
489
}
490
} else {
491
sprops.os_name = "Windows 9X (unknown)";
492
}
493
break;
494
case VER_PLATFORM_WIN32_NT:
495
if (majorVersion <= 4) {
496
sprops.os_name = "Windows NT";
497
} else if (majorVersion == 5) {
498
switch (minorVersion) {
499
case 0: sprops.os_name = "Windows 2000"; break;
500
case 1: sprops.os_name = "Windows XP"; break;
501
case 2:
502
/*
503
* From MSDN OSVERSIONINFOEX and SYSTEM_INFO documentation:
504
*
505
* "Because the version numbers for Windows Server 2003
506
* and Windows XP 6u4 bit are identical, you must also test
507
* whether the wProductType member is VER_NT_WORKSTATION.
508
* and si.wProcessorArchitecture is
509
* PROCESSOR_ARCHITECTURE_AMD64 (which is 9)
510
* If it is, the operating system is Windows XP 64 bit;
511
* otherwise, it is Windows Server 2003."
512
*/
513
if (is_workstation && is_64bit) {
514
sprops.os_name = "Windows XP"; /* 64 bit */
515
} else {
516
sprops.os_name = "Windows 2003";
517
}
518
break;
519
default: sprops.os_name = "Windows NT (unknown)"; break;
520
}
521
} else if (majorVersion == 6) {
522
/*
523
* See table in MSDN OSVERSIONINFOEX documentation.
524
*/
525
if (is_workstation) {
526
switch (minorVersion) {
527
case 0: sprops.os_name = "Windows Vista"; break;
528
case 1: sprops.os_name = "Windows 7"; break;
529
case 2: sprops.os_name = "Windows 8"; break;
530
case 3: sprops.os_name = "Windows 8.1"; break;
531
default: sprops.os_name = "Windows NT (unknown)";
532
}
533
} else {
534
switch (minorVersion) {
535
case 0: sprops.os_name = "Windows Server 2008"; break;
536
case 1: sprops.os_name = "Windows Server 2008 R2"; break;
537
case 2: sprops.os_name = "Windows Server 2012"; break;
538
case 3: sprops.os_name = "Windows Server 2012 R2"; break;
539
default: sprops.os_name = "Windows NT (unknown)";
540
}
541
}
542
} else if (majorVersion == 10) {
543
if (is_workstation) {
544
switch (minorVersion) {
545
case 0: sprops.os_name = "Windows 10"; break;
546
default: sprops.os_name = "Windows NT (unknown)";
547
}
548
} else {
549
switch (minorVersion) {
550
case 0:
551
/* Windows server 2019 GA 10/2018 build number is 17763 */
552
if (buildNumber > 17762) {
553
sprops.os_name = "Windows Server 2019";
554
} else {
555
sprops.os_name = "Windows Server 2016";
556
}
557
break;
558
default: sprops.os_name = "Windows NT (unknown)";
559
}
560
}
561
} else {
562
sprops.os_name = "Windows NT (unknown)";
563
}
564
break;
565
default:
566
sprops.os_name = "Windows (unknown)";
567
break;
568
}
569
sprintf(buf, "%d.%d", majorVersion, minorVersion);
570
sprops.os_version = _strdup(buf);
571
#if defined(_M_AMD64)
572
sprops.os_arch = "amd64";
573
#elif defined(_X86_)
574
sprops.os_arch = "x86";
575
#elif defined(_M_ARM64)
576
sprops.os_arch = "aarch64";
577
#else
578
sprops.os_arch = "unknown";
579
#endif
580
}
581
582
/* Endianness of platform */
583
{
584
unsigned int endianTest = 0xff000000;
585
if (((char*)(&endianTest))[0] != 0) {
586
sprops.cpu_endian = "big";
587
} else {
588
sprops.cpu_endian = "little";
589
}
590
}
591
592
/* CPU ISA list */
593
sprops.cpu_isalist = cpu_isalist();
594
595
/*
596
* User name
597
* We try to avoid calling GetUserName as it turns out to
598
* be surprisingly expensive on NT. It pulls in an extra
599
* 100 K of footprint.
600
*/
601
{
602
WCHAR *uname = _wgetenv(L"USERNAME");
603
if (uname != NULL && wcslen(uname) > 0) {
604
sprops.user_name = _wcsdup(uname);
605
} else {
606
DWORD buflen = 0;
607
if (GetUserNameW(NULL, &buflen) == 0 &&
608
GetLastError() == ERROR_INSUFFICIENT_BUFFER)
609
{
610
uname = (WCHAR*)malloc(buflen * sizeof(WCHAR));
611
if (uname != NULL && GetUserNameW(uname, &buflen) == 0) {
612
free(uname);
613
uname = NULL;
614
}
615
} else {
616
uname = NULL;
617
}
618
sprops.user_name = (uname != NULL) ? uname : L"unknown";
619
}
620
}
621
622
/*
623
* Home directory
624
*
625
* The normal result is that for a given user name XXX:
626
* On multi-user NT, user.home gets set to c:\winnt\profiles\XXX.
627
* On multi-user Win95, user.home gets set to c:\windows\profiles\XXX.
628
* On single-user Win95, user.home gets set to c:\windows.
629
*/
630
{
631
WCHAR *homep = getHomeFromShell32();
632
if (homep == NULL) {
633
homep = L"C:\\";
634
}
635
sprops.user_home = homep;
636
}
637
638
/*
639
* user.language
640
* user.script, user.country, user.variant (if user's environment specifies them)
641
* file.encoding
642
*/
643
{
644
/*
645
* query the system for the current system default locale
646
* (which is a Windows LCID value),
647
*/
648
LCID userDefaultLCID = GetUserDefaultLCID();
649
LCID systemDefaultLCID = GetSystemDefaultLCID();
650
LANGID userDefaultUILang = GetUserDefaultUILanguage();
651
LCID userDefaultUILCID = MAKELCID(userDefaultUILang, SORTIDFROMLCID(userDefaultLCID));
652
653
{
654
char * display_encoding;
655
HANDLE hStdOutErr;
656
657
// Windows UI Language selection list only cares "language"
658
// information of the UI Language. For example, the list
659
// just lists "English" but it actually means "en_US", and
660
// the user cannot select "en_GB" (if exists) in the list.
661
// So, this hack is to use the user LCID region information
662
// for the UI Language, if the "language" portion of those
663
// two locales are the same.
664
if (PRIMARYLANGID(LANGIDFROMLCID(userDefaultLCID)) ==
665
PRIMARYLANGID(userDefaultUILang)) {
666
userDefaultUILCID = userDefaultLCID;
667
}
668
669
SetupI18nProps(userDefaultLCID,
670
&sprops.format_language,
671
&sprops.format_script,
672
&sprops.format_country,
673
&sprops.format_variant,
674
&sprops.encoding);
675
SetupI18nProps(userDefaultUILCID,
676
&sprops.display_language,
677
&sprops.display_script,
678
&sprops.display_country,
679
&sprops.display_variant,
680
&display_encoding);
681
682
sprops.sun_jnu_encoding = getEncodingInternal(systemDefaultLCID);
683
if (LANGIDFROMLCID(userDefaultLCID) == 0x0c04 && majorVersion == 6) {
684
// MS claims "Vista has built-in support for HKSCS-2004.
685
// All of the HKSCS-2004 characters have Unicode 4.1.
686
// PUA code point assignments". But what it really means
687
// is that the HKSCS-2004 is ONLY supported in Unicode.
688
// Test indicates the MS950 in its zh_HK locale is a
689
// "regular" MS950 which does not handle HKSCS-2004 at
690
// all. Set encoding to MS950_HKSCS.
691
sprops.encoding = "MS950_HKSCS";
692
sprops.sun_jnu_encoding = "MS950_HKSCS";
693
}
694
695
hStdOutErr = GetStdHandle(STD_OUTPUT_HANDLE);
696
if (hStdOutErr != INVALID_HANDLE_VALUE &&
697
GetFileType(hStdOutErr) == FILE_TYPE_CHAR) {
698
sprops.sun_stdout_encoding = getConsoleEncoding();
699
}
700
hStdOutErr = GetStdHandle(STD_ERROR_HANDLE);
701
if (hStdOutErr != INVALID_HANDLE_VALUE &&
702
GetFileType(hStdOutErr) == FILE_TYPE_CHAR) {
703
if (sprops.sun_stdout_encoding != NULL)
704
sprops.sun_stderr_encoding = sprops.sun_stdout_encoding;
705
else
706
sprops.sun_stderr_encoding = getConsoleEncoding();
707
}
708
}
709
}
710
711
sprops.unicode_encoding = "UnicodeLittle";
712
713
/* User TIMEZONE
714
* We defer setting up timezone until it's actually necessary.
715
* Refer to TimeZone.getDefault(). The system property
716
* is able to be set by the command line interface -Duser.timezone.
717
*/
718
719
/* Current directory */
720
{
721
WCHAR buf[MAX_PATH];
722
if (GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR), buf) != 0)
723
sprops.user_dir = _wcsdup(buf);
724
}
725
726
sprops.file_separator = "\\";
727
sprops.path_separator = ";";
728
sprops.line_separator = "\r\n";
729
730
return &sprops;
731
}
732
733
jstring
734
GetStringPlatform(JNIEnv *env, nchar* wcstr)
735
{
736
return (*env)->NewString(env, wcstr, (jsize)wcslen(wcstr));
737
}
738
739