1 6 package com.memoire.vainstall; 7 8 import java.io.BufferedReader ; 9 import java.io.BufferedWriter ; 10 import java.io.ByteArrayInputStream ; 11 import java.io.ByteArrayOutputStream ; 12 import java.io.File ; 13 import java.io.FileFilter ; 14 import java.io.FileInputStream ; 15 import java.io.FileOutputStream ; 16 import java.io.FileReader ; 17 import java.io.FileWriter ; 18 import java.io.IOException ; 19 import java.io.InputStream ; 20 import java.io.InputStreamReader ; 21 import java.io.LineNumberReader ; 22 import java.io.ObjectOutputStream ; 23 import java.io.OutputStreamWriter ; 24 import java.io.PrintWriter ; 25 import java.io.Reader ; 26 import java.io.UnsupportedEncodingException ; 27 import java.net.URL ; 28 import java.net.URLClassLoader ; 29 import java.text.NumberFormat ; 30 import java.util.Hashtable ; 31 import java.util.Iterator ; 32 import java.util.Locale ; 33 import java.util.Map ; 34 import java.util.Properties ; 35 import java.util.StringTokenizer ; 36 import java.util.Vector ; 37 import java.util.jar.JarEntry ; 38 import java.util.jar.JarInputStream ; 39 import java.util.jar.JarOutputStream ; 40 import java.util.zip.CRC32 ; 41 import java.util.zip.GZIPOutputStream ; 42 import java.util.zip.ZipEntry ; 43 import java.util.zip.ZipOutputStream ; 44 45 49 public class VAArchiver { 50 private static final String JAVA_HOME = System.getProperty("java.home"); 51 52 private static final String [] JAVAC_SEARCH_PATH = new String [] { "../bin", 55 "bin" }; 56 57 private static final String JAVAC = "javac"; 58 59 private static final String JDK_HOME = System.getProperty("java.home") 60 + File.separator + ".."; 61 62 private static String RC_DIR = null; 63 64 private static String VAILOGO = null; 65 66 private static final String [] JAR_FILES_COMMON = new String [] { 67 "com/memoire/vainstall/Language_da_DK.class", 68 "com/memoire/vainstall/Language_de_DE.class", 69 "com/memoire/vainstall/Language_en_UK.class", 70 "com/memoire/vainstall/Language_fr_FR.class", 71 "com/memoire/vainstall/Language_it_IT.class", 72 "com/memoire/vainstall/Language_ja_JP.class", 73 "com/memoire/vainstall/AbstractInstall.class", 74 "com/memoire/vainstall/Setup.class", 75 "com/memoire/vainstall/VAClassLoader.class", 76 "com/memoire/vainstall/SetupFileFilter.class", 77 "com/memoire/vainstall/UpgradeInfo.class", 78 "com/memoire/vainstall/LogInfo.class", 79 "com/memoire/vainstall/Uninstall.class", 80 "com/memoire/vainstall/VAGlobals.class", 81 "com/memoire/vainstall/VAStats.class", 82 "com/memoire/vainstall/VAStep.class", 83 "com/memoire/vainstall/VAStepFactory.class", 84 "com/memoire/vainstall/VAWelcomeStep.class", 85 "com/memoire/vainstall/VAReadmeStep.class", 86 "com/memoire/vainstall/VALanguageStep.class", 87 "com/memoire/vainstall/VALicenseStep.class", 88 "com/memoire/vainstall/VALicenseKeyStep.class", 89 "com/memoire/vainstall/VADirectoryStep.class", 90 "com/memoire/vainstall/VAInstallStep.class", 91 "com/memoire/vainstall/VAUpgradeStep.class", 92 "com/memoire/vainstall/VAShortcutStep.class", 93 "com/memoire/vainstall/VAEndStep.class", 94 "com/memoire/vainstall/VAWizardInterface.class", 95 "com/memoire/vainstall/VALinkDebian.class", 96 "com/memoire/vainstall/VALinkLinux.class", 97 "com/memoire/vainstall/VAShortcutEntry.class", 98 "com/memoire/vainstall/VAConstant.class", 99 "com/memoire/vainstall/VALinkGnome.class", 100 "com/memoire/vainstall/VALinkKDE.class", 101 "com/memoire/vainstall/VALinkWindows.class", 102 "com/memoire/vainstall/VAFile.class", 103 "com/memoire/vainstall/LicenseKeySupport.class", 104 "com/memoire/vainstall/LicenseKeySupport$FieldInfo.class", 105 "com/memoire/vainstall/DefaultLicenseKeySupport.class", 106 "com/memoire/vainstall/TestLicenseKeySupport.class" }; 107 108 private static final String [] JAR_FILES_JNISHORTCUT = new String [] { 109 "JNIWinShortcut.dll", 110 "com/memoire/vainstall/JNIWindowsShortcut.class" }; 111 112 private static final String [] JAR_FILES_JNIREGISTRY = new String [] { 113 "ICE_JNIRegistry.dll", 114 "com/ice/jni/registry/NoSuchKeyException.class", 115 "com/ice/jni/registry/NoSuchValueException.class", 116 "com/ice/jni/registry/RegBinaryValue.class", 117 "com/ice/jni/registry/RegDWordValue.class", 118 "com/ice/jni/registry/RegMultiStringValue.class", 119 "com/ice/jni/registry/RegStringValue.class", 120 "com/ice/jni/registry/Registry.class", 121 "com/ice/jni/registry/RegistryException.class", 122 "com/ice/jni/registry/RegistryKey.class", 123 "com/ice/jni/registry/RegistryValue.class", 124 "com/ice/text/HexNumberFormat.class", 125 "com/ice/util/AWTUtilities.class", 126 "com/ice/util/ClassUtilities.class", "com/ice/util/FileLog.class", 127 "com/ice/util/HTTPUtilities.class", "com/ice/util/HexDump.class", 128 "com/ice/util/StringUtilities.class", 129 "com/ice/util/URLUtilities.class", 130 "com/ice/util/UserProperties.class" }; 131 132 private static final String [] JAR_FILES_TEXT_UI = new String [] { 133 "com/memoire/vainstall/tui/Language_da_DK.class", 134 "com/memoire/vainstall/tui/Language_de_DE.class", 135 "com/memoire/vainstall/tui/Language_en_UK.class", 136 "com/memoire/vainstall/tui/Language_fr_FR.class", 137 "com/memoire/vainstall/tui/Language_it_IT.class", 138 "com/memoire/vainstall/tui/Language_ja_JP.class", 139 "com/memoire/vainstall/tui/NullOutputStream.class", 140 "com/memoire/vainstall/tui/TuiDefaultStep.class", 141 "com/memoire/vainstall/tui/TuiDirectoryStep.class", 142 "com/memoire/vainstall/tui/TuiInstallStep.class", 143 "com/memoire/vainstall/tui/TuiLanguageStep.class", 144 "com/memoire/vainstall/tui/TuiLicenseStep.class", 145 "com/memoire/vainstall/tui/TuiReadmeStep.class", 146 "com/memoire/vainstall/tui/TuiShortcutStep.class", 147 "com/memoire/vainstall/tui/TuiWelcomeStep.class", 148 "com/memoire/vainstall/tui/TuiWizard.class", 149 "com/memoire/vainstall/tui/VATextUI.class", 150 "com/memoire/vainstall/tui/TuiUpgradeStep.class", 151 "com/memoire/vainstall/tui/TuiEndStep.class" }; 152 153 private static final String [] JAR_FILES_ANSI_UI = new String [] { "com/memoire/vainstall/aui/VAAnsiUI.class", }; 158 159 private static final String [] JAR_FILES_UNATTENDED_UI = new String [] { 160 "com/memoire/vainstall/uui/VAUnattendedUI.class", 161 "com/memoire/vainstall/uui/UuiDefaultStep.class", 162 "com/memoire/vainstall/uui/UuiDirectoryStep.class", 163 "com/memoire/vainstall/uui/UuiEndStep.class", 164 "com/memoire/vainstall/uui/UuiInstallStep.class", 165 "com/memoire/vainstall/uui/UuiLanguageStep.class", 166 "com/memoire/vainstall/uui/UuiLicenseStep.class", 167 "com/memoire/vainstall/uui/UuiReadmeStep.class", 168 "com/memoire/vainstall/uui/UuiShortcutStep.class", 169 "com/memoire/vainstall/uui/UuiUpgradeStep.class", 170 "com/memoire/vainstall/uui/UuiWelcomeStep.class", 171 "com/memoire/vainstall/uui/UuiWizard.class" }; 172 173 private static final String [] JAR_FILES_GRAPHIC_UI = new String [] { 174 "com/memoire/vainstall/gui/Language_da_DK.class", 175 "com/memoire/vainstall/gui/Language_de_DE.class", 176 "com/memoire/vainstall/gui/Language_en_UK.class", 177 "com/memoire/vainstall/gui/Language_fr_FR.class", 178 "com/memoire/vainstall/gui/Language_it_IT.class", 179 "com/memoire/vainstall/gui/Language_ja_JP.class", 180 "com/memoire/vainstall/gui/VABlueScreen.class", 181 "com/memoire/vainstall/gui/VABlueScreen$1.class", 182 "com/memoire/vainstall/gui/VAGraphicUI.class", 183 "com/memoire/vainstall/gui/VAWizard.class", 184 "com/memoire/vainstall/gui/VAWizard$1.class", 185 "com/memoire/vainstall/gui/VAPanel.class", 186 "com/memoire/vainstall/gui/VAWelcomePanel.class", 187 "com/memoire/vainstall/gui/VAImagePanel.class", 188 "com/memoire/vainstall/gui/VAInstallPanel.class", 189 "com/memoire/vainstall/gui/VALanguagePanel.class", 190 "com/memoire/vainstall/gui/VALicensePanel.class", 191 "com/memoire/vainstall/gui/VALicenseKeyPanel.class", 192 "com/memoire/vainstall/gui/VALicenseKeyPanel$1.class", 193 "com/memoire/vainstall/gui/VAReadmePanel.class", 194 "com/memoire/vainstall/gui/VADirectoryPanel.class", 195 "com/memoire/vainstall/gui/VADirectoryPanel$1.class", 196 "com/memoire/vainstall/gui/VAUpgradePanel.class", 197 "com/memoire/vainstall/gui/VAShortcutPanel.class", 198 "com/memoire/vainstall/gui/VAEndPanel.class", }; 199 200 private static final String [] JAR_FILES_XTRA_UI = new String [] { 201 "com/memoire/vainstall/xui/Language_da_DK.class", 202 "com/memoire/vainstall/xui/Language_de_DE.class", 203 "com/memoire/vainstall/xui/Language_en_UK.class", 204 "com/memoire/vainstall/xui/Language_fr_FR.class", 205 "com/memoire/vainstall/xui/Language_it_IT.class", 206 "com/memoire/vainstall/xui/Language_ja_JP.class", 207 "com/memoire/vainstall/xui/XuiBlueScreen.class", 208 "com/memoire/vainstall/xui/XuiWizard.class", 209 "com/memoire/vainstall/xui/XuiAbstractPanel.class", 210 "com/memoire/vainstall/xui/XuiPanel.class", 211 "com/memoire/vainstall/xui/XuiImagePanel.class", 212 "com/memoire/vainstall/xui/XuiTitle.class", 213 "com/memoire/vainstall/xui/XuiButton.class", 214 "com/memoire/vainstall/xui/XuiButtonBorder.class", 215 "com/memoire/vainstall/xui/XuiLabel.class", 216 "com/memoire/vainstall/xui/XuiList.class", 217 "com/memoire/vainstall/xui/XuiRadioButton.class", 218 "com/memoire/vainstall/xui/XuiOptionPane.class", 219 "com/memoire/vainstall/xui/XuiWelcomePanel.class", 220 "com/memoire/vainstall/xui/XuiReadmePanel.class", 221 "com/memoire/vainstall/xui/XuiLicensePanel.class", 222 "com/memoire/vainstall/xui/XuiLicenseKeyPanel.class", 223 "com/memoire/vainstall/xui/XuiLicenseKeyPanel$1.class", 224 "com/memoire/vainstall/xui/XuiInstallPanel.class", 225 "com/memoire/vainstall/xui/XuiShortcutPanel.class", 226 "com/memoire/vainstall/xui/XuiUpgradePanel.class", 227 "com/memoire/vainstall/xui/XuiLanguagePanel.class", 228 "com/memoire/vainstall/xui/XuiEndPanel.class", 229 "com/memoire/vainstall/xui/XuiDirectoryPanel$1.class", 230 "com/memoire/vainstall/xui/XuiDirectoryPanel.class", 231 "com/memoire/vainstall/xui/VAXtraUI.class", }; 232 233 private static final String [] JAR_FILES_CUSTOM_PRE_POST = new String [] { 236 "com/memoire/vainstall/AbstractCustomPrePost.class", 237 "com/memoire/vainstall/InputStreamToDetails.class", }; 238 239 private File filelist_; 240 241 private String destPath_; 242 243 private String archMethod_; 244 245 private long archOffset_; 246 247 private long installClassOffset_; 248 249 private long installClassSize_; 250 251 private long jarSize_; 252 253 private String licenseKeySupportClassName_, encodeKey_; 254 255 private LicenseKeySupport licenseKeySupport_; 256 257 private String uiMode_; 258 259 private String uiBluescreen_; 260 261 private String uiBluescreenColor_; 262 263 private String image_; 264 265 private String appName_, appVersion_; 266 267 private String linkSectionName_, linkSectionIcon_, linkEntryName_, 268 linkEntryIcon_; 269 270 private String instClassName_; 271 272 private boolean createUninstallShortcut_; 273 274 private String [] targets_; 275 276 private String currentTarget_; 277 278 private String jarAlias_, jarPassphrase_, jarCodebase_, jarVendor_, 279 jarHomepage_; 280 281 private File license_; 282 283 private File readme_; 284 285 private ByteArrayOutputStream archiveInfos_; 286 287 private int archivecount_; 288 289 private Vector archiveEntryList_; 290 291 private String additionalFiles_; 292 293 private Properties installProperties = new Properties (); 295 296 private String customPrePostClassName_; 298 299 private String customPrePostJarfileName_; 300 301 private static String getJavaBinPath() { 302 String path = null; 303 for (int i = 0; i < JAVAC_SEARCH_PATH.length && path == null; i++) { 304 String aPath; 305 aPath = JAVA_HOME + File.separator + JAVAC_SEARCH_PATH[i]; 306 if (new File (aPath).exists()) { 307 path = aPath; 308 } 309 } 310 return path; 311 } 312 313 public VAArchiver() { 314 filelist_ = null; 315 destPath_ = null; 316 archMethod_ = null; 317 installClassOffset_ = -10987654321L; 318 installClassSize_ = -1234543210L; 319 archOffset_ = -1234567890L; 320 uiMode_ = null; 321 uiBluescreenColor_ = null; 322 uiBluescreen_ = null; 323 appName_ = appVersion_ = null; 324 linkSectionName_ = linkSectionIcon_ = linkEntryName_ = linkEntryIcon_ = null; 325 instClassName_ = null; 326 targets_ = new String [0]; 327 jarAlias_ = jarPassphrase_ = jarCodebase_ = jarHomepage_ = jarVendor_ = null; 328 license_ = null; 329 readme_ = null; 330 archiveInfos_ = null; 331 archivecount_ = 0; 332 archiveEntryList_ = new Vector (); 333 licenseKeySupportClassName_ = "com.memoire.vainstall.DefaultLicenseKeySupport"; 334 } 335 336 public void start() { 337 if (!processProperties()) 338 return; 339 try { 340 System.out.println(); 341 System.out.println(VAGlobals.i18n("VAArchiver_CompressingFiles")); 342 archiveInfos_ = new ByteArrayOutputStream (); 343 File zip = makeArchive("archive.zip"); 344 zip.deleteOnExit(); 345 System.out.println(); 346 System.out.println(VAGlobals.i18n("VAArchiver_CreatingJarFiles")); 347 archiveInfos_.flush(); 348 byte[] infosbytes = archiveInfos_.toByteArray(); 349 File jar = makeJar("install.jar", zip, license_, readme_, 350 infosbytes); 351 jarSize_ = jar.length(); 352 archiveInfos_.close(); 353 jar.deleteOnExit(); 354 File installJavaFile = new File (instClassName_ + ".java"); 355 installJavaFile.deleteOnExit(); 356 File instClass = null; 357 boolean deleteInstallClass = true; 358 for (int i = 0; i < targets_.length; i++) { 359 System.out.println(); 360 System.out.println(targets_[i] 361 + VAGlobals.i18n("VAArchiver_Target")); 362 currentTarget_ = targets_[i]; 363 System.out.println(VAGlobals 364 .i18n("VAArchiver_GeneratingInstallClass")); 365 generateInstallCode(installJavaFile, 370 "com/memoire/vainstall/resources/Install.vaitpl", 371 "com/memoire/vainstall/VAClassLoader.class"); 372 System.out.println(VAGlobals 373 .i18n("VAArchiver_CompilingInstallClass")); 374 instClass = compile(installJavaFile.getName()); 375 installClassSize_ = instClass.length(); 376 VAGlobals 377 .printDebug(" InstallClass size=" + installClassSize_); 378 if ("jar".equals(targets_[i])) { 379 File jarTarget = new File (instClassName_ + ".jar"); 380 File mfFile = new File (instClassName_ + ".mf"); 381 mfFile.deleteOnExit(); 382 System.out.println(VAGlobals 383 .i18n("VAArchiver_CreatingManifestFile")); 384 generateManifestFile(mfFile); 385 System.out.println(VAGlobals 387 .i18n("VAArchiver_UpdatingJarFile")); 388 copy(jar, jarTarget); 389 jar("uvfm", jarTarget, new File [] { mfFile, instClass }); 390 if (jarAlias_ != null && !"".equals(jarAlias_.trim()) 392 && jarPassphrase_ != null 393 && !"".equals(jarPassphrase_.trim())) { 394 System.out.println(VAGlobals 395 .i18n("VAArchiver_SigningJarFile")); 396 jarsign(jarPassphrase_, jarTarget, jarAlias_); 397 } 398 } else if ("jnlp".equals(targets_[i])) { 399 File jnlpFile = new File (instClassName_ + ".jnlp"); 400 System.out.println(VAGlobals 401 .i18n("VAArchiver_CreatingJnlpFile")); 402 generateJnlpFile(jnlpFile); 403 } else if ("java".equals(targets_[i])) { 404 installClassOffset_ = -10987654321L; 405 deleteInstallClass = false; 406 if (archMethod_.equals("append")) { 407 archOffset_ = instClass.length(); 408 VAGlobals.printDebug(VAGlobals 409 .i18n("VAArchiver_ArchiveOffset") 410 + archOffset_); 411 generateInstallCode( 412 installJavaFile, 413 "com/memoire/vainstall/resources/Install.vaitpl", 414 "com/memoire/vainstall/VAClassLoader.class"); 415 System.out.println(VAGlobals 416 .i18n("VAArchiver_CompilingInstallClass")); 417 compile(installJavaFile.getName()); 418 System.out.println(VAGlobals 419 .i18n("VAArchiver_AppendingArchive")); 420 appendArchive(instClass); 421 } 422 } else if ("unix".equals(targets_[i])) { 423 File unixShellFile = new File (instClassName_ + ".sh"); 424 installClassOffset_ = generateUnixInstallShell( 425 unixShellFile, 426 "com/memoire/vainstall/resources/Install-sh.vaitpl", 427 instClass); 428 VAGlobals.printDebug(VAGlobals 429 .i18n("VAArchiver_InstallClassOffset") 430 + installClassOffset_); 431 if (archMethod_.equals("append")) { 432 archOffset_ = unixShellFile.length(); 433 VAGlobals.printDebug(VAGlobals 434 .i18n("VAArchiver_ArchiveOffset") 435 + archOffset_); 436 generateInstallCode( 437 installJavaFile, 438 "com/memoire/vainstall/resources/Install.vaitpl", 439 "com/memoire/vainstall/VAClassLoader.class"); 440 System.out.println(VAGlobals 441 .i18n("VAArchiver_CompilingInstallClass")); 442 compile(installJavaFile.getName()); 443 generateUnixInstallShell( 444 unixShellFile, 445 "com/memoire/vainstall/resources/Install-sh.vaitpl", 446 instClass); 447 System.out.println(VAGlobals 448 .i18n("VAArchiver_AppendingArchive")); 449 appendArchive(unixShellFile); 450 } 451 } else if (("win95".equals(targets_[i])) 452 || ("linux-i386".equals(targets_[i]))) { 453 File nativeExeFile = null; 454 if ("win95".equals(targets_[i])) 455 nativeExeFile = new File (instClassName_ + ".exe"); 456 else if ("linux-i386".equals(targets_[i])) 457 nativeExeFile = new File (instClassName_ + ".lin"); 458 installClassOffset_ = generateNativeInstallExe( 459 nativeExeFile, 460 "com/memoire/vainstall/resources/Install-" 461 + targets_[i] + "-exe.vaitpl", instClass); 462 VAGlobals.printDebug(VAGlobals 463 .i18n("VAArchiver_InstallClassOffset") 464 + installClassOffset_); 465 if (archMethod_.equals("append")) { 466 archOffset_ = nativeExeFile.length(); 467 VAGlobals.printDebug(VAGlobals 468 .i18n("VAArchiver_ArchiveOffset") 469 + archOffset_); 470 generateInstallCode( 471 installJavaFile, 472 "com/memoire/vainstall/resources/Install.vaitpl", 473 "com/memoire/vainstall/VAClassLoader.class"); 474 System.out.println(VAGlobals 475 .i18n("VAArchiver_CompilingInstallClass")); 476 compile(installJavaFile.getName()); 477 generateNativeInstallExe(nativeExeFile, 478 "com/memoire/vainstall/resources/Install-" 479 + targets_[i] + "-exe.vaitpl", 480 instClass); 481 System.out.println(VAGlobals 482 .i18n("VAArchiver_AppendingArchive")); 483 appendArchive(nativeExeFile); 484 System.out.println("win95 end"); 485 } 486 } 487 } 488 if (instClass != null && deleteInstallClass) 489 instClass.delete(); 490 } catch (IOException e) { 491 e.printStackTrace(); 492 } 493 } 494 495 File lnfFile_; 496 497 private boolean processProperties() { 498 String tempString; 499 RC_DIR = "com/memoire/vainstall/resources"; 500 VAILOGO = RC_DIR + "/vailogo.gif"; 501 VAGlobals.setLanguage("default"); 503 String tmp = VAProperties.PROPERTIES 504 .getProperty("vainstall.destination.language"); 505 if (tmp != null && !"".equals(tmp)) { 506 installProperties.put("vainstall.destination.language", tmp); 507 } 508 String useFullPath = VAProperties.PROPERTIES 510 .getProperty("vainstall.script.java.fullpath"); 511 if (useFullPath != null && "true".equalsIgnoreCase(useFullPath)) { 512 installProperties.put("vainstall.script.java.fullpath", "true"); 513 } 514 String minJavaVersion = VAProperties.PROPERTIES.getProperty( 516 "vainstall.java.version.min", null); 517 String maxJavaVersion = VAProperties.PROPERTIES.getProperty( 518 "vainstall.java.version.max", null); 519 String javaVendor = VAProperties.PROPERTIES.getProperty( 521 "vainstall.java.vendor", null); 522 if (minJavaVersion != null && minJavaVersion.trim().length() > 0) { 523 installProperties.put("vainstall.java.version.min", minJavaVersion); 524 } 525 if (maxJavaVersion != null && maxJavaVersion.trim().length() > 0) { 526 installProperties.put("vainstall.java.version.max", maxJavaVersion); 527 } 528 if(javaVendor!=null && javaVendor.trim().length()>0){ 529 installProperties.put("vainstall.java.vendor", javaVendor); 530 } 531 String key = "vainstall.java.download.url"; 532 String val = VAProperties.PROPERTIES.getProperty(key, null); 533 if (val != null) 534 installProperties.put(key, val); 535 536 String shortcutsInInstallDir = VAProperties.PROPERTIES 537 .getProperty("vainstall.shortcut.in.installdir"); 538 if (shortcutsInInstallDir != null 539 && "true".equalsIgnoreCase(shortcutsInInstallDir)) { 540 installProperties.put("vainstall.shortcut.in.installdir", "true"); 541 } 542 tmp = VAProperties.PROPERTIES.getProperty("vainstall.archive.filelist"); 543 if (tmp == null || "".equals(tmp)) { 544 System.err.println("vainstall.archive.filelist null"); 545 return false; 546 } 547 filelist_ = new File (tmp); 548 if ((!filelist_.exists()) || (!filelist_.canRead())) { 549 System.err.println(VAGlobals.i18n("VAArchiver_CanNotRead") 550 + filelist_); 551 return false; 552 } 553 destPath_ = VAProperties.PROPERTIES 554 .getProperty("vainstall.destination.defaultPath"); 555 if (destPath_ == null || "".equals(destPath_)) { 556 System.err.println("vainstall.destination.defaultPath null"); 557 return false; 558 } else { 559 if (!checkVaiPath(destPath_)) { 560 System.err.println("vainstall.destination.defaultPath" 561 + VAGlobals.i18n("VAArchiver_HasIncorrectFormat")); 562 return false; 563 } 564 } 565 tmp = VAProperties.PROPERTIES 566 .getProperty("vainstall.destination.installMode"); 567 if (("update".equals(tmp))) { 568 destPath_ = "[UPDATE]"; 569 } else if (("module".equals(tmp))) { 570 destPath_ = "[MODULE]"; 571 } else if (!"install".equals(tmp)) { 572 System.err.println(VAGlobals.i18n("VAArchiver_NoValidInstallmode") 573 + ":" + VAGlobals.i18n("VAArchiver_DefaultingTo") 574 + "install"); 575 } 576 tmp = VAProperties.PROPERTIES 577 .getProperty("vainstall.destination.targets"); 578 if (tmp == null || "".equals(tmp)) { 579 System.err.println(VAGlobals.i18n("VAArchiver_NoTargetSpecified") 580 + " (vainstall.destination.targets)"); 581 return false; 582 } 583 StringTokenizer tok = new StringTokenizer (tmp, ","); 584 Vector v = new Vector (); 585 while (tok.hasMoreTokens()) { 586 String t = tok.nextToken().trim().toLowerCase(); 587 if ((!"java".equals(t)) && (!"jar".equals(t)) 588 && (!"jnlp".equals(t)) && (!"unix".equals(t)) 589 && (!"win95".equals(t)) && (!"linux-i386".equals(t))) { 590 System.err.println(VAGlobals.i18n("VAArchiver_UnknownTarget") 591 + t); 592 return false; 593 } 594 if (!v.contains(t)) 595 v.add(t); 596 } 597 if (v.contains("jnlp") && !v.contains("jar")) 599 v.add("jar"); 600 targets_ = new String [v.size()]; 601 int i = 0; 604 if (v.contains("jar")) 605 targets_[i++] = "jar"; 606 if (v.contains("jnlp")) 607 targets_[i++] = "jnlp"; 608 if (v.contains("unix")) 609 targets_[i++] = "unix"; 610 if (v.contains("linux-i386")) 611 targets_[i++] = "linux-i386"; 612 if (v.contains("win95")) 613 targets_[i++] = "win95"; 614 if (v.contains("java")) 615 targets_[i++] = "java"; 616 if (v.contains("jar")) { 617 jarAlias_ = VAProperties.PROPERTIES 618 .getProperty("vainstall.jarsigner.alias"); 619 jarPassphrase_ = VAProperties.PROPERTIES 620 .getProperty("vainstall.jarsigner.passphrase"); 621 } 622 if (v.contains("jnlp")) { 623 jarCodebase_ = VAProperties.PROPERTIES 624 .getProperty("vainstall.jnlp.codebase"); 625 if (jarCodebase_ == null || "".equals(jarCodebase_)) { 626 System.err.println("vainstall.jnlp.codebase null"); 627 return false; 628 } 629 jarHomepage_ = VAProperties.PROPERTIES 630 .getProperty("vainstall.jnlp.homepage"); 631 if (jarHomepage_ == null || "".equals(jarHomepage_)) { 632 System.err.println("vainstall.jnlp.homepage null"); 633 return false; 634 } 635 jarVendor_ = VAProperties.PROPERTIES 636 .getProperty("vainstall.jnlp.vendor"); 637 if (jarVendor_ == null || "".equals(jarVendor_)) { 638 System.err.println("vainstall.jnlp.vendor null"); 639 return false; 640 } 641 } 642 archMethod_ = VAProperties.PROPERTIES 643 .getProperty("vainstall.archive.archivingMethod"); 644 if (archMethod_ == null || "".equals(archMethod_)) { 645 archMethod_ = "append"; 646 } 647 uiMode_ = VAProperties.PROPERTIES 648 .getProperty("vainstall.destination.ui"); 649 if (uiMode_ == null || "".equals(uiMode_)) { 650 uiMode_ = "graphic"; 651 } 652 if ("graphic".equals(uiMode_)) { 654 String lnfClass = VAProperties.PROPERTIES 655 .getProperty("vainstall.lnf.class"); 656 if (lnfClass != null) { 657 installProperties.put("vainstall.lnf.class", lnfClass); 658 String lnfFileName = VAProperties.PROPERTIES 659 .getProperty("vainstall.lnf.jar"); 660 if (lnfFileName != null) { 661 File jarFile = new File (lnfFileName); 662 if (jarFile.exists()) { 663 lnfFile_ = jarFile; 665 installProperties.put("vainstall.lnf.jar", jarFile 666 .getName()); 667 668 } else { 669 System.err.println("lnf jar File does NOT exist " 670 + jarFile.getAbsolutePath()); 671 } 672 } 673 } 674 } 675 676 uiBluescreen_ = VAProperties.PROPERTIES 677 .getProperty("vainstall.destination.ui.bluescreen"); 678 if (uiBluescreen_ == null || "".equals(uiBluescreen_)) { 679 uiBluescreen_ = "yes"; 680 } 681 uiBluescreenColor_ = VAProperties.PROPERTIES 682 .getProperty("vainstall.destination.ui.bluescreen.colour"); 683 if ((uiBluescreenColor_ != null) && (!"".equals(uiBluescreenColor_))) { 684 try { 685 Integer.parseInt(uiBluescreenColor_, 16); 686 } catch (NumberFormatException nfe) { 687 System.err.println("vainstall.destination.ui.bluescreen.colour" 688 + VAGlobals.i18n("VAArchiver_HasIncorrectFormat")); 689 return false; 690 } 691 } 692 tmp = VAProperties.PROPERTIES 693 .getProperty("vainstall.destination.ui.image"); 694 if ((tmp == null) || (tmp.equals(""))) { 695 System.err.println("vainstall.destination.ui.image null:" 696 + VAGlobals.i18n("VAArchiver_WillUseDefaultImage")); 697 image_ = RC_DIR + "/banner.gif"; 700 } else { 701 image_ = tmp; 702 File img = new File (image_); 703 if ((!img.exists()) || (!img.canRead())) { 704 System.err.println(VAGlobals.i18n("VAArchiver_CanNotRead") 705 + image_ + ":" 706 + VAGlobals.i18n("VAArchiver_WillUseDefaultImage")); 707 image_ = RC_DIR + "/banner.gif"; 708 } 709 } 710 appName_ = VAProperties.PROPERTIES 711 .getProperty("vainstall.destination.appName"); 712 if (appName_ == null || "".equals(appName_)) { 713 System.err.println("vainstall.destination.appName null"); 714 return false; 715 } 716 appVersion_ = VAProperties.PROPERTIES 717 .getProperty("vainstall.destination.appVersion"); 718 if (appVersion_ == null || "".equals(appVersion_)) { 719 System.out 720 .println("vainstall.destination.appVersion null, assuming it is an unversioned plugin"); 721 } 723 linkSectionName_ = VAProperties.PROPERTIES 724 .getProperty("vainstall.destination.linkSectionName"); 725 if (linkSectionName_ == null || "".equals(linkSectionName_)) { 726 System.err.println("vainstall.destination.linkSectionName null:" 727 + VAGlobals.i18n("VAArchiver_DefaultingTo") 728 + "\"Applications\""); 729 linkSectionName_ = "Applications"; 730 } 731 linkSectionIcon_ = VAProperties.PROPERTIES 732 .getProperty("vainstall.destination.linkSectionIcon"); 733 if ((linkSectionIcon_ == null) || "".equals(linkSectionIcon_)) { 734 System.err.println("vainstall.destination.linkSectionIcon null"); 735 linkSectionIcon_ = ""; 736 } 737 linkEntryName_ = VAProperties.PROPERTIES 738 .getProperty("vainstall.destination.linkEntryName"); 739 if (linkEntryName_ == null || "".equals(linkEntryName_)) { 740 System.err.println("vainstall.destination.linkEntryName null:" 741 + VAGlobals.i18n("VAArchiver_DefaultingTo") + "\"" 742 + appName_ + "\""); 743 linkEntryName_ = appName_; 744 } 745 linkEntryIcon_ = VAProperties.PROPERTIES 746 .getProperty("vainstall.destination.linkEntryIcon"); 747 if ((linkEntryIcon_ == null) || "".equals(linkEntryIcon_)) { 748 System.err.println("vainstall.destination.linkEntryIcon null"); 749 linkEntryIcon_ = ""; 750 } 751 tempString = VAProperties.PROPERTIES 752 .getProperty("vainstall.destination.createUninstallShortcut"); 753 if (tempString != null && tempString.equals("yes")) 754 createUninstallShortcut_ = true; 755 else 756 createUninstallShortcut_ = false; 757 instClassName_ = VAProperties.PROPERTIES 758 .getProperty("vainstall.archive.installClassName"); 759 if (instClassName_ == null || "".equals(instClassName_)) { 760 instClassName_ = "Install_" + appName_; 761 } 762 tmp = VAProperties.PROPERTIES.getProperty("vainstall.archive.license"); 763 if (tmp == null || "".equals(tmp)) { 764 System.err.println("vainstall.archive.license null"); 765 return false; 766 } 767 license_ = new File (tmp); 768 if ((!license_.exists()) || (!license_.canRead())) { 769 System.err.println(VAGlobals.i18n("VAArchiver_CanNotRead") 770 + license_); 771 return false; 772 } 773 try { 774 InputStream licenseStream = new FileInputStream (license_); 775 String licenseEncoding = VAProperties.PROPERTIES 776 .getProperty("vainstall.archive.license.encoding"); 777 if (licenseEncoding != null && licenseEncoding.equals("") == false) { 778 try { 779 InputStreamReader isrLicense = new InputStreamReader ( 780 licenseStream, licenseEncoding); 781 } catch (UnsupportedEncodingException exc) { 782 System.err.println("Unsuported encoding for license!"); 783 return false; 784 } 785 } 786 } catch (Exception exc) { 787 System.err.println("Problems reading license file!"); 788 return false; 789 } 790 tmp = VAProperties.PROPERTIES 791 .getProperty("vainstall.license.key.support"); 792 if (tmp != null && !"".equals(tmp)) { 793 licenseKeySupportClassName_ = tmp; 794 } 795 encodeKey_ = VAProperties.PROPERTIES 796 .getProperty("vainstall.license.key.support.encode.key"); 797 additionalFiles_ = VAProperties.PROPERTIES 798 .getProperty("vainstall.additional.files"); 799 Class cls = null; 800 try { 801 cls = Class.forName(licenseKeySupportClassName_); 802 } catch (Exception ex) { 803 if ((cls == null) && (additionalFiles_ != null)) { 804 StringTokenizer fmi = new StringTokenizer (additionalFiles_, ","); 805 while (fmi.hasMoreTokens()) { 806 StringTokenizer fm = new StringTokenizer (fmi.nextToken(), 807 "!"); 808 String classFound = fm.nextToken(); 809 if ((classFound != null) 810 && (classFound.indexOf(licenseKeySupportClassName_) > -1)) { 811 try { 812 URLClassLoader urlcl = new URLClassLoader ( 813 new URL [] { new File (classFound) 814 .getParentFile().toURL() }); 815 cls = urlcl.loadClass(licenseKeySupportClassName_); 816 } catch (Exception ex2) { 817 System.out 818 .println("License key support could not be initialized with specific URLCLassLoader" 819 + ex2); 820 } 821 break; 822 } 823 } 824 } 825 } 826 if (cls == null) { 827 throw new RuntimeException ( 828 "License key support could not be initialized: "); 829 } 830 try { 831 System.out.println(cls.getName()); 832 licenseKeySupport_ = (LicenseKeySupport) cls.newInstance(); 833 } catch (Exception ex) { 834 System.err.println("LicenseKeySupport can't be instantiated" + ex); 835 } 836 tmp = VAProperties.PROPERTIES.getProperty("vainstall.archive.readme"); 837 if (tmp == null || "".equals(tmp)) { 838 System.err.println("vainstall.archive.readme null"); 839 return false; 840 } 841 readme_ = new File (tmp); 842 if ((!readme_.exists()) || (!readme_.canRead())) { 843 System.err.println(VAGlobals.i18n("VAArchiver_CanNotRead") 844 + readme_); 845 return false; 846 } 847 try { 848 InputStream readmeStream = new FileInputStream (readme_); 849 String readmeEncoding = VAProperties.PROPERTIES 850 .getProperty("vainstall.archive.readme.encoding"); 851 if (readmeEncoding != null && readmeEncoding.equals("") == false) { 852 try { 853 InputStreamReader isrReadme = new InputStreamReader ( 854 readmeStream, readmeEncoding); 855 } catch (UnsupportedEncodingException exc) { 856 System.err.println("Unsupported encoding for readme!"); 857 return false; 858 } 859 } 860 } catch (Exception exc) { 861 System.err.println("Problems reading readme file!"); 862 return false; 863 } 864 customPrePostClassName_ = VAProperties.PROPERTIES 866 .getProperty("vainstall.install.customprepost.className"); 867 if (customPrePostClassName_ == null) { 868 customPrePostClassName_ = ""; 869 } else if (!"com.memoire.vainstall.AbstractCustomPrePost" 870 .equals(customPrePostClassName_)) { 871 customPrePostJarfileName_ = VAProperties.PROPERTIES 872 .getProperty("vainstall.install.customprepost.jarFileName"); 873 if (customPrePostJarfileName_ == null 874 || "".equals(customPrePostJarfileName_)) { 875 System.err 876 .println("vainstall.install.customprepost.jarFileName null"); 877 return false; 878 } 879 } 880 installProperties.put("vainstall.install.customprepost.className", 881 customPrePostClassName_); 882 return true; 883 } 884 885 private File makeArchive(String filename) throws IOException { 886 LineNumberReader files = new LineNumberReader (new FileReader (filelist_)); 887 String line = files.readLine(); 888 if (line == null) { 889 files.close(); 890 throw new IOException (VAGlobals.i18n("VAArchiver_EmptyFilelist")); 891 } 892 File zip = new File (filename); 893 File parent = zip.getParentFile(); 894 if ((parent != null) && (!parent.canWrite())) 895 throw new IOException (zip + VAGlobals.i18n("VAArchiver_NotWritten")); 896 ZipOutputStream stream = new ZipOutputStream (new GZIPOutputStream ( 897 licenseKeySupport_.encodeStream(new FileOutputStream (zip), 898 encodeKey_))); 899 stream.setLevel(0); 900 Vector archiveExeList = new Vector (); 901 FileNameGroup fileNameGroup = null; 902 ObjectOutputStream infos = new ObjectOutputStream (archiveInfos_); 903 Vector scripts = new Vector (); 904 while (line != null) { 905 if ((!line.trim().equals("")) && (!line.trim().startsWith("#"))) { 906 if (line.trim().startsWith("{")) { 907 String script = addScript(files, scripts); 908 if (script != null) 909 archiveExeList.add("[SCRIPT]" + script); 910 line = files.readLine(); 911 continue; 912 } 913 fileNameGroup = new FileNameGroup(line); 914 File file = new File (convertToLocalPath(fileNameGroup 915 .getOrigin())); 916 String entryName = fileNameGroup.getDestination(); 917 if (!checkVaiPath(entryName)) 918 throw new IOException (VAGlobals 919 .i18n("VAArchiver_InvalidPathInFilelist") 920 + files.getLineNumber() + "): " + entryName); 921 if (fileNameGroup.isExecutable()) { 922 archiveExeList.add(entryName); 923 } 924 FileFilter filter = null; 925 try { 926 filter = fileNameGroup.getFileFilter(); 927 } catch (IllegalArgumentException iae) { 928 throw new IOException (VAGlobals 929 .i18n("VAArchiver_InFilelist") 930 + files.getLineNumber() + "): " + iae.getMessage()); 931 } 932 addToArchive(stream, file, filter, entryName, fileNameGroup 933 .isRecursive() ? Integer.MAX_VALUE : 1); 934 } 935 line = files.readLine(); 936 } 937 stream.close(); 938 files.close(); 939 infos.writeInt(archivecount_); 940 infos.writeObject(scripts); 941 infos.writeObject(archiveExeList); 942 infos.flush(); 943 return zip; 944 } 945 946 private String addScript(LineNumberReader files, Vector scripts) 947 throws IOException { 948 String destName = null; 949 int blocLineNbr = files.getLineNumber(); 950 String line = files.readLine(); 951 String cmd = null; 952 Hashtable keywords = new Hashtable (); 953 if (line != null) 954 cmd = line.trim(); 955 System.out.println(" script: " + cmd); 956 line = files.readLine(); 957 while ((line != null) && (!line.trim().equals("}"))) { 958 line = line.trim(); 959 int ind = line.indexOf('='); 960 if ((ind > 0) && ((ind + 1) < line.length())) { 961 keywords.put(line.substring(0, ind), line.substring(ind + 1)); 962 } 963 line = files.readLine(); 964 } 965 if ((cmd == null) || (line == null)) 966 throw new IOException ("Unterminated script bloc : line " 967 + blocLineNbr); 968 if (cmd.equals("JavaLauncher")) { 973 String k = (String ) keywords.get("Class"); 974 if (k == null) 975 throw new IOException ("Invalid script bloc : line " 976 + blocLineNbr + " (no Class)"); 977 else 978 System.out.println(" Class=" + k); 979 980 } else if (cmd.equals("JarLauncher")) { 981 String k = (String ) keywords.get("Jar"); 982 if (k != null) { 983 System.out.println(" Jar=" + k); 984 } else 985 throw new IOException ("Invalid script bloc : line " 986 + blocLineNbr + " (no Jar)"); 987 } else { 988 throw new IOException ("Unsupported script : line " + blocLineNbr 989 + " (" + cmd + ")"); 990 } 991 String k = (String ) keywords.get("ScriptName"); 997 if (k != null) { 998 System.out.println(" ScriptName=" + k); 999 destName = k; 1000 } else 1001 throw new IOException ("Invalid script bloc : line " + blocLineNbr 1002 + " (no ScriptName)"); 1003 String lineSep = "\n"; 1007 StringBuffer buf = new StringBuffer (); 1008 buf.append("CMD").append(lineSep).append(cmd); 1010 for (Iterator it = keywords.entrySet().iterator(); it.hasNext();) { 1011 Map.Entry e = (Map.Entry ) it.next(); 1012 if (e.getValue() != null) { 1013 buf.append(lineSep).append((String ) e.getKey()).append(lineSep) 1014 .append((String ) e.getValue()); 1015 } 1016 } 1017 if (buf.length() > 0) 1018 scripts.add(buf.toString()); 1019 return destName; 1020 } 1021 1022 private void addToArchive(ZipOutputStream stream, File file, 1023 FileFilter filter, String entryName, int recurseDepth) 1024 throws IOException { 1025 if (file.exists()) { 1026 if (file.isDirectory()) { 1027 File [] ls = file.listFiles(filter); 1028 if (ls.length == 0) { 1029 if (archiveEntryList_.contains(entryName + "/")) { 1031 System.err.println(" warning: duplicate entry: " 1032 + entryName + "/" + ". Skipping."); 1033 } else { 1034 System.out.println(" " + file); 1035 ZipEntry newEntry = new ZipEntry (entryName + "/"); 1036 stream.putNextEntry(newEntry); 1037 stream.closeEntry(); 1038 archiveEntryList_.add(entryName + "/"); 1039 } 1040 } 1041 for (int i = 0; i < ls.length; i++) { 1042 String ename = ls[i].getAbsolutePath(); 1043 ename = entryName 1044 + ename.substring(file.getAbsolutePath().length()); 1045 ename = convertToGenericPath(ename); 1046 if (ename.startsWith("/")) 1047 ename = ename.substring(1); 1048 if (recurseDepth > 0) 1049 addToArchive(stream, ls[i], filter, ename, 1050 recurseDepth - 1); 1051 } 1052 } else if (archiveEntryList_.contains(entryName)) { 1053 System.err.println(" warning: duplicate entry: " + entryName 1054 + ". Skipping."); 1055 } else { 1056 System.out.println(" " + file); 1057 1061 archivecount_++; 1062 ZipEntry newEntry = new ZipEntry (entryName); 1063 stream.putNextEntry(newEntry); 1064 FileInputStream in = new FileInputStream (file); 1065 byte[] buf = new byte[2048]; 1066 int read = in.read(buf, 0, buf.length); 1067 while (read > 0) { 1068 stream.write(buf, 0, read); 1069 read = in.read(buf, 0, buf.length); 1070 } 1071 in.close(); 1072 stream.closeEntry(); 1073 archiveEntryList_.add(entryName); 1074 } 1075 } else { 1076 System.err.println(" error: file " + file 1077 + " does not exist. Skipping."); 1078 } 1079 } 1080 1081 private String convertToLocalPath(String entry) throws IOException { 1082 String res = Setup.expandDirectory(entry, true, null); 1083 if (res == null) 1084 throw new IOException ("Invalid path: " + entry); 1085 return res.replace('/', File.separatorChar); 1086 } 1087 1088 private String convertToGenericPath(String line) { 1089 return line.replace(File.separatorChar, '/'); 1090 } 1091 1092 private void generateInstallCode(File javaFile, String instTemplate, 1093 String classLoader) throws IOException { 1094 String tempString; 1095 PrintWriter writer = new PrintWriter (new FileWriter (javaFile)); 1096 int read = 0; 1097 byte[] buf = new byte[128]; 1098 InputStream is = getClass().getResourceAsStream("/" + instTemplate); 1101 InputStreamReader isr = new InputStreamReader (is); 1102 LineNumberReader reader = new LineNumberReader (isr); 1103 System.out.println(VAGlobals 1104 .i18n("VAArchiver_GeneratingInstallClassCode")); 1105 String line = reader.readLine(); 1106 while ((line != null) && (!line.startsWith("// --> InstallClassName"))) { 1107 writer.println(line); 1108 line = reader.readLine(); 1109 } 1110 writer.println("public class " + instClassName_ + " {"); 1111 writer.println(" private static final Class installClass=new " 1112 + instClassName_ + "().getClass();"); 1113 line = reader.readLine(); 1114 while ((line != null) && (!line.startsWith("// --> ArchivingMethod"))) { 1115 writer.println(line); 1116 line = reader.readLine(); 1117 } 1118 writer.println(" private static String ARCH_METHOD=\"" + archMethod_ 1119 + "\";"); 1120 line = reader.readLine(); 1121 while ((line != null) && (!line.startsWith("// --> TargetType"))) { 1122 writer.println(line); 1123 line = reader.readLine(); 1124 } 1125 writer.println(" private static String TARGET_TYPE=\"" 1126 + currentTarget_ + "\";"); 1127 line = reader.readLine(); 1128 while ((line != null) 1129 && (!line.startsWith("// --> InstallClassOffset"))) { 1130 writer.println(line); 1131 line = reader.readLine(); 1132 } 1133 writer.println(" private static long ICLASS_OFFSET=" 1134 + installClassOffset_ + "L;"); 1135 line = reader.readLine(); 1136 while ((line != null) && (!line.startsWith("// --> InstallClassSize"))) { 1137 writer.println(line); 1138 line = reader.readLine(); 1139 } 1140 if (installClassSize_ != archOffset_) 1141 writer.println(" private static long ICLASS_SIZE=" 1142 + installClassSize_ + "L;"); 1143 else 1144 writer.println(" private static long ICLASS_SIZE=-1234543210L;"); 1145 line = reader.readLine(); 1146 while ((line != null) && (!line.startsWith("// --> ArchiveOffset"))) { 1147 writer.println(line); 1148 line = reader.readLine(); 1149 } 1150 writer.println(" private static long ARCH_OFFSET=" + archOffset_ 1151 + "L;"); 1152 line = reader.readLine(); 1153 while ((line != null) && (!line.startsWith("// --> JarSize"))) { 1154 writer.println(line); 1155 line = reader.readLine(); 1156 } 1157 writer.println(" private static long JAR_SIZE=" + jarSize_ + "L;"); 1158 line = reader.readLine(); 1159 while ((line != null) && (!line.startsWith("// --> UIMode"))) { 1160 writer.println(line); 1161 line = reader.readLine(); 1162 } 1163 writer.println(" private static String UI_MODE=\"" + uiMode_ + "\";"); 1164 line = reader.readLine(); 1165 while ((line != null) && (!line.startsWith("// --> UIBluescreen"))) { 1166 writer.println(line); 1167 line = reader.readLine(); 1168 } 1169 writer.println(" private static String UI_BLUESCREEN=\"" 1170 + uiBluescreen_ + "\";"); 1171 line = reader.readLine(); 1172 while ((line != null) && (!line.startsWith("// --> UIBluescreenColor"))) { 1173 writer.println(line); 1174 line = reader.readLine(); 1175 } 1176 writer.println(" private static String UI_BLUESCREEN_COLOR=\"" 1177 + uiBluescreenColor_ + "\";"); 1178 line = reader.readLine(); 1179 while ((line != null) && (!line.startsWith("// --> DestPath"))) { 1180 writer.println(line); 1181 line = reader.readLine(); 1182 } 1183 writer.println(" private static String DEST_PATH=\"" + destPath_ 1184 + "\";"); 1185 line = reader.readLine(); 1186 while ((line != null) && (!line.startsWith("// --> AppInfo"))) { 1187 writer.println(line); 1188 line = reader.readLine(); 1189 } 1190 writer 1191 .println(" private static String APP_NAME=\"" + appName_ 1192 + "\";"); 1193 if (appVersion_ != null) 1194 writer.println(" private static String APP_VERSION=\"" 1195 + appVersion_ + "\";"); 1196 else 1197 writer.println(" private static String APP_VERSION=null;"); 1198 line = reader.readLine(); 1199 while ((line != null) && (!line.startsWith("// --> LinkInfos"))) { 1200 System.out.println("fred " + line); 1201 writer.println(line); 1202 line = reader.readLine(); 1203 } 1204 writer.println(" private static String LINK_SECTION_NAME=\"" 1205 + linkSectionName_ + "\";"); 1206 writer.println(" private static String LINK_SECTION_ICON=\"" 1207 + linkSectionIcon_ + "\";"); 1208 writer.println(" private static String LINK_ENTRY_NAME=\"" 1209 + linkEntryName_ + "\";"); 1210 writer.println(" private static String LINK_ENTRY_ICON=\"" 1211 + linkEntryIcon_ + "\";"); 1212 if (createUninstallShortcut_) 1213 tempString = "true"; 1214 else 1215 tempString = "false"; 1216 writer.println(" private static boolean CREATE_UNINSTALL_SHORTCUT=" 1217 + tempString + ";"); 1218 line = reader.readLine(); 1219 while ((line != null) && (!line.startsWith("// --> LicenseKey"))) { 1220 writer.println(line); 1221 line = reader.readLine(); 1222 } 1223 writer.println(" private static String LICENSE_KEY_SUPPORT_NAME=\"" 1224 + licenseKeySupportClassName_ + "\";"); 1225 System.out.println(VAGlobals.i18n("VAArchiver_AppendingClassloader")); 1226 line = reader.readLine(); 1227 while ((line != null) && (!line.startsWith("// --> ClassLoader"))) { 1228 writer.println(line); 1229 line = reader.readLine(); 1230 } 1231 InputStream isClassLoader = getClass().getResourceAsStream( 1232 "/" + classLoader); 1233 writer.println(" private static String[] CL_CLASS={"); 1235 read = isClassLoader.read(buf); 1236 while (read > 0) { 1237 writer.println("\"" + codeLine(buf, read) + "\","); 1238 read = isClassLoader.read(buf); 1239 } 1240 isClassLoader.close(); 1241 writer.println(" };\n}"); 1242 reader.close(); 1243 writer.close(); 1244 is.close(); 1246 isr.close(); 1247 } 1248 1249 private void generateJnlpFile(File jnlpFile) throws IOException { 1250 PrintWriter out = new PrintWriter ( 1251 new BufferedWriter (new OutputStreamWriter (new FileOutputStream ( 1252 jnlpFile), "UTF-8"))); 1253 out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 1254 out.println("<jnlp spec=\"1.0\""); 1255 out.println(" codebase=\"" + jarCodebase_ + "\""); 1256 out.println(" HREF=\"" + instClassName_ + ".jnlp\">"); 1257 out.println(" <information>"); 1258 if (appVersion_ != null) 1259 out.println(" <title>" + appName_ + " " + appVersion_ 1260 + " Installer</title>"); 1261 else 1262 out.println(" <title>" + appName_ + " " + " Installer</title>"); 1263 out.println(" <vendor>" + jarVendor_ + "</vendor>"); 1264 out.println(" <homepage HREF=\"" + jarHomepage_ + "\"/>"); 1265 if (appVersion_ != null) 1266 out.println(" <description>Installer for " + appName_ + " " 1267 + appVersion_ + "</description>"); 1268 else 1269 out.println(" <description>Installer for " + appName_ 1270 + "</description>"); 1271 out.println(" <offline/>"); 1274 out.println(" </information>"); 1275 out.println(" <resources>"); 1276 out.println(" <j2se version=\"1.3 1.2\"/>"); 1277 out.println(" <jar HREF=\"" + instClassName_ + ".jar\"/>"); 1278 out.println(" <property name=\"DEBUG\" value=\"yes\"/>"); 1279 out.println(" </resources>"); 1280 out.println(" <security>"); 1281 out.println(" <all-permissions/>"); 1282 out.println(" </security>"); 1283 out.println(" <application-desc main-class=\"" + instClassName_ 1284 + "\"/>"); 1285 out.println("</jnlp>"); 1286 out.close(); 1287 } 1288 1289 private void generateManifestFile(File mfFile) throws IOException { 1290 PrintWriter out = new PrintWriter (new BufferedWriter ( 1291 new OutputStreamWriter (new FileOutputStream (mfFile), "UTF-8"))); 1292 out.println("Manifest-Version: 1.0"); 1293 out.println("Main-Class: " + instClassName_); 1294 out.close(); 1295 } 1296 1297 private long generateUnixInstallShell(File unixShellFile, 1298 String instTemplate, File instClassFile) throws IOException { 1299 FileOutputStream byteWriter = new FileOutputStream (unixShellFile); 1300 InputStream is = getClass().getResourceAsStream("/" + instTemplate); 1301 InputStreamReader isr = new InputStreamReader (is); 1302 LineNumberReader reader = new LineNumberReader (isr); 1303 String content = ""; 1304 String installClassStartStr = "000000000000"; 1305 NumberFormat nf = NumberFormat.getInstance(Locale.US); 1306 nf.setGroupingUsed(false); 1307 nf.setMinimumIntegerDigits(installClassStartStr.length()); 1308 int installClassStartPos = 0; 1309 long installClassOffset = 0; 1310 System.out.println(VAGlobals.i18n("VAArchiver_GenerateInstallShell")); 1311 String line = reader.readLine(); 1312 while ((line != null) && (!line.startsWith("# InstallClassStart"))) { 1313 content += line + "\n"; 1314 line = reader.readLine(); 1315 } 1316 content += "InstallClassStart=" + installClassStartStr + "\n"; 1317 installClassStartPos = content.length() - 1 - 1 1318 - installClassStartStr.length(); 1319 line = reader.readLine(); 1320 while ((line != null) && (!line.startsWith("# InstallClassSize"))) { 1321 content += line + "\n"; 1322 line = reader.readLine(); 1323 } 1324 content += new String ("InstallClassSize=" + instClassFile.length() 1325 + "\n"); 1326 line = reader.readLine(); 1327 while ((line != null) && (!line.startsWith("# InstallClassName"))) { 1328 content += line + "\n"; 1329 line = reader.readLine(); 1330 } 1331 content += new String ("InstallClassName=" + instClassName_ + "\n"); 1332 line = reader.readLine(); 1333 while ((line != null) && (!line.startsWith("# Install class"))) { 1334 content += line + "\n"; 1335 line = reader.readLine(); 1336 } 1337 if (line != null) 1338 content += line + "\n"; 1339 byteWriter.write(content.substring(0, installClassStartPos + 1) 1340 .getBytes()); 1341 byteWriter.write(nf.format(content.length()).getBytes()); 1342 byteWriter.write(content.substring( 1343 installClassStartPos + 1 + installClassStartStr.length()) 1344 .getBytes()); 1345 installClassOffset = content.length(); 1346 content = null; 1347 FileInputStream classStream = new FileInputStream (instClassFile); 1348 byte[] buf = new byte[2048]; 1349 int read = classStream.read(buf); 1350 while (read > 0) { 1351 byteWriter.write(buf, 0, read); 1352 read = classStream.read(buf); 1353 } 1354 classStream.close(); 1355 reader.close(); 1356 byteWriter.close(); 1357 return installClassOffset; 1358 } 1359 1360 private void shiftArray(byte[] array) { 1361 for (int i = 0; i < (array.length - 1); i++) 1362 array[i] = array[i + 1]; 1363 array[array.length - 1] = 0; 1364 } 1365 1366 private long generateNativeInstallExe(File nativeInstallFile, 1367 String instTemplate, File instClassFile) throws IOException { 1368 InputStream reader = getClass().getResourceAsStream("/" + instTemplate); 1389 ByteArrayOutputStream content = new ByteArrayOutputStream (); 1393 String installClassVarStr = "000000000000"; 1394 byte[] buf = new byte[installClassVarStr.length()]; 1395 NumberFormat nf = NumberFormat.getInstance(Locale.US); 1396 nf.setGroupingUsed(false); 1397 nf.setMinimumIntegerDigits(installClassVarStr.length()); 1398 int installClassStopPos = 0; 1399 long installClassOffset = reader.available(); 1400 int position = 0; 1401 System.out.println(VAGlobals.i18n("VAArchiver_GenerateInstallExe")); 1402 reader.read(buf, 0, buf.length); 1404 position = 1; 1406 for (int n = 0; n < 3; n++) { 1408 while ((!new String (buf).equals("clname_here_")) 1410 && (!new String (buf).equals("clstart_here")) 1411 && (!new String (buf).equals("clstop_here_"))) { 1412 content.write(buf[0]); 1413 int nextb = reader.read(); 1415 position++; 1416 shiftArray(buf); 1417 buf[buf.length - 1] = (byte) nextb; 1419 } 1420 if (new String (buf).equals("clname_here_")) { 1421 VAGlobals.printDebug(" clname_here_ found at " 1422 + (position - 1)); 1423 StringBuffer clnameBuffer = new StringBuffer (64); 1424 clnameBuffer.append(instClassName_); 1425 for (int i = clnameBuffer.length() - 1; i < 64; i++) { 1426 clnameBuffer.append('.'); 1427 } 1428 byte[] clnameBytes = clnameBuffer.toString().getBytes(); 1429 for (int i = 0; i < 64; i++) { 1431 content.write(clnameBytes[i]); 1432 position++; 1433 } 1434 reader.skip(64 - buf.length); 1436 reader.read(buf, 0, buf.length); 1438 } else if (new String (buf).equals("clstart_here")) { 1439 VAGlobals.printDebug(" clstart_here found at " 1440 + (position - 1)); 1441 buf = nf.format(installClassOffset).getBytes(); 1442 for (int i = 0; i < buf.length; i++) { 1444 content.write(buf[i]); 1445 position++; 1446 } 1447 reader.read(buf, 0, buf.length); 1449 } else if (new String (buf).equals("clstop_here_")) { 1450 VAGlobals.printDebug(" clstop_here_ found at " 1451 + (position - 1)); 1452 installClassStopPos = position - 1; 1454 content.write(buf); 1456 position += 12; 1457 reader.read(buf, 0, buf.length); 1459 } 1460 } 1461 content.write(buf); 1462 buf = new byte[2048]; 1464 int read = reader.read(buf); 1465 while (read > 0) { 1466 content.write(buf, 0, read); 1467 read = reader.read(buf); 1468 } 1469 reader.close(); 1470 FileInputStream classStream = new FileInputStream (instClassFile); 1472 read = classStream.read(buf); 1473 while (read > 0) { 1474 content.write(buf, 0, read); 1475 read = classStream.read(buf); 1476 } 1477 classStream.close(); 1478 content.close(); 1479 byte[] contentBytes = content.toByteArray(); 1481 installClassVarStr = nf.format(contentBytes.length); 1482 byte[] installClassVarBytes = installClassVarStr.getBytes(); 1483 for (int i = 0; i < installClassVarBytes.length; i++) { 1484 contentBytes[installClassStopPos + i] = installClassVarBytes[i]; 1485 } 1486 FileOutputStream out = new FileOutputStream (nativeInstallFile); 1488 out.write(contentBytes); 1489 out.close(); 1490 return installClassOffset; 1491 } 1492 1493 private void appendArchive(File instClass) throws IOException { 1494 FileOutputStream out = new FileOutputStream (instClass.getName(), true); 1495 FileInputStream zipStream = new FileInputStream ("install.jar"); 1496 byte[] buf = new byte[2048]; 1497 int read = zipStream.read(buf); 1498 while (read > 0) { 1499 out.write(buf, 0, read); 1500 read = zipStream.read(buf); 1501 } 1502 zipStream.close(); 1503 out.close(); 1504 } 1505 1506 private void copy(File fin, File fout) throws IOException { 1507 FileOutputStream out = null; 1508 FileInputStream in = null; 1509 try { 1510 out = new FileOutputStream (fout); 1511 in = new FileInputStream (fin); 1512 byte[] buf = new byte[2048]; 1513 int read = in.read(buf); 1514 while (read > 0) { 1515 out.write(buf, 0, read); 1516 read = in.read(buf); 1517 } 1518 } catch (IOException _e) { 1519 throw _e; 1520 } finally { 1521 if (in != null) 1522 in.close(); 1523 if (out != null) 1524 out.close(); 1525 } 1526 } 1527 1528 private void jar(String options, File jarFile, File [] files) 1529 throws IOException { 1530 Process p = null; 1531 Vector argsv = new Vector (); 1532 argsv.add(getJavaBinPath() + File.separator + "jar"); 1533 if (options != null && !options.equals("")) 1534 argsv.add(options); 1535 argsv.add(jarFile.getName()); 1536 for (int i = 0; i < files.length; i++) 1537 argsv.add(files[i].getName()); 1538 String [] args = new String [argsv.size()]; 1539 for (int i = 0; i < args.length; i++) 1540 args[i] = (String ) argsv.get(i); 1541 try { 1542 p = Runtime.getRuntime().exec(args); 1543 p.waitFor(); 1544 } catch (Exception rte) { 1545 throw new IOException ( 1546 "Runtime exception: check if you have installed the JDK and run java from the JDK\n" 1547 + "Exception message: " + rte.getMessage()); 1548 } 1549 printCmdOutput(p, "jar"); 1550 if (p.exitValue() != 0) 1551 throw new RuntimeException (" abnormal exit"); 1552 } 1553 1554 private void jarsign(String passphrase, File jarFile, String alias) 1555 throws IOException { 1556 Process p = null; 1557 try { 1558 p = Runtime.getRuntime().exec( 1559 new String [] { 1560 JDK_HOME + File.separator + "bin" + File.separator 1561 + "jarsigner", "-storepass", passphrase, 1562 jarFile.getName(), alias }); 1563 p.waitFor(); 1564 } catch (Exception rte) { 1565 throw new IOException ( 1566 "Runtime exception: check if you have installed the JDK and run java from the JDK\n" 1567 + "Exception message: " + rte.getMessage()); 1568 } 1569 printCmdOutput(p, "jarsign"); 1570 if (p.exitValue() != 0) 1571 throw new RuntimeException (" abnormal exit"); 1572 } 1573 1574 private File compile(String javafile) throws IOException { 1575 File classFile = null; 1576 Process p = null; 1577 try { 1578 p = Runtime.getRuntime().exec( 1579 new String [] { getJavaBinPath() + File.separator + JAVAC, 1580 javafile }); 1581 p.waitFor(); 1582 } catch (Exception rte) { 1583 throw new IOException ( 1584 "Runtime exception: check if you have installed the JDK and run java from the JDK\n" 1585 + "Exception message: " + rte.getMessage()); 1586 } 1587 printCmdOutput(p, "javac"); 1588 if (p.exitValue() != 0) 1589 throw new RuntimeException (" abnormal exit"); 1590 classFile = new File (javafile.substring(0, javafile.lastIndexOf('.')) 1591 + ".class"); 1592 System.out.println(" " + classFile + " " + classFile.exists()); 1593 return classFile; 1596 } 1597 1598 private void printCmdOutput(Process p, String cmdName) throws IOException { 1599 BufferedReader psIn = new BufferedReader (new InputStreamReader (p 1600 .getInputStream())); 1601 BufferedReader psErr = new BufferedReader (new InputStreamReader (p 1602 .getErrorStream())); 1603 int n = 0; 1604 System.out.println(" --- start " + cmdName + " ---"); 1605 String inLine = psIn.readLine(); 1606 String errLine = psErr.readLine(); 1607 while ((inLine != null) || (errLine != null)) { 1608 if (inLine != null) 1609 System.out.println(" " + inLine); 1610 if (errLine != null) 1611 System.err.println(" " + errLine); 1612 inLine = psIn.readLine(); 1613 errLine = psErr.readLine(); 1614 } 1615 psIn.close(); 1616 psErr.close(); 1617 System.out.println(" --- end " + cmdName + " ---"); 1618 } 1619 1620 private File makeJar(String filename, File archive, File license, 1621 File readme, byte[] archiveInfos) throws IOException { 1622 File jar = new File (filename); 1623 JarOutputStream out = new JarOutputStream (new FileOutputStream (jar)); 1624 copyInternalToJar(out, JAR_FILES_COMMON); 1626 copyInternalToJar(out, JAR_FILES_JNIREGISTRY); 1627 copyInternalToJar(out, JAR_FILES_JNISHORTCUT); 1628 copyInternalToJar(out, JAR_FILES_TEXT_UI); 1630 copyInternalToJar(out, JAR_FILES_ANSI_UI); 1631 if (uiMode_.equals("graphic")) 1632 copyInternalToJar(out, JAR_FILES_GRAPHIC_UI); 1633 if (uiMode_.equals("xtra")) 1634 copyInternalToJar(out, JAR_FILES_XTRA_UI); 1635 if (uiMode_.equals("unattended")) 1636 copyInternalToJar(out, JAR_FILES_UNATTENDED_UI); 1637 if (customPrePostClassName_.length() > 0) { 1639 copyInternalToJar(out, JAR_FILES_CUSTOM_PRE_POST); 1640 if (!"com.memoire.vainstall.AbstractCustomPrePost" 1642 .equals(customPrePostClassName_)) { 1643 copyJarFilesToJar(out, customPrePostJarfileName_); 1644 } 1645 } 1646 addToJar(out, new ByteArrayInputStream (archiveInfos), 1648 "com/memoire/vainstall/archive_infos", archiveInfos.length); 1649 addToJar(out, new FileInputStream (archive), 1651 "com/memoire/vainstall/archive.zip", archive.length()); 1652 InputStream licenseStream = new FileInputStream (license); 1654 String licenseEncoding = VAProperties.PROPERTIES 1655 .getProperty("vainstall.archive.license.encoding"); 1656 if (licenseEncoding == null || licenseEncoding.equals("") == true) { 1657 licenseEncoding = new InputStreamReader (licenseStream) 1659 .getEncoding(); 1660 } 1661 InputStreamReader isrLicense = new InputStreamReader (licenseStream, 1662 licenseEncoding); 1663 addToJarEncoded(out, isrLicense, "com/memoire/vainstall/license.txt", 1664 license.length()); 1665 InputStream readmeStream = new FileInputStream (readme); 1667 String readmeEncoding = VAProperties.PROPERTIES 1668 .getProperty("vainstall.archive.readme.encoding"); 1669 if (readmeEncoding == null || readmeEncoding.equals("") == true) { 1670 readmeEncoding = new InputStreamReader (readmeStream).getEncoding(); 1672 } 1673 InputStreamReader isrReadme = new InputStreamReader (readmeStream, 1674 readmeEncoding); 1675 addToJarEncoded(out, isrReadme, "com/memoire/vainstall/readme.txt", 1676 readme.length()); 1677 InputStream invaiimage = null; 1679 try { 1680 invaiimage = new FileInputStream (new File (image_)); 1681 } catch (Exception exc) { 1682 image_ = "/" + image_; 1683 invaiimage = getClass().getResourceAsStream(image_); 1684 } 1685 if (invaiimage == null) { 1686 invaiimage = getClass().getResourceAsStream( 1687 "com/memoire/vainstall/resources/banner.gif"); 1688 image_ = "com/memoire/vainstall/resources/banner.gif"; 1689 } 1690 if (invaiimage != null) { 1691 addToJar(out, invaiimage, 1692 "com/memoire/vainstall/resources/banner.gif", invaiimage 1693 .available()); 1694 } 1695 InputStream invailogo = getClass().getResourceAsStream("/" + VAILOGO); 1697 addToJar(out, invailogo, VAILOGO, invailogo.available()); 1698 ByteArrayOutputStream poutstream = new ByteArrayOutputStream (); 1701 installProperties.store(poutstream, VAGlobals.NAME + " " 1702 + VAGlobals.VERSION); 1703 ByteArrayInputStream pinstream = new ByteArrayInputStream (poutstream 1704 .toByteArray()); 1705 addToJar(out, pinstream, 1706 "com/memoire/vainstall/resources/vainstall.properties", 1707 poutstream.toByteArray().length); 1708 if (lnfFile_ != null) { 1709 System.out.println("add lnf jar file: " 1710 + lnfFile_.getAbsolutePath()); 1711 addToJar(out, new FileInputStream (lnfFile_), 1712 "com/memoire/vainstall/resources/" + lnfFile_.getName(), 1713 lnfFile_.length()); 1714 } 1715 System.out.println("additionalFiles"); 1716 if (additionalFiles_ != null) { 1717 StringTokenizer fmi = new StringTokenizer (additionalFiles_, ","); 1718 while (fmi.hasMoreTokens()) { 1719 StringTokenizer fm = new StringTokenizer (fmi.nextToken(), "!"); 1720 File sf = new File (fm.nextToken()); 1721 String df = fm.nextToken(); 1722 addToJar(out, new FileInputStream (sf), df, sf.length()); 1723 } 1724 System.out.println("additionalFiles FIN"); 1725 } 1726 out.close(); 1727 return jar; 1728 } 1729 1730 1739 private void copyInternalToJar(JarOutputStream out, String [] JAR_FILES) 1740 throws IOException { 1741 for (int i = 0; i < JAR_FILES.length; i++) { 1742 String sourceName = JAR_FILES[i]; 1743 if (sourceName.endsWith(".jar")) { 1744 copyJarFilesToJar(out, sourceName); 1745 } else { 1746 InputStream is = getClass().getResourceAsStream( 1747 "/" + sourceName); 1748 if (is == null) { 1749 System.out 1750 .println("Cannot add the resource " 1751 + sourceName 1752 + " to the jar, since it cannot be found (bummer!)"); 1753 } else { 1754 addToJar(out, is, sourceName, is.available()); 1755 } 1756 } 1757 } } 1759 1760 1769 private void copyJarFilesToJar(JarOutputStream out, String jarSourceName) 1770 throws IOException { 1771 byte[] buffer = new byte[2048]; 1772 InputStream isJar = getClass().getResourceAsStream("/" + jarSourceName); 1773 JarInputStream zin = new JarInputStream (isJar); 1774 JarEntry entry = null; 1775 while ((entry = zin.getNextJarEntry()) != null) { 1776 ByteArrayOutputStream bos = new ByteArrayOutputStream (); 1777 while (true) { 1778 int read = zin.read(buffer); 1779 if (read == -1) 1780 break; 1781 bos.write(buffer, 0, read); 1782 } 1783 ByteArrayInputStream bais = new ByteArrayInputStream (bos 1784 .toByteArray()); 1785 addToJar(out, bais, entry.getName(), bos.toByteArray().length); 1786 bos.close(); 1787 zin.closeEntry(); 1788 } zin.close(); 1790 isJar.close(); 1791 } 1792 1793 private void addToJar(JarOutputStream out, InputStream in, 1794 String entryName, long length) throws IOException { 1795 byte[] buf = new byte[2048]; 1796 ZipEntry entry = new ZipEntry (entryName); 1797 CRC32 crc = new CRC32 (); 1798 entry.setSize(length); 1799 entry.setCrc(crc.getValue()); 1800 out.putNextEntry(entry); 1801 int read = in.read(buf); 1802 while (read > 0) { 1803 crc.update(buf, 0, read); 1804 out.write(buf, 0, read); 1805 read = in.read(buf); 1806 } 1807 entry.setCrc(crc.getValue()); 1808 in.close(); 1810 out.closeEntry(); 1811 } 1812 1813 private void addToJarEncoded(JarOutputStream out, InputStreamReader isr, 1814 String entryName, long length) throws IOException { 1815 StringBuffer buffer = new StringBuffer (); 1816 Reader reader = new BufferedReader (isr); 1817 int ch; 1818 while ((ch = reader.read()) > -1) { 1819 buffer.append((char) ch); 1820 } 1821 reader.close(); 1822 isr.close(); 1823 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 1824 OutputStreamWriter osw = new OutputStreamWriter (baos, "UTF8"); 1825 osw.write(buffer.toString()); 1826 osw.flush(); 1827 ByteArrayInputStream bais = new ByteArrayInputStream (baos.toByteArray()); 1828 addToJar(out, bais, entryName, length); 1829 } 1830 1831 private boolean checkVaiPath(String dir) { 1833 int index = dir.indexOf(']'); 1834 if (!dir.startsWith("[")) 1835 return true; 1836 if (index <= 2) 1837 return false; 1838 String prefix = dir.substring(1, index).trim(); 1839 1843 if ("HOME".equals(prefix) || "PROGRAM".equals(prefix) 1844 || prefix.startsWith("ENV{")) { 1845 return true; 1846 } 1847 if ((prefix.length() == 2) && (prefix.endsWith(":")) 1848 && (Character.isLetter(prefix.charAt(0)))) 1849 return true; 1850 return false; 1851 } 1852 1853 private String codeLine(byte[] data, int siz) { 1854 String res = null; 1855 byte[] convert = new byte[2 * siz]; 1856 for (int i = 0; i < siz; i++) { 1857 convert[2 * i] = (byte) (65 + (data[i] & 0x0F)); 1858 convert[2 * i + 1] = (byte) (65 + (data[i] & 0xF0) / 16); 1859 } 1860 res = new String (convert); 1861 return res; 1862 } 1863} 1864 1865class FileNameGroup { 1866 String originBase_, destBase_, commonPath_, extensions_; 1867 1868 boolean executable_; 1869 1870 boolean recursive_; 1871 1872 public FileNameGroup(String line) { 1873 executable_ = false; 1874 recursive_ = true; 1875 if (line.startsWith("(E)")) { 1876 line = line.substring(3); 1877 executable_ = true; 1878 } 1879 if (line.startsWith("(N)")) { 1880 line = line.substring(3); 1881 recursive_ = false; 1882 } 1883 StringTokenizer tok = new StringTokenizer (new String (line), "|", true); 1884 originBase_ = tok.nextToken(); 1885 if (originBase_.endsWith("/")) 1886 originBase_ = originBase_.substring(0, originBase_.length() - 1); 1887 tok.nextToken(); 1888 destBase_ = tok.nextToken(); 1889 if (destBase_.equals("|")) 1890 destBase_ = null; 1891 else { 1892 if (destBase_.endsWith("/")) 1893 destBase_ = destBase_.substring(0, destBase_.length() - 1); 1894 tok.nextToken(); 1895 } 1896 extensions_ = null; 1897 commonPath_ = null; 1898 if (tok.hasMoreTokens()) { 1899 commonPath_ = tok.nextToken(); 1900 if (commonPath_.equals("|")) 1901 commonPath_ = null; 1902 if (tok.hasMoreTokens()) { 1903 if (commonPath_ != null) 1904 tok.nextToken(); 1905 if (tok.hasMoreTokens()) 1906 extensions_ = tok.nextToken(); 1907 } 1908 } 1909 } 1910 1911 public String getOrigin() { 1912 if (commonPath_ == null) 1913 return originBase_; 1914 return originBase_ + "/" + commonPath_; 1915 } 1916 1917 public String getDestination() { 1918 if ((destBase_ == null) && (commonPath_ == null)) 1919 return ""; 1920 if (destBase_ == null) 1921 return commonPath_; 1922 if (commonPath_ == null) 1923 return destBase_; 1924 return destBase_ + "/" + commonPath_; 1925 } 1926 1927 public FileFilter getFileFilter() throws IllegalArgumentException { 1928 String [] ext = null; 1929 if (extensions_ != null) { 1930 StringTokenizer t = new StringTokenizer (extensions_, ","); 1931 ext = new String [t.countTokens()]; 1932 for (int i = 0; i < ext.length; i++) { 1933 ext[i] = t.nextToken(); 1934 if ((ext[i].length() >= 2) && (ext[i].startsWith("*"))) 1935 ext[i] = ext[i].substring(1); 1936 else if ((ext[i].length() >= 3) && (ext[i].startsWith("!*"))) 1937 ext[i] = "!" + ext[i].substring(2); 1938 else 1939 throw new IllegalArgumentException ("invalid pattern: " 1940 + ext[i]); 1941 } 1942 } 1943 return new VaiFileFilter(ext); 1944 } 1945 1946 public boolean isExecutable() { 1947 return executable_; 1948 } 1949 1950 public boolean isRecursive() { 1951 return recursive_; 1952 } 1953} 1954 1955class VaiFileFilter implements FileFilter { 1956 String [] ext_; 1957 1958 public VaiFileFilter(String [] ext) { 1959 ext_ = ext; 1960 } 1961 1962 public boolean accept(File pathname) { 1963 boolean a = true; 1964 if (ext_ == null) 1965 return true; 1966 String p = pathname.getName(); 1967 for (int i = 0; i < ext_.length; i++) { 1968 if (ext_[i].startsWith("!")) { 1969 a = a && (!p.endsWith(ext_[i].substring(1))); 1970 } else { 1971 a = a && (p.endsWith(ext_[i])); 1972 } 1973 } 1974 return a; 1975 } 1976}
| Popular Tags
|