xref: /haiku/headers/private/package/hpkg/PackageWriterImpl.h (revision 323b65468e5836bb27a5e373b14027d902349437)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
7 #define _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
8 
9 
10 #include <util/DoublyLinkedList.h>
11 #include <util/OpenHashTable.h>
12 
13 #include <package/hpkg/PackageWriter.h>
14 #include <package/hpkg/Strings.h>
15 #include <package/hpkg/WriterImplBase.h>
16 
17 
18 namespace BPackageKit {
19 
20 namespace BHPKG {
21 
22 
23 class BDataReader;
24 class BErrorOutput;
25 
26 
27 namespace BPrivate {
28 
29 
30 struct hpkg_header;
31 
32 class PackageWriterImpl : public WriterImplBase {
33 	typedef	WriterImplBase		inherited;
34 
35 public:
36 								PackageWriterImpl(
37 									BPackageWriterListener* listener);
38 								~PackageWriterImpl();
39 
40 			status_t			Init(const char* fileName);
41 			status_t			AddEntry(const char* fileName);
42 			status_t			Finish();
43 
44 private:
45 			struct Attribute;
46 			struct Entry;
47 			struct SubPathAdder;
48 
49 			typedef DoublyLinkedList<Entry> EntryList;
50 
51 private:
52 			status_t			_Init(const char* fileName);
53 			status_t			_Finish();
54 
55 			status_t			_RegisterEntry(const char* fileName);
56 			Entry*				_RegisterEntry(Entry* parent,
57 									const char* name, size_t nameLength,
58 									bool isImplicit);
59 
60 			status_t			_CheckLicenses();
61 
62 			void				_WriteTOC(hpkg_header& header);
63 			int32				_WriteTOCSections(uint64& _stringsSize,
64 									uint64& _mainSize);
65 			void				_WriteAttributeChildren(Attribute* attribute);
66 
67 			void				_WritePackageAttributes(hpkg_header& header);
68 
69 			void				_AddEntry(int dirFD, Entry* entry,
70 									const char* fileName, char* pathBuffer);
71 
72 			Attribute*			_AddAttribute(BHPKGAttributeID attributeID,
73 									const AttributeValue& value);
74 
75 	template<typename Type>
76 	inline	Attribute*			_AddAttribute(BHPKGAttributeID attributeID,
77 									Type value);
78 
79 			Attribute*			_AddStringAttribute(
80 									BHPKGAttributeID attributeID,
81 									const char* value);
82 			Attribute*			_AddDataAttribute(BHPKGAttributeID attributeID,
83 									uint64 dataSize, uint64 dataOffset);
84 			Attribute*			_AddDataAttribute(BHPKGAttributeID attributeID,
85 									uint64 dataSize, const uint8* data);
86 
87 			status_t			_AddData(BDataReader& dataReader, off_t size);
88 
89 			status_t			_WriteUncompressedData(BDataReader& dataReader,
90 									off_t size, uint64 writeOffset);
91 			status_t			_WriteZlibCompressedData(
92 									BDataReader& dataReader,
93 									off_t size, uint64 writeOffset,
94 									uint64& _compressedSize);
95 
96 private:
97 			BPackageWriterListener*	fListener;
98 
99 			off_t				fHeapOffset;
100 			off_t				fHeapEnd;
101 
102 			void*				fDataBuffer;
103 			const size_t		fDataBufferSize;
104 
105 			Entry*				fRootEntry;
106 
107 			Attribute*			fRootAttribute;
108 			Attribute*			fTopAttribute;
109 
110 			StringCache			fStringCache;
111 
112 			BPackageInfo		fPackageInfo;
113 };
114 
115 
116 }	// namespace BPrivate
117 
118 }	// namespace BHPKG
119 
120 }	// namespace BPackageKit
121 
122 
123 #endif	// _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
124