michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: #ifndef _nsZipWriter_h_ michael@0: #define _nsZipWriter_h_ michael@0: michael@0: #include "nsIZipWriter.h" michael@0: #include "nsIFileStreams.h" michael@0: #include "nsIBufferedStreams.h" michael@0: #include "nsIRequestObserver.h" michael@0: #include "nsZipHeader.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCOMArray.h" michael@0: #include "nsTArray.h" michael@0: #include "nsDataHashtable.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: #define ZIPWRITER_CONTRACTID "@mozilla.org/zipwriter;1" michael@0: #define ZIPWRITER_CID { 0x430d416c, 0xa722, 0x4ad1, \ michael@0: { 0xbe, 0x98, 0xd9, 0xa4, 0x45, 0xf8, 0x5e, 0x3f } } michael@0: michael@0: #define OPERATION_ADD 0 michael@0: #define OPERATION_REMOVE 1 michael@0: struct nsZipQueueItem michael@0: { michael@0: public: michael@0: uint32_t mOperation; michael@0: nsCString mZipEntry; michael@0: nsCOMPtr mFile; michael@0: nsCOMPtr mChannel; michael@0: nsCOMPtr mStream; michael@0: PRTime mModTime; michael@0: int32_t mCompression; michael@0: uint32_t mPermissions; michael@0: }; michael@0: michael@0: class nsZipWriter MOZ_FINAL : public nsIZipWriter, michael@0: public nsIRequestObserver michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIZIPWRITER michael@0: NS_DECL_NSIREQUESTOBSERVER michael@0: michael@0: nsZipWriter(); michael@0: nsresult EntryCompleteCallback(nsZipHeader *aHeader, nsresult aStatus); michael@0: michael@0: private: michael@0: ~nsZipWriter(); michael@0: michael@0: uint32_t mCDSOffset; michael@0: bool mCDSDirty; michael@0: bool mInQueue; michael@0: michael@0: nsCOMPtr mFile; michael@0: nsCOMPtr mProcessObserver; michael@0: nsCOMPtr mProcessContext; michael@0: nsCOMPtr mStream; michael@0: nsCOMArray mHeaders; michael@0: nsTArray mQueue; michael@0: nsDataHashtable mEntryHash; michael@0: nsCString mComment; michael@0: michael@0: nsresult SeekCDS(); michael@0: void Cleanup(); michael@0: nsresult ReadFile(nsIFile *aFile); michael@0: nsresult InternalAddEntryDirectory(const nsACString & aZipEntry, michael@0: PRTime aModTime, uint32_t aPermissions); michael@0: nsresult BeginProcessingAddition(nsZipQueueItem* aItem, bool* complete); michael@0: nsresult BeginProcessingRemoval(int32_t aPos); michael@0: nsresult AddEntryStream(const nsACString & aZipEntry, PRTime aModTime, michael@0: int32_t aCompression, nsIInputStream *aStream, michael@0: bool aQueue, uint32_t aPermissions); michael@0: void BeginProcessingNextItem(); michael@0: void FinishQueue(nsresult aStatus); michael@0: }; michael@0: michael@0: #endif