001: /*
002: * ConsoleInstall.java
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 java.io.*;
017: import java.util.Vector;
018:
019: /*
020: * Performs text-only installation.
021: */
022: public class ConsoleInstall {
023: public ConsoleInstall() {
024: installer = new Install();
025:
026: String appName = installer.getProperty("app.name");
027: String appVersion = installer.getProperty("app.version");
028:
029: BufferedReader in = new BufferedReader(new InputStreamReader(
030: System.in));
031:
032: System.out.println("*** " + appName + " " + appVersion
033: + " installer");
034:
035: OperatingSystem os = OperatingSystem.getOperatingSystem();
036:
037: String installDir = os.getInstallDirectory(appName, appVersion);
038:
039: System.out.print("Installation directory: [" + installDir
040: + "] ");
041: System.out.flush();
042:
043: String _installDir = readLine(in);
044: if (_installDir.length() != 0)
045: installDir = _installDir;
046:
047: OperatingSystem.OSTask[] osTasks = os.getOSTasks(installer);
048:
049: for (int i = 0; i < osTasks.length; i++) {
050: OperatingSystem.OSTask osTask = osTasks[i];
051: String label = osTask.getLabel();
052: // label == null means no configurable options
053: if (label != null) {
054: String dir = osTask.getDirectory();
055: System.out.print(label + " [" + dir + "] ");
056: System.out.flush();
057:
058: dir = readLine(in);
059: osTask.setEnabled(true);
060: if (dir.length() != 0) {
061: if (dir.equals("off"))
062: osTask.setEnabled(false);
063: else
064: osTask.setDirectory(dir);
065: }
066: }
067: }
068:
069: int compCount = installer.getIntegerProperty("comp.count");
070: Vector components = new Vector(compCount);
071:
072: System.out.println("*** Program components to install");
073: for (int i = 0; i < compCount; i++) {
074: String fileset = installer.getProperty("comp." + i
075: + ".fileset");
076:
077: String osDep = installer.getProperty("comp." + i + ".os");
078: if (osDep != null) {
079: if (!os.getClass().getName().endsWith(osDep)) {
080: continue;
081: }
082: }
083:
084: System.out.print("Install "
085: + installer.getProperty("comp." + i + ".name")
086: + " ("
087: + installer.getProperty("comp." + i + ".disk-size")
088: + "Kb) [Y/n]? ");
089:
090: String line = readLine(in);
091: if (line.length() == 0 || line.charAt(0) == 'y'
092: || line.charAt(0) == 'Y')
093: components.addElement(fileset);
094: }
095:
096: System.out.println("*** Starting installation...");
097: ConsoleProgress progress = new ConsoleProgress();
098: InstallThread thread = new InstallThread(installer, progress,
099: installDir, osTasks, 0 /* XXX */, components);
100: thread.start();
101: }
102:
103: // private members
104: private Install installer;
105:
106: private String readLine(BufferedReader in) {
107: try {
108: String line = in.readLine();
109: if (line == null) {
110: System.err.println("\nEOF in input!");
111: System.exit(1);
112: // can't happen
113: throw new InternalError();
114: }
115: return line;
116: } catch (IOException io) {
117: System.err.println("\nI/O error: " + io);
118: System.exit(1);
119: // can't happen
120: throw new InternalError();
121: }
122: }
123: }
|