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