1 22 23 package com.izforge.izpack.installer; 24 25 import java.io.BufferedInputStream ; 26 import java.io.BufferedOutputStream ; 27 import java.io.File ; 28 import java.io.FileInputStream ; 29 import java.io.FileNotFoundException ; 30 import java.io.FileOutputStream ; 31 import java.io.IOException ; 32 import java.io.InputStream ; 33 import java.io.ObjectInputStream ; 34 import java.lang.reflect.Constructor ; 35 import java.net.URL ; 36 import java.util.ArrayList ; 37 import java.util.HashMap ; 38 import java.util.HashSet ; 39 import java.util.Iterator ; 40 import java.util.List ; 41 import java.util.Stack ; 42 import java.util.TreeSet ; 43 import java.util.zip.ZipEntry ; 44 import java.util.zip.ZipInputStream ; 45 import java.util.zip.ZipOutputStream ; 46 47 import org.apache.regexp.RE; 48 import org.apache.regexp.RECompiler; 49 import org.apache.regexp.RESyntaxException; 50 51 import com.izforge.izpack.ExecutableFile; 52 import com.izforge.izpack.LocaleDatabase; 53 import com.izforge.izpack.Pack; 54 import com.izforge.izpack.PackFile; 55 import com.izforge.izpack.ParsableFile; 56 import com.izforge.izpack.UpdateCheck; 57 import com.izforge.izpack.event.InstallerListener; 58 import com.izforge.izpack.util.AbstractUIHandler; 59 import com.izforge.izpack.util.AbstractUIProgressHandler; 60 import com.izforge.izpack.util.FileExecutor; 61 import com.izforge.izpack.util.IoHelper; 62 import com.izforge.izpack.util.OsConstraint; 63 import com.izforge.izpack.util.VariableSubstitutor; 64 65 71 public class Unpacker implements IUnpacker 72 { 73 74 75 private AutomatedInstallData idata; 76 77 78 private AbstractUIProgressHandler handler; 79 80 81 private UninstallData udata; 82 83 84 private VariableSubstitutor vs; 85 86 87 private static HashMap instances = new HashMap (); 88 89 90 private File absolute_installpath; 91 92 93 private LocaleDatabase langpack = null; 94 95 96 private static boolean interruptDesired = false; 97 98 99 private static boolean discardInterrupt = false; 100 101 102 private static final String LANG_FILE_NAME = "packsLang.xml"; 103 104 public static final String ALIVE = "alive"; 105 106 public static final String INTERRUPT = "doInterrupt"; 107 108 public static final String INTERRUPTED = "interruppted"; 109 110 111 private boolean result = true; 112 113 119 public Unpacker(AutomatedInstallData idata, AbstractUIProgressHandler handler) 120 { 121 try 123 { 124 String resource = LANG_FILE_NAME + "_" + idata.localeISO3; 125 this.langpack = new LocaleDatabase(ResourceManager.getInstance().getInputStream( 126 resource)); 127 } 128 catch (Throwable exception) 129 {} 130 131 this.idata = idata; 132 this.handler = handler; 133 134 vs = new VariableSubstitutor(idata.getVariables()); 136 } 137 138 143 public static HashMap getRunningInstances() 144 { 145 synchronized (instances) 146 { return (HashMap ) (instances.clone()); 149 } 150 } 151 152 155 private void addToInstances() 156 { 157 synchronized (instances) 158 { 159 instances.put(this, ALIVE); 160 } 161 } 162 163 166 private void removeFromInstances() 167 { 168 synchronized (instances) 169 { 170 instances.remove(this); 171 } 172 } 173 174 179 private static void setInterruptAll() 180 { 181 synchronized (instances) 182 { 183 Iterator iter = instances.keySet().iterator(); 184 while (iter.hasNext()) 185 { 186 Object key = iter.next(); 187 if (instances.get(key).equals(ALIVE)) 188 { 189 instances.put(key, INTERRUPT); 190 } 191 } 192 setInterruptDesired(true); 195 } 196 } 197 198 206 public static boolean interruptAll(long waitTime) 207 { 208 long t0 = System.currentTimeMillis(); 209 if (isDiscardInterrupt()) return (false); 210 setInterruptAll(); 211 while (!isInterruptReady()) 212 { 213 if (System.currentTimeMillis() - t0 > waitTime) return (true); 214 try 215 { 216 Thread.sleep(100); 217 } 218 catch (InterruptedException e) 219 {} 220 } 221 return (true); 222 } 223 224 private static boolean isInterruptReady() 225 { 226 synchronized (instances) 227 { 228 Iterator iter = instances.keySet().iterator(); 229 while (iter.hasNext()) 230 { 231 Object key = iter.next(); 232 if (!instances.get(key).equals(INTERRUPTED)) return (false); 233 } 234 return (true); 235 } 236 237 } 238 239 245 private boolean performInterrupted() 246 { 247 synchronized (instances) 248 { 249 Object doIt = instances.get(this); 250 if (doIt != null && (doIt.equals(INTERRUPT) || doIt.equals(INTERRUPTED))) 251 { 252 instances.put(this, INTERRUPTED); 253 this.result = false; 254 return (true); 255 } 256 return (false); 257 } 258 } 259 260 265 private boolean shouldInterrupt() 266 { 267 synchronized (instances) 268 { 269 Object doIt = instances.get(this); 270 if (doIt != null && (doIt.equals(INTERRUPT) || doIt.equals(INTERRUPTED))) { return (true); } 271 return (false); 272 } 273 274 } 275 276 279 public void run() 280 { 281 addToInstances(); 282 try 283 { 284 FileOutputStream out = null; 287 ArrayList parsables = new ArrayList (); 288 ArrayList executables = new ArrayList (); 289 ArrayList updatechecks = new ArrayList (); 290 List packs = idata.selectedPacks; 291 int npacks = packs.size(); 292 handler.startAction("Unpacking", npacks); 293 udata = UninstallData.getInstance(); 294 List [] customActions = getCustomActions(); 296 informListeners(customActions, InstallerListener.BEFORE_PACKS, idata, new Integer ( 298 npacks), handler); 299 packs = idata.selectedPacks; 300 npacks = packs.size(); 301 302 for (int i = 0; i < npacks; i++) 304 { 305 int n = idata.allPacks.indexOf(packs.get(i)); 307 308 informListeners(customActions, InstallerListener.BEFORE_PACK, packs.get(i), 310 new Integer (npacks), handler); 311 ObjectInputStream objIn = new ObjectInputStream (getPackAsStream(n)); 312 313 int nfiles = objIn.readInt(); 315 316 final Pack pack = ((Pack) packs.get(i)); 318 String stepname = pack.name; if (langpack != null && !(pack.id == null || "".equals(pack.id))) 321 { 322 323 final String name = langpack.getString(pack.id); 324 if (name != null && !"".equals(name)) 325 { 326 stepname = name; 327 } 328 } 329 handler.nextStep(stepname, i + 1, nfiles); 330 for (int j = 0; j < nfiles; j++) 331 { 332 PackFile pf = (PackFile) objIn.readObject(); 334 335 if (OsConstraint.oneMatchesCurrentSystem(pf.osConstraints())) 336 { 337 String path = IoHelper.translatePath(pf.getTargetPath(), vs); 339 File pathFile = new File (path); 340 File dest = pathFile; 341 if (!pf.isDirectory()) dest = pathFile.getParentFile(); 342 343 if (!dest.exists()) 344 { 345 List fileListeners = customActions[customActions.length - 1]; 349 if (fileListeners != null && fileListeners.size() > 0) 350 mkDirsWithEnhancement(dest, pf, customActions); 351 else 352 { 354 if (!dest.mkdirs()) 355 { 356 handler.emitError("Error creating directories", 357 "Could not create directory\n" + dest.getPath()); 358 handler.stopAction(); 359 this.result = false; 360 return; 361 } 362 } 363 } 364 365 if (pf.isDirectory()) continue; 366 367 informListeners(customActions, InstallerListener.BEFORE_FILE, pathFile, pf, 369 null); 370 udata.addFile(path); 372 373 handler.progress(j, path); 374 375 if ((pathFile.exists()) && (pf.override() != PackFile.OVERRIDE_TRUE)) 379 { 380 boolean overwritefile = false; 381 382 if (pf.override() != PackFile.OVERRIDE_FALSE) 384 { 385 if (pf.override() == PackFile.OVERRIDE_TRUE) 386 { 387 overwritefile = true; 388 } 389 else if (pf.override() == PackFile.OVERRIDE_UPDATE) 390 { 391 overwritefile = (pathFile.lastModified() < pf.lastModified()); 400 } 401 else 402 { 403 int def_choice = -1; 404 405 if (pf.override() == PackFile.OVERRIDE_ASK_FALSE) 406 def_choice = AbstractUIHandler.ANSWER_NO; 407 if (pf.override() == PackFile.OVERRIDE_ASK_TRUE) 408 def_choice = AbstractUIHandler.ANSWER_YES; 409 410 int answer = handler.askQuestion(idata.langpack 411 .getString("InstallPanel.overwrite.title") 412 + " - " + pathFile.getName(), idata.langpack 413 .getString("InstallPanel.overwrite.question") 414 + pathFile.getAbsolutePath(), 415 AbstractUIHandler.CHOICES_YES_NO, def_choice); 416 417 overwritefile = (answer == AbstractUIHandler.ANSWER_YES); 418 } 419 420 } 421 422 if (!overwritefile) 423 { 424 if (!pf.isBackReference() && !((Pack) packs.get(i)).loose) 425 objIn.skip(pf.length()); 426 continue; 427 } 428 429 } 430 431 InputStream pis = objIn; 433 if (pf.isBackReference()) 434 { 435 InputStream is = getPackAsStream(pf.previousPackNumber); 436 pis = new ObjectInputStream (is); 437 is.skip(pf.offsetInPreviousPack - 4); 442 } 445 else if (((Pack) packs.get(i)).loose) 446 { 447 452 453 458 URL url = getClass().getResource("/info"); 460 String urlPath = url.getPath(); 461 int pos = urlPath.indexOf('!'); 462 if (pos>=0 && urlPath.startsWith("file:/")){ 463 urlPath = urlPath.substring("file:/".length(), pos); 465 } 466 File installerDir = new File (urlPath); 467 if (!installerDir.isDirectory()) 468 { 469 installerDir = installerDir.getParentFile(); 470 } 471 472 File resolvedFile = new File (installerDir, pf.getRelativeSourcePath()); 473 if (!resolvedFile.exists()){ 474 final File userDir = new File (System.getProperty("user.dir")); 477 resolvedFile = new File (userDir, pf.getRelativeSourcePath()); 478 } 479 if (resolvedFile.exists()){ 480 pis = new FileInputStream (resolvedFile); 481 pf = new PackFile(resolvedFile.getParentFile(), resolvedFile, pf.getTargetPath(), pf.osConstraints(), pf.override(), pf.getAdditionals()); 483 }else{ 484 System.out.println("Could not find loosely bundled file: "+pf.getRelativeSourcePath()); 488 out.close(); 489 continue; 490 } 491 } 492 493 out = new FileOutputStream (pathFile); 494 byte[] buffer = new byte[5120]; 495 long bytesCopied = 0; 496 while (bytesCopied < pf.length()) 497 { 498 if (performInterrupted()) 499 { out.close(); 501 if (pis != objIn) pis.close(); 502 return; 503 } 504 int maxBytes = (int) Math.min(pf.length() - bytesCopied, buffer.length); 505 int bytesInBuffer = pis.read(buffer, 0, maxBytes); 506 if (bytesInBuffer == -1) 507 throw new IOException ("Unexpected end of stream (installer corrupted?)"); 508 509 out.write(buffer, 0, bytesInBuffer); 510 511 bytesCopied += bytesInBuffer; 512 } 513 out.close(); 515 if (pis != objIn) pis.close(); 516 517 if (pf.lastModified() >= 0) pathFile.setLastModified(pf.lastModified()); 519 informListeners(customActions, InstallerListener.AFTER_FILE, pathFile, pf, 521 null); 522 523 } 524 else 525 { 526 if (!pf.isBackReference()) objIn.skip(pf.length()); 527 } 528 } 529 530 int numParsables = objIn.readInt(); 532 for (int k = 0; k < numParsables; k++) 533 { 534 ParsableFile pf = (ParsableFile) objIn.readObject(); 535 pf.path = IoHelper.translatePath(pf.path, vs); 536 parsables.add(pf); 537 } 538 539 int numExecutables = objIn.readInt(); 541 for (int k = 0; k < numExecutables; k++) 542 { 543 ExecutableFile ef = (ExecutableFile) objIn.readObject(); 544 ef.path = IoHelper.translatePath(ef.path, vs); 545 if (null != ef.argList && !ef.argList.isEmpty()) 546 { 547 String arg = null; 548 for (int j = 0; j < ef.argList.size(); j++) 549 { 550 arg = (String ) ef.argList.get(j); 551 arg = IoHelper.translatePath(arg, vs); 552 ef.argList.set(j, arg); 553 } 554 } 555 executables.add(ef); 556 if (ef.executionStage == ExecutableFile.UNINSTALL) 557 { 558 udata.addExecutable(ef); 559 } 560 } 561 handleAdditionalUninstallData(udata, customActions); 563 564 int numUpdateChecks = objIn.readInt(); 566 567 for (int k = 0; k < numUpdateChecks; k++) 568 { 569 UpdateCheck uc = (UpdateCheck) objIn.readObject(); 570 571 updatechecks.add(uc); 572 } 573 574 objIn.close(); 575 576 if (performInterrupted()) 577 { return; 579 } 580 581 informListeners(customActions, InstallerListener.AFTER_PACK, packs.get(i), 583 new Integer (i), handler); 584 } 585 586 ScriptParser parser = new ScriptParser(parsables, vs); 588 parser.parseFiles(); 589 if (performInterrupted()) 590 { return; 592 } 593 594 FileExecutor executor = new FileExecutor(executables); 596 if (executor.executeFiles(ExecutableFile.POSTINSTALL, handler) != 0) 597 { 598 handler.emitError("File execution failed", "The installation was not completed"); 599 this.result = false; 600 } 601 602 if (performInterrupted()) 603 { return; 605 } 606 607 putUninstaller(); 609 610 performUpdateChecks(updatechecks); 612 613 if (performInterrupted()) 614 { return; 616 } 617 618 informListeners(customActions, InstallerListener.AFTER_PACKS, idata, handler, null); 620 if (performInterrupted()) 621 { return; 623 } 624 625 handler.stopAction(); 627 } 628 catch (Exception err) 629 { 630 handler.stopAction(); 632 handler.emitError("An error occured", err.toString()); 633 err.printStackTrace(); 634 this.result = false; 635 } 636 finally 637 { 638 removeFromInstances(); 639 } 640 } 641 642 645 public boolean getResult() 646 { 647 return this.result; 648 } 649 650 653 private void performUpdateChecks(ArrayList updatechecks) 654 { 655 ArrayList include_patterns = new ArrayList (); 656 ArrayList exclude_patterns = new ArrayList (); 657 658 RECompiler recompiler = new RECompiler(); 659 660 this.absolute_installpath = new File (idata.getInstallPath()).getAbsoluteFile(); 661 662 for (Iterator iter = updatechecks.iterator(); iter.hasNext();) 664 { 665 UpdateCheck uc = (UpdateCheck) iter.next(); 666 667 if (uc.includesList != null) 668 include_patterns.addAll(preparePatterns(uc.includesList, recompiler)); 669 670 if (uc.excludesList != null) 671 exclude_patterns.addAll(preparePatterns(uc.excludesList, recompiler)); 672 } 673 674 if (include_patterns.size() == 0) return; 676 677 680 TreeSet installed_files = new TreeSet (); 682 683 for (Iterator if_it = this.udata.getFilesList().iterator(); if_it.hasNext();) 684 { 685 String fname = (String ) if_it.next(); 686 687 File f = new File (fname); 688 689 if (!f.isAbsolute()) 690 { 691 f = new File (this.absolute_installpath, fname); 692 } 693 694 installed_files.add(f.getAbsolutePath()); 695 } 696 697 Stack scanstack = new Stack (); 702 703 ArrayList files_to_delete = new ArrayList (); 705 706 try 707 { 708 scanstack.add(absolute_installpath); 709 710 while (!scanstack.empty()) 711 { 712 File f = (File ) scanstack.pop(); 713 714 File [] files = f.listFiles(); 715 716 if (files == null) { throw new IOException (f.getPath() + "is not a directory!"); } 717 718 for (int i = 0; i < files.length; i++) 719 { 720 File newf = files[i]; 721 722 String newfname = newf.getPath(); 723 724 if (installed_files.contains(newfname)) continue; 726 727 if (fileMatchesOnePattern(newfname, include_patterns) 728 && (!fileMatchesOnePattern(newfname, exclude_patterns))) 729 { 730 files_to_delete.add(newf); 731 } 732 733 if (newf.isDirectory()) 734 { 735 scanstack.push(newf); 736 } 737 738 } 739 } 740 } 741 catch (IOException e) 742 { 743 this.handler.emitError("error while performing update checks", e.toString()); 744 } 745 746 for (Iterator f_it = files_to_delete.iterator(); f_it.hasNext();) 747 { 748 File f = (File ) f_it.next(); 749 750 if (!f.isDirectory()) 751 { 753 this.handler.emitNotification("deleting " + f.getPath()); 754 f.delete(); 755 } 756 757 } 758 759 } 760 761 767 private boolean fileMatchesOnePattern(String filename, ArrayList patterns) 768 { 769 for (Iterator inc_it = patterns.iterator(); inc_it.hasNext();) 771 { 772 RE pattern = (RE) inc_it.next(); 773 774 if (pattern.match(filename)) { return true; } 775 } 776 777 return false; 778 } 779 780 786 private List preparePatterns(ArrayList list, RECompiler recompiler) 787 { 788 ArrayList result = new ArrayList (); 789 790 for (Iterator iter = list.iterator(); iter.hasNext();) 791 { 792 String element = (String ) iter.next(); 793 794 if ((element != null) && (element.length() > 0)) 795 { 796 element = this.vs.substitute(element, "plain"); 798 799 File f = new File (element); 801 802 if (!f.isAbsolute()) 806 { 807 element = new File (this.absolute_installpath, element).toString(); 808 } 809 810 StringBuffer element_re = new StringBuffer (); 818 819 int lookahead = -1; 820 821 int pos = 0; 822 823 while (pos < element.length()) 824 { 825 char c; 826 827 if (lookahead != -1) 828 { 829 c = (char) lookahead; 830 lookahead = -1; 831 } 832 else 833 c = element.charAt(pos++); 834 835 switch (c) 836 { 837 case '/': { 838 element_re.append(File.separator); 839 break; 840 } 841 case '\\': 843 case '.': { 844 element_re.append("\\"); 845 element_re.append(c); 846 break; 847 } 848 case '*': { 849 if (pos == element.length()) 850 { 851 element_re.append("[^").append(File.separator).append("]*"); 852 break; 853 } 854 855 lookahead = element.charAt(pos++); 856 857 if (lookahead == '*') 859 { 860 element_re.append(".*"); 861 lookahead = -1; 863 } 864 else 865 { 866 element_re.append("[^").append(File.separator).append("]*"); 867 } 869 break; 870 } 871 default: { 872 element_re.append(c); 873 break; 874 } 875 } 877 } 878 879 element_re.append('$'); 881 882 try 884 { 885 result.add(new RE(recompiler.compile(element_re.toString()))); 886 } 887 catch (RESyntaxException e) 888 { 889 this.handler.emitNotification("internal error: pattern \"" + element 890 + "\" produced invalid RE \"" + f.getPath() + "\""); 891 } 892 893 } 894 } 895 896 return result; 897 } 898 899 904 private void putUninstaller() throws Exception 905 { 906 InputStream [] in = new InputStream [2]; 909 in[0] = Unpacker.class.getResourceAsStream("/res/IzPack.uninstaller"); 910 if (in[0] == null) return; 911 in[1] = Unpacker.class.getResourceAsStream("/res/IzPack.uninstaller-ext"); 914 915 String dest = IoHelper.translatePath("$INSTALL_PATH", vs) + File.separator + "Uninstaller"; 917 String jar = dest + File.separator + idata.info.getUninstallerName(); 918 File pathMaker = new File (dest); 919 pathMaker.mkdirs(); 920 921 udata.setUninstallerJarFilename(jar); 923 udata.setUninstallerPath(dest); 924 925 FileOutputStream out = new FileOutputStream (jar); 927 BufferedOutputStream bos = new BufferedOutputStream (out); 929 ZipOutputStream outJar = new ZipOutputStream (bos); 930 idata.uninstallOutJar = outJar; 931 outJar.setLevel(9); 932 udata.addFile(jar); 933 934 HashSet doubles = new HashSet (); 936 937 for (int i = 0; i < in.length; ++i) 938 { 939 if (in[i] == null) continue; 940 ZipInputStream inRes = new ZipInputStream (in[i]); 941 ZipEntry zentry = inRes.getNextEntry(); 942 while (zentry != null) 943 { 944 if (!doubles.contains(zentry.getName())) 946 { 947 doubles.add(zentry.getName()); 948 outJar.putNextEntry(new ZipEntry (zentry.getName())); 949 950 int unc = inRes.read(); 952 while (unc != -1) 953 { 954 outJar.write(unc); 955 unc = inRes.read(); 956 } 957 958 inRes.closeEntry(); 960 outJar.closeEntry(); 961 } 962 zentry = inRes.getNextEntry(); 963 } 964 inRes.close(); 965 } 966 967 InputStream in2 = Unpacker.class.getResourceAsStream("/langpacks/" + idata.localeISO3 969 + ".xml"); 970 outJar.putNextEntry(new ZipEntry ("langpack.xml")); 971 int read = in2.read(); 972 while (read != -1) 973 { 974 outJar.write(read); 975 read = in2.read(); 976 } 977 outJar.closeEntry(); 978 } 979 980 987 private InputStream getPackAsStream(int n) throws Exception 988 { 989 InputStream in = null; 990 991 String webDirURL = idata.info.getWebDirURL(); 992 993 if (webDirURL == null) { 995 in = Unpacker.class.getResourceAsStream("/packs/pack" + n); 996 } 997 else 998 { 1000 1004 String baseName = idata.info.getInstallerBase(); 1006 String packURL = webDirURL + "/" + baseName + ".pack" + n + ".jar"; 1007 URL url = new URL ("jar:" + packURL + "!/packs/pack" + n); 1008 in = new WebAccessor(null).openInputStream(url); 1012 if (in == null) throw new FileNotFoundException (url.toString()); 1015 } 1016 if( in != null && idata.info.getPackDecoderClassName() != null ) 1017 { 1018 Class decoder = Class.forName(idata.info.getPackDecoderClassName()); 1019 Class [] paramsClasses = new Class [1]; 1020 paramsClasses[0] = Class.forName("java.io.InputStream"); 1021 Constructor constructor = decoder.getDeclaredConstructor(paramsClasses); 1022 InputStream buffer = new BufferedInputStream (in); 1026 Object [] params = { buffer }; 1027 Object instance = null; 1028 instance = constructor.newInstance( params); 1029 if (!InputStream .class.isInstance(instance)) 1030 throw new InstallerException( "'" + idata.info.getPackDecoderClassName() 1031 + "' must be derived from " 1032 + InputStream .class.toString()); 1033 in = (InputStream ) instance; 1034 1035 } 1036 return in; 1037 } 1038 1039 1041 1050 private void informListeners(List [] customActions, int action, Object firstParam, 1051 Object secondParam, Object thirdParam) throws Exception 1052 { 1053 List listener = null; 1054 switch (action) 1056 { 1057 case InstallerListener.BEFORE_FILE: 1058 case InstallerListener.AFTER_FILE: 1059 case InstallerListener.BEFORE_DIR: 1060 case InstallerListener.AFTER_DIR: 1061 listener = customActions[customActions.length - 1]; 1062 break; 1063 default: 1064 listener = customActions[0]; 1065 break; 1066 } 1067 if (listener == null) return; 1068 Iterator iter = listener.iterator(); 1070 while (iter.hasNext()) 1071 { 1072 if (shouldInterrupt()) return; 1073 InstallerListener il = (InstallerListener) iter.next(); 1074 switch (action) 1075 { 1076 case InstallerListener.BEFORE_FILE: 1077 il.beforeFile((File ) firstParam, (PackFile) secondParam); 1078 break; 1079 case InstallerListener.AFTER_FILE: 1080 il.afterFile((File ) firstParam, (PackFile) secondParam); 1081 break; 1082 case InstallerListener.BEFORE_DIR: 1083 il.beforeDir((File ) firstParam, (PackFile) secondParam); 1084 break; 1085 case InstallerListener.AFTER_DIR: 1086 il.afterDir((File ) firstParam, (PackFile) secondParam); 1087 break; 1088 case InstallerListener.BEFORE_PACK: 1089 il.beforePack((Pack) firstParam, (Integer ) secondParam, 1090 (AbstractUIProgressHandler) thirdParam); 1091 break; 1092 case InstallerListener.AFTER_PACK: 1093 il.afterPack((Pack) firstParam, (Integer ) secondParam, 1094 (AbstractUIProgressHandler) thirdParam); 1095 break; 1096 case InstallerListener.BEFORE_PACKS: 1097 il.beforePacks((AutomatedInstallData) firstParam, (Integer ) secondParam, 1098 (AbstractUIProgressHandler) thirdParam); 1099 break; 1100 case InstallerListener.AFTER_PACKS: 1101 il.afterPacks((AutomatedInstallData) firstParam, 1102 (AbstractUIProgressHandler) secondParam); 1103 break; 1104 1105 } 1106 } 1107 } 1108 1109 1115 private List [] getCustomActions() 1116 { 1117 String [] listenerNames = AutomatedInstallData.CUSTOM_ACTION_TYPES; 1118 List [] retval = new List [listenerNames.length + 1]; 1119 int i; 1120 for (i = 0; i < listenerNames.length; ++i) 1121 { 1122 retval[i] = (List ) idata.customData.get(listenerNames[i]); 1123 if (retval[i] == null) 1124 retval[i] = new ArrayList (); 1126 } 1127 if (retval[AutomatedInstallData.INSTALLER_LISTENER_INDEX].size() > 0) 1128 { i = retval.length - 1; retval[i] = new ArrayList (); 1133 Iterator iter = ((List ) retval[AutomatedInstallData.INSTALLER_LISTENER_INDEX]) 1134 .iterator(); 1135 while (iter.hasNext()) 1136 { 1137 InstallerListener li = (InstallerListener) iter.next(); 1140 if (li.isFileListener()) retval[i].add(li); 1141 } 1142 1143 } 1144 return (retval); 1145 } 1146 1147 1153 private void handleAdditionalUninstallData(UninstallData udata, List [] customData) 1154 { 1155 udata.addAdditionalData("__uninstallLibs__", 1157 customData[AutomatedInstallData.UNINSTALLER_LIBS_INDEX]); 1158 udata.addAdditionalData("uninstallerListeners", 1160 customData[AutomatedInstallData.UNINSTALLER_LISTENER_INDEX]); 1161 udata.addAdditionalData("uninstallerJars", 1163 customData[AutomatedInstallData.UNINSTALLER_JARS_INDEX]); 1164 } 1165 1166 1177 1178 private boolean mkDirsWithEnhancement(File dest, PackFile pf, List [] customActions) 1179 throws Exception 1180 { 1181 String path = "unknown"; 1182 if (dest != null) path = dest.getAbsolutePath(); 1183 if (dest != null && !dest.exists() && dest.getParentFile() != null) 1184 { 1185 if (dest.getParentFile().exists()) 1186 informListeners(customActions, InstallerListener.BEFORE_DIR, dest, pf, null); 1187 if (!dest.mkdir()) 1188 { 1189 mkDirsWithEnhancement(dest.getParentFile(), pf, customActions); 1190 if (!dest.mkdir()) dest = null; 1191 } 1192 informListeners(customActions, InstallerListener.AFTER_DIR, dest, pf, null); 1193 } 1194 if (dest == null) 1195 { 1196 handler.emitError("Error creating directories", "Could not create directory\n" + path); 1197 handler.stopAction(); 1198 return (false); 1199 } 1200 return (true); 1201 } 1202 1203 1205 1210 public static synchronized boolean isDiscardInterrupt() 1211 { 1212 return discardInterrupt; 1213 } 1214 1215 1220 public static synchronized void setDiscardInterrupt(boolean di) 1221 { 1222 discardInterrupt = di; 1223 setInterruptDesired(false); 1224 } 1225 1226 1231 public static boolean isInterruptDesired() 1232 { 1233 return interruptDesired; 1234 } 1235 1236 1239 private static void setInterruptDesired(boolean interruptDesired) 1240 { 1241 Unpacker.interruptDesired = interruptDesired; 1242 } 1243} 1244 | Popular Tags |