Esempio n. 1
0
  /**
   * Creates a single patch file that contains the differences between the two specified application
   * directories. The patch file will be created in the <code>nvdir</code> directory with name
   * <code>patchV.dat</code> where V is the old application version.
   */
  public void createDiff(File nvdir, File ovdir, boolean verbose) throws IOException {
    // sanity check
    String nvers = nvdir.getName();
    String overs = ovdir.getName();
    try {
      if (Long.parseLong(nvers) <= Long.parseLong(overs)) {
        String err =
            "New version (" + nvers + ") must be greater " + "than old version (" + overs + ").";
        throw new IOException(err);
      }
    } catch (NumberFormatException nfe) {
      throw new IOException("Non-numeric versions? [nvers=" + nvers + ", overs=" + overs + "].");
    }

    Application oapp = new Application(ovdir, null, SysProps.nameOfExtraFile());
    oapp.init(false);
    ArrayList<Resource> orsrcs = new ArrayList<Resource>();
    orsrcs.addAll(oapp.getCodeResources());
    orsrcs.addAll(oapp.getResources());

    Application napp = new Application(nvdir, null, SysProps.nameOfExtraFile());
    napp.init(false);
    ArrayList<Resource> nrsrcs = new ArrayList<Resource>();
    nrsrcs.addAll(napp.getCodeResources());
    nrsrcs.addAll(napp.getResources());

    // first create a patch for the main application
    File patch = new File(nvdir, "patch" + overs + ".dat");
    createPatch(patch, orsrcs, nrsrcs, verbose);

    // next create patches for any auxiliary resource groups
    for (Application.AuxGroup ag : napp.getAuxGroups()) {
      orsrcs = new ArrayList<Resource>();
      Application.AuxGroup oag = oapp.getAuxGroup(ag.name);
      if (oag != null) {
        orsrcs.addAll(oag.codes);
        orsrcs.addAll(oag.rsrcs);
      }
      nrsrcs = new ArrayList<Resource>();
      nrsrcs.addAll(ag.codes);
      nrsrcs.addAll(ag.rsrcs);
      patch = new File(nvdir, "patch-" + ag.name + overs + ".dat");
      createPatch(patch, orsrcs, nrsrcs, verbose);
    }
  }