01: /*
02: * InstallThread.java
03: *
04: * Originally written by Slava Pestov for the jEdit installer project. This work
05: * has been placed into the public domain. You may use this work in any way and
06: * for any purpose you wish.
07: *
08: * THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, NOT EVEN THE
09: * 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: package installer;
14:
15: import java.io.*;
16: import java.util.Vector;
17:
18: /*
19: * The thread that performs installation.
20: */
21: public class InstallThread extends Thread {
22: public InstallThread(Install installer, Progress progress,
23: String installDir, OperatingSystem.OSTask[] osTasks,
24: int size, Vector components) {
25: super ("Install thread");
26:
27: this .installer = installer;
28: this .progress = progress;
29: this .installDir = installDir;
30: this .osTasks = osTasks;
31: this .size = size;
32: this .components = components;
33: }
34:
35: public void run() {
36: progress.setMaximum(size * 1024);
37:
38: try {
39: // install user-selected packages
40: for (int i = 0; i < components.size(); i++) {
41: String comp = (String) components.elementAt(i);
42: System.err.println("Installing " + comp);
43: installComponent(comp);
44: }
45:
46: // do operating system specific stuff (creating startup
47: // scripts, installing man pages, etc.)
48: for (int i = 0; i < osTasks.length; i++) {
49: System.err.println("Performing task "
50: + osTasks[i].getName());
51: osTasks[i].perform(installDir, components);
52: }
53: } catch (FileNotFoundException fnf) {
54: progress.error("The installer could not create the "
55: + "destination directory.\n"
56: + "Maybe you do not have write permission?");
57: return;
58: } catch (IOException io) {
59: progress.error(io.toString());
60: return;
61: }
62:
63: progress.done();
64: }
65:
66: // private members
67: private Install installer;
68: private Progress progress;
69: private String installDir;
70: private OperatingSystem.OSTask[] osTasks;
71: private int size;
72: private Vector components;
73:
74: private void installComponent(String name) throws IOException {
75: InputStream in = new BufferedInputStream(getClass()
76: .getResourceAsStream(name + ".tar.bz2"));
77: // skip header bytes
78: // maybe should check if they're valid or not?
79: in.read();
80: in.read();
81:
82: TarInputStream tarInput = new TarInputStream(
83: new CBZip2InputStream(in));
84: TarEntry entry;
85: while ((entry = tarInput.getNextEntry()) != null) {
86: if (entry.isDirectory())
87: continue;
88: String fileName = entry.getName();
89: //System.err.println(fileName);
90: String outfile = installDir + File.separatorChar
91: + fileName.replace('/', File.separatorChar);
92: installer.copy(tarInput, outfile, progress);
93: }
94:
95: tarInput.close();
96: }
97: }
|