예제 #1
0
  /**
   * Unpacks a pack file.
   *
   * @param file the pack file meta-data
   * @param packInputStream the pack input stream
   * @param target the target
   * @throws IOException for any I/O error
   * @throws InstallerException for any installer exception
   */
  @Override
  public void unpack(PackFile file, ObjectInputStream packInputStream, File target)
      throws IOException, InstallerException {
    // Old way of doing the job by using the (absolute) sourcepath.
    // Since this is very likely to fail and does not conform to the documentation prefer using
    // relative
    // path's
    // pis = new FileInputStream(pf.sourcePath);

    File resolvedFile = new File(sourceDir, file.getRelativeSourcePath());
    if (!resolvedFile.exists()) {
      // try alternative destination - the current working directory
      // user.dir is likely (depends on launcher type) the current directory of the executable or
      // jar-file...
      final File userDir = new File(System.getProperty("user.dir"));
      resolvedFile = new File(userDir, file.getRelativeSourcePath());
    }
    if (resolvedFile.exists()) {
      InputStream stream = new FileInputStream(resolvedFile);
      // may have a different length & last modified than we had at compile time, therefore we have
      // to
      // build a new PackFile for the copy process...
      file =
          new PackFile(
              resolvedFile.getParentFile(),
              resolvedFile,
              file.getTargetPath(),
              file.osConstraints(),
              file.override(),
              file.overrideRenameTo(),
              file.blockable(),
              file.getAdditionals());

      copy(file, stream, target);
    } else {
      // file not found. Since this file was loosely bundled, continue with the installation.
      logger.warning("Could not find loosely bundled file: " + file.getRelativeSourcePath());
      if (prompt.confirm(
              Prompt.Type.WARNING,
              "File not found",
              "Could not find loosely bundled file: " + file.getRelativeSourcePath(),
              Prompt.Options.OK_CANCEL)
          == Prompt.Option.OK) {
        throw new InstallerException("Installation cancelled");
      }
    }
  }