Beispiel #1
0
  private void createOutputJar() {
    // Me make the .uninstaller directory
    String dest =
        IoHelper.translatePath(installdata.getInfo().getUninstallerPath(), variableSubstitutor);
    String jar = dest + File.separator + installdata.getInfo().getUninstallerName();
    File pathMaker = new File(dest);
    pathMaker.mkdirs();

    // We log the uninstaller deletion information
    udata.setUninstallerJarFilename(jar);
    udata.setUninstallerPath(dest);

    // We open our final jar file
    try {
      out = new FileOutputStream(jar);
    } catch (FileNotFoundException e) {
      throw new IzPackException("Problem writing uninstaller jar", e);
    }

    try {
      // Intersect a buffer else byte for byte will be written to the file.
      bos = new BufferedOutputStream(out);
      outJar = new JarOutputStream(bos);
    } catch (IOException e) {
      throw new IzPackException("Problem writing uninstaller jar", e);
    }

    outJar.setLevel(9);
    udata.addFile(jar, true);
  }
Beispiel #2
0
 private void writeExecutables(UninstallData udata, JarOutputStream outJar) throws IOException {
   outJar.putNextEntry(new JarEntry("executables"));
   ObjectOutputStream execStream = new ObjectOutputStream(outJar);
   execStream.writeInt(udata.getExecutablesList().size());
   for (ExecutableFile file : udata.getExecutablesList()) {
     execStream.writeObject(file);
   }
   execStream.flush();
   outJar.closeEntry();
 }
Beispiel #3
0
 private void writeUninstallerJarFileLog(UninstallData udata, JarOutputStream outJar)
     throws IOException {
   BufferedWriter logWriter;
   outJar.putNextEntry(new JarEntry("jarlocation.log"));
   logWriter = new BufferedWriter(new OutputStreamWriter(outJar));
   logWriter.write(udata.getUninstallerJarFilename());
   logWriter.newLine();
   logWriter.write(udata.getUninstallerPath());
   logWriter.flush();
   outJar.closeEntry();
 }
  /**
   * Puts the uninstaller.
   *
   * @exception Exception Description of the Exception
   */
  private void putUninstaller() throws Exception {
    // Me make the .uninstaller directory
    String dest = translatePath("$INSTALL_PATH") + File.separator + "Uninstaller";
    String jar = dest + File.separator + "uninstaller.jar";
    File pathMaker = new File(dest);
    pathMaker.mkdirs();

    // We log the uninstaller deletion information
    UninstallData udata = UninstallData.getInstance();
    udata.setUninstallerJarFilename(jar);
    udata.setUninstallerPath(dest);

    // We open our final jar file
    FileOutputStream out = new FileOutputStream(jar);
    ZipOutputStream outJar = new ZipOutputStream(out);
    idata.uninstallOutJar = outJar;
    outJar.setLevel(9);
    udata.addFile(jar);

    // We copy the uninstaller
    InputStream in = getClass().getResourceAsStream("/res/IzPack.uninstaller");
    ZipInputStream inRes = new ZipInputStream(in);
    ZipEntry zentry = inRes.getNextEntry();
    while (zentry != null) {
      // Puts a new entry
      outJar.putNextEntry(new ZipEntry(zentry.getName()));

      // Byte to byte copy
      int unc = inRes.read();
      while (unc != -1) {
        outJar.write(unc);
        unc = inRes.read();
      }

      // Next one please
      inRes.closeEntry();
      outJar.closeEntry();
      zentry = inRes.getNextEntry();
    }
    inRes.close();

    // We put the langpack
    in = getClass().getResourceAsStream("/langpacks/" + idata.localeISO3 + ".xml");
    outJar.putNextEntry(new ZipEntry("langpack.xml"));
    int read = in.read();
    while (read != -1) {
      outJar.write(read);
      read = in.read();
    }
    outJar.closeEntry();
  }
Beispiel #5
0
  private void writeScriptFiles(UninstallData udata, JarOutputStream outJar) throws IOException {

    ArrayList<String> unInstallScripts = udata.getUninstallScripts();
    ObjectOutputStream rootStream;
    int idx = 0;
    for (String unInstallScript : unInstallScripts) {
      outJar.putNextEntry(new JarEntry(UninstallData.ROOTSCRIPT + Integer.toString(idx)));
      rootStream = new ObjectOutputStream(outJar);
      rootStream.writeUTF(unInstallScript);
      rootStream.flush();
      outJar.closeEntry();
      idx++;
    }
  }
