Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
nsInstallFile Class Reference

#include <nsInstallFile.h>

Inheritance diagram for nsInstallFile:
Inheritance graph
[legend]
Collaboration diagram for nsInstallFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsInstallFile (nsInstall *inInstall, const nsString &inVRName, const nsString &inVInfo, const nsString &inJarLocation, nsInstallFolder *folderSpec, const nsString &inPartialPath, PRInt32 mode, PRBool bRegister, PRInt32 *error)
virtual ~nsInstallFile ()
PRInt32 Prepare ()
PRInt32 Complete ()
void Abort ()
char * toString ()
PRBool CanUninstall ()
PRBool RegisterPackageNode ()

Protected Attributes

nsInstallmInstall

Private Member Functions

PRInt32 CompleteFileMove ()
void CreateAllFolders (nsInstall *inInstall, nsIFile *inFolderPath, PRInt32 *error)

Private Attributes

nsStringmVersionInfo
nsStringmJarLocation
nsCOMPtr< nsIFilemExtractedFile
nsCOMPtr< nsIFilemFinalFile
nsStringmVersionRegistryName
PRBool mReplaceFile
PRBool mRegister
PRUint32 mFolderCreateCount
PRInt32 mMode

Detailed Description

Definition at line 60 of file nsInstallFile.h.


Constructor & Destructor Documentation

nsInstallFile::nsInstallFile ( nsInstall inInstall,
const nsString inVRName,
const nsString inVInfo,
const nsString inJarLocation,
nsInstallFolder folderSpec,
const nsString inPartialPath,
PRInt32  mode,
PRBool  bRegister,
PRInt32 error 
)

Definition at line 65 of file nsInstallFile.cpp.

  : nsInstallObject(inInstall),
    mVersionInfo(nsnull),
    mJarLocation(nsnull),
    mExtractedFile(nsnull),
    mFinalFile(nsnull),
    mVersionRegistryName(nsnull),
    mReplaceFile(PR_FALSE),
    mRegister(aRegister),
    mMode(mode)
{
    MOZ_COUNT_CTOR(nsInstallFile);

    PRBool flagExists, flagIsFile;
    mFolderCreateCount = 0;

    if ((folderSpec == nsnull) || (inInstall == NULL))
    {
        *error = nsInstall::INVALID_ARGUMENTS;
        return;
    }

    *error = nsInstall::SUCCESS;
    
    nsCOMPtr<nsIFile> tmp = folderSpec->GetFileSpec();
    if (!tmp)
    {
        *error = nsInstall::INVALID_ARGUMENTS;
        return;
    }

    tmp->Clone(getter_AddRefs(mFinalFile));
    if (mFinalFile == nsnull)
    {
        *error = nsInstall::OUT_OF_MEMORY;
        return;
    }

    mFinalFile->Exists(&flagExists);
    if (flagExists)
    {
        // is there a file with the same name as the proposed folder?
        mFinalFile->IsFile(&flagIsFile);
        if ( flagIsFile) 
        {
            *error = nsInstall::ACCESS_DENIED;
            return;
        }
        // else this directory already exists, so do nothing
    }

    //Need to parse the inPartialPath to remove any separators
    PRBool finished = PR_FALSE;
    PRUint32 offset = 0;
    PRInt32 location = 0, nodeLength = 0;
    nsString subString;

    location = inPartialPath.FindChar('/', offset);
    if (location == ((PRInt32)inPartialPath.Length() - 1)) //trailing slash
    {
        *error = nsInstall::INVALID_ARGUMENTS;
        return;
    }

    while (!finished)
    {
        if (location == kNotFound) //no separators were found
        {
            nodeLength = inPartialPath.Length() - offset;
            finished = PR_TRUE;
        }
        else
        {
            nodeLength = location - offset;
        }
        
        if (nodeLength > MAX_FILENAME) 
        {
            *error = nsInstall::FILENAME_TOO_LONG;
            return;
        }
        else
        {
            nsresult rv = inPartialPath.Mid(subString, offset, nodeLength);
            mFinalFile->Append(subString);
            offset += nodeLength + 1;
            if (!finished)
                location = inPartialPath.FindChar('/', offset);
        }
    }

    mFinalFile->Exists(&mReplaceFile);
    mVersionRegistryName  = new nsString(inComponentName);
    mJarLocation          = new nsString(inJarLocation);
    mVersionInfo             = new nsString(inVInfo);
     
    if (mVersionRegistryName == nsnull ||
        mJarLocation         == nsnull ||
        mVersionInfo         == nsnull )
    {
        *error = nsInstall::OUT_OF_MEMORY;
        return;
    }
}

