1 22 package com.izforge.izpack.panels; 23 24 import com.izforge.izpack.ExecutableFile; 25 import com.izforge.izpack.installer.AutomatedInstallData; 26 import com.izforge.izpack.installer.PanelAutomation; 27 import com.izforge.izpack.installer.UninstallData; 28 import com.izforge.izpack.util.Debug; 29 import com.izforge.izpack.util.FileExecutor; 30 import com.izforge.izpack.util.OsConstraint; 31 import com.izforge.izpack.util.OsVersion; 32 import com.izforge.izpack.util.TargetFactory; 33 import com.izforge.izpack.util.os.Shortcut; 34 35 import net.n3.nanoxml.XMLElement; 36 37 import java.io.File ; 38 39 import java.util.ArrayList ; 40 import java.util.Enumeration ; 41 import java.util.Vector ; 42 43 50 public class ShortcutPanelAutomationHelper implements PanelAutomation 51 { 52 53 55 61 public void makeXMLData(AutomatedInstallData idata, XMLElement panelRoot) 62 { 63 Debug.log(this.getClass().getName() + "::entering makeXMLData()"); 64 65 } 67 68 76 public boolean runAutomated(AutomatedInstallData installData, XMLElement panelRoot) 77 { 78 Shortcut shortcut; 79 80 84 Vector shortcuts = new Vector (); 85 86 Vector execFiles = new Vector (); 87 88 93 Vector files = new Vector (); 94 95 Debug.log(this.getClass().getName() + " Entered runAutomated()"); 96 97 try 98 { 99 shortcut = (Shortcut) (TargetFactory.getInstance() 100 .makeObject("com.izforge.izpack.util.os.Shortcut")); 101 shortcut.initialize(Shortcut.APPLICATIONS, "-"); 102 } 103 catch (Throwable exception) 104 { 105 Debug.log("Could not create shortcut instance"); 106 exception.printStackTrace(); 107 108 return true; 109 } 110 111 if (!shortcut.supported()) 117 { 118 Debug.log("shortcuts not supported here"); 119 120 return true; 121 } 122 123 if (!OsConstraint.oneMatchesCurrentSystem(panelRoot)) 124 { 125 Debug.log("Shortcuts Not oneMatchesCurrentSystem"); 126 127 return true; 128 } 129 130 shortcuts = new Vector (); 131 132 Vector shortcutElements; 133 ShortcutData data; 134 XMLElement dataElement; 135 136 dataElement = panelRoot.getFirstChildNamed(ShortcutPanel.AUTO_KEY_PROGRAM_GROUP); 140 141 String groupName = dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_NAME); 142 143 if (groupName == null) 144 { 145 groupName = ""; 146 } 147 148 shortcutElements = panelRoot.getChildrenNamed(ShortcutPanel.AUTO_KEY_SHORTCUT); 152 153 for (int i = 0; i < shortcutElements.size(); i++) 154 { 155 Debug.log(this.getClass().getName() + "runAutomated:shortcutElements " + i); 156 data = new ShortcutData(); 157 dataElement = (XMLElement) shortcutElements.elementAt(i); 158 159 data.name = dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_NAME); 160 data.addToGroup = Boolean.valueOf( 161 dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_GROUP)).booleanValue(); 162 163 if (OsVersion.IS_WINDOWS) 164 { 165 data.type = Integer.valueOf( 166 dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_TYPE)).intValue(); 167 } 168 else 169 { 170 Debug.log("WARN: On Linux data.type is NOT an int. Ignored."); 171 } 172 173 data.commandLine = dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_COMMAND); 174 data.description = dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_DESCRIPTION); 175 data.iconFile = dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_ICON); 176 data.iconIndex = Integer.valueOf( 177 dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_ICON_INDEX)).intValue(); 178 data.initialState = Integer.valueOf( 179 dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_INITIAL_STATE)) 180 .intValue(); 181 data.target = dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_TARGET); 182 data.workingDirectory = dataElement 183 .getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_WORKING_DIR); 184 185 data.deskTopEntryLinux_Encoding = dataElement.getAttribute( 187 ShortcutPanel.SPEC_ATTRIBUTE_ENCODING, ""); 188 data.deskTopEntryLinux_MimeType = dataElement.getAttribute( 189 ShortcutPanel.SPEC_ATTRIBUTE_MIMETYPE, ""); 190 data.deskTopEntryLinux_Terminal = dataElement.getAttribute( 191 ShortcutPanel.SPEC_ATTRIBUTE_TERMINAL, ""); 192 data.deskTopEntryLinux_TerminalOptions = dataElement.getAttribute( 193 ShortcutPanel.SPEC_ATTRIBUTE_TERMINAL_OPTIONS, ""); 194 data.deskTopEntryLinux_Type = dataElement.getAttribute( 195 ShortcutPanel.SPEC_ATTRIBUTE_TYPE, ""); 196 197 data.deskTopEntryLinux_URL = dataElement.getAttribute(ShortcutPanel.SPEC_ATTRIBUTE_URL, 198 ""); 199 200 data.deskTopEntryLinux_X_KDE_SubstituteUID = dataElement.getAttribute( 201 ShortcutPanel.SPEC_ATTRIBUTE_KDE_SUBST_UID, "false"); 202 203 data.deskTopEntryLinux_X_KDE_UserName = dataElement.getAttribute( 204 ShortcutPanel.SPEC_ATTRIBUTE_KDE_USERNAME, "root"); 205 206 data.Categories = dataElement.getAttribute(ShortcutPanel.SPEC_CATEGORIES, 207 "Application;Development"); 208 209 data.TryExec = dataElement.getAttribute(ShortcutPanel.SPEC_TRYEXEC, ""); 210 211 data.createForAll = new Boolean (dataElement.getAttribute(ShortcutPanel.CREATE_FOR_ALL, 212 "false")); 213 data.userType = Integer.valueOf( 214 dataElement.getAttribute(ShortcutPanel.USER_TYPE, Integer 215 .toString(Shortcut.CURRENT_USER))).intValue(); 216 shortcuts.add(data); 218 } 219 220 System.out.print("[ Creating shortcuts "); 221 222 for (int i = 0; i < shortcuts.size(); i++) 224 { 225 data = (ShortcutData) shortcuts.elementAt(i); 226 227 try 228 { 229 if( data.subgroup!=null ) 230 { 231 groupName = groupName + data.subgroup; 232 } 233 shortcut.setUserType(data.userType); 234 shortcut.setLinkName(data.name); 235 236 if (OsVersion.IS_WINDOWS) 237 { 238 shortcut.setLinkType(data.type); 239 } 240 241 shortcut.setArguments(data.commandLine); 242 shortcut.setDescription(data.description); 243 shortcut.setIconLocation(data.iconFile, data.iconIndex); 244 245 shortcut.setShowCommand(data.initialState); 246 shortcut.setTargetPath(data.target); 247 shortcut.setWorkingDirectory(data.workingDirectory); 248 shortcut.setEncoding(data.deskTopEntryLinux_Encoding); 249 shortcut.setMimetype(data.deskTopEntryLinux_MimeType); 250 251 shortcut.setTerminal(data.deskTopEntryLinux_Terminal); 252 shortcut.setTerminalOptions(data.deskTopEntryLinux_TerminalOptions); 253 254 if (!OsVersion.IS_WINDOWS) 255 { 256 shortcut.setType(data.deskTopEntryLinux_Type); 257 } 258 259 shortcut.setKdeSubstUID(data.deskTopEntryLinux_X_KDE_SubstituteUID); 260 shortcut.setURL(data.deskTopEntryLinux_URL); 261 shortcut.setCreateForAll(data.createForAll); 262 263 if (data.addToGroup) 264 { 265 shortcut.setProgramGroup(groupName); 266 } 267 else 268 { 269 shortcut.setProgramGroup(""); 270 } 271 272 try 273 { 274 System.out.print("."); 276 System.out.flush(); 277 278 shortcut.save(); 279 280 String fileName = shortcut.getFileName(); 282 files.add(0, fileName); 283 284 File file = new File(fileName); 285 File base = new File(shortcut.getBasePath()); 286 Vector intermediates = new Vector (); 287 288 execFiles.add(new ExecutableFile(fileName, ExecutableFile.UNINSTALL, 290 ExecutableFile.IGNORE, new ArrayList (), false)); 291 292 files.add(fileName); 293 294 while ((file = file.getParentFile()) != null) 295 { 296 if (file.equals(base)) 297 { 298 break; 299 } 300 301 intermediates.add(file); 302 } 303 304 if (file != null) 305 { 306 Enumeration filesEnum = intermediates.elements(); 307 308 while (filesEnum.hasMoreElements()) 309 { 310 files.add(0, filesEnum.nextElement().toString()); 311 } 312 } 313 } 314 catch (Exception exception) 315 {} 316 } 317 catch (Throwable exception) 318 { 319 continue; 320 } 321 } 322 323 try 326 { 327 if (execFiles != null) 328 { 329 FileExecutor executor = new FileExecutor(execFiles); 330 331 } 340 } 341 catch (NullPointerException nep) 342 { 343 nep.printStackTrace(); 344 } 345 catch (RuntimeException cannot) 346 { 347 cannot.printStackTrace(); 348 } 349 350 System.out.println(" done. ]"); 351 System.out.print("[ Add shortcuts to uninstaller "); 352 353 UninstallData uninstallData = UninstallData.getInstance(); 354 355 for (int i = 0; i < files.size(); i++) 356 { 357 uninstallData.addFile((String ) files.elementAt(i)); 358 System.out.print("."); 359 System.out.flush(); 360 } 361 362 System.out.println(" done. ]"); 363 364 return true; 365 } 366 } 367 | Popular Tags |