1 13 14 package installer; 15 16 import java.io.*; 17 import java.util.Vector ; 18 19 22 public class ConsoleInstall 23 { 24 public ConsoleInstall() 25 { 26 installer = new Install(); 27 28 String appName = installer.getProperty("app.name"); 29 String appVersion = installer.getProperty("app.version"); 30 31 BufferedReader in = new BufferedReader(new InputStreamReader( 32 System.in)); 33 34 System.out.println("*** " + appName + " " + appVersion + " installer"); 35 36 OperatingSystem os = OperatingSystem.getOperatingSystem(); 37 38 String installDir = os.getInstallDirectory(appName,appVersion); 39 40 System.out.print("Installation directory: [" + installDir + "] "); 41 System.out.flush(); 42 43 String _installDir = readLine(in); 44 if(_installDir.length() != 0) 45 installDir = _installDir; 46 47 OperatingSystem.OSTask[] osTasks = os.getOSTasks(installer); 48 49 for(int i = 0; i < osTasks.length; i++) 50 { 51 OperatingSystem.OSTask osTask = osTasks[i]; 52 String label = osTask.getLabel(); 53 if(label != null) 55 { 56 String dir = osTask.getDirectory(); 57 System.out.print(label + " [" + dir + "] "); 58 System.out.flush(); 59 60 dir = readLine(in); 61 osTask.setEnabled(true); 62 if(dir.length() != 0) 63 { 64 if(dir.equals("off")) 65 osTask.setEnabled(false); 66 else 67 osTask.setDirectory(dir); 68 } 69 } 70 } 71 72 int compCount = installer.getIntegerProperty("comp.count"); 73 Vector components = new Vector (compCount); 74 75 System.out.println("*** Program components to install"); 76 for(int i = 0; i < compCount; i++) 77 { 78 String fileset = installer.getProperty("comp." + i + ".fileset"); 79 80 String osDep = installer.getProperty("comp." + i + ".os"); 81 if(osDep != null) 82 { 83 if(!os.getClass().getName().endsWith(osDep)) 84 { 85 continue; 86 } 87 } 88 89 System.out.print("Install " 90 + installer.getProperty("comp." + i + ".name") 91 + " (" 92 + installer.getProperty("comp." + i + ".disk-size") 93 + "Kb) [Y/n]? "); 94 95 String line = readLine(in); 96 if(line.length() == 0 || line.charAt(0) == 'y' 97 || line.charAt(0) == 'Y') 98 components.addElement(fileset); 99 } 100 101 System.out.println("*** Starting installation..."); 102 ConsoleProgress progress = new ConsoleProgress(); 103 InstallThread thread = new InstallThread( 104 installer,progress,installDir,osTasks, 105 0 ,components); 106 thread.start(); 107 } 108 109 private Install installer; 111 112 private String readLine(BufferedReader in) 113 { 114 try 115 { 116 String line = in.readLine(); 117 if(line == null) 118 { 119 System.err.println("\nEOF in input!"); 120 System.exit(1); 121 throw new InternalError (); 123 } 124 return line; 125 } 126 catch(IOException io) 127 { 128 System.err.println("\nI/O error: " + io); 129 System.exit(1); 130 throw new InternalError (); 132 } 133 } 134 } 135 | Popular Tags |