Here is the call graph for this function:

Definition at line 179 of file nsInstallFile.cpp.

{
    if (mVersionRegistryName)
        delete mVersionRegistryName;
  
    if (mJarLocation)
        delete mJarLocation;
  
    if (mVersionInfo)
        delete mVersionInfo;
    
    //if(mFinalFile)
    //    mFinalFile = nsnull;

    //if(mExtractedFile)
    //    mExtractedFile = nsnull;

    MOZ_COUNT_DTOR(nsInstallFile);
}

Member Function Documentation

void nsInstallFile::Abort ( ) [virtual]

Implements nsInstallObject.

Definition at line 330 of file nsInstallFile.cpp.

Implements nsInstallObject.

Definition at line 434 of file nsInstallFile.cpp.

{
    return PR_TRUE;
}

Implements nsInstallObject.

Definition at line 305 of file nsInstallFile.cpp.

{
    PRInt32 err;

    if (mInstall == nsnull || mVersionRegistryName == nsnull || mFinalFile == nsnull ) 
    {
       return nsInstall::INVALID_ARGUMENTS;
    }
   
    err = CompleteFileMove();
    
    if ( mRegister && (0 == err || nsInstall::REBOOT_NEEDED == err) ) 
    {
        nsCAutoString path;
        mFinalFile->GetNativePath(path);
        VR_Install( NS_CONST_CAST(char*, NS_ConvertUCS2toUTF8(*mVersionRegistryName).get()),
                    NS_CONST_CAST(char*, path.get()),
                    NS_CONST_CAST(char*, NS_ConvertUCS2toUTF8(*mVersionInfo).get()),
                    PR_FALSE );
    }
    
    return err;

}

Here is the call graph for this function:

Definition at line 397 of file nsInstallFile.cpp.

