PageRenderTime 109ms CodeModel.GetById 99ms app.highlight 8ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 130 lines | 85 code | 21 blank | 24 comment | 18 complexity | f5e58a3eec7a8721f32eb765b4f18bd4 MD5 | raw file
  1/*
  2 * ConsoleInstall.java
  3 * Copyright (C) 1999, 2000 Slava Pestov
  4 *
  5 * This program is free software; you can redistribute it and/or
  6 * modify it under the terms of the GNU General Public License
  7 * as published by the Free Software Foundation; either version 2
  8 * of the License, or any later version.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU General Public License
 16 * along with this program; if not, write to the Free Software
 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 18 */
 19
 20package installer;
 21
 22import java.io.*;
 23import java.util.Vector;
 24
 25/*
 26 * Performs text-only installation.
 27 */
 28public class ConsoleInstall
 29{
 30	public ConsoleInstall()
 31	{
 32		installer = new Install();
 33
 34		String appName = installer.getProperty("app.name");
 35		String appVersion = installer.getProperty("app.version");
 36
 37		BufferedReader in = new BufferedReader(new InputStreamReader(
 38			System.in));
 39
 40		System.out.println("*** " + appName + " " + appVersion + " installer");
 41
 42		OperatingSystem os = OperatingSystem.getOperatingSystem();
 43
 44		String installDir = OperatingSystem.getOperatingSystem()
 45			.getInstallDirectory(appName,appVersion);
 46
 47		System.out.print("Installation directory [" + installDir + "]: ");
 48		System.out.flush();
 49
 50		String _installDir = readLine(in);
 51		if(_installDir.length() != 0)
 52			installDir = _installDir;
 53
 54		String binDir = OperatingSystem.getOperatingSystem()
 55			.getShortcutDirectory(appName,appVersion);
 56
 57		if(binDir != null)
 58		{
 59			System.out.print("Shortcut directory [" + binDir + "]: ");
 60			System.out.flush();
 61
 62			String _binDir = readLine(in);
 63			if(_binDir.length() != 0)
 64				binDir = _binDir;
 65		}
 66
 67		int compCount = installer.getIntProperty("comp.count");
 68		Vector components = new Vector(compCount);
 69
 70		System.out.println("*** Program components to install");
 71		for(int i = 0; i < compCount; i++)
 72		{
 73			String fileset = installer.getProperty("comp." + i + ".fileset");
 74
 75			String osDep = installer.getProperty("comp." + i + ".os");
 76			if(osDep != null)
 77			{
 78				if(!OperatingSystem.getOperatingSystem()
 79					.getClass().getName().endsWith(osDep))
 80				{
 81					continue;
 82				}
 83			}
 84
 85			System.out.print("Install "
 86				+ installer.getProperty("comp." + i + ".name")
 87				+ " ("
 88				+ installer.getProperty("comp." + i + ".disk-size")
 89				+ "Kb) [Y/n]? ");
 90
 91			String line = readLine(in);
 92			if(line.length() == 0 || line.charAt(0) == 'y'
 93				|| line.charAt(0) == 'Y')
 94				components.addElement(fileset);
 95		}
 96
 97		System.out.println("*** Starting installation...");
 98		ConsoleProgress progress = new ConsoleProgress();
 99		InstallThread thread = new InstallThread(
100			installer,progress,installDir,binDir,
101			0 /* XXX */,components);
102		thread.start();
103	}
104
105	// private members
106	private Install installer;
107
108	private String readLine(BufferedReader in)
109	{
110		try
111		{
112			String line = in.readLine();
113			if(line == null)
114			{
115				System.err.println("\nEOF in input!");
116				System.exit(1);
117				// can't happen
118				throw new InternalError();
119			}
120			return line;
121		}
122		catch(IOException io)
123		{
124			System.err.println("\nI/O error: " + io);
125			System.exit(1);
126			// can't happen
127			throw new InternalError();
128		}
129	}
130}