Landing nsIFile.
git-svn-id: svn://10.0.0.236/trunk@58490 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
|
||||
interface nsISimpleEnumerator;
|
||||
interface nsIInputStream;
|
||||
native nsFileSpec(nsFileSpec&);
|
||||
interface nsIFile;
|
||||
|
||||
[scriptable, uuid(6ca5e43e-9632-11d3-8cd9-0060b0fc14a3)]
|
||||
interface nsIZipEntry : nsISupports
|
||||
@@ -47,7 +47,7 @@ interface nsIZipReader : nsISupports
|
||||
/**
|
||||
* Initializes a zip reader after construction.
|
||||
*/
|
||||
[noscript] void init(in nsFileSpec zipFile);
|
||||
void init(in nsIFile zipFile);
|
||||
|
||||
/**
|
||||
* Opens a zip reader.
|
||||
@@ -63,7 +63,7 @@ interface nsIZipReader : nsISupports
|
||||
/**
|
||||
* Extracts a zip entry into a local file specified by outFile.
|
||||
*/
|
||||
[noscript] void extract(in string zipEntry, in nsFileSpec outFile);
|
||||
void extract(in string zipEntry, in nsIFile outFile);
|
||||
|
||||
/**
|
||||
* Returns a nsIZipEntry describing a specified zip entry.
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
#include "nsJAR.h"
|
||||
#include "nsJARInputStream.h"
|
||||
//#include "nsIFile.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
#ifndef __gen_nsIFile_h__
|
||||
#define NS_ERROR_FILE_UNRECONGNIZED_PATH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 1)
|
||||
@@ -99,7 +99,7 @@ nsJAR::~nsJAR()
|
||||
NS_IMPL_ISUPPORTS1(nsJAR, nsIZipReader);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJAR::Init(nsFileSpec& zipFile)
|
||||
nsJAR::Init(nsIFile* zipFile)
|
||||
{
|
||||
mZipFile = zipFile;
|
||||
return NS_OK;
|
||||
@@ -108,7 +108,16 @@ nsJAR::Init(nsFileSpec& zipFile)
|
||||
NS_IMETHODIMP
|
||||
nsJAR::Open()
|
||||
{
|
||||
PRInt32 err = mZip.OpenArchive( nsNSPRPath(mZipFile) );
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(mZipFile, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRFileDesc* fd;
|
||||
rv = localFile->OpenNSPRFileDesc(PR_RDONLY, 0664, &fd);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRInt32 err = mZip.OpenArchiveWithFileDesc(fd);
|
||||
PR_Close(fd);
|
||||
return ziperr2nsresult(err);
|
||||
}
|
||||
|
||||
@@ -120,9 +129,19 @@ nsJAR::Close()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJAR::Extract(const char *zipEntry, nsFileSpec& outFile)
|
||||
nsJAR::Extract(const char *zipEntry, nsIFile* outFile)
|
||||
{
|
||||
PRInt32 err = mZip.ExtractFile(zipEntry, nsNSPRPath(outFile));
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(outFile, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRFileDesc* fd;
|
||||
rv = localFile->OpenNSPRFileDesc(PR_RDWR, 0664, &fd);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRUint16 mode;
|
||||
PRInt32 err = mZip.ExtractFileToFileDesc(zipEntry, fd, &mode);
|
||||
PR_Close(fd);
|
||||
return ziperr2nsresult(err);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,12 +28,13 @@
|
||||
#ifndef nsJAR_h__
|
||||
#define nsJAR_h__
|
||||
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIZipReader.h"
|
||||
#include "prtypes.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsZipArchive.h"
|
||||
#include "zipfile.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsIInputStream;
|
||||
|
||||
@@ -60,7 +61,7 @@ class nsJAR : public nsIZipReader
|
||||
|
||||
private:
|
||||
|
||||
nsFileSpec mZipFile;
|
||||
nsCOMPtr<nsIFile> mZipFile;
|
||||
nsZipArchive mZip;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "nsJARChannel.h"
|
||||
#include "nsCRT.h"
|
||||
@@ -28,12 +27,11 @@
|
||||
#include "nsIURL.h"
|
||||
#include "nsIMIMEService.h"
|
||||
#include "nsAutoLock.h"
|
||||
#include "nsIFileStreams.h"
|
||||
|
||||
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
||||
static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID);
|
||||
static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsJARDownloadObserver : public nsIStreamObserver
|
||||
@@ -58,18 +56,18 @@ public:
|
||||
"wrong transport");
|
||||
// after successfully downloading the jar file to the cache,
|
||||
// start the extraction process:
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFileChannel> jarCacheFile;
|
||||
rv = serv->NewChannelFromNativePath(mJarCacheFile.GetNativePathCString(),
|
||||
mJARChannel->mLoadGroup,
|
||||
mJARChannel->mCallbacks,
|
||||
mJARChannel->mLoadAttributes,
|
||||
nsnull,
|
||||
mJARChannel->mBufferSegmentSize,
|
||||
mJARChannel->mBufferMaxSize,
|
||||
getter_AddRefs(jarCacheFile));
|
||||
rv = NS_NewFileChannel(mJarCacheFile,
|
||||
PR_RDONLY,
|
||||
nsnull, // XXX content type
|
||||
0, // XXX content length
|
||||
mJARChannel->mLoadGroup,
|
||||
mJARChannel->mCallbacks,
|
||||
mJARChannel->mLoadAttributes,
|
||||
nsnull,
|
||||
mJARChannel->mBufferSegmentSize,
|
||||
mJARChannel->mBufferMaxSize,
|
||||
getter_AddRefs(jarCacheFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mJARChannel->ExtractJARElement(jarCacheFile);
|
||||
@@ -78,7 +76,7 @@ public:
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsJARDownloadObserver(nsFileSpec& jarCacheFile, nsJARChannel* jarChannel) {
|
||||
nsJARDownloadObserver(nsIFile* jarCacheFile, nsJARChannel* jarChannel) {
|
||||
NS_INIT_REFCNT();
|
||||
mJarCacheFile = jarCacheFile;
|
||||
mJARChannel = jarChannel;
|
||||
@@ -90,7 +88,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
nsFileSpec mJarCacheFile;
|
||||
nsCOMPtr<nsIFile> mJarCacheFile;
|
||||
nsJARChannel* mJARChannel;
|
||||
};
|
||||
|
||||
@@ -314,29 +312,35 @@ nsJARChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
else {
|
||||
// otherwise, we need to download the jar file
|
||||
|
||||
nsFileSpec jarCacheFile;
|
||||
rv = GetCacheFile(jarCacheFile);
|
||||
nsCOMPtr<nsIFile> jarCacheFile;
|
||||
rv = GetCacheFile(getter_AddRefs(jarCacheFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (jarCacheFile.IsFile()) {
|
||||
|
||||
PRBool filePresent;
|
||||
|
||||
rv = jarCacheFile->IsFile(&filePresent);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (filePresent)
|
||||
{
|
||||
// then we've already got the file in the local cache -- no need to download it
|
||||
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFileChannel> jarCacheChannel;
|
||||
rv = serv->NewChannelFromNativePath(jarCacheFile.GetNativePathCString(),
|
||||
mLoadGroup,
|
||||
mCallbacks,
|
||||
mLoadAttributes,
|
||||
nsnull,
|
||||
mBufferSegmentSize,
|
||||
mBufferMaxSize,
|
||||
getter_AddRefs(jarCacheChannel));
|
||||
|
||||
nsCOMPtr<nsIChannel> jarCacheChannel;
|
||||
rv = fts->CreateTransport(jarCacheFile,
|
||||
PR_RDONLY,
|
||||
mCommand,
|
||||
mBufferSegmentSize,
|
||||
mBufferMaxSize,
|
||||
getter_AddRefs(jarCacheChannel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = ExtractJARElement(jarCacheChannel);
|
||||
|
||||
nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(jarCacheChannel);
|
||||
if (fileChannel) return NS_ERROR_FAILURE;
|
||||
rv = ExtractJARElement(fileChannel);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -347,7 +351,8 @@ nsJARChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
|
||||
// use a file transport to serve as a data pump for the download (done
|
||||
// on some other thread)
|
||||
rv = fts->CreateTransport(jarCacheFile, mCommand,
|
||||
nsCOMPtr<nsIChannel> jarCacheTransport;
|
||||
rv = fts->CreateTransport(jarCacheFile, PR_RDONLY, mCommand,
|
||||
mBufferSegmentSize, mBufferMaxSize,
|
||||
getter_AddRefs(mJarCacheTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@@ -369,16 +374,25 @@ nsJARChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJARChannel::GetCacheFile(nsFileSpec& cacheFile)
|
||||
nsJARChannel::GetCacheFile(nsIFile* *cacheFile)
|
||||
{
|
||||
// XXX change later to use the real network cache
|
||||
nsresult rv;
|
||||
|
||||
nsSpecialSystemDirectory jarCacheFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
|
||||
jarCacheFile += "jarCache";
|
||||
nsCOMPtr<nsIFile> jarCacheFile;
|
||||
rv = NS_GetSpecialDirectory("xpcom.currentProcess.componentDirectory",
|
||||
getter_AddRefs(jarCacheFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!jarCacheFile.Exists())
|
||||
jarCacheFile.CreateDirectory();
|
||||
jarCacheFile->Append("jarCache");
|
||||
|
||||
PRBool exists;
|
||||
rv = jarCacheFile->Exists(&exists);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!exists) {
|
||||
rv = jarCacheFile->Create(nsIFile::DIRECTORY_TYPE, 0664);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURL> jarBaseURL = do_QueryInterface(mJARBaseURI, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@@ -386,10 +400,11 @@ nsJARChannel::GetCacheFile(nsFileSpec& cacheFile)
|
||||
char* jarFileName;
|
||||
rv = jarBaseURL->GetFileName(&jarFileName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
jarCacheFile += jarFileName;
|
||||
jarCacheFile->Append(jarFileName);
|
||||
nsCRT::free(jarFileName);
|
||||
|
||||
cacheFile = jarCacheFile;
|
||||
*cacheFile = jarCacheFile;
|
||||
NS_ADDREF(*cacheFile);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -606,8 +621,8 @@ nsJARChannel::Open(char* *contentType, PRInt32 *contentLength)
|
||||
getter_AddRefs(mJAR));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsFileSpec fs;
|
||||
rv = mJARBaseFile->GetFileSpec(&fs);
|
||||
nsCOMPtr<nsIFile> fs;
|
||||
rv = mJARBaseFile->GetFile(getter_AddRefs(fs));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mJAR->Init(fs);
|
||||
|
||||
@@ -28,13 +28,13 @@
|
||||
#include "nsIJARProtocolHandler.h"
|
||||
#include "nsIJARURI.h"
|
||||
#include "nsIFileSystem.h"
|
||||
#include "nsIFileChannel.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIZipReader.h"
|
||||
#include "nsIFileChannel.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsIFile.h"
|
||||
|
||||
class nsIFileChannel;
|
||||
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
PRUint32 bufferMaxSize);
|
||||
|
||||
nsresult ExtractJARElement(nsIFileChannel* jarFileChannel);
|
||||
nsresult GetCacheFile(nsFileSpec& cacheFile);
|
||||
nsresult GetCacheFile(nsIFile* *cacheFile);
|
||||
|
||||
friend class nsJARDownloadObserver;
|
||||
|
||||
|
||||
@@ -289,6 +289,22 @@ PRInt32 nsZipArchive::OpenArchive( const char * aArchiveName )
|
||||
return BuildFileList();
|
||||
}
|
||||
|
||||
PRInt32 nsZipArchive::OpenArchiveWithFileDesc(PRFileDesc* fd)
|
||||
{
|
||||
//-- validate arguments
|
||||
if (fd == 0)
|
||||
return ZIP_ERR_PARAM;
|
||||
|
||||
//-- not allowed to do two opens on the same object!
|
||||
if ( mFd != 0 )
|
||||
return ZIP_ERR_GENERAL;
|
||||
|
||||
mFd = fd;
|
||||
|
||||
//-- get table of contents for archive
|
||||
return BuildFileList();
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
// nsZipArchive::CloseArchive
|
||||
//---------------------------------------------
|
||||
@@ -339,17 +355,17 @@ PRInt32 nsZipArchive::GetItem( const char * aFilename, nsZipItem *result)
|
||||
//---------------------------------------------
|
||||
// nsZipArchive::ReadInit
|
||||
//---------------------------------------------
|
||||
PRInt32 nsZipArchive::ReadInit(const char* aFilename, nsZipRead** aRead)
|
||||
PRInt32 nsZipArchive::ReadInit(const char* zipEntry, nsZipRead** aRead)
|
||||
{
|
||||
//-- Parameter validity check
|
||||
if (aFilename == 0 || aRead == 0)
|
||||
if (zipEntry == 0 || aRead == 0)
|
||||
return ZIP_ERR_PARAM;
|
||||
|
||||
PRInt32 result;
|
||||
|
||||
//-- find item and seek to file position
|
||||
nsZipItem* item;
|
||||
result = ReadInitImpl(aFilename, &item);
|
||||
result = ReadInitImpl(zipEntry, &item);
|
||||
if (result != ZIP_OK) return result;
|
||||
|
||||
//-- Create nsZipRead object
|
||||
@@ -429,17 +445,41 @@ PRUint32 nsZipArchive::Available(nsZipRead* aRead)
|
||||
//---------------------------------------------
|
||||
// nsZipArchive::ExtractFile
|
||||
//---------------------------------------------
|
||||
PRInt32 nsZipArchive::ExtractFile(const char* aFilename, const char* aOutname)
|
||||
PRInt32 nsZipArchive::ExtractFile(const char* zipEntry, const char* aOutname)
|
||||
{
|
||||
PRFileDesc* fOut = PR_Open(aOutname, ZFILE_CREATE, 0644);
|
||||
if (fOut == 0)
|
||||
return ZIP_ERR_DISK;
|
||||
|
||||
PRUint16 mode;
|
||||
PRInt32 status = ExtractFileToFileDesc(zipEntry, fOut, &mode);
|
||||
PR_Close(fOut);
|
||||
|
||||
if (status != ZIP_OK) {
|
||||
PR_Delete(aOutname);
|
||||
}
|
||||
#if defined(XP_UNIX) || defined(XP_PC)
|
||||
else {
|
||||
//-- set extracted file permissions
|
||||
chmod(aOutname, mode);
|
||||
}
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsZipArchive::ExtractFileToFileDesc(const char * zipEntry, PRFileDesc* outFD,
|
||||
PRUint16 *itemModeResult)
|
||||
{
|
||||
//-- sanity check arguments
|
||||
if ( aFilename == 0 || aOutname == 0 )
|
||||
if ( zipEntry == 0 || outFD == 0 )
|
||||
return ZIP_ERR_PARAM;
|
||||
|
||||
PRInt32 status;
|
||||
nsZipItem* item;
|
||||
|
||||
//-- Find item in archive and seek to it
|
||||
status = ReadInitImpl( aFilename, &item );
|
||||
status = ReadInitImpl( zipEntry, &item );
|
||||
if (status != ZIP_OK)
|
||||
return status;
|
||||
|
||||
@@ -447,18 +487,18 @@ PRInt32 nsZipArchive::ExtractFile(const char* aFilename, const char* aOutname)
|
||||
switch( item->compression )
|
||||
{
|
||||
case STORED:
|
||||
status = CopyItemToDisk( item, aOutname );
|
||||
status = CopyItemToDisk( item, outFD );
|
||||
break;
|
||||
|
||||
case DEFLATED:
|
||||
status = InflateItem( item, aOutname, 0 );
|
||||
status = InflateItem( item, outFD, 0 );
|
||||
break;
|
||||
|
||||
default:
|
||||
//-- unsupported compression type
|
||||
return ZIP_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (status != ZIP_OK)
|
||||
PR_Delete(aOutname);
|
||||
#if defined(XP_UNIX) || defined(XP_PC)
|
||||
@@ -468,7 +508,8 @@ PRInt32 nsZipArchive::ExtractFile(const char* aFilename, const char* aOutname)
|
||||
chmod(aOutname, item->mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
*itemModeResult = item->mode;
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -784,15 +825,15 @@ PRInt32 nsZipArchive::BuildFileList()
|
||||
//---------------------------------------------
|
||||
// nsZipArchive::GetFileItem
|
||||
//---------------------------------------------
|
||||
nsZipItem* nsZipArchive::GetFileItem( const char * aFilename )
|
||||
nsZipItem* nsZipArchive::GetFileItem( const char * zipEntry )
|
||||
{
|
||||
PR_ASSERT( aFilename != 0 );
|
||||
PR_ASSERT( zipEntry != 0 );
|
||||
|
||||
nsZipItem* item = mFiles[ HashName(aFilename) ];
|
||||
nsZipItem* item = mFiles[ HashName(zipEntry) ];
|
||||
|
||||
for ( ; item != 0; item = item->next )
|
||||
{
|
||||
if ( 0 == PL_strcmp( aFilename, item->name ) )
|
||||
if ( 0 == PL_strcmp( zipEntry, item->name ) )
|
||||
break; //-- found it
|
||||
}
|
||||
|
||||
@@ -820,12 +861,12 @@ PRUint32 nsZipArchive::HashName( const char* aName )
|
||||
//---------------------------------------------
|
||||
// nsZipArchive::ReadInitImpl
|
||||
//---------------------------------------------
|
||||
PRInt32 nsZipArchive::ReadInitImpl(const char* aFilename, nsZipItem** aItem)
|
||||
PRInt32 nsZipArchive::ReadInitImpl(const char* zipEntry, nsZipItem** aItem)
|
||||
{
|
||||
PR_ASSERT (aFilename != 0);
|
||||
PR_ASSERT (zipEntry != 0);
|
||||
|
||||
//-- find file information
|
||||
*aItem = GetFileItem( aFilename );
|
||||
*aItem = GetFileItem( zipEntry );
|
||||
if ( *aItem == 0 )
|
||||
return ZIP_ERR_FNF;
|
||||
|
||||
@@ -883,13 +924,12 @@ PRInt32 nsZipArchive::ReadItem( nsZipRead* aRead, char* aBuf,
|
||||
//---------------------------------------------
|
||||
// nsZipArchive::CopyItemToDisk
|
||||
//---------------------------------------------
|
||||
PRInt32 nsZipArchive::CopyItemToDisk( const nsZipItem* aItem, const char* aOutname )
|
||||
PRInt32 nsZipArchive::CopyItemToDisk(const nsZipItem* aItem, PRFileDesc* fOut)
|
||||
{
|
||||
PRInt32 status = ZIP_OK;
|
||||
PRUint32 chunk, pos, size, crc;
|
||||
PRFileDesc* fOut = 0;
|
||||
|
||||
PR_ASSERT( aItem != 0 && aOutname != 0 );
|
||||
PR_ASSERT( aItem != 0 && fOut != 0 );
|
||||
|
||||
char* buf = (char*)PR_Malloc(ZIP_BUFLEN);
|
||||
if ( buf == 0 )
|
||||
@@ -901,14 +941,6 @@ PRInt32 nsZipArchive::CopyItemToDisk( const nsZipItem* aItem, const char* aOutna
|
||||
//-- initialize crc
|
||||
crc = crc32(0L, Z_NULL, 0);
|
||||
|
||||
//-- open output file
|
||||
fOut = PR_Open( aOutname, ZFILE_CREATE , 0644);
|
||||
if ( fOut == 0 )
|
||||
{
|
||||
status = ZIP_ERR_DISK;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
//-- copy chunks until file is done
|
||||
size = aItem->size;
|
||||
for ( pos=0; pos < size; pos += chunk )
|
||||
@@ -937,10 +969,6 @@ PRInt32 nsZipArchive::CopyItemToDisk( const nsZipItem* aItem, const char* aOutna
|
||||
if ( (status == ZIP_OK) && (crc != aItem->crc32) )
|
||||
status = ZIP_ERR_CORRUPT;
|
||||
|
||||
cleanup:
|
||||
if ( fOut != 0 )
|
||||
PR_Close( fOut );
|
||||
|
||||
PR_FREEIF( buf );
|
||||
return status;
|
||||
}
|
||||
@@ -949,7 +977,7 @@ cleanup:
|
||||
//---------------------------------------------
|
||||
// nsZipArchive::InflateItem
|
||||
//---------------------------------------------
|
||||
PRInt32 nsZipArchive::InflateItem( const nsZipItem* aItem, const char* aOutname,
|
||||
PRInt32 nsZipArchive::InflateItem( const nsZipItem* aItem, PRFileDesc* fOut,
|
||||
char* bigBuf )
|
||||
/*
|
||||
* This function either inflates an archive item to disk, to the
|
||||
@@ -966,7 +994,6 @@ PRInt32 nsZipArchive::InflateItem( const nsZipItem* aItem, const char* aOutname,
|
||||
PRInt32 status = ZIP_OK;
|
||||
PRUint32 chunk, inpos, outpos, size, crc;
|
||||
PRUint32 bigBufSize;
|
||||
PRFileDesc* fOut = 0;
|
||||
z_stream zs;
|
||||
int zerr;
|
||||
PRBool bInflating = PR_FALSE;
|
||||
@@ -980,7 +1007,7 @@ PRInt32 nsZipArchive::InflateItem( const nsZipItem* aItem, const char* aOutname,
|
||||
#endif /* STANDALONE */
|
||||
|
||||
// -- if aOutname is null, we'll be writing to a buffer instead of a file
|
||||
if (aOutname != 0)
|
||||
if (fOut != 0)
|
||||
{
|
||||
PR_ASSERT( aItem != 0 );
|
||||
bToFile = PR_TRUE;
|
||||
@@ -1005,17 +1032,6 @@ PRInt32 nsZipArchive::InflateItem( const nsZipItem* aItem, const char* aOutname,
|
||||
//-- We should already be at the correct spot in the archive.
|
||||
//-- ReadInitImpl did the seek().
|
||||
|
||||
if (bToFile)
|
||||
{
|
||||
//-- open output file
|
||||
fOut = PR_Open( aOutname, ZFILE_CREATE, 0644);
|
||||
if ( fOut == 0 )
|
||||
{
|
||||
status = ZIP_ERR_DISK;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
//-- set up the inflate
|
||||
memset( &zs, 0, sizeof(zs) );
|
||||
zerr = inflateInit2( &zs, -MAX_WBITS );
|
||||
@@ -1147,8 +1163,6 @@ cleanup:
|
||||
inflateEnd( &zs );
|
||||
}
|
||||
|
||||
if (fOut != 0 )
|
||||
PR_Close( fOut );
|
||||
PR_FREEIF( inbuf );
|
||||
PR_FREEIF( outbuf );
|
||||
return status;
|
||||
|
||||
@@ -100,7 +100,9 @@ public:
|
||||
* @param aArchiveName full pathname of archive
|
||||
* @return status code
|
||||
*/
|
||||
PRInt32 OpenArchive( const char * aArchiveName );
|
||||
PRInt32 OpenArchive(const char * aArchiveName);
|
||||
|
||||
PRInt32 OpenArchiveWithFileDesc(PRFileDesc* fd);
|
||||
|
||||
/**
|
||||
* Closes an open archive.
|
||||
@@ -121,11 +123,11 @@ public:
|
||||
* Prepare to read from an item in the archive. Must be called
|
||||
* before any calls to Read or Available
|
||||
*
|
||||
* @param aFilename name of item in file
|
||||
* @param zipEntry name of item in file
|
||||
* @param (out) a structure used by Read and Available
|
||||
* @return status code
|
||||
*/
|
||||
PRInt32 ReadInit( const char* aFilename, nsZipRead** aRead);
|
||||
PRInt32 ReadInit(const char* zipEntry, nsZipRead** aRead);
|
||||
|
||||
/**
|
||||
* Read
|
||||
@@ -155,11 +157,14 @@ public:
|
||||
/**
|
||||
* ExtractFile
|
||||
*
|
||||
* @param aFilename name of file in archive to extract
|
||||
* @param zipEntry name of file in archive to extract
|
||||
* @param aOutname where to extract on disk
|
||||
* @return status code
|
||||
*/
|
||||
PRInt32 ExtractFile( const char * aFilename, const char * aOutname );
|
||||
PRInt32 ExtractFile( const char * zipEntry, const char * aOutname );
|
||||
|
||||
PRInt32 ExtractFileToFileDesc(const char * zipEntry, PRFileDesc* outFD,
|
||||
PRUint16 *itemModeResult);
|
||||
|
||||
/**
|
||||
* FindInit
|
||||
@@ -195,15 +200,15 @@ private:
|
||||
nsZipArchive(const nsZipArchive& rhs); // prevent copies
|
||||
|
||||
PRInt32 BuildFileList();
|
||||
nsZipItem* GetFileItem( const char * aFilename );
|
||||
nsZipItem* GetFileItem( const char * zipEntry );
|
||||
PRUint32 HashName( const char* aName );
|
||||
|
||||
PRInt32 ReadInitImpl(const char* aFilename, nsZipItem** aItem);
|
||||
PRInt32 ReadInitImpl(const char* zipEntry, nsZipItem** aItem);
|
||||
PRInt32 ReadItem( nsZipRead* aRead, char* aBuf,
|
||||
PRUint32 aCount, PRUint32* aActual );
|
||||
PRInt32 CopyItemToDisk( const nsZipItem* aItem, const char* aOutname );
|
||||
PRInt32 CopyItemToDisk( const nsZipItem* aItem, PRFileDesc* outFD );
|
||||
PRInt32 InflateItem( const nsZipItem* aItem,
|
||||
const char* aOutname,
|
||||
PRFileDesc* outFD,
|
||||
char* buf );
|
||||
PRInt32 ReadInflatedItem( const nsZipItem* aItem,
|
||||
char* inflatedBuf, char* outbuf,
|
||||
|
||||
Reference in New Issue
Block a user