PageRenderTime 278ms CodeModel.GetById 271ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/installer/ConsoleInstall.java

#
Java | 134 lines | 94 code | 21 blank | 19 comment | 20 complexity | 374dabb578ff3130dbab45d15f0cb354 MD5 | raw file
  1/*
  2 * ConsoleInstall.java
  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 java.io.*;
 17import java.util.Vector;
 18
 19/*
 20 * Performs text-only installation.
 21 */
 22public class ConsoleInstall
 23{
 24	public ConsoleInstall()
 25	{
 26		installer = new Install();
 27
 28		String appName = installer.getProperty("app.name");
 29		String appVersion = installer.getProperty("app.version");
 30
 31		BufferedReader in = new BufferedReader(new InputStreamReader(
 32			System.in));
 33
 34		System.out.println("*** " + appName + " " + appVersion + " installer");
 35
 36		OperatingSystem os = OperatingSystem.getOperatingSystem();
 37
 38		String installDir = os.getInstallDirectory(appName,appVersion);
 39
 40		System.out.print("Installation directory: [" + installDir + "] ");
 41		System.out.flush();
 42
 43		String _installDir = readLine(in);
 44		if(_installDir.length() != 0)
 45			installDir = _installDir;
 46
 47		OperatingSystem.OSTask[] osTasks = os.getOSTasks(installer);
 48
 49		for(int i = 0; i < osTasks.length; i++)
 50		{
 51			OperatingSystem.OSTask osTask = osTasks[i];
 52			String label = osTask.getLabel();
 53			// label == null means no configurable options
 54			if(label != null)
 55			{
 56				String dir = osTask.getDirectory();
 57				System.out.print(label + " [" + dir + "] ");
 58				System.out.flush();
 59
 60				dir = readLine(in);
 61				osTask.setEnabled(true);
 62				if(dir.length() != 0)
 63				{
 64					if(dir.equals("off"))
 65						osTask.setEnabled(false);
 66					else
 67						osTask.setDirectory(dir);
 68				}
 69			}
 70		}
 71
 72		int compCount = installer.getIntegerProperty("comp.count");
 73		Vector components = new Vector(compCount);
 74
 75		System.out.println("*** Program components to install");
 76		for(int i = 0; i < compCount; i++)
 77		{
 78			String fileset = installer.getProperty("comp." + i + ".fileset");
 79
 80			String osDep = installer.getProperty("comp." + i + ".os");
 81			if(osDep != null)
 82			{
 83				if(!os.getClass().getName().endsWith(osDep))
 84				{
 85					continue;
 86				}
 87			}
 88
 89			System.out.print("Install "
 90				+ installer.getProperty("comp." + i + ".name")
 91				+ " ("
 92				+ installer.getProperty("comp." + i + ".disk-size")
 93				+ "Kb) [Y/n]? ");
 94
 95			String line = readLine(in);
 96			if(line.length() == 0 || line.charAt(0) == 'y'
 97				|| line.charAt(0) == 'Y')
 98				components.addElement(fileset);
 99		}
100
101		System.out.println("*** Starting installation...");
102		ConsoleProgress progress = new ConsoleProgress();
103		InstallThread thread = new InstallThread(
104			installer,progress,installDir,osTasks,
105			0 /* XXX */,components);
106		thread.start();
107	}
108
109	// private members
110	private Install installer;
111
112	private String readLine(BufferedReader in)
113	{
114		try
115		{
116			String line = in.readLine();
117			if(line == null)
118			{
119				System.err.println("\nEOF in input!");
120				System.exit(1);
121				// can't happen
122				throw new InternalError();
123			}
124			return line;
125		}
126		catch(IOException io)
127		{
128			System.err.println("\nI/O error: " + io);
129			System.exit(1);
130			// can't happen
131			throw new InternalError();
132		}
133	}
134}