home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIPHEFT062001.ISO / browser / nc32lyc / comm.z / java40.jar / netscape / softupdate / InstallDelete.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-08-15  |  3.7 KB  |  123 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. class InstallDelete extends InstallObject {
  9.    private String finalFile;
  10.    private String registryName;
  11.    int FILE_DOES_NOT_EXIST;
  12.    int FILE_READ_ONLY;
  13.    int FILE_IS_DIRECTORY;
  14.    int deleteStatus;
  15.    static final int DELETE_FILE = 1;
  16.    static final int DELETE_COMPONENT = 2;
  17.  
  18.    InstallDelete(SoftwareUpdate var1, FolderSpec var2, String var3) throws SoftUpdateException {
  19.       super(var1);
  20.       this.deleteStatus = 1;
  21.       this.finalFile = var2.MakeFullPath(var3);
  22.       this.FILE_DOES_NOT_EXIST = -214;
  23.       this.FILE_READ_ONLY = -215;
  24.       this.FILE_IS_DIRECTORY = -216;
  25.       this.processInstallDelete();
  26.    }
  27.  
  28.    InstallDelete(SoftwareUpdate var1, String var2) throws SoftUpdateException {
  29.       super(var1);
  30.       this.deleteStatus = 2;
  31.       this.registryName = var2;
  32.       this.FILE_DOES_NOT_EXIST = -214;
  33.       this.FILE_READ_ONLY = -215;
  34.       this.FILE_IS_DIRECTORY = -216;
  35.       this.processInstallDelete();
  36.    }
  37.  
  38.    private void processInstallDelete() throws SoftUpdateException {
  39.       PrivilegeManager var2 = AppletSecurity.getPrivilegeManager();
  40.       Target var3 = Target.findTarget("Impersonator");
  41.       var2.enablePrivilege(var3);
  42.       Target var4 = Target.findTarget("SoftwareInstall");
  43.       var2.enablePrivilege(var4, super.softUpdate.GetPrincipal());
  44.       if (this.deleteStatus == 2) {
  45.          int var1 = VersionRegistry.inRegistry(this.registryName);
  46.          if (var1 != 0) {
  47.             throw new SoftUpdateException(Strings.error_NotInRegistry() + this.registryName, -213);
  48.          }
  49.  
  50.          this.finalFile = VersionRegistry.componentPath(this.registryName);
  51.       }
  52.  
  53.       if (this.finalFile != null) {
  54.          int var5 = this.NativeCheckFileStatus();
  55.          if (var5 != 0) {
  56.             if (var5 == -214) {
  57.                throw new SoftUpdateException(Strings.error_FileDoesNotExist() + this.finalFile, var5);
  58.             }
  59.  
  60.             if (var5 == -215) {
  61.                throw new SoftUpdateException(Strings.error_FileReadOnly() + this.finalFile, var5);
  62.             }
  63.  
  64.             if (var5 == -216) {
  65.                throw new SoftUpdateException(Strings.error_FileIsDirectory() + this.finalFile, var5);
  66.             }
  67.  
  68.             throw new SoftUpdateException(Strings.error_Unexpected() + this.finalFile, var5);
  69.          }
  70.       }
  71.  
  72.    }
  73.  
  74.    protected void Prepare() throws SoftUpdateException {
  75.    }
  76.  
  77.    protected void Complete() throws SoftUpdateException {
  78.       int var1 = -1;
  79.       PrivilegeManager var3 = AppletSecurity.getPrivilegeManager();
  80.       Target var4 = Target.findTarget("Impersonator");
  81.       var3.enablePrivilege(var4);
  82.       Target var2 = Target.findTarget("SoftwareInstall");
  83.       var3.enablePrivilege(var2, super.softUpdate.GetPrincipal());
  84.       if (this.deleteStatus == 2) {
  85.          var1 = VersionRegistry.deleteComponent(this.registryName);
  86.       }
  87.  
  88.       if (this.deleteStatus != 1 && var1 != 0) {
  89.          throw new SoftUpdateException(Strings.error_Unexpected() + this.finalFile, var1);
  90.       } else {
  91.          if (this.finalFile != null) {
  92.             var1 = this.NativeComplete();
  93.             if (var1 != 0 && var1 != -214) {
  94.                var3.revertPrivilege(var2);
  95.                throw new SoftUpdateException(Strings.error_Unexpected() + this.finalFile, var1);
  96.             }
  97.          }
  98.  
  99.       }
  100.    }
  101.  
  102.    protected void Abort() {
  103.    }
  104.  
  105.    private native int NativeComplete() throws SoftUpdateException;
  106.  
  107.    private native int NativeCheckFileStatus() throws SoftUpdateException;
  108.  
  109.    public String toString() {
  110.       Object[] var1 = new Object[]{this.finalFile};
  111.       Object[] var2 = new Object[]{this.registryName};
  112.       return this.deleteStatus == 1 ? MessageFormat.format(Strings.details_DeleteFile(), var1) : MessageFormat.format(Strings.details_DeleteComponent(), var2);
  113.    }
  114.  
  115.    protected boolean CanUninstall() {
  116.       return false;
  117.    }
  118.  
  119.    protected boolean RegisterPackageNode() {
  120.       return false;
  121.    }
  122. }
  123.