blob: d2ca82eb55c7817aa3e0dd13509fe19678f15d9b [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);
Kenny Root1dfd9f82010-07-19 10:31:34 -070038 bool removeFrom(const char* filename);
39 bool removeFrom(int fd);
Kenny Rootb94a9a62010-06-01 10:34:29 -070040
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
72private:
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 Root1dfd9f82010-07-19 10:31:34 -070083 size_t mFooterStart;
84
Kenny Rootb94a9a62010-06-01 10:34:29 -070085 unsigned char* mReadBuf;
86
87 bool parseObbFile(int fd);
88};
89
90}
91#endif /* OBBFILE_H_ */