コード例 #1
0
REGERR su_UninstallProcessItem(char *component_path)
{
    int refcount;
    int err;
    char filepath[MAXREGPATHLEN];
    nsCOMPtr<nsILocalFile> nsLFPath;
    nsCOMPtr<nsIFile> nsFPath;

    err = VR_GetPath(component_path, sizeof(filepath), filepath);
    if ( err == REGERR_OK )
    {
        NS_NewNativeLocalFile(nsDependentCString(filepath), PR_TRUE, getter_AddRefs(nsLFPath));
        nsFPath = nsLFPath;
        err = VR_GetRefCount(component_path, &refcount);  
        if ( err == REGERR_OK )
        {
            --refcount;
            if (refcount > 0)
                err = VR_SetRefCount(component_path, refcount);  
            else 
            {
                err = VR_Remove(component_path);
                DeleteFileNowOrSchedule(nsFPath);
            }
        }
        else
        {
            /* delete node and file */
            err = VR_Remove(component_path);
            DeleteFileNowOrSchedule(nsFPath);
        }
    }
    return err;
}
コード例 #2
0
/* Complete
 * Completes the install:
 * - move the downloaded file to the final location
 * - updates the registry
 */
char* nsInstallFile::Complete()
{
    int err;
    int refCount;
    int rc;

    if (softUpdate == NULL) {
        return SU_GetErrorMsg3("nsSoftwareUpdate object is null",
                               SUERR_INVALID_ARGUMENTS);
    }
    if (vrName == NULL) {
        return SU_GetErrorMsg3("version registry name is null",
                               SUERR_INVALID_ARGUMENTS);
    }
    if (finalFile == NULL) {
        return  SU_GetErrorMsg3("folderSpec's full path (finalFile) is null",
                                SUERR_INVALID_ARGUMENTS);
    }

    /* Check the security for our target */
    // XXX: Make the following security code into a function.

    /* Request impersonation privileges */
    nsTarget* impersonation = nsTarget::findTarget(IMPERSONATOR);
    nsPrivilegeManager* privMgr = nsPrivilegeManager::getPrivilegeManager();
    nsTarget* install_target = NULL;

    if ((privMgr != NULL) && (impersonation != NULL)) {
        privMgr->enablePrivilege(impersonation, 1);

        /* check the security permissions */
        install_target = nsTarget::findTarget(INSTALL_PRIV);
        if (install_target != NULL) {
            if (!privMgr->enablePrivilege(install_target,
                                          softUpdate->GetPrincipal(), 1)) {
                return SU_GetErrorMsg3("Permssion was denied",
                                       SUERR_ACCESS_DENIED);
            }
        }
    }

    err = NativeComplete();

    if ((privMgr != NULL) && (install_target != NULL)) {
        privMgr->revertPrivilege(install_target, 1);
    }

    char *vr_name = vrName->ToNewCString();
    char *final_file = finalFile->ToNewCString();

    // Add java archives to the classpath. Don't add if we're
    // replacing an existing file -- it'll already be there.

    if ( bJavaDir && !replace ) {
        PRBool found_zip = endsWith(finalFile, ".zip");
        PRBool found_jar = endsWith(finalFile, ".jar");;
        if (found_zip || found_jar) {
            AddToClasspath( finalFile );
        }
    }


    // Register file and log for Uninstall

    if ( 0 == err || SU_REBOOT_NEEDED == err ) {
        // we ignore all registry errors because they're not
        // important enough to abort an otherwise OK install.
        if (!bChild) {
            int found;
            if (regPackageName) {
                char *reg_package_name = regPackageName->ToNewCString();
                found = VR_UninstallFileExistsInList( reg_package_name, vr_name );
                delete reg_package_name;
            } else {
                found = VR_UninstallFileExistsInList( "", vr_name );
            }
            if (found != REGERR_OK)
                bUpgrade = PR_FALSE;
            else
                bUpgrade = PR_TRUE;
        } else if (REGERR_OK == VR_InRegistry(vr_name)) {
            bUpgrade = PR_TRUE;
        } else {
            bUpgrade = PR_FALSE;
        }

        err = VR_GetRefCount( vr_name, &refCount );
        if ( err != REGERR_OK )
        {
            refCount = 0;
        }


        if (!bUpgrade) {
            if (refCount != 0)
            {
                rc = 1 + refCount;
                VR_Install( vr_name, final_file, versionInfo->toString(), PR_FALSE );
                VR_SetRefCount( vr_name, rc );
            }
            else
            {
                if (replace)
                {
                    VR_Install( vr_name, final_file, versionInfo->toString(), PR_FALSE);
                    VR_SetRefCount( vr_name, 2 );
                }
                else
                {
                    VR_Install( vr_name, final_file, versionInfo->toString(), PR_FALSE );
                    VR_SetRefCount( vr_name, 1 );

                }
            }
        }
        else if (bUpgrade)
        {
            if (refCount == 0)
            {
                VR_Install( vr_name, final_file, versionInfo->toString(), PR_FALSE );
                VR_SetRefCount( vr_name, 1 );
            }
            else
            {
                VR_Install( vr_name, final_file, versionInfo->toString(), PR_FALSE );
                VR_SetRefCount( vr_name, 0 );
            }
        }

        if ( !bChild && !bUpgrade ) {
            if (regPackageName) {
                char *reg_package_name = regPackageName->ToNewCString();
                VR_UninstallAddFileToList( reg_package_name, vr_name );
                delete reg_package_name;
            } else {
                VR_UninstallAddFileToList( "", vr_name );
            }
        }
    }
    delete vr_name;
    delete final_file;

    if ( err != 0 ) {
        return SU_GetErrorMsg2(SU_ERROR_INSTALL_FILE_UNEXPECTED, finalFile, err);
    }
    return NULL;
}