1/* 2 * Copyright 2009,2011, Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef _PACKAGE__HPKG__PACKAGE_WRITER_H_ 6#define _PACKAGE__HPKG__PACKAGE_WRITER_H_ 7 8 9#include <SupportDefs.h> 10 11#include <package/hpkg/ErrorOutput.h> 12 13 14class BPositionIO; 15 16 17namespace BPackageKit { 18 19namespace BHPKG { 20 21namespace BPrivate { 22 class PackageWriterImpl; 23} 24using BPrivate::PackageWriterImpl; 25 26 27class BPackageWriterListener : public BErrorOutput { 28public: 29 virtual void PrintErrorVarArgs(const char* format, 30 va_list args) = 0; 31 32 virtual void OnEntryAdded(const char* path) = 0; 33 34 virtual void OnTOCSizeInfo(uint64 uncompressedStringsSize, 35 uint64 uncompressedMainSize, 36 uint64 uncompressedTOCSize) = 0; 37 virtual void OnPackageAttributesSizeInfo(uint32 stringCount, 38 uint32 uncompressedSize) = 0; 39 virtual void OnPackageSizeInfo(uint32 headerSize, 40 uint64 heapSize, uint64 tocSize, 41 uint32 packageAttributesSize, 42 uint64 totalSize) = 0; 43}; 44 45 46class BPackageWriterParameters { 47public: 48 BPackageWriterParameters(); 49 ~BPackageWriterParameters(); 50 51 uint32 Flags() const; 52 void SetFlags(uint32 flags); 53 54 uint32 Compression() const; 55 void SetCompression(uint32 compression); 56 57 int32 CompressionLevel() const; 58 void SetCompressionLevel(int32 compressionLevel); 59 60private: 61 uint32 fFlags; 62 uint32 fCompression; 63 int32 fCompressionLevel; 64}; 65 66 67class BPackageWriter { 68public: 69 BPackageWriter( 70 BPackageWriterListener* listener); 71 ~BPackageWriter(); 72 73 status_t Init(const char* fileName, 74 const BPackageWriterParameters* parameters 75 = NULL); 76 status_t Init(BPositionIO* file, bool keepFile, 77 const BPackageWriterParameters* parameters 78 = NULL); 79 status_t SetInstallPath(const char* installPath); 80 void SetCheckLicenses(bool checkLicenses); 81 status_t AddEntry(const char* fileName, int fd = -1); 82 status_t Finish(); 83 84 status_t Recompress(BPositionIO* inputFile); 85 // to be called after Init(); no Finish() 86 87private: 88 PackageWriterImpl* fImpl; 89}; 90 91 92} // namespace BHPKG 93 94} // namespace BPackageKit 95 96 97#endif // _PACKAGE__HPKG__PACKAGE_WRITER_H_ 98