{
    int    result         = 0;
    PRBool bIsEqual = PR_FALSE;
    
    if (mExtractedFile == nsnull) 
    {
        return nsInstall::UNEXPECTED_ERROR;
    }
       
    
    mExtractedFile->Equals(mFinalFile, &bIsEqual);
    if ( bIsEqual ) 
    {
        /* No need to rename, they are the same */
        result = nsInstall::SUCCESS;
    } 
    else 
    {
        result = ReplaceFileNowOrSchedule(mExtractedFile, mFinalFile, mMode );
    }

    if(mMode & WIN_SHARED_FILE)
    {
      nsCAutoString path;
      mFinalFile->GetNativePath(path);
      RegisterSharedFile(path.get(), mReplaceFile);
    }

    return result;  
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsInstallFile::CreateAllFolders ( nsInstall inInstall,
nsIFile inFolderPath,
PRInt32 error 
) [private]

Definition at line 202 of file nsInstallFile.cpp.

{
    PRBool              flagExists;
    nsInstallLogComment *ilc   = nsnull;

    nsresult rv = aFolder->Exists(&flagExists);
    if (NS_FAILED(rv))
        *aError = nsInstall::UNEXPECTED_ERROR;
    else if (flagExists)
        *aError = nsInstall::SUCCESS;
    else
    {
        // Doesn't exist, work our way up trying to create each node above
        nsCOMPtr<nsIFile> parent;
        rv = aFolder->GetParent(getter_AddRefs(parent));
        if (NS_FAILED(rv))
        {
            // we're already at the top -- give up
            *aError = nsInstall::ACCESS_DENIED;
            return;
        }

        CreateAllFolders(aInstall, parent, aError);
        if (*aError != nsInstall::SUCCESS)
            return;

        aFolder->Create(nsIFile::DIRECTORY_TYPE, 0755); //nsIFileXXX: What kind of permissions are required here?
        ++mFolderCreateCount;

        nsAutoString folderPath;
        aFolder->GetPath(folderPath);
        ilc = new nsInstallLogComment(aInstall,
                                      NS_LITERAL_STRING("CreateFolder"),
                                      folderPath,
                                      aError);
        if(ilc == nsnull)
            *aError = nsInstall::OUT_OF_MEMORY;

        if(*aError == nsInstall::SUCCESS)
            *aError = mInstall->ScheduleForInstall(ilc);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsInstallObject.

Definition at line 278 of file nsInstallFile.cpp.

{
    PRInt32 error = nsInstall::SUCCESS;

    if (mInstall == nsnull || mFinalFile == nsnull || mJarLocation == nsnull )
        return nsInstall::INVALID_ARGUMENTS;

    if (mReplaceFile == PR_FALSE)
    {
       /* although it appears that we are creating the dir _again_ it is necessary
        * when inPartialPath has arbitrary levels of nested dirs before the leaf
        */
        nsCOMPtr<nsIFile> parent;
        mFinalFile->GetParent(getter_AddRefs(parent));
        CreateAllFolders(mInstall, parent, &error);
        if(nsInstall::SUCCESS != error)
            return error;
    }

    return mInstall->ExtractFileFromJar(*mJarLocation, mFinalFile, getter_AddRefs(mExtractedFile)); 
}

Here is the call graph for this function:

Implements nsInstallObject.

Definition at line 444 of file nsInstallFile.cpp.

{
    return PR_TRUE;
}
char * nsInstallFile::toString ( ) [virtual]

Implements nsInstallObject.

Definition at line 337 of file nsInstallFile.cpp.

{
    char* buffer  = new char[RESBUFSIZE];
    char* rsrcVal = nsnull;

    if (buffer == nsnull || !mInstall)
        return nsnull;
    else
        buffer[0] = '\0';
    
    if (mReplaceFile)
    {
        if(mMode & WIN_SHARED_FILE)
        {
            rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("ReplaceSharedFile"));
        }
        else
        {
            rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("ReplaceFile"));
        }
    }
    else
    {
        if(mMode & WIN_SHARED_FILE)
        {
            rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("InstallSharedFile"));
        }
        else
        {
            rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("InstallFile"));
        }
    }

    if (rsrcVal)
    {
        char*    interimCStr = nsnull;
        nsString interimStr;

        if(mMode & DO_NOT_UNINSTALL)
          interimStr.Assign(NS_LITERAL_STRING("(*dnu*) "));

        interimStr.AppendWithConversion(rsrcVal);
        interimCStr = ToNewCString(interimStr);

        if(interimCStr)
        {
            nsCAutoString fname;
            if (mFinalFile)
                mFinalFile->GetNativePath(fname);

            PR_snprintf( buffer, RESBUFSIZE, interimCStr, fname.get() );
            Recycle(interimCStr);
        }
        Recycle(rsrcVal);
    }

    return buffer;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 101 of file nsInstallFile.h.

Definition at line 102 of file nsInstallFile.h.

Definition at line 108 of file nsInstallFile.h.

nsInstall* nsInstallObject::mInstall [protected, inherited]

Definition at line 69 of file nsInstallObject.h.

Definition at line 100 of file nsInstallFile.h.

Definition at line 110 of file nsInstallFile.h.

Definition at line 107 of file nsInstallFile.h.

Definition at line 106 of file nsInstallFile.h.

Definition at line 98 of file nsInstallFile.h.

Definition at line 104 of file nsInstallFile.h.


The documentation for this class was generated from the following files: