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