private BufferedWriter getExternLogFile(AutomatedInstallData installdata) {
    String logfile = installdata.getVariable(LOGFILE_PATH);
    BufferedWriter extLogWriter = null;
    if (logfile != null) {
      if (logfile.toLowerCase().startsWith("default")) {
        logfile = installdata.getInfo().getUninstallerPath() + "/install.log";
      }
      logfile = IoHelper.translatePath(logfile, variableSubstitutor);
      File outFile = new File(logfile);
      if (!outFile.getParentFile().exists()) {
        outFile.getParentFile().mkdirs();
      }
      FileOutputStream out = null;
      try {
        out = new FileOutputStream(outFile);
      } catch (FileNotFoundException e) {
        Debug.trace("Cannot create logfile!");
        Debug.error(e);
      }
      if (out != null) {
        extLogWriter = new BufferedWriter(new OutputStreamWriter(out));
      }
    }

    return extLogWriter;
  }
  public void registerUninstallKey() throws NativeLibException {
    String uninstallName = getUninstallName();
    if (uninstallName == null) {
      return;
    }
    String keyName = UNINSTALL_ROOT + uninstallName;
    String cmd =
        "\""
            + installdata.getVariable("JAVA_HOME")
            + "\\bin\\javaw.exe\" -jar \""
            + installdata.getVariable("INSTALL_PATH")
            + "\\uninstaller\\uninstaller.jar\"";
    String appVersion = installdata.getVariable("APP_VER");
    String appUrl = installdata.getVariable("APP_URL");

    int oldVal = getRoot();
    try {
      setRoot(HKEY_LOCAL_MACHINE);
      setValue(keyName, "DisplayName", uninstallName);
    } catch (
        NativeLibException
            exception) { // Users without administrative rights should be able to install the app
                         // for themselves
      Debug.trace(
          "Failed to register uninstaller in HKEY_LOCAL_MACHINE hive, trying HKEY_CURRENT_USER: "******"DisplayName", uninstallName);
    }
    setValue(keyName, "UninstallString", cmd);
    setValue(keyName, "DisplayVersion", appVersion);
    if (appUrl != null && appUrl.length() > 0) {
      setValue(keyName, "HelpLink", appUrl);
    }
    // Try to write the uninstaller icon out.
    try {
      InputStream input = ResourceManager.getInstance().getInputStream(UNINSTALLER_ICON);
      String iconPath =
          installdata.getVariable("INSTALL_PATH")
              + File.separator
              + "Uninstaller"
              + File.separator
              + "UninstallerIcon.ico";
      FileOutputStream out = new FileOutputStream(iconPath);
      byte[] buffer = new byte[5120];
      long bytesCopied = 0;
      int bytesInBuffer;
      while ((bytesInBuffer = input.read(buffer)) != -1) {
        out.write(buffer, 0, bytesInBuffer);
        bytesCopied += bytesInBuffer;
      }
      input.close();
      out.close();
      setValue(keyName, "DisplayIcon", iconPath);
    } catch (Exception exception) { // May be no icon resource defined; ignore it
      Debug.trace(exception);
    }
    setRoot(oldVal);
  }
 /**
  * Add the contents of a custom langpack (if exist) to the previos loaded comman langpack. If not
  * exist, trace an info and do nothing more.
  *
  * @param idata install data to be used
  */
 protected void addCustomLangpack(AutomatedInstallData idata) {
   // We try to load and add a custom langpack.
   try {
     idata.langpack.add(ResourceManager.getInstance().getInputStream(LANG_FILE_NAME));
   } catch (Throwable exception) {
     Debug.trace("No custom langpack available.");
     return;
   }
   Debug.trace("Custom langpack for " + idata.localeISO3 + " available.");
 }
 /*
  * (non-Javadoc)
  *
  * @see de.reddot.installer.rules.Condition#readFromXML(net.n3.nanoxml.XMLElement)
  */
 public void readFromXML(IXMLElement xmlcondition) {
   try {
     if (xmlcondition.getChildrenCount() != 2) {
       Debug.log("xor-condition needs two conditions as operands");
       return;
     }
     this.leftoperand = RulesEngine.analyzeCondition(xmlcondition.getChildAtIndex(0));
     this.rightoperand = RulesEngine.analyzeCondition(xmlcondition.getChildAtIndex(1));
   } catch (Exception e) {
     Debug.log("missing element in xor-condition");
   }
 }
  /** @param args */
  public static void main(String[] args) {
    // default is to look in the current directory
    MultiVolumeInstaller.setMediadirectory(new File(".").getParent());
    if ((args.length > 0) && ("-direct".equals(args[0]))) {
      String[] newargs;
      if (args.length > 1) {
        // cut out the direct parameter
        newargs = new String[args.length - 1];
        System.arraycopy(args, 1, newargs, 0, args.length - 1);
      } else {
        // set arguments to empty string array
        newargs = new String[0];
      }
      MultiVolumeInstaller.install(newargs);
    } else {
      try {
        Class clazz = MultiVolumeInstaller.class;
        Method target = clazz.getMethod("install", new Class[] {String[].class});
        String[] newargs = new String[args.length + 2];

        System.arraycopy(args, 0, newargs, 2, args.length);
        // try to find the directory, where the jar file is located, this class was loaded
        // from
        newargs[0] = "-mediadir";
        newargs[1] = SelfModifier.findJarFile(clazz).getParent();
        System.out.println("Setting mediadir: " + newargs[1]);
        MultiVolumeInstaller.setMediadirectory(SelfModifier.findJarFile(clazz).getParent());
        new SelfModifier(target).invoke(newargs);
      } catch (Exception e) {
        Debug.trace(e);
      }
    }
  }
 /**
  * Sets the type of link
  *
  * @param type The type of link desired. The following values can be set: <br>
  *     (note APPLICATION on Windows is 'Start Menu\Programs') APPLICATION is a Mac term.
  *     <ul>
  *       <li>{@link com.izforge.izpack.util.os.Shortcut#DESKTOP}
  *       <li>{@link com.izforge.izpack.util.os.Shortcut#APPLICATIONS}
  *       <li>{@link com.izforge.izpack.util.os.Shortcut#START_MENU}
  *       <li>{@link com.izforge.izpack.util.os.Shortcut#START_UP}
  *     </ul>
  *
  * @exception IllegalArgumentException if an an invalid type is passed
  * @throws UnsupportedEncodingException
  */
 public void setLinkType(int type) throws IllegalArgumentException, UnsupportedEncodingException {
   Debug.log(CLASS + myClass + ".setLinkType() '" + type + "'");
   switch (type) {
     case DESKTOP:
       {
         shortcut.setLinkType(ShellLink.DESKTOP);
         break;
       }
     case APPLICATIONS:
       {
         shortcut.setLinkType(ShellLink.PROGRAM_MENU);
         break;
       }
     case START_MENU:
       {
         shortcut.setLinkType(ShellLink.START_MENU);
         break;
       }
     case START_UP:
       {
         shortcut.setLinkType(ShellLink.STARTUP);
         break;
       }
     default:
       {
         throw (new IllegalArgumentException(type + "is not recognized as a valid link type"));
       }
   }
 }
 /**
  * This method initializes the object. It is used as a replacement for the constructor because of
  * the way it is instantiated through the <code>TargetFactory</code>.
  *
  * @param type the type or classification of the program group in which the link should exist. The
  *     following types are recognized: <br>
  *     <ul>
  *       <li>{@link com.izforge.izpack.util.os.Shortcut#APPLICATIONS}
  *       <li>{@link com.izforge.izpack.util.os.Shortcut#START_MENU}
  *       <li>{@link com.izforge.izpack.util.os.Shortcut#DESKTOP}
  *       <li>{@link com.izforge.izpack.util.os.Shortcut#START_UP}
  *     </ul>
  *
  * @param name the name of the shortcut.
  */
 public void initialize(int type, String name) throws Exception {
   Debug.log(CLASS + myClass + ".initialize() '" + Integer.toString(type) + "', '" + name + "'");
   switch (type) {
     case APPLICATIONS:
       {
         shortcut = new ShellLink(ShellLink.PROGRAM_MENU, name);
         break;
       }
     case START_MENU:
       {
         shortcut = new ShellLink(ShellLink.START_MENU, name);
         break;
       }
     case DESKTOP:
       {
         shortcut = new ShellLink(ShellLink.DESKTOP, name);
         break;
       }
     case START_UP:
       {
         shortcut = new ShellLink(ShellLink.STARTUP, name);
         break;
       }
     default:
       {
         shortcut = new ShellLink(ShellLink.PROGRAM_MENU, name);
         break;
       }
   }
 }
 /**
  * Sets the show command that is passed to the target application when the link is activated. The
  * show command determines if the the window will be restored to the previous size, minimized,
  * maximized or visible at all. <br>
  * <br>
  * <b>Note: </b> <br>
  * Using <code>HIDE</code> will cause the target window not to show at all. There is not even a
  * button on the taskbar. This is a very useful setting when batch files are used to launch a Java
  * application as it will then appear to run just like any native Windows application. <br>
  *
  * @param show the show command. Valid settings are: <br>
  *     <ul>
  *       <li>{@link com.izforge.izpack.util.os.Shortcut#HIDE}
  *       <li>{@link com.izforge.izpack.util.os.Shortcut#NORMAL}
  *       <li>{@link com.izforge.izpack.util.os.Shortcut#MINIMIZED}
  *       <li>{@link com.izforge.izpack.util.os.Shortcut#MAXIMIZED}
  *     </ul>
  *
  * @see #getShowCommand internally maps from Shortcut. to ShellLink.
  */
 public void setShowCommand(int show) throws IllegalArgumentException {
   Debug.log(CLASS + myClass + ".setShowCommand() '" + Integer.toString(show) + "'");
   switch (show) {
     case HIDE:
       {
         shortcut.setShowCommand(ShellLink.MINNOACTIVE);
         break;
       }
     case NORMAL:
       {
         shortcut.setShowCommand(ShellLink.NORMAL);
         break;
       }
     case MINIMIZED:
       {
         shortcut.setShowCommand(ShellLink.MINNOACTIVE);
         break;
       }
     case MAXIMIZED:
       {
         shortcut.setShowCommand(ShellLink.MAXIMIZED);
         break;
       }
     default:
       {
         throw (new IllegalArgumentException(show + "is not recognized as a show command"));
       }
   }
 }
  /**
   * helper: recursively scan given directory.
   *
   * @return list of files found (might be empty)
   */
  private ArrayList<File> scanDirectory(File path) {
    Debug.trace("scanning directory " + path.getAbsolutePath());

    ArrayList<File> scan_result = new ArrayList<File>();

    if (!path.isDirectory()) {
      return scan_result;
    }

    File[] entries = path.listFiles();

    for (File file : entries) {
      if (file == null) {
        continue;
      }

      if (file.isDirectory()) {
        scan_result.addAll(scanDirectory(file));
      } else if ((file.isFile()) && (file.getName().toLowerCase().endsWith(".java"))) {
        scan_result.add(file);
      }
    }

    return scan_result;
  }
  /**
   * Returns <code>true</code> if the target OS supports current user and all users.
   *
   * @return <code>true</code> if the target OS supports current and all users.
   */
  public boolean multipleUsers() {
    boolean result = false;
    // Win NT4 won't have PROGRAMS for CURRENT_USER.
    // Win 98 may not have 'Start Menu\Programs' for ALL_USERS
    String allUsers = shortcut.getallUsersLinkPath();

    Debug.log(CLASS + myClass + ".multipleUsers()-1 '" + allUsers + "'");

    String currentUsers = shortcut.getcurrentUserLinkPath();
    Debug.log(CLASS + myClass + ".multipleUsers()-2 '" + currentUsers + "'");

    if (allUsers == null || currentUsers == null) result = false;
    else result = allUsers.length() > 0 && currentUsers.length() > 0;

    Debug.log(CLASS + myClass + ".multipleUsers()-3 '" + result + "'");
    return (result);
  }
 /*--------------------------------------------------------------------------*/
 public void setUserType(int type) {
   Debug.log(CLASS + myClass + ".setUserType() '" + type + "'");
   if (type == CURRENT_USER) {
     if (shortcut.getcurrentUserLinkPath().length() > 0) {
       shortcut.setUserType(ShellLink.CURRENT_USER);
     }
   } else if (type == ALL_USERS) {
     if (shortcut.getallUsersLinkPath().length() > 0) {
       shortcut.setUserType(ShellLink.ALL_USERS);
     }
   }
 }
 /** The run() method. */
 public void run() {
   try {
     createInstaller(); // Execute the compiler - may send info to
     // System.out
   } catch (CompilerException ce) {
     System.out.println(ce.getMessage() + "\n");
   } catch (Exception e) {
     if (Debug.stackTracing()) {
       e.printStackTrace();
     } else {
       System.out.println("ERROR: " + e.getMessage());
     }
   }
 }
    /**
     * Eclipse compiler hopefully only uses println(String).
     *
     * <p>{@inheritDoc}
     */
    public void println(String x) {
      if (x.startsWith("[completed ")) {
        int pos = x.lastIndexOf("#");
        int endpos = x.lastIndexOf("/");
        String fileno_str = x.substring(pos + 1, endpos - pos - 1);
        try {
          int fileno = Integer.parseInt(fileno_str);
          this.listener.progress(fileno, x);
        } catch (NumberFormatException _nfe) {
          Debug.log("could not parse eclipse compiler output: '" + x + "': " + _nfe.getMessage());
        }
      }

      super.println(x);
    }
  @Override
  public boolean isTrue() {
    if (!this.complete) {
      return false;
    } else {
      if (this.usedclass == null) {
        try {
          this.usedclass = Class.forName(this.classname);
        } catch (ClassNotFoundException e) {
          Debug.log("Can't find class " + this.classname);
          return false;
        }
      }
      if ((this.usedfield == null) && (this.fieldname != null)) {
        try {
          this.usedfield = this.usedclass.getField(this.fieldname);
        } catch (SecurityException e) {
          Debug.log("No permission to access specified field: " + this.fieldname);
          return false;
        } catch (NoSuchFieldException e) {
          Debug.log("No such field: " + this.fieldname);
          return false;
        }
      }
      if ((this.usedmethod == null) && (this.methodname != null)) {
        Debug.log("not implemented yet.");
        return false;
      }

      if (this.usedfield != null) {
        // access field
        if ("boolean".equals(this.returnvaluetype)) {
          try {
            boolean returnval = this.usedfield.getBoolean(null);
            boolean expectedreturnval = Boolean.valueOf(this.returnvalue);
            return returnval == expectedreturnval;
          } catch (IllegalArgumentException e) {
            Debug.log("IllegalArgumentexeption " + this.fieldname);
          } catch (IllegalAccessException e) {
            Debug.log("IllegalAccessException " + this.fieldname);
          }
        } else {
          Debug.log("not implemented yet.");
          return false;
        }
      }
      return false;
    }
  }
  /**
   * Gets the user type for the link
   *
   * @return userType
   * @see #CURRENT_USER
   * @see #ALL_USERS
   */
  public int getUserType() {
    int utype = shortcut.getUserType();

    Debug.log(CLASS + myClass + ".getUserType() '" + utype + "'");

    switch (utype) {
      case ShellLink.ALL_USERS:
        utype = ALL_USERS;
        break;

      case ShellLink.CURRENT_USER:
        utype = CURRENT_USER;
        break;
    }

    return utype;
  }
  /**
   * Gets the Folders where to place the program-groups and their shortcuts, for the given usertype.
   *
   * @see com.izforge.izpack.util.os.Shortcut#getProgramsFolder(int)
   */
  public String getProgramsFolder(int current_user) {
    /** CURRENT_USER = 0; the constant to use for selecting the current user. */
    int USER = 0;

    if (current_user == Shortcut.CURRENT_USER) USER = ShellLink.CURRENT_USER;
    else if (current_user == Shortcut.ALL_USERS) USER = ShellLink.ALL_USERS;

    String result = null;
    try {
      result =
          new String(
              shortcut.getLinkPath(USER).getBytes(StringTool.getPlatformEncoding()),
              StringTool.getPlatformEncoding());
    } catch (UnsupportedEncodingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    Debug.log(CLASS + myClass + ".getProgramsFolder() '" + current_user + "', '" + result + "'");
    return result;
  }
  /**
   * Gets the type of link types are: <br>
   *
   * <ul>
   *   <li>{@link com.izforge.izpack.util.os.Shortcut#DESKTOP}
   *   <li>{@link com.izforge.izpack.util.os.Shortcut#APPLICATIONS}
   *   <li>{@link com.izforge.izpack.util.os.Shortcut#START_MENU}
   *   <li>{@link com.izforge.izpack.util.os.Shortcut#START_UP}
   * </ul>
   *
   * maps from ShellLink-types to Shortcut-types.
   */
  public int getLinkType() {
    int typ = shortcut.getLinkType();
    Debug.log(CLASS + myClass + ".getLinkType() '" + typ + "'");
    switch (typ) {
      case ShellLink.DESKTOP:
        typ = DESKTOP;
        break;
      case ShellLink.PROGRAM_MENU:
        typ = APPLICATIONS;
        break;
      case ShellLink.START_MENU:
        typ = START_MENU;
        break;
      case ShellLink.STARTUP:
        typ = START_UP;
        break;
      default:
        break;
    }

    return typ;
  }
  /** perform the actual compilation */
  private CompileResult compileJobs() {
    ArrayList<String> args = new ArrayList<String>();
    StringTokenizer tokenizer = new StringTokenizer(this.compilerArgumentsToUse);

    while (tokenizer.hasMoreTokens()) {
      args.add(tokenizer.nextToken());
    }

    Iterator<CompilationJob> job_it = this.jobs.iterator();

    this.handler.startAction("Compilation", this.jobs.size());

    // check whether compiler is valid (but only if there are jobs)
    if (job_it.hasNext()) {
      CompilationJob first_job = this.jobs.get(0);

      CompileResult check_result = first_job.checkCompiler(this.compilerToUse, args);
      if (!check_result.isContinue()) {
        return check_result;
      }
    }

    int job_no = 0;

    while (job_it.hasNext()) {
      CompilationJob job = job_it.next();

      this.handler.nextStep(job.getName(), job.getSize(), job_no++);

      CompileResult job_result = job.perform(this.compilerToUse, args);

      if (!job_result.isContinue()) {
        return job_result;
      }
    }

    Debug.trace("compilation finished.");
    return new CompileResult();
  }
  /*
   * returns current showCommand. internally maps from ShellLink. to Shortcut.
   *
   */
  public int getShowCommand() {
    int showCommand = shortcut.getShowCommand();

    Debug.log(CLASS + myClass + ".getShowCommand() '" + Integer.toString(showCommand) + "'");

    switch (showCommand) {
      case ShellLink.NORMAL:
        showCommand = NORMAL;
        break;
        // both MINNOACTIVE and MINIMIZED map to Shortcut.MINIMIZED
      case ShellLink.MINNOACTIVE:
      case ShellLink.MINIMIZED:
        showCommand = MINIMIZED;
        break;
      case ShellLink.MAXIMIZED:
        showCommand = MAXIMIZED;
        break;
      default:
        break;
    }

    return showCommand;
  }
  /**
   * helper: recursively scan given directory.
   *
   * @return list of files found (might be empty)
   */
  private ArrayList scanDirectory(File path) {
    Debug.trace("scanning directory " + path.getAbsolutePath());

    ArrayList result = new ArrayList();

    if (!path.isDirectory()) return result;

    File[] entries = path.listFiles();

    for (int i = 0; i < entries.length; i++) {
      File f = entries[i];

      if (f == null) continue;

      if (f.isDirectory()) {
        result.addAll(scanDirectory(f));
      } else if ((f.isFile()) && (f.getName().toLowerCase().endsWith(".java"))) {
        result.add(f);
      }
    }

    return result;
  }
Exemple #21
0
  public ConsoleInstaller(String langcode) throws Exception {
    super();
    loadInstallData(this.installdata);

    this.installdata.localeISO3 = langcode;
    // Fallback: choose the first listed language pack if not specified via commandline
    if (this.installdata.localeISO3 == null) {
      this.installdata.localeISO3 = getAvailableLangPacks().get(0);
    }

    InputStream in =
        getClass().getResourceAsStream("/langpacks/" + this.installdata.localeISO3 + ".xml");
    this.installdata.langpack = new LocaleDatabase(in);
    this.installdata.setVariable(ScriptParser.ISO3_LANG, this.installdata.localeISO3);
    ResourceManager.create(this.installdata);
    loadConditions(installdata);
    loadInstallerRequirements();
    loadDynamicVariables();
    if (!checkInstallerRequirements(installdata)) {
      Debug.log("not all installerconditions are fulfilled.");
      return;
    }
    addCustomLangpack(installdata);
  }
 /**
  * Sets the location of the icon that is shown for the shortcut on the desktop.
  *
  * @param path a fully qualified file name of a file that contains the icon.
  * @param index the index of the specific icon to use in the file. If there is only one icon in
  *     the file, use an index of 0.
  */
 public void setIconLocation(String path, int index) {
   Debug.log(
       CLASS + myClass + ".setIconLocation() '" + path + "', '" + Integer.toString(index) + "'");
   shortcut.setIconLocation(path, index);
 }
 /**
  * Sets the name of the program group this ShellLinbk should be placed in.
  *
  * @param groupName the name of the program group
  */
 public void setProgramGroup(String groupName) {
   Debug.log(CLASS + myClass + ".setProgramGroup() '" + groupName + "'");
   shortcut.setProgramGroup(groupName);
 }
 /**
  * Gets the link hotKey
  *
  * @return int hotKey
  */
 public int getHotkey() {
   int result = shortcut.getHotkey();
   Debug.log(CLASS + myClass + ".getHotkey() '" + result + "'");
   return result;
 }
 /**
  * Sets the link hotKey
  *
  * @param hotkey
  *     <p>incoming 2 byte hotkey is: high byte modifier: SHIFT = 0x01 CONTROL= 0x02 ALT = 0x04 EXT
  *     = 0x08
  *     <p>lower byte contains ascii letter. ie 0x0278 represents CTRL+x 0x068a represents
  *     CTRL+ALT+z
  */
 public void setHotkey(int hotkey) {
   Debug.log(CLASS + myClass + ".setHotkey() '" + hotkey + "'");
   shortcut.setHotkey(hotkey);
 }
 /**
  * returns icon Location
  *
  * @return iconLocation
  */
 public String getIconLocation() {
   String result = shortcut.getIconLocation();
   Debug.log(CLASS + myClass + ".getIconLocation() '" + result + "'");
   return result;
 }
 /**
  * Sets the absolute path to the shortcut target.
  *
  * @param path the fully qualified file name of the target
  */
 public void setTargetPath(String path) {
   Debug.log(CLASS + myClass + ".setTargetPath() '" + path + "'");
   shortcut.setTargetPath(path);
 }
 /**
  * Sets the working directory for the link target.
  *
  * @param dir the working directory
  */
 public void setWorkingDirectory(String dir) {
   Debug.log(CLASS + myClass + ".setWorkingDirectory() '" + dir + "'");
   shortcut.setWorkingDirectory(dir);
 }
 /**
  * Gets the working directory for the link target.
  *
  * @return the working directory.
  */
 public String getWorkingDirectory() {
   String result = shortcut.getWorkingDirectory();
   Debug.log(CLASS + myClass + ".getWorkingDirectory() '" + result + "'");
   return result;
 }
 /**
  * Sets the name shown in a menu or on the desktop for the link.
  *
  * @param name The name that the link should display on a menu or on the desktop. Do not include a
  *     file extension.
  */
 public void setLinkName(String name) {
   Debug.log(CLASS + myClass + ".setLinkName() '" + name + "'");
   shortcut.setLinkName(name);
 }