1 /* 2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de> 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <package/hpkg/PackageWriter.h> 8 9 #include <new> 10 11 #include <package/hpkg/PackageWriterImpl.h> 12 13 14 namespace BPackageKit { 15 16 namespace BHPKG { 17 18 19 // #pragma mark - BPackageWriterParameters 20 21 22 BPackageWriterParameters::BPackageWriterParameters() 23 : 24 fFlags(0), 25 fCompressionLevel(B_HPKG_COMPRESSION_LEVEL_BEST) 26 { 27 } 28 29 30 BPackageWriterParameters::~BPackageWriterParameters() 31 { 32 } 33 34 35 uint32 36 BPackageWriterParameters::Flags() const 37 { 38 return fFlags; 39 } 40 41 42 void 43 BPackageWriterParameters::SetFlags(uint32 flags) 44 { 45 fFlags = flags; 46 } 47 48 49 int32 50 BPackageWriterParameters::CompressionLevel() const 51 { 52 return fCompressionLevel; 53 } 54 55 56 void 57 BPackageWriterParameters::SetCompressionLevel(int32 compressionLevel) 58 { 59 fCompressionLevel = compressionLevel; 60 } 61 62 63 // #pragma mark - BPackageWriter 64 65 66 BPackageWriter::BPackageWriter(BPackageWriterListener* listener) 67 : 68 fImpl(new (std::nothrow) PackageWriterImpl(listener)) 69 { 70 } 71 72 73 BPackageWriter::~BPackageWriter() 74 { 75 delete fImpl; 76 } 77 78 79 status_t 80 BPackageWriter::Init(const char* fileName, 81 const BPackageWriterParameters* parameters) 82 { 83 if (fImpl == NULL) 84 return B_NO_MEMORY; 85 86 BPackageWriterParameters defaultParameters; 87 88 return fImpl->Init(fileName, 89 parameters != NULL ? *parameters : defaultParameters); 90 } 91 92 93 status_t 94 BPackageWriter::SetInstallPath(const char* installPath) 95 { 96 if (fImpl == NULL) 97 return B_NO_INIT; 98 99 return fImpl->SetInstallPath(installPath); 100 } 101 102 103 void 104 BPackageWriter::SetCheckLicenses(bool checkLicenses) 105 { 106 if (fImpl != NULL) 107 fImpl->SetCheckLicenses(checkLicenses); 108 } 109 110 111 status_t 112 BPackageWriter::AddEntry(const char* fileName, int fd) 113 { 114 if (fImpl == NULL) 115 return B_NO_INIT; 116 117 return fImpl->AddEntry(fileName, fd); 118 } 119 120 121 status_t 122 BPackageWriter::Finish() 123 { 124 if (fImpl == NULL) 125 return B_NO_INIT; 126 127 return fImpl->Finish(); 128 } 129 130 131 } // namespace BHPKG 132 133 } // namespace BPackageKit 134