Kenny Root | b94a9a6 | 2010-06-01 10:34:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef OBBFILE_H_ |
| 18 | #define OBBFILE_H_ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include <utils/RefBase.h> |
| 23 | #include <utils/String8.h> |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | class ObbFile : public RefBase { |
| 28 | protected: |
| 29 | virtual ~ObbFile(); |
| 30 | |
| 31 | public: |
| 32 | ObbFile(); |
| 33 | |
| 34 | bool readFrom(const char* filename); |
| 35 | bool readFrom(int fd); |
| 36 | bool writeTo(const char* filename); |
| 37 | bool writeTo(int fd); |
Kenny Root | 1dfd9f8 | 2010-07-19 10:31:34 -0700 | [diff] [blame^] | 38 | bool removeFrom(const char* filename); |
| 39 | bool removeFrom(int fd); |
Kenny Root | b94a9a6 | 2010-06-01 10:34:29 -0700 | [diff] [blame] | 40 | |
| 41 | const char* getFileName() const { |
| 42 | return mFileName; |
| 43 | } |
| 44 | |
| 45 | const String8 getPackageName() const { |
| 46 | return mPackageName; |
| 47 | } |
| 48 | |
| 49 | int32_t getVersion() const { |
| 50 | return mVersion; |
| 51 | } |
| 52 | |
| 53 | void setPackageName(String8 packageName) { |
| 54 | mPackageName = packageName; |
| 55 | } |
| 56 | |
| 57 | void setVersion(int32_t version) { |
| 58 | mVersion = version; |
| 59 | } |
| 60 | |
| 61 | static inline uint32_t get4LE(const unsigned char* buf) { |
| 62 | return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); |
| 63 | } |
| 64 | |
| 65 | static inline void put4LE(unsigned char* buf, uint32_t val) { |
| 66 | buf[0] = val & 0xFF; |
| 67 | buf[1] = (val >> 8) & 0xFF; |
| 68 | buf[2] = (val >> 16) & 0xFF; |
| 69 | buf[3] = (val >> 24) & 0xFF; |
| 70 | } |
| 71 | |
| 72 | private: |
| 73 | /* Package name this ObbFile is associated with */ |
| 74 | String8 mPackageName; |
| 75 | |
| 76 | /* Package version this ObbFile is associated with */ |
| 77 | int32_t mVersion; |
| 78 | |
| 79 | const char* mFileName; |
| 80 | |
| 81 | size_t mFileSize; |
| 82 | |
Kenny Root | 1dfd9f8 | 2010-07-19 10:31:34 -0700 | [diff] [blame^] | 83 | size_t mFooterStart; |
| 84 | |
Kenny Root | b94a9a6 | 2010-06-01 10:34:29 -0700 | [diff] [blame] | 85 | unsigned char* mReadBuf; |
| 86 | |
| 87 | bool parseObbFile(int fd); |
| 88 | }; |
| 89 | |
| 90 | } |
| 91 | #endif /* OBBFILE_H_ */ |