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