1 13 14 package installer; 15 16 import javax.swing.plaf.metal.*; 17 import javax.swing.*; 18 import java.io.*; 19 import java.util.Properties ; 20 21 public class Install 22 { 23 public static void main(String [] args) 24 { 25 String javaVersion = System.getProperty("java.version"); 26 if(javaVersion.compareTo("1.3") < 0) 27 { 28 System.err.println("You are running Java version " 29 + javaVersion + "."); 30 System.err.println("This installer requires Java 1.3 or later."); 31 System.exit(1); 32 } 33 34 if(args.length == 0) 35 new SwingInstall(); 36 else if(args.length == 1 && args[0].equals("text")) 37 new ConsoleInstall(); 38 else if(args.length >= 2 && args[0].equals("auto")) 39 new NonInteractiveInstall(args); 40 else 41 { 42 System.err.println("Usage:"); 43 System.err.println("java -jar <installer JAR>"); 44 System.err.println("java -jar <installer JAR> text"); 45 System.err.println("java -jar <installer JAR> auto" 46 + " <install dir> [unix-script=<dir>] [unix-man=<dir>]"); 47 System.err.println("text parameter starts installer in text-only mode."); 48 System.err.println("auto parameter starts installer in non-interactive mode."); 49 } 50 } 51 52 public Install() 53 { 54 props = new Properties (); 55 try 56 { 57 InputStream in = getClass().getResourceAsStream("/installer/install.props"); 58 props.load(in); 59 in.close(); 60 } 61 catch(IOException io) 62 { 63 System.err.println("Error loading 'install.props':"); 64 io.printStackTrace(); 65 } 66 67 buf = new byte[32768]; 68 } 69 70 public String getProperty(String name) 71 { 72 return props.getProperty(name); 73 } 74 75 public int getIntegerProperty(String name) 76 { 77 try 78 { 79 return Integer.parseInt(props.getProperty(name)); 80 } 81 catch(Exception e) 82 { 83 return -1; 84 } 85 } 86 87 public void copy(InputStream in, String outfile, Progress progress) 88 throws IOException 89 { 90 File outFile = new File(outfile); 91 92 OperatingSystem.getOperatingSystem().mkdirs(outFile.getParent()); 93 94 BufferedOutputStream out = new BufferedOutputStream( 95 new FileOutputStream(outFile)); 96 97 int count; 98 99 for(;;) 100 { 101 count = in.read(buf,0,Math.min(in.available(),buf.length)); 102 if(count == -1 || count == 0) 103 break; 104 105 out.write(buf,0,count); 106 if(progress != null) 107 progress.advance(count); 108 } 109 110 out.close(); 112 } 113 114 private Properties props; 116 private byte[] buf; 117 } 118 | Popular Tags |