001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/ http://izpack.codehaus.org/
005: *
006: * Copyright 2007 Dennis Reil
007: *
008: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
009: * in compliance with the License. You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software distributed under the License
014: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
015: * or implied. See the License for the specific language governing permissions and limitations under
016: * the License.
017: */
018: package com.izforge.izpack.installer;
019:
020: import java.io.File;
021: import java.lang.reflect.Method;
022:
023: import com.izforge.izpack.uninstaller.SelfModifier;
024: import com.izforge.izpack.util.Debug;
025:
026: /**
027: * Main class, for starting the installer if it was build to support more than one volume.
028: *
029: * @author Dennis Reil, <Dennis.Reil@reddot.de>
030: *
031: */
032: public class MultiVolumeInstaller {
033:
034: // where is the installer looking for media files
035: protected static String mediadirectory;
036:
037: /**
038: * @param args
039: */
040: public static void main(String[] args) {
041: // default is to look in the current directory
042: MultiVolumeInstaller.setMediadirectory(new File(".")
043: .getParent());
044: if ((args.length > 0) && ("-direct".equals(args[0]))) {
045: String[] newargs;
046: if (args.length > 1) {
047: // cut out the direct parameter
048: newargs = new String[args.length - 1];
049: System.arraycopy(args, 1, newargs, 0, args.length - 1);
050: } else {
051: // set arguments to empty string array
052: newargs = new String[0];
053: }
054: MultiVolumeInstaller.install(newargs);
055: } else {
056: try {
057: Class<MultiVolumeInstaller> clazz = MultiVolumeInstaller.class;
058: Method target = clazz.getMethod("install",
059: new Class[] { String[].class });
060: String[] newargs = new String[args.length + 2];
061:
062: System.arraycopy(args, 0, newargs, 2, args.length);
063: // try to find the directory, where the jar file is located, this class was loaded
064: // from
065: newargs[0] = "-mediadir";
066: newargs[1] = SelfModifier.findJarFile(clazz)
067: .getParent();
068: System.out.println("Setting mediadir: " + newargs[1]);
069: MultiVolumeInstaller.setMediadirectory(SelfModifier
070: .findJarFile(clazz).getParent());
071: new SelfModifier(target).invoke(newargs);
072: } catch (Exception e) {
073: Debug.trace(e);
074: }
075: }
076: }
077:
078: public static String getMediadirectory() {
079: return MultiVolumeInstaller.mediadirectory;
080: }
081:
082: public static void setMediadirectory(String mediadirectory) {
083: MultiVolumeInstaller.mediadirectory = mediadirectory;
084: }
085:
086: public static void install(String[] args) {
087: if ((args.length >= 2) && ("-mediadir".equals(args[0]))) {
088: // mediadir option given
089: MultiVolumeInstaller.setMediadirectory(args[1]);
090: if (args.length > 2) {
091: // cut out this option
092: String[] newargs = new String[args.length - 2];
093: System.arraycopy(args, 2, newargs, 0, args.length - 2);
094: args = newargs;
095: } else {
096: // put in an empty string array
097: args = new String[0];
098: }
099: }
100: // just call the izpack installer
101: Installer.main(args);
102: }
103: }
|