PackageWriter.h revision cdfeba5a
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			int32				CompressionLevel() const;
56			void				SetCompressionLevel(int32 compressionLevel);
57
58private:
59			uint32				fFlags;
60			int32				fCompressionLevel;
61};
62
63
64class BPackageWriter {
65public:
66								BPackageWriter(
67									BPackageWriterListener* listener);
68								~BPackageWriter();
69
70			status_t			Init(const char* fileName,
71									const BPackageWriterParameters* parameters
72										= NULL);
73			status_t			SetInstallPath(const char* installPath);
74			void				SetCheckLicenses(bool checkLicenses);
75			status_t			AddEntry(const char* fileName, int fd = -1);
76			status_t			Finish();
77
78			status_t			Recompress(BPackageReader* reader);
79									// to be called after Init(); no Finish()
80
81private:
82			PackageWriterImpl*	fImpl;
83};
84
85
86}	// namespace BHPKG
87
88}	// namespace BPackageKit
89
90
91#endif	// _PACKAGE__HPKG__PACKAGE_WRITER_H_
92