/* void addEntryFile (in AUTF8String aZipEntry, in int32_t aCompression, * in nsIFile aFile, in boolean aQueue); */ NS_IMETHODIMP nsZipWriter::AddEntryFile(const nsACString & aZipEntry, int32_t aCompression, nsIFile *aFile, bool aQueue) { NS_ENSURE_ARG_POINTER(aFile); if (!mStream) return NS_ERROR_NOT_INITIALIZED; nsresult rv; if (aQueue) { nsZipQueueItem item; item.mOperation = OPERATION_ADD; item.mZipEntry = aZipEntry; item.mCompression = aCompression; rv = aFile->Clone(getter_AddRefs(item.mFile)); NS_ENSURE_SUCCESS(rv, rv); if (!mQueue.AppendElement(item)) return NS_ERROR_OUT_OF_MEMORY; return NS_OK; } if (mInQueue) return NS_ERROR_IN_PROGRESS; bool exists; rv = aFile->Exists(&exists); NS_ENSURE_SUCCESS(rv, rv); if (!exists) return NS_ERROR_FILE_NOT_FOUND; bool isdir; rv = aFile->IsDirectory(&isdir); NS_ENSURE_SUCCESS(rv, rv); PRTime modtime; rv = aFile->GetLastModifiedTime(&modtime); NS_ENSURE_SUCCESS(rv, rv); modtime *= PR_USEC_PER_MSEC; uint32_t permissions; rv = aFile->GetPermissions(&permissions); NS_ENSURE_SUCCESS(rv, rv); if (isdir) return InternalAddEntryDirectory(aZipEntry, modtime, permissions); if (mEntryHash.Get(aZipEntry, nullptr)) return NS_ERROR_FILE_ALREADY_EXISTS; nsCOMPtr<nsIInputStream> inputStream; rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), aFile); NS_ENSURE_SUCCESS(rv, rv); rv = AddEntryStream(aZipEntry, modtime, aCompression, inputStream, false, permissions); NS_ENSURE_SUCCESS(rv, rv); return inputStream->Close(); }
/* void addEntryStream (in AUTF8String aZipEntry, in PRTime aModTime, * in int32_t aCompression, in nsIInputStream aStream, * in boolean aQueue); */ NS_IMETHODIMP nsZipWriter::AddEntryStream(const nsACString & aZipEntry, PRTime aModTime, int32_t aCompression, nsIInputStream *aStream, bool aQueue) { return AddEntryStream(aZipEntry, aModTime, aCompression, aStream, aQueue, PERMISSIONS_FILE); }
/* void addEntryChannel (in AUTF8String aZipEntry, in PRTime aModTime, * in int32_t aCompression, in nsIChannel aChannel, * in boolean aQueue); */ NS_IMETHODIMP nsZipWriter::AddEntryChannel(const nsACString & aZipEntry, PRTime aModTime, int32_t aCompression, nsIChannel *aChannel, bool aQueue) { NS_ENSURE_ARG_POINTER(aChannel); if (!mStream) return NS_ERROR_NOT_INITIALIZED; if (aQueue) { nsZipQueueItem item; item.mOperation = OPERATION_ADD; item.mZipEntry = aZipEntry; item.mModTime = aModTime; item.mCompression = aCompression; item.mPermissions = PERMISSIONS_FILE; item.mChannel = aChannel; if (!mQueue.AppendElement(item)) return NS_ERROR_OUT_OF_MEMORY; return NS_OK; } if (mInQueue) return NS_ERROR_IN_PROGRESS; if (mEntryHash.Get(aZipEntry, nullptr)) return NS_ERROR_FILE_ALREADY_EXISTS; nsCOMPtr<nsIInputStream> inputStream; nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo(); nsresult rv; if (loadInfo && loadInfo->GetSecurityMode()) { rv = aChannel->Open2(getter_AddRefs(inputStream)); } else { rv = aChannel->Open(getter_AddRefs(inputStream)); } NS_ENSURE_SUCCESS(rv, rv); rv = AddEntryStream(aZipEntry, aModTime, aCompression, inputStream, false, PERMISSIONS_FILE); NS_ENSURE_SUCCESS(rv, rv); return inputStream->Close(); }
/* void addEntryChannel (in AUTF8String aZipEntry, in PRTime aModTime, * in PRInt32 aCompression, in nsIChannel aChannel, * in boolean aQueue); */ NS_IMETHODIMP nsZipWriter::AddEntryChannel(const nsACString & aZipEntry, PRTime aModTime, PRInt32 aCompression, nsIChannel *aChannel, PRBool aQueue) { NS_ENSURE_ARG_POINTER(aChannel); if (!mStream) return NS_ERROR_NOT_INITIALIZED; if (aQueue) { nsZipQueueItem item; item.mOperation = OPERATION_ADD; item.mZipEntry = aZipEntry; item.mModTime = aModTime; item.mCompression = aCompression; item.mChannel = aChannel; if (!mQueue.AppendElement(item)) return NS_ERROR_OUT_OF_MEMORY; return NS_OK; } if (mInQueue) return NS_ERROR_IN_PROGRESS; if (mEntryHash.Get(aZipEntry, nsnull)) return NS_ERROR_FILE_ALREADY_EXISTS; nsCOMPtr<nsIInputStream> inputStream; nsresult rv = aChannel->Open(getter_AddRefs(inputStream)); NS_ENSURE_SUCCESS(rv, rv); rv = AddEntryStream(aZipEntry, aModTime, aCompression, inputStream, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); return inputStream->Close(); }