/jEdit/tags/jedit-4-3-pre5/installer/Install.java
Java | 117 lines | 87 code | 16 blank | 14 comment | 17 complexity | 9b021f49be1ef63850faa099f4b04343 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
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
14package installer;
15
16import javax.swing.plaf.metal.*;
17import javax.swing.*;
18import java.io.*;
19import java.util.Properties;
20
21public 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 //in.close();
111 out.close();
112 }
113
114 // private members
115 private Properties props;
116 private byte[] buf;
117}