001: /*
002: * Install.java - Main class of the installer
003: *
004: * Originally written by Slava Pestov for the jEdit installer project. This work
005: * has been placed into the public domain. You may use this work in any way and
006: * for any purpose you wish.
007: *
008: * THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, NOT EVEN THE
009: * IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR OF THIS SOFTWARE, ASSUMES
010: * _NO_ RESPONSIBILITY FOR ANY CONSEQUENCE RESULTING FROM THE USE, MODIFICATION,
011: * OR REDISTRIBUTION OF THIS SOFTWARE.
012: */
013:
014: package installer;
015:
016: import javax.swing.plaf.metal.*;
017: import javax.swing.*;
018: import java.io.*;
019: import java.util.Properties;
020:
021: public class Install {
022: public static void main(String[] args) {
023: String javaVersion = System.getProperty("java.version");
024: if (javaVersion.compareTo("1.3") < 0) {
025: System.err.println("You are running Java version "
026: + javaVersion + ".");
027: System.err
028: .println("This installer requires Java 1.3 or later.");
029: System.exit(1);
030: }
031:
032: if (args.length == 0)
033: new SwingInstall();
034: else if (args.length == 1 && args[0].equals("text"))
035: new ConsoleInstall();
036: else if (args.length >= 2 && args[0].equals("auto"))
037: new NonInteractiveInstall(args);
038: else {
039: System.err.println("Usage:");
040: System.err.println("java -jar <installer JAR>");
041: System.err.println("java -jar <installer JAR> text");
042: System.err
043: .println("java -jar <installer JAR> auto"
044: + " <install dir> [unix-script=<dir>] [unix-man=<dir>]");
045: System.err
046: .println("text parameter starts installer in text-only mode.");
047: System.err
048: .println("auto parameter starts installer in non-interactive mode.");
049: }
050: }
051:
052: public Install() {
053: props = new Properties();
054: try {
055: InputStream in = getClass().getResourceAsStream(
056: "/installer/install.props");
057: props.load(in);
058: in.close();
059: } catch (IOException io) {
060: System.err.println("Error loading 'install.props':");
061: io.printStackTrace();
062: }
063:
064: buf = new byte[32768];
065: }
066:
067: public String getProperty(String name) {
068: return props.getProperty(name);
069: }
070:
071: public int getIntegerProperty(String name) {
072: try {
073: return Integer.parseInt(props.getProperty(name));
074: } catch (Exception e) {
075: return -1;
076: }
077: }
078:
079: public void copy(InputStream in, String outfile, Progress progress)
080: throws IOException {
081: File outFile = new File(outfile);
082:
083: OperatingSystem.getOperatingSystem()
084: .mkdirs(outFile.getParent());
085:
086: BufferedOutputStream out = new BufferedOutputStream(
087: new FileOutputStream(outFile));
088:
089: int count;
090:
091: for (;;) {
092: count = in.read(buf, 0, Math
093: .min(in.available(), buf.length));
094: if (count == -1 || count == 0)
095: break;
096:
097: out.write(buf, 0, count);
098: if (progress != null)
099: progress.advance(count);
100: }
101:
102: //in.close();
103: out.close();
104: }
105:
106: // private members
107: private Properties props;
108: private byte[] buf;
109: }
|