source: josm/trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java@ 8449

Last change on this file since 8449 was 8404, checked in by Don-vip, 9 years ago

When doing a String.toLowerCase()/toUpperCase() call, use a Locale. This avoids problems with certain locales, i.e. Lithuanian or Turkish. See PMD UseLocaleWithCaseConversions rule and String.toLowerCase() javadoc.

  • Property svn:eol-style set to native
File size: 26.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import static java.awt.event.InputEvent.ALT_DOWN_MASK;
5import static java.awt.event.InputEvent.CTRL_DOWN_MASK;
6import static java.awt.event.InputEvent.SHIFT_DOWN_MASK;
7import static java.awt.event.KeyEvent.VK_A;
8import static java.awt.event.KeyEvent.VK_C;
9import static java.awt.event.KeyEvent.VK_D;
10import static java.awt.event.KeyEvent.VK_DELETE;
11import static java.awt.event.KeyEvent.VK_DOWN;
12import static java.awt.event.KeyEvent.VK_ENTER;
13import static java.awt.event.KeyEvent.VK_ESCAPE;
14import static java.awt.event.KeyEvent.VK_F10;
15import static java.awt.event.KeyEvent.VK_F4;
16import static java.awt.event.KeyEvent.VK_LEFT;
17import static java.awt.event.KeyEvent.VK_NUM_LOCK;
18import static java.awt.event.KeyEvent.VK_PRINTSCREEN;
19import static java.awt.event.KeyEvent.VK_RIGHT;
20import static java.awt.event.KeyEvent.VK_SHIFT;
21import static java.awt.event.KeyEvent.VK_SPACE;
22import static java.awt.event.KeyEvent.VK_TAB;
23import static java.awt.event.KeyEvent.VK_UP;
24import static java.awt.event.KeyEvent.VK_V;
25import static java.awt.event.KeyEvent.VK_X;
26import static java.awt.event.KeyEvent.VK_Y;
27import static java.awt.event.KeyEvent.VK_Z;
28import static org.openstreetmap.josm.tools.I18n.tr;
29
30import java.awt.GraphicsEnvironment;
31import java.io.File;
32import java.io.IOException;
33import java.nio.file.DirectoryStream;
34import java.nio.file.FileSystems;
35import java.nio.file.Files;
36import java.nio.file.Path;
37import java.security.InvalidKeyException;
38import java.security.KeyFactory;
39import java.security.KeyStore;
40import java.security.KeyStoreException;
41import java.security.NoSuchAlgorithmException;
42import java.security.NoSuchProviderException;
43import java.security.PublicKey;
44import java.security.SignatureException;
45import java.security.cert.CertificateException;
46import java.security.spec.InvalidKeySpecException;
47import java.security.spec.X509EncodedKeySpec;
48import java.util.ArrayList;
49import java.util.Collection;
50import java.util.Enumeration;
51import java.util.List;
52import java.util.Locale;
53
54import javax.swing.JOptionPane;
55
56import org.openstreetmap.josm.Main;
57
58/**
59 * {@code PlatformHook} implementation for Microsoft Windows systems.
60 * @since 1023
61 */
62public class PlatformHookWindows extends PlatformHookUnixoid implements PlatformHook {
63
64 private static final byte[] INSECURE_PUBLIC_KEY = new byte[] {
65 0x30, (byte) 0x82, 0x1, 0x22, 0x30, 0xd, 0x6, 0x9, 0x2a, (byte) 0x86, 0x48,
66 (byte) 0x86, (byte) 0xf7, 0xd, 0x1, 0x1, 0x1, 0x5, 0x0, 0x3, (byte) 0x82, 0x1, 0xf, 0x0,
67 0x30, (byte) 0x82, 0x01, 0x0a, 0x02, (byte) 0x82, 0x01, 0x01, 0x00, (byte) 0x95, (byte) 0x95, (byte) 0x88,
68 (byte) 0x84, (byte) 0xc8, (byte) 0xd9, 0x6b, (byte) 0xc5, (byte) 0xda, 0x0b, 0x69, (byte) 0xbf, (byte) 0xfc,
69 0x7e, (byte) 0xb9, (byte) 0x96, 0x2c, (byte) 0xeb, (byte) 0x8f, (byte) 0xbc, 0x6e, 0x40, (byte) 0xe6, (byte) 0xe2,
70 (byte) 0xfc, (byte) 0xf1, 0x7f, 0x73, (byte) 0xa7, (byte) 0x9d, (byte) 0xde, (byte) 0xc7, (byte) 0x88, 0x57, 0x51,
71 (byte) 0x84, (byte) 0xed, (byte) 0x96, (byte) 0xfb, (byte) 0xe1, 0x38, (byte) 0xef, 0x08, 0x2b, (byte) 0xf3,
72 (byte) 0xc7, (byte) 0xc3, 0x5d, (byte) 0xfe, (byte) 0xf9, 0x51, (byte) 0xe6, 0x29, (byte) 0xfc, (byte) 0xe5, 0x0d,
73 (byte) 0xa1, 0x0d, (byte) 0xa8, (byte) 0xb4, (byte) 0xae, 0x26, 0x18, 0x19, 0x4d, 0x6c, 0x0c, 0x3b, 0x12, (byte) 0xba,
74 (byte) 0xbc, 0x5f, 0x32, (byte) 0xb3, (byte) 0xbe, (byte) 0x9d, 0x17, 0x0d, 0x4d, 0x2f, 0x1a, 0x48, (byte) 0xb7,
75 (byte) 0xac, (byte) 0xf7, 0x1a, 0x43, 0x01, (byte) 0x97, (byte) 0xf4, (byte) 0xf8, 0x4c, (byte) 0xbb, 0x6a, (byte) 0xbc,
76 0x33, (byte) 0xe1, 0x73, 0x1e, (byte) 0x86, (byte) 0xfb, 0x2e, (byte) 0xb1, 0x63, 0x75, (byte) 0x85, (byte) 0xdc,
77 (byte) 0x82, 0x6c, 0x28, (byte) 0xf1, (byte) 0xe3, (byte) 0x90, 0x63, (byte) 0x9d, 0x3d, 0x48, (byte) 0x8a, (byte) 0x8c,
78 0x47, (byte) 0xe2, 0x10, 0x0b, (byte) 0xef, (byte) 0x91, (byte) 0x94, (byte) 0xb0, 0x6c, 0x4c, (byte) 0x80, 0x76, 0x03,
79 (byte) 0xe1, (byte) 0xb6, (byte) 0x90, (byte) 0x87, (byte) 0xd9, (byte) 0xae, (byte) 0xf4, (byte) 0x8e, (byte) 0xe0,
80 (byte) 0x9f, (byte) 0xe7, 0x3a, 0x2c, 0x2f, 0x21, (byte) 0xd4, 0x46, (byte) 0xba, (byte) 0x95, 0x70, (byte) 0xa9, 0x5b,
81 0x20, 0x2a, (byte) 0xfa, 0x52, 0x3e, (byte) 0x9d, (byte) 0xd9, (byte) 0xef, 0x28, (byte) 0xc5, (byte) 0xd1, 0x60,
82 (byte) 0x89, 0x68, 0x6e, 0x7f, (byte) 0xd7, (byte) 0x9e, (byte) 0x89, 0x4c, (byte) 0xeb, 0x4d, (byte) 0xd2, (byte) 0xc6,
83 (byte) 0xf4, 0x2d, 0x02, 0x5d, (byte) 0xda, (byte) 0xde, 0x33, (byte) 0xfe, (byte) 0xc1, 0x7e, (byte) 0xde, 0x4f, 0x1f,
84 (byte) 0x9b, 0x6e, 0x6f, 0x0f, 0x66, 0x71, 0x19, (byte) 0xe9, 0x43, 0x3c, (byte) 0x83, 0x0a, 0x0f, 0x28, 0x21, (byte) 0xc8,
85 0x38, (byte) 0xd3, 0x4e, 0x48, (byte) 0xdf, (byte) 0xd4, (byte) 0x99, (byte) 0xb5, (byte) 0xc6, (byte) 0x8d, (byte) 0xd4,
86 (byte) 0xc1, 0x69, 0x58, 0x79, (byte) 0x82, 0x32, (byte) 0x82, (byte) 0xd4, (byte) 0x86, (byte) 0xe2, 0x04, 0x08, 0x63,
87 (byte) 0x87, (byte) 0xf0, 0x2a, (byte) 0xf6, (byte) 0xec, 0x3e, 0x51, 0x0f, (byte) 0xda, (byte) 0xb4, 0x67, 0x19, 0x5e,
88 0x16, 0x02, (byte) 0x9f, (byte) 0xf1, 0x19, 0x0c, 0x3e, (byte) 0xb8, 0x04, 0x49, 0x07, 0x53, 0x02, 0x03, 0x01, 0x00, 0x01
89 };
90
91 private static final String WINDOWS_ROOT = "Windows-ROOT";
92
93 @Override
94 public void afterPrefStartupHook() {
95 extendFontconfig("fontconfig.properties.src");
96 }
97
98 @Override
99 public void openUrl(String url) throws IOException {
100 Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
101 }
102
103 @Override
104 public void initSystemShortcuts() {
105 //Shortcut.registerSystemCut("system:menuexit", tr("reserved"), VK_Q, CTRL_DOWN_MASK);
106 Shortcut.registerSystemShortcut("system:duplicate", tr("reserved"), VK_D, CTRL_DOWN_MASK); // not really system, but to avoid odd results
107
108 // Windows 7 shortcuts: http://windows.microsoft.com/en-US/windows7/Keyboard-shortcuts
109
110 // Shortcuts with setAutomatic(): items with automatic shortcuts will not be added to the menu bar at all
111
112 // Don't know why Ctrl-Alt-Del isn't even listed on official Microsoft support page
113 Shortcut.registerSystemShortcut("system:reset", tr("reserved"), VK_DELETE, CTRL_DOWN_MASK | ALT_DOWN_MASK).setAutomatic();
114
115 // Ease of Access keyboard shortcuts
116 Shortcut.registerSystemShortcut("microsoft-reserved-01", tr("reserved"), VK_PRINTSCREEN, ALT_DOWN_MASK | SHIFT_DOWN_MASK).setAutomatic(); // Turn High Contrast on or off
117 Shortcut.registerSystemShortcut("microsoft-reserved-02", tr("reserved"), VK_NUM_LOCK, ALT_DOWN_MASK | SHIFT_DOWN_MASK).setAutomatic(); // Turn Mouse Keys on or off
118 //Shortcut.registerSystemCut("microsoft-reserved-03", tr("reserved"), VK_U, );// Open the Ease of Access Center (TODO: Windows-U, how to handle it in Java ?)
119
120 // General keyboard shortcuts
121 //Shortcut.registerSystemShortcut("system:help", tr("reserved"), VK_F1, 0); // Display Help
122 Shortcut.registerSystemShortcut("system:copy", tr("reserved"), VK_C, CTRL_DOWN_MASK); // Copy the selected item
123 Shortcut.registerSystemShortcut("system:cut", tr("reserved"), VK_X, CTRL_DOWN_MASK); // Cut the selected item
124 Shortcut.registerSystemShortcut("system:paste", tr("reserved"), VK_V, CTRL_DOWN_MASK); // Paste the selected item
125 Shortcut.registerSystemShortcut("system:undo", tr("reserved"), VK_Z, CTRL_DOWN_MASK); // Undo an action
126 Shortcut.registerSystemShortcut("system:redo", tr("reserved"), VK_Y, CTRL_DOWN_MASK); // Redo an action
127 //Shortcut.registerSystemCut("microsoft-reserved-10", tr("reserved"), VK_DELETE, 0); // Delete the selected item and move it to the Recycle Bin
128 //Shortcut.registerSystemCut("microsoft-reserved-11", tr("reserved"), VK_DELETE, SHIFT_DOWN_MASK); // Delete the selected item without moving it to the Recycle Bin first
129 //Shortcut.registerSystemCut("system:rename", tr("reserved"), VK_F2, 0); // Rename the selected item
130 Shortcut.registerSystemShortcut("system:movefocusright", tr("reserved"), VK_RIGHT, CTRL_DOWN_MASK); // Move the cursor to the beginning of the next word
131 Shortcut.registerSystemShortcut("system:movefocusleft", tr("reserved"), VK_LEFT, CTRL_DOWN_MASK); // Move the cursor to the beginning of the previous word
132 Shortcut.registerSystemShortcut("system:movefocusdown", tr("reserved"), VK_DOWN, CTRL_DOWN_MASK); // Move the cursor to the beginning of the next paragraph
133 Shortcut.registerSystemShortcut("system:movefocusup", tr("reserved"), VK_UP, CTRL_DOWN_MASK); // Move the cursor to the beginning of the previous paragraph
134 //Shortcut.registerSystemCut("microsoft-reserved-17", tr("reserved"), VK_RIGHT, CTRL_DOWN_MASK | SHIFT_DOWN_MASK); // Select a block of text
135 //Shortcut.registerSystemCut("microsoft-reserved-18", tr("reserved"), VK_LEFT, CTRL_DOWN_MASK | SHIFT_DOWN_MASK); // Select a block of text
136 //Shortcut.registerSystemCut("microsoft-reserved-19", tr("reserved"), VK_DOWN, CTRL_DOWN_MASK | SHIFT_DOWN_MASK); // Select a block of text
137 //Shortcut.registerSystemCut("microsoft-reserved-20", tr("reserved"), VK_UP, CTRL_DOWN_MASK | SHIFT_DOWN_MASK); // Select a block of text
138 //Shortcut.registerSystemCut("microsoft-reserved-21", tr("reserved"), VK_RIGHT, SHIFT_DOWN_MASK); // Select more than one item in a window or on the desktop, or select text within a document
139 //Shortcut.registerSystemCut("microsoft-reserved-22", tr("reserved"), VK_LEFT, SHIFT_DOWN_MASK); // Select more than one item in a window or on the desktop, or select text within a document
140 //Shortcut.registerSystemCut("microsoft-reserved-23", tr("reserved"), VK_DOWN, SHIFT_DOWN_MASK); // Select more than one item in a window or on the desktop, or select text within a document
141 //Shortcut.registerSystemCut("microsoft-reserved-24", tr("reserved"), VK_UP, SHIFT_DOWN_MASK); // Select more than one item in a window or on the desktop, or select text within a document
142 //Shortcut.registerSystemCut("microsoft-reserved-25", tr("reserved"), VK_RIGHT+, CTRL_DOWN_MASK); // Select multiple individual items in a window or on the desktop (TODO: ctrl+arrow+spacebar, how to handle it in Java ?)
143 //Shortcut.registerSystemCut("microsoft-reserved-26", tr("reserved"), VK_LEFT+, CTRL_DOWN_MASK); // Select multiple individual items in a window or on the desktop (TODO: ctrl+arrow+spacebar, how to handle it in Java ?)
144 //Shortcut.registerSystemCut("microsoft-reserved-27", tr("reserved"), VK_DOWN+, CTRL_DOWN_MASK); // Select multiple individual items in a window or on the desktop (TODO: ctrl+arrow+spacebar, how to handle it in Java ?)
145 //Shortcut.registerSystemCut("microsoft-reserved-28", tr("reserved"), VK_UP+, CTRL_DOWN_MASK); // Select multiple individual items in a window or on the desktop (TODO: ctrl+arrow+spacebar, how to handle it in Java ?)
146 Shortcut.registerSystemShortcut("system:selectall", tr("reserved"), VK_A, CTRL_DOWN_MASK); // Select all items in a document or window
147 //Shortcut.registerSystemCut("system:search", tr("reserved"), VK_F3, 0); // Search for a file or folder
148 Shortcut.registerSystemShortcut("microsoft-reserved-31", tr("reserved"), VK_ENTER, ALT_DOWN_MASK).setAutomatic(); // Display properties for the selected item
149 Shortcut.registerSystemShortcut("system:exit", tr("reserved"), VK_F4, ALT_DOWN_MASK).setAutomatic(); // Close the active item, or exit the active program
150 Shortcut.registerSystemShortcut("microsoft-reserved-33", tr("reserved"), VK_SPACE, ALT_DOWN_MASK).setAutomatic(); // Open the shortcut menu for the active window
151 //Shortcut.registerSystemCut("microsoft-reserved-34", tr("reserved"), VK_F4, CTRL_DOWN_MASK); // Close the active document (in programs that allow you to have multiple documents open simultaneously)
152 Shortcut.registerSystemShortcut("microsoft-reserved-35", tr("reserved"), VK_TAB, ALT_DOWN_MASK).setAutomatic(); // Switch between open items
153 Shortcut.registerSystemShortcut("microsoft-reserved-36", tr("reserved"), VK_TAB, CTRL_DOWN_MASK | ALT_DOWN_MASK).setAutomatic(); // Use the arrow keys to switch between open items
154 //Shortcut.registerSystemCut("microsoft-reserved-37", tr("reserved"), VK_TAB, ); // Cycle through programs on the taskbar by using Aero Flip 3-D (TODO: Windows-Tab, how to handle it in Java ?)
155 //Shortcut.registerSystemCut("microsoft-reserved-38", tr("reserved"), VK_TAB, CTRL_DOWN_MASK | ); // Use the arrow keys to cycle through programs on the taskbar by using Aero Flip 3-D (TODO: Ctrl-Windows-Tab, how to handle it in Java ?)
156 Shortcut.registerSystemShortcut("microsoft-reserved-39", tr("reserved"), VK_ESCAPE, ALT_DOWN_MASK).setAutomatic(); // Cycle through items in the order in which they were opened
157 //Shortcut.registerSystemCut("microsoft-reserved-40", tr("reserved"), VK_F6, 0); // Cycle through screen elements in a window or on the desktop
158 //Shortcut.registerSystemCut("microsoft-reserved-41", tr("reserved"), VK_F4, 0); // Display the address bar list in Windows Explorer
159 Shortcut.registerSystemShortcut("microsoft-reserved-42", tr("reserved"), VK_F10, SHIFT_DOWN_MASK); // Display the shortcut menu for the selected item
160 Shortcut.registerSystemShortcut("microsoft-reserved-43", tr("reserved"), VK_ESCAPE, CTRL_DOWN_MASK).setAutomatic(); // Open the Start menu
161 //Shortcut.registerSystemShortcut("microsoft-reserved-44", tr("reserved"), VK_F10, 0); // Activate the menu bar in the active program
162 //Shortcut.registerSystemCut("microsoft-reserved-45", tr("reserved"), VK_RIGHT, 0); // Open the next menu to the right, or open a submenu
163 //Shortcut.registerSystemCut("microsoft-reserved-46", tr("reserved"), VK_LEFT, 0); // Open the next menu to the left, or close a submenu
164 //Shortcut.registerSystemCut("microsoft-reserved-47", tr("reserved"), VK_F5, 0); // Refresh the active window
165 //Shortcut.registerSystemCut("microsoft-reserved-48", tr("reserved"), VK_UP, ALT_DOWN_MASK); // View the folder one level up in Windows Explorer
166 //Shortcut.registerSystemCut("microsoft-reserved-49", tr("reserved"), VK_ESCAPE, 0); // Cancel the current task
167 Shortcut.registerSystemShortcut("microsoft-reserved-50", tr("reserved"), VK_ESCAPE, CTRL_DOWN_MASK | SHIFT_DOWN_MASK).setAutomatic(); // Open Task Manager
168 Shortcut.registerSystemShortcut("microsoft-reserved-51", tr("reserved"), VK_SHIFT, ALT_DOWN_MASK).setAutomatic(); // Switch the input language when multiple input languages are enabled
169 Shortcut.registerSystemShortcut("microsoft-reserved-52", tr("reserved"), VK_SHIFT, CTRL_DOWN_MASK).setAutomatic(); // Switch the keyboard layout when multiple keyboard layouts are enabled
170 //Shortcut.registerSystemCut("microsoft-reserved-53", tr("reserved"), ); // Change the reading direction of text in right-to-left reading languages (TODO: unclear)
171 }
172
173 @Override
174 public String getDefaultStyle() {
175 return "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
176 }
177
178 @Override
179 public boolean rename(File from, File to) {
180 if (to.exists())
181 to.delete();
182 return from.renameTo(to);
183 }
184
185 @Override
186 public String getOSDescription() {
187 return Utils.strip(System.getProperty("os.name")) + " " +
188 ((System.getenv("ProgramFiles(x86)") == null) ? "32" : "64") + "-Bit";
189 }
190
191 /**
192 * Loads Windows-ROOT keystore.
193 * @return Windows-ROOT keystore
194 * @throws NoSuchAlgorithmException if the algorithm used to check the integrity of the keystore cannot be found
195 * @throws CertificateException if any of the certificates in the keystore could not be loaded
196 * @throws IOException if there is an I/O or format problem with the keystore data, if a password is required but not given
197 * @throws KeyStoreException if no Provider supports a KeyStore implementation for the type "Windows-ROOT"
198 * @since 7343
199 */
200 public static KeyStore getRootKeystore() throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException {
201 KeyStore ks = KeyStore.getInstance(WINDOWS_ROOT);
202 ks.load(null, null);
203 return ks;
204 }
205
206 /**
207 * Removes potential insecure certificates installed with previous versions of JOSM on Windows.
208 * @throws NoSuchAlgorithmException on unsupported signature algorithms
209 * @throws CertificateException if any of the certificates in the Windows keystore could not be loaded
210 * @throws KeyStoreException if no Provider supports a KeyStoreSpi implementation for the type "Windows-ROOT"
211 * @throws IOException if there is an I/O or format problem with the keystore data, if a password is required but not given
212 * @since 7335
213 */
214 public static void removeInsecureCertificates() throws NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException {
215 // We offered before a public private key we need now to remove from Windows PCs as it might be a huge security risk (see #10230)
216 PublicKey insecurePubKey = null;
217 try {
218 insecurePubKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(INSECURE_PUBLIC_KEY));
219 } catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
220 Main.error(e);
221 return;
222 }
223 KeyStore ks = getRootKeystore();
224 Enumeration<String> en = ks.aliases();
225 Collection<String> insecureCertificates = new ArrayList<>();
226 while (en.hasMoreElements()) {
227 String alias = en.nextElement();
228 // Look for certificates associated with a private key
229 if (ks.isKeyEntry(alias)) {
230 try {
231 ks.getCertificate(alias).verify(insecurePubKey);
232 // If no exception, this is a certificate signed with the insecure key -> remove it
233 insecureCertificates.add(alias);
234 } catch (InvalidKeyException | NoSuchProviderException | SignatureException e) {
235 // If exception this is not a certificate related to JOSM, just trace it
236 Main.trace(alias + " --> " + e.getClass().getName());
237 }
238 }
239 }
240 // Remove insecure certificates
241 if (!insecureCertificates.isEmpty()) {
242 StringBuilder message = new StringBuilder("<html>");
243 message.append(tr("A previous version of JOSM has installed a custom certificate "+
244 "in order to provide HTTPS support for Remote Control:"))
245 .append("<br><ul>");
246 for (String alias : insecureCertificates) {
247 message.append("<li>")
248 .append(alias)
249 .append("</li>");
250 }
251 message.append("</ul>")
252 .append(tr("It appears it could be an important <b>security risk</b>.<br><br>"+
253 "You are now going to be prompted by Windows to remove this insecure certificate.<br>"+
254 "For your own safety, <b>please click Yes</b> in next dialog."))
255 .append("</html>");
256 JOptionPane.showMessageDialog(Main.parent, message.toString(), tr("Warning"), JOptionPane.WARNING_MESSAGE);
257 for (String alias : insecureCertificates) {
258 Main.warn(tr("Removing insecure certificate from {0} keystore: {1}", WINDOWS_ROOT, alias));
259 try {
260 ks.deleteEntry(alias);
261 } catch (KeyStoreException e) {
262 Main.error(tr("Unable to remove insecure certificate from keystore: {0}", e.getMessage()));
263 }
264 }
265 }
266 }
267
268 @Override
269 public boolean setupHttpsCertificate(String entryAlias, KeyStore.TrustedCertificateEntry trustedCert)
270 throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
271 KeyStore ks = getRootKeystore();
272 // Look for certificate to install
273 String alias = ks.getCertificateAlias(trustedCert.getTrustedCertificate());
274 if (alias != null) {
275 // JOSM certificate found, return
276 Main.debug(tr("JOSM localhost certificate found in {0} keystore: {1}", WINDOWS_ROOT, alias));
277 return false;
278 }
279 if (!GraphicsEnvironment.isHeadless()) {
280 // JOSM certificate not found, warn user
281 StringBuilder message = new StringBuilder("<html>");
282 message.append(tr("Remote Control is configured to provide HTTPS support.<br>"+
283 "This requires to add a custom certificate generated by JOSM to the Windows Root CA store.<br><br>"+
284 "You are now going to be prompted by Windows to confirm this operation.<br>"+
285 "To enable proper HTTPS support, <b>please click Yes</b> in next dialog.<br><br>"+
286 "If unsure, you can also click No then disable HTTPS support in Remote Control preferences."))
287 .append("</html>");
288 JOptionPane.showMessageDialog(Main.parent, message.toString(),
289 tr("HTTPS support in Remote Control"), JOptionPane.INFORMATION_MESSAGE);
290 }
291 // install it to Windows-ROOT keystore, used by IE, Chrome and Safari, but not by Firefox
292 Main.info(tr("Adding JOSM localhost certificate to {0} keystore", WINDOWS_ROOT));
293 ks.setEntry(entryAlias, trustedCert, null);
294 return true;
295 }
296
297 @Override
298 public File getDefaultCacheDirectory() {
299 String p = System.getenv("LOCALAPPDATA");
300 if (p == null || p.isEmpty()) {
301 // Fallback for Windows OS earlier than Windows Vista, where the variable is not defined
302 p = System.getenv("APPDATA");
303 }
304 return new File(new File(p, "JOSM"), "cache");
305 }
306
307 @Override
308 public File getDefaultPrefDirectory() {
309 return new File(System.getenv("APPDATA"), "JOSM");
310 }
311
312 @Override
313 public Collection<String> getInstalledFonts() {
314 // Cannot use GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()
315 // because we have to set the system property before Java initializes its fonts.
316 // Use more low-level method to find the installed fonts.
317 List<String> fontsAvail = new ArrayList<>();
318 Path fontPath = FileSystems.getDefault().getPath(System.getenv("SYSTEMROOT"), "Fonts");
319 try (DirectoryStream<Path> ds = Files.newDirectoryStream(fontPath)) {
320 for (Path p : ds) {
321 Path filename = p.getFileName();
322 if (filename != null) {
323 fontsAvail.add(filename.toString().toUpperCase(Locale.ENGLISH));
324 }
325 }
326 fontsAvail.add(""); // for devanagari
327 } catch (IOException ex) {
328 Main.error(ex, false);
329 Main.warn("extended font config - failed to load available Fonts");
330 fontsAvail = null;
331 }
332 return fontsAvail;
333 }
334
335 @Override
336 public Collection<FontEntry> getAdditionalFonts() {
337 Collection<FontEntry> def = new ArrayList<>();
338 def.add(new FontEntry("devanagari", "", "")); // just include in fallback list
339 // font already defined in template
340
341 // Windows scripts: https://msdn.microsoft.com/en-us/goglobal/bb688099.aspx
342 // IE default fonts: https://msdn.microsoft.com/en-us/library/ie/dn467844(v=vs.85).aspx
343
344 // Windows 8/8.1 and later
345 def.add(new FontEntry("javanese", "Javanese Text", "JAVATEXT.TTF")); // ISO 639: jv
346 def.add(new FontEntry("leelawadee", "Leelawadee", "LEELAWAD.TTF")); // ISO 639: bug
347 def.add(new FontEntry("myanmar", "Myanmar Text", "MMRTEXT.TTF")); // ISO 639: my
348 def.add(new FontEntry("nirmala", "Nirmala UI", "NIRMALA.TTF")); // ISO 639: sat,srb
349 def.add(new FontEntry("segoeui", "Segoe UI", "SEGOEUI.TTF")); // ISO 639: lis
350
351 // Windows 7 and later
352 def.add(new FontEntry("nko_tifinagh_vai_osmanya", "Ebrima", "EBRIMA.TTF")); // ISO 639: ber. Nko only since Win 8
353 def.add(new FontEntry("khmer1", "Khmer UI", "KHMERUI.TTF")); // ISO 639: km
354 def.add(new FontEntry("lao1", "Lao UI", "LAOUI.TTF")); // ISO 639: lo
355 def.add(new FontEntry("tai_le", "Microsoft Tai Le", "TAILE.TTF")); // ISO 639: khb
356 def.add(new FontEntry("new_tai_lue", "Microsoft New Tai Lue", "NTHAILU.TTF")); // ISO 639: khb
357
358 // Windows Vista and later:
359 def.add(new FontEntry("ethiopic", "Nyala", "NYALA.TTF")); // ISO 639: am,gez,ti
360 def.add(new FontEntry("tibetan", "Microsoft Himalaya", "HIMALAYA.TTF")); // ISO 639: bo,dz
361 def.add(new FontEntry("cherokee", "Plantagenet Cherokee", "PLANTC.TTF")); // ISO 639: chr
362 def.add(new FontEntry("unified_canadian", "Euphemia", "EUPHEMIA.TTF")); // ISO 639: cr,in
363 def.add(new FontEntry("khmer2", "DaunPenh", "DAUNPENH.TTF")); // ISO 639: km
364 def.add(new FontEntry("khmer3", "MoolBoran", "MOOLBOR.TTF")); // ISO 639: km
365 def.add(new FontEntry("lao_thai", "DokChampa", "DOKCHAMP.TTF")); // ISO 639: lo
366 def.add(new FontEntry("mongolian", "Mongolian Baiti", "MONBAITI.TTF")); // ISO 639: mn
367 def.add(new FontEntry("oriya", "Kalinga", "KALINGA.TTF")); // ISO 639: or
368 def.add(new FontEntry("sinhala", "Iskoola Pota", "ISKPOTA.TTF")); // ISO 639: si
369 def.add(new FontEntry("yi", "Yi Baiti", "MSYI.TTF")); // ISO 639: ii
370
371 // Windows XP and later
372 def.add(new FontEntry("gujarati", "Shruti", "SHRUTI.TTF"));
373 def.add(new FontEntry("kannada", "Tunga", "TUNGA.TTF"));
374 def.add(new FontEntry("gurmukhi", "Raavi", "RAAVI.TTF"));
375 def.add(new FontEntry("telugu", "Gautami", "GAUTAMI.TTF"));
376 def.add(new FontEntry("bengali", "Vrinda", "VRINDA.TTF")); // since XP SP2
377 def.add(new FontEntry("syriac", "Estrangelo Edessa", "ESTRE.TTF")); // ISO 639: arc
378 def.add(new FontEntry("thaana", "MV Boli", "MVBOLI.TTF")); // ISO 639: dv
379 def.add(new FontEntry("malayalam", "Kartika", "KARTIKA.TTF")); // ISO 639: ml; since XP SP2
380
381 // Windows 2000 and later
382 def.add(new FontEntry("tamil", "Latha", "LATHA.TTF"));
383
384 // Comes with MS Office & Outlook 2000. Good unicode coverage, so add if available.
385 def.add(new FontEntry("arialuni", "Arial Unicode MS", "ARIALUNI.TTF"));
386
387 return def;
388 }
389}
Note: See TracBrowser for help on using the repository browser.