Class PlatformHookWindows

    • Method Detail

      • afterPrefStartupHook

        public void afterPrefStartupHook()
        Description copied from interface: PlatformHook
        The afterPrefStartupHook will be called early, but after the preferences have been loaded and basic processing of command line arguments is finished. It is guaranteed to be called before the GUI setup has started.
        Specified by:
        afterPrefStartupHook in interface PlatformHook
      • startupHook

        public void startupHook​(PlatformHook.JavaExpirationCallback javaCallback,
                                PlatformHook.SanityCheckCallback sanityCheckCallback)
        Description copied from interface: PlatformHook
        The startupHook will be called early, but after the GUI setup has started.

        Reason: On OSX we need to register some callbacks with the OS, so we'll receive events from the system menu.

        Specified by:
        startupHook in interface PlatformHook
        Parameters:
        javaCallback - Java expiration callback, providing GUI feedback
        sanityCheckCallback - Sanity check callback, providing GUI feedback
      • openUrl

        public void openUrl​(java.lang.String url)
                     throws java.io.IOException
        Description copied from interface: PlatformHook
        The openURL hook will be used to open a URL in the default web browser.
        Specified by:
        openUrl in interface PlatformHook
        Parameters:
        url - The URL to open
        Throws:
        java.io.IOException - if any I/O error occurs
      • initSystemShortcuts

        public void initSystemShortcuts()
        Description copied from interface: PlatformHook
        The initSystemShortcuts hook will be called by the Shortcut class after the modifier groups have been read from the config, but before any shortcuts are read from it or registered from within the application.

        Please note that you are not allowed to register any shortcuts from this hook, but only "systemCuts"!

        BTW: SystemCuts should be named "system:<whatever>", and it'd be best if you'd recycle the names already used by the Windows and OSX hooks. Especially the latter has really many of them.

        You should also register any and all shortcuts that the operating system handles itself to block JOSM from trying to use them---as that would just not work. Call setAutomatic on them to prevent the keyboard preferences from allowing the user to change them.

        Specified by:
        initSystemShortcuts in interface PlatformHook
      • getDefaultStyle

        public java.lang.String getDefaultStyle()
        Description copied from interface: PlatformHook
        Returns the default LAF to be used on this platform to look almost as a native application.
        Specified by:
        getDefaultStyle in interface PlatformHook
        Returns:
        The default native LAF for this platform
      • rename

        public boolean rename​(java.io.File from,
                              java.io.File to)
        Description copied from interface: PlatformHook
        Renames a file.
        Specified by:
        rename in interface PlatformHook
        Parameters:
        from - Source file
        to - Target file
        Returns:
        true if the file has been renamed, false otherwise
      • getProductName

        public static java.lang.String getProductName()
                                               throws java.lang.IllegalAccessException,
                                                      java.lang.reflect.InvocationTargetException
        Returns the Windows product name from registry (example: "Windows 10 Pro")
        Returns:
        the Windows product name from registry
        Throws:
        java.lang.IllegalAccessException - if Java language access control is enforced and the underlying method is inaccessible
        java.lang.reflect.InvocationTargetException - if the underlying method throws an exception
        Since:
        12744
      • getReleaseId

        public static java.lang.String getReleaseId()
                                             throws java.lang.IllegalAccessException,
                                                    java.lang.reflect.InvocationTargetException
        Returns the Windows release identifier from registry (example: "1703")
        Returns:
        the Windows release identifier from registry
        Throws:
        java.lang.IllegalAccessException - if Java language access control is enforced and the underlying method is inaccessible
        java.lang.reflect.InvocationTargetException - if the underlying method throws an exception
        Since:
        12744
      • getDisplayVersion

        public static java.lang.String getDisplayVersion()
                                                  throws java.lang.IllegalAccessException,
                                                         java.lang.reflect.InvocationTargetException
        Returns the Windows display version from registry (example: "22H2")
        Returns:
        the Windows display version from registry
        Throws:
        java.lang.IllegalAccessException - if Java language access control is enforced and the underlying method is inaccessible
        java.lang.reflect.InvocationTargetException - if the underlying method throws an exception
        Since:
        19041
      • getCurrentBuild

        public static java.lang.String getCurrentBuild()
                                                throws java.lang.IllegalAccessException,
                                                       java.lang.reflect.InvocationTargetException
        Returns the Windows current build number from registry (example: "15063")
        Returns:
        the Windows current build number from registry
        Throws:
        java.lang.IllegalAccessException - if Java language access control is enforced and the underlying method is inaccessible
        java.lang.reflect.InvocationTargetException - if the underlying method throws an exception
        Since:
        12744
      • getRootKeystore

        public static java.security.KeyStore getRootKeystore()
                                                      throws java.security.NoSuchAlgorithmException,
                                                             java.security.cert.CertificateException,
                                                             java.io.IOException,
                                                             java.security.KeyStoreException
        Loads Windows-ROOT keystore.
        Returns:
        Windows-ROOT keystore
        Throws:
        java.security.NoSuchAlgorithmException - if the algorithm used to check the integrity of the keystore cannot be found
        java.security.cert.CertificateException - if any of the certificates in the keystore could not be loaded
        java.io.IOException - if there is an I/O or format problem with the keystore data, if a password is required but not given
        java.security.KeyStoreException - if no Provider supports a KeyStore implementation for the type "Windows-ROOT"
        Since:
        7343
      • getX509Certificate

        public java.security.cert.X509Certificate getX509Certificate​(CertificateAmendment.NativeCertAmend certAmend)
                                                              throws java.security.KeyStoreException,
                                                                     java.security.NoSuchAlgorithmException,
                                                                     java.security.cert.CertificateException,
                                                                     java.io.IOException
        Description copied from interface: PlatformHook
        Returns the X509Certificate matching the given certificate amendment information.
        Specified by:
        getX509Certificate in interface PlatformHook
        Parameters:
        certAmend - certificate amendment
        Returns:
        the X509Certificate matching the given certificate amendment information, or null
        Throws:
        java.security.KeyStoreException - in case of error
        java.security.NoSuchAlgorithmException - in case of error
        java.security.cert.CertificateException - in case of error
        java.io.IOException - in case of error
      • sha256matches

        private static boolean sha256matches​(java.security.cert.Certificate result,
                                             CertificateAmendment.NativeCertAmend certAmend,
                                             java.security.MessageDigest md)
                                      throws java.security.cert.CertificateEncodingException
        Throws:
        java.security.cert.CertificateEncodingException
      • extendFontconfig

        protected void extendFontconfig​(java.lang.String templateFileName)

        Add more fallback fonts to the Java runtime, in order to get support for more scripts.

        The font configuration in Java doesn't include some Indic scripts, even though MS Windows ships with fonts that cover these unicode ranges.

        To fix this, the fontconfig.properties template is copied to the JOSM cache folder. Then, the additional entries are added to the font configuration. Finally the system property "sun.awt.fontconfig" is set to the customized fontconfig.properties file.

        This is a crude hack, but better than no font display at all for these languages. There is no guarantee, that the template file ($JAVA_HOME/lib/fontconfig.properties.src) matches the default configuration (which is in a binary format). Furthermore, the system property "sun.awt.fontconfig" is undocumented and may no longer work in future versions of Java.

        Related Java bug: JDK-8008572

        Parameters:
        templateFileName - file name of the fontconfig.properties template file
      • getInstalledFonts

        protected java.util.Collection<java.lang.String> getInstalledFonts()
        Get a list of fonts that are installed on the system. Must be done without triggering the Java Font initialization. (See extendFontconfig(java.lang.String), have to set system property first, which is then read by sun.awt.FontConfiguration upon initialization.)
        Returns:
        list of file names
      • getAdditionalFonts

        protected java.util.Collection<PlatformHookWindows.FontEntrygetAdditionalFonts()
        Get default list of additional fonts to add to the configuration. Java will choose thee first font in the list that can render a certain character.
        Returns:
        list of FontEntry objects
      • isDotNet45Installed

        public static boolean isDotNet45Installed()
        Determines if the .NET framework 4.5 (or later) is installed. Windows 7 ships by default with an older version.
        Returns:
        true if the .NET framework 4.5 (or later) is installed.
        Since:
        13463
      • getPowerShellVersion

        public static int getPowerShellVersion()
        Returns the major version number of PowerShell.
        Returns:
        the major version number of PowerShell. -1 in case of error
        Since:
        13465
      • webRequest

        public static java.lang.String webRequest​(java.lang.String uri)
                                           throws java.io.IOException
        Performs a web request using Windows CryptoAPI (through PowerShell). This is useful to ensure Windows trust store will contain a specific root CA.
        Parameters:
        uri - the web URI to request
        Returns:
        HTTP response from the given URI
        Throws:
        java.io.IOException - if any I/O error occurs
        Since:
        13458
      • resolveFileLink

        public java.io.File resolveFileLink​(java.io.File file)
        Description copied from interface: PlatformHook
        Resolves a file link to its destination file.
        Specified by:
        resolveFileLink in interface PlatformHook
        Parameters:
        file - file (link or regular file)
        Returns:
        destination file in case of a file link, file if regular
      • getPossiblePreferenceDirs

        public java.util.Collection<java.lang.String> getPossiblePreferenceDirs()
        Description copied from interface: PlatformHook
        Returns a set of possible platform specific directories where resources could be stored.
        Specified by:
        getPossiblePreferenceDirs in interface PlatformHook
        Returns:
        A set of possible platform specific directories where resources could be stored.