Back to index

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

#include <nsZipExtractor.h>

List of all members.

Public Member Functions

 nsZipExtractor (char *aSrc, char *aDest)
 ~nsZipExtractor ()
int Extract (nsComponent *aXPIEngine, int aTotal)
 nsZipExtractor (char *aSrc, char *aDest)
 ~nsZipExtractor ()
int Extract (nsComponent *aXPIEngine, int aTotal)

Private Member Functions

int DirCreateRecursive (char *aPath)
int DirCreateRecursive (char *aPath)

Private Attributes

char * mSrc
char * mDest

Detailed Description

Definition at line 49 of file nsZipExtractor.h.


Constructor & Destructor Documentation

nsZipExtractor::nsZipExtractor ( char *  aSrc,
char *  aDest 
)

Definition at line 46 of file nsZipExtractor.cpp.

                                                      :
    mSrc(NULL),
    mDest(NULL)
{
    if (aSrc)
        mSrc = strdup(aSrc);
    if (aDest)
        mDest = strdup(aDest);
}

Definition at line 56 of file nsZipExtractor.cpp.

nsZipExtractor::nsZipExtractor ( char *  aSrc,
char *  aDest 
)

Member Function Documentation

int nsZipExtractor::DirCreateRecursive ( char *  aPath) [private]

Definition at line 161 of file nsZipExtractor.cpp.

{
    int err = OK;
    char *slash = NULL, *pathpos = NULL;
    char currdir[MAXPATHLEN];
    struct stat dummy;
    
    if (!aPath || !mDest)
        return E_PARAM;

    slash = aPath + strlen(mDest);
    if (*slash != '/')
        return E_INVALID_PTR;

    while (slash)
    {
        memset(currdir, 0, MAXPATHLEN);
        strncpy(currdir, aPath, slash - aPath);
        
        if (-1 == stat(currdir, &dummy))
            mkdir(currdir, 0755);
        
        pathpos = slash;
        slash = strchr(pathpos+1, '/');
    }   

    return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsZipExtractor::DirCreateRecursive ( char *  aPath) [private]
int nsZipExtractor::Extract ( nsComponent aXPIEngine,
int  aTotal 
)
int nsZipExtractor::Extract ( nsComponent aXPIEngine,
int  aTotal 
)

Definition at line 63 of file nsZipExtractor.cpp.

{
    DUMP("Extract");
   
    char apath[MAXPATHLEN]; /* archive path */
    char bindir[512];
    char zpath[MAXPATHLEN]; /* path of file in zip archive */
    char epath[MAXPATHLEN]; /* path of file after being extracted */
    char *leaf = NULL, *lslash = NULL;
    struct stat dummy;
    int i, bFoundAll = FALSE, err = OK;
    PRInt32 zerr = ZIP_OK;
    void *hZip = NULL, *hFind = NULL;

    if (!aXPIEngine || !(aXPIEngine->GetArchive()))
        return E_PARAM;

    sprintf(apath, "%s/%s", mSrc, aXPIEngine->GetArchive());
    if (-1 == stat(apath, &dummy))
        return E_NO_DOWNLOAD;

    /* initialize archive etc. 
     */
    zerr = ZIP_OpenArchive(apath, &hZip);
    if (zerr != ZIP_OK) return E_EXTRACTION;
    hFind = ZIP_FindInit(hZip, (const char *) NULL);
    if (!hFind)
    {
        err = E_EXTRACTION;
        goto au_revoir;
    }

    /* extract files 
     */
    i = 0;
    while (!bFoundAll)
    {
        memset(zpath, 0, MAXPATHLEN);
        zerr = ZIP_FindNext(hFind, zpath, MAXPATHLEN);
        if (zerr == ZIP_ERR_FNF)
        {
            bFoundAll = true;
            break;
        }
        if (zerr != ZIP_OK)
        {
            err = E_EXTRACTION;
            goto au_revoir;
        }

        /* directory encountered: ignore entry
         */
        lslash = strrchr(zpath, '/');
        if (lslash == (zpath + strlen(zpath) - 1))
            continue;

        if (!lslash)
            leaf = zpath;
        else
            leaf = lslash + 1;
        if (!leaf)
            continue;

        /* update UI
         */
        if (gCtx->opt->mMode != nsXIOptions::MODE_SILENT)
            nsInstallDlg::MajorProgressCB(leaf, i, 
                aTotal, nsInstallDlg::ACT_EXTRACT);

        sprintf(epath, "%s/%s", mDest, zpath);
        err = DirCreateRecursive(epath);
        if (err != OK) goto au_revoir;

        zerr = ZIP_ExtractFile(hZip, zpath, epath);
        if (zerr != ZIP_OK)
        {
            err = E_EXTRACTION;
            goto au_revoir;
        }

        i++;
    }
    
    sprintf(bindir, "%s/%s", mDest, TMP_EXTRACT_SUBDIR);
    if (-1 == stat(bindir, &dummy))
        err = E_EXTRACTION;

au_revoir:
    /* close archive etc.
     */
    if (hFind)
        ZIP_FindFree(hFind);
    if (hZip)
        ZIP_CloseArchive(&hZip);
    return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

char * nsZipExtractor::mDest [private]

Definition at line 61 of file nsZipExtractor.h.

char * nsZipExtractor::mSrc [private]

Definition at line 60 of file nsZipExtractor.h.


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