| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.tools;
|
|---|
| 3 |
|
|---|
| 4 | import static java.awt.event.InputEvent.ALT_DOWN_MASK;
|
|---|
| 5 | import static java.awt.event.InputEvent.CTRL_DOWN_MASK;
|
|---|
| 6 | import static java.awt.event.InputEvent.SHIFT_DOWN_MASK;
|
|---|
| 7 | import static java.awt.event.KeyEvent.VK_A;
|
|---|
| 8 | import static java.awt.event.KeyEvent.VK_C;
|
|---|
| 9 | import static java.awt.event.KeyEvent.VK_D;
|
|---|
| 10 | import static java.awt.event.KeyEvent.VK_DELETE;
|
|---|
| 11 | import static java.awt.event.KeyEvent.VK_DOWN;
|
|---|
| 12 | import static java.awt.event.KeyEvent.VK_ENTER;
|
|---|
| 13 | import static java.awt.event.KeyEvent.VK_ESCAPE;
|
|---|
| 14 | import static java.awt.event.KeyEvent.VK_F10;
|
|---|
| 15 | import static java.awt.event.KeyEvent.VK_F4;
|
|---|
| 16 | import static java.awt.event.KeyEvent.VK_LEFT;
|
|---|
| 17 | import static java.awt.event.KeyEvent.VK_NUM_LOCK;
|
|---|
| 18 | import static java.awt.event.KeyEvent.VK_PRINTSCREEN;
|
|---|
| 19 | import static java.awt.event.KeyEvent.VK_RIGHT;
|
|---|
| 20 | import static java.awt.event.KeyEvent.VK_SHIFT;
|
|---|
| 21 | import static java.awt.event.KeyEvent.VK_SPACE;
|
|---|
| 22 | import static java.awt.event.KeyEvent.VK_TAB;
|
|---|
| 23 | import static java.awt.event.KeyEvent.VK_UP;
|
|---|
| 24 | import static java.awt.event.KeyEvent.VK_V;
|
|---|
| 25 | import static java.awt.event.KeyEvent.VK_X;
|
|---|
| 26 | import static java.awt.event.KeyEvent.VK_Y;
|
|---|
| 27 | import static java.awt.event.KeyEvent.VK_Z;
|
|---|
| 28 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 29 | import static org.openstreetmap.josm.tools.WinRegistry.HKEY_LOCAL_MACHINE;
|
|---|
| 30 |
|
|---|
| 31 | import java.awt.GraphicsEnvironment;
|
|---|
| 32 | import java.io.BufferedWriter;
|
|---|
| 33 | import java.io.File;
|
|---|
| 34 | import java.io.FileInputStream;
|
|---|
| 35 | import java.io.IOException;
|
|---|
| 36 | import java.io.OutputStream;
|
|---|
| 37 | import java.io.OutputStreamWriter;
|
|---|
| 38 | import java.io.Writer;
|
|---|
| 39 | import java.lang.reflect.InvocationTargetException;
|
|---|
| 40 | import java.nio.charset.StandardCharsets;
|
|---|
| 41 | import java.nio.file.DirectoryStream;
|
|---|
| 42 | import java.nio.file.FileSystems;
|
|---|
| 43 | import java.nio.file.Files;
|
|---|
| 44 | import java.nio.file.Path;
|
|---|
| 45 | import java.security.InvalidKeyException;
|
|---|
| 46 | import java.security.KeyFactory;
|
|---|
| 47 | import java.security.KeyStore;
|
|---|
| 48 | import java.security.KeyStoreException;
|
|---|
| 49 | import java.security.MessageDigest;
|
|---|
| 50 | import java.security.NoSuchAlgorithmException;
|
|---|
| 51 | import java.security.NoSuchProviderException;
|
|---|
| 52 | import java.security.PublicKey;
|
|---|
| 53 | import java.security.SignatureException;
|
|---|
| 54 | import java.security.cert.Certificate;
|
|---|
| 55 | import java.security.cert.CertificateException;
|
|---|
| 56 | import java.security.cert.X509Certificate;
|
|---|
| 57 | import java.security.spec.InvalidKeySpecException;
|
|---|
| 58 | import java.security.spec.X509EncodedKeySpec;
|
|---|
| 59 | import java.util.ArrayList;
|
|---|
| 60 | import java.util.Arrays;
|
|---|
| 61 | import java.util.Collection;
|
|---|
| 62 | import java.util.Enumeration;
|
|---|
| 63 | import java.util.List;
|
|---|
| 64 | import java.util.Locale;
|
|---|
| 65 | import java.util.Properties;
|
|---|
| 66 |
|
|---|
| 67 | import javax.swing.JOptionPane;
|
|---|
| 68 |
|
|---|
| 69 | import org.openstreetmap.josm.Main;
|
|---|
| 70 | import org.openstreetmap.josm.data.Preferences;
|
|---|
| 71 | import org.openstreetmap.josm.io.CertificateAmendment.CertAmend;
|
|---|
| 72 |
|
|---|
| 73 | /**
|
|---|
| 74 | * {@code PlatformHook} implementation for Microsoft Windows systems.
|
|---|
| 75 | * @since 1023
|
|---|
| 76 | */
|
|---|
| 77 | public class PlatformHookWindows implements PlatformHook {
|
|---|
| 78 |
|
|---|
| 79 | /**
|
|---|
| 80 | * Simple data class to hold information about a font.
|
|---|
| 81 | *
|
|---|
| 82 | * Used for fontconfig.properties files.
|
|---|
| 83 | */
|
|---|
| 84 | public static class FontEntry {
|
|---|
| 85 | /**
|
|---|
| 86 | * The character subset. Basically a free identifier, but should be unique.
|
|---|
| 87 | */
|
|---|
| 88 | @Preferences.pref
|
|---|
| 89 | public String charset;
|
|---|
| 90 |
|
|---|
| 91 | /**
|
|---|
| 92 | * Platform font name.
|
|---|
| 93 | */
|
|---|
| 94 | @Preferences.pref
|
|---|
| 95 | @Preferences.writeExplicitly
|
|---|
| 96 | public String name = "";
|
|---|
| 97 |
|
|---|
| 98 | /**
|
|---|
| 99 | * File name.
|
|---|
| 100 | */
|
|---|
| 101 | @Preferences.pref
|
|---|
| 102 | @Preferences.writeExplicitly
|
|---|
| 103 | public String file = "";
|
|---|
| 104 |
|
|---|
| 105 | /**
|
|---|
| 106 | * Constructs a new {@code FontEntry}.
|
|---|
| 107 | */
|
|---|
| 108 | public FontEntry() {
|
|---|
| 109 | // Default constructor needed for construction by reflection
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | /**
|
|---|
| 113 | * Constructs a new {@code FontEntry}.
|
|---|
| 114 | * @param charset The character subset. Basically a free identifier, but should be unique
|
|---|
| 115 | * @param name Platform font name
|
|---|
| 116 | * @param file File name
|
|---|
| 117 | */
|
|---|
| 118 | public FontEntry(String charset, String name, String file) {
|
|---|
| 119 | this.charset = charset;
|
|---|
| 120 | this.name = name;
|
|---|
| 121 | this.file = file;
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | private static final byte[] INSECURE_PUBLIC_KEY = new byte[] {
|
|---|
| 126 | 0x30, (byte) 0x82, 0x1, 0x22, 0x30, 0xd, 0x6, 0x9, 0x2a, (byte) 0x86, 0x48,
|
|---|
| 127 | (byte) 0x86, (byte) 0xf7, 0xd, 0x1, 0x1, 0x1, 0x5, 0x0, 0x3, (byte) 0x82, 0x1, 0xf, 0x0,
|
|---|
| 128 | 0x30, (byte) 0x82, 0x01, 0x0a, 0x02, (byte) 0x82, 0x01, 0x01, 0x00, (byte) 0x95, (byte) 0x95, (byte) 0x88,
|
|---|
| 129 | (byte) 0x84, (byte) 0xc8, (byte) 0xd9, 0x6b, (byte) 0xc5, (byte) 0xda, 0x0b, 0x69, (byte) 0xbf, (byte) 0xfc,
|
|---|
| 130 | 0x7e, (byte) 0xb9, (byte) 0x96, 0x2c, (byte) 0xeb, (byte) 0x8f, (byte) 0xbc, 0x6e, 0x40, (byte) 0xe6, (byte) 0xe2,
|
|---|
| 131 | (byte) 0xfc, (byte) 0xf1, 0x7f, 0x73, (byte) 0xa7, (byte) 0x9d, (byte) 0xde, (byte) 0xc7, (byte) 0x88, 0x57, 0x51,
|
|---|
| 132 | (byte) 0x84, (byte) 0xed, (byte) 0x96, (byte) 0xfb, (byte) 0xe1, 0x38, (byte) 0xef, 0x08, 0x2b, (byte) 0xf3,
|
|---|
| 133 | (byte) 0xc7, (byte) 0xc3, 0x5d, (byte) 0xfe, (byte) 0xf9, 0x51, (byte) 0xe6, 0x29, (byte) 0xfc, (byte) 0xe5, 0x0d,
|
|---|
| 134 | (byte) 0xa1, 0x0d, (byte) 0xa8, (byte) 0xb4, (byte) 0xae, 0x26, 0x18, 0x19, 0x4d, 0x6c, 0x0c, 0x3b, 0x12, (byte) 0xba,
|
|---|
| 135 | (byte) 0xbc, 0x5f, 0x32, (byte) 0xb3, (byte) 0xbe, (byte) 0x9d, 0x17, 0x0d, 0x4d, 0x2f, 0x1a, 0x48, (byte) 0xb7,
|
|---|
| 136 | (byte) 0xac, (byte) 0xf7, 0x1a, 0x43, 0x01, (byte) 0x97, (byte) 0xf4, (byte) 0xf8, 0x4c, (byte) 0xbb, 0x6a, (byte) 0xbc,
|
|---|
| 137 | 0x33, (byte) 0xe1, 0x73, 0x1e, (byte) 0x86, (byte) 0xfb, 0x2e, (byte) 0xb1, 0x63, 0x75, (byte) 0x85, (byte) 0xdc,
|
|---|
| 138 | (byte) 0x82, 0x6c, 0x28, (byte) 0xf1, (byte) 0xe3, (byte) 0x90, 0x63, (byte) 0x9d, 0x3d, 0x48, (byte) 0x8a, (byte) 0x8c,
|
|---|
| 139 | 0x47, (byte) 0xe2, 0x10, 0x0b, (byte) 0xef, (byte) 0x91, (byte) 0x94, (byte) 0xb0, 0x6c, 0x4c, (byte) 0x80, 0x76, 0x03,
|
|---|
| 140 | (byte) 0xe1, (byte) 0xb6, (byte) 0x90, (byte) 0x87, (byte) 0xd9, (byte) 0xae, (byte) 0xf4, (byte) 0x8e, (byte) 0xe0,
|
|---|
| 141 | (byte) 0x9f, (byte) 0xe7, 0x3a, 0x2c, 0x2f, 0x21, (byte) 0xd4, 0x46, (byte) 0xba, (byte) 0x95, 0x70, (byte) 0xa9, 0x5b,
|
|---|
| 142 | 0x20, 0x2a, (byte) 0xfa, 0x52, 0x3e, (byte) 0x9d, (byte) 0xd9, (byte) 0xef, 0x28, (byte) 0xc5, (byte) 0xd1, 0x60,
|
|---|
| 143 | (byte) 0x89, 0x68, 0x6e, 0x7f, (byte) 0xd7, (byte) 0x9e, (byte) 0x89, 0x4c, (byte) 0xeb, 0x4d, (byte) 0xd2, (byte) 0xc6,
|
|---|
| 144 | (byte) 0xf4, 0x2d, 0x02, 0x5d, (byte) 0xda, (byte) 0xde, 0x33, (byte) 0xfe, (byte) 0xc1, 0x7e, (byte) 0xde, 0x4f, 0x1f,
|
|---|
| 145 | (byte) 0x9b, 0x6e, 0x6f, 0x0f, 0x66, 0x71, 0x19, (byte) 0xe9, 0x43, 0x3c, (byte) 0x83, 0x0a, 0x0f, 0x28, 0x21, (byte) 0xc8,
|
|---|
| 146 | 0x38, (byte) 0xd3, 0x4e, 0x48, (byte) 0xdf, (byte) 0xd4, (byte) 0x99, (byte) 0xb5, (byte) 0xc6, (byte) 0x8d, (byte) 0xd4,
|
|---|
| 147 | (byte) 0xc1, 0x69, 0x58, 0x79, (byte) 0x82, 0x32, (byte) 0x82, (byte) 0xd4, (byte) 0x86, (byte) 0xe2, 0x04, 0x08, 0x63,
|
|---|
| 148 | (byte) 0x87, (byte) 0xf0, 0x2a, (byte) 0xf6, (byte) 0xec, 0x3e, 0x51, 0x0f, (byte) 0xda, (byte) 0xb4, 0x67, 0x19, 0x5e,
|
|---|
| 149 | 0x16, 0x02, (byte) 0x9f, (byte) 0xf1, 0x19, 0x0c, 0x3e, (byte) 0xb8, 0x04, 0x49, 0x07, 0x53, 0x02, 0x03, 0x01, 0x00, 0x01
|
|---|
| 150 | };
|
|---|
| 151 |
|
|---|
| 152 | private static final String WINDOWS_ROOT = "Windows-ROOT";
|
|---|
| 153 |
|
|---|
| 154 | private static final String CURRENT_VERSION = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
|
|---|
| 155 |
|
|---|
| 156 | private String oSBuildNumber;
|
|---|
| 157 |
|
|---|
| 158 | @Override
|
|---|
| 159 | public void afterPrefStartupHook() {
|
|---|
| 160 | extendFontconfig("fontconfig.properties.src");
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | @Override
|
|---|
| 164 | public void startupHook(JavaExpirationCallback callback) {
|
|---|
| 165 | checkExpiredJava(callback);
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | @Override
|
|---|
| 169 | public void openUrl(String url) throws IOException {
|
|---|
| 170 | Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | @Override
|
|---|
| 174 | public void initSystemShortcuts() {
|
|---|
| 175 | // CHECKSTYLE.OFF: LineLength
|
|---|
| 176 | //Shortcut.registerSystemCut("system:menuexit", tr("reserved"), VK_Q, CTRL_DOWN_MASK);
|
|---|
| 177 | Shortcut.registerSystemShortcut("system:duplicate", tr("reserved"), VK_D, CTRL_DOWN_MASK); // not really system, but to avoid odd results
|
|---|
| 178 |
|
|---|
| 179 | // Windows 7 shortcuts: http://windows.microsoft.com/en-US/windows7/Keyboard-shortcuts
|
|---|
| 180 |
|
|---|
| 181 | // Shortcuts with setAutomatic(): items with automatic shortcuts will not be added to the menu bar at all
|
|---|
| 182 |
|
|---|
| 183 | // Don't know why Ctrl-Alt-Del isn't even listed on official Microsoft support page
|
|---|
| 184 | Shortcut.registerSystemShortcut("system:reset", tr("reserved"), VK_DELETE, CTRL_DOWN_MASK | ALT_DOWN_MASK).setAutomatic();
|
|---|
| 185 |
|
|---|
| 186 | // Ease of Access keyboard shortcuts
|
|---|
| 187 | Shortcut.registerSystemShortcut("microsoft-reserved-01", tr("reserved"), VK_PRINTSCREEN, ALT_DOWN_MASK | SHIFT_DOWN_MASK).setAutomatic(); // Turn High Contrast on or off
|
|---|
| 188 | Shortcut.registerSystemShortcut("microsoft-reserved-02", tr("reserved"), VK_NUM_LOCK, ALT_DOWN_MASK | SHIFT_DOWN_MASK).setAutomatic(); // Turn Mouse Keys on or off
|
|---|
| 189 | //Shortcut.registerSystemCut("microsoft-reserved-03", tr("reserved"), VK_U, );// Open the Ease of Access Center (TODO: Windows-U, how to handle it in Java ?)
|
|---|
| 190 |
|
|---|
| 191 | // General keyboard shortcuts
|
|---|
| 192 | //Shortcut.registerSystemShortcut("system:help", tr("reserved"), VK_F1, 0); // Display Help
|
|---|
| 193 | Shortcut.registerSystemShortcut("system:copy", tr("reserved"), VK_C, CTRL_DOWN_MASK); // Copy the selected item
|
|---|
| 194 | Shortcut.registerSystemShortcut("system:cut", tr("reserved"), VK_X, CTRL_DOWN_MASK); // Cut the selected item
|
|---|
| 195 | Shortcut.registerSystemShortcut("system:paste", tr("reserved"), VK_V, CTRL_DOWN_MASK); // Paste the selected item
|
|---|
| 196 | Shortcut.registerSystemShortcut("system:undo", tr("reserved"), VK_Z, CTRL_DOWN_MASK); // Undo an action
|
|---|
| 197 | Shortcut.registerSystemShortcut("system:redo", tr("reserved"), VK_Y, CTRL_DOWN_MASK); // Redo an action
|
|---|
| 198 | //Shortcut.registerSystemCut("microsoft-reserved-10", tr("reserved"), VK_DELETE, 0); // Delete the selected item and move it to the Recycle Bin
|
|---|
| 199 | //Shortcut.registerSystemCut("microsoft-reserved-11", tr("reserved"), VK_DELETE, SHIFT_DOWN_MASK); // Delete the selected item without moving it to the Recycle Bin first
|
|---|
| 200 | //Shortcut.registerSystemCut("system:rename", tr("reserved"), VK_F2, 0); // Rename the selected item
|
|---|
| 201 | Shortcut.registerSystemShortcut("system:movefocusright", tr("reserved"), VK_RIGHT, CTRL_DOWN_MASK); // Move the cursor to the beginning of the next word
|
|---|
| 202 | Shortcut.registerSystemShortcut("system:movefocusleft", tr("reserved"), VK_LEFT, CTRL_DOWN_MASK); // Move the cursor to the beginning of the previous word
|
|---|
| 203 | Shortcut.registerSystemShortcut("system:movefocusdown", tr("reserved"), VK_DOWN, CTRL_DOWN_MASK); // Move the cursor to the beginning of the next paragraph
|
|---|
| 204 | Shortcut.registerSystemShortcut("system:movefocusup", tr("reserved"), VK_UP, CTRL_DOWN_MASK); // Move the cursor to the beginning of the previous paragraph
|
|---|
| 205 | //Shortcut.registerSystemCut("microsoft-reserved-17", tr("reserved"), VK_RIGHT, CTRL_DOWN_MASK | SHIFT_DOWN_MASK); // Select a block of text
|
|---|
| 206 | //Shortcut.registerSystemCut("microsoft-reserved-18", tr("reserved"), VK_LEFT, CTRL_DOWN_MASK | SHIFT_DOWN_MASK); // Select a block of text
|
|---|
| 207 | //Shortcut.registerSystemCut("microsoft-reserved-19", tr("reserved"), VK_DOWN, CTRL_DOWN_MASK | SHIFT_DOWN_MASK); // Select a block of text
|
|---|
| 208 | //Shortcut.registerSystemCut("microsoft-reserved-20", tr("reserved"), VK_UP, CTRL_DOWN_MASK | SHIFT_DOWN_MASK); // Select a block of text
|
|---|
| 209 | //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
|
|---|
| 210 | //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
|
|---|
| 211 | //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
|
|---|
| 212 | //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
|
|---|
| 213 | //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 ?)
|
|---|
| 214 | //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 ?)
|
|---|
| 215 | //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 ?)
|
|---|
| 216 | //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 ?)
|
|---|
| 217 | Shortcut.registerSystemShortcut("system:selectall", tr("reserved"), VK_A, CTRL_DOWN_MASK); // Select all items in a document or window
|
|---|
| 218 | //Shortcut.registerSystemCut("system:search", tr("reserved"), VK_F3, 0); // Search for a file or folder
|
|---|
| 219 | Shortcut.registerSystemShortcut("microsoft-reserved-31", tr("reserved"), VK_ENTER, ALT_DOWN_MASK).setAutomatic(); // Display properties for the selected item
|
|---|
| 220 | Shortcut.registerSystemShortcut("system:exit", tr("reserved"), VK_F4, ALT_DOWN_MASK).setAutomatic(); // Close the active item, or exit the active program
|
|---|
| 221 | Shortcut.registerSystemShortcut("microsoft-reserved-33", tr("reserved"), VK_SPACE, ALT_DOWN_MASK).setAutomatic(); // Open the shortcut menu for the active window
|
|---|
| 222 | //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)
|
|---|
| 223 | Shortcut.registerSystemShortcut("microsoft-reserved-35", tr("reserved"), VK_TAB, ALT_DOWN_MASK).setAutomatic(); // Switch between open items
|
|---|
| 224 | 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
|
|---|
| 225 | //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 ?)
|
|---|
| 226 | //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 ?)
|
|---|
| 227 | Shortcut.registerSystemShortcut("microsoft-reserved-39", tr("reserved"), VK_ESCAPE, ALT_DOWN_MASK).setAutomatic(); // Cycle through items in the order in which they were opened
|
|---|
| 228 | //Shortcut.registerSystemCut("microsoft-reserved-40", tr("reserved"), VK_F6, 0); // Cycle through screen elements in a window or on the desktop
|
|---|
| 229 | //Shortcut.registerSystemCut("microsoft-reserved-41", tr("reserved"), VK_F4, 0); // Display the address bar list in Windows Explorer
|
|---|
| 230 | Shortcut.registerSystemShortcut("microsoft-reserved-42", tr("reserved"), VK_F10, SHIFT_DOWN_MASK); // Display the shortcut menu for the selected item
|
|---|
| 231 | Shortcut.registerSystemShortcut("microsoft-reserved-43", tr("reserved"), VK_ESCAPE, CTRL_DOWN_MASK).setAutomatic(); // Open the Start menu
|
|---|
| 232 | //Shortcut.registerSystemShortcut("microsoft-reserved-44", tr("reserved"), VK_F10, 0); // Activate the menu bar in the active program
|
|---|
| 233 | //Shortcut.registerSystemCut("microsoft-reserved-45", tr("reserved"), VK_RIGHT, 0); // Open the next menu to the right, or open a submenu
|
|---|
| 234 | //Shortcut.registerSystemCut("microsoft-reserved-46", tr("reserved"), VK_LEFT, 0); // Open the next menu to the left, or close a submenu
|
|---|
| 235 | //Shortcut.registerSystemCut("microsoft-reserved-47", tr("reserved"), VK_F5, 0); // Refresh the active window
|
|---|
| 236 | //Shortcut.registerSystemCut("microsoft-reserved-48", tr("reserved"), VK_UP, ALT_DOWN_MASK); // View the folder one level up in Windows Explorer
|
|---|
| 237 | //Shortcut.registerSystemCut("microsoft-reserved-49", tr("reserved"), VK_ESCAPE, 0); // Cancel the current task
|
|---|
| 238 | Shortcut.registerSystemShortcut("microsoft-reserved-50", tr("reserved"), VK_ESCAPE, CTRL_DOWN_MASK | SHIFT_DOWN_MASK).setAutomatic(); // Open Task Manager
|
|---|
| 239 | Shortcut.registerSystemShortcut("microsoft-reserved-51", tr("reserved"), VK_SHIFT, ALT_DOWN_MASK).setAutomatic(); // Switch the input language when multiple input languages are enabled
|
|---|
| 240 | Shortcut.registerSystemShortcut("microsoft-reserved-52", tr("reserved"), VK_SHIFT, CTRL_DOWN_MASK).setAutomatic(); // Switch the keyboard layout when multiple keyboard layouts are enabled
|
|---|
| 241 | //Shortcut.registerSystemCut("microsoft-reserved-53", tr("reserved"), ); // Change the reading direction of text in right-to-left reading languages (TODO: unclear)
|
|---|
| 242 | // CHECKSTYLE.ON: LineLength
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | @Override
|
|---|
| 246 | public String getDefaultStyle() {
|
|---|
| 247 | return "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | @Override
|
|---|
| 251 | public boolean rename(File from, File to) {
|
|---|
| 252 | if (to.exists())
|
|---|
| 253 | Utils.deleteFile(to);
|
|---|
| 254 | return from.renameTo(to);
|
|---|
| 255 | }
|
|---|
| 256 |
|
|---|
| 257 | @Override
|
|---|
| 258 | public String getOSDescription() {
|
|---|
| 259 | return Utils.strip(System.getProperty("os.name")) + ' ' +
|
|---|
| 260 | ((System.getenv("ProgramFiles(x86)") == null) ? "32" : "64") + "-Bit";
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | /**
|
|---|
| 264 | * Returns the Windows product name from registry (example: "Windows 10 Pro")
|
|---|
| 265 | * @return the Windows product name from registry
|
|---|
| 266 | * @throws IllegalAccessException if Java language access control is enforced and the underlying method is inaccessible
|
|---|
| 267 | * @throws InvocationTargetException if the underlying method throws an exception
|
|---|
| 268 | * @since 12744
|
|---|
| 269 | */
|
|---|
| 270 | public static String getProductName() throws IllegalAccessException, InvocationTargetException {
|
|---|
| 271 | return WinRegistry.readString(HKEY_LOCAL_MACHINE, CURRENT_VERSION, "ProductName");
|
|---|
| 272 | }
|
|---|
| 273 |
|
|---|
| 274 | /**
|
|---|
| 275 | * Returns the Windows release identifier from registry (example: "1703")
|
|---|
| 276 | * @return the Windows release identifier from registry
|
|---|
| 277 | * @throws IllegalAccessException if Java language access control is enforced and the underlying method is inaccessible
|
|---|
| 278 | * @throws InvocationTargetException if the underlying method throws an exception
|
|---|
| 279 | * @since 12744
|
|---|
| 280 | */
|
|---|
| 281 | public static String getReleaseId() throws IllegalAccessException, InvocationTargetException {
|
|---|
| 282 | return WinRegistry.readString(HKEY_LOCAL_MACHINE, CURRENT_VERSION, "ReleaseId");
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | /**
|
|---|
| 286 | * Returns the Windows current build number from registry (example: "15063")
|
|---|
| 287 | * @return the Windows current build number from registry
|
|---|
| 288 | * @throws IllegalAccessException if Java language access control is enforced and the underlying method is inaccessible
|
|---|
| 289 | * @throws InvocationTargetException if the underlying method throws an exception
|
|---|
| 290 | * @since 12744
|
|---|
| 291 | */
|
|---|
| 292 | public static String getCurrentBuild() throws IllegalAccessException, InvocationTargetException {
|
|---|
| 293 | return WinRegistry.readString(HKEY_LOCAL_MACHINE, CURRENT_VERSION, "CurrentBuild");
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | private static String buildOSBuildNumber() {
|
|---|
| 297 | StringBuilder sb = new StringBuilder();
|
|---|
| 298 | try {
|
|---|
| 299 | sb.append(getProductName());
|
|---|
| 300 | String releaseId = getReleaseId();
|
|---|
| 301 | if (releaseId != null) {
|
|---|
| 302 | sb.append(' ').append(releaseId);
|
|---|
| 303 | }
|
|---|
| 304 | sb.append(" (").append(getCurrentBuild()).append(')');
|
|---|
| 305 | } catch (ReflectiveOperationException e) {
|
|---|
| 306 | Logging.error(e);
|
|---|
| 307 | }
|
|---|
| 308 | return sb.toString();
|
|---|
| 309 | }
|
|---|
| 310 |
|
|---|
| 311 | @Override
|
|---|
| 312 | public String getOSBuildNumber() {
|
|---|
| 313 | if (oSBuildNumber == null) {
|
|---|
| 314 | oSBuildNumber = buildOSBuildNumber();
|
|---|
| 315 | }
|
|---|
| 316 | return oSBuildNumber;
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | /**
|
|---|
| 320 | * Loads Windows-ROOT keystore.
|
|---|
| 321 | * @return Windows-ROOT keystore
|
|---|
| 322 | * @throws NoSuchAlgorithmException if the algorithm used to check the integrity of the keystore cannot be found
|
|---|
| 323 | * @throws CertificateException if any of the certificates in the keystore could not be loaded
|
|---|
| 324 | * @throws IOException if there is an I/O or format problem with the keystore data, if a password is required but not given
|
|---|
| 325 | * @throws KeyStoreException if no Provider supports a KeyStore implementation for the type "Windows-ROOT"
|
|---|
| 326 | * @since 7343
|
|---|
| 327 | */
|
|---|
| 328 | public static KeyStore getRootKeystore() throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException {
|
|---|
| 329 | KeyStore ks = KeyStore.getInstance(WINDOWS_ROOT);
|
|---|
| 330 | ks.load(null, null);
|
|---|
| 331 | return ks;
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | /**
|
|---|
| 335 | * Removes potential insecure certificates installed with previous versions of JOSM on Windows.
|
|---|
| 336 | * @throws NoSuchAlgorithmException on unsupported signature algorithms
|
|---|
| 337 | * @throws CertificateException if any of the certificates in the Windows keystore could not be loaded
|
|---|
| 338 | * @throws KeyStoreException if no Provider supports a KeyStoreSpi implementation for the type "Windows-ROOT"
|
|---|
| 339 | * @throws IOException if there is an I/O or format problem with the keystore data, if a password is required but not given
|
|---|
| 340 | * @since 7335
|
|---|
| 341 | */
|
|---|
| 342 | public static void removeInsecureCertificates() throws NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException {
|
|---|
| 343 | // 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)
|
|---|
| 344 | PublicKey insecurePubKey = null;
|
|---|
| 345 | try {
|
|---|
| 346 | insecurePubKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(INSECURE_PUBLIC_KEY));
|
|---|
| 347 | } catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
|
|---|
| 348 | Logging.error(e);
|
|---|
| 349 | return;
|
|---|
| 350 | }
|
|---|
| 351 | KeyStore ks = getRootKeystore();
|
|---|
| 352 | Enumeration<String> en = ks.aliases();
|
|---|
| 353 | Collection<String> insecureCertificates = new ArrayList<>();
|
|---|
| 354 | while (en.hasMoreElements()) {
|
|---|
| 355 | String alias = en.nextElement();
|
|---|
| 356 | // Look for certificates associated with a private key
|
|---|
| 357 | if (ks.isKeyEntry(alias)) {
|
|---|
| 358 | try {
|
|---|
| 359 | ks.getCertificate(alias).verify(insecurePubKey);
|
|---|
| 360 | // If no exception, this is a certificate signed with the insecure key -> remove it
|
|---|
| 361 | insecureCertificates.add(alias);
|
|---|
| 362 | } catch (InvalidKeyException | NoSuchProviderException | SignatureException e) {
|
|---|
| 363 | // If exception this is not a certificate related to JOSM, just trace it
|
|---|
| 364 | Logging.trace(alias + " --> " + e.getClass().getName());
|
|---|
| 365 | Logging.trace(e);
|
|---|
| 366 | }
|
|---|
| 367 | }
|
|---|
| 368 | }
|
|---|
| 369 | // Remove insecure certificates
|
|---|
| 370 | if (!insecureCertificates.isEmpty()) {
|
|---|
| 371 | StringBuilder message = new StringBuilder("<html>");
|
|---|
| 372 | message.append(tr("A previous version of JOSM has installed a custom certificate "+
|
|---|
| 373 | "in order to provide HTTPS support for Remote Control:"))
|
|---|
| 374 | .append("<br><ul>");
|
|---|
| 375 | for (String alias : insecureCertificates) {
|
|---|
| 376 | message.append("<li>")
|
|---|
| 377 | .append(alias)
|
|---|
| 378 | .append("</li>");
|
|---|
| 379 | }
|
|---|
| 380 | message.append("</ul>")
|
|---|
| 381 | .append(tr("It appears it could be an important <b>security risk</b>.<br><br>"+
|
|---|
| 382 | "You are now going to be prompted by Windows to remove this insecure certificate.<br>"+
|
|---|
| 383 | "For your own safety, <b>please click Yes</b> in next dialog."))
|
|---|
| 384 | .append("</html>");
|
|---|
| 385 | JOptionPane.showMessageDialog(Main.parent, message.toString(), tr("Warning"), JOptionPane.WARNING_MESSAGE);
|
|---|
| 386 | for (String alias : insecureCertificates) {
|
|---|
| 387 | Logging.warn(tr("Removing insecure certificate from {0} keystore: {1}", WINDOWS_ROOT, alias));
|
|---|
| 388 | try {
|
|---|
| 389 | ks.deleteEntry(alias);
|
|---|
| 390 | } catch (KeyStoreException e) {
|
|---|
| 391 | Logging.log(Logging.LEVEL_ERROR, tr("Unable to remove insecure certificate from keystore: {0}", e.getMessage()), e);
|
|---|
| 392 | }
|
|---|
| 393 | }
|
|---|
| 394 | }
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | @Override
|
|---|
| 398 | public boolean setupHttpsCertificate(String entryAlias, KeyStore.TrustedCertificateEntry trustedCert)
|
|---|
| 399 | throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
|
|---|
| 400 | KeyStore ks = getRootKeystore();
|
|---|
| 401 | // Look for certificate to install
|
|---|
| 402 | try {
|
|---|
| 403 | String alias = ks.getCertificateAlias(trustedCert.getTrustedCertificate());
|
|---|
| 404 | if (alias != null) {
|
|---|
| 405 | // JOSM certificate found, return
|
|---|
| 406 | Logging.debug(tr("JOSM localhost certificate found in {0} keystore: {1}", WINDOWS_ROOT, alias));
|
|---|
| 407 | return false;
|
|---|
| 408 | }
|
|---|
| 409 | } catch (ArrayIndexOutOfBoundsException e) {
|
|---|
| 410 | // catch error of JDK-8172244 as bug seems to not be fixed anytime soon
|
|---|
| 411 | Logging.log(Logging.LEVEL_ERROR, "JDK-8172244 occured. Abort HTTPS setup", e);
|
|---|
| 412 | return false;
|
|---|
| 413 | }
|
|---|
| 414 | if (!GraphicsEnvironment.isHeadless()) {
|
|---|
| 415 | // JOSM certificate not found, warn user
|
|---|
| 416 | StringBuilder message = new StringBuilder("<html>");
|
|---|
| 417 | message.append(tr("Remote Control is configured to provide HTTPS support.<br>"+
|
|---|
| 418 | "This requires to add a custom certificate generated by JOSM to the Windows Root CA store.<br><br>"+
|
|---|
| 419 | "You are now going to be prompted by Windows to confirm this operation.<br>"+
|
|---|
| 420 | "To enable proper HTTPS support, <b>please click Yes</b> in next dialog.<br><br>"+
|
|---|
| 421 | "If unsure, you can also click No then disable HTTPS support in Remote Control preferences."))
|
|---|
| 422 | .append("</html>");
|
|---|
| 423 | JOptionPane.showMessageDialog(Main.parent, message.toString(),
|
|---|
| 424 | tr("HTTPS support in Remote Control"), JOptionPane.INFORMATION_MESSAGE);
|
|---|
| 425 | }
|
|---|
| 426 | // install it to Windows-ROOT keystore, used by IE, Chrome and Safari, but not by Firefox
|
|---|
| 427 | Logging.info(tr("Adding JOSM localhost certificate to {0} keystore", WINDOWS_ROOT));
|
|---|
| 428 | ks.setEntry(entryAlias, trustedCert, null);
|
|---|
| 429 | return true;
|
|---|
| 430 | }
|
|---|
| 431 |
|
|---|
| 432 | @Override
|
|---|
| 433 | public X509Certificate getX509Certificate(CertAmend certAmend)
|
|---|
| 434 | throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
|
|---|
| 435 | KeyStore ks = getRootKeystore();
|
|---|
| 436 | // Search by alias (fast)
|
|---|
| 437 | Certificate result = ks.getCertificate(certAmend.getId());
|
|---|
| 438 | if (result instanceof X509Certificate) {
|
|---|
| 439 | return (X509Certificate) result;
|
|---|
| 440 | }
|
|---|
| 441 | // If not found, search by SHA-256 (slower)
|
|---|
| 442 | MessageDigest md = MessageDigest.getInstance("SHA-256");
|
|---|
| 443 | for (Enumeration<String> aliases = ks.aliases(); aliases.hasMoreElements();) {
|
|---|
| 444 | result = ks.getCertificate(aliases.nextElement());
|
|---|
| 445 | if (result instanceof X509Certificate
|
|---|
| 446 | && certAmend.getSha256().equalsIgnoreCase(Utils.toHexString(md.digest(result.getEncoded())))) {
|
|---|
| 447 | return (X509Certificate) result;
|
|---|
| 448 | }
|
|---|
| 449 | }
|
|---|
| 450 | // Not found
|
|---|
| 451 | return null;
|
|---|
| 452 | }
|
|---|
| 453 |
|
|---|
| 454 | @Override
|
|---|
| 455 | public File getDefaultCacheDirectory() {
|
|---|
| 456 | String p = System.getenv("LOCALAPPDATA");
|
|---|
| 457 | if (p == null || p.isEmpty()) {
|
|---|
| 458 | // Fallback for Windows OS earlier than Windows Vista, where the variable is not defined
|
|---|
| 459 | p = System.getenv("APPDATA");
|
|---|
| 460 | }
|
|---|
| 461 | return new File(new File(p, Main.pref.getJOSMDirectoryBaseName()), "cache");
|
|---|
| 462 | }
|
|---|
| 463 |
|
|---|
| 464 | @Override
|
|---|
| 465 | public File getDefaultPrefDirectory() {
|
|---|
| 466 | return new File(System.getenv("APPDATA"), Main.pref.getJOSMDirectoryBaseName());
|
|---|
| 467 | }
|
|---|
| 468 |
|
|---|
| 469 | @Override
|
|---|
| 470 | public File getDefaultUserDataDirectory() {
|
|---|
| 471 | // Use preferences directory by default
|
|---|
| 472 | return Main.pref.getPreferencesDirectory();
|
|---|
| 473 | }
|
|---|
| 474 |
|
|---|
| 475 | /**
|
|---|
| 476 | * <p>Add more fallback fonts to the Java runtime, in order to get
|
|---|
| 477 | * support for more scripts.</p>
|
|---|
| 478 | *
|
|---|
| 479 | * <p>The font configuration in Java doesn't include some Indic scripts,
|
|---|
| 480 | * even though MS Windows ships with fonts that cover these unicode ranges.</p>
|
|---|
| 481 | *
|
|---|
| 482 | * <p>To fix this, the fontconfig.properties template is copied to the JOSM
|
|---|
| 483 | * cache folder. Then, the additional entries are added to the font
|
|---|
| 484 | * configuration. Finally the system property "sun.awt.fontconfig" is set
|
|---|
| 485 | * to the customized fontconfig.properties file.</p>
|
|---|
| 486 | *
|
|---|
| 487 | * <p>This is a crude hack, but better than no font display at all for these languages.
|
|---|
| 488 | * There is no guarantee, that the template file
|
|---|
| 489 | * ($JAVA_HOME/lib/fontconfig.properties.src) matches the default
|
|---|
| 490 | * configuration (which is in a binary format).
|
|---|
| 491 | * Furthermore, the system property "sun.awt.fontconfig" is undocumented and
|
|---|
| 492 | * may no longer work in future versions of Java.</p>
|
|---|
| 493 | *
|
|---|
| 494 | * <p>Related Java bug: <a href="https://bugs.openjdk.java.net/browse/JDK-8008572">JDK-8008572</a></p>
|
|---|
| 495 | *
|
|---|
| 496 | * @param templateFileName file name of the fontconfig.properties template file
|
|---|
| 497 | */
|
|---|
| 498 | protected void extendFontconfig(String templateFileName) {
|
|---|
| 499 | String customFontconfigFile = Main.pref.get("fontconfig.properties", null);
|
|---|
| 500 | if (customFontconfigFile != null) {
|
|---|
| 501 | Utils.updateSystemProperty("sun.awt.fontconfig", customFontconfigFile);
|
|---|
| 502 | return;
|
|---|
| 503 | }
|
|---|
| 504 | if (!Main.pref.getBoolean("font.extended-unicode", true))
|
|---|
| 505 | return;
|
|---|
| 506 |
|
|---|
| 507 | String javaLibPath = System.getProperty("java.home") + File.separator + "lib";
|
|---|
| 508 | Path templateFile = FileSystems.getDefault().getPath(javaLibPath, templateFileName);
|
|---|
| 509 | if (!Files.isReadable(templateFile)) {
|
|---|
| 510 | Logging.warn("extended font config - unable to find font config template file {0}", templateFile.toString());
|
|---|
| 511 | return;
|
|---|
| 512 | }
|
|---|
| 513 | try (FileInputStream fis = new FileInputStream(templateFile.toFile())) {
|
|---|
| 514 | Properties props = new Properties();
|
|---|
| 515 | props.load(fis);
|
|---|
| 516 | byte[] content = Files.readAllBytes(templateFile);
|
|---|
| 517 | File cachePath = Main.pref.getCacheDirectory();
|
|---|
| 518 | Path fontconfigFile = cachePath.toPath().resolve("fontconfig.properties");
|
|---|
| 519 | OutputStream os = Files.newOutputStream(fontconfigFile);
|
|---|
| 520 | os.write(content);
|
|---|
| 521 | try (Writer w = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8))) {
|
|---|
| 522 | Collection<FontEntry> extrasPref = Main.pref.getListOfStructs(
|
|---|
| 523 | "font.extended-unicode.extra-items", getAdditionalFonts(), FontEntry.class);
|
|---|
| 524 | Collection<FontEntry> extras = new ArrayList<>();
|
|---|
| 525 | w.append("\n\n# Added by JOSM to extend unicode coverage of Java font support:\n\n");
|
|---|
| 526 | List<String> allCharSubsets = new ArrayList<>();
|
|---|
| 527 | for (FontEntry entry: extrasPref) {
|
|---|
| 528 | Collection<String> fontsAvail = getInstalledFonts();
|
|---|
| 529 | if (fontsAvail != null && fontsAvail.contains(entry.file.toUpperCase(Locale.ENGLISH))) {
|
|---|
| 530 | if (!allCharSubsets.contains(entry.charset)) {
|
|---|
| 531 | allCharSubsets.add(entry.charset);
|
|---|
| 532 | extras.add(entry);
|
|---|
| 533 | } else {
|
|---|
| 534 | Logging.trace("extended font config - already registered font for charset ''{0}'' - skipping ''{1}''",
|
|---|
| 535 | entry.charset, entry.name);
|
|---|
| 536 | }
|
|---|
| 537 | } else {
|
|---|
| 538 | Logging.trace("extended font config - Font ''{0}'' not found on system - skipping", entry.name);
|
|---|
| 539 | }
|
|---|
| 540 | }
|
|---|
| 541 | for (FontEntry entry: extras) {
|
|---|
| 542 | allCharSubsets.add(entry.charset);
|
|---|
| 543 | if ("".equals(entry.name)) {
|
|---|
| 544 | continue;
|
|---|
| 545 | }
|
|---|
| 546 | String key = "allfonts." + entry.charset;
|
|---|
| 547 | String value = entry.name;
|
|---|
| 548 | String prevValue = props.getProperty(key);
|
|---|
| 549 | if (prevValue != null && !prevValue.equals(value)) {
|
|---|
| 550 | Logging.warn("extended font config - overriding ''{0}={1}'' with ''{2}''", key, prevValue, value);
|
|---|
| 551 | }
|
|---|
| 552 | w.append(key + '=' + value + '\n');
|
|---|
| 553 | }
|
|---|
| 554 | w.append('\n');
|
|---|
| 555 | for (FontEntry entry: extras) {
|
|---|
| 556 | if ("".equals(entry.name) || "".equals(entry.file)) {
|
|---|
| 557 | continue;
|
|---|
| 558 | }
|
|---|
| 559 | String key = "filename." + entry.name.replace(' ', '_');
|
|---|
| 560 | String value = entry.file;
|
|---|
| 561 | String prevValue = props.getProperty(key);
|
|---|
| 562 | if (prevValue != null && !prevValue.equals(value)) {
|
|---|
| 563 | Logging.warn("extended font config - overriding ''{0}={1}'' with ''{2}''", key, prevValue, value);
|
|---|
| 564 | }
|
|---|
| 565 | w.append(key + '=' + value + '\n');
|
|---|
| 566 | }
|
|---|
| 567 | w.append('\n');
|
|---|
| 568 | String fallback = props.getProperty("sequence.fallback");
|
|---|
| 569 | if (fallback != null) {
|
|---|
| 570 | w.append("sequence.fallback=" + fallback + ',' + Utils.join(",", allCharSubsets) + '\n');
|
|---|
| 571 | } else {
|
|---|
| 572 | w.append("sequence.fallback=" + Utils.join(",", allCharSubsets) + '\n');
|
|---|
| 573 | }
|
|---|
| 574 | }
|
|---|
| 575 | Utils.updateSystemProperty("sun.awt.fontconfig", fontconfigFile.toString());
|
|---|
| 576 | } catch (IOException ex) {
|
|---|
| 577 | Logging.error(ex);
|
|---|
| 578 | }
|
|---|
| 579 | }
|
|---|
| 580 |
|
|---|
| 581 | /**
|
|---|
| 582 | * Get a list of fonts that are installed on the system.
|
|---|
| 583 | *
|
|---|
| 584 | * Must be done without triggering the Java Font initialization.
|
|---|
| 585 | * (See {@link #extendFontconfig(java.lang.String)}, have to set system
|
|---|
| 586 | * property first, which is then read by sun.awt.FontConfiguration upon initialization.)
|
|---|
| 587 | *
|
|---|
| 588 | * @return list of file names
|
|---|
| 589 | */
|
|---|
| 590 | protected Collection<String> getInstalledFonts() {
|
|---|
| 591 | // Cannot use GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()
|
|---|
| 592 | // because we have to set the system property before Java initializes its fonts.
|
|---|
| 593 | // Use more low-level method to find the installed fonts.
|
|---|
| 594 | List<String> fontsAvail = new ArrayList<>();
|
|---|
| 595 | Path fontPath = FileSystems.getDefault().getPath(System.getenv("SYSTEMROOT"), "Fonts");
|
|---|
| 596 | try (DirectoryStream<Path> ds = Files.newDirectoryStream(fontPath)) {
|
|---|
| 597 | for (Path p : ds) {
|
|---|
| 598 | Path filename = p.getFileName();
|
|---|
| 599 | if (filename != null) {
|
|---|
| 600 | fontsAvail.add(filename.toString().toUpperCase(Locale.ENGLISH));
|
|---|
| 601 | }
|
|---|
| 602 | }
|
|---|
| 603 | fontsAvail.add(""); // for devanagari
|
|---|
| 604 | } catch (IOException ex) {
|
|---|
| 605 | Logging.log(Logging.LEVEL_ERROR, ex);
|
|---|
| 606 | Logging.warn("extended font config - failed to load available Fonts");
|
|---|
| 607 | fontsAvail = null;
|
|---|
| 608 | }
|
|---|
| 609 | return fontsAvail;
|
|---|
| 610 | }
|
|---|
| 611 |
|
|---|
| 612 | /**
|
|---|
| 613 | * Get default list of additional fonts to add to the configuration.
|
|---|
| 614 | *
|
|---|
| 615 | * Java will choose thee first font in the list that can render a certain character.
|
|---|
| 616 | *
|
|---|
| 617 | * @return list of FontEntry objects
|
|---|
| 618 | */
|
|---|
| 619 | protected Collection<FontEntry> getAdditionalFonts() {
|
|---|
| 620 | Collection<FontEntry> def = new ArrayList<>(33);
|
|---|
| 621 | def.add(new FontEntry("devanagari", "", "")); // just include in fallback list font already defined in template
|
|---|
| 622 |
|
|---|
| 623 | // Windows scripts: https://msdn.microsoft.com/en-us/goglobal/bb688099.aspx
|
|---|
| 624 | // IE default fonts: https://msdn.microsoft.com/en-us/library/ie/dn467844(v=vs.85).aspx
|
|---|
| 625 |
|
|---|
| 626 | // Windows 10 and later
|
|---|
| 627 | def.add(new FontEntry("historic", "Segoe UI Historic", "SEGUIHIS.TTF")); // historic charsets
|
|---|
| 628 |
|
|---|
| 629 | // Windows 8/8.1 and later
|
|---|
| 630 | def.add(new FontEntry("javanese", "Javanese Text", "JAVATEXT.TTF")); // ISO 639: jv
|
|---|
| 631 | def.add(new FontEntry("leelawadee", "Leelawadee", "LEELAWAD.TTF")); // ISO 639: bug
|
|---|
| 632 | def.add(new FontEntry("myanmar", "Myanmar Text", "MMRTEXT.TTF")); // ISO 639: my
|
|---|
| 633 | def.add(new FontEntry("nirmala", "Nirmala UI", "NIRMALA.TTF")); // ISO 639: sat,srb
|
|---|
| 634 | def.add(new FontEntry("segoeui", "Segoe UI", "SEGOEUI.TTF")); // ISO 639: lis
|
|---|
| 635 | def.add(new FontEntry("emoji", "Segoe UI Emoji", "SEGUIEMJ.TTF")); // emoji symbol characters
|
|---|
| 636 |
|
|---|
| 637 | // Windows 7 and later
|
|---|
| 638 | def.add(new FontEntry("nko_tifinagh_vai_osmanya", "Ebrima", "EBRIMA.TTF")); // ISO 639: ber. Nko only since Win 8
|
|---|
| 639 | def.add(new FontEntry("khmer1", "Khmer UI", "KHMERUI.TTF")); // ISO 639: km
|
|---|
| 640 | def.add(new FontEntry("lao1", "Lao UI", "LAOUI.TTF")); // ISO 639: lo
|
|---|
| 641 | def.add(new FontEntry("tai_le", "Microsoft Tai Le", "TAILE.TTF")); // ISO 639: khb
|
|---|
| 642 | def.add(new FontEntry("new_tai_lue", "Microsoft New Tai Lue", "NTHAILU.TTF")); // ISO 639: khb
|
|---|
| 643 |
|
|---|
| 644 | // Windows Vista and later:
|
|---|
| 645 | def.add(new FontEntry("ethiopic", "Nyala", "NYALA.TTF")); // ISO 639: am,gez,ti
|
|---|
| 646 | def.add(new FontEntry("tibetan", "Microsoft Himalaya", "HIMALAYA.TTF")); // ISO 639: bo,dz
|
|---|
| 647 | def.add(new FontEntry("cherokee", "Plantagenet Cherokee", "PLANTC.TTF")); // ISO 639: chr
|
|---|
| 648 | def.add(new FontEntry("unified_canadian", "Euphemia", "EUPHEMIA.TTF")); // ISO 639: cr,in
|
|---|
| 649 | def.add(new FontEntry("khmer2", "DaunPenh", "DAUNPENH.TTF")); // ISO 639: km
|
|---|
| 650 | def.add(new FontEntry("khmer3", "MoolBoran", "MOOLBOR.TTF")); // ISO 639: km
|
|---|
| 651 | def.add(new FontEntry("lao_thai", "DokChampa", "DOKCHAMP.TTF")); // ISO 639: lo
|
|---|
| 652 | def.add(new FontEntry("mongolian", "Mongolian Baiti", "MONBAITI.TTF")); // ISO 639: mn
|
|---|
| 653 | def.add(new FontEntry("oriya", "Kalinga", "KALINGA.TTF")); // ISO 639: or
|
|---|
| 654 | def.add(new FontEntry("sinhala", "Iskoola Pota", "ISKPOTA.TTF")); // ISO 639: si
|
|---|
| 655 | def.add(new FontEntry("yi", "Yi Baiti", "MSYI.TTF")); // ISO 639: ii
|
|---|
| 656 |
|
|---|
| 657 | // Windows XP and later
|
|---|
| 658 | def.add(new FontEntry("gujarati", "Shruti", "SHRUTI.TTF"));
|
|---|
| 659 | def.add(new FontEntry("kannada", "Tunga", "TUNGA.TTF"));
|
|---|
| 660 | def.add(new FontEntry("gurmukhi", "Raavi", "RAAVI.TTF"));
|
|---|
| 661 | def.add(new FontEntry("telugu", "Gautami", "GAUTAMI.TTF"));
|
|---|
| 662 | def.add(new FontEntry("bengali", "Vrinda", "VRINDA.TTF")); // since XP SP2
|
|---|
| 663 | def.add(new FontEntry("syriac", "Estrangelo Edessa", "ESTRE.TTF")); // ISO 639: arc
|
|---|
| 664 | def.add(new FontEntry("thaana", "MV Boli", "MVBOLI.TTF")); // ISO 639: dv
|
|---|
| 665 | def.add(new FontEntry("malayalam", "Kartika", "KARTIKA.TTF")); // ISO 639: ml; since XP SP2
|
|---|
| 666 |
|
|---|
| 667 | // Windows 2000 and later
|
|---|
| 668 | def.add(new FontEntry("tamil", "Latha", "LATHA.TTF"));
|
|---|
| 669 |
|
|---|
| 670 | // Comes with MS Office & Outlook 2000. Good unicode coverage, so add if available.
|
|---|
| 671 | def.add(new FontEntry("arialuni", "Arial Unicode MS", "ARIALUNI.TTF"));
|
|---|
| 672 |
|
|---|
| 673 | return def;
|
|---|
| 674 | }
|
|---|
| 675 |
|
|---|
| 676 | @Override
|
|---|
| 677 | public List<File> getDefaultProj4NadshiftDirectories() {
|
|---|
| 678 | return Arrays.asList(new File("C:\\PROJ\\NAD"));
|
|---|
| 679 | }
|
|---|
| 680 | }
|
|---|