home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIPHEFT062001.ISO / browser / nc32lyc / comm.z / java40.jar / netscape / softupdate / InstallPatch.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-08-15  |  3.9 KB  |  138 lines

  1. package netscape.softupdate;
  2.  
  3. import java.text.MessageFormat;
  4. import netscape.security.AppletSecurity;
  5. import netscape.security.PrivilegeManager;
  6. import netscape.security.Target;
  7.  
  8. final class InstallPatch extends InstallObject {
  9.    private String vrName;
  10.    private VersionInfo versionInfo;
  11.    private String jarLocation;
  12.    private String patchURL;
  13.    private String targetfile;
  14.    private String patchedfile;
  15.  
  16.    InstallPatch(SoftwareUpdate var1, String var2, VersionInfo var3, String var4) throws SoftUpdateException {
  17.       super(var1);
  18.       this.vrName = var2;
  19.       this.versionInfo = var3;
  20.       this.jarLocation = var4;
  21.       this.targetfile = VersionRegistry.componentPath(this.vrName);
  22.       if (this.targetfile == null) {
  23.          throw new SoftUpdateException("", -213);
  24.       } else {
  25.          this.checkPrivileges();
  26.       }
  27.    }
  28.  
  29.    InstallPatch(SoftwareUpdate var1, String var2, VersionInfo var3, String var4, FolderSpec var5, String var6) throws SoftUpdateException {
  30.       super(var1);
  31.       this.vrName = var2;
  32.       this.versionInfo = var3;
  33.       this.jarLocation = var4;
  34.       this.targetfile = var5.MakeFullPath(var6);
  35.       this.checkPrivileges();
  36.    }
  37.  
  38.    private void checkPrivileges() {
  39.       PrivilegeManager var1 = AppletSecurity.getPrivilegeManager();
  40.       Target var2 = Target.findTarget("Impersonator");
  41.       Target var3 = Target.findTarget("SoftwareInstall");
  42.       var1.enablePrivilege(var2);
  43.       var1.enablePrivilege(var3, super.softUpdate.GetPrincipal());
  44.    }
  45.  
  46.    protected void Prepare() throws SoftUpdateException {
  47.       int var1 = 0;
  48.       String var2 = null;
  49.       boolean var3 = false;
  50.       PrivilegeManager var4 = AppletSecurity.getPrivilegeManager();
  51.       Target var5 = Target.findTarget("Impersonator");
  52.       Target var6 = Target.findTarget("SoftwareInstall");
  53.       var4.enablePrivilege(var5);
  54.       var4.enablePrivilege(var6, super.softUpdate.GetPrincipal());
  55.  
  56.       try {
  57.          ((InstallObject)this).NativeDoesFileExist(this.targetfile);
  58.       } catch (SoftUpdateException var9) {
  59.          var1 = var9.GetError();
  60.       }
  61.  
  62.       if (var1 == 0) {
  63.          this.patchURL = super.softUpdate.ExtractJARFile(this.jarLocation, this.targetfile);
  64.          if (super.softUpdate.patchList.containsKey(this.targetfile)) {
  65.             var2 = (String)super.softUpdate.patchList.get(this.targetfile);
  66.             var3 = true;
  67.          } else {
  68.             var2 = this.targetfile;
  69.             var3 = false;
  70.          }
  71.  
  72.          try {
  73.             this.patchedfile = this.NativePatch(var2, this.patchURL);
  74.          } catch (SoftUpdateException var8) {
  75.             var1 = var8.GetError();
  76.          }
  77.  
  78.          if (this.patchedfile != null) {
  79.             super.softUpdate.patchList.put(this.targetfile, this.patchedfile);
  80.          }
  81.       }
  82.  
  83.       if (var3) {
  84.          this.NativeDeleteFile(var2);
  85.       }
  86.  
  87.       if (var1 != 0) {
  88.          Object[] var7 = new Object[]{this.targetfile};
  89.          throw new SoftUpdateException(MessageFormat.format(Strings.error_PatchFailed(), var7), var1);
  90.       }
  91.    }
  92.  
  93.    protected void Complete() throws SoftUpdateException {
  94.       this.checkPrivileges();
  95.       String var2 = (String)super.softUpdate.patchList.get(this.targetfile);
  96.       if (var2.compareTo(this.patchedfile) == 0) {
  97.          int var1 = this.NativeReplace(this.targetfile, this.patchedfile);
  98.          if (var1 != 0 && var1 != 999) {
  99.             Object[] var3 = new Object[]{this.targetfile};
  100.             throw new SoftUpdateException(MessageFormat.format(Strings.error_InstallFileUnexpected(), var3), var1);
  101.          }
  102.  
  103.          VersionRegistry.installComponent(this.vrName, this.targetfile, this.versionInfo);
  104.          if (var1 != 0) {
  105.             throw new SoftUpdateException(this.targetfile, var1);
  106.          }
  107.       }
  108.  
  109.    }
  110.  
  111.    protected void Abort() {
  112.       String var1 = (String)super.softUpdate.patchList.get(this.targetfile);
  113.       if (var1.compareTo(this.patchedfile) == 0) {
  114.          this.NativeDeleteFile(this.patchedfile);
  115.       }
  116.  
  117.    }
  118.  
  119.    private native String NativePatch(String var1, String var2) throws SoftUpdateException;
  120.  
  121.    private native int NativeReplace(String var1, String var2);
  122.  
  123.    private native void NativeDeleteFile(String var1);
  124.  
  125.    public String toString() {
  126.       Object[] var1 = new Object[]{this.targetfile};
  127.       return MessageFormat.format(Strings.details_Patch(), var1);
  128.    }
  129.  
  130.    protected boolean CanUninstall() {
  131.       return true;
  132.    }
  133.  
  134.    protected boolean RegisterPackageNode() {
  135.       return true;
  136.    }
  137. }
  138.