blob: 104e7b77ae4ea846604432e48844dea1cf442774 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23/*
24 *
25 *
26 * A simple tool to output all the installed locales on a Windows machine, and
27 * corresponding Java default locale/file.encoding using PrintDefaultLocale
28 *
29 * WARNING: This tool directly modifies the locale info in the Windows registry.
30 * It may not work with the Windows versions after Windows XP SP2. Also,
31 * if the test did not complete or was manually killed, you will need to reset
32 * the user default locale in the Control Panel manually.
33 *
34 * Usage: "deflocale.exe <java launcher> PrintDefaultLocale
35 *
36 * How to compile: "cl deflocale.c advapi32.lib"
37 */
38#include <windows.h>
39#include <stdio.h>
40#include <memory.h>
41
42char* launcher;
43char szBuffer[MAX_PATH];
44LCID LCIDArray[1024];
45int numLCIDs = 0;
46
47void testLCID(int anLCID) {
48 HKEY hk;
49
50 printf("\n");
51 printf("OS Locale (lcid: %x): ", anLCID);
52 GetLocaleInfo(anLCID, LOCALE_SENGLANGUAGE, szBuffer, MAX_PATH);
53 printf("%s (", szBuffer);
54 GetLocaleInfo(anLCID, LOCALE_SENGCOUNTRY, szBuffer, MAX_PATH);
55 printf("%s) - ", szBuffer);
56 GetLocaleInfo(anLCID, LOCALE_IDEFAULTANSICODEPAGE, szBuffer, MAX_PATH);
57 printf("%s\n", szBuffer);
58 fflush(0);
59
60 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\International", 0, KEY_READ | KEY_WRITE, &hk) == ERROR_SUCCESS) {
61 BYTE original[16];
62 BYTE test[16];
63 DWORD cb = 16;
64 STARTUPINFO si;
65 PROCESS_INFORMATION pi;
66
67 RegQueryValueEx(hk, "Locale", 0, 0, original, &cb);
68 sprintf(test, "%08x", anLCID);
69 RegSetValueEx(hk, "Locale", 0, REG_SZ, test, cb);
70
71 ZeroMemory(&si, sizeof(si));
72 si.cb = sizeof(si);
73 ZeroMemory(&pi, sizeof(pi));
74 if (CreateProcess(NULL, launcher, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)==0) {
75 printf("CreateProcess failed with the error code: %x\n", GetLastError());
76 }
77
78 WaitForSingleObject( pi.hProcess, INFINITE );
79
80 RegSetValueEx(hk, "Locale", 0, REG_SZ, original, cb);
81 RegCloseKey(hk);
82 }
83}
84
85BOOL CALLBACK EnumLocaleProc(LPTSTR lpLocaleStr) {
86 sscanf(lpLocaleStr, "%08x", &LCIDArray[numLCIDs]);
87 numLCIDs ++;
88
89 return TRUE;
90}
91
92int sortLCIDs(LCID * pLCID1, LCID * pLCID2) {
93 if (*pLCID1 < *pLCID2) return (-1);
94 if (*pLCID1 == *pLCID2) return 0;
95 if (*pLCID1 > *pLCID2) return 1;
96}
97
98int main(int argc, char** argv) {
99 OSVERSIONINFO osvi;
100 LPTSTR commandline = GetCommandLine();
101 int i;
102
103 osvi.dwOSVersionInfoSize = sizeof(osvi);
104 GetVersionEx(&osvi);
105 printf("# OSVersionInfo\n");
106 printf("# MajorVersion: %d\n", osvi.dwMajorVersion);
107 printf("# MinorVersion: %d\n", osvi.dwMinorVersion);
108 printf("# BuildNumber: %d\n", osvi.dwBuildNumber);
109 printf("# CSDVersion: %s\n", osvi.szCSDVersion);
110 printf("\n");
111 fflush(0);
112
113 launcher = strchr(commandline, ' ')+1;
114 while (*launcher == ' ') {
115 launcher++;
116 }
117
118 // Enumerate locales
119 EnumSystemLocales(EnumLocaleProc, LCID_INSTALLED);
120
121 // Sort LCIDs
122 qsort(LCIDArray, numLCIDs, sizeof(LCID), (void *)sortLCIDs);
123
124 // Execute enumeration of Java default locales
125 for (i = 0; i < numLCIDs; i ++) {
126 testLCID(LCIDArray[i]);
127 }
128}