Beispiel #6
0
  /**
   * Write uninstall data.
   *
   * @return true if the infos were successfuly written, false otherwise.
   */
  public boolean write() {
    try {
      if (!isUninstallShouldBeWriten()) {
        return false;
      }
      BufferedWriter extLogWriter = getExternLogFile(installdata);
      createOutputJar();
      // We get the data
      List<String> files = udata.getUninstalableFilesList();

      if (outJar == null) {
        return true; // it is allowed not to have an installer
      }

      System.out.println("[ Writing the uninstaller data ... ]");

      writeJarSkeleton(installdata, pathResolver, outJar);

      writeFilesLog(installdata, extLogWriter, files, outJar);

      writeUninstallerJarFileLog(udata, outJar);

      writeExecutables(udata, outJar);

      writeAdditionalUninstallData(udata, outJar);

      writeScriptFiles(udata, outJar);

      // Cleanup
      outJar.flush();
      outJar.close();
      bos.close();
      out.close();
      return true;
    } catch (Exception err) {
      err.printStackTrace();
      return false;
    }
  }
Beispiel #7
0
  private void writeAdditionalUninstallData(UninstallData udata, JarOutputStream outJar)
      throws IOException {
    Map<String, Object> additionalData = udata.getAdditionalData();
    if (additionalData != null && !additionalData.isEmpty()) {
      Set<String> exist = new HashSet<String>();
      for (String key : additionalData.keySet()) {
        Object contents = additionalData.get(key);
        if ("__uninstallLibs__".equals(key)) {
          for (Object o : ((List) contents)) {
            String nativeLibName = (String) ((List) o).get(0);
            byte[] buffer = new byte[5120];
            long bytesCopied = 0;
            int bytesInBuffer;
            outJar.putNextEntry(new JarEntry("/com/izforge/izpack/bin/native/" + nativeLibName));
            InputStream in =
                getClass().getResourceAsStream("/com/izforge/izpack/bin/native/" + nativeLibName);
            while ((bytesInBuffer = in.read(buffer)) != -1) {
              outJar.write(buffer, 0, bytesInBuffer);
              bytesCopied += bytesInBuffer;
            }
            outJar.closeEntry();
          }
        } else if ("uninstallerListeners".equals(key) || "uninstallerJars".equals(key)) {
          // It is a ArrayList of ArrayLists which contains the full
          // package paths of all needed class files.
          // First we create a new ArrayList which contains only
          // the full paths for the uninstall listener self; thats
          // the first entry of each sub ArrayList.
          ArrayList<String> subContents = new ArrayList<String>();

          // Secound put the class into uninstaller.jar
          for (Object o : ((List) contents)) {
            byte[] buffer = new byte[5120];
            long bytesCopied = 0;
            int bytesInBuffer;
            CustomData customData = (CustomData) o;
            // First element of the list contains the listener
            // class path;
            // remind it for later.
            if (customData.listenerName != null) {
              subContents.add(customData.listenerName);
            }
            for (String content : customData.contents) {
              if (exist.contains(content)) {
                continue;
              }
              exist.add(content);
              try {
                outJar.putNextEntry(new JarEntry(content));
              } catch (JarException je) { // Ignore, or ignore not ?? May be it is a
                // exception because
                // a doubled entry was tried, then we should
                // ignore ...
                Debug.trace("JarException in writing custom data: " + je.getMessage());
                continue;
              }
              InputStream in = getClass().getResourceAsStream("/" + content);
              if (in != null) {
                while ((bytesInBuffer = in.read(buffer)) != -1) {
                  outJar.write(buffer, 0, bytesInBuffer);
                  bytesCopied += bytesInBuffer;
                }
              } else {
                Debug.trace("custom data not found: " + content);
              }
              outJar.closeEntry();
            }
          }
          // Third we write the list into the
          // uninstaller.jar
          outJar.putNextEntry(new JarEntry(key));
          ObjectOutputStream objOut = new ObjectOutputStream(outJar);
          objOut.writeObject(subContents);
          objOut.flush();
          outJar.closeEntry();

        } else {
          outJar.putNextEntry(new JarEntry(key));
          if (contents instanceof ByteArrayOutputStream) {
            ((ByteArrayOutputStream) contents).writeTo(outJar);
          } else {
            ObjectOutputStream objOut = new ObjectOutputStream(outJar);
            objOut.writeObject(contents);
            objOut.flush();
          }
          outJar.closeEntry();
        }
      }
    }
  }
  /** The run method. */
  public void run() {
    instances.add(this);
    try {
      listener.startUnpack();
      String currentOs = System.getProperty("os.name").toLowerCase();
      //
      // Initialisations
      FileOutputStream out = null;
      ArrayList parsables = new ArrayList();
      ArrayList executables = new ArrayList();
      List packs = idata.selectedPacks;
      int npacks = packs.size();
      udata = UninstallData.getInstance();

      // Specific to the web installers
      if (idata.kind.equalsIgnoreCase("web") || idata.kind.equalsIgnoreCase("web-kunststoff")) {
        InputStream kin = getClass().getResourceAsStream("/res/WebInstallers.url");
        BufferedReader kreader = new BufferedReader(new InputStreamReader(kin));
        jarLocation = kreader.readLine();
      }

      // We unpack the selected packs
      for (int i = 0; i < npacks; i++) {
        // We get the pack stream
        int n = idata.allPacks.indexOf(packs.get(i));
        ObjectInputStream objIn = new ObjectInputStream(getPackAsStream(n));

        // We unpack the files
        int nfiles = objIn.readInt();
        listener.changeUnpack(0, nfiles, ((Pack) packs.get(i)).name);
        for (int j = 0; j < nfiles; j++) {
          // We read the header
          PackFile pf = (PackFile) objIn.readObject();
          if (null == pf.os || matchOS(currentOs, pf.os.toLowerCase())) {
            // We translate & build the path
            String path = translatePath(pf.targetPath);
            File pathFile = new File(path);
            String fname = pathFile.getName();
            int z = fname.length();
            File dest = pathFile.getParentFile();
            if (!dest.exists()) dest.mkdirs();

            // We add the path to the log,
            udata.addFile(path);

            listener.progressUnpack(j, path);

            // if this file exists and shouldnot override skip this file
            if (((pf.override == false) && (pathFile.exists()))) {
              objIn.skip(pf.length);
              continue;
            }

            // We copy the file
            out = new FileOutputStream(path);
            byte[] buffer = new byte[5120];
            long bytesCopied = 0;
            while (bytesCopied < pf.length) {
              int maxBytes =
                  (pf.length - bytesCopied < buffer.length
                      ? (int) (pf.length - bytesCopied)
                      : buffer.length);
              int bytesInBuffer = objIn.read(buffer, 0, maxBytes);
              if (bytesInBuffer == -1) throw new IOException("Unexpected end of stream");

              out.write(buffer, 0, bytesInBuffer);

              bytesCopied += bytesInBuffer;
            }
            // Cleanings
            out.close();

            // Empty dirs restoring
            String _n = pathFile.getName();
            if (_n.startsWith("izpack-keepme") && _n.endsWith(".tmp")) pathFile.delete();

          } else objIn.skip(pf.length);
        }

        // Load information about parsable files
        int numParsables = objIn.readInt();
        int k;
        for (k = 0; k < numParsables; k++) {
          ParsableFile pf = (ParsableFile) objIn.readObject();
          pf.path = translatePath(pf.path);
          parsables.add(pf);
        }

        // Load information about executable files
        int numExecutables = objIn.readInt();
        for (k = 0; k < numExecutables; k++) {
          ExecutableFile ef = (ExecutableFile) objIn.readObject();
          ef.path = translatePath(ef.path);
          if (null != ef.argList && !ef.argList.isEmpty()) {
            String arg = null;
            for (int j = 0; j < ef.argList.size(); j++) {
              arg = (String) ef.argList.get(j);
              arg = translatePath(arg);
              ef.argList.set(j, arg);
            }
          }
          executables.add(ef);
          if (ef.executionStage == ExecutableFile.UNINSTALL) {
            udata.addExecutable(ef);
          }
        }
        objIn.close();
      }

      // We use the scripts parser
      ScriptParser parser = new ScriptParser(parsables, vs);
      parser.parseFiles();

      // We use the file executor
      FileExecutor executor = new FileExecutor(executables);
      if (executor.executeFiles(ExecutableFile.POSTINSTALL) != 0)
        javax.swing.JOptionPane.showMessageDialog(
            null,
            "The installation was not completed.",
            "Installation warning",
            javax.swing.JOptionPane.WARNING_MESSAGE);

      // We put the uninstaller
      putUninstaller();

      // The end :-)
      listener.stopUnpack();
    } catch (Exception err) {
      listener.stopUnpack();
      listener.errorUnpack(err.toString());
    }
    instances.remove(instances.indexOf(this));
  }