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 fCompression(B_HPKG_COMPRESSION_ZLIB), 26 fCompressionLevel(B_HPKG_COMPRESSION_LEVEL_BEST) 27 { 28 } 29 30 31 BPackageWriterParameters::~BPackageWriterParameters() 32 { 33 } 34 35 36 uint32 37 BPackageWriterParameters::Flags() const 38 { 39 return fFlags; 40 } 41 42 43 void 44 BPackageWriterParameters::SetFlags(uint32 flags) 45 { 46 fFlags = flags; 47 } 48 49 50 uint32 51 BPackageWriterParameters::Compression() const 52 { 53 return fCompression; 54 } 55 56 57 void 58 BPackageWriterParameters::SetCompression(uint32 compression) 59 { 60 fCompression = compression; 61 } 62 63 64 int32 65 BPackageWriterParameters::CompressionLevel() const 66 { 67 return fCompressionLevel; 68 } 69 70 71 void 72 BPackageWriterParameters::SetCompressionLevel(int32 compressionLevel) 73 { 74 fCompressionLevel = compressionLevel; 75 } 76 77 78 // #pragma mark - BPackageWriter 79 80 81 BPackageWriter::BPackageWriter(BPackageWriterListener* listener) 82 : 83 fImpl(new (std::nothrow) PackageWriterImpl(listener)) 84 { 85 } 86 87 88 BPackageWriter::~BPackageWriter() 89 { 90 delete fImpl; 91 } 92 93 94 status_t 95 BPackageWriter::Init(const char* fileName, 96 const BPackageWriterParameters* parameters) 97 { 98 if (fImpl == NULL) 99 return B_NO_MEMORY; 100 101 BPackageWriterParameters defaultParameters; 102 103 return fImpl->Init(fileName, 104 parameters != NULL ? *parameters : defaultParameters); 105 } 106 107 108 status_t 109 BPackageWriter::Init(BPositionIO* file, bool keepFile, 110 const BPackageWriterParameters* parameters) 111 { 112 if (fImpl == NULL) 113 return B_NO_MEMORY; 114 115 BPackageWriterParameters defaultParameters; 116 117 return fImpl->Init(file, keepFile, 118 parameters != NULL ? *parameters : defaultParameters); 119 } 120 121 122 status_t 123 BPackageWriter::SetInstallPath(const char* installPath) 124 { 125 if (fImpl == NULL) 126 return B_NO_INIT; 127 128 return fImpl->SetInstallPath(installPath); 129 } 130 131 132 void 133 BPackageWriter::SetCheckLicenses(bool checkLicenses) 134 { 135 if (fImpl != NULL) 136 fImpl->SetCheckLicenses(checkLicenses); 137 } 138 139 140 status_t 141 BPackageWriter::AddEntry(const char* fileName, int fd) 142 { 143 if (fImpl == NULL) 144 return B_NO_INIT; 145 146 return fImpl->AddEntry(fileName, fd); 147 } 148 149 150 status_t 151 BPackageWriter::Finish() 152 { 153 if (fImpl == NULL) 154 return B_NO_INIT; 155 156 return fImpl->Finish(); 157 } 158 159 160 status_t 161 BPackageWriter::Recompress(BPositionIO* inputFile) 162 { 163 if (fImpl == NULL) 164 return B_NO_INIT; 165 166 return fImpl->Recompress(inputFile); 167 } 168 169 170 } // namespace BHPKG 171 172 } // namespace BPackageKit 173