private void loadClassData(IXMLElement spec) { if (spec == null) { createShortcuts = false; return; } /** * 1. 2. Set flag if 'defaultCurrentUser' element found 3. Find out if we should simulate a not * supported scenario 4. Set flag if 'lateShortcutInstall' element found */ simulateNotSupported = (spec.getFirstChildNamed(SPEC_KEY_NOT_SUPPORTED) != null); defaultCurrentUserFlag = (spec.getFirstChildNamed(SPEC_KEY_DEF_CUR_USER) != null); skipIfNotSupported = (spec.getFirstChildNamed(SPEC_KEY_SKIP_IFNOT_SUPPORTED) != null); setCreateShortcutsImmediately(spec.getFirstChildNamed(SPEC_KEY_LATE_INSTALL) == null); /** * Find out in which program group the shortcuts should be placed and where this program group * should be located */ IXMLElement group = null; List<IXMLElement> groupSpecs = spec.getChildrenNamed(SPEC_KEY_PROGRAM_GROUP); String selectedInstallGroup = this.installData.getVariable("INSTALL_GROUP"); if (selectedInstallGroup != null) { // The user selected an InstallGroup before. // We may have some restrictions on the installation group // search all defined ProgramGroups for the given InstallGroup for (IXMLElement g : groupSpecs) { String instGrp = g.getAttribute(SPEC_ATTRIBUTE_INSTALLGROUP); if (instGrp != null && selectedInstallGroup.equalsIgnoreCase(instGrp)) { group = g; break; } } } if (group == null) { group = spec.getFirstChildNamed(SPEC_KEY_PROGRAM_GROUP); } String location; if (group != null) { programGroupComment = group.getAttribute("comment", ""); programGroupIconFile = group.getAttribute("iconFile", ""); suggestedProgramGroup = group.getAttribute(SPEC_ATTRIBUTE_DEFAULT_GROUP, ""); location = group.getAttribute(SPEC_ATTRIBUTE_LOCATION, SPEC_VALUE_APPLICATIONS); } else { suggestedProgramGroup = ""; location = SPEC_VALUE_APPLICATIONS; } try { if (location.equals(SPEC_VALUE_APPLICATIONS)) { shortcut.setLinkType(Shortcut.APPLICATIONS); } else if (location.equals(SPEC_VALUE_START_MENU)) { shortcut.setLinkType(Shortcut.START_MENU); } } catch (UnsupportedEncodingException e) { // ignore } }
/** Creates all shortcuts based on the information in shortcuts. */ private void createShortcuts(List<ShortcutData> shortcuts) { if (!createShortcuts) { return; } String groupName; List<String> startMenuShortcuts = new ArrayList<String>(); for (ShortcutData data : shortcuts) { try { groupName = this.groupName + data.subgroup; shortcut.setUserType(userType); shortcut.setLinkName(data.name); shortcut.setLinkType(data.type); shortcut.setArguments(data.commandLine); shortcut.setDescription(data.description); shortcut.setIconLocation(data.iconFile, data.iconIndex); shortcut.setShowCommand(data.initialState); shortcut.setTargetPath(data.target); shortcut.setWorkingDirectory(data.workingDirectory); shortcut.setEncoding(data.deskTopEntryLinux_Encoding); shortcut.setMimetype(data.deskTopEntryLinux_MimeType); shortcut.setRunAsAdministrator(data.runAsAdministrator); shortcut.setTerminal(data.deskTopEntryLinux_Terminal); shortcut.setTerminalOptions(data.deskTopEntryLinux_TerminalOptions); shortcut.setType(data.deskTopEntryLinux_Type); shortcut.setKdeSubstUID(data.deskTopEntryLinux_X_KDE_SubstituteUID); shortcut.setKdeUserName(data.deskTopEntryLinux_X_KDE_UserName); shortcut.setURL(data.deskTopEntryLinux_URL); shortcut.setTryExec(data.TryExec); shortcut.setCategories(data.Categories); shortcut.setCreateForAll(data.createForAll); shortcut.setUninstaller(uninstallData); if (data.addToGroup) { shortcut.setProgramGroup(groupName); } else { shortcut.setProgramGroup(""); } shortcut.save(); if (data.type == Shortcut.APPLICATIONS || data.addToGroup) { if (shortcut instanceof com.izforge.izpack.util.os.Unix_Shortcut) { com.izforge.izpack.util.os.Unix_Shortcut unixcut = (com.izforge.izpack.util.os.Unix_Shortcut) shortcut; String f = unixcut.getWrittenFileName(); if (f != null) { startMenuShortcuts.add(f); } } } // add the file and directory name to the file list String fileName = shortcut.getFileName(); files.add(0, fileName); File file = new File(fileName); File base = new File(shortcut.getBasePath()); Vector<File> intermediates = new Vector<File>(); execFiles.add( new ExecutableFile( fileName, ExecutableFile.UNINSTALL, ExecutableFile.IGNORE, new ArrayList<OsModel>(), false)); files.add(fileName); while ((file = file.getParentFile()) != null) { if (file.equals(base)) { break; } intermediates.add(file); } if (file != null) { Enumeration<File> filesEnum = intermediates.elements(); while (filesEnum.hasMoreElements()) { files.add(0, filesEnum.nextElement().toString()); } } } catch (Exception exception) { } } if (OsVersion.IS_UNIX) { writeXDGMenuFile( startMenuShortcuts, this.groupName, programGroupIconFile, programGroupComment); } shortcut.execPostAction(); try { if (execFiles != null) { // // TODO: Hi Guys, // TODO The following commented lines sometimes produces an uncatchable // nullpointer Exception! // TODO evaluate for what reason the files should exec. // TODO if there is a serious explanation, why to do that, // TODO the code must be more robust // FileExecutor executor = new FileExecutor(execFiles); // evaluate executor.executeFiles( ExecutableFile.NEVER, null ); } } catch (NullPointerException nep) { nep.printStackTrace(); } catch (RuntimeException cannot) { cannot.printStackTrace(); } shortcut.cleanUp(); }
/** @param userType {@link Shortcut#CURRENT_USER} {@link Shortcut#ALL_USERS} */ public void setUserType(int userType) { this.userType = userType; shortcut.setUserType(this.userType); }
/** @return <code>true</code> if we support multiple users otherwise <code>false</code> */ public boolean isSupportingMultipleUsers() { return shortcut.multipleUsers(); }
/** @return <code>true</code> if shortcut creation is supported otherwise <code>false</code> */ public boolean isSupported() { return !simulateNotSupported && shortcut.supported(); }
/** * Returns the ProgramsFolder for the current User * * @param user type of the user {@link Shortcut#ALL_USERS} or {@link Shortcut#CURRENT_USER} * @return The basedir */ public File getProgramsFolder(int user) { String path = shortcut.getProgramsFolder(user); return (new File(path)); }
/** * @param user type of the user {@link Shortcut#ALL_USERS} or {@link Shortcut#CURRENT_USER} * @return a list of progrma group names. */ public List<String> getProgramGroups(int user) { return shortcut.getProgramGroups(user); }