jdk/src/windows/native/java/lang/java_props_md.c
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 7018 154795ed10de
child 9027 540bd52f1881
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 7018
diff changeset
     2
 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <windows.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <shlobj.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <objidl.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <locale.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <sys/timeb.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <tchar.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "locale_str.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "java_props.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#ifndef VER_PLATFORM_WIN32_WINDOWS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#define VER_PLATFORM_WIN32_WINDOWS 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
1626
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
    41
#ifndef PROCESSOR_ARCHITECTURE_AMD64
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
    42
#define PROCESSOR_ARCHITECTURE_AMD64 9
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
    43
#endif
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
    44
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
    45
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
    46
static void SetupI18nProps(LCID lcid, char** language, char** script, char** country,
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    47
               char** variant, char** encoding);
1626
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
    48
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#define SHELL_KEY "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
    51
#define PROPSIZE 9      // eight-letter + null terminator
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
    52
#define SNAMESIZE 86    // max number of chars for LOCALE_SNAME is 85
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
    53
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    54
static char *
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    55
getEncodingInternal(LCID lcid)
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    56
{
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    57
    char * ret = malloc(16);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    58
    int codepage;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    60
    if (GetLocaleInfo(lcid,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    61
                      LOCALE_IDEFAULTANSICODEPAGE,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    62
                      ret+2, 14) == 0) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    63
        codepage = 1252;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    64
    } else {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    65
        codepage = atoi(ret+2);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    66
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    68
    switch (codepage) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    69
    case 0:
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    70
        strcpy(ret, "UTF-8");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    71
        break;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    72
    case 874:     /*  9:Thai     */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    73
    case 932:     /* 10:Japanese */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    74
    case 949:     /* 12:Korean Extended Wansung */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    75
    case 950:     /* 13:Chinese (Taiwan, Hongkong, Macau) */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    76
    case 1361:    /* 15:Korean Johab */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    77
        ret[0] = 'M';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    78
        ret[1] = 'S';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    79
        break;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    80
    case 936:
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    81
        strcpy(ret, "GBK");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    82
        break;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    83
    case 54936:
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    84
        strcpy(ret, "GB18030");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    85
        break;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    86
    default:
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    87
        ret[0] = 'C';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    88
        ret[1] = 'p';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    89
        break;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    90
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
    92
    //Traditional Chinese Windows should use MS950_HKSCS_XP as the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    //default encoding, if HKSCS patch has been installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // "old" MS950 0xfa41 -> u+e001
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // "new" MS950 0xfa41 -> u+92db
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    if (strcmp(ret, "MS950") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        TCHAR  mbChar[2] = {(char)0xfa, (char)0x41};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        WCHAR  unicodeChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        MultiByteToWideChar(CP_ACP, 0, mbChar, 2, &unicodeChar, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (unicodeChar == 0x92db) {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   101
            strcpy(ret, "MS950_HKSCS_XP");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        //SimpChinese Windows should use GB18030 as the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        //encoding, if gb18030 patch has been installed (on windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        //2000/XP, (1)Codepage 54936 will be available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        //(2)simsun18030.ttc will exist under system fonts dir )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (strcmp(ret, "GBK") == 0 && IsValidCodePage(54936)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            char systemPath[MAX_PATH + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            char* gb18030Font = "\\FONTS\\SimSun18030.ttc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            FILE *f = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            if (GetWindowsDirectory(systemPath, MAX_PATH + 1) != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                strlen(systemPath) + strlen(gb18030Font) < MAX_PATH + 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                strcat(systemPath, "\\FONTS\\SimSun18030.ttc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                if ((f = fopen(systemPath, "r")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    fclose(f);
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   117
                    strcpy(ret, "GB18030");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
// Exported entries for AWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
DllExport const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
getEncodingFromLangID(LANGID langID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
{
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   130
    return getEncodingInternal(MAKELCID(langID, SORT_DEFAULT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   133
// Returns BCP47 Language Tag
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
DllExport const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
getJavaIDFromLangID(LANGID langID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
{
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   137
    char * elems[5]; // lang, script, ctry, variant, encoding
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   138
    char * ret = malloc(SNAMESIZE);
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   139
    int index;
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   140
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   141
    SetupI18nProps(MAKELCID(langID, SORT_DEFAULT),
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   142
                   &(elems[0]), &(elems[1]), &(elems[2]), &(elems[3]), &(elems[4]));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   144
    // there always is the "language" tag
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   145
    strcpy(ret, elems[0]);
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   146
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   147
    // append other elements, if any
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   148
    for (index = 1; index < 4; index++) {
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   149
        if ((elems[index])[0] != '\0') {
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   150
            strcat(ret, "-");
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   151
            strcat(ret, elems[index]);
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   152
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   154
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   155
    for (index = 0; index < 5; index++) {
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   156
        free(elems[index]);
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   157
    }
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   158
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   159
    return ret;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * Code to figure out the user's home directory using the registry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
*/
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   165
static WCHAR*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
getHomeFromRegistry()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    HKEY key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    int rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    DWORD type;
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   171
    WCHAR *p;
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   172
    WCHAR path[MAX_PATH+1];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    int size = MAX_PATH+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    rc = RegOpenKeyEx(HKEY_CURRENT_USER, SHELL_KEY, 0, KEY_READ, &key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    if (rc != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        // Shell folder doesn't exist??!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    path[0] = 0;
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   182
    rc = RegQueryValueExW(key, L"Desktop", 0, &type, (LPBYTE)path, &size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    if (rc != ERROR_SUCCESS || type != REG_SZ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /* Get the parent of Desktop directory */
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   188
    p = wcsrchr(path, L'\\');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    if (p == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   192
    *p = L'\0';
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   193
    return _wcsdup(path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * Code to figure out the user's home directory using shell32.dll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
typedef HRESULT (WINAPI *GetSpecialFolderType)(HWND, int, LPITEMIDLIST *);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
typedef BOOL (WINAPI *GetPathFromIDListType)(LPCITEMIDLIST, LPSTR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   202
WCHAR*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
getHomeFromShell32()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
{
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   205
    HMODULE lib = LoadLibraryW(L"SHELL32.DLL");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    GetSpecialFolderType do_get_folder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    GetPathFromIDListType do_get_path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    HRESULT rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    LPITEMIDLIST item_list = 0;
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   210
    WCHAR *p;
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   211
    WCHAR path[MAX_PATH+1];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    int size = MAX_PATH+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    if (lib == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        // We can't load the library !!??
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    do_get_folder = (GetSpecialFolderType)GetProcAddress(lib, "SHGetSpecialFolderLocation");
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   220
    do_get_path = (GetPathFromIDListType)GetProcAddress(lib, "SHGetPathFromIDListW");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    if (do_get_folder == 0 || do_get_path == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        // the library doesn't hold the right functions !!??
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    rc = (*do_get_folder)(NULL, CSIDL_DESKTOPDIRECTORY, &item_list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    if (!SUCCEEDED(rc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        // we can't find the shell folder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    path[0] = 0;
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   234
    (*do_get_path)(item_list, (LPSTR)path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /* Get the parent of Desktop directory */
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   237
    p = wcsrchr(path, L'\\');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    if (p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        *p = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * We've been successful.  Note that we don't free the memory allocated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * by ShGetSpecialFolderLocation.  We only ever come through here once,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * and only if the registry lookup failed, so it's just not worth it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * We also don't unload the SHELL32 DLL.  We've paid the hit for loading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * it and we may need it again later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   250
    return _wcsdup(path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
static boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
haveMMX(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    boolean mmx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    HMODULE lib = LoadLibrary("KERNEL32");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    if (lib != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        BOOL (WINAPI *isProcessorFeaturePresent)(DWORD) =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            (BOOL (WINAPI *)(DWORD))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            GetProcAddress(lib, "IsProcessorFeaturePresent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (isProcessorFeaturePresent != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            mmx = isProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        FreeLibrary(lib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    return mmx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
static const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
cpu_isalist(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    SYSTEM_INFO info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    GetSystemInfo(&info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    switch (info.wProcessorArchitecture) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
#ifdef PROCESSOR_ARCHITECTURE_IA64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    case PROCESSOR_ARCHITECTURE_IA64: return "ia64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
#ifdef PROCESSOR_ARCHITECTURE_AMD64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    case PROCESSOR_ARCHITECTURE_AMD64: return "amd64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    case PROCESSOR_ARCHITECTURE_INTEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        switch (info.wProcessorLevel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        case 6: return haveMMX()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            ? "pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            : "pentium_pro pentium i486 i386 i86";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        case 5: return haveMMX()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            ? "pentium+mmx pentium i486 i386 i86"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            : "pentium i486 i386 i86";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        case 4: return "i486 i386 i86";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        case 3: return "i386 i86";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   296
static void
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   297
SetupI18nProps(LCID lcid, char** language, char** script, char** country,
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   298
               char** variant, char** encoding) {
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   299
    /* script */
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   300
    char tmp[SNAMESIZE];
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   301
    *script = malloc(PROPSIZE);
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   302
    if (GetLocaleInfo(lcid,
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   303
                      LOCALE_SNAME, tmp, SNAMESIZE) == 0 ||
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   304
        sscanf(tmp, "%*[a-z\\-]%1[A-Z]%[a-z]", *script, &((*script)[1])) == 0 ||
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   305
        strlen(*script) != 4) {
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   306
        (*script)[0] = '\0';
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   307
    }
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   308
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   309
    /* country */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   310
    *country = malloc(PROPSIZE);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   311
    if (GetLocaleInfo(lcid,
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   312
                      LOCALE_SISO3166CTRYNAME, *country, PROPSIZE) == 0 &&
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   313
        GetLocaleInfo(lcid,
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   314
                      LOCALE_SISO3166CTRYNAME2, *country, PROPSIZE) == 0) {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   315
        (*country)[0] = '\0';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   316
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   317
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   318
    /* language */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   319
    *language = malloc(PROPSIZE);
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   320
    if (GetLocaleInfo(lcid,
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   321
                      LOCALE_SISO639LANGNAME, *language, PROPSIZE) == 0 &&
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   322
        GetLocaleInfo(lcid,
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   323
                      LOCALE_SISO639LANGNAME2, *language, PROPSIZE) == 0) {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   324
            /* defaults to en_US */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   325
            strcpy(*language, "en");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   326
            strcpy(*country, "US");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   327
        }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   328
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   329
    /* variant */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   330
    *variant = malloc(PROPSIZE);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   331
    (*variant)[0] = '\0';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   332
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   333
    /* handling for Norwegian */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   334
    if (strcmp(*language, "nb") == 0) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   335
        strcpy(*language, "no");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   336
        strcpy(*country , "NO");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   337
    } else if (strcmp(*language, "nn") == 0) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   338
        strcpy(*language, "no");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   339
        strcpy(*country , "NO");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   340
        strcpy(*variant, "NY");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   341
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   342
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   343
    /* encoding */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   344
    *encoding = getEncodingInternal(lcid);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   345
}
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   346
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
java_props_t *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
GetJavaProperties(JNIEnv* env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    static java_props_t sprops = {0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   352
    OSVERSIONINFOEX ver;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   353
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    if (sprops.user_dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return &sprops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /* AWT properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    sprops.awt_toolkit = "sun.awt.windows.WToolkit";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /* tmp dir */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    {
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   363
        WCHAR tmpdir[MAX_PATH + 1];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        /* we might want to check that this succeed */
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   365
        GetTempPathW(MAX_PATH + 1, tmpdir);
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   366
        sprops.tmp_dir = _wcsdup(tmpdir);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /* Printing properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    sprops.printerJob = "sun.awt.windows.WPrinterJob";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /* Java2D properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    sprops.graphics_env = "sun.awt.Win32GraphicsEnvironment";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    {    /* This is used only for debugging of font problems. */
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   376
        WCHAR *path = _wgetenv(L"JAVA2D_FONTPATH");
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   377
        sprops.font_dir = (path != NULL) ? _wcsdup(path) : NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /* OS properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        char buf[100];
1626
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   383
        SYSTEM_INFO si;
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   384
        PGNSI pGNSI;
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   385
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        ver.dwOSVersionInfoSize = sizeof(ver);
49
b25b3ff21b7c 6642034: System.getProperty("os.name") returns Windows Vista on Windows Server 2008 (longhorn)
martin
parents: 2
diff changeset
   387
        GetVersionEx((OSVERSIONINFO *) &ver);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
1626
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   389
        ZeroMemory(&si, sizeof(SYSTEM_INFO));
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   390
        // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   391
        pGNSI = (PGNSI) GetProcAddress(
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   392
                GetModuleHandle(TEXT("kernel32.dll")),
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   393
                "GetNativeSystemInfo");
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   394
        if(NULL != pGNSI)
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   395
            pGNSI(&si);
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   396
        else
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   397
            GetSystemInfo(&si);
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   398
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
         * From msdn page on OSVERSIONINFOEX, current as of this
49
b25b3ff21b7c 6642034: System.getProperty("os.name") returns Windows Vista on Windows Server 2008 (longhorn)
martin
parents: 2
diff changeset
   401
         * writing, decoding of dwMajorVersion and dwMinorVersion.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
         *  Operating system            dwMajorVersion  dwMinorVersion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
         * ==================           ==============  ==============
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
         * Windows 95                   4               0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
         * Windows 98                   4               10
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
         * Windows ME                   4               90
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
         * Windows 3.51                 3               51
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
         * Windows NT 4.0               4               0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
         * Windows 2000                 5               0
1626
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   412
         * Windows XP 32 bit            5               1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
         * Windows Server 2003 family   5               2
1626
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   414
         * Windows XP 64 bit            5               2
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   415
         *       where ((&ver.wServicePackMinor) + 2) = 1
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   416
         *       and  si.wProcessorArchitecture = 9
3212
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   417
         * Windows Vista family         6               0  (VER_NT_WORKSTATION)
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   418
         * Windows Server 2008          6               0  (!VER_NT_WORKSTATION)
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   419
         * Windows 7                    6               1  (VER_NT_WORKSTATION)
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   420
         * Windows Server 2008 R2       6               1  (!VER_NT_WORKSTATION)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
         * This mapping will presumably be augmented as new Windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
         * versions are released.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        switch (ver.dwPlatformId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        case VER_PLATFORM_WIN32s:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            sprops.os_name = "Windows 3.1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        case VER_PLATFORM_WIN32_WINDOWS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
           if (ver.dwMajorVersion == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                switch (ver.dwMinorVersion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                case  0: sprops.os_name = "Windows 95";           break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                case 10: sprops.os_name = "Windows 98";           break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                case 90: sprops.os_name = "Windows Me";           break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                default: sprops.os_name = "Windows 9X (unknown)"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                sprops.os_name = "Windows 9X (unknown)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        case VER_PLATFORM_WIN32_NT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            if (ver.dwMajorVersion <= 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                sprops.os_name = "Windows NT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            } else if (ver.dwMajorVersion == 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                switch (ver.dwMinorVersion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                case  0: sprops.os_name = "Windows 2000";         break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                case  1: sprops.os_name = "Windows XP";           break;
1626
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   448
                case  2:
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   449
                   /*
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   450
                    * From MSDN OSVERSIONINFOEX and SYSTEM_INFO documentation:
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   451
                    *
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   452
                    * "Because the version numbers for Windows Server 2003
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   453
                    * and Windows XP 6u4 bit are identical, you must also test
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   454
                    * whether the wProductType member is VER_NT_WORKSTATION.
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   455
                    * and si.wProcessorArchitecture is
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   456
                    * PROCESSOR_ARCHITECTURE_AMD64 (which is 9)
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   457
                    * If it is, the operating system is Windows XP 64 bit;
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   458
                    * otherwise, it is Windows Server 2003."
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   459
                    */
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   460
                    if(ver.wProductType == VER_NT_WORKSTATION &&
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   461
                       si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   462
                        sprops.os_name = "Windows XP"; /* 64 bit */
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   463
                    } else {
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   464
                        sprops.os_name = "Windows 2003";
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   465
                    }
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   466
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                default: sprops.os_name = "Windows NT (unknown)"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            } else if (ver.dwMajorVersion == 6) {
49
b25b3ff21b7c 6642034: System.getProperty("os.name") returns Windows Vista on Windows Server 2008 (longhorn)
martin
parents: 2
diff changeset
   470
                /*
3212
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   471
                 * See table in MSDN OSVERSIONINFOEX documentation.
49
b25b3ff21b7c 6642034: System.getProperty("os.name") returns Windows Vista on Windows Server 2008 (longhorn)
martin
parents: 2
diff changeset
   472
                 */
2424
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   473
                if (ver.wProductType == VER_NT_WORKSTATION) {
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   474
                    switch (ver.dwMinorVersion) {
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   475
                    case  0: sprops.os_name = "Windows Vista";        break;
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   476
                    case  1: sprops.os_name = "Windows 7";            break;
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   477
                    default: sprops.os_name = "Windows NT (unknown)";
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   478
                    }
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   479
                } else {
3212
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   480
                    switch (ver.dwMinorVersion) {
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   481
                    case  0: sprops.os_name = "Windows Server 2008";    break;
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   482
                    case  1: sprops.os_name = "Windows Server 2008 R2"; break;
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   483
                    default: sprops.os_name = "Windows NT (unknown)";
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   484
                    }
2424
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   485
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                sprops.os_name = "Windows NT (unknown)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            sprops.os_name = "Windows (unknown)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        sprintf(buf, "%d.%d", ver.dwMajorVersion, ver.dwMinorVersion);
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 6489
diff changeset
   495
        sprops.os_version = _strdup(buf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
#if _M_IA64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        sprops.os_arch = "ia64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
#elif _M_AMD64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        sprops.os_arch = "amd64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
#elif _X86_
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        sprops.os_arch = "x86";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        sprops.os_arch = "unknown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 6489
diff changeset
   506
        sprops.patch_level = _strdup(ver.szCSDVersion);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        sprops.desktop = "windows";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    /* Endianness of platform */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        unsigned int endianTest = 0xff000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        if (((char*)(&endianTest))[0] != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            sprops.cpu_endian = "big";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            sprops.cpu_endian = "little";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    /* CPU ISA list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    sprops.cpu_isalist = cpu_isalist();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * User name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * We try to avoid calling GetUserName as it turns out to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * be surprisingly expensive on NT.  It pulls in an extra
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * 100 K of footprint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    {
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   531
        WCHAR *uname = _wgetenv(L"USERNAME");
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   532
        if (uname != NULL && wcslen(uname) > 0) {
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   533
            sprops.user_name = _wcsdup(uname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        } else {
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   535
            WCHAR buf[100];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            int buflen = sizeof(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            sprops.user_name =
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   538
                GetUserNameW(buf, &buflen) ? _wcsdup(buf) : L"unknown";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * Home directory/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * We first look under a standard registry key.  If that fails we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * fall back on using a SHELL32.DLL API.  If that fails we use a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * default value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * Note: To save space we want to avoid loading SHELL32.DLL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * unless really necessary.  However if we do load it, we leave it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * in memory, as it may be needed again later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * The normal result is that for a given user name XXX:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *     On multi-user NT, user.home gets set to c:\winnt\profiles\XXX.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *     On multi-user Win95, user.home gets set to c:\windows\profiles\XXX.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *     On single-user Win95, user.home gets set to c:\windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    {
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   559
        WCHAR *homep = getHomeFromRegistry();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        if (homep == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            homep = getHomeFromShell32();
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   562
            if (homep == NULL)
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   563
                homep = L"C:\\";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   565
        sprops.user_home = _wcsdup(homep);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *  user.language
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   570
     *  user.script, user.country, user.variant (if user's environment specifies them)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *  file.encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *  file.encoding.pkg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
         * query the system for the current system default locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
         * (which is a Windows LCID value),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
         */
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   579
        LCID userDefaultLCID = GetUserDefaultLCID();
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   580
        LCID systemDefaultLCID = GetSystemDefaultLCID();
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   581
        LCID userDefaultUILang = GetUserDefaultUILanguage();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   584
            char * display_encoding;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   586
            SetupI18nProps(userDefaultUILang,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   587
                           &sprops.language,
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   588
                           &sprops.script,
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   589
                           &sprops.country,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   590
                           &sprops.variant,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   591
                           &display_encoding);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   592
            SetupI18nProps(userDefaultLCID,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   593
                           &sprops.format_language,
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   594
                           &sprops.format_script,
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   595
                           &sprops.format_country,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   596
                           &sprops.format_variant,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   597
                           &sprops.encoding);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   598
            SetupI18nProps(userDefaultUILang,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   599
                           &sprops.display_language,
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   600
                           &sprops.display_script,
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   601
                           &sprops.display_country,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   602
                           &sprops.display_variant,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   603
                           &display_encoding);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   605
            sprops.sun_jnu_encoding = getEncodingInternal(systemDefaultLCID);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   606
            if (LANGIDFROMLCID(userDefaultLCID) == 0x0c04 && ver.dwMajorVersion == 6) {
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   607
                // MS claims "Vista has built-in support for HKSCS-2004.
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   608
                // All of the HKSCS-2004 characters have Unicode 4.1.
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   609
                // PUA code point assignments". But what it really means
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   610
                // is that the HKSCS-2004 is ONLY supported in Unicode.
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   611
                // Test indicates the MS950 in its zh_HK locale is a
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   612
                // "regular" MS950 which does not handle HKSCS-2004 at
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   613
                // all. Set encoding to MS950_HKSCS.
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   614
                sprops.encoding = "MS950_HKSCS";
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   615
                sprops.sun_jnu_encoding = "MS950_HKSCS";
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   616
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    sprops.unicode_encoding = "UnicodeLittle";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    /* User TIMEZONE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
         * We defer setting up timezone until it's actually necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
         * Refer to TimeZone.getDefault(). However, the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
         * property is necessary to be able to be set by the command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
         * line interface -D. Here temporarily set a null string to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
         * timezone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        sprops.timezone = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    /* Current directory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    {
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   635
        WCHAR buf[MAX_PATH];
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   636
        GetCurrentDirectoryW(sizeof(buf), buf);
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   637
        sprops.user_dir = _wcsdup(buf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    sprops.file_separator = "\\";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    sprops.path_separator = ";";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    sprops.line_separator = "\r\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    return &sprops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
}
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   646
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   647
jstring
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   648
GetStringPlatform(JNIEnv *env, nchar* wcstr)
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   649
{
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   650
    return (*env)->NewString(env, wcstr, wcslen(wcstr));
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   651
}