blob: 075927cdfa2e231da8b34b55cfaa3005b95e4d2c [file] [log] [blame]
Kenny Rootb94a9a62010-06-01 10:34:29 -07001/*
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
25namespace android {
26
27class ObbFile : public RefBase {
28protected:
29 virtual ~ObbFile();
30
31public:
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);
38
39 const char* getFileName() const {
40 return mFileName;
41 }
42
43 const String8 getPackageName() const {
44 return mPackageName;
45 }
46
47 int32_t getVersion() const {
48 return mVersion;
49 }
50
51 void setPackageName(String8 packageName) {
52 mPackageName = packageName;
53 }
54
55 void setVersion(int32_t version) {
56 mVersion = version;
57 }
58
59 static inline uint32_t get4LE(const unsigned char* buf) {
60 return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
61 }
62
63 static inline void put4LE(unsigned char* buf, uint32_t val) {
64 buf[0] = val & 0xFF;
65 buf[1] = (val >> 8) & 0xFF;
66 buf[2] = (val >> 16) & 0xFF;
67 buf[3] = (val >> 24) & 0xFF;
68 }
69
70private:
71 /* Package name this ObbFile is associated with */
72 String8 mPackageName;
73
74 /* Package version this ObbFile is associated with */
75 int32_t mVersion;
76
77 const char* mFileName;
78
79 size_t mFileSize;
80
81 unsigned char* mReadBuf;
82
83 bool parseObbFile(int fd);
84};
85
86}
87#endif /* OBBFILE_H_ */