KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > installer > Install


1 /*
2  * Install.java - Main class of the installer
3  *
4  * Originally written by Slava Pestov for the jEdit installer project. This work
5  * has been placed into the public domain. You may use this work in any way and
6  * for any purpose you wish.
7  *
8  * THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, NOT EVEN THE
9  * IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR OF THIS SOFTWARE, ASSUMES
10  * _NO_ RESPONSIBILITY FOR ANY CONSEQUENCE RESULTING FROM THE USE, MODIFICATION,
11  * OR REDISTRIBUTION OF THIS SOFTWARE.
12  */

13
14 package installer;
15
16 import javax.swing.plaf.metal.*;
17 import javax.swing.*;
18 import java.io.*;
19 import java.util.Properties JavaDoc;
20
21 public class Install
22 {
23     public static void main(String JavaDoc[] args)
24     {
25         String JavaDoc 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 JavaDoc();
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 JavaDoc getProperty(String JavaDoc name)
71     {
72         return props.getProperty(name);
73     }
74
75     public int getIntegerProperty(String JavaDoc name)
76     {
77         try
78         {
79             return Integer.parseInt(props.getProperty(name));
80         }
81         catch(Exception JavaDoc e)
82         {
83             return -1;
84         }
85     }
86
87     public void copy(InputStream in, String JavaDoc 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         //in.close();
111
out.close();
112     }
113
114     // private members
115
private Properties JavaDoc props;
116     private byte[] buf;
117 }
118
Popular Tags