xref: /haiku/headers/os/storage/Resources.h (revision 24159a0c7d6d6dcba9f2a0c1a7c08d2c8167f21b)
1 /*
2  * Copyright 2001-2006, Haiku Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 /*!
6 	\file Resources.h
7 	BResources interface declaration.
8 */
9 
10 #ifndef _RESOURCES_H
11 #define _RESOURCES_H
12 
13 #include <Entry.h>
14 #include <File.h>
15 #include <image.h>
16 
17 namespace BPrivate {
18 	namespace Storage {
19 		class ResourcesContainer;
20 		class ResourceFile;
21 	};
22 };
23 
24 /*!
25 	\class BResources
26 	\brief Represent the resources in a file
27 
28 	Provides an interface for accessing and manipulating resources.
29 
30 	\author Ingo Weinhold
31 
32 	\version 1.0.0
33 */
34 class BResources {
35 public:
36 	BResources();
37 	BResources(const BFile *file, bool clobber = false);
38 	BResources(const char *path, bool clobber = false);			// Haiku only
39 	BResources(const entry_ref *ref, bool clobber = false);		// Haiku only
40 
41 	virtual ~BResources();
42 
43 	status_t SetTo(const BFile *file, bool clobber = false);
44 	status_t SetTo(const char *path, bool clobber = false);		// Haiku only
45 	status_t SetTo(const entry_ref *ref, bool clobber = false);	// Haiku only
46 
47 	// Haiku only
48 	status_t SetToImage(image_id image, bool clobber = false);
49 	status_t SetToImage(const void *codeOrDataPointer, bool clobber = false);
50 
51 	void Unset();
52 	status_t InitCheck() const;
53 
54 	const BFile &File() const;
55 
56 	const void *LoadResource(type_code type, int32 id, size_t *outSize);
57 	const void *LoadResource(type_code type, const char *name,
58 							 size_t *outSize);
59 
60 	status_t PreloadResourceType(type_code type = 0);
61 
62 	status_t Sync();
63 	status_t MergeFrom(BFile *fromFile);
64 	status_t WriteTo(BFile *file);
65 
66 	status_t AddResource(type_code type, int32 id, const void *data,
67 						 size_t length, const char *name = NULL);
68 
69 	bool HasResource(type_code type, int32 id);
70 	bool HasResource(type_code type, const char *name);
71 
72 	bool GetResourceInfo(int32 byIndex, type_code *typeFound, int32 *idFound,
73 						 const char **nameFound, size_t *lengthFound);
74 	bool GetResourceInfo(type_code byType, int32 andIndex, int32 *idFound,
75 						 const char **nameFound, size_t *lengthFound);
76 	bool GetResourceInfo(type_code byType, int32 andID,
77 						 const char **nameFound, size_t *lengthFound);
78 	bool GetResourceInfo(type_code byType, const char *andName, int32 *idFound,
79 						 size_t *lengthFound);
80 	bool GetResourceInfo(const void *byPointer, type_code *typeFound,
81 						 int32 *idFound, size_t *lengthFound,
82 						 const char **nameFound);
83 
84 	status_t RemoveResource(const void *resource);
85 	status_t RemoveResource(type_code type, int32 id);
86 
87 
88 	// deprecated
89 
90 	status_t WriteResource(type_code type, int32 id, const void *data,
91 						   off_t offset, size_t length);
92 
93 	status_t ReadResource(type_code type, int32 id, void *data, off_t offset,
94 						  size_t length);
95 
96 	void *FindResource(type_code type, int32 id, size_t *lengthFound);
97 	void *FindResource(type_code type, const char *name, size_t *lengthFound);
98 
99 private:
100 	// FBC
101 	virtual void _ReservedResources1();
102 	virtual void _ReservedResources2();
103 	virtual void _ReservedResources3();
104 	virtual void _ReservedResources4();
105 	virtual void _ReservedResources5();
106 	virtual void _ReservedResources6();
107 	virtual void _ReservedResources7();
108 	virtual void _ReservedResources8();
109 
110 private:
111 	BFile							fFile;
112 	BPrivate::Storage::ResourcesContainer	*fContainer;
113 	BPrivate::Storage::ResourceFile		*fResourceFile;
114 	bool							fReadOnly;
115 	bool							_pad[3];
116 	uint32							_reserved[3];	// FBC
117 };
118 
119 #endif	// _RESOURCES_H
120