2009-11-13 16:45:49 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
2011-02-05 01:40:10 +03:00
|
|
|
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
|
2009-11-13 16:45:49 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2011-01-30 18:05:38 +03:00
|
|
|
#ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
|
|
|
|
#define _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
|
2009-11-13 16:45:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
#include <util/DoublyLinkedList.h>
|
|
|
|
#include <util/OpenHashTable.h>
|
|
|
|
|
2011-01-31 18:43:33 +03:00
|
|
|
#include <package/hpkg/PackageWriter.h>
|
2011-01-28 02:17:03 +03:00
|
|
|
#include <package/hpkg/Strings.h>
|
2011-02-08 01:25:16 +03:00
|
|
|
#include <package/hpkg/WriterImplBase.h>
|
2011-01-28 02:17:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
namespace BPackageKit {
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
namespace BHPKG {
|
|
|
|
|
|
|
|
|
|
|
|
class BDataReader;
|
2011-01-31 18:43:33 +03:00
|
|
|
class BErrorOutput;
|
2009-11-13 16:45:49 +03:00
|
|
|
|
2011-01-28 02:17:03 +03:00
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
namespace BPrivate {
|
|
|
|
|
|
|
|
|
|
|
|
struct hpkg_header;
|
2009-11-13 16:45:49 +03:00
|
|
|
|
2011-02-08 01:25:16 +03:00
|
|
|
class PackageWriterImpl : public WriterImplBase {
|
2009-11-13 16:45:49 +03:00
|
|
|
public:
|
2011-01-31 18:43:33 +03:00
|
|
|
PackageWriterImpl(
|
|
|
|
BPackageWriterListener* listener);
|
2011-01-30 18:05:38 +03:00
|
|
|
~PackageWriterImpl();
|
2009-11-13 16:45:49 +03:00
|
|
|
|
|
|
|
status_t Init(const char* fileName);
|
|
|
|
status_t AddEntry(const char* fileName);
|
|
|
|
status_t Finish();
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct AttributeTypeKey;
|
|
|
|
struct AttributeType;
|
|
|
|
struct AttributeTypeHashDefinition;
|
|
|
|
struct Attribute;
|
|
|
|
struct AttributeTypeUsageGreater;
|
|
|
|
struct Entry;
|
2011-01-31 18:43:33 +03:00
|
|
|
struct SubPathAdder;
|
2009-11-13 16:45:49 +03:00
|
|
|
|
|
|
|
typedef BOpenHashTable<AttributeTypeHashDefinition>
|
|
|
|
AttributeTypeTable;
|
|
|
|
typedef DoublyLinkedList<Entry> EntryList;
|
|
|
|
|
|
|
|
private:
|
|
|
|
status_t _Init(const char* fileName);
|
|
|
|
status_t _Finish();
|
|
|
|
|
|
|
|
status_t _RegisterEntry(const char* fileName);
|
|
|
|
Entry* _RegisterEntry(Entry* parent,
|
|
|
|
const char* name, size_t nameLength,
|
|
|
|
bool isImplicit);
|
|
|
|
|
2011-02-08 22:50:36 +03:00
|
|
|
status_t _CheckLicenses();
|
|
|
|
|
2009-11-16 00:29:53 +03:00
|
|
|
void _WriteTOC(hpkg_header& header);
|
|
|
|
int32 _WriteTOCSections(uint64& _attributeTypesSize,
|
|
|
|
uint64& _stringsSize, uint64& _mainSize);
|
2009-11-13 16:45:49 +03:00
|
|
|
void _WriteAttributeTypes();
|
|
|
|
void _WriteAttributeChildren(Attribute* attribute);
|
|
|
|
|
2009-11-16 00:29:53 +03:00
|
|
|
void _WritePackageAttributes(hpkg_header& header);
|
|
|
|
|
2009-11-13 16:45:49 +03:00
|
|
|
void _AddEntry(int dirFD, Entry* entry,
|
2011-01-31 18:43:33 +03:00
|
|
|
const char* fileName, char* pathBuffer);
|
2009-11-13 16:45:49 +03:00
|
|
|
|
|
|
|
Attribute* _AddAttribute(const char* attributeName,
|
|
|
|
const AttributeValue& value);
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
inline Attribute* _AddAttribute(const char* attributeName,
|
|
|
|
Type value);
|
|
|
|
|
|
|
|
Attribute* _AddStringAttribute(const char* attributeName,
|
|
|
|
const char* value);
|
|
|
|
Attribute* _AddDataAttribute(const char* attributeName,
|
|
|
|
uint64 dataSize, uint64 dataOffset);
|
2009-11-15 11:41:57 +03:00
|
|
|
Attribute* _AddDataAttribute(const char* attributeName,
|
|
|
|
uint64 dataSize, const uint8* data);
|
2009-11-13 16:45:49 +03:00
|
|
|
|
|
|
|
AttributeType* _GetAttributeType(const char* attributeName,
|
|
|
|
uint8 type);
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
status_t _AddData(BDataReader& dataReader, off_t size);
|
2011-02-08 01:25:16 +03:00
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
status_t _WriteUncompressedData(BDataReader& dataReader,
|
2009-11-15 11:41:57 +03:00
|
|
|
off_t size, uint64 writeOffset);
|
2011-02-08 01:25:16 +03:00
|
|
|
status_t _WriteZlibCompressedData(
|
|
|
|
BDataReader& dataReader,
|
2009-11-15 11:41:57 +03:00
|
|
|
off_t size, uint64 writeOffset,
|
2009-11-15 00:08:33 +03:00
|
|
|
uint64& _compressedSize);
|
2009-11-13 16:45:49 +03:00
|
|
|
|
|
|
|
private:
|
2011-01-31 18:43:33 +03:00
|
|
|
BPackageWriterListener* fListener;
|
|
|
|
|
2009-11-13 16:45:49 +03:00
|
|
|
off_t fHeapOffset;
|
|
|
|
off_t fHeapEnd;
|
2009-11-16 00:29:53 +03:00
|
|
|
|
2011-02-08 13:59:38 +03:00
|
|
|
void* fDataBuffer;
|
|
|
|
const size_t fDataBufferSize;
|
|
|
|
|
2009-11-13 16:45:49 +03:00
|
|
|
Entry* fRootEntry;
|
|
|
|
|
|
|
|
Attribute* fRootAttribute;
|
|
|
|
Attribute* fTopAttribute;
|
|
|
|
|
2011-02-08 01:25:16 +03:00
|
|
|
StringCache fStringCache;
|
2009-11-13 16:45:49 +03:00
|
|
|
AttributeTypeTable* fAttributeTypes;
|
2011-02-08 22:50:36 +03:00
|
|
|
|
|
|
|
BPackageInfo fPackageInfo;
|
2009-11-13 16:45:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-01-28 02:17:03 +03:00
|
|
|
} // namespace BPrivate
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
} // namespace BHPKG
|
2011-01-28 02:17:03 +03:00
|
|
|
|
|
|
|
} // namespace BPackageKit
|
|
|
|
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
#endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
|