xref: /haiku/src/kits/storage/AppFileInfo.cpp (revision bae87c9140b843a16dd71b5ed9cf467f44b57b98)
131dc79a1SAxel Dörfler /*
231dc79a1SAxel Dörfler  * Copyright 2002-2006, Haiku Inc.
331dc79a1SAxel Dörfler  * Distributed under the terms of the MIT License.
431dc79a1SAxel Dörfler  *
531dc79a1SAxel Dörfler  * Authors:
631dc79a1SAxel Dörfler  *		Ingo Weinhold, bonefish@users.sf.net
721881ce5SIngo Weinhold  */
8d6b205f3SIngo Weinhold 
931dc79a1SAxel Dörfler 
1098da112cSIngo Weinhold #include <new>
1198da112cSIngo Weinhold #include <set>
1298da112cSIngo Weinhold #include <string>
1398da112cSIngo Weinhold 
14d6b205f3SIngo Weinhold #include <AppFileInfo.h>
1598da112cSIngo Weinhold #include <Bitmap.h>
1698da112cSIngo Weinhold #include <File.h>
1798da112cSIngo Weinhold #include <fs_attr.h>
189ecf9d1cSIngo Weinhold #include <IconUtils.h>
1998da112cSIngo Weinhold #include <MimeType.h>
2098da112cSIngo Weinhold #include <RegistrarDefs.h>
2198da112cSIngo Weinhold #include <Resources.h>
2298da112cSIngo Weinhold #include <Roster.h>
2398da112cSIngo Weinhold #include <String.h>
2498da112cSIngo Weinhold 
2550f17542Shaydentech using namespace std;
2650f17542Shaydentech 
2798da112cSIngo Weinhold // attributes
2898da112cSIngo Weinhold static const char *kTypeAttribute				= "BEOS:TYPE";
2998da112cSIngo Weinhold static const char *kSignatureAttribute			= "BEOS:APP_SIG";
3098da112cSIngo Weinhold static const char *kAppFlagsAttribute			= "BEOS:APP_FLAGS";
3198da112cSIngo Weinhold static const char *kSupportedTypesAttribute		= "BEOS:FILE_TYPES";
3298da112cSIngo Weinhold static const char *kVersionInfoAttribute		= "BEOS:APP_VERSION";
3398da112cSIngo Weinhold static const char *kMiniIconAttribute			= "BEOS:M:";
3498da112cSIngo Weinhold static const char *kLargeIconAttribute			= "BEOS:L:";
359ecf9d1cSIngo Weinhold static const char *kIconAttribute				= "BEOS:";
3698da112cSIngo Weinhold static const char *kStandardIconType			= "STD_ICON";
379ecf9d1cSIngo Weinhold static const char *kIconType					= "ICON";
3898da112cSIngo Weinhold 
3998da112cSIngo Weinhold // resource IDs
4098da112cSIngo Weinhold static const int32 kTypeResourceID				= 2;
4198da112cSIngo Weinhold static const int32 kSignatureResourceID			= 1;
4298da112cSIngo Weinhold static const int32 kAppFlagsResourceID			= 1;
4398da112cSIngo Weinhold static const int32 kSupportedTypesResourceID	= 1;
4498da112cSIngo Weinhold static const int32 kMiniIconResourceID			= 101;
4598da112cSIngo Weinhold static const int32 kLargeIconResourceID			= 101;
467fb6186fSStephan Aßmus static const int32 kIconResourceID				= 101;
4798da112cSIngo Weinhold static const int32 kVersionInfoResourceID		= 1;
4898da112cSIngo Weinhold static const int32 kMiniIconForTypeResourceID	= 0;
4998da112cSIngo Weinhold static const int32 kLargeIconForTypeResourceID	= 0;
507fb6186fSStephan Aßmus static const int32 kIconForTypeResourceID		= 0;
5198da112cSIngo Weinhold 
5298da112cSIngo Weinhold // type codes
5398da112cSIngo Weinhold enum {
5498da112cSIngo Weinhold 	B_APP_FLAGS_TYPE	= 'APPF',
5598da112cSIngo Weinhold 	B_VERSION_INFO_TYPE	= 'APPV',
5698da112cSIngo Weinhold };
5798da112cSIngo Weinhold 
5888706bbeSAxel Dörfler // R5 also exports these (Tracker is using them):
5988706bbeSAxel Dörfler // (maybe we better want to drop them silently and declare
6088706bbeSAxel Dörfler // the above in a public Haiku header - and use that one in
6188706bbeSAxel Dörfler // Tracker when compiled for Haiku)
6288706bbeSAxel Dörfler extern const uint32 MINI_ICON_TYPE, LARGE_ICON_TYPE;
6388706bbeSAxel Dörfler const uint32 MINI_ICON_TYPE = 'MICN';
6488706bbeSAxel Dörfler const uint32 LARGE_ICON_TYPE = 'ICON';
6588706bbeSAxel Dörfler 
6678b31a7cSIngo Weinhold // debugging
6778b31a7cSIngo Weinhold //#define DBG(x) x
6878b31a7cSIngo Weinhold #define DBG(x)
6978b31a7cSIngo Weinhold #define OUT	printf
70d6b205f3SIngo Weinhold 
71d6b205f3SIngo Weinhold // constructor
72d6b205f3SIngo Weinhold /*!	\brief Creates an uninitialized BAppFileInfo object.
73d6b205f3SIngo Weinhold */
74d6b205f3SIngo Weinhold BAppFileInfo::BAppFileInfo()
75d6b205f3SIngo Weinhold 			: fResources(NULL),
76d6b205f3SIngo Weinhold 			  fWhere(B_USE_BOTH_LOCATIONS)
77d6b205f3SIngo Weinhold {
78d6b205f3SIngo Weinhold }
79d6b205f3SIngo Weinhold 
80d6b205f3SIngo Weinhold // constructor
81d6b205f3SIngo Weinhold /*!	\brief Creates an BAppFileInfo object and initializes it to the supplied
82d6b205f3SIngo Weinhold 		   file.
83d6b205f3SIngo Weinhold 
84d6b205f3SIngo Weinhold 	The caller retains ownership of the supplied BFile object. It must not
85d6b205f3SIngo Weinhold 	be deleted during the life time of the BAppFileInfo. It is not deleted
86d6b205f3SIngo Weinhold 	when the BAppFileInfo is destroyed.
87d6b205f3SIngo Weinhold 
88d6b205f3SIngo Weinhold 	\param file The file the object shall be initialized to.
89d6b205f3SIngo Weinhold */
90d6b205f3SIngo Weinhold BAppFileInfo::BAppFileInfo(BFile *file)
91d6b205f3SIngo Weinhold 			: fResources(NULL),
92d6b205f3SIngo Weinhold 			  fWhere(B_USE_BOTH_LOCATIONS)
93d6b205f3SIngo Weinhold {
9498da112cSIngo Weinhold 	SetTo(file);
95d6b205f3SIngo Weinhold }
96d6b205f3SIngo Weinhold 
97d6b205f3SIngo Weinhold // destructor
98d6b205f3SIngo Weinhold /*!	\brief Frees all resources associated with this object.
99d6b205f3SIngo Weinhold 
100d6b205f3SIngo Weinhold 	The BFile the object is set to is not deleted.
101d6b205f3SIngo Weinhold */
102d6b205f3SIngo Weinhold BAppFileInfo::~BAppFileInfo()
103d6b205f3SIngo Weinhold {
10498da112cSIngo Weinhold 	if (fResources)
10598da112cSIngo Weinhold 		delete fResources;
106d6b205f3SIngo Weinhold }
107d6b205f3SIngo Weinhold 
108d6b205f3SIngo Weinhold // SetTo
109d6b205f3SIngo Weinhold /*!	\brief Initializes the BAppFileInfo to the supplied file.
110d6b205f3SIngo Weinhold 
111d6b205f3SIngo Weinhold 	The caller retains ownership of the supplied BFile object. It must not
112d6b205f3SIngo Weinhold 	be deleted during the life time of the BAppFileInfo. It is not deleted
113d6b205f3SIngo Weinhold 	when the BAppFileInfo is destroyed.
114d6b205f3SIngo Weinhold 
115d6b205f3SIngo Weinhold 	\param file The file the object shall be initialized to.
116d6b205f3SIngo Weinhold 
117d6b205f3SIngo Weinhold 	\return
118d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
119d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a file or \a file is not properly initialized.
120d6b205f3SIngo Weinhold */
121d6b205f3SIngo Weinhold status_t
122d6b205f3SIngo Weinhold BAppFileInfo::SetTo(BFile *file)
123d6b205f3SIngo Weinhold {
12498da112cSIngo Weinhold 	// unset the old file
12598da112cSIngo Weinhold 	BNodeInfo::SetTo(NULL);
12698da112cSIngo Weinhold 	if (fResources) {
12798da112cSIngo Weinhold 		delete fResources;
12898da112cSIngo Weinhold 		fResources = NULL;
12998da112cSIngo Weinhold 	}
130c2a2369dSAxel Dörfler 
13198da112cSIngo Weinhold 	// check param
13298da112cSIngo Weinhold 	status_t error = (file && file->InitCheck() == B_OK ? B_OK : B_BAD_VALUE);
133c2a2369dSAxel Dörfler 
134c2a2369dSAxel Dörfler 	info_location where = B_USE_BOTH_LOCATIONS;
135c2a2369dSAxel Dörfler 
13698da112cSIngo Weinhold 	// create resources
13798da112cSIngo Weinhold 	if (error == B_OK) {
13898da112cSIngo Weinhold 		fResources = new(nothrow) BResources();
139c2a2369dSAxel Dörfler 		if (fResources) {
14098da112cSIngo Weinhold 			error = fResources->SetTo(file);
141c2a2369dSAxel Dörfler 			if (error != B_OK) {
142c2a2369dSAxel Dörfler 				// no resources - this is no critical error, we'll just use
143c2a2369dSAxel Dörfler 				// attributes only, then
144c2a2369dSAxel Dörfler 				where = B_USE_ATTRIBUTES;
145c2a2369dSAxel Dörfler 				error = B_OK;
146c2a2369dSAxel Dörfler 			}
147c2a2369dSAxel Dörfler 		} else
14898da112cSIngo Weinhold 			error = B_NO_MEMORY;
14998da112cSIngo Weinhold 	}
150c2a2369dSAxel Dörfler 
15198da112cSIngo Weinhold 	// set node info
15298da112cSIngo Weinhold 	if (error == B_OK)
15398da112cSIngo Weinhold 		error = BNodeInfo::SetTo(file);
154c2a2369dSAxel Dörfler 
155c2a2369dSAxel Dörfler 	if (error != B_OK || (where & B_USE_RESOURCES) == 0) {
15698da112cSIngo Weinhold 		delete fResources;
15798da112cSIngo Weinhold 		fResources = NULL;
15898da112cSIngo Weinhold 	}
159c2a2369dSAxel Dörfler 
160c2a2369dSAxel Dörfler 	// clean up on error
161c2a2369dSAxel Dörfler 	if (error != B_OK) {
16298da112cSIngo Weinhold 		if (InitCheck() == B_OK)
16398da112cSIngo Weinhold 			BNodeInfo::SetTo(NULL);
16498da112cSIngo Weinhold 	}
165c2a2369dSAxel Dörfler 
16698da112cSIngo Weinhold 	// set data location
16798da112cSIngo Weinhold 	if (error == B_OK)
168c2a2369dSAxel Dörfler 		SetInfoLocation(where);
169c2a2369dSAxel Dörfler 
17098da112cSIngo Weinhold 	// set error
17198da112cSIngo Weinhold 	fCStatus = error;
17298da112cSIngo Weinhold 	return error;
173d6b205f3SIngo Weinhold }
174d6b205f3SIngo Weinhold 
175d6b205f3SIngo Weinhold // GetType
176d6b205f3SIngo Weinhold /*!	\brief Gets the file's MIME type.
177d6b205f3SIngo Weinhold 
178d6b205f3SIngo Weinhold 	\param type A pointer to a pre-allocated character buffer of size
179d6b205f3SIngo Weinhold 		   \c B_MIME_TYPE_LENGTH or larger into which the MIME type of the
180d6b205f3SIngo Weinhold 		   file shall be written.
181d6b205f3SIngo Weinhold 	\return
182d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
183d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
184d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a type or the type string stored in the
185d6b205f3SIngo Weinhold 	  attribute/resources is longer than \c B_MIME_TYPE_LENGTH.
186d6b205f3SIngo Weinhold 	- \c B_BAD_TYPE: The attribute/resources the type string is stored in have
187d6b205f3SIngo Weinhold 	  the wrong type.
188d6b205f3SIngo Weinhold 	- \c B_ENTRY_NOT_FOUND: No type is set on the file.
189d6b205f3SIngo Weinhold 	- other error codes
190d6b205f3SIngo Weinhold */
191d6b205f3SIngo Weinhold status_t
192d6b205f3SIngo Weinhold BAppFileInfo::GetType(char *type) const
193d6b205f3SIngo Weinhold {
19498da112cSIngo Weinhold 	// check param and initialization
19598da112cSIngo Weinhold 	status_t error = (type ? B_OK : B_BAD_VALUE);
19698da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
19798da112cSIngo Weinhold 		error = B_NO_INIT;
19898da112cSIngo Weinhold 	// read the data
19998da112cSIngo Weinhold 	size_t read = 0;
20098da112cSIngo Weinhold 	if (error == B_OK) {
20198da112cSIngo Weinhold 		error = _ReadData(kTypeAttribute, kTypeResourceID, B_MIME_STRING_TYPE,
20298da112cSIngo Weinhold 						  type, B_MIME_TYPE_LENGTH, read);
20398da112cSIngo Weinhold 	}
20498da112cSIngo Weinhold 	// check the read data -- null terminate the string
20598da112cSIngo Weinhold 	if (error == B_OK && type[read - 1] != '\0') {
20698da112cSIngo Weinhold 		if (read == B_MIME_TYPE_LENGTH)
20798da112cSIngo Weinhold 			error = B_ERROR;
20898da112cSIngo Weinhold 		else
20998da112cSIngo Weinhold 			type[read] = '\0';
21098da112cSIngo Weinhold 	}
21198da112cSIngo Weinhold 	return error;
212d6b205f3SIngo Weinhold }
213d6b205f3SIngo Weinhold 
214d6b205f3SIngo Weinhold // SetType
215d6b205f3SIngo Weinhold /*!	\brief Sets the file's MIME type.
216d6b205f3SIngo Weinhold 
217d6b205f3SIngo Weinhold 	If \a type is \c NULL the file's MIME type is unset.
218d6b205f3SIngo Weinhold 
219d6b205f3SIngo Weinhold 	\param type The MIME type to be assigned to the file. Must not be longer
220d6b205f3SIngo Weinhold 		   than \c B_MIME_TYPE_LENGTH (including the terminating null).
221d6b205f3SIngo Weinhold 		   May be \c NULL.
222d6b205f3SIngo Weinhold 	\return
223d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
224d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
225d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \a type is longer than \c B_MIME_TYPE_LENGTH.
226d6b205f3SIngo Weinhold 	- other error codes
227d6b205f3SIngo Weinhold */
228d6b205f3SIngo Weinhold status_t
229d6b205f3SIngo Weinhold BAppFileInfo::SetType(const char *type)
230d6b205f3SIngo Weinhold {
23198da112cSIngo Weinhold 	// check initialization
23298da112cSIngo Weinhold 	status_t error = B_OK;
23398da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
23498da112cSIngo Weinhold 		error = B_NO_INIT;
23598da112cSIngo Weinhold 	if (error == B_OK) {
23698da112cSIngo Weinhold 		if (type) {
23798da112cSIngo Weinhold 			// check param
23898da112cSIngo Weinhold 			size_t typeLen = strlen(type);
23998da112cSIngo Weinhold 			if (error == B_OK && typeLen >= B_MIME_TYPE_LENGTH)
24098da112cSIngo Weinhold 				error = B_BAD_VALUE;
24198da112cSIngo Weinhold 			// write the data
24298da112cSIngo Weinhold 			if (error == B_OK) {
24398da112cSIngo Weinhold 				error = _WriteData(kTypeAttribute, kTypeResourceID,
24498da112cSIngo Weinhold 								   B_MIME_STRING_TYPE, type, typeLen + 1);
24598da112cSIngo Weinhold 			}
24698da112cSIngo Weinhold 		} else
24798da112cSIngo Weinhold 			error = _RemoveData(kTypeAttribute, B_MIME_STRING_TYPE);
24898da112cSIngo Weinhold 	}
24998da112cSIngo Weinhold 	return error;
250d6b205f3SIngo Weinhold }
251d6b205f3SIngo Weinhold 
252d6b205f3SIngo Weinhold // GetSignature
253d6b205f3SIngo Weinhold /*!	\brief Gets the file's application signature.
254d6b205f3SIngo Weinhold 
255d6b205f3SIngo Weinhold 	\param signature A pointer to a pre-allocated character buffer of size
256d6b205f3SIngo Weinhold 		   \c B_MIME_TYPE_LENGTH or larger into which the application
257d6b205f3SIngo Weinhold 		   signature of the file shall be written.
258d6b205f3SIngo Weinhold 	\return
259d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
260d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
261d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a signature or the signature stored in the
262d6b205f3SIngo Weinhold 	  attribute/resources is longer than \c B_MIME_TYPE_LENGTH.
263d6b205f3SIngo Weinhold 	- \c B_BAD_TYPE: The attribute/resources the signature is stored in have
264d6b205f3SIngo Weinhold 	  the wrong type.
265d6b205f3SIngo Weinhold 	- \c B_ENTRY_NOT_FOUND: No signature is set on the file.
266d6b205f3SIngo Weinhold 	- other error codes
267d6b205f3SIngo Weinhold */
268d6b205f3SIngo Weinhold status_t
269d6b205f3SIngo Weinhold BAppFileInfo::GetSignature(char *signature) const
270d6b205f3SIngo Weinhold {
27198da112cSIngo Weinhold 	// check param and initialization
27298da112cSIngo Weinhold 	status_t error = (signature ? B_OK : B_BAD_VALUE);
27398da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
27498da112cSIngo Weinhold 		error = B_NO_INIT;
27598da112cSIngo Weinhold 	// read the data
27698da112cSIngo Weinhold 	size_t read = 0;
27798da112cSIngo Weinhold 	if (error == B_OK) {
27898da112cSIngo Weinhold 		error = _ReadData(kSignatureAttribute, kSignatureResourceID,
27998da112cSIngo Weinhold 						  B_MIME_STRING_TYPE, signature, B_MIME_TYPE_LENGTH,
28098da112cSIngo Weinhold 						  read);
28198da112cSIngo Weinhold 	}
28298da112cSIngo Weinhold 	// check the read data -- null terminate the string
28398da112cSIngo Weinhold 	if (error == B_OK && signature[read - 1] != '\0') {
28498da112cSIngo Weinhold 		if (read == B_MIME_TYPE_LENGTH)
28598da112cSIngo Weinhold 			error = B_ERROR;
28698da112cSIngo Weinhold 		else
28798da112cSIngo Weinhold 			signature[read] = '\0';
28898da112cSIngo Weinhold 	}
28998da112cSIngo Weinhold 	return error;
290d6b205f3SIngo Weinhold }
291d6b205f3SIngo Weinhold 
292d6b205f3SIngo Weinhold // SetSignature
293d6b205f3SIngo Weinhold /*!	\brief Sets the file's application signature.
294d6b205f3SIngo Weinhold 
295d6b205f3SIngo Weinhold 	If \a signature is \c NULL the file's application signature is unset.
296d6b205f3SIngo Weinhold 
297d6b205f3SIngo Weinhold 	\param signature The application signature to be assigned to the file.
298d6b205f3SIngo Weinhold 		   Must not be longer than \c B_MIME_TYPE_LENGTH (including the
299d6b205f3SIngo Weinhold 		   terminating null). May be \c NULL.
300d6b205f3SIngo Weinhold 	\return
301d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
302d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
303d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \a signature is longer than \c B_MIME_TYPE_LENGTH.
304d6b205f3SIngo Weinhold 	- other error codes
305d6b205f3SIngo Weinhold */
306d6b205f3SIngo Weinhold status_t
307d6b205f3SIngo Weinhold BAppFileInfo::SetSignature(const char *signature)
308d6b205f3SIngo Weinhold {
30998da112cSIngo Weinhold 	// check initialization
31098da112cSIngo Weinhold 	status_t error = B_OK;
31198da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
31298da112cSIngo Weinhold 		error = B_NO_INIT;
31398da112cSIngo Weinhold 	if (error == B_OK) {
31498da112cSIngo Weinhold 		if (signature) {
31598da112cSIngo Weinhold 			// check param
31698da112cSIngo Weinhold 			size_t signatureLen = strlen(signature);
31798da112cSIngo Weinhold 			if (error == B_OK && signatureLen >= B_MIME_TYPE_LENGTH)
31898da112cSIngo Weinhold 				error = B_BAD_VALUE;
31998da112cSIngo Weinhold 			// write the data
32098da112cSIngo Weinhold 			if (error == B_OK) {
32198da112cSIngo Weinhold 				error = _WriteData(kSignatureAttribute, kSignatureResourceID,
32298da112cSIngo Weinhold 								   B_MIME_STRING_TYPE, signature,
32398da112cSIngo Weinhold 								   signatureLen + 1);
32498da112cSIngo Weinhold 			}
32598da112cSIngo Weinhold 		} else
32698da112cSIngo Weinhold 			error = _RemoveData(kSignatureAttribute, B_MIME_STRING_TYPE);
32798da112cSIngo Weinhold 	}
32898da112cSIngo Weinhold 	return error;
329d6b205f3SIngo Weinhold }
330d6b205f3SIngo Weinhold 
331d6b205f3SIngo Weinhold // GetAppFlags
332d6b205f3SIngo Weinhold /*!	\brief Gets the file's application flags.
333d6b205f3SIngo Weinhold 
334d6b205f3SIngo Weinhold 	\param flags A pointer to a pre-allocated uint32 into which the application
335d6b205f3SIngo Weinhold 		   flags of the file shall be written.
336d6b205f3SIngo Weinhold 	\return
337d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
338d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
339d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a flags.
340d6b205f3SIngo Weinhold 	- \c B_BAD_TYPE: The attribute/resources the flags are stored in have
341d6b205f3SIngo Weinhold 	  the wrong type.
342d6b205f3SIngo Weinhold 	- \c B_ENTRY_NOT_FOUND: No application flags are set on the file.
343d6b205f3SIngo Weinhold 	- other error codes
344d6b205f3SIngo Weinhold */
345d6b205f3SIngo Weinhold status_t
346d6b205f3SIngo Weinhold BAppFileInfo::GetAppFlags(uint32 *flags) const
347d6b205f3SIngo Weinhold {
34898da112cSIngo Weinhold 	// check param and initialization
34998da112cSIngo Weinhold 	status_t error = (flags ? B_OK : B_BAD_VALUE);
35098da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
35198da112cSIngo Weinhold 		error = B_NO_INIT;
35298da112cSIngo Weinhold 	// read the data
35398da112cSIngo Weinhold 	size_t read = 0;
35498da112cSIngo Weinhold 	if (error == B_OK) {
35598da112cSIngo Weinhold 		error = _ReadData(kAppFlagsAttribute, kAppFlagsResourceID,
35698da112cSIngo Weinhold 						  B_APP_FLAGS_TYPE, flags, sizeof(uint32),
35798da112cSIngo Weinhold 						  read);
35898da112cSIngo Weinhold 	}
35998da112cSIngo Weinhold 	// check the read data
36098da112cSIngo Weinhold 	if (error == B_OK && read != sizeof(uint32))
36198da112cSIngo Weinhold 		error = B_ERROR;
36298da112cSIngo Weinhold 	return error;
363d6b205f3SIngo Weinhold }
364d6b205f3SIngo Weinhold 
365d6b205f3SIngo Weinhold // SetAppFlags
366d6b205f3SIngo Weinhold /*!	\brief Sets the file's application flags.
367d6b205f3SIngo Weinhold 	\param flags The application flags to be assigned to the file.
368d6b205f3SIngo Weinhold 	\return
369d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
370d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
371d6b205f3SIngo Weinhold 	- other error codes
372d6b205f3SIngo Weinhold */
373d6b205f3SIngo Weinhold status_t
374d6b205f3SIngo Weinhold BAppFileInfo::SetAppFlags(uint32 flags)
375d6b205f3SIngo Weinhold {
37698da112cSIngo Weinhold 	// check initialization
37798da112cSIngo Weinhold 	status_t error = B_OK;
37898da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
37998da112cSIngo Weinhold 		error = B_NO_INIT;
38098da112cSIngo Weinhold 	if (error == B_OK) {
38198da112cSIngo Weinhold 		// write the data
38298da112cSIngo Weinhold 		if (error == B_OK) {
38398da112cSIngo Weinhold 			error = _WriteData(kAppFlagsAttribute, kAppFlagsResourceID,
38498da112cSIngo Weinhold 							   B_APP_FLAGS_TYPE, &flags, sizeof(uint32));
38598da112cSIngo Weinhold 		}
38698da112cSIngo Weinhold 	}
38798da112cSIngo Weinhold 	return error;
388d6b205f3SIngo Weinhold }
389d6b205f3SIngo Weinhold 
390d6b205f3SIngo Weinhold // GetSupportedTypes
391d6b205f3SIngo Weinhold /*!	\brief Gets the MIME types supported by the application.
392d6b205f3SIngo Weinhold 
393d6b205f3SIngo Weinhold 	The supported MIME types are added to a field "types" of type
394d6b205f3SIngo Weinhold 	\c B_STRING_TYPE in \a types.
395d6b205f3SIngo Weinhold 
396d6b205f3SIngo Weinhold 	\param types A pointer to a pre-allocated BMessage into which the
397d6b205f3SIngo Weinhold 		   MIME types supported by the appplication shall be written.
398d6b205f3SIngo Weinhold 	\return
399d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
400d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
401d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a types.
402d6b205f3SIngo Weinhold 	- \c B_BAD_TYPE: The attribute/resources the supported types are stored in
403d6b205f3SIngo Weinhold 	  have the wrong type.
404d6b205f3SIngo Weinhold 	- \c B_ENTRY_NOT_FOUND: No supported types are set on the file.
405d6b205f3SIngo Weinhold 	- other error codes
406d6b205f3SIngo Weinhold */
407d6b205f3SIngo Weinhold status_t
408d6b205f3SIngo Weinhold BAppFileInfo::GetSupportedTypes(BMessage *types) const
409d6b205f3SIngo Weinhold {
41098da112cSIngo Weinhold 	// check param and initialization
41198da112cSIngo Weinhold 	status_t error = (types ? B_OK : B_BAD_VALUE);
41298da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
41398da112cSIngo Weinhold 		error = B_NO_INIT;
41498da112cSIngo Weinhold 	// read the data
41598da112cSIngo Weinhold 	size_t read = 0;
41698da112cSIngo Weinhold 	void *buffer = NULL;
41798da112cSIngo Weinhold 	if (error == B_OK) {
41898da112cSIngo Weinhold 		error = _ReadData(kSupportedTypesAttribute, kSupportedTypesResourceID,
41998da112cSIngo Weinhold 						  B_MESSAGE_TYPE, NULL, 0, read, &buffer);
42098da112cSIngo Weinhold 	}
42198da112cSIngo Weinhold 	// unflatten the buffer
42298da112cSIngo Weinhold 	if (error == B_OK)
42398da112cSIngo Weinhold 		error = types->Unflatten((const char*)buffer);
42498da112cSIngo Weinhold 	// clean up
42598da112cSIngo Weinhold 	if (buffer)
42698da112cSIngo Weinhold 		free(buffer);
42798da112cSIngo Weinhold 	return error;
428d6b205f3SIngo Weinhold }
429d6b205f3SIngo Weinhold 
430d6b205f3SIngo Weinhold // SetSupportedTypes
431d6b205f3SIngo Weinhold /*!	\brief Sets the MIME types supported by the application.
432d6b205f3SIngo Weinhold 
433d6b205f3SIngo Weinhold 	If \a types is \c NULL the application's supported types are unset.
434d6b205f3SIngo Weinhold 
435d6b205f3SIngo Weinhold 	The supported MIME types must be stored in a field "types" of type
436d6b205f3SIngo Weinhold 	\c B_STRING_TYPE in \a types.
437d6b205f3SIngo Weinhold 
43883a812a1SIngo Weinhold 	The method informs the registrar about this news.
43983a812a1SIngo Weinhold 	For each supported type the result of BMimeType::GetSupportingApps() will
44083a812a1SIngo Weinhold 	afterwards include the signature of this application. That is, the
44183a812a1SIngo Weinhold 	application file needs to have a signature set.
44283a812a1SIngo Weinhold 
44383a812a1SIngo Weinhold 	\a syncAll specifies whether the not longer supported types shall be
44483a812a1SIngo Weinhold 	updated as well, i.e. whether this application shall be remove from the
44583a812a1SIngo Weinhold 	lists of supporting applications.
44683a812a1SIngo Weinhold 
447d6b205f3SIngo Weinhold 	\param types The supported types to be assigned to the file.
448d6b205f3SIngo Weinhold 		   May be \c NULL.
44983a812a1SIngo Weinhold 	\param syncAll \c true to also synchronize the not longer supported
45083a812a1SIngo Weinhold 		   types, \c false otherwise.
451d6b205f3SIngo Weinhold 	\return
452d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
453d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
454d6b205f3SIngo Weinhold 	- other error codes
455d6b205f3SIngo Weinhold */
456d6b205f3SIngo Weinhold status_t
457d6b205f3SIngo Weinhold BAppFileInfo::SetSupportedTypes(const BMessage *types, bool syncAll)
458d6b205f3SIngo Weinhold {
45998da112cSIngo Weinhold 	// check initialization
46098da112cSIngo Weinhold 	status_t error = B_OK;
46198da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
46298da112cSIngo Weinhold 		error = B_NO_INIT;
46398da112cSIngo Weinhold 	BMimeType mimeType;
46498da112cSIngo Weinhold 	if (error == B_OK)
46598da112cSIngo Weinhold 		error = GetMetaMime(&mimeType);
4667f20062dSJérôme Duval 	if (error == B_OK || error == B_ENTRY_NOT_FOUND) {
4677f20062dSJérôme Duval 		error = B_OK;
46898da112cSIngo Weinhold 		if (types) {
46917819be3SIngo Weinhold 			// check param -- supported types must be valid
47017819be3SIngo Weinhold 			const char *type;
47117819be3SIngo Weinhold 			for (int32 i = 0;
47217819be3SIngo Weinhold 				 error == B_OK && types->FindString("types", i, &type) == B_OK;
47317819be3SIngo Weinhold 				 i++) {
47417819be3SIngo Weinhold 				if (!BMimeType::IsValid(type))
47517819be3SIngo Weinhold 					error = B_BAD_VALUE;
47617819be3SIngo Weinhold 			}
47717819be3SIngo Weinhold 			// get flattened size
47817819be3SIngo Weinhold 			ssize_t size = 0;
47917819be3SIngo Weinhold 			if (error == B_OK) {
48017819be3SIngo Weinhold 				size = types->FlattenedSize();
48198da112cSIngo Weinhold 				if (size < 0)
48298da112cSIngo Weinhold 					error = size;
48317819be3SIngo Weinhold 			}
48498da112cSIngo Weinhold 			// allocate a buffer for the flattened data
48598da112cSIngo Weinhold 			char *buffer = NULL;
48698da112cSIngo Weinhold 			if (error == B_OK) {
48798da112cSIngo Weinhold 				buffer = new(nothrow) char[size];
48898da112cSIngo Weinhold 				if (!buffer)
48998da112cSIngo Weinhold 					error = B_NO_MEMORY;
49098da112cSIngo Weinhold 			}
49198da112cSIngo Weinhold 			// flatten the message
49298da112cSIngo Weinhold 			if (error == B_OK)
49398da112cSIngo Weinhold 				error = types->Flatten(buffer, size);
49498da112cSIngo Weinhold 			// write the data
49598da112cSIngo Weinhold 			if (error == B_OK) {
49698da112cSIngo Weinhold 				error = _WriteData(kSupportedTypesAttribute,
49798da112cSIngo Weinhold 								   kSupportedTypesResourceID, B_MESSAGE_TYPE,
49898da112cSIngo Weinhold 								   buffer, size);
49998da112cSIngo Weinhold 			}
50098da112cSIngo Weinhold 			// clean up
50198da112cSIngo Weinhold 			if (buffer)
50298da112cSIngo Weinhold 				delete[] buffer;
50398da112cSIngo Weinhold 		} else
50498da112cSIngo Weinhold 			error = _RemoveData(kSupportedTypesAttribute, B_MESSAGE_TYPE);
50598da112cSIngo Weinhold 		// update the MIME database, if the app signature is installed
50617819be3SIngo Weinhold 		if (error == B_OK && mimeType.IsInstalled())
50717819be3SIngo Weinhold 			error = mimeType.SetSupportedTypes(types, syncAll);
50898da112cSIngo Weinhold 	}
50998da112cSIngo Weinhold 	return error;
510d6b205f3SIngo Weinhold }
511d6b205f3SIngo Weinhold 
512d6b205f3SIngo Weinhold // SetSupportedTypes
513d6b205f3SIngo Weinhold /*!	\brief Sets the MIME types supported by the application.
514d6b205f3SIngo Weinhold 
51598da112cSIngo Weinhold 	This method is a short-hand for SetSupportedTypes(types, false).
51683a812a1SIngo Weinhold 	\see SetSupportedType(const BMessage*, bool) for detailed information.
517d6b205f3SIngo Weinhold 
518d6b205f3SIngo Weinhold 	\param types The supported types to be assigned to the file.
519d6b205f3SIngo Weinhold 		   May be \c NULL.
520d6b205f3SIngo Weinhold 	\return
521d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
522d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
523d6b205f3SIngo Weinhold 	- other error codes
524d6b205f3SIngo Weinhold */
525d6b205f3SIngo Weinhold status_t
526d6b205f3SIngo Weinhold BAppFileInfo::SetSupportedTypes(const BMessage *types)
527d6b205f3SIngo Weinhold {
52898da112cSIngo Weinhold 	return SetSupportedTypes(types, false);
529d6b205f3SIngo Weinhold }
530d6b205f3SIngo Weinhold 
531d6b205f3SIngo Weinhold // IsSupportedType
532d6b205f3SIngo Weinhold /*!	\brief Returns whether the application supports the supplied MIME type.
533d6b205f3SIngo Weinhold 
534d6b205f3SIngo Weinhold 	If the application supports the wildcard type "application/octet-stream"
535d6b205f3SIngo Weinhold 	any this method returns \c true for any MIME type.
536d6b205f3SIngo Weinhold 
537d6b205f3SIngo Weinhold 	\param type The MIME type in question.
538d6b205f3SIngo Weinhold 	\return \c true, if \a type is a valid MIME type and it is supported by
539d6b205f3SIngo Weinhold 			the application, \c false otherwise.
540d6b205f3SIngo Weinhold */
541d6b205f3SIngo Weinhold bool
542d6b205f3SIngo Weinhold BAppFileInfo::IsSupportedType(const char *type) const
543d6b205f3SIngo Weinhold {
54498da112cSIngo Weinhold 	status_t error = (type ? B_OK : B_BAD_VALUE);
54598da112cSIngo Weinhold 	// get the supported types
54698da112cSIngo Weinhold 	BMessage types;
54798da112cSIngo Weinhold 	if (error == B_OK)
54898da112cSIngo Weinhold 		error = GetSupportedTypes(&types);
54998da112cSIngo Weinhold 	// turn type into a BMimeType
55098da112cSIngo Weinhold 	BMimeType mimeType;
55198da112cSIngo Weinhold 	if (error == B_OK)
55298da112cSIngo Weinhold 		error = mimeType.SetTo(type);
55398da112cSIngo Weinhold 	// iterate through the supported types
55498da112cSIngo Weinhold 	bool found = false;
55598da112cSIngo Weinhold 	if (error == B_OK) {
55698da112cSIngo Weinhold 		const char *supportedType;
55798da112cSIngo Weinhold 		for (int32 i = 0;
55898da112cSIngo Weinhold 			 !found && types.FindString("types", i, &supportedType) == B_OK;
55998da112cSIngo Weinhold 			 i++) {
56098da112cSIngo Weinhold 			found = !strcmp(supportedType, "application/octet-stream")
56198da112cSIngo Weinhold 					|| BMimeType(supportedType).Contains(&mimeType);
56298da112cSIngo Weinhold 		}
56398da112cSIngo Weinhold 	}
56498da112cSIngo Weinhold 	return found;
565d6b205f3SIngo Weinhold }
566d6b205f3SIngo Weinhold 
567d6b205f3SIngo Weinhold // Supports
568d6b205f3SIngo Weinhold /*!	\brief Returns whether the application supports the supplied MIME type
569d6b205f3SIngo Weinhold 		   explicitly.
570d6b205f3SIngo Weinhold 
571d6b205f3SIngo Weinhold 	Unlike IsSupportedType(), this method returns \c true, only if the type
572d6b205f3SIngo Weinhold 	is explicitly supported, regardless of whether it supports
573d6b205f3SIngo Weinhold 	"application/octet-stream".
574d6b205f3SIngo Weinhold 
575d6b205f3SIngo Weinhold 	\param type The MIME type in question.
576d6b205f3SIngo Weinhold 	\return \c true, if \a type is a valid MIME type and it is explicitly
577d6b205f3SIngo Weinhold 			supported by the application, \c false otherwise.
578d6b205f3SIngo Weinhold */
579d6b205f3SIngo Weinhold bool
580d6b205f3SIngo Weinhold BAppFileInfo::Supports(BMimeType *type) const
581d6b205f3SIngo Weinhold {
58298da112cSIngo Weinhold 	status_t error = (type && type->InitCheck() == B_OK ? B_OK : B_BAD_VALUE);
58398da112cSIngo Weinhold 	// get the supported types
58498da112cSIngo Weinhold 	BMessage types;
58598da112cSIngo Weinhold 	if (error == B_OK)
58698da112cSIngo Weinhold 		error = GetSupportedTypes(&types);
58798da112cSIngo Weinhold 	// iterate through the supported types
58898da112cSIngo Weinhold 	bool found = false;
58998da112cSIngo Weinhold 	if (error == B_OK) {
59098da112cSIngo Weinhold 		const char *supportedType;
59198da112cSIngo Weinhold 		for (int32 i = 0;
59298da112cSIngo Weinhold 			 !found && types.FindString("types", i, &supportedType) == B_OK;
59398da112cSIngo Weinhold 			 i++) {
59498da112cSIngo Weinhold 			found = BMimeType(supportedType).Contains(type);
59598da112cSIngo Weinhold 		}
59698da112cSIngo Weinhold 	}
59798da112cSIngo Weinhold 	return found;
598d6b205f3SIngo Weinhold }
599d6b205f3SIngo Weinhold 
600d6b205f3SIngo Weinhold // GetIcon
601d6b205f3SIngo Weinhold /*!	\brief Gets the file's icon.
602d6b205f3SIngo Weinhold 	\param icon A pointer to a pre-allocated BBitmap of the correct dimension
603d6b205f3SIngo Weinhold 		   to store the requested icon (16x16 for the mini and 32x32 for the
604d6b205f3SIngo Weinhold 		   large icon).
605d6b205f3SIngo Weinhold 	\param which Specifies the size of the icon to be retrieved:
606d6b205f3SIngo Weinhold 		   \c B_MINI_ICON for the mini and \c B_LARGE_ICON for the large icon.
607d6b205f3SIngo Weinhold 	\return
608d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
609d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
610d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a icon, unsupported icon size \a which or bitmap
611d6b205f3SIngo Weinhold 		 dimensions (\a icon) and icon size (\a which) do not match.
612d6b205f3SIngo Weinhold 	- other error codes
613d6b205f3SIngo Weinhold */
614d6b205f3SIngo Weinhold status_t
615d6b205f3SIngo Weinhold BAppFileInfo::GetIcon(BBitmap *icon, icon_size which) const
616d6b205f3SIngo Weinhold {
61798da112cSIngo Weinhold 	return GetIconForType(NULL, icon, which);
618d6b205f3SIngo Weinhold }
619d6b205f3SIngo Weinhold 
6207fb6186fSStephan Aßmus // GetIcon
6217fb6186fSStephan Aßmus /*!	\brief Gets the file's icon.
6227fb6186fSStephan Aßmus 	\param data The pointer in which the flat icon data will be returned.
6237fb6186fSStephan Aßmus 	\param size The pointer in which the size of the data found will be returned.
6247fb6186fSStephan Aßmus 	\return
6257fb6186fSStephan Aßmus 	- \c B_OK: Everything went fine.
6267fb6186fSStephan Aßmus 	- \c B_NO_INIT: The object is not properly initialized.
6277fb6186fSStephan Aßmus 	- \c B_BAD_VALUE: \c NULL \a data or \c NULL size.
6287fb6186fSStephan Aßmus 	- other error codes
6297fb6186fSStephan Aßmus */
6307fb6186fSStephan Aßmus status_t
6317fb6186fSStephan Aßmus BAppFileInfo::GetIcon(uint8** data, size_t* size) const
6327fb6186fSStephan Aßmus {
6337fb6186fSStephan Aßmus 	return GetIconForType(NULL, data, size);
6347fb6186fSStephan Aßmus }
6357fb6186fSStephan Aßmus 
636d6b205f3SIngo Weinhold // SetIcon
637d6b205f3SIngo Weinhold /*!	\brief Sets the file's icon.
638d6b205f3SIngo Weinhold 
639d6b205f3SIngo Weinhold 	If \a icon is \c NULL the file's icon is unset.
640d6b205f3SIngo Weinhold 
641d6b205f3SIngo Weinhold 	\param icon A pointer to the BBitmap containing the icon to be set.
642d6b205f3SIngo Weinhold 		   May be \c NULL.
643d6b205f3SIngo Weinhold 	\param which Specifies the size of the icon to be set: \c B_MINI_ICON
644d6b205f3SIngo Weinhold 		   for the mini and \c B_LARGE_ICON for the large icon.
645d6b205f3SIngo Weinhold 	\return
646d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
647d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
648d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: Unknown icon size \a which or bitmap dimensions (\a icon)
649d6b205f3SIngo Weinhold 		 and icon size (\a which) do not match.
650d6b205f3SIngo Weinhold 	- other error codes
651d6b205f3SIngo Weinhold */
652d6b205f3SIngo Weinhold status_t
653d6b205f3SIngo Weinhold BAppFileInfo::SetIcon(const BBitmap *icon, icon_size which)
654d6b205f3SIngo Weinhold {
65598da112cSIngo Weinhold 	return SetIconForType(NULL, icon, which);
656d6b205f3SIngo Weinhold }
657d6b205f3SIngo Weinhold 
6587fb6186fSStephan Aßmus // SetIcon
6597fb6186fSStephan Aßmus /*!	\brief Sets the file's icon.
6607fb6186fSStephan Aßmus 
6617fb6186fSStephan Aßmus 	If \a icon is \c NULL the file's icon is unset.
6627fb6186fSStephan Aßmus 
6637fb6186fSStephan Aßmus 	\param data A pointer to the data buffer containing the vector icon
6647fb6186fSStephan Aßmus 		   to be set. May be \c NULL.
6657fb6186fSStephan Aßmus 	\param size Specifies the size of buffer pointed to by \a data.
6667fb6186fSStephan Aßmus 	\return
6677fb6186fSStephan Aßmus 	- \c B_OK: Everything went fine.
6687fb6186fSStephan Aßmus 	- \c B_NO_INIT: The object is not properly initialized.
6697fb6186fSStephan Aßmus 	- \c B_BAD_VALUE: \c NULL data.
6707fb6186fSStephan Aßmus 	- other error codes
6717fb6186fSStephan Aßmus */
6727fb6186fSStephan Aßmus status_t
6737fb6186fSStephan Aßmus BAppFileInfo::SetIcon(const uint8* data, size_t size)
6747fb6186fSStephan Aßmus {
6757fb6186fSStephan Aßmus 	return SetIconForType(NULL, data, size);
6767fb6186fSStephan Aßmus }
6777fb6186fSStephan Aßmus 
678d6b205f3SIngo Weinhold // GetVersionInfo
679d6b205f3SIngo Weinhold /*!	\brief Gets the file's version info.
680d6b205f3SIngo Weinhold 	\param info A pointer to a pre-allocated version_info structure into which
681d6b205f3SIngo Weinhold 		   the version info should be written.
682d6b205f3SIngo Weinhold 	\param kind Specifies the kind of the version info to be retrieved:
683d6b205f3SIngo Weinhold 		   \c B_APP_VERSION_KIND for the application's version info and
684d6b205f3SIngo Weinhold 		   \c B_SYSTEM_VERSION_KIND for the suite's info the application
685d6b205f3SIngo Weinhold 		   belongs to.
686d6b205f3SIngo Weinhold 	\return
687d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
688d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
689d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a info.
690d6b205f3SIngo Weinhold 	- other error codes
691d6b205f3SIngo Weinhold */
692d6b205f3SIngo Weinhold status_t
693d6b205f3SIngo Weinhold BAppFileInfo::GetVersionInfo(version_info *info, version_kind kind) const
694d6b205f3SIngo Weinhold {
69598da112cSIngo Weinhold 	// check params and initialization
696b1970bb8SIngo Weinhold 	if (!info)
697b1970bb8SIngo Weinhold 		return B_BAD_VALUE;
698b1970bb8SIngo Weinhold 
69998da112cSIngo Weinhold 	int32 index = 0;
70098da112cSIngo Weinhold 	switch (kind) {
70198da112cSIngo Weinhold 		case B_APP_VERSION_KIND:
70298da112cSIngo Weinhold 			index = 0;
70398da112cSIngo Weinhold 			break;
70498da112cSIngo Weinhold 		case B_SYSTEM_VERSION_KIND:
70598da112cSIngo Weinhold 			index = 1;
70698da112cSIngo Weinhold 			break;
70798da112cSIngo Weinhold 		default:
708b1970bb8SIngo Weinhold 			return B_BAD_VALUE;
70998da112cSIngo Weinhold 	}
710b1970bb8SIngo Weinhold 
711b1970bb8SIngo Weinhold 	if (InitCheck() != B_OK)
712b1970bb8SIngo Weinhold 		return B_NO_INIT;
713b1970bb8SIngo Weinhold 
71498da112cSIngo Weinhold 	// read the data
71598da112cSIngo Weinhold 	size_t read = 0;
71698da112cSIngo Weinhold 	version_info infos[2];
717b1970bb8SIngo Weinhold 	status_t error = _ReadData(kVersionInfoAttribute, kVersionInfoResourceID,
718b1970bb8SIngo Weinhold 		B_VERSION_INFO_TYPE, infos, 2 * sizeof(version_info), read);
719b1970bb8SIngo Weinhold 	if (error != B_OK)
72098da112cSIngo Weinhold 		return error;
721b1970bb8SIngo Weinhold 
722b1970bb8SIngo Weinhold 	// check the read data
723b1970bb8SIngo Weinhold 	if (read == sizeof(version_info)) {
724b1970bb8SIngo Weinhold 		// only the app version info is there -- return a cleared system info
725b1970bb8SIngo Weinhold 		if (index == 0)
726b1970bb8SIngo Weinhold 			*info = infos[index];
727b1970bb8SIngo Weinhold 		else if (index == 1)
728b1970bb8SIngo Weinhold 			memset(info, 0, sizeof(version_info));
729b1970bb8SIngo Weinhold 	} else if (read == 2 * sizeof(version_info)) {
730b1970bb8SIngo Weinhold 		*info = infos[index];
731b1970bb8SIngo Weinhold 	} else
732b1970bb8SIngo Weinhold 		return B_ERROR;
733b1970bb8SIngo Weinhold 
734b1970bb8SIngo Weinhold 	// return result
735b1970bb8SIngo Weinhold 	return B_OK;
736d6b205f3SIngo Weinhold }
737d6b205f3SIngo Weinhold 
738d6b205f3SIngo Weinhold // SetVersionInfo
739d6b205f3SIngo Weinhold /*!	\brief Sets the file's version info.
740d6b205f3SIngo Weinhold 
741d6b205f3SIngo Weinhold 	If \a info is \c NULL the file's version info is unset.
742d6b205f3SIngo Weinhold 
743d6b205f3SIngo Weinhold 	\param info The version info to be set. May be \c NULL.
744d6b205f3SIngo Weinhold 	\param kind Specifies kind of version info to be set:
745d6b205f3SIngo Weinhold 		   \c B_APP_VERSION_KIND for the application's version info and
746d6b205f3SIngo Weinhold 		   \c B_SYSTEM_VERSION_KIND for the suite's info the application
747d6b205f3SIngo Weinhold 		   belongs to.
748d6b205f3SIngo Weinhold 	\return
749d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
750d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
751d6b205f3SIngo Weinhold 	- other error codes
752d6b205f3SIngo Weinhold */
753d6b205f3SIngo Weinhold status_t
754d6b205f3SIngo Weinhold BAppFileInfo::SetVersionInfo(const version_info *info, version_kind kind)
755d6b205f3SIngo Weinhold {
75698da112cSIngo Weinhold 	// check initialization
75798da112cSIngo Weinhold 	status_t error = B_OK;
75898da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
75998da112cSIngo Weinhold 		error = B_NO_INIT;
76098da112cSIngo Weinhold 	if (error == B_OK) {
76198da112cSIngo Weinhold 		if (info) {
76298da112cSIngo Weinhold 			// check param
76398da112cSIngo Weinhold 			int32 index = 0;
76498da112cSIngo Weinhold 			if (error == B_OK) {
76598da112cSIngo Weinhold 				switch (kind) {
76698da112cSIngo Weinhold 					case B_APP_VERSION_KIND:
76798da112cSIngo Weinhold 						index = 0;
76898da112cSIngo Weinhold 						break;
76998da112cSIngo Weinhold 					case B_SYSTEM_VERSION_KIND:
77098da112cSIngo Weinhold 						index = 1;
77198da112cSIngo Weinhold 						break;
77298da112cSIngo Weinhold 					default:
77398da112cSIngo Weinhold 						error = B_BAD_VALUE;
77498da112cSIngo Weinhold 						break;
77598da112cSIngo Weinhold 				}
77698da112cSIngo Weinhold 			}
77798da112cSIngo Weinhold 			// read both infos
77898da112cSIngo Weinhold 			version_info infos[2];
77998da112cSIngo Weinhold 			if (error == B_OK) {
78098da112cSIngo Weinhold 				size_t read;
781b1970bb8SIngo Weinhold 				if (_ReadData(kVersionInfoAttribute, kVersionInfoResourceID,
782b1970bb8SIngo Weinhold 						B_VERSION_INFO_TYPE, infos, 2 * sizeof(version_info),
783b1970bb8SIngo Weinhold 						read) == B_OK) {
784b1970bb8SIngo Weinhold 					// clear the part that hasn't been read
785b1970bb8SIngo Weinhold 					if (read < sizeof(infos))
786b1970bb8SIngo Weinhold 						memset((char*)infos + read, 0, sizeof(infos) - read);
787b1970bb8SIngo Weinhold 				} else {
788b1970bb8SIngo Weinhold 					// failed to read -- clear
789b1970bb8SIngo Weinhold 					memset(infos, 0, sizeof(infos));
790b1970bb8SIngo Weinhold 				}
79198da112cSIngo Weinhold 			}
79298da112cSIngo Weinhold 			infos[index] = *info;
79398da112cSIngo Weinhold 			// write the data
79498da112cSIngo Weinhold 			if (error == B_OK) {
79598da112cSIngo Weinhold 				error = _WriteData(kVersionInfoAttribute,
79698da112cSIngo Weinhold 								   kVersionInfoResourceID,
79798da112cSIngo Weinhold 								   B_VERSION_INFO_TYPE, infos,
79898da112cSIngo Weinhold 								   2 * sizeof(version_info));
79998da112cSIngo Weinhold 			}
80098da112cSIngo Weinhold 		} else
80198da112cSIngo Weinhold 			error = _RemoveData(kVersionInfoAttribute, B_VERSION_INFO_TYPE);
80298da112cSIngo Weinhold 	}
80398da112cSIngo Weinhold 	return error;
804d6b205f3SIngo Weinhold }
805d6b205f3SIngo Weinhold 
806d6b205f3SIngo Weinhold // GetIconForType
807d6b205f3SIngo Weinhold /*!	\brief Gets the icon the application provides for a given MIME type.
80898da112cSIngo Weinhold 
80998da112cSIngo Weinhold 	If \a type is \c NULL, the application's icon is retrieved.
81098da112cSIngo Weinhold 
81198da112cSIngo Weinhold 	\param type The MIME type in question. May be \c NULL.
812d6b205f3SIngo Weinhold 	\param icon A pointer to a pre-allocated BBitmap of the correct dimension
813d6b205f3SIngo Weinhold 		   to store the requested icon (16x16 for the mini and 32x32 for the
814d6b205f3SIngo Weinhold 		   large icon).
815d6b205f3SIngo Weinhold 	\param which Specifies the size of the icon to be retrieved:
816d6b205f3SIngo Weinhold 		   \c B_MINI_ICON for the mini and \c B_LARGE_ICON for the large icon.
817d6b205f3SIngo Weinhold 	\return
818d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
819d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
82098da112cSIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a icon, unsupported icon size
821d6b205f3SIngo Weinhold 		 \a which or bitmap dimensions (\a icon) and icon size (\a which) do
822d6b205f3SIngo Weinhold 		 not match.
823d6b205f3SIngo Weinhold 	- other error codes
824d6b205f3SIngo Weinhold */
825d6b205f3SIngo Weinhold status_t
826d6b205f3SIngo Weinhold BAppFileInfo::GetIconForType(const char *type, BBitmap *icon,
827d6b205f3SIngo Weinhold 							 icon_size which) const
828d6b205f3SIngo Weinhold {
8299ecf9d1cSIngo Weinhold 	if (InitCheck() != B_OK)
8309ecf9d1cSIngo Weinhold 		return B_NO_INIT;
8319ecf9d1cSIngo Weinhold 
8329ecf9d1cSIngo Weinhold 	if (!icon || icon->InitCheck() != B_OK)
8339ecf9d1cSIngo Weinhold 		return B_BAD_VALUE;
8349ecf9d1cSIngo Weinhold 
8359ecf9d1cSIngo Weinhold 	// try vector icon first
8369ecf9d1cSIngo Weinhold 	BString vectorAttributeName(kIconAttribute);
8379ecf9d1cSIngo Weinhold 
8389ecf9d1cSIngo Weinhold 	// check type param
8399ecf9d1cSIngo Weinhold 	if (type) {
8409ecf9d1cSIngo Weinhold 		if (BMimeType::IsValid(type))
8419ecf9d1cSIngo Weinhold 			vectorAttributeName += type;
8429ecf9d1cSIngo Weinhold 		else
8439ecf9d1cSIngo Weinhold 			return B_BAD_VALUE;
8449ecf9d1cSIngo Weinhold 	} else {
8459ecf9d1cSIngo Weinhold 		vectorAttributeName += kIconType;
8469ecf9d1cSIngo Weinhold 	}
8479ecf9d1cSIngo Weinhold 	const char* attribute = vectorAttributeName.String();
8489ecf9d1cSIngo Weinhold 
8499ecf9d1cSIngo Weinhold 	size_t bytesRead;
8509ecf9d1cSIngo Weinhold 	void* allocatedBuffer;
851*bae87c91SAxel Dörfler 	status_t error = _ReadData(attribute, -1, B_VECTOR_ICON_TYPE, NULL, 0,
8529ecf9d1cSIngo Weinhold 							   bytesRead, &allocatedBuffer);
8539ecf9d1cSIngo Weinhold 	if (error == B_OK) {
8547fb6186fSStephan Aßmus 		error = BIconUtils::GetVectorIcon((uint8*)allocatedBuffer,
8559ecf9d1cSIngo Weinhold 										  bytesRead, icon);
8567fb6186fSStephan Aßmus 		free(allocatedBuffer);
8577fb6186fSStephan Aßmus 		return error;
8589ecf9d1cSIngo Weinhold 	}
8599ecf9d1cSIngo Weinhold 
8609ecf9d1cSIngo Weinhold 	// no vector icon if we got this far
8619ecf9d1cSIngo Weinhold 
8629ecf9d1cSIngo Weinhold 	error = B_OK;
86398da112cSIngo Weinhold 	// set some icon size related variables
86498da112cSIngo Weinhold 	BString attributeString;
86598da112cSIngo Weinhold 	BRect bounds;
866a04efc92SIngo Weinhold 	uint32 attrType = 0;
867a04efc92SIngo Weinhold 	size_t attrSize = 0;
86898da112cSIngo Weinhold 	switch (which) {
86998da112cSIngo Weinhold 		case B_MINI_ICON:
87098da112cSIngo Weinhold 			attributeString = kMiniIconAttribute;
87198da112cSIngo Weinhold 			bounds.Set(0, 0, 15, 15);
87298da112cSIngo Weinhold 			attrType = B_MINI_ICON_TYPE;
87398da112cSIngo Weinhold 			attrSize = 16 * 16;
87498da112cSIngo Weinhold 			break;
87598da112cSIngo Weinhold 		case B_LARGE_ICON:
87698da112cSIngo Weinhold 			attributeString = kLargeIconAttribute;
87798da112cSIngo Weinhold 			bounds.Set(0, 0, 31, 31);
87898da112cSIngo Weinhold 			attrType = B_LARGE_ICON_TYPE;
87998da112cSIngo Weinhold 			attrSize = 32 * 32;
88098da112cSIngo Weinhold 			break;
88198da112cSIngo Weinhold 		default:
8829ecf9d1cSIngo Weinhold 			return B_BAD_VALUE;
88398da112cSIngo Weinhold 	}
88498da112cSIngo Weinhold 	// check type param
88598da112cSIngo Weinhold 	if (type) {
88617819be3SIngo Weinhold 		if (BMimeType::IsValid(type))
88717819be3SIngo Weinhold 			attributeString += type;
88817819be3SIngo Weinhold 		else
8899ecf9d1cSIngo Weinhold 			return B_BAD_VALUE;
89098da112cSIngo Weinhold 	} else
89117819be3SIngo Weinhold 		attributeString += kStandardIconType;
8929ecf9d1cSIngo Weinhold 
8939ecf9d1cSIngo Weinhold 	attribute = attributeString.String();
89417819be3SIngo Weinhold 
89598da112cSIngo Weinhold 	// check parameter and initialization
8969ecf9d1cSIngo Weinhold 	if (icon->Bounds() != bounds)
8979ecf9d1cSIngo Weinhold 		return B_BAD_VALUE;
8989ecf9d1cSIngo Weinhold 
89998da112cSIngo Weinhold 	// read the data
90098da112cSIngo Weinhold 	if (error == B_OK) {
90198da112cSIngo Weinhold 		bool otherColorSpace = (icon->ColorSpace() != B_CMAP8);
90298da112cSIngo Weinhold 		char *buffer = NULL;
90398da112cSIngo Weinhold 		size_t read;
90498da112cSIngo Weinhold 		if (otherColorSpace) {
90598da112cSIngo Weinhold 			// other color space than stored in attribute
90698da112cSIngo Weinhold 			buffer = new(nothrow) char[attrSize];
90798da112cSIngo Weinhold 			if (!buffer)
90898da112cSIngo Weinhold 				error = B_NO_MEMORY;
90998da112cSIngo Weinhold 			if (error == B_OK) {
91098da112cSIngo Weinhold 				error = _ReadData(attribute, -1, attrType, buffer, attrSize,
91198da112cSIngo Weinhold 								  read);
91298da112cSIngo Weinhold 			}
91398da112cSIngo Weinhold 		} else {
91498da112cSIngo Weinhold 			error = _ReadData(attribute, -1, attrType, icon->Bits(), attrSize,
91598da112cSIngo Weinhold 							  read);
91698da112cSIngo Weinhold 		}
91798da112cSIngo Weinhold 		if (error == B_OK && read != attrSize)
91898da112cSIngo Weinhold 			error = B_ERROR;
91998da112cSIngo Weinhold 		if (otherColorSpace) {
92098da112cSIngo Weinhold 			// other color space than stored in attribute
92176ba3434SIngo Weinhold 			if (error == B_OK) {
92276ba3434SIngo Weinhold 				error = icon->ImportBits(buffer, attrSize, B_ANY_BYTES_PER_ROW,
92376ba3434SIngo Weinhold 										 0, B_CMAP8);
92476ba3434SIngo Weinhold 			}
92598da112cSIngo Weinhold 			delete[] buffer;
92698da112cSIngo Weinhold 		}
92798da112cSIngo Weinhold 	}
92898da112cSIngo Weinhold 	return error;
929d6b205f3SIngo Weinhold }
930d6b205f3SIngo Weinhold 
9317fb6186fSStephan Aßmus // GetIconForType
9327fb6186fSStephan Aßmus /*!	\brief Gets the icon the application provides for a given MIME type.
9337fb6186fSStephan Aßmus 
9347fb6186fSStephan Aßmus 	If \a type is \c NULL, the application's icon is retrieved.
9357fb6186fSStephan Aßmus 
9367fb6186fSStephan Aßmus 	\param type The MIME type in question. May be \c NULL.
9377fb6186fSStephan Aßmus 	\param data A pointer in which the icon data will be returned. When you
9387fb6186fSStephan Aßmus 	are done with the data, you should use free() to deallocate it.
9397fb6186fSStephan Aßmus 	\param size A pointer in which the size of the retrieved data is returned.
9407fb6186fSStephan Aßmus 	\return
9417fb6186fSStephan Aßmus 	- \c B_OK: Everything went fine.
9427fb6186fSStephan Aßmus 	- \c B_NO_INIT: The object is not properly initialized.
9437fb6186fSStephan Aßmus 	- \c B_BAD_VALUE: \c NULL \a data and/or \a size. Or the supplied
9447fb6186fSStephan Aßmus 	\a type is not a valid MIME type.
9457fb6186fSStephan Aßmus 	- other error codes
9467fb6186fSStephan Aßmus */
9477fb6186fSStephan Aßmus status_t
9487fb6186fSStephan Aßmus BAppFileInfo::GetIconForType(const char *type, uint8** data,
9497fb6186fSStephan Aßmus 							 size_t* size) const
9507fb6186fSStephan Aßmus {
9517fb6186fSStephan Aßmus 	if (InitCheck() != B_OK)
9527fb6186fSStephan Aßmus 		return B_NO_INIT;
9537fb6186fSStephan Aßmus 
9547fb6186fSStephan Aßmus 	if (!data || !size)
9557fb6186fSStephan Aßmus 		return B_BAD_VALUE;
9567fb6186fSStephan Aßmus 
9577fb6186fSStephan Aßmus 	// get vector icon
9587fb6186fSStephan Aßmus 	BString attributeName(kIconAttribute);
9597fb6186fSStephan Aßmus 
9607fb6186fSStephan Aßmus 	// check type param
9617fb6186fSStephan Aßmus 	if (type) {
9627fb6186fSStephan Aßmus 		if (BMimeType::IsValid(type))
9637fb6186fSStephan Aßmus 			attributeName += type;
9647fb6186fSStephan Aßmus 		else
9657fb6186fSStephan Aßmus 			return B_BAD_VALUE;
9667fb6186fSStephan Aßmus 	} else {
9677fb6186fSStephan Aßmus 		attributeName += kIconType;
9687fb6186fSStephan Aßmus 	}
9697fb6186fSStephan Aßmus 
9707fb6186fSStephan Aßmus 	void* allocatedBuffer = NULL;
9717fb6186fSStephan Aßmus 	status_t ret = _ReadData(attributeName.String(), -1,
972*bae87c91SAxel Dörfler 							 B_VECTOR_ICON_TYPE, NULL, 0, *size, &allocatedBuffer);
9737fb6186fSStephan Aßmus 
9747fb6186fSStephan Aßmus 	if (ret < B_OK)
9757fb6186fSStephan Aßmus 		return ret;
9767fb6186fSStephan Aßmus 
9777fb6186fSStephan Aßmus 	*data = (uint8*)allocatedBuffer;
9787fb6186fSStephan Aßmus 	return B_OK;
9797fb6186fSStephan Aßmus }
9807fb6186fSStephan Aßmus 
981d6b205f3SIngo Weinhold // SetIconForType
982d6b205f3SIngo Weinhold /*!	\brief Sets the icon the application provides for a given MIME type.
983d6b205f3SIngo Weinhold 
98498da112cSIngo Weinhold 	If \a type is \c NULL, the application's icon is set.
985d6b205f3SIngo Weinhold 	If \a icon is \c NULL the icon is unset.
986d6b205f3SIngo Weinhold 
98798da112cSIngo Weinhold 	If the file has a signature, then the icon is also set on the MIME type.
98898da112cSIngo Weinhold 	If the type for the signature has not been installed yet, it is installed
98998da112cSIngo Weinhold 	before.
99098da112cSIngo Weinhold 
99198da112cSIngo Weinhold 	\param type The MIME type in question. May be \c NULL.
992d6b205f3SIngo Weinhold 	\param icon A pointer to the BBitmap containing the icon to be set.
993d6b205f3SIngo Weinhold 		   May be \c NULL.
994d6b205f3SIngo Weinhold 	\param which Specifies the size of the icon to be set: \c B_MINI_ICON
995d6b205f3SIngo Weinhold 		   for the mini and \c B_LARGE_ICON for the large icon.
996d6b205f3SIngo Weinhold 	\return
997d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
998d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
9997fb6186fSStephan Aßmus 	- \c B_BAD_VALUE: Either the icon size \a which is unkown, bitmap dimensions (\a icon)
10007fb6186fSStephan Aßmus 		 and icon size (\a which) do not match, or the provided \a type is
10017fb6186fSStephan Aßmus 		 not a valid MIME type.
1002d6b205f3SIngo Weinhold 	- other error codes
1003d6b205f3SIngo Weinhold */
1004d6b205f3SIngo Weinhold status_t
1005d6b205f3SIngo Weinhold BAppFileInfo::SetIconForType(const char *type, const BBitmap *icon,
1006d6b205f3SIngo Weinhold 							 icon_size which)
1007d6b205f3SIngo Weinhold {
100898da112cSIngo Weinhold 	status_t error = B_OK;
100998da112cSIngo Weinhold 	// set some icon size related variables
101098da112cSIngo Weinhold 	BString attributeString;
101198da112cSIngo Weinhold 	BRect bounds;
1012a04efc92SIngo Weinhold 	uint32 attrType = 0;
1013a04efc92SIngo Weinhold 	size_t attrSize = 0;
1014a04efc92SIngo Weinhold 	int32 resourceID = 0;
101598da112cSIngo Weinhold 	switch (which) {
101698da112cSIngo Weinhold 		case B_MINI_ICON:
101798da112cSIngo Weinhold 			attributeString = kMiniIconAttribute;
101898da112cSIngo Weinhold 			bounds.Set(0, 0, 15, 15);
101998da112cSIngo Weinhold 			attrType = B_MINI_ICON_TYPE;
102098da112cSIngo Weinhold 			attrSize = 16 * 16;
102198da112cSIngo Weinhold 			resourceID = (type ? kMiniIconForTypeResourceID
102298da112cSIngo Weinhold 							   : kMiniIconResourceID);
102398da112cSIngo Weinhold 			break;
102498da112cSIngo Weinhold 		case B_LARGE_ICON:
102598da112cSIngo Weinhold 			attributeString = kLargeIconAttribute;
102698da112cSIngo Weinhold 			bounds.Set(0, 0, 31, 31);
102798da112cSIngo Weinhold 			attrType = B_LARGE_ICON_TYPE;
102898da112cSIngo Weinhold 			attrSize = 32 * 32;
102998da112cSIngo Weinhold 			resourceID = (type ? kLargeIconForTypeResourceID
103098da112cSIngo Weinhold 							   : kLargeIconResourceID);
103198da112cSIngo Weinhold 			break;
103298da112cSIngo Weinhold 		default:
103398da112cSIngo Weinhold 			error = B_BAD_VALUE;
103498da112cSIngo Weinhold 			break;
103598da112cSIngo Weinhold 	}
103698da112cSIngo Weinhold 	// check type param
103798da112cSIngo Weinhold 	if (error == B_OK) {
103898da112cSIngo Weinhold 		if (type) {
103917819be3SIngo Weinhold 			if (BMimeType::IsValid(type))
104098da112cSIngo Weinhold 				attributeString += type;
104117819be3SIngo Weinhold 			else
104217819be3SIngo Weinhold 				error = B_BAD_VALUE;
104398da112cSIngo Weinhold 		} else
104498da112cSIngo Weinhold 			attributeString += kStandardIconType;
104598da112cSIngo Weinhold 	}
104698da112cSIngo Weinhold 	const char *attribute = attributeString.String();
104798da112cSIngo Weinhold 	// check parameter and initialization
104898da112cSIngo Weinhold 	if (error == B_OK && icon
104998da112cSIngo Weinhold 		&& (icon->InitCheck() != B_OK || icon->Bounds() != bounds)) {
105098da112cSIngo Weinhold 		error = B_BAD_VALUE;
105198da112cSIngo Weinhold 	}
105298da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
105398da112cSIngo Weinhold 		error = B_NO_INIT;
105498da112cSIngo Weinhold 	// write/remove the attribute
105598da112cSIngo Weinhold 	if (error == B_OK) {
105698da112cSIngo Weinhold 		if (icon) {
105798da112cSIngo Weinhold 			bool otherColorSpace = (icon->ColorSpace() != B_CMAP8);
105898da112cSIngo Weinhold 			if (otherColorSpace) {
1059290bc091SIngo Weinhold 				BBitmap bitmap(bounds, B_BITMAP_NO_SERVER_LINK, B_CMAP8);
106098da112cSIngo Weinhold 				error = bitmap.InitCheck();
106176ba3434SIngo Weinhold 				if (error == B_OK)
106276ba3434SIngo Weinhold 					error = bitmap.ImportBits(icon);
106398da112cSIngo Weinhold 				if (error == B_OK) {
106498da112cSIngo Weinhold 					error = _WriteData(attribute, resourceID, attrType,
106598da112cSIngo Weinhold 									   bitmap.Bits(), attrSize, true);
106698da112cSIngo Weinhold 				}
106798da112cSIngo Weinhold 			} else {
106898da112cSIngo Weinhold 				error = _WriteData(attribute, resourceID, attrType,
106998da112cSIngo Weinhold 								   icon->Bits(), attrSize, true);
107098da112cSIngo Weinhold 			}
107198da112cSIngo Weinhold 		} else	// no icon given => remove
107298da112cSIngo Weinhold 			error = _RemoveData(attribute, attrType);
107398da112cSIngo Weinhold 	}
107498da112cSIngo Weinhold 	// set the attribute on the MIME type, if the file has a signature
107598da112cSIngo Weinhold 	BMimeType mimeType;
107698da112cSIngo Weinhold 	if (error == B_OK && GetMetaMime(&mimeType) == B_OK) {
107798da112cSIngo Weinhold 		if (!mimeType.IsInstalled())
107898da112cSIngo Weinhold 			error = mimeType.Install();
107998da112cSIngo Weinhold 		if (error == B_OK)
108098da112cSIngo Weinhold 			error = mimeType.SetIconForType(type, icon, which);
108198da112cSIngo Weinhold 	}
108298da112cSIngo Weinhold 	return error;
1083d6b205f3SIngo Weinhold }
1084d6b205f3SIngo Weinhold 
10857fb6186fSStephan Aßmus // SetIconForType
10867fb6186fSStephan Aßmus /*!	\brief Sets the icon the application provides for a given MIME type.
10877fb6186fSStephan Aßmus 
10887fb6186fSStephan Aßmus 	If \a type is \c NULL, the application's icon is set.
10897fb6186fSStephan Aßmus 	If \a data is \c NULL the icon is unset.
10907fb6186fSStephan Aßmus 
10917fb6186fSStephan Aßmus 	If the file has a signature, then the icon is also set on the MIME type.
10927fb6186fSStephan Aßmus 	If the type for the signature has not been installed yet, it is installed
10937fb6186fSStephan Aßmus 	before.
10947fb6186fSStephan Aßmus 
10957fb6186fSStephan Aßmus 	\param type The MIME type in question. May be \c NULL.
10967fb6186fSStephan Aßmus 	\param data A pointer to the data containing the icon to be set.
10977fb6186fSStephan Aßmus 		   May be \c NULL.
10987fb6186fSStephan Aßmus 	\param size Specifies the size of buffer provided in \a data.
10997fb6186fSStephan Aßmus 	\return
11007fb6186fSStephan Aßmus 	- \c B_OK: Everything went fine.
11017fb6186fSStephan Aßmus 	- \c B_NO_INIT: The object is not properly initialized.
11027fb6186fSStephan Aßmus 	- \c B_BAD_VALUE: The provided \a type is not a valid MIME type.
11037fb6186fSStephan Aßmus 	- other error codes
11047fb6186fSStephan Aßmus */
11057fb6186fSStephan Aßmus status_t
11067fb6186fSStephan Aßmus BAppFileInfo::SetIconForType(const char* type, const uint8* data,
11077fb6186fSStephan Aßmus 							 size_t size)
11087fb6186fSStephan Aßmus {
11097fb6186fSStephan Aßmus 	if (InitCheck() != B_OK)
11107fb6186fSStephan Aßmus 		return B_NO_INIT;
11117fb6186fSStephan Aßmus 
11127fb6186fSStephan Aßmus 	// set some icon related variables
11137fb6186fSStephan Aßmus 	BString attributeString = kIconAttribute;
11147fb6186fSStephan Aßmus 	int32 resourceID = type ? kIconForTypeResourceID : kIconResourceID;
1115*bae87c91SAxel Dörfler 	uint32 attrType = B_VECTOR_ICON_TYPE;
11167fb6186fSStephan Aßmus 
11177fb6186fSStephan Aßmus 	// check type param
11187fb6186fSStephan Aßmus 	if (type) {
11197fb6186fSStephan Aßmus 		if (BMimeType::IsValid(type))
11207fb6186fSStephan Aßmus 			attributeString += type;
11217fb6186fSStephan Aßmus 		else
11227fb6186fSStephan Aßmus 			return B_BAD_VALUE;
11237fb6186fSStephan Aßmus 	} else
11247fb6186fSStephan Aßmus 		attributeString += kIconType;
11257fb6186fSStephan Aßmus 
11267fb6186fSStephan Aßmus 	const char *attribute = attributeString.String();
11277fb6186fSStephan Aßmus 
11287fb6186fSStephan Aßmus 	status_t error;
11297fb6186fSStephan Aßmus 	// write/remove the attribute
11307fb6186fSStephan Aßmus 	if (data)
11317fb6186fSStephan Aßmus 		error = _WriteData(attribute, resourceID, attrType, data, size, true);
11327fb6186fSStephan Aßmus 	else	// no icon given => remove
11337fb6186fSStephan Aßmus 		error = _RemoveData(attribute, attrType);
11347fb6186fSStephan Aßmus 
11357fb6186fSStephan Aßmus 	// set the attribute on the MIME type, if the file has a signature
11367fb6186fSStephan Aßmus 	BMimeType mimeType;
11377fb6186fSStephan Aßmus 	if (error == B_OK && GetMetaMime(&mimeType) == B_OK) {
11387fb6186fSStephan Aßmus 		if (!mimeType.IsInstalled())
11397fb6186fSStephan Aßmus 			error = mimeType.Install();
11407fb6186fSStephan Aßmus 		if (error == B_OK)
11417fb6186fSStephan Aßmus 			error = mimeType.SetIconForType(type, data, size);
11427fb6186fSStephan Aßmus 	}
11437fb6186fSStephan Aßmus 	return error;
11447fb6186fSStephan Aßmus }
11457fb6186fSStephan Aßmus 
1146d6b205f3SIngo Weinhold // SetInfoLocation
1147d6b205f3SIngo Weinhold /*!	\brief Specifies the location where the meta data shall be stored.
1148d6b205f3SIngo Weinhold 
1149d6b205f3SIngo Weinhold 	The options for \a location are:
1150d6b205f3SIngo Weinhold 	- \c B_USE_ATTRIBUTES: Store the data in the attributes.
1151d6b205f3SIngo Weinhold 	- \c B_USE_RESOURCES: Store the data in the resources.
1152d6b205f3SIngo Weinhold 	- \c B_USE_BOTH_LOCATIONS: Store the data in attributes and resources.
1153d6b205f3SIngo Weinhold 
1154d6b205f3SIngo Weinhold 	\param location The location where the meta data shall be stored.
1155d6b205f3SIngo Weinhold */
1156d6b205f3SIngo Weinhold void
1157d6b205f3SIngo Weinhold BAppFileInfo::SetInfoLocation(info_location location)
1158d6b205f3SIngo Weinhold {
115998da112cSIngo Weinhold 	fWhere = location;
1160d6b205f3SIngo Weinhold }
1161d6b205f3SIngo Weinhold 
1162d6b205f3SIngo Weinhold // IsUsingAttributes
1163d6b205f3SIngo Weinhold /*!	\brief Returns whether the object stores the meta data (also) in the
1164d6b205f3SIngo Weinhold 		   file's attributes.
1165d6b205f3SIngo Weinhold 	\return \c true, if the meta data are (also) stored in the file's
1166d6b205f3SIngo Weinhold 			attributes, \c false otherwise.
1167d6b205f3SIngo Weinhold */
1168d6b205f3SIngo Weinhold bool
1169d6b205f3SIngo Weinhold BAppFileInfo::IsUsingAttributes() const
1170d6b205f3SIngo Weinhold {
117198da112cSIngo Weinhold 	return (fWhere & B_USE_ATTRIBUTES);
1172d6b205f3SIngo Weinhold }
1173d6b205f3SIngo Weinhold 
1174d6b205f3SIngo Weinhold // IsUsingResources
1175d6b205f3SIngo Weinhold /*!	\brief Returns whether the object stores the meta data (also) in the
1176d6b205f3SIngo Weinhold 		   file's resources.
1177d6b205f3SIngo Weinhold 	\return \c true, if the meta data are (also) stored in the file's
1178d6b205f3SIngo Weinhold 			resources, \c false otherwise.
1179d6b205f3SIngo Weinhold */
1180d6b205f3SIngo Weinhold bool
1181d6b205f3SIngo Weinhold BAppFileInfo::IsUsingResources() const
1182d6b205f3SIngo Weinhold {
118398da112cSIngo Weinhold 	return (fWhere & B_USE_RESOURCES);
1184d6b205f3SIngo Weinhold }
1185d6b205f3SIngo Weinhold 
1186d6b205f3SIngo Weinhold // FBC
1187d6b205f3SIngo Weinhold void BAppFileInfo::_ReservedAppFileInfo1() {}
1188d6b205f3SIngo Weinhold void BAppFileInfo::_ReservedAppFileInfo2() {}
1189d6b205f3SIngo Weinhold void BAppFileInfo::_ReservedAppFileInfo3() {}
1190d6b205f3SIngo Weinhold 
1191d6b205f3SIngo Weinhold // =
1192d6b205f3SIngo Weinhold /*!	\brief Privatized assignment operator to prevent usage.
1193d6b205f3SIngo Weinhold */
1194d6b205f3SIngo Weinhold BAppFileInfo &
1195d6b205f3SIngo Weinhold BAppFileInfo::operator=(const BAppFileInfo &)
1196d6b205f3SIngo Weinhold {
1197d6b205f3SIngo Weinhold 	return *this;
1198d6b205f3SIngo Weinhold }
1199d6b205f3SIngo Weinhold 
1200d6b205f3SIngo Weinhold // copy constructor
1201d6b205f3SIngo Weinhold /*!	\brief Privatized copy constructor to prevent usage.
1202d6b205f3SIngo Weinhold */
1203d6b205f3SIngo Weinhold BAppFileInfo::BAppFileInfo(const BAppFileInfo &)
1204d6b205f3SIngo Weinhold {
1205d6b205f3SIngo Weinhold }
1206d6b205f3SIngo Weinhold 
120798da112cSIngo Weinhold // GetMetaMime
120898da112cSIngo Weinhold /*!	\brief Initializes a BMimeType to the file's signature.
120998da112cSIngo Weinhold 
121098da112cSIngo Weinhold 	The parameter \a meta is not checked.
121198da112cSIngo Weinhold 
121298da112cSIngo Weinhold 	\param meta A pointer to a pre-allocated BMimeType that shall be
121398da112cSIngo Weinhold 		   initialized to the file's signature.
121498da112cSIngo Weinhold 	\return
121598da112cSIngo Weinhold 	- \c B_OK: Everything went fine.
121698da112cSIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a meta
121798da112cSIngo Weinhold 	- \c B_ENTRY_NOT_FOUND: The file has not signature or the signature is
121898da112cSIngo Weinhold (	  not installed in the MIME database.)
121998da112cSIngo Weinhold 	  no valid MIME string.
122098da112cSIngo Weinhold 	- other error codes
122198da112cSIngo Weinhold */
122298da112cSIngo Weinhold status_t
122398da112cSIngo Weinhold BAppFileInfo::GetMetaMime(BMimeType *meta) const
122498da112cSIngo Weinhold {
122598da112cSIngo Weinhold 	char signature[B_MIME_TYPE_LENGTH];
122698da112cSIngo Weinhold 	status_t error = GetSignature(signature);
122798da112cSIngo Weinhold 	if (error == B_OK)
122898da112cSIngo Weinhold 		error = meta->SetTo(signature);
12297f20062dSJérôme Duval 	else if (error == B_BAD_VALUE)
12307f20062dSJérôme Duval 		error = B_ENTRY_NOT_FOUND;
123198da112cSIngo Weinhold 	if (error == B_OK && !meta->IsValid())
123298da112cSIngo Weinhold 		error = B_BAD_VALUE;
123398da112cSIngo Weinhold 	return error;
123498da112cSIngo Weinhold }
123598da112cSIngo Weinhold 
123698da112cSIngo Weinhold // _ReadData
123798da112cSIngo Weinhold /*!	\brief Reads data from an attribute or resource.
123898da112cSIngo Weinhold 
123998da112cSIngo Weinhold 	The data are read from the location specified by \a fWhere.
124098da112cSIngo Weinhold 
124198da112cSIngo Weinhold 	The object must be properly initialized. The parameters are NOT checked.
124298da112cSIngo Weinhold 
124398da112cSIngo Weinhold 	\param name The name of the attribute/resource to be read.
124498da112cSIngo Weinhold 	\param id The resource ID of the resource to be read. Is ignored, when
124598da112cSIngo Weinhold 		   < 0.
124698da112cSIngo Weinhold 	\param type The type of the attribute/resource to be read.
124798da112cSIngo Weinhold 	\param buffer A pre-allocated buffer for the data to be read.
124898da112cSIngo Weinhold 	\param bufferSize The size of the supplied buffer.
124998da112cSIngo Weinhold 	\param bytesRead A reference parameter, set to the number of bytes
125098da112cSIngo Weinhold 		   actually read.
125198da112cSIngo Weinhold 	\param allocatedBuffer If not \c NULL, the method allocates a buffer
125298da112cSIngo Weinhold 		   large enough too store the whole data and writes a pointer to it
125398da112cSIngo Weinhold 		   into this variable. If \c NULL, the supplied buffer is used.
125498da112cSIngo Weinhold 	\return
125598da112cSIngo Weinhold 	- \c B_OK: Everything went fine.
125698da112cSIngo Weinhold 	- error code
125798da112cSIngo Weinhold */
125898da112cSIngo Weinhold status_t
125998da112cSIngo Weinhold BAppFileInfo::_ReadData(const char *name, int32 id, type_code type,
126098da112cSIngo Weinhold 						void *buffer, size_t bufferSize,
126198da112cSIngo Weinhold 						size_t &bytesRead, void **allocatedBuffer) const
126298da112cSIngo Weinhold {
126398da112cSIngo Weinhold 	status_t error = B_OK;
1264338b8dc3SIngo Weinhold 
126598da112cSIngo Weinhold 	if (allocatedBuffer)
126698da112cSIngo Weinhold 		buffer = NULL;
1267338b8dc3SIngo Weinhold 
1268338b8dc3SIngo Weinhold 	bool foundData = false;
1269338b8dc3SIngo Weinhold 
127098da112cSIngo Weinhold 	if (IsUsingAttributes()) {
127198da112cSIngo Weinhold 		// get an attribute info
127298da112cSIngo Weinhold 		attr_info info;
127398da112cSIngo Weinhold 		if (error == B_OK)
127498da112cSIngo Weinhold 			error = fNode->GetAttrInfo(name, &info);
1275338b8dc3SIngo Weinhold 
127698da112cSIngo Weinhold 		// check type and size, allocate a buffer, if required
127798da112cSIngo Weinhold 		if (error == B_OK && info.type != type)
127898da112cSIngo Weinhold 			error = B_BAD_VALUE;
1279b4598d95SIngo Weinhold 		if (error == B_OK && allocatedBuffer) {
128098da112cSIngo Weinhold 			buffer = malloc(info.size);
128198da112cSIngo Weinhold 			if (!buffer)
128298da112cSIngo Weinhold 				error = B_NO_MEMORY;
128398da112cSIngo Weinhold 			bufferSize = info.size;
128498da112cSIngo Weinhold 		}
128598da112cSIngo Weinhold 		if (error == B_OK && bufferSize < info.size)
128698da112cSIngo Weinhold 			error = B_BAD_VALUE;
1287338b8dc3SIngo Weinhold 
128898da112cSIngo Weinhold 		// read the data
128998da112cSIngo Weinhold 		if (error == B_OK) {
129098da112cSIngo Weinhold 			ssize_t read = fNode->ReadAttr(name, type, 0, buffer, info.size);
129198da112cSIngo Weinhold 			if (read < 0)
129298da112cSIngo Weinhold 				error = read;
129398da112cSIngo Weinhold 			else if (read != info.size)
129498da112cSIngo Weinhold 				error = B_ERROR;
129598da112cSIngo Weinhold 			else
129698da112cSIngo Weinhold 				bytesRead = read;
129798da112cSIngo Weinhold 		}
1298338b8dc3SIngo Weinhold 
1299338b8dc3SIngo Weinhold 		foundData = (error == B_OK);
1300b4598d95SIngo Weinhold 
1301b4598d95SIngo Weinhold 		// free the allocated buffer on error
1302b4598d95SIngo Weinhold 		if (!foundData && allocatedBuffer && buffer) {
1303b4598d95SIngo Weinhold 			free(buffer);
1304b4598d95SIngo Weinhold 			buffer = NULL;
1305b4598d95SIngo Weinhold 		}
1306338b8dc3SIngo Weinhold 	}
1307338b8dc3SIngo Weinhold 
1308338b8dc3SIngo Weinhold 	if (!foundData && IsUsingResources()) {
130998da112cSIngo Weinhold 		// get a resource info
1310338b8dc3SIngo Weinhold 		error = B_OK;
131198da112cSIngo Weinhold 		int32 idFound;
131298da112cSIngo Weinhold 		size_t sizeFound;
131398da112cSIngo Weinhold 		if (error == B_OK) {
131498da112cSIngo Weinhold 			if (!fResources->GetResourceInfo(type, name, &idFound, &sizeFound))
131598da112cSIngo Weinhold 				error = B_ENTRY_NOT_FOUND;
131698da112cSIngo Weinhold 		}
1317338b8dc3SIngo Weinhold 
131898da112cSIngo Weinhold 		// check id and size, allocate a buffer, if required
131998da112cSIngo Weinhold 		if (error == B_OK && id >= 0 && idFound != id)
132098da112cSIngo Weinhold 			error = B_ENTRY_NOT_FOUND;
1321b4598d95SIngo Weinhold 		if (error == B_OK && allocatedBuffer) {
132298da112cSIngo Weinhold 			buffer = malloc(sizeFound);
132398da112cSIngo Weinhold 			if (!buffer)
132498da112cSIngo Weinhold 				error = B_NO_MEMORY;
132598da112cSIngo Weinhold 			bufferSize = sizeFound;
132698da112cSIngo Weinhold 		}
132798da112cSIngo Weinhold 		if (error == B_OK && bufferSize < sizeFound)
132898da112cSIngo Weinhold 			error = B_BAD_VALUE;
1329338b8dc3SIngo Weinhold 
133098da112cSIngo Weinhold 		// load resource
133198da112cSIngo Weinhold 		const void *resourceData = NULL;
133298da112cSIngo Weinhold 		if (error == B_OK) {
133398da112cSIngo Weinhold 			resourceData = fResources->LoadResource(type, name, &bytesRead);
133498da112cSIngo Weinhold 			if (resourceData && sizeFound == bytesRead)
133598da112cSIngo Weinhold 				memcpy(buffer, resourceData, bytesRead);
133698da112cSIngo Weinhold 			else
133798da112cSIngo Weinhold 				error = B_ERROR;
133898da112cSIngo Weinhold 		}
1339773be699SAxel Dörfler 	} else if (!foundData)
134098da112cSIngo Weinhold 		error = B_BAD_VALUE;
1341338b8dc3SIngo Weinhold 
134298da112cSIngo Weinhold 	// return the allocated buffer, or free it on error
134398da112cSIngo Weinhold 	if (allocatedBuffer) {
134498da112cSIngo Weinhold 		if (error == B_OK)
134598da112cSIngo Weinhold 			*allocatedBuffer = buffer;
134698da112cSIngo Weinhold 		else
134798da112cSIngo Weinhold 			free(buffer);
134898da112cSIngo Weinhold 	}
1349338b8dc3SIngo Weinhold 
135098da112cSIngo Weinhold 	return error;
135198da112cSIngo Weinhold }
135298da112cSIngo Weinhold 
135398da112cSIngo Weinhold // _WriteData
135498da112cSIngo Weinhold /*!	\brief Writes data to an attribute or resource.
135598da112cSIngo Weinhold 
135698da112cSIngo Weinhold 	The data are written to the location(s) specified by \a fWhere.
135798da112cSIngo Weinhold 
135898da112cSIngo Weinhold 	The object must be properly initialized. The parameters are NOT checked.
135998da112cSIngo Weinhold 
136098da112cSIngo Weinhold 	\param name The name of the attribute/resource to be written.
136198da112cSIngo Weinhold 	\param id The resource ID of the resource to be written.
136298da112cSIngo Weinhold 	\param type The type of the attribute/resource to be written.
136398da112cSIngo Weinhold 	\param buffer A buffer containing the data to be written.
136498da112cSIngo Weinhold 	\param bufferSize The size of the supplied buffer.
136598da112cSIngo Weinhold 	\param findID If set to \c true use the ID that is already assigned to the
136698da112cSIngo Weinhold 		   \a name / \a type pair or take the first unused ID >= \a id.
136798da112cSIngo Weinhold 		   If \c false, \a id is used.
136898da112cSIngo Weinhold 	If \a id is already in use and .
136998da112cSIngo Weinhold 	\return
137098da112cSIngo Weinhold 	- \c B_OK: Everything went fine.
137198da112cSIngo Weinhold 	- error code
137298da112cSIngo Weinhold */
137398da112cSIngo Weinhold status_t
137498da112cSIngo Weinhold BAppFileInfo::_WriteData(const char *name, int32 id, type_code type,
137598da112cSIngo Weinhold 						 const void *buffer, size_t bufferSize, bool findID)
137698da112cSIngo Weinhold {
137798da112cSIngo Weinhold 	status_t error = B_OK;
137898da112cSIngo Weinhold 	// write to attribute
137998da112cSIngo Weinhold 	if (IsUsingAttributes() && error == B_OK) {
138098da112cSIngo Weinhold 		ssize_t written = fNode->WriteAttr(name, type, 0, buffer, bufferSize);
138198da112cSIngo Weinhold 		if (written < 0)
138298da112cSIngo Weinhold 			error = written;
138398da112cSIngo Weinhold 		else if (written != (ssize_t)bufferSize)
138498da112cSIngo Weinhold 			error = B_ERROR;
138598da112cSIngo Weinhold 	}
138698da112cSIngo Weinhold 	// write to resource
138798da112cSIngo Weinhold 	if (IsUsingResources() && error == B_OK) {
138898da112cSIngo Weinhold 		if (findID) {
138998da112cSIngo Weinhold 			// get the resource info
139098da112cSIngo Weinhold 			int32 idFound;
139198da112cSIngo Weinhold 			size_t sizeFound;
139298da112cSIngo Weinhold 			if (fResources->GetResourceInfo(type, name, &idFound, &sizeFound))
139398da112cSIngo Weinhold 				id = idFound;
139498da112cSIngo Weinhold 			else {
139598da112cSIngo Weinhold 				// type-name pair doesn't exist yet -- find unused ID
139698da112cSIngo Weinhold 				while (fResources->HasResource(type, id))
139798da112cSIngo Weinhold 					id++;
139898da112cSIngo Weinhold 			}
139998da112cSIngo Weinhold 		}
140098da112cSIngo Weinhold 		error = fResources->AddResource(type, id, buffer, bufferSize, name);
140198da112cSIngo Weinhold 	}
140298da112cSIngo Weinhold 	return error;
140398da112cSIngo Weinhold }
140498da112cSIngo Weinhold 
140598da112cSIngo Weinhold // _RemoveData
140698da112cSIngo Weinhold /*!	\brief Removes an attribute or resource.
140798da112cSIngo Weinhold 
140898da112cSIngo Weinhold 	The removal location is specified by \a fWhere.
140998da112cSIngo Weinhold 
141098da112cSIngo Weinhold 	The object must be properly initialized. The parameters are NOT checked.
141198da112cSIngo Weinhold 
141298da112cSIngo Weinhold 	\param name The name of the attribute/resource to be remove.
141398da112cSIngo Weinhold 	\param type The type of the attribute/resource to be removed.
141498da112cSIngo Weinhold 	\return
141598da112cSIngo Weinhold 	- \c B_OK: Everything went fine.
141698da112cSIngo Weinhold 	- error code
141798da112cSIngo Weinhold */
141898da112cSIngo Weinhold status_t
141998da112cSIngo Weinhold BAppFileInfo::_RemoveData(const char *name, type_code type)
142098da112cSIngo Weinhold {
142198da112cSIngo Weinhold 	status_t error = B_OK;
142298da112cSIngo Weinhold 	// remove the attribute
142398da112cSIngo Weinhold 	if (IsUsingAttributes() && error == B_OK) {
142498da112cSIngo Weinhold 		error = fNode->RemoveAttr(name);
142598da112cSIngo Weinhold 		// It's no error, if there has been no attribute.
142698da112cSIngo Weinhold 		if (error == B_ENTRY_NOT_FOUND)
142798da112cSIngo Weinhold 			error = B_OK;
142898da112cSIngo Weinhold 	}
142998da112cSIngo Weinhold 	// remove the resource
143098da112cSIngo Weinhold 	if (IsUsingResources() && error == B_OK) {
143198da112cSIngo Weinhold 		// get a resource info
143298da112cSIngo Weinhold 		int32 idFound;
143398da112cSIngo Weinhold 		size_t sizeFound;
143498da112cSIngo Weinhold 		if (fResources->GetResourceInfo(type, name, &idFound, &sizeFound))
143598da112cSIngo Weinhold 			error = fResources->RemoveResource(type, idFound);
143698da112cSIngo Weinhold 	}
143798da112cSIngo Weinhold 	return error;
143898da112cSIngo Weinhold }
143998da112cSIngo Weinhold 
1440