1 13 package installer; 14 15 import java.io.*; 16 import java.util.Vector ; 17 18 21 public class InstallThread extends Thread 22 { 23 public InstallThread(Install installer, Progress progress, 24 String installDir, OperatingSystem.OSTask[] osTasks, 25 int size, Vector components) 26 { 27 super("Install thread"); 28 29 this.installer = installer; 30 this.progress = progress; 31 this.installDir = installDir; 32 this.osTasks = osTasks; 33 this.size = size; 34 this.components = components; 35 } 36 37 public void run() 38 { 39 progress.setMaximum(size * 1024); 40 41 try 42 { 43 for(int i = 0; i < components.size(); i++) 45 { 46 String comp = (String )components.elementAt(i); 47 System.err.println("Installing " + comp); 48 installComponent(comp); 49 } 50 51 for(int i = 0; i < osTasks.length; i++) 54 { 55 System.err.println("Performing task " + 56 osTasks[i].getName()); 57 osTasks[i].perform(installDir,components); 58 } 59 } 60 catch(FileNotFoundException fnf) 61 { 62 progress.error("The installer could not create the " 63 + "destination directory.\n" 64 + "Maybe you do not have write permission?"); 65 return; 66 } 67 catch(IOException io) 68 { 69 progress.error(io.toString()); 70 return; 71 } 72 73 progress.done(); 74 } 75 76 private Install installer; 78 private Progress progress; 79 private String installDir; 80 private OperatingSystem.OSTask[] osTasks; 81 private int size; 82 private Vector components; 83 84 private void installComponent(String name) throws IOException 85 { 86 InputStream in = new BufferedInputStream( 87 getClass().getResourceAsStream(name + ".tar.bz2")); 88 in.read(); 91 in.read(); 92 93 TarInputStream tarInput = new TarInputStream( 94 new CBZip2InputStream(in)); 95 TarEntry entry; 96 while((entry = tarInput.getNextEntry()) != null) 97 { 98 if(entry.isDirectory()) 99 continue; 100 String fileName = entry.getName(); 101 String outfile = installDir + File.separatorChar 103 + fileName.replace('/',File.separatorChar); 104 installer.copy(tarInput,outfile,progress); 105 } 106 107 tarInput.close(); 108 } 109 } 110 | Popular Tags |