1 7 8 package com.memoire.vainstall.ant; 9 10 import org.apache.tools.ant.*; 11 import org.apache.tools.ant.taskdefs.*; 12 import org.apache.tools.ant.types.*; 13 import org.apache.tools.ant.util.*; 14 15 import com.memoire.vainstall.*; 17 import java.util.zip.*; 18 import java.util.jar.*; 19 import java.util.*; 20 import java.text.*; 21 import java.io.*; 22 import java.net.*; 23 25 39 public class VAInstallTask 40 extends Task 41 { 42 43 45 private static final String JAVA_HOME=System.getProperty("java.home"); 46 private static final String JDK_HOME=System.getProperty("java.home")+File.separator+".."; 47 private static String VAILOGO = null; 48 49 private static final String [] JAR_FILES_COMMON = new String [] 50 { 51 "com/memoire/vainstall/Language_da_DK.class", 52 "com/memoire/vainstall/Language_de_DE.class", 53 "com/memoire/vainstall/Language_en_UK.class", 54 "com/memoire/vainstall/Language_fr_FR.class", 55 "com/memoire/vainstall/Language_ja_JP.class", 56 "com/memoire/vainstall/Language_it_IT.class", 57 "com/memoire/vainstall/AbstractInstall.class", 58 "com/memoire/vainstall/Setup.class", 59 "com/memoire/vainstall/VAClassLoader.class", 60 "com/memoire/vainstall/SetupFileFilter.class", 61 "com/memoire/vainstall/UpgradeInfo.class", 62 "com/memoire/vainstall/LogInfo.class", 63 "com/memoire/vainstall/Uninstall.class", 64 "com/memoire/vainstall/VAGlobals.class", 65 "com/memoire/vainstall/VAStats.class", 66 "com/memoire/vainstall/VAStep.class", 67 "com/memoire/vainstall/VAStepFactory.class", 68 "com/memoire/vainstall/VAWelcomeStep.class", 69 "com/memoire/vainstall/VAReadmeStep.class", 70 "com/memoire/vainstall/VALanguageStep.class", 71 "com/memoire/vainstall/VALicenseStep.class", 72 "com/memoire/vainstall/VALicenseKeyStep.class", 73 "com/memoire/vainstall/VADirectoryStep.class", 74 "com/memoire/vainstall/VAInstallStep.class", 75 "com/memoire/vainstall/VAUpgradeStep.class", 76 "com/memoire/vainstall/VAShortcutStep.class", 77 "com/memoire/vainstall/VAEndStep.class", 78 "com/memoire/vainstall/VAWizardInterface.class", 79 "com/memoire/vainstall/VALinkDebian.class", 80 "com/memoire/vainstall/VALinkGnome.class", 81 "com/memoire/vainstall/VALinkWindows.class", 82 "com/memoire/vainstall/VALinkKDE.class", 83 84 "com/memoire/vainstall/LicenseKeySupport.class", 85 "com/memoire/vainstall/LicenseKeySupport$FieldInfo.class", 86 "com/memoire/vainstall/DefaultLicenseKeySupport.class", 87 "com/memoire/vainstall/TestLicenseKeySupport.class" 88 }; 89 90 private static final String [] JAR_FILES_JNISHORTCUT = new String [] 91 { 92 "JNIWindowsShortcut.dll", 93 "com/memoire/vainstall/JNIWindowsShortcut.class", 94 }; 95 96 private static final String [] JAR_FILES_JNIREGISTRY = new String [] 97 { 98 "ICE_JNIRegistry.dll", 99 "com/ice/jni/registry/NoSuchKeyException.class", 100 "com/ice/jni/registry/NoSuchValueException.class", 101 "com/ice/jni/registry/RegBinaryValue.class", 102 "com/ice/jni/registry/RegDWordValue.class", 103 "com/ice/jni/registry/RegMultiStringValue.class", 104 "com/ice/jni/registry/RegStringValue.class", 105 "com/ice/jni/registry/Registry.class", 106 "com/ice/jni/registry/RegistryException.class", 107 "com/ice/jni/registry/RegistryKey.class", 108 "com/ice/jni/registry/RegistryValue.class", 109 "com/ice/text/HexNumberFormat.class", 110 "com/ice/util/AWTUtilities.class", 111 "com/ice/util/ClassUtilities.class", 112 "com/ice/util/FileLog.class", 113 "com/ice/util/HTTPUtilities.class", 114 "com/ice/util/HexDump.class", 115 "com/ice/util/StringUtilities.class", 116 "com/ice/util/URLUtilities.class", 117 "com/ice/util/UserProperties.class" 118 }; 119 120 121 private static final String [] JAR_FILES_TEXT_UI = new String [] 122 { 123 "com/memoire/vainstall/tui/Language_da_DK.class", 124 "com/memoire/vainstall/tui/Language_de_DE.class", 125 "com/memoire/vainstall/tui/Language_en_UK.class", 126 "com/memoire/vainstall/tui/Language_fr_FR.class", 127 "com/memoire/vainstall/tui/Language_ja_JP.class", 128 "com/memoire/vainstall/tui/NullOutputStream.class", 129 "com/memoire/vainstall/tui/TuiDefaultStep.class", 130 "com/memoire/vainstall/tui/TuiDirectoryStep.class", 131 "com/memoire/vainstall/tui/TuiInstallStep.class", 132 "com/memoire/vainstall/tui/TuiLanguageStep.class", 133 "com/memoire/vainstall/tui/TuiLicenseStep.class", 134 "com/memoire/vainstall/tui/TuiReadmeStep.class", 135 "com/memoire/vainstall/tui/TuiShortcutStep.class", 136 "com/memoire/vainstall/tui/TuiWelcomeStep.class", 137 "com/memoire/vainstall/tui/TuiWizard.class", 138 "com/memoire/vainstall/tui/VATextUI.class", 139 "com/memoire/vainstall/tui/TuiUpgradeStep.class", 140 "com/memoire/vainstall/tui/TuiEndStep.class", 141 }; 142 143 private static final String [] JAR_FILES_ANSI_UI = new String [] 144 { 145 "com/memoire/vainstall/aui/VAAnsiUI.class", 147 }; 148 149 private static final String [] JAR_FILES_GRAPHIC_UI = new String [] 150 { 151 "com/memoire/vainstall/gui/Language_da_DK.class", 152 "com/memoire/vainstall/gui/Language_de_DE.class", 153 "com/memoire/vainstall/gui/Language_en_UK.class", 154 "com/memoire/vainstall/gui/Language_fr_FR.class", 155 "com/memoire/vainstall/gui/Language_ja_JP.class", 156 "com/memoire/vainstall/gui/VABlueScreen.class", 157 "com/memoire/vainstall/gui/VABlueScreen$1.class", 158 "com/memoire/vainstall/gui/VAGraphicUI.class", 159 "com/memoire/vainstall/gui/VAWizard.class", 160 "com/memoire/vainstall/gui/VAPanel.class", 161 "com/memoire/vainstall/gui/VAWelcomePanel.class", 162 "com/memoire/vainstall/gui/VAImagePanel.class", 163 "com/memoire/vainstall/gui/VAInstallPanel.class", 164 "com/memoire/vainstall/gui/VALanguagePanel.class", 165 "com/memoire/vainstall/gui/VALicensePanel.class", 166 "com/memoire/vainstall/gui/VALicenseKeyPanel.class", 167 "com/memoire/vainstall/gui/VALicenseKeyPanel$1.class", 168 "com/memoire/vainstall/gui/VAReadmePanel.class", 169 "com/memoire/vainstall/gui/VADirectoryPanel.class", 170 "com/memoire/vainstall/gui/VADirectoryPanel$1.class", 171 "com/memoire/vainstall/gui/VAUpgradePanel.class", 172 "com/memoire/vainstall/gui/VAShortcutPanel.class", 173 "com/memoire/vainstall/gui/VAEndPanel.class", 174 }; 175 176 private static final String [] JAR_FILES_XTRA_UI = new String [] 177 { 178 "com/memoire/vainstall/xui/Language_da_DK.class", 179 "com/memoire/vainstall/xui/Language_de_DE.class", 180 "com/memoire/vainstall/xui/Language_en_UK.class", 181 "com/memoire/vainstall/xui/Language_fr_FR.class", 182 "com/memoire/vainstall/xui/Language_ja_JP.class", 183 "com/memoire/vainstall/xui/XuiBlueScreen.class", 184 "com/memoire/vainstall/xui/XuiWizard.class", 185 "com/memoire/vainstall/xui/XuiAbstractPanel.class", 186 "com/memoire/vainstall/xui/XuiPanel.class", 187 "com/memoire/vainstall/xui/XuiImagePanel.class", 188 "com/memoire/vainstall/xui/XuiTitle.class", 189 "com/memoire/vainstall/xui/XuiButton.class", 190 "com/memoire/vainstall/xui/XuiButtonBorder.class", 191 "com/memoire/vainstall/xui/XuiLabel.class", 192 "com/memoire/vainstall/xui/XuiRadioButton.class", 193 "com/memoire/vainstall/xui/XuiOptionPane.class", 194 "com/memoire/vainstall/xui/XuiWelcomePanel.class", 195 "com/memoire/vainstall/xui/XuiReadmePanel.class", 196 "com/memoire/vainstall/xui/XuiLicensePanel.class", 197 "com/memoire/vainstall/xui/XuiInstallPanel.class", 198 "com/memoire/vainstall/xui/XuiShortcutPanel.class", 199 "com/memoire/vainstall/xui/XuiUpgradePanel.class", 200 "com/memoire/vainstall/xui/XuiLanguagePanel.class", 201 "com/memoire/vainstall/xui/XuiEndPanel.class", 202 "com/memoire/vainstall/xui/XuiDirectoryPanel$1.class", 203 "com/memoire/vainstall/xui/XuiDirectoryPanel.class", 204 "com/memoire/vainstall/xui/VAXtraUI.class", 205 }; 206 207 private final static String IMAGE_KEY = 208 "com/memoire/vainstall/resources/banner.gif"; 209 210 private File filelist_; 211 private String destPath_; 212 private String archMethod_; 213 private long archOffset_; 214 private long installClassOffset_; 215 private long installClassSize_; 216 private long jarSize_; 217 private String licenseKeySupportClassName_ = "com.memoire.vainstall.DefaultLicenseKeySupport"; 218 private String encodeKey_; 219 private LicenseKeySupport licenseKeySupport_; 220 private String additionalFiles_; 221 222 private String uiMode_; 223 private String uiBluescreen_; 224 private String uiBluescreenColor_; 225 226 private String image_; 227 228 private String appName_, appVersion_; 229 private String linkSectionName_, linkSectionIcon_, linkEntryName_, linkEntryIcon_; 230 private String instClassName_; 231 private String [] targets_; 232 private String currentTarget_; 233 private String jarAlias_, jarPassphrase_, jarCodebase_, jarVendor_, jarHomepage_; 234 private File license_; 235 private File readme_; 236 private ByteArrayOutputStream archiveInfos_; 237 private int archivecount_; 238 private Vector archiveEntryList_; 239 240 private Properties installProperties = new Properties(); 242 243 245 protected Vector filesets = new Vector(); 246 247 protected Vector javaLauncherList = new Vector(); 248 249 252 public void addFileset(FileSet set) 253 { 254 filesets.addElement(set); 255 } 256 257 public JavaLauncherArgument createJavaLauncher() 258 { 259 JavaLauncherArgument ga = new JavaLauncherArgument(); 260 javaLauncherList.addElement(ga); 261 return ga; 262 } 263 264 public class JavaLauncherArgument { 265 private String scriptname; private String javaclass; 268 private String classargs; private String javamode; private String javaargs; private String classpath; 273 public JavaLauncherArgument() 274 { 275 } 276 277 public void setScriptname(String arg) 278 { 279 scriptname = arg; 280 } 281 282 public String getScriptname() 283 { 284 return scriptname; 285 } 286 287 public void setJavaclass(String arg) 288 { 289 javaclass = arg; 290 } 291 292 public String getJavaclass() 293 { 294 return javaclass; 295 } 296 297 public void setClassargs(String arg) 298 { 299 classargs = arg; 300 } 301 302 public String getClassargs() 303 { 304 return classargs; 305 } 306 307 public void setJavamode(String arg) 308 { 309 javamode = arg; 310 } 311 312 public String getJavamode() 313 { 314 return javamode; 315 } 316 317 public void setJavaargs(String arg) 318 { 319 javaargs = arg; 320 } 321 322 public String getJavaargs() 323 { 324 return javaargs; 325 } 326 327 public void setClasspath(String arg) 328 { 329 classpath = arg; 330 } 331 332 public String getClasspath() 333 { 334 return classpath; 335 } 336 337 } 339 public void execute() 340 throws BuildException 341 { 342 343 validateAttributes(); 344 345 start(); 346 } 347 348 protected void validateAttributes() 349 throws BuildException 350 { 351 if(filesets.size() == 0) 352 { 353 throw new BuildException("Specify at least one fileset."); 354 } 355 356 for(int l=0;l<javaLauncherList.size();l++) 358 { 359 JavaLauncherArgument arg = (JavaLauncherArgument)javaLauncherList.elementAt(l); 360 if(arg.getScriptname() == null || arg.getJavaclass() == null) 361 { 362 throw new BuildException("'scriptname' and 'javaclass' is required for 'javalauncher'."); 363 } 364 } } 366 367 private void addFilesetsToArchive(ZipOutputStream stream) 368 throws java.io.IOException 369 { 370 371 for(int i=0;i<filesets.size();i++) 373 { 374 FileSet fs = (FileSet)filesets.elementAt(i); 375 DirectoryScanner ds = fs.getDirectoryScanner(project); 376 String workDirAsString = fs.getDir(project).toString(); 377 378 String [] srcFiles = ds.getIncludedFiles(); 379 String [] srcDirs = ds.getIncludedDirectories(); 380 381 394 for(int j=0;j<srcFiles.length;j++) 396 { 397 System.out.println("file="+srcFiles[j]); 398 ZipEntry newEntry=new ZipEntry(srcFiles[j]); 399 stream.putNextEntry(newEntry); 400 FileInputStream in=new FileInputStream(workDirAsString+File.separator+srcFiles[j]); 401 byte[] buf=new byte[2048]; 402 int read=in.read(buf, 0, buf.length); 403 while( read>0 ) { 404 stream.write(buf, 0, read); 405 read=in.read(buf, 0, buf.length); 406 } 407 in.close(); 408 stream.closeEntry(); 409 archivecount_++; 410 archiveEntryList_.add(srcFiles[j]); 411 } 412 413 } 415 } 416 417 419 public VAInstallTask() 420 { 421 filelist_=null; 422 destPath_=null; 423 archMethod_=null; 424 installClassOffset_=-10987654321L; 425 installClassSize_=-1234543210L; 426 archOffset_=-1234567890L; 427 uiMode_=null; 428 uiBluescreenColor_=null; 429 uiBluescreen_=null; 430 appName_=appVersion_=null; 431 linkSectionName_=linkSectionIcon_=linkEntryName_=linkEntryIcon_=null; 432 instClassName_=null; 433 targets_=new String [0]; 434 jarAlias_=jarPassphrase_=jarCodebase_=jarHomepage_=jarVendor_=null; 435 license_=null; 436 readme_=null; 437 archiveInfos_=null; 438 archivecount_=0; 439 archiveEntryList_=new Vector(); 440 } 441 442 public void start() 443 { 444 if( !processProperties() ) return; 445 446 try { 447 log(VAGlobals.i18n("VAArchiver_CompressingFiles")); 448 449 archiveInfos_=new ByteArrayOutputStream(); 450 File zip=makeArchive("archive.zip"); 451 zip.deleteOnExit(); 452 453 System.out.println(VAGlobals.i18n("VAArchiver_CreatingJarFiles")); 454 archiveInfos_.flush(); 455 byte[] infosbytes=archiveInfos_.toByteArray(); 456 File jar=makeJar("install.jar", zip, license_, readme_, infosbytes); 457 jarSize_=jar.length(); 458 archiveInfos_.close(); 459 jar.deleteOnExit(); 460 461 File installJavaFile=new File(instClassName_+".java"); 462 installJavaFile.deleteOnExit(); 463 File instClass=null; 464 boolean deleteInstallClass=true; 465 466 for(int i=0; i<targets_.length; i++) { 467 468 System.out.println(); 469 System.out.println(targets_[i]+VAGlobals.i18n("VAArchiver_Target")); 470 currentTarget_=targets_[i]; 471 System.out.println(VAGlobals.i18n("VAArchiver_GeneratingInstallClass")); 472 generateInstallCode(installJavaFile, 476 "com/memoire/vainstall/resources/Install.vaitpl", 477 "com/memoire/vainstall/VAClassLoader.class"); 478 System.out.println(VAGlobals.i18n("VAArchiver_CompilingInstallClass")); 479 instClass=compile(installJavaFile.getName()); 480 installClassSize_=instClass.length(); 481 VAGlobals.printDebug(" InstallClass size="+installClassSize_); 482 483 if( "jar".equals(targets_[i]) ) { 484 File jarTarget=new File(instClassName_+".jar"); 485 File mfFile=new File(instClassName_+".mf"); 486 mfFile.deleteOnExit(); 487 System.out.println(VAGlobals.i18n("VAArchiver_CreatingManifestFile")); 488 generateManifestFile(mfFile); 489 System.out.println(VAGlobals.i18n("VAArchiver_UpdatingJarFile")); 491 copy(jar, jarTarget); 492 jar("uvfm", jarTarget, new File[] {mfFile, instClass}); 493 if( jarAlias_!=null && !"".equals(jarAlias_.trim()) && 495 jarPassphrase_!=null && !"".equals(jarPassphrase_.trim()) ) { 496 System.out.println(VAGlobals.i18n("VAArchiver_SigningJarFile")); 497 jarsign(jarPassphrase_, jarTarget, jarAlias_); 498 } 499 } else 500 if( "jnlp".equals(targets_[i]) ) { 501 File jnlpFile=new File(instClassName_+".jnlp"); 502 System.out.println(VAGlobals.i18n("VAArchiver_CreatingJnlpFile")); 503 generateJnlpFile(jnlpFile); 504 } else 505 506 if( "java".equals(targets_[i]) ) { 507 installClassOffset_=-10987654321L; 508 deleteInstallClass=false; 509 if( archMethod_.equals("append") ) { 510 archOffset_=instClass.length(); 511 VAGlobals.printDebug(VAGlobals.i18n("VAArchiver_ArchiveOffset")+archOffset_); 512 generateInstallCode( 513 installJavaFile, 514 "com/memoire/vainstall/resources/Install.vaitpl", 515 "com/memoire/vainstall/VAClassLoader.class"); 516 System.out.println(VAGlobals.i18n("VAArchiver_CompilingInstallClass")); 517 compile(installJavaFile.getName()); 518 System.out.println(VAGlobals.i18n("VAArchiver_AppendingArchive")); 519 appendArchive(instClass); 520 } 521 } else 522 if( "unix".equals(targets_[i]) ) { 523 File unixShellFile=new File(instClassName_+".sh"); 524 525 installClassOffset_=generateUnixInstallShell( 526 unixShellFile, 527 "com/memoire/vainstall/resources/Install-sh.vaitpl", 528 instClass); 529 VAGlobals.printDebug(VAGlobals.i18n("VAArchiver_InstallClassOffset")+installClassOffset_); 530 531 if( archMethod_.equals("append") ) { 532 archOffset_=unixShellFile.length(); 533 VAGlobals.printDebug(VAGlobals.i18n("VAArchiver_ArchiveOffset")+archOffset_); 534 generateInstallCode( 535 installJavaFile, 536 "com/memoire/vainstall/resources/Install.vaitpl", 537 "com/memoire/vainstall/VAClassLoader.class"); 538 System.out.println(VAGlobals.i18n("VAArchiver_CompilingInstallClass")); 539 compile(installJavaFile.getName()); 540 generateUnixInstallShell( 541 unixShellFile, 542 "com/memoire/vainstall/resources/Install-sh.vaitpl", 543 instClass); 544 System.out.println(VAGlobals.i18n("VAArchiver_AppendingArchive")); 545 appendArchive(unixShellFile); 546 } 547 } else 548 if( ("win95".equals(targets_[i]))|| 549 ("linux-i386".equals(targets_[i])) ) { 550 File nativeExeFile=null; 551 if( "win95".equals(targets_[i]) ) nativeExeFile=new File(instClassName_+".exe"); 552 else 553 if( "linux-i386".equals(targets_[i]) ) nativeExeFile=new File(instClassName_+".lin"); 554 555 installClassOffset_=generateNativeInstallExe( 556 nativeExeFile, 557 "com/memoire/vainstall/resources/Install-"+targets_[i]+"-exe.vaitpl", 558 instClass); 559 VAGlobals.printDebug(VAGlobals.i18n("VAArchiver_InstallClassOffset")+installClassOffset_); 560 561 if( archMethod_.equals("append") ) { 562 archOffset_=nativeExeFile.length(); 563 VAGlobals.printDebug(VAGlobals.i18n("VAArchiver_ArchiveOffset")+archOffset_); 564 generateInstallCode( 565 installJavaFile, 566 "com/memoire/vainstall/resources/Install.vaitpl", 567 "com/memoire/vainstall/VAClassLoader.class"); 568 System.out.println(VAGlobals.i18n("VAArchiver_CompilingInstallClass")); 569 compile(installJavaFile.getName()); 570 generateNativeInstallExe( 571 nativeExeFile, 572 "com/memoire/vainstall/resources/Install-"+targets_[i]+"-exe.vaitpl", 573 instClass); 574 System.out.println(VAGlobals.i18n("VAArchiver_AppendingArchive")); 575 appendArchive(nativeExeFile); 576 } 577 } 578 } 579 if( instClass!=null && deleteInstallClass ) instClass.delete(); 580 581 } catch( IOException e ) { 582 e.printStackTrace(); 583 } 584 } 585 586 private boolean processProperties() 587 { 588 VAILOGO = "com/memoire/vainstall/resources/vailogo.gif"; 589 VAGlobals.setLanguage("default"); 591 String tmp = getProject().getProperty("vainstall.destination.language"); 592 if(tmp != null) 593 { 594 installProperties.put("vainstall.destination.language",tmp); 595 } 596 String useFullPath=getProject().getProperty("vainstall.script.java.fullpath"); 598 System.err.println("use full path "+useFullPath); 599 if(useFullPath!=null && "true".equalsIgnoreCase(useFullPath)){ 600 installProperties.put("vainstall.script.java.fullpath",Boolean.TRUE); 601 } 602 603 destPath_ = getProject().getProperty("vainstall.destination.defaultPath"); 605 if(destPath_ == null) 606 { 607 log("Note: Property 'vainstall.destination.defaultPath' = null"); 608 return false; 609 } 610 else 611 { 612 if(checkVaiPath(destPath_) == false) 613 { 614 log("Note: Property 'vainstall.destination.defaultPath' has incorrect format."); 615 return false; 616 } 617 } 618 619 tmp = getProject().getProperty("vainstall.destination.installMode"); 621 if("update".equals(tmp) == true) 622 { 623 destPath_="[UPDATE]"; 624 } 625 else 626 { 627 if( !"install".equals(tmp) ) 628 { 629 log("Note: Property 'vainstall.destination.installMode'. No valid install mode specified: Defaulting to 'install'."); 630 System.err.println("no valid installMode specified: defaulting to install"); 631 } 632 } 633 634 tmp = getProject().getProperty("vainstall.destination.targets"); 636 if(tmp == null) 637 { 638 log("Note: Property 'vainstall.destination.targets'. No target specified."); 639 return false; 640 } 641 StringTokenizer tok=new StringTokenizer(tmp, ","); 642 Vector v=new Vector(); 643 while( tok.hasMoreTokens() ) { 644 String t=tok.nextToken().trim().toLowerCase(); 645 if( (!"java".equals(t))&& 646 (!"jar".equals(t))&& 647 (!"jnlp".equals(t))&& 648 (!"unix".equals(t))&& 649 (!"win95".equals(t))&& 650 (!"linux-i386".equals(t)) ) { 651 System.err.println("unknown target: "+t); 652 return false; 653 } 654 if( !v.contains(t) ) v.add(t); 655 } 656 if( v.contains("jnlp") && !v.contains("jar") ) v.add("jar"); 658 targets_=new String [v.size()]; 659 int i=0; 662 if( v.contains("jar") ) targets_[i++]="jar"; 663 if( v.contains("jnlp") ) targets_[i++]="jnlp"; 664 if( v.contains("unix") ) targets_[i++]="unix"; 665 if( v.contains("linux-i386") ) targets_[i++]="linux-i386"; 666 if( v.contains("win95") ) targets_[i++]="win95"; 667 if( v.contains("java") ) targets_[i++]="java"; 668 669 if( v.contains("jar") ) { 670 jarAlias_=VAProperties.PROPERTIES.getProperty("vainstall.jarsigner.alias"); 671 jarPassphrase_=VAProperties.PROPERTIES.getProperty("vainstall.jarsigner.passphrase"); 672 } 673 674 if( v.contains("jnlp") ) { 675 jarCodebase_=VAProperties.PROPERTIES.getProperty("vainstall.jnlp.codebase"); 676 if( jarCodebase_==null || "".equals(jarCodebase_) ) { 677 System.err.println("vainstall.jnlp.codebase null"); 678 return false; 679 } 680 681 jarHomepage_=VAProperties.PROPERTIES.getProperty("vainstall.jnlp.homepage"); 682 if( jarHomepage_==null || "".equals(jarHomepage_) ) { 683 System.err.println("vainstall.jnlp.homepage null"); 684 return false; 685 } 686 687 jarVendor_=VAProperties.PROPERTIES.getProperty("vainstall.jnlp.vendor"); 688 if( jarVendor_==null || "".equals(jarVendor_) ) { 689 System.err.println("vainstall.jnlp.vendor null"); 690 return false; 691 } 692 } 693 694 archMethod_ = getProject().getProperty("vainstall.archive.archivingMethod"); 696 if(archMethod_==null) 697 { 698 archMethod_="append"; 699 } 700 701 uiMode_ = getProject().getProperty("vainstall.destination.ui"); 703 if(uiMode_ == null) 704 { 705 uiMode_="graphic"; 706 } 707 708 uiBluescreen_ = getProject().getProperty("vainstall.destination.ui.bluescreen"); 710 if(uiBluescreen_ == null) 711 { 712 uiBluescreen_="yes"; 713 } 714 715 uiBluescreenColor_ = getProject().getProperty("vainstall.destination.ui.bluescreen.colour"); 717 if((uiBluescreenColor_ != null) && (!"".equals(uiBluescreenColor_)) ) 718 { 719 try 720 { 721 Integer.parseInt(uiBluescreenColor_, 16); 722 } 723 catch(NumberFormatException nfe) 724 { 725 log("Note: Property 'vainstall.destination.ui.bluescreen.colour' has invalid format."); 726 return false; 727 } 728 } 729 730 tmp = getProject().getProperty("vainstall.destination.ui.image"); 732 if(tmp == null) 733 { 734 log("Note: Property 'vainstall.destination.ui.image' = null: Will use default image."); 735 image_= IMAGE_KEY; 736 } 737 else 738 { 739 image_= tmp; 740 } 741 742 appName_ = getProject().getProperty("vainstall.destination.appName"); 744 if(appName_ == null) 745 { 746 log("Note: Property 'vainstall.destination.appName' = null."); 747 return false; 748 } 749 750 appVersion_ = getProject().getProperty("vainstall.destination.appVersion"); 752 if(appVersion_ == null) 753 { 754 log("Note: Property 'vainstall.destination.appVersion' = null."); 755 return false; 756 } 757 758 linkSectionName_ = getProject().getProperty("vainstall.destination.linkSectionName"); 760 if(linkSectionName_ == null) 761 { 762 log("Note: Property 'vainstall.destination.appVersion' = null : Defaulting to 'Applications'."); 763 linkSectionName_="Applications"; 764 } 765 766 linkSectionIcon_ = getProject().getProperty("vainstall.destination.linkSectionIcon"); 768 if(linkSectionIcon_ == null) 769 { 770 log("Note: Property 'vainstall.destination.linkSectionIcon' = null."); 771 linkSectionIcon_=""; 772 } 773 774 linkEntryName_ = getProject().getProperty("vainstall.destination.linkEntryName"); 776 if(linkEntryName_ == null) 777 { 778 log("Note: Property 'vainstall.destination.linkEntryName' = null : Defaulting to '"+appName_+"'."); 779 linkEntryName_=appName_; 780 } 781 782 linkEntryIcon_ = getProject().getProperty("vainstall.destination.linkEntryIcon"); 784 if(linkEntryIcon_ == null) 785 { 786 log("Note: Property 'vainstall.destination.linkEntryIcon' = null."); 787 linkEntryIcon_=""; 788 } 789 790 instClassName_ = getProject().getProperty("vainstall.archive.installClassName"); 792 if(instClassName_ == null) 793 { 794 instClassName_="Install_"+appName_; 795 } 796 797 tmp = getProject().getProperty("vainstall.archive.license"); 799 if(tmp == null) 800 { 801 log("Note: Property 'vainstall.archive.license' = null."); 802 return false; 803 } 804 license_=new File(tmp); 805 if( (!license_.exists()) || (!license_.canRead()) ) 806 { 807 log("Note: Property 'vainstall.archive.license' : Can not read "+license_+"."); 808 return false; 809 } 810 try { 811 InputStream licenseStream = new FileInputStream(license_); 812 String licenseEncoding = VAProperties.PROPERTIES.getProperty("vainstall.archive.license.encoding"); 813 if(licenseEncoding != null && licenseEncoding.equals("") == false) 814 { 815 try { 816 InputStreamReader isrLicense = new InputStreamReader(licenseStream, licenseEncoding); 817 } catch(UnsupportedEncodingException exc) { 818 log("Note: Unsuported encoding for license!"); 819 return false; 820 } 821 } 822 } catch(Exception exc) { 823 log("Note: Problems reading license file!"); 824 return false; 825 } 826 827 828 tmp=getProject().getProperty("vainstall.license.key.support"); 829 System.out.println("fred "+tmp); 830 if( tmp!=null && !"".equals(tmp) ) { 831 licenseKeySupportClassName_ = tmp; 832 } 833 encodeKey_=getProject().getProperty("vainstall.license.key.support.encode.key"); 834 additionalFiles_=getProject().getProperty("vainstall.additional.files"); 835 Class cls=null; 836 try 837 { 838 cls = Class.forName(licenseKeySupportClassName_); 839 } 840 catch(Exception ex) 841 { 842 if( (cls==null) && (additionalFiles_ != null) ) 843 { 844 StringTokenizer fmi = new StringTokenizer(additionalFiles_,","); 845 while(fmi.hasMoreTokens()) { 846 StringTokenizer fm = new StringTokenizer(fmi.nextToken(),"!"); 847 String classFound = fm.nextToken(); 848 if( (classFound!=null) 849 && (classFound.indexOf(licenseKeySupportClassName_)>-1) ){ 850 try{ 851 URLClassLoader urlcl=new URLClassLoader(new URL[]{new File(classFound).getParentFile().toURL()}); 852 cls = urlcl.loadClass(licenseKeySupportClassName_); 853 } 854 catch(Exception ex2){ 855 System.out.println("License key support could not be initialized with specific URLCLassLoader"+ex2); 856 } 857 break; 858 } 859 } 860 } 861 } 862 if(cls==null) 863 { 864 throw new RuntimeException ("License key support could not be initialized: "); 865 } 866 try{ 867 System.out.println(cls.getName()); 868 licenseKeySupport_ = (LicenseKeySupport) cls.newInstance(); 869 } 870 catch(Exception ex){ 871 System.err.println("LicenseKeySupport can't be instantiated"+ex); 872 } 873 874 875 876 tmp = getProject().getProperty("vainstall.archive.readme"); 878 if(tmp == null) 879 { 880 log("Note: Property 'vainstall.archive.readme' = null."); 881 return false; 882 } 883 readme_=new File(tmp); 884 if( (!readme_.exists())||(!readme_.canRead()) ) 885 { 886 log("Note: Property 'vainstall.archive.readme' : Can not read "+readme_+"."); 887 return false; 888 } 889 try { 890 InputStream readmeStream = new FileInputStream(readme_); 891 String readmeEncoding = VAProperties.PROPERTIES.getProperty("vainstall.archive.readme.encoding"); 892 if(readmeEncoding != null && readmeEncoding.equals("") == false) 893 { 894 try { 895 InputStreamReader isrReadme = new InputStreamReader(readmeStream, readmeEncoding); 896 } catch(UnsupportedEncodingException exc) { 897 log("Note: Unsupported encoding for readme!"); 898 return false; 899 } 900 } 901 } catch(Exception exc) { 902 log("Note: Problems reading readme file!"); 903 return false; 904 } 905 906 return true; 907 } 908 909 private File makeArchive(String filename) 910 throws IOException 911 { 912 Vector scripts=new Vector(); 913 914 Vector archiveExeList = new Vector(); 915 916 for(int l=0;l<javaLauncherList.size();l++) 918 { 919 JavaLauncherArgument arg = (JavaLauncherArgument)javaLauncherList.elementAt(l); 920 921 String dest="JavaLauncher\n"; 922 dest+="Class="+arg.getJavaclass()+"\n"; 923 dest+="ClassPath="+(arg.getClasspath()==null?"":arg.getClasspath())+"\n"; 924 dest+="JavaMode="+(arg.getJavamode()==null?"console":arg.getJavamode())+"\n"; 925 dest+="JavaArgs="+(arg.getJavaargs()==null?"":arg.getJavaargs())+"\n"; 926 dest+="ClassArgs="+(arg.getClassargs()==null?"":arg.getClassargs())+"\n"; 927 dest+="ScriptName="+arg.getScriptname()+"\n"; 928 scripts.add(dest); 929 archiveExeList.add("[SCRIPT]"+arg.getScriptname()); 930 } 932 File zipFile = new File(filename); 934 File parent = zipFile.getParentFile(); 935 if( (parent!=null)&&(!parent.canWrite()) ) throw new IOException(zipFile+" can not be written"); 936 ZipOutputStream stream=new ZipOutputStream( 937 new GZIPOutputStream(new FileOutputStream(zipFile))); 938 stream.setLevel(0); 939 940 addFilesetsToArchive(stream); 941 942 stream.close(); 944 945 ObjectOutputStream infos=new ObjectOutputStream(archiveInfos_); 947 948 infos.writeInt(archivecount_); 949 950 infos.writeObject(scripts); 952 953 infos.writeObject(archiveExeList); 955 956 infos.flush(); 957 958 return zipFile; 959 } 960 961 private String convertToLocalPath(String entry) throws IOException 962 { 963 String res=Setup.expandDirectory(entry, true, null); 964 if( res==null ) 965 throw new IOException("Invalid path: "+entry); 966 return res.replace('/', File.separatorChar); 967 } 968 969 private String convertToGenericPath(String line) 970 { 971 return line.replace(File.separatorChar, '/'); 972 } 973 974 private void generateInstallCode(File javaFile, 975 String instTemplate, String classLoader) throws IOException 976 { 977 PrintWriter writer=new PrintWriter(new FileWriter(javaFile)); 978 int read=0; 979 byte[] buf=new byte[128]; 980 981 InputStream is = getClass().getResourceAsStream("/"+instTemplate); 983 InputStreamReader isr = new InputStreamReader(is); 984 LineNumberReader reader=new LineNumberReader(isr); 985 986 System.out.println(VAGlobals.i18n("VAArchiver_GeneratingInstallClassCode")); 987 988 String line=reader.readLine(); 989 while( (line!=null)&&(!line.startsWith("// --> InstallClassName")) ) { 990 writer.println(line); 991 line=reader.readLine(); 992 } 993 writer.println("public class "+instClassName_+" {"); 994 writer.println(" private static final Class installClass=new "+instClassName_+"().getClass();"); 995 996 line=reader.readLine(); 997 while( (line!=null)&&(!line.startsWith("// --> ArchivingMethod")) ) { 998 writer.println(line); 999 line=reader.readLine(); 1000 } 1001 writer.println(" private static String ARCH_METHOD=\""+archMethod_+"\";"); 1002 1003 line=reader.readLine(); 1004 while( (line!=null)&&(!line.startsWith("// --> TargetType")) ) { 1005 writer.println(line); 1006 line=reader.readLine(); 1007 } 1008 writer.println(" private static String TARGET_TYPE=\""+currentTarget_+"\";"); 1009 1010 line=reader.readLine(); 1011 while( (line!=null)&&(!line.startsWith("// --> InstallClassOffset")) ) { 1012 writer.println(line); 1013 line=reader.readLine(); 1014 } 1015 writer.println(" private static long ICLASS_OFFSET="+installClassOffset_+"L;"); 1016 1017 line=reader.readLine(); 1018 while( (line!=null)&&(!line.startsWith("// --> InstallClassSize")) ) { 1019 writer.println(line); 1020 line=reader.readLine(); 1021 } 1022 if( installClassSize_!=archOffset_ ) 1023 writer.println(" private static long ICLASS_SIZE="+installClassSize_+"L;"); 1024 else 1025 writer.println(" private static long ICLASS_SIZE=-1234543210L;"); 1026 1027 line=reader.readLine(); 1028 while( (line!=null)&&(!line.startsWith("// --> ArchiveOffset")) ) { 1029 writer.println(line); 1030 line=reader.readLine(); 1031 } 1032 writer.println(" private static long ARCH_OFFSET="+archOffset_+"L;"); 1033 1034 1035 line=reader.readLine(); 1036 while( (line!=null)&&(!line.startsWith("// --> JarSize")) ) { 1037 writer.println(line); 1038 line=reader.readLine(); 1039 } 1040 writer.println(" private static long JAR_SIZE="+jarSize_+"L;"); 1041 1042 line=reader.readLine(); 1043 while( (line!=null)&&(!line.startsWith("// --> UIMode")) ) { 1044 writer.println(line); 1045 line=reader.readLine(); 1046 } 1047 writer.println(" private static String UI_MODE=\""+uiMode_+"\";"); 1048 1049 line=reader.readLine(); 1050 while( (line!=null)&&(!line.startsWith("// --> UIBluescreen")) ) { 1051 writer.println(line); 1052 line=reader.readLine(); 1053 } 1054 writer.println(" private static String UI_BLUESCREEN=\""+uiBluescreen_+"\";"); 1055 1056 line=reader.readLine(); 1057 while( (line!=null)&&(!line.startsWith("// --> UIBluescreenColor")) ) { 1058 writer.println(line); 1059 line=reader.readLine(); 1060 } 1061 writer.println(" private static String UI_BLUESCREEN_COLOR=\""+uiBluescreenColor_+"\";"); 1062 1063 line=reader.readLine(); 1064 while( (line!=null)&&(!line.startsWith("// --> DestPath")) ) { 1065 writer.println(line); 1066 line=reader.readLine(); 1067 } 1068 writer.println(" private static String DEST_PATH=\""+destPath_+"\";"); 1069 1070 line=reader.readLine(); 1071 while( (line!=null)&&(!line.startsWith("// --> AppInfo")) ) { 1072 writer.println(line); 1073 line=reader.readLine(); 1074 } 1075 writer.println(" private static String APP_NAME=\""+appName_+"\";"); 1076 writer.println(" private static String APP_VERSION=\""+appVersion_+"\";"); 1077 1078 line=reader.readLine(); 1079 while( (line!=null)&&(!line.startsWith("// --> LinkInfos")) ) { 1080 writer.println(line); 1081 line=reader.readLine(); 1082 } 1083 writer.println(" private static String LINK_SECTION_NAME=\""+linkSectionName_+"\";"); 1084 writer.println(" private static String LINK_SECTION_ICON=\""+linkSectionIcon_+"\";"); 1085 writer.println(" private static String LINK_ENTRY_NAME=\""+linkEntryName_+"\";"); 1086 writer.println(" private static String LINK_ENTRY_ICON=\""+linkEntryIcon_+"\";"); 1087 1088 line=reader.readLine(); 1089 while( (line!=null)&&(!line.startsWith("// --> LicenseKey")) ) { 1090 writer.println(line); 1091 line=reader.readLine(); 1092 } 1093 writer.println(" private static String LICENSE_KEY_SUPPORT_NAME=\""+licenseKeySupportClassName_+"\";"); 1094 1095 1096 1097 System.out.println(VAGlobals.i18n("VAArchiver_AppendingClassloader")); 1098 line=reader.readLine(); 1099 while( (line!=null)&&(!line.startsWith("// --> ClassLoader")) ) { 1100 writer.println(line); 1101 line=reader.readLine(); 1102 } 1103 1104 InputStream isClassLoader = getClass().getResourceAsStream("/"+classLoader); 1105 1106 System.out.println(" CLASSLOADER = "+"/"+classLoader); 1107 writer.println(" private static String[] CL_CLASS={"); 1108 read=isClassLoader.read(buf); 1109 while(read>0) { 1110 writer.println("\""+codeLine(buf, read)+"\","); 1111 read=isClassLoader.read(buf); 1112 } 1113 isClassLoader.close(); 1114 1115 writer.println(" };\n}"); 1116 reader.close(); 1117 writer.close(); 1118 1119 is.close(); 1121 isr.close(); 1122 1123 } 1124 1125 private void generateJnlpFile(File jnlpFile) throws IOException 1126 { 1127 PrintWriter out=new PrintWriter 1128 (new BufferedWriter 1129 (new OutputStreamWriter(new FileOutputStream(jnlpFile),"UTF-8"))); 1130 1131 out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 1132 out.println("<jnlp spec=\"1.0\""); 1133 out.println(" codebase=\""+jarCodebase_+"\""); 1134 out.println(" HREF=\""+instClassName_+".jnlp\">"); 1135 out.println(" <information>"); 1136 out.println(" <title>"+appName_+" "+appVersion_+" Installer</title>"); 1137 out.println(" <vendor>"+jarVendor_+"</vendor>"); 1138 out.println(" <homepage HREF=\""+jarHomepage_+"\"/>"); 1139 out.println(" <description>Installer for "+appName_+" "+appVersion_+"</description>"); 1140 out.println(" <offline/>"); 1142 out.println(" </information>"); 1143 out.println(" <resources>"); 1144 out.println(" <j2se version=\"1.3 1.2\"/>"); 1145 out.println(" <jar HREF=\""+instClassName_+".jar\"/>"); 1146 out.println(" </resources>"); 1147 out.println(" <security>"); 1148 out.println(" <all-permissions/>"); 1149 out.println(" </security>"); 1150 out.println(" <application-desc main-class=\""+instClassName_+"\"/>"); 1151 out.println("</jnlp>"); 1152 out.close(); 1153 } 1154 1155 private void generateManifestFile(File mfFile) throws IOException 1156 { 1157 PrintWriter out=new PrintWriter 1158 (new BufferedWriter 1159 (new OutputStreamWriter(new FileOutputStream(mfFile),"UTF-8"))); 1160 1161 out.println("Manifest-Version: 1.0"); 1162 out.println("Main-Class: "+instClassName_); 1163 out.close(); 1164 } 1165 1166 private long generateUnixInstallShell(File unixShellFile, 1167 String instTemplate, File instClassFile) throws IOException 1168 { 1169 FileOutputStream byteWriter=new FileOutputStream(unixShellFile); 1170 1171 InputStream is = getClass().getResourceAsStream("/"+instTemplate); 1172 InputStreamReader isr = new InputStreamReader(is); 1173 LineNumberReader reader=new LineNumberReader(isr); 1174 String content=""; 1175 String installClassStartStr="000000000000"; 1176 NumberFormat nf=NumberFormat.getInstance(Locale.US); 1177 nf.setGroupingUsed(false); 1178 nf.setMinimumIntegerDigits(installClassStartStr.length()); 1179 int installClassStartPos=0; 1180 long installClassOffset=0; 1181 1182 System.out.println(VAGlobals.i18n("VAArchiver_GenerateInstallShell")); 1183 1184 String line=reader.readLine(); 1185 while( (line!=null)&&(!line.startsWith("# InstallClassStart")) ) { 1186 content+=line+"\n"; 1187 line=reader.readLine(); 1188 } 1189 content+="InstallClassStart="+installClassStartStr+"\n"; 1190 installClassStartPos=content.length()-1-1-installClassStartStr.length(); 1191 1192 line=reader.readLine(); 1193 while( (line!=null)&&(!line.startsWith("# InstallClassSize")) ) { 1194 content+=line+"\n"; 1195 line=reader.readLine(); 1196 } 1197 content+=new String ("InstallClassSize="+instClassFile.length()+"\n"); 1198 1199 line=reader.readLine(); 1200 while( (line!=null)&&(!line.startsWith("# InstallClassName")) ) { 1201 content+=line+"\n"; 1202 line=reader.readLine(); 1203 } 1204 content+=new String ("InstallClassName="+instClassName_+"\n"); 1205 1206 line=reader.readLine(); 1207 while( (line!=null)&&(!line.startsWith("# Install class")) ) { 1208 content+=line+"\n"; 1209 line=reader.readLine(); 1210 } 1211 if( line!=null ) content+=line+"\n"; 1212 byteWriter.write(content.substring(0, installClassStartPos+1).getBytes()); 1213 byteWriter.write(nf.format(content.length()).getBytes()); 1214 byteWriter.write(content.substring(installClassStartPos+1+installClassStartStr.length()).getBytes()); 1215 installClassOffset=content.length(); 1216 content=null; 1217 1218 FileInputStream classStream=new FileInputStream(instClassFile); 1219 byte[] buf=new byte[2048]; 1220 int read=classStream.read(buf); 1221 while(read>0) { 1222 byteWriter.write(buf, 0, read); 1223 read=classStream.read(buf); 1224 } 1225 classStream.close(); 1226 reader.close(); 1227 byteWriter.close(); 1228 return installClassOffset; 1229 } 1230 1231 private void shiftArray(byte[] array) 1232 { 1233 for(int i=0; i<(array.length-1); i++) array[i]=array[i+1]; 1234 array[array.length-1]=0; 1235 } 1236 1237 private long generateNativeInstallExe(File nativeInstallFile, 1238 String instTemplate, File instClassFile) throws IOException 1239 { 1240 1253 1254 InputStream reader = getClass().getResourceAsStream("/"+instTemplate); 1256 System.out.println("generateNativeInstallExe = /"+instTemplate); 1258 System.out.println("reader length="+reader.available()); 1259 1260 ByteArrayOutputStream content=new ByteArrayOutputStream(); 1261 String installClassVarStr="000000000000"; 1262 byte[] buf=new byte[installClassVarStr.length()]; 1263 NumberFormat nf=NumberFormat.getInstance(Locale.US); 1264 nf.setGroupingUsed(false); 1265 nf.setMinimumIntegerDigits(installClassVarStr.length()); 1266 int installClassStopPos=0; 1267 long installClassOffset=reader.available(); 1268 int position=0; 1269 1270 System.out.println(VAGlobals.i18n("VAArchiver_GenerateInstallExe")); 1271 1272 reader.read(buf, 0, buf.length); 1274 position=1; 1276 1277 for(int n=0; n<3; n++) { 1279 while( (!new String (buf).equals("clname_here_"))&& 1281 (!new String (buf).equals("clstart_here"))&& 1282 (!new String (buf).equals("clstop_here_")) ) { 1283 content.write(buf[0]); 1284 int nextb=reader.read(); 1286 position++; 1287 shiftArray(buf); 1288 buf[buf.length-1]=(byte)nextb; 1290 } 1291 if( new String (buf).equals("clname_here_") ) { 1292 System.err.println(" clname_here_ found at "+(position-1)); 1293 StringBuffer clnameBuffer=new StringBuffer (64); 1294 clnameBuffer.append(instClassName_); 1295 for(int i=clnameBuffer.length()-1; i<64; i++) { 1296 clnameBuffer.append('.'); 1297 } 1298 byte[] clnameBytes=clnameBuffer.toString().getBytes(); 1299 for(int i=0; i<64; i++) { 1301 content.write(clnameBytes[i]); 1302 position++; 1303 } 1304 reader.skip(64-buf.length); 1306 reader.read(buf, 0, buf.length); 1308 } else 1309 if( new String (buf).equals("clstart_here") ) { 1310 System.err.println(" clstart_here found at "+(position-1)); 1311 buf=nf.format(installClassOffset).getBytes(); 1312 for(int i=0; i<buf.length; i++) { 1314 content.write(buf[i]); 1315 position++; 1316 } 1317 reader.read(buf, 0, buf.length); 1319 } else 1320 if( new String (buf).equals("clstop_here_") ) { 1321 System.err.println(" clstop_here_ found at "+(position-1)); 1322 installClassStopPos=position-1; 1324 content.write(buf); 1326 position+=12; 1327 reader.read(buf, 0, buf.length); 1329 } 1330 } 1331 content.write(buf); 1332 1363 buf=new byte[2048]; 1365 int read=reader.read(buf); 1366 while( read>0 ) { 1367 content.write(buf, 0, read); 1368 read=reader.read(buf); 1369 } 1370 reader.close(); 1371 1372 FileInputStream classStream=new FileInputStream(instClassFile); 1374 1375 read=classStream.read(buf); 1376 while( read>0 ) { 1377 content.write(buf, 0, read); 1378 read=classStream.read(buf); 1379 } 1380 classStream.close(); 1381 content.close(); 1382 1383 byte[] contentBytes=content.toByteArray(); 1385 installClassVarStr=nf.format(contentBytes.length); 1386 byte[] installClassVarBytes=installClassVarStr.getBytes(); 1387 for(int i=0; i<installClassVarBytes.length; i++) { 1388 contentBytes[installClassStopPos+i]=installClassVarBytes[i]; 1389 } 1390 1391 FileOutputStream out=new FileOutputStream(nativeInstallFile); 1393 out.write(contentBytes); 1394 out.close(); 1395 return installClassOffset; 1396 } 1397 1398 private void appendArchive(File instClass) throws IOException 1399 { 1400 FileOutputStream out=new FileOutputStream(instClass.getName(), true); 1401 FileInputStream zipStream=new FileInputStream("install.jar"); 1402 byte[] buf=new byte[2048]; 1403 int read=zipStream.read(buf); 1404 while(read>0) { 1405 out.write(buf, 0, read); 1406 read=zipStream.read(buf); 1407 } 1408 zipStream.close(); 1409 out.close(); 1410 } 1411 1412 private void copy(File fin, File fout) throws IOException 1413 { 1414 FileOutputStream out=new FileOutputStream(fout); 1415 FileInputStream in=new FileInputStream(fin); 1416 byte[] buf=new byte[2048]; 1417 int read=in.read(buf); 1418 while( read>0 ) { 1419 out.write(buf, 0, read); 1420 read=in.read(buf); 1421 } 1422 in.close(); 1423 out.close(); 1424 } 1425 1426 private void jar(String options, File jarFile, File[] files) throws IOException 1427 { 1428 Process p=null; 1429 Vector argsv=new Vector(); 1430 argsv.add(JDK_HOME+File.separator+"bin"+File.separator+"jar"); 1431 if( options!=null && !options.equals("") ) argsv.add(options); 1432 argsv.add(jarFile.getName()); 1433 for(int i=0; i<files.length; i++) argsv.add(files[i].getName()); 1434 String [] args=new String [argsv.size()]; 1435 for(int i=0; i<args.length; i++) args[i]=(String )argsv.get(i); 1436 try { 1437 p=Runtime.getRuntime().exec(args); 1438 p.waitFor(); 1439 } catch( Exception rte ) { 1440 throw new IOException("Runtime exception: check if you have installed the JDK and run java from the JDK\n"+ 1441 "Exception message: "+rte.getMessage()); 1442 } 1443 printCmdOutput(p, "jar"); 1444 if( p.exitValue()!=0 ) throw new RuntimeException (" abnormal exit"); 1445 } 1446 1447 private void jarsign(String passphrase, File jarFile, String alias) throws IOException 1448 { 1449 Process p=null; 1450 try { 1451 p=Runtime.getRuntime().exec(new String [] 1452 {JDK_HOME+File.separator+"bin"+File.separator+"jarsigner", 1453 "-storepass", 1454 passphrase, 1455 jarFile.getName(), 1456 alias}); 1457 p.waitFor(); 1458 } catch( Exception rte ) { 1459 throw new IOException("Runtime exception: check if you have installed the JDK and run java from the JDK\n"+ 1460 "Exception message: "+rte.getMessage()); 1461 } 1462 printCmdOutput(p, "jarsign"); 1463 if( p.exitValue()!=0 ) throw new RuntimeException (" abnormal exit"); 1464 } 1465 1466 private File compile(String javafile) throws IOException 1467 { 1468 File classFile=null; 1469 Process p=null; 1470 try { 1471 p=Runtime.getRuntime().exec(new String [] 1472 {JDK_HOME+File.separator+"bin"+File.separator+"javac", javafile}); 1473 p.waitFor(); 1474 } catch( Exception rte ) { 1475 throw new IOException("Runtime exception: check if you have installed the JDK and run java from the JDK\n"+ 1476 "Exception message: "+rte.getMessage()); 1477 } 1478 printCmdOutput(p, "javac"); 1479 if( p.exitValue()!=0 ) throw new RuntimeException (" abnormal exit"); 1480 1481 classFile=new File(javafile.substring(0, javafile.lastIndexOf('.'))+".class"); 1482 System.out.println(" "+classFile+" "+classFile.exists()); 1483 return classFile; 1485 } 1486 1487 private void printCmdOutput(Process p, String cmdName) throws IOException 1488 { 1489 BufferedReader psIn=new BufferedReader( 1490 new InputStreamReader(p.getInputStream())); 1491 BufferedReader psErr=new BufferedReader( 1492 new InputStreamReader(p.getErrorStream())); 1493 int n=0; 1494 System.out.println(" --- start "+cmdName+" ---"); 1495 String inLine=psIn.readLine(); 1496 String errLine=psErr.readLine(); 1497 while( (inLine!=null)||(errLine!=null) ) { 1498 if( inLine!=null ) System.out.println(" "+inLine); 1499 if( errLine!=null ) System.err.println(" "+errLine); 1500 inLine=psIn.readLine(); 1501 errLine=psErr.readLine(); 1502 } 1503 psIn.close(); 1504 psErr.close(); 1505 System.out.println(" --- end "+cmdName+" ---"); 1506 } 1507 1508 private File makeJar(String filename, File archive, File license, File readme, byte[] archiveInfos) 1509 throws IOException 1510 { 1511 File jar=new File(filename); 1512 JarOutputStream out = new JarOutputStream(new FileOutputStream(jar)); 1513 1514 copyInternalToJar(out,JAR_FILES_COMMON); 1516 copyInternalToJar(out,JAR_FILES_JNIREGISTRY); 1517 copyInternalToJar(out,JAR_FILES_JNISHORTCUT); 1518 copyInternalToJar(out,JAR_FILES_TEXT_UI); 1520 copyInternalToJar(out,JAR_FILES_ANSI_UI); 1521 1522 if(uiMode_.equals("graphic") == true) 1523 { 1524 copyInternalToJar(out,JAR_FILES_GRAPHIC_UI); 1525 } 1526 1527 if(uiMode_.equals("xtra") == true) 1528 { 1529 copyInternalToJar(out,JAR_FILES_XTRA_UI); 1530 } 1531 1532 addToJar(out, new ByteArrayInputStream(archiveInfos), "com/memoire/vainstall/archive_infos", archiveInfos.length); 1534 1535 addToJar(out, new FileInputStream(archive), "com/memoire/vainstall/archive.zip", archive.length()); 1537 1538 InputStream licenseStream = new FileInputStream(license); 1540 String licenseEncoding = VAProperties.PROPERTIES.getProperty("vainstall.archive.license.encoding"); 1541 if(licenseEncoding == null || licenseEncoding.equals("") == true) 1542 { 1543 licenseEncoding = new InputStreamReader(licenseStream).getEncoding(); 1545 } 1546 InputStreamReader isrLicense = new InputStreamReader(licenseStream, licenseEncoding); 1547 addToJarEncoded(out, isrLicense, "com/memoire/vainstall/license.txt", license.length()); 1548 1549 InputStream readmeStream = new FileInputStream(readme); 1551 String readmeEncoding = VAProperties.PROPERTIES.getProperty("vainstall.archive.readme.encoding"); 1552 if(readmeEncoding == null || readmeEncoding.equals("") == true) 1553 { 1554 readmeEncoding = new InputStreamReader(readmeStream).getEncoding(); 1556 } 1557 InputStreamReader isrReadme = new InputStreamReader(readmeStream, readmeEncoding); 1558 addToJarEncoded(out, isrReadme, "com/memoire/vainstall/readme.txt", readme.length()); 1559 1560 InputStream invaiimage = null; 1562 try 1563 { 1564 invaiimage = new FileInputStream(new File(image_)); 1565 } 1566 catch(Exception exc) 1567 { 1568 image_ = "/"+image_; 1569 invaiimage = getClass().getResourceAsStream(image_); 1570 } 1571 if(invaiimage == null) 1572 { 1573 invaiimage = getClass().getResourceAsStream(IMAGE_KEY); 1574 image_ = "com/memoire/vainstall/resources/banner.gif"; 1575 } 1576 if(invaiimage != null) 1577 { 1578 addToJar(out, invaiimage, IMAGE_KEY, invaiimage.available()); 1580 } 1581 InputStream invailogo = getClass().getResourceAsStream("/"+VAILOGO); 1583 addToJar(out,invailogo,VAILOGO, invailogo.available()); 1584 invailogo.close(); 1585 1586 ByteArrayOutputStream poutstream = new ByteArrayOutputStream(); 1589 installProperties.store(poutstream,VAGlobals.NAME+" "+VAGlobals.VERSION); 1590 ByteArrayInputStream pinstream = new ByteArrayInputStream(poutstream.toByteArray()); 1591 addToJar(out,pinstream,"com/memoire/vainstall/resources/vainstall.properties",poutstream.toByteArray().length); 1592 1593 out.close(); 1594 return jar; 1595 } 1596 1597 1603 private void copyInternalToJar(JarOutputStream out, String [] JAR_FILES) 1604 throws IOException 1605 { 1606 for(int i=0; i<JAR_FILES.length; i++) { 1607 1608 String sourceName = JAR_FILES[i]; 1609 if( sourceName.endsWith(".jar") ) 1610 { 1611 copyJarFilesToJar(out,sourceName); 1612 } 1613 else 1614 { 1615 InputStream is = getClass().getResourceAsStream("/"+sourceName); 1617 addToJar(out, is, sourceName, is.available()); 1618 } 1619 } } 1621 1622 1628 private void copyJarFilesToJar(JarOutputStream out, String jarSourceName) 1629 throws IOException 1630 { 1631 byte[] buffer = new byte[2048]; 1632 1633 InputStream isJar = getClass().getResourceAsStream("/"+jarSourceName); 1634 JarInputStream zin = new JarInputStream(isJar); 1635 1636 JarEntry entry = null; 1637 while((entry = zin.getNextJarEntry()) != null) 1638 { 1639 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 1640 while(true) 1641 { 1642 int read = zin.read(buffer); 1643 if(read == -1)break; 1644 bos.write(buffer, 0, read); 1645 } 1646 ByteArrayInputStream bais = new ByteArrayInputStream(bos.toByteArray()); 1647 addToJar(out, bais, entry.getName(), bos.toByteArray().length); 1648 bos.close(); 1649 zin.closeEntry(); 1650 } zin.close(); 1652 isJar.close(); 1653 } 1654 1655 private void addToJar(JarOutputStream out, InputStream in, String entryName, long length) throws IOException 1656 { 1657 byte[] buf=new byte[2048]; 1658 ZipEntry entry=new ZipEntry(entryName); 1659 CRC32 crc=new CRC32(); 1660 entry.setSize(length); 1661 entry.setCrc(crc.getValue()); 1662 out.putNextEntry(entry); 1663 int read=in.read(buf); 1664 while(read>0) { 1665 crc.update(buf, 0, read); 1666 out.write(buf, 0, read); 1667 read=in.read(buf); 1668 } 1669 entry.setCrc(crc.getValue()); 1670 in.close(); 1672 out.closeEntry(); 1673 } 1674 1675 private void addToJarEncoded(JarOutputStream out, InputStreamReader isr, String entryName, long length) 1676 throws IOException 1677 { 1678 1679 StringBuffer buffer = new StringBuffer (); 1680 1681 Reader reader = new BufferedReader(isr); 1682 int ch; 1683 while ((ch = reader.read()) > -1) { 1684 buffer.append((char)ch); 1685 } 1686 reader.close(); 1687 isr.close(); 1688 1689 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 1690 OutputStreamWriter osw = new OutputStreamWriter(baos,"UTF8"); 1691 osw.write(buffer.toString()); 1692 osw.flush(); 1693 1694 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); 1695 1696 addToJar(out,bais,entryName,length); 1697 } 1698 1699 private boolean checkVaiPath(String dir) 1701 { 1702 int index=dir.indexOf(']'); 1703 if( !dir.startsWith("[") ) return true; 1704 if( index<=2 ) return false; 1705 String prefix=dir.substring(1, index).trim(); 1706 System.out.println(dir); 1707 System.out.println(prefix); 1708 if( ("HOME".equals(prefix))|| 1709 ("PROGRAM".equals(prefix)) ) return true; 1710 if( (prefix.length()==2)&& 1711 (prefix.endsWith(":"))&& 1712 (Character.isLetter(prefix.charAt(0))) ) return true; 1713 return false; 1714 } 1715 1716 private String codeLine(byte[] data, int siz) 1717 { 1718 String res=null; 1719 byte[] convert=new byte[2*siz]; 1720 for(int i=0; i<siz; i++) { 1721 convert[2*i ]=(byte)(65+(data[i]&0x0F) ); 1722 convert[2*i+1]=(byte)(65+(data[i]&0xF0)/16); 1723 } 1724 res=new String (convert); 1725 return res; 1726 } 1727 1728} 1729 1730 | Popular Tags |