From 4db0048a356cc01d7b73f2f23500fd4548205daf Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Tue, 23 Jul 2024 17:03:43 +0100 Subject: [PATCH] JAL-3631 Consolidated repeated code (mainly form verification). Added appdir hash routine. Wizard installer of .app bundle now deprecated, can't be used :( --- utils/install4j/install4j10_template.install4j | 829 ++++++++---------------- 1 file changed, 269 insertions(+), 560 deletions(-) diff --git a/utils/install4j/install4j10_template.install4j b/utils/install4j/install4j10_template.install4j index eb99e67..61a5d07 100644 --- a/utils/install4j/install4j10_template.install4j +++ b/utils/install4j/install4j10_template.install4j @@ -180,6 +180,237 @@ + public static String getOsAppDataPath(Context context) { + Map<String, String> osAppDataPathMap = new HashMap<>(); + osAppDataPathMap.put("macos", "Library/Application Support/Jalview-Desktop"); + osAppDataPathMap.put("linux", ".local/share/jalview-desktop"); + osAppDataPathMap.put("windows", "AppData\\Local\\Jalview-Desktop"); + osAppDataPathMap.put("other", ".jalview-desktop"); + String appDataPath; + String append; + if (Util.isMacOS()) { + appDataPath = osAppDataPathMap.get("macos"); + append = context.getCompilerVariable("JALVIEW_APPLICATION_NAME"); + } else if (Util.isWindows()) { + appDataPath = osAppDataPathMap.get("windows"); + append = context.getCompilerVariable("APPLICATION_FOLDER"); + } else if (Util.isLinux()) { + appDataPath = osAppDataPathMap.get("linux"); + append = context.getCompilerVariable("APPLICATION_FOLDER").toLowerCase(Locale.ROOT); + } else { + appDataPath = osAppDataPathMap.get("other"); + append = context.getCompilerVariable("APPLICATION_FOLDER").toLowerCase(Locale.ROOT); + } + return "~" + File.separator + appDataPath + File.separator + append; +} + +// methods used in advanced options form validation +public static void validateUserSpaceAdvancedOptionsForm(FormEnvironment formEnvironment) { + FormComponent fc_advancedOptions = formEnvironment.getFormComponentById("US_ADVANCED_OPTIONS"); + FormComponent fc_notUsed = formEnvironment.getFormComponentById("US_NOT_USED"); + FormComponent fc_userUpdates = formEnvironment.getFormComponentById("US_ALLOW_USER_APPDIR_UPDATES"); + FormComponent fc_warning = formEnvironment.getFormComponentById("US_NO_UPDATES_WARNING"); + LayoutGroup lg_advancedOptions = formEnvironment.getLayoutGroupById("US_ADVANCED_OPTIONS_GROUP"); + + // get boolean status of "Enable advanced options" checkbox + JCheckBox jcb_advancedOptions = (JCheckBox) fc_advancedOptions.getConfigurationObject(); + boolean advancedOptions = jcb_advancedOptions.isSelected(); + + // set visibility of Advanced options layout group + lg_advancedOptions.setVisible(advancedOptions); + fc_notUsed.setVisible(!advancedOptions); + + if (!advancedOptions) { + return; + } + + JCheckBox jcb_userUpdates = (JCheckBox) fc_userUpdates.getConfigurationObject(); + boolean userUpdates = fc_userUpdates.isEnabled() && jcb_userUpdates.isSelected(); + + boolean showWarning = advancedOptions && (!userUpdates); + + fc_warning.setVisible(showWarning); +} + +public static void validateSystemSpaceAdvancedOptionsForm(Context context, FormEnvironment formEnvironment) { + validateSystemSpaceAdvancedOptionsForm(context, formEnvironment, true); +} + +public static boolean validateSystemSpaceAdvancedOptionsForm(Context context, FormEnvironment formEnvironment, boolean ret) { + FormComponent fc_advancedOptions = formEnvironment.getFormComponentById("SS_ADVANCED_OPTIONS"); + FormComponent fc_notUsed = formEnvironment.getFormComponentById("SS_NOT_USED"); + FormComponent fc_userUpdates = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_UPDATES"); + FormComponent fc_installerUpdates = formEnvironment.getFormComponentById("SS_ALLOW_INSTALLER_APPDIR_UPDATES"); + FormComponent fc_allowUserAppdirPath = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_PATH"); + FormComponent fc_userAppdirPath = formEnvironment.getFormComponentById("SS_USER_APPDIR_PATH"); + LayoutGroup lg_advancedGroup = formEnvironment.getLayoutGroupById("SS_ADVANCED_OPTIONS_GROUP"); + LayoutGroup lg_setUserAppdirPath = formEnvironment.getLayoutGroupById("SS_SET_USER_APPDIR_PATH"); + + + + // get boolean status of "Enable advanced options" checkbox + JCheckBox jcb_advancedOptions = (JCheckBox) fc_advancedOptions.getConfigurationObject(); + boolean advancedOptions = jcb_advancedOptions.isSelected(); + + // set visibility of Advanced options layout group + lg_advancedGroup.setVisible(advancedOptions); + fc_notUsed.setVisible(!advancedOptions); + + if (!advancedOptions) { + return ret; + } + + + + // get boolean status of "Allow user-space updates" checkbox + JCheckBox jcb_user = (JCheckBox) fc_userUpdates.getConfigurationObject(); + boolean userUpdates = jcb_user.isSelected(); + + // set enabled of customised user appdir path group + lg_setUserAppdirPath.setEnabled(advancedOptions && userUpdates); + + // set enabled of allow installation updates checkbox + fc_installerUpdates.setEnabled(advancedOptions && !userUpdates); + + + + // get boolean status of "Customise the user-space path" checkbox + JCheckBox jcb_allowUserAppdirPath = (JCheckBox) fc_allowUserAppdirPath.getConfigurationObject(); + boolean allowUserAppdirPath = jcb_allowUserAppdirPath.isSelected(); + + // set enabled of userAppdirPath text field + fc_userAppdirPath.setEnabled(advancedOptions && allowUserAppdirPath && fc_allowUserAppdirPath.isEnabled()); + + // get String value of userAppdirPath text field + JTextField jtf_userAppdirPath = (JTextField) fc_userAppdirPath.getConfigurationObject(); + String userAppdirPath = jtf_userAppdirPath.getText(); + + + + // get boolean status of "Allow installation updates" checkbox + JCheckBox jcb_installer = (JCheckBox) fc_installerUpdates.getConfigurationObject(); + boolean installerUpdates = jcb_installer.isSelected(); + + + + // should we show the No updates warning? + boolean showNoUpdatesWarning = advancedOptions && !(userUpdates || installerUpdates); + FormComponent fc_noUpdatesWarning = formEnvironment.getFormComponentById("SS_NO_UPDATES_WARNING"); + fc_noUpdatesWarning.setVisible(advancedOptions && showNoUpdatesWarning); + + + + // should we show the invalid user-space path warning? + showInvalidUserAppdirPathWarning(context, formEnvironment); + + + + // set whether "Set defaults" button should be enabled + FormComponent fc_setDefaults = formEnvironment.getFormComponentById("SS_SET_DEFAULTS"); + JButton jb_setDefaults = (JButton) fc_setDefaults.getConfigurationObject(); + boolean enableSetDefaults = !( userUpdates && !allowUserAppdirPath && userAppdirPath.length() == 0 && !installerUpdates ); + jb_setDefaults.setEnabled(enableSetDefaults); + + + + return ret; +} + +public static boolean isUserAppdirPathValid(Context context) { // this is only valid when form is updated + return isUserAppdirPathValid(context, (String) context.getVariable("userAppdirPath")); +} + +public static boolean isUserAppdirPathValid(Context context, FormComponent fc_userAppdirPath) { + // get String value of userAppdirPath text field + JTextField jtf_userAppdirPath = (JTextField) fc_userAppdirPath.getConfigurationObject(); + String userAppdirPath = jtf_userAppdirPath.getText(); + return isUserAppdirPathValid(context, userAppdirPath); +} + +public static boolean isUserAppdirPathValid(Context context, String userAppdirPath) { + if (userAppdirPath == null || userAppdirPath.length() == 0) { + return true; // null will be switched to default + } + + boolean u = userAppdirPath.contains("%u"); + boolean h = userAppdirPath.contains("%h"); + boolean t = userAppdirPath.startsWith("~" + (String)context.getVariable("sys.fileSeparator")); + + return u || h || t; +} + +public static void showInvalidUserAppdirPathWarning(Context context, FormEnvironment formEnvironment) { + FormComponent fc_advancedOptions = formEnvironment.getFormComponentById("SS_ADVANCED_OPTIONS"); + FormComponent fc_userUpdates = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_UPDATES"); + FormComponent fc_allowUserAppdirPath = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_PATH"); + FormComponent fc_userAppdirPath = formEnvironment.getFormComponentById("SS_USER_APPDIR_PATH"); + FormComponent fc_invalidPathWarning = formEnvironment.getFormComponentById("SS_INVALID_USER_APPDIR_PATH_WARNING"); + + // get boolean status of "Allow user-space updates" checkbox + boolean advancedOptions = ((JCheckBox) fc_advancedOptions.getConfigurationObject()).isSelected(); + + // get boolean status of "Allow user-space updates" checkbox + boolean userUpdates = ((JCheckBox) fc_userUpdates.getConfigurationObject()).isSelected(); + + // get boolean status of "Customise the user-space path" checkbox + boolean allowUserAppdirPath = ((JCheckBox) fc_allowUserAppdirPath).isSelected(); + + // show/hide warning + boolean showInvalidPathWarning = advancedOptions && userUpdates && allowUserAppdirPath && !isUserAppdirPathValid(context, fc_userAppdirPath); + fc_invalidPathWarning.setVisible(showInvalidPathWarning); +} + +// methods to get installer.appdir hash +protected static final String XLATE = "0123456789abcdef"; + +public static String hexlate (byte[] bytes, int count) +{ + if (bytes == null) { + return ""; + } + + count = Math.min(count, bytes.length); + char[] chars = new char[count*2]; + + for (int i = 0; i < count; i++) { + int val = bytes[i]; + if (val < 0) { + val += 256; + } + chars[2*i] = XLATE.charAt(val/16); + chars[2*i+1] = XLATE.charAt(val%16); + } + + return new String(chars); +} + +public static String hexlate (byte[] bytes) +{ + return (bytes == null) ? "" : hexlate(bytes, bytes.length); +} + +public static final String getFullPathToDirectoryHash(String install_app_dir) +{ + java.security.MessageDigest md; + try { + md = java.security.MessageDigest.getInstance("SHA-256"); + } catch (java.security.NoSuchAlgorithmException nsae) { + throw new RuntimeException("JVM does not support SHA-256. Gurp!"); + } + byte[] contents = install_app_dir.getBytes(java.nio.charset.StandardCharsets.UTF_8); + String hash = hexlate(md.digest(contents)); + return hash.substring(0,8); +} + +public static final String getCanonicalFullPathToDirectoryHash(String installerAppdir) { + try { + return getFullPathToDirectoryHash(new File(installerAppdir).getCanonicalPath()); + }catch (IOException ioex) { + System.err.println("Unable to resolve '"+installerAppdir+"' as a proper path on this system.\nNot generating an installer appdir hash"); + return ""; + } +} + @@ -334,7 +565,7 @@ - Util.isLinux() || Util.isUnixInstaller() + Util.isLinux() || Util.isUnixInstaller() || ( Util.isMacosInstaller() && context.getBooleanVariable("isAdmin") ) makeSymbolicLink @@ -446,27 +677,7 @@ return wrapperLink; - Map<String, String> osAppDataPathMap = new HashMap<>(); -osAppDataPathMap.put("macos", "Library/Application Support/Jalview-Desktop"); -osAppDataPathMap.put("linux", ".local/share/jalview-desktop"); -osAppDataPathMap.put("windows", "AppData\\Local\\Jalview-Desktop"); -osAppDataPathMap.put("other", ".jalview-desktop"); -String appDataPath; -String append; -if (Util.isMacOS()) { - appDataPath = osAppDataPathMap.get("macos"); - append = context.getCompilerVariable("JALVIEW_APPLICATION_NAME"); -} else if (Util.isWindows()) { - appDataPath = osAppDataPathMap.get("windows"); - append = context.getCompilerVariable("APPLICATION_FOLDER"); -} else if (Util.isLinux()) { - appDataPath = osAppDataPathMap.get("linux"); - append = context.getCompilerVariable("APPLICATION_FOLDER").toLowerCase(Locale.ROOT); -} else { - appDataPath = osAppDataPathMap.get("other"); - append = context.getCompilerVariable("APPLICATION_FOLDER").toLowerCase(Locale.ROOT); -} -return "~" + File.separator + appDataPath + File.separator + append; + getOsAppDataPath(context) userDefaultAppdirBase @@ -725,36 +936,7 @@ return console.askOkCancel(message, true); - FormComponent fc_advancedOptions = formEnvironment.getFormComponentById("US_ADVANCED_OPTIONS"); -FormComponent fc_notUsed = formEnvironment.getFormComponentById("US_NOT_USED"); -FormComponent fc_userUpdates = formEnvironment.getFormComponentById("US_ALLOW_USER_APPDIR_UPDATES"); -FormComponent fc_warning = formEnvironment.getFormComponentById("US_NO_UPDATES_WARNING"); -LayoutGroup lg_advancedOptions = formEnvironment.getLayoutGroupById("US_ADVANCED_OPTIONS_GROUP"); - - - -// get boolean status of "Enable advanced options" checkbox -JCheckBox jcb_advancedOptions = (JCheckBox) fc_advancedOptions.getConfigurationObject(); -boolean advancedOptions = jcb_advancedOptions.isSelected(); - -// set visibility of Advanced options layout group -lg_advancedOptions.setVisible(advancedOptions); -fc_notUsed.setVisible(!advancedOptions); - -if (!advancedOptions) { - return; -} - - - - -JCheckBox jcb_userUpdates = (JCheckBox) fc_userUpdates.getConfigurationObject(); -boolean userUpdates = fc_userUpdates.isEnabled() && jcb_userUpdates.isSelected(); - -boolean showWarning = advancedOptions && (!userUpdates); - -fc_warning.setVisible(showWarning); - + validateUserSpaceAdvancedOptionsForm(formEnvironment) advancedOptions @@ -840,25 +1022,7 @@ On ${installer:osName}, user updates will be installed under - FormComponent fc_advancedOptions = formEnvironment.getFormComponentById("US_ADVANCED_OPTIONS"); -FormComponent fc_userUpdates = formEnvironment.getFormComponentById("US_ALLOW_USER_APPDIR_UPDATES"); -FormComponent fc_warning = formEnvironment.getFormComponentById("US_NO_UPDATES_WARNING"); -LayoutGroup lg_advancedOptions = formEnvironment.getLayoutGroupById("US_ADVANCED_OPTIONS_GROUP"); - -JCheckBox jcb_advancedOptions = (JCheckBox) fc_advancedOptions.getConfigurationObject(); -boolean advancedOptions = jcb_advancedOptions.isSelected(); - -lg_advancedOptions.setVisible(advancedOptions); -if (!advancedOptions) { - return; -} - -JCheckBox jcb_userUpdates = (JCheckBox) fc_userUpdates.getConfigurationObject(); -boolean userUpdates = fc_userUpdates.isEnabled() && jcb_userUpdates.isSelected(); - -boolean showWarning = advancedOptions && (!userUpdates); -fc_warning.setVisible(showWarning); - + validateUserSpaceAdvancedOptionsForm(formEnvironment) allowUserDefaultAppdirUpdates @@ -933,83 +1097,7 @@ fc_warning.setVisible(showWarning); - FormComponent fc_advancedOptions = formEnvironment.getFormComponentById("SS_ADVANCED_OPTIONS"); -FormComponent fc_notUsed = formEnvironment.getFormComponentById("SS_NOT_USED"); -FormComponent fc_userUpdates = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_UPDATES"); -FormComponent fc_installerUpdates = formEnvironment.getFormComponentById("SS_ALLOW_INSTALLER_APPDIR_UPDATES"); -FormComponent fc_allowUserAppdirPath = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_PATH"); -FormComponent fc_userAppdirPath = formEnvironment.getFormComponentById("SS_USER_APPDIR_PATH"); -LayoutGroup lg_advancedGroup = formEnvironment.getLayoutGroupById("SS_ADVANCED_OPTIONS_GROUP"); -LayoutGroup lg_setUserAppdirPath = formEnvironment.getLayoutGroupById("SS_SET_USER_APPDIR_PATH"); - - - -// get boolean status of "Enable advanced options" checkbox -JCheckBox jcb_advancedOptions = (JCheckBox) fc_advancedOptions.getConfigurationObject(); -boolean advancedOptions = jcb_advancedOptions.isSelected(); - -// set visibility of Advanced options layout group -lg_advancedGroup.setVisible(advancedOptions); -fc_notUsed.setVisible(!advancedOptions); - -if (!advancedOptions) { - return; -} - - - -// get boolean status of "Allow user-space updates" checkbox -JCheckBox jcb_user = (JCheckBox) fc_userUpdates.getConfigurationObject(); -boolean userUpdates = jcb_user.isSelected(); - -// set enabled of customised user appdir path group -lg_setUserAppdirPath.setEnabled(advancedOptions && userUpdates); - -// set enabled of allow installation updates checkbox -fc_installerUpdates.setEnabled(advancedOptions && !userUpdates); - - - -// get boolean status of "Customise the user-space path" checkbox -JCheckBox jcb_allowUserAppdirPath = (JCheckBox) fc_allowUserAppdirPath.getConfigurationObject(); -boolean allowUserAppdirPath = jcb_allowUserAppdirPath.isSelected(); - -// set enabled of userAppdirPath text field -fc_userAppdirPath.setEnabled(advancedOptions && allowUserAppdirPath && fc_allowUserAppdirPath.isEnabled()); - -// get String value of userAppdirPath text field -JTextField jtf_userAppdirPath = (JTextField) fc_userAppdirPath.getConfigurationObject(); -String userAppdirPath = jtf_userAppdirPath.getText(); - - - -// get boolean status of "Allow installation updates" checkbox -JCheckBox jcb_installer = (JCheckBox) fc_installerUpdates.getConfigurationObject(); -boolean installerUpdates = jcb_installer.isSelected(); - -// should we show the No updates warning? -boolean showNoUpdatesWarning = advancedOptions && !(userUpdates || installerUpdates); -FormComponent fc_noUpdatesWarning = formEnvironment.getFormComponentById("SS_NO_UPDATES_WARNING"); -fc_noUpdatesWarning.setVisible(advancedOptions && showNoUpdatesWarning); - - - -// should we show the invalid user-space path warning? -boolean u = userAppdirPath.contains("%u"); -boolean h = userAppdirPath.contains("%h"); -boolean t = userAppdirPath.startsWith("~" + (String)context.getVariable("sys.fileSeparator")); - -boolean showInvalidPathWarning = !( userAppdirPath.length() == 0 || u || h || t ); -FormComponent fc_invalidPathWarning = formEnvironment.getFormComponentById("SS_INVALID_USER_APPDIR_PATH_WARNING"); -fc_invalidPathWarning.setVisible(advancedOptions && userUpdates && allowUserAppdirPath && fc_userAppdirPath.isEnabled() && showInvalidPathWarning); - - - -// set whether "Set defaults" button should be enabled -FormComponent fc_setDefaults = formEnvironment.getFormComponentById("SS_SET_DEFAULTS"); -JButton jb_setDefaults = (JButton) fc_setDefaults.getConfigurationObject(); -boolean enableSetDefaults = !( userUpdates && !allowUserAppdirPath && userAppdirPath.length() == 0 && !installerUpdates ); -jb_setDefaults.setEnabled(enableSetDefaults); + validateSystemSpaceAdvancedOptionsForm(context, formEnvironment) advancedOptions @@ -1096,83 +1184,7 @@ unless customised below. </html> - FormComponent fc_advancedOptions = formEnvironment.getFormComponentById("SS_ADVANCED_OPTIONS"); -FormComponent fc_notUsed = formEnvironment.getFormComponentById("SS_NOT_USED"); -FormComponent fc_userUpdates = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_UPDATES"); -FormComponent fc_installerUpdates = formEnvironment.getFormComponentById("SS_ALLOW_INSTALLER_APPDIR_UPDATES"); -FormComponent fc_allowUserAppdirPath = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_PATH"); -FormComponent fc_userAppdirPath = formEnvironment.getFormComponentById("SS_USER_APPDIR_PATH"); -LayoutGroup lg_advancedGroup = formEnvironment.getLayoutGroupById("SS_ADVANCED_OPTIONS_GROUP"); -LayoutGroup lg_setUserAppdirPath = formEnvironment.getLayoutGroupById("SS_SET_USER_APPDIR_PATH"); - - - -// get boolean status of "Enable advanced options" checkbox -JCheckBox jcb_advancedOptions = (JCheckBox) fc_advancedOptions.getConfigurationObject(); -boolean advancedOptions = jcb_advancedOptions.isSelected(); - -// set visibility of Advanced options layout group -lg_advancedGroup.setVisible(advancedOptions); -fc_notUsed.setVisible(!advancedOptions); - -if (!advancedOptions) { - return; -} - - - -// get boolean status of "Allow user-space updates" checkbox -JCheckBox jcb_user = (JCheckBox) fc_userUpdates.getConfigurationObject(); -boolean userUpdates = jcb_user.isSelected(); - -// set enabled of customised user appdir path group -lg_setUserAppdirPath.setEnabled(advancedOptions && userUpdates); - -// set enabled of allow installation updates checkbox -fc_installerUpdates.setEnabled(advancedOptions && !userUpdates); - - - -// get boolean status of "Customise the user-space path" checkbox -JCheckBox jcb_allowUserAppdirPath = (JCheckBox) fc_allowUserAppdirPath.getConfigurationObject(); -boolean allowUserAppdirPath = jcb_allowUserAppdirPath.isSelected(); - -// set enabled of userAppdirPath text field -fc_userAppdirPath.setEnabled(advancedOptions && allowUserAppdirPath && fc_allowUserAppdirPath.isEnabled()); - -// get String value of userAppdirPath text field -JTextField jtf_userAppdirPath = (JTextField) fc_userAppdirPath.getConfigurationObject(); -String userAppdirPath = jtf_userAppdirPath.getText(); - - - -// get boolean status of "Allow installation updates" checkbox -JCheckBox jcb_installer = (JCheckBox) fc_installerUpdates.getConfigurationObject(); -boolean installerUpdates = jcb_installer.isSelected(); - -// should we show the No updates warning? -boolean showNoUpdatesWarning = advancedOptions && !(userUpdates || installerUpdates); -FormComponent fc_noUpdatesWarning = formEnvironment.getFormComponentById("SS_NO_UPDATES_WARNING"); -fc_noUpdatesWarning.setVisible(advancedOptions && showNoUpdatesWarning); - - - -// should we show the invalid user-space path warning? -boolean u = userAppdirPath.contains("%u"); -boolean h = userAppdirPath.contains("%h"); -boolean t = userAppdirPath.startsWith("~" + (String)context.getVariable("sys.fileSeparator")); - -boolean showInvalidPathWarning = !( userAppdirPath.length() == 0 || u || h || t ); -FormComponent fc_invalidPathWarning = formEnvironment.getFormComponentById("SS_INVALID_USER_APPDIR_PATH_WARNING"); -fc_invalidPathWarning.setVisible(advancedOptions && userUpdates && allowUserAppdirPath && fc_userAppdirPath.isEnabled() && showInvalidPathWarning); - - - -// set whether "Set defaults" button should be enabled -FormComponent fc_setDefaults = formEnvironment.getFormComponentById("SS_SET_DEFAULTS"); -JButton jb_setDefaults = (JButton) fc_setDefaults.getConfigurationObject(); -boolean enableSetDefaults = !( userUpdates && !allowUserAppdirPath && userAppdirPath.length() == 0 && !installerUpdates ); -jb_setDefaults.setEnabled(enableSetDefaults); + validateSystemSpaceAdvancedOptionsForm(context, formEnvironment) allowUserDefaultAppdirUpdates @@ -1200,83 +1212,7 @@ jb_setDefaults.setEnabled(enableSetDefaults); Customise the user-space path - FormComponent fc_advancedOptions = formEnvironment.getFormComponentById("SS_ADVANCED_OPTIONS"); -FormComponent fc_notUsed = formEnvironment.getFormComponentById("SS_NOT_USED"); -FormComponent fc_userUpdates = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_UPDATES"); -FormComponent fc_installerUpdates = formEnvironment.getFormComponentById("SS_ALLOW_INSTALLER_APPDIR_UPDATES"); -FormComponent fc_allowUserAppdirPath = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_PATH"); -FormComponent fc_userAppdirPath = formEnvironment.getFormComponentById("SS_USER_APPDIR_PATH"); -LayoutGroup lg_advancedGroup = formEnvironment.getLayoutGroupById("SS_ADVANCED_OPTIONS_GROUP"); -LayoutGroup lg_setUserAppdirPath = formEnvironment.getLayoutGroupById("SS_SET_USER_APPDIR_PATH"); - - - -// get boolean status of "Enable advanced options" checkbox -JCheckBox jcb_advancedOptions = (JCheckBox) fc_advancedOptions.getConfigurationObject(); -boolean advancedOptions = jcb_advancedOptions.isSelected(); - -// set visibility of Advanced options layout group -lg_advancedGroup.setVisible(advancedOptions); -fc_notUsed.setVisible(!advancedOptions); - -if (!advancedOptions) { - return; -} - - - -// get boolean status of "Allow user-space updates" checkbox -JCheckBox jcb_user = (JCheckBox) fc_userUpdates.getConfigurationObject(); -boolean userUpdates = jcb_user.isSelected(); - -// set enabled of customised user appdir path group -lg_setUserAppdirPath.setEnabled(advancedOptions && userUpdates); - -// set enabled of allow installation updates checkbox -fc_installerUpdates.setEnabled(advancedOptions && !userUpdates); - - - -// get boolean status of "Customise the user-space path" checkbox -JCheckBox jcb_allowUserAppdirPath = (JCheckBox) fc_allowUserAppdirPath.getConfigurationObject(); -boolean allowUserAppdirPath = jcb_allowUserAppdirPath.isSelected(); - -// set enabled of userAppdirPath text field -fc_userAppdirPath.setEnabled(advancedOptions && allowUserAppdirPath && fc_allowUserAppdirPath.isEnabled()); - -// get String value of userAppdirPath text field -JTextField jtf_userAppdirPath = (JTextField) fc_userAppdirPath.getConfigurationObject(); -String userAppdirPath = jtf_userAppdirPath.getText(); - - - -// get boolean status of "Allow installation updates" checkbox -JCheckBox jcb_installer = (JCheckBox) fc_installerUpdates.getConfigurationObject(); -boolean installerUpdates = jcb_installer.isSelected(); - -// should we show the No updates warning? -boolean showNoUpdatesWarning = advancedOptions && !(userUpdates || installerUpdates); -FormComponent fc_noUpdatesWarning = formEnvironment.getFormComponentById("SS_NO_UPDATES_WARNING"); -fc_noUpdatesWarning.setVisible(advancedOptions && showNoUpdatesWarning); - - - -// should we show the invalid user-space path warning? -boolean u = userAppdirPath.contains("%u"); -boolean h = userAppdirPath.contains("%h"); -boolean t = userAppdirPath.startsWith("~" + (String)context.getVariable("sys.fileSeparator")); - -boolean showInvalidPathWarning = !( userAppdirPath.length() == 0 || u || h || t ); -FormComponent fc_invalidPathWarning = formEnvironment.getFormComponentById("SS_INVALID_USER_APPDIR_PATH_WARNING"); -fc_invalidPathWarning.setVisible(advancedOptions && userUpdates && allowUserAppdirPath && fc_userAppdirPath.isEnabled() && showInvalidPathWarning); - - - -// set whether "Set defaults" button should be enabled -FormComponent fc_setDefaults = formEnvironment.getFormComponentById("SS_SET_DEFAULTS"); -JButton jb_setDefaults = (JButton) fc_setDefaults.getConfigurationObject(); -boolean enableSetDefaults = !( userUpdates && !allowUserAppdirPath && userAppdirPath.length() == 0 && !installerUpdates ); -jb_setDefaults.setEnabled(enableSetDefaults); + validateSystemSpaceAdvancedOptionsForm(context, formEnvironment) allowSetUserAppdirPath @@ -1307,98 +1243,12 @@ The default value on ${installer:osName} is </html> - FormComponent fc_advancedOptions = formEnvironment.getFormComponentById("SS_ADVANCED_OPTIONS"); -FormComponent fc_notUsed = formEnvironment.getFormComponentById("SS_NOT_USED"); -FormComponent fc_userUpdates = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_UPDATES"); -FormComponent fc_installerUpdates = formEnvironment.getFormComponentById("SS_ALLOW_INSTALLER_APPDIR_UPDATES"); -FormComponent fc_allowUserAppdirPath = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_PATH"); -FormComponent fc_userAppdirPath = formEnvironment.getFormComponentById("SS_USER_APPDIR_PATH"); -LayoutGroup lg_advancedGroup = formEnvironment.getLayoutGroupById("SS_ADVANCED_OPTIONS_GROUP"); -LayoutGroup lg_setUserAppdirPath = formEnvironment.getLayoutGroupById("SS_SET_USER_APPDIR_PATH"); - - - -// get boolean status of "Enable advanced options" checkbox -JCheckBox jcb_advancedOptions = (JCheckBox) fc_advancedOptions.getConfigurationObject(); -boolean advancedOptions = jcb_advancedOptions.isSelected(); - -// set visibility of Advanced options layout group -lg_advancedGroup.setVisible(advancedOptions); -fc_notUsed.setVisible(!advancedOptions); - -if (!advancedOptions) { - return true; -} - - - -// get boolean status of "Allow user-space updates" checkbox -JCheckBox jcb_user = (JCheckBox) fc_userUpdates.getConfigurationObject(); -boolean userUpdates = jcb_user.isSelected(); - -// set enabled of customised user appdir path group -lg_setUserAppdirPath.setEnabled(advancedOptions && userUpdates); - -// set enabled of allow installation updates checkbox -fc_installerUpdates.setEnabled(advancedOptions && !userUpdates); - - - -// get boolean status of "Customise the user-space path" checkbox -JCheckBox jcb_allowUserAppdirPath = (JCheckBox) fc_allowUserAppdirPath.getConfigurationObject(); -boolean allowUserAppdirPath = jcb_allowUserAppdirPath.isSelected(); - -// set enabled of userAppdirPath text field -fc_userAppdirPath.setEnabled(advancedOptions && allowUserAppdirPath && fc_allowUserAppdirPath.isEnabled()); - -// get String value of userAppdirPath text field -JTextField jtf_userAppdirPath = (JTextField) fc_userAppdirPath.getConfigurationObject(); -String userAppdirPath = jtf_userAppdirPath.getText(); - - - -// get boolean status of "Allow installation updates" checkbox -JCheckBox jcb_installer = (JCheckBox) fc_installerUpdates.getConfigurationObject(); -boolean installerUpdates = jcb_installer.isSelected(); - -// should we show the No updates warning? -boolean showNoUpdatesWarning = advancedOptions && !(userUpdates || installerUpdates); -FormComponent fc_noUpdatesWarning = formEnvironment.getFormComponentById("SS_NO_UPDATES_WARNING"); -fc_noUpdatesWarning.setVisible(advancedOptions && showNoUpdatesWarning); - - - -// should we show the invalid user-space path warning? -boolean u = userAppdirPath.contains("%u"); -boolean h = userAppdirPath.contains("%h"); -boolean t = userAppdirPath.startsWith("~" + (String)context.getVariable("sys.fileSeparator")); - -boolean showInvalidPathWarning = !( userAppdirPath.length() == 0 || u || h || t ); -FormComponent fc_invalidPathWarning = formEnvironment.getFormComponentById("SS_INVALID_USER_APPDIR_PATH_WARNING"); -fc_invalidPathWarning.setVisible(advancedOptions && userUpdates && allowUserAppdirPath && fc_userAppdirPath.isEnabled() && showInvalidPathWarning); - - - -// set whether "Set defaults" button should be enabled -FormComponent fc_setDefaults = formEnvironment.getFormComponentById("SS_SET_DEFAULTS"); -JButton jb_setDefaults = (JButton) fc_setDefaults.getConfigurationObject(); -boolean enableSetDefaults = !( userUpdates && !allowUserAppdirPath && userAppdirPath.length() == 0 && !installerUpdates ); -jb_setDefaults.setEnabled(enableSetDefaults); - - - -return true; + validateSystemSpaceAdvancedOptionsForm(context, formEnvironment, true) - boolean u = text.contains("%u"); -boolean h = text.contains("%h"); -boolean t = text.startsWith("~" + (String)context.getVariable("sys.fileSeparator")); - -boolean showInvalidPathWarning = !( text.length() == 0 || u || h || t ); -FormComponent fc_invalidPathWarning = formEnvironment.getFormComponentById("SS_INVALID_USER_APPDIR_PATH_WARNING"); -fc_invalidPathWarning.setVisible(showInvalidPathWarning); + showInvalidUserAppdirPathWarning(context, formEnvironment) @@ -1442,83 +1292,7 @@ Installation updates will be installed into </html> - FormComponent fc_advancedOptions = formEnvironment.getFormComponentById("SS_ADVANCED_OPTIONS"); -FormComponent fc_notUsed = formEnvironment.getFormComponentById("SS_NOT_USED"); -FormComponent fc_userUpdates = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_UPDATES"); -FormComponent fc_installerUpdates = formEnvironment.getFormComponentById("SS_ALLOW_INSTALLER_APPDIR_UPDATES"); -FormComponent fc_allowUserAppdirPath = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_PATH"); -FormComponent fc_userAppdirPath = formEnvironment.getFormComponentById("SS_USER_APPDIR_PATH"); -LayoutGroup lg_advancedGroup = formEnvironment.getLayoutGroupById("SS_ADVANCED_OPTIONS_GROUP"); -LayoutGroup lg_setUserAppdirPath = formEnvironment.getLayoutGroupById("SS_SET_USER_APPDIR_PATH"); - - - -// get boolean status of "Enable advanced options" checkbox -JCheckBox jcb_advancedOptions = (JCheckBox) fc_advancedOptions.getConfigurationObject(); -boolean advancedOptions = jcb_advancedOptions.isSelected(); - -// set visibility of Advanced options layout group -lg_advancedGroup.setVisible(advancedOptions); -fc_notUsed.setVisible(!advancedOptions); - -if (!advancedOptions) { - return; -} - - - -// get boolean status of "Allow user-space updates" checkbox -JCheckBox jcb_user = (JCheckBox) fc_userUpdates.getConfigurationObject(); -boolean userUpdates = jcb_user.isSelected(); - -// set enabled of customised user appdir path group -lg_setUserAppdirPath.setEnabled(advancedOptions && userUpdates); - -// set enabled of allow installation updates checkbox -fc_installerUpdates.setEnabled(advancedOptions && !userUpdates); - - - -// get boolean status of "Customise the user-space path" checkbox -JCheckBox jcb_allowUserAppdirPath = (JCheckBox) fc_allowUserAppdirPath.getConfigurationObject(); -boolean allowUserAppdirPath = jcb_allowUserAppdirPath.isSelected(); - -// set enabled of userAppdirPath text field -fc_userAppdirPath.setEnabled(advancedOptions && allowUserAppdirPath && fc_allowUserAppdirPath.isEnabled()); - -// get String value of userAppdirPath text field -JTextField jtf_userAppdirPath = (JTextField) fc_userAppdirPath.getConfigurationObject(); -String userAppdirPath = jtf_userAppdirPath.getText(); - - - -// get boolean status of "Allow installation updates" checkbox -JCheckBox jcb_installer = (JCheckBox) fc_installerUpdates.getConfigurationObject(); -boolean installerUpdates = jcb_installer.isSelected(); - -// should we show the No updates warning? -boolean showNoUpdatesWarning = advancedOptions && !(userUpdates || installerUpdates); -FormComponent fc_noUpdatesWarning = formEnvironment.getFormComponentById("SS_NO_UPDATES_WARNING"); -fc_noUpdatesWarning.setVisible(advancedOptions && showNoUpdatesWarning); - - - -// should we show the invalid user-space path warning? -boolean u = userAppdirPath.contains("%u"); -boolean h = userAppdirPath.contains("%h"); -boolean t = userAppdirPath.startsWith("~" + (String)context.getVariable("sys.fileSeparator")); - -boolean showInvalidPathWarning = !( userAppdirPath.length() == 0 || u || h || t ); -FormComponent fc_invalidPathWarning = formEnvironment.getFormComponentById("SS_INVALID_USER_APPDIR_PATH_WARNING"); -fc_invalidPathWarning.setVisible(advancedOptions && userUpdates && allowUserAppdirPath && fc_userAppdirPath.isEnabled() && showInvalidPathWarning); - - - -// set whether "Set defaults" button should be enabled -FormComponent fc_setDefaults = formEnvironment.getFormComponentById("SS_SET_DEFAULTS"); -JButton jb_setDefaults = (JButton) fc_setDefaults.getConfigurationObject(); -boolean enableSetDefaults = !( userUpdates && !allowUserAppdirPath && userAppdirPath.length() == 0 && !installerUpdates ); -jb_setDefaults.setEnabled(enableSetDefaults); + validateSystemSpaceAdvancedOptionsForm(context, formEnvironment) allowInstallerAppdirUpdates @@ -1529,94 +1303,20 @@ jb_setDefaults.setEnabled(enableSetDefaults); - FormComponent fc_advancedOptions = formEnvironment.getFormComponentById("SS_ADVANCED_OPTIONS"); -FormComponent fc_notUsed = formEnvironment.getFormComponentById("SS_NOT_USED"); -FormComponent fc_userUpdates = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_UPDATES"); + FormComponent fc_userUpdates = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_UPDATES"); FormComponent fc_installerUpdates = formEnvironment.getFormComponentById("SS_ALLOW_INSTALLER_APPDIR_UPDATES"); FormComponent fc_allowUserAppdirPath = formEnvironment.getFormComponentById("SS_ALLOW_USER_APPDIR_PATH"); FormComponent fc_userAppdirPath = formEnvironment.getFormComponentById("SS_USER_APPDIR_PATH"); -LayoutGroup lg_advancedGroup = formEnvironment.getLayoutGroupById("SS_ADVANCED_OPTIONS_GROUP"); -LayoutGroup lg_setUserAppdirPath = formEnvironment.getLayoutGroupById("SS_SET_USER_APPDIR_PATH"); - - // set defaults -JCheckBox jcb_user = (JCheckBox) fc_userUpdates.getConfigurationObject(); -jcb_user.setSelected(true); - -JCheckBox jcb_allowUserAppdirPath = (JCheckBox) fc_allowUserAppdirPath.getConfigurationObject(); -jcb_allowUserAppdirPath.setSelected(false); - -JTextField jtf_userAppdirPath = (JTextField) fc_userAppdirPath.getConfigurationObject(); -jtf_userAppdirPath.setText(""); +((JCheckBox) fc_userUpdates.getConfigurationObject()).setSelected(true); +((JCheckBox) fc_allowUserAppdirPath.getConfigurationObject()).setSelected(false); +((JTextField) fc_userAppdirPath.getConfigurationObject()).setText(""); +((JCheckBox) fc_installerUpdates.getConfigurationObject()).setSelected(false); -JCheckBox jcb_installer = (JCheckBox) fc_installerUpdates.getConfigurationObject(); -jcb_installer.setSelected(false); - - - -// get boolean status of "Enable advanced options" checkbox -JCheckBox jcb_advancedOptions = (JCheckBox) fc_advancedOptions.getConfigurationObject(); -boolean advancedOptions = jcb_advancedOptions.isSelected(); - -// set visibility of Advanced options layout group -lg_advancedGroup.setVisible(advancedOptions); -fc_notUsed.setVisible(!advancedOptions); - -if (!advancedOptions) { - return; -} - - - -// get boolean status of "Allow user-space updates" checkbox -boolean userUpdates = jcb_user.isSelected(); - -// set enabled of customised user appdir path group -lg_setUserAppdirPath.setEnabled(advancedOptions && userUpdates); - -// set enabled of allow installation updates checkbox -fc_installerUpdates.setEnabled(advancedOptions && !userUpdates); - - - -// get boolean status of "Customise the user-space path" checkbox -boolean allowUserAppdirPath = jcb_allowUserAppdirPath.isSelected(); - -// set enabled of userAppdirPath text field -fc_userAppdirPath.setEnabled(advancedOptions && allowUserAppdirPath && fc_allowUserAppdirPath.isEnabled()); - -// get String value of userAppdirPath text field -String userAppdirPath = jtf_userAppdirPath.getText(); - - - -// get boolean status of "Allow installation updates" checkbox -boolean installerUpdates = jcb_installer.isSelected(); - -// should we show the No updates warning? -boolean showNoUpdatesWarning = advancedOptions && !(userUpdates || installerUpdates); -FormComponent fc_noUpdatesWarning = formEnvironment.getFormComponentById("SS_NO_UPDATES_WARNING"); -fc_noUpdatesWarning.setVisible(advancedOptions && showNoUpdatesWarning); - - - -// should we show the invalid user-space path warning? -boolean u = userAppdirPath.contains("%u"); -boolean h = userAppdirPath.contains("%h"); -boolean t = userAppdirPath.startsWith("~" + (String)context.getVariable("sys.fileSeparator")); - -boolean showInvalidPathWarning = !( userAppdirPath.length() == 0 || u || h || t ); -FormComponent fc_invalidPathWarning = formEnvironment.getFormComponentById("SS_INVALID_USER_APPDIR_PATH_WARNING"); -fc_invalidPathWarning.setVisible(advancedOptions && userUpdates && allowUserAppdirPath && fc_userAppdirPath.isEnabled() && showInvalidPathWarning); - - - -// set whether "Set defaults" button should be enabled -FormComponent fc_setDefaults = formEnvironment.getFormComponentById("SS_SET_DEFAULTS"); -JButton jb_setDefaults = (JButton) fc_setDefaults.getConfigurationObject(); -boolean enableSetDefaults = !( userUpdates && !allowUserAppdirPath && userAppdirPath.length() == 0 && !installerUpdates ); -jb_setDefaults.setEnabled(enableSetDefaults); +// revalidate +validateSystemSpaceAdvancedOptionsForm(context, formEnvironment); + Reset advanced options to defaults @@ -1971,14 +1671,29 @@ context.getBooleanVariable("addToDockAction") context.getBooleanVariable("appendToPathAction") + + + + + String dir = (String)context.getVariable("sys.installationDir"); +System.out.println("##### sys.installationDir = " + dir); +String hash = getCanonicalFullPathToDirectoryHash(dir); +System.out.println("##### sys.installationDir hash = " + dir); +return (Object) hash; + + + + installationAppdirHash + + - /etc/paths.d/${compiler:APPLICATION_FOLDER} + /etc/paths.d/${compiler:APPLICATION_FOLDER}-${installer:installationAppdirHash} - /Applications/${compiler:JALVIEW_APPLICATION_NAME}.app/Contents/MacOS + ${installer:sys.installationDir}/${installer:sys.contentDir}/${compiler:JALVIEW_APPLICATION_NAME}.app/Contents/MacOS Util.isMacOS() @@ -2005,7 +1720,7 @@ context.getBooleanVariable("addToDockAction") - + @@ -3014,13 +2729,7 @@ ${compiler:JALVIEW_APPLICATION_NAME} will now launch. - - - - - - - - + + -- 1.7.10.2