xref: /haiku/src/kits/storage/AppFileInfo.cpp (revision 2a74c55308e0d9daf37c209ca0aece0aea99b60f)
131dc79a1SAxel Dörfler /*
2d0c290bfSAxel Dörfler  * Copyright 2002-2007, 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 	delete fResources;
105d6b205f3SIngo Weinhold }
106d6b205f3SIngo Weinhold 
107d6b205f3SIngo Weinhold // SetTo
108d6b205f3SIngo Weinhold /*!	\brief Initializes the BAppFileInfo to the supplied file.
109d6b205f3SIngo Weinhold 
110d6b205f3SIngo Weinhold 	The caller retains ownership of the supplied BFile object. It must not
111d6b205f3SIngo Weinhold 	be deleted during the life time of the BAppFileInfo. It is not deleted
112d6b205f3SIngo Weinhold 	when the BAppFileInfo is destroyed.
113d6b205f3SIngo Weinhold 
114d6b205f3SIngo Weinhold 	\param file The file the object shall be initialized to.
115d6b205f3SIngo Weinhold 
116d6b205f3SIngo Weinhold 	\return
117d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
118d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a file or \a file is not properly initialized.
119d6b205f3SIngo Weinhold */
120d6b205f3SIngo Weinhold status_t
121d6b205f3SIngo Weinhold BAppFileInfo::SetTo(BFile *file)
122d6b205f3SIngo Weinhold {
12398da112cSIngo Weinhold 	// unset the old file
12498da112cSIngo Weinhold 	BNodeInfo::SetTo(NULL);
12598da112cSIngo Weinhold 	if (fResources) {
12698da112cSIngo Weinhold 		delete fResources;
12798da112cSIngo Weinhold 		fResources = NULL;
12898da112cSIngo Weinhold 	}
129c2a2369dSAxel Dörfler 
13098da112cSIngo Weinhold 	// check param
13198da112cSIngo Weinhold 	status_t error = (file && file->InitCheck() == B_OK ? B_OK : B_BAD_VALUE);
132c2a2369dSAxel Dörfler 
133c2a2369dSAxel Dörfler 	info_location where = B_USE_BOTH_LOCATIONS;
134c2a2369dSAxel Dörfler 
13598da112cSIngo Weinhold 	// create resources
13698da112cSIngo Weinhold 	if (error == B_OK) {
13798da112cSIngo Weinhold 		fResources = new(nothrow) BResources();
138c2a2369dSAxel Dörfler 		if (fResources) {
13998da112cSIngo Weinhold 			error = fResources->SetTo(file);
140c2a2369dSAxel Dörfler 			if (error != B_OK) {
141c2a2369dSAxel Dörfler 				// no resources - this is no critical error, we'll just use
142c2a2369dSAxel Dörfler 				// attributes only, then
143c2a2369dSAxel Dörfler 				where = B_USE_ATTRIBUTES;
144c2a2369dSAxel Dörfler 				error = B_OK;
145c2a2369dSAxel Dörfler 			}
146c2a2369dSAxel Dörfler 		} else
14798da112cSIngo Weinhold 			error = B_NO_MEMORY;
14898da112cSIngo Weinhold 	}
149c2a2369dSAxel Dörfler 
15098da112cSIngo Weinhold 	// set node info
15198da112cSIngo Weinhold 	if (error == B_OK)
15298da112cSIngo Weinhold 		error = BNodeInfo::SetTo(file);
153c2a2369dSAxel Dörfler 
154c2a2369dSAxel Dörfler 	if (error != B_OK || (where & B_USE_RESOURCES) == 0) {
15598da112cSIngo Weinhold 		delete fResources;
15698da112cSIngo Weinhold 		fResources = NULL;
15798da112cSIngo Weinhold 	}
158c2a2369dSAxel Dörfler 
159c2a2369dSAxel Dörfler 	// clean up on error
160c2a2369dSAxel Dörfler 	if (error != B_OK) {
16198da112cSIngo Weinhold 		if (InitCheck() == B_OK)
16298da112cSIngo Weinhold 			BNodeInfo::SetTo(NULL);
16398da112cSIngo Weinhold 	}
164c2a2369dSAxel Dörfler 
16598da112cSIngo Weinhold 	// set data location
16698da112cSIngo Weinhold 	if (error == B_OK)
167c2a2369dSAxel Dörfler 		SetInfoLocation(where);
168c2a2369dSAxel Dörfler 
16998da112cSIngo Weinhold 	// set error
17098da112cSIngo Weinhold 	fCStatus = error;
17198da112cSIngo Weinhold 	return error;
172d6b205f3SIngo Weinhold }
173d6b205f3SIngo Weinhold 
174d6b205f3SIngo Weinhold // GetType
175d6b205f3SIngo Weinhold /*!	\brief Gets the file's MIME type.
176d6b205f3SIngo Weinhold 
177d6b205f3SIngo Weinhold 	\param type A pointer to a pre-allocated character buffer of size
178d6b205f3SIngo Weinhold 		   \c B_MIME_TYPE_LENGTH or larger into which the MIME type of the
179d6b205f3SIngo Weinhold 		   file shall be written.
180d6b205f3SIngo Weinhold 	\return
181d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
182d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
183d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a type or the type string stored in the
184d6b205f3SIngo Weinhold 	  attribute/resources is longer than \c B_MIME_TYPE_LENGTH.
185d6b205f3SIngo Weinhold 	- \c B_BAD_TYPE: The attribute/resources the type string is stored in have
186d6b205f3SIngo Weinhold 	  the wrong type.
187d6b205f3SIngo Weinhold 	- \c B_ENTRY_NOT_FOUND: No type is set on the file.
188d6b205f3SIngo Weinhold 	- other error codes
189d6b205f3SIngo Weinhold */
190d6b205f3SIngo Weinhold status_t
191d6b205f3SIngo Weinhold BAppFileInfo::GetType(char *type) const
192d6b205f3SIngo Weinhold {
19398da112cSIngo Weinhold 	// check param and initialization
19498da112cSIngo Weinhold 	status_t error = (type ? B_OK : B_BAD_VALUE);
19598da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
19698da112cSIngo Weinhold 		error = B_NO_INIT;
19798da112cSIngo Weinhold 	// read the data
19898da112cSIngo Weinhold 	size_t read = 0;
19998da112cSIngo Weinhold 	if (error == B_OK) {
20098da112cSIngo Weinhold 		error = _ReadData(kTypeAttribute, kTypeResourceID, B_MIME_STRING_TYPE,
20198da112cSIngo Weinhold 						  type, B_MIME_TYPE_LENGTH, read);
20298da112cSIngo Weinhold 	}
20398da112cSIngo Weinhold 	// check the read data -- null terminate the string
20498da112cSIngo Weinhold 	if (error == B_OK && type[read - 1] != '\0') {
20598da112cSIngo Weinhold 		if (read == B_MIME_TYPE_LENGTH)
20698da112cSIngo Weinhold 			error = B_ERROR;
20798da112cSIngo Weinhold 		else
20898da112cSIngo Weinhold 			type[read] = '\0';
20998da112cSIngo Weinhold 	}
21098da112cSIngo Weinhold 	return error;
211d6b205f3SIngo Weinhold }
212d6b205f3SIngo Weinhold 
213d6b205f3SIngo Weinhold // SetType
214d6b205f3SIngo Weinhold /*!	\brief Sets the file's MIME type.
215d6b205f3SIngo Weinhold 
216d6b205f3SIngo Weinhold 	If \a type is \c NULL the file's MIME type is unset.
217d6b205f3SIngo Weinhold 
218d6b205f3SIngo Weinhold 	\param type The MIME type to be assigned to the file. Must not be longer
219d6b205f3SIngo Weinhold 		   than \c B_MIME_TYPE_LENGTH (including the terminating null).
220d6b205f3SIngo Weinhold 		   May be \c NULL.
221d6b205f3SIngo Weinhold 	\return
222d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
223d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
224d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \a type is longer than \c B_MIME_TYPE_LENGTH.
225d6b205f3SIngo Weinhold 	- other error codes
226d6b205f3SIngo Weinhold */
227d6b205f3SIngo Weinhold status_t
228d6b205f3SIngo Weinhold BAppFileInfo::SetType(const char *type)
229d6b205f3SIngo Weinhold {
23098da112cSIngo Weinhold 	// check initialization
23198da112cSIngo Weinhold 	status_t error = B_OK;
23298da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
23398da112cSIngo Weinhold 		error = B_NO_INIT;
23498da112cSIngo Weinhold 	if (error == B_OK) {
23598da112cSIngo Weinhold 		if (type) {
23698da112cSIngo Weinhold 			// check param
23798da112cSIngo Weinhold 			size_t typeLen = strlen(type);
23898da112cSIngo Weinhold 			if (error == B_OK && typeLen >= B_MIME_TYPE_LENGTH)
23998da112cSIngo Weinhold 				error = B_BAD_VALUE;
24098da112cSIngo Weinhold 			// write the data
24198da112cSIngo Weinhold 			if (error == B_OK) {
24298da112cSIngo Weinhold 				error = _WriteData(kTypeAttribute, kTypeResourceID,
24398da112cSIngo Weinhold 								   B_MIME_STRING_TYPE, type, typeLen + 1);
24498da112cSIngo Weinhold 			}
24598da112cSIngo Weinhold 		} else
24698da112cSIngo Weinhold 			error = _RemoveData(kTypeAttribute, B_MIME_STRING_TYPE);
24798da112cSIngo Weinhold 	}
24898da112cSIngo Weinhold 	return error;
249d6b205f3SIngo Weinhold }
250d6b205f3SIngo Weinhold 
251d6b205f3SIngo Weinhold // GetSignature
252d6b205f3SIngo Weinhold /*!	\brief Gets the file's application signature.
253d6b205f3SIngo Weinhold 
254d6b205f3SIngo Weinhold 	\param signature A pointer to a pre-allocated character buffer of size
255d6b205f3SIngo Weinhold 		   \c B_MIME_TYPE_LENGTH or larger into which the application
256d6b205f3SIngo Weinhold 		   signature of the file shall be written.
257d6b205f3SIngo Weinhold 	\return
258d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
259d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
260d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a signature or the signature stored in the
261d6b205f3SIngo Weinhold 	  attribute/resources is longer than \c B_MIME_TYPE_LENGTH.
262d6b205f3SIngo Weinhold 	- \c B_BAD_TYPE: The attribute/resources the signature is stored in have
263d6b205f3SIngo Weinhold 	  the wrong type.
264d6b205f3SIngo Weinhold 	- \c B_ENTRY_NOT_FOUND: No signature is set on the file.
265d6b205f3SIngo Weinhold 	- other error codes
266d6b205f3SIngo Weinhold */
267d6b205f3SIngo Weinhold status_t
268d6b205f3SIngo Weinhold BAppFileInfo::GetSignature(char *signature) const
269d6b205f3SIngo Weinhold {
27098da112cSIngo Weinhold 	// check param and initialization
27198da112cSIngo Weinhold 	status_t error = (signature ? B_OK : B_BAD_VALUE);
27298da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
27398da112cSIngo Weinhold 		error = B_NO_INIT;
27498da112cSIngo Weinhold 	// read the data
27598da112cSIngo Weinhold 	size_t read = 0;
27698da112cSIngo Weinhold 	if (error == B_OK) {
27798da112cSIngo Weinhold 		error = _ReadData(kSignatureAttribute, kSignatureResourceID,
27898da112cSIngo Weinhold 						  B_MIME_STRING_TYPE, signature, B_MIME_TYPE_LENGTH,
27998da112cSIngo Weinhold 						  read);
28098da112cSIngo Weinhold 	}
28198da112cSIngo Weinhold 	// check the read data -- null terminate the string
28298da112cSIngo Weinhold 	if (error == B_OK && signature[read - 1] != '\0') {
28398da112cSIngo Weinhold 		if (read == B_MIME_TYPE_LENGTH)
28498da112cSIngo Weinhold 			error = B_ERROR;
28598da112cSIngo Weinhold 		else
28698da112cSIngo Weinhold 			signature[read] = '\0';
28798da112cSIngo Weinhold 	}
28898da112cSIngo Weinhold 	return error;
289d6b205f3SIngo Weinhold }
290d6b205f3SIngo Weinhold 
291d6b205f3SIngo Weinhold // SetSignature
292d6b205f3SIngo Weinhold /*!	\brief Sets the file's application signature.
293d6b205f3SIngo Weinhold 
294d6b205f3SIngo Weinhold 	If \a signature is \c NULL the file's application signature is unset.
295d6b205f3SIngo Weinhold 
296d6b205f3SIngo Weinhold 	\param signature The application signature to be assigned to the file.
297d6b205f3SIngo Weinhold 		   Must not be longer than \c B_MIME_TYPE_LENGTH (including the
298d6b205f3SIngo Weinhold 		   terminating null). May be \c NULL.
299d6b205f3SIngo Weinhold 	\return
300d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
301d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
302d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \a signature is longer than \c B_MIME_TYPE_LENGTH.
303d6b205f3SIngo Weinhold 	- other error codes
304d6b205f3SIngo Weinhold */
305d6b205f3SIngo Weinhold status_t
306d6b205f3SIngo Weinhold BAppFileInfo::SetSignature(const char *signature)
307d6b205f3SIngo Weinhold {
30898da112cSIngo Weinhold 	// check initialization
30998da112cSIngo Weinhold 	status_t error = B_OK;
31098da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
31198da112cSIngo Weinhold 		error = B_NO_INIT;
31298da112cSIngo Weinhold 	if (error == B_OK) {
31398da112cSIngo Weinhold 		if (signature) {
31498da112cSIngo Weinhold 			// check param
31598da112cSIngo Weinhold 			size_t signatureLen = strlen(signature);
31698da112cSIngo Weinhold 			if (error == B_OK && signatureLen >= B_MIME_TYPE_LENGTH)
31798da112cSIngo Weinhold 				error = B_BAD_VALUE;
31898da112cSIngo Weinhold 			// write the data
31998da112cSIngo Weinhold 			if (error == B_OK) {
32098da112cSIngo Weinhold 				error = _WriteData(kSignatureAttribute, kSignatureResourceID,
32198da112cSIngo Weinhold 								   B_MIME_STRING_TYPE, signature,
32298da112cSIngo Weinhold 								   signatureLen + 1);
32398da112cSIngo Weinhold 			}
32498da112cSIngo Weinhold 		} else
32598da112cSIngo Weinhold 			error = _RemoveData(kSignatureAttribute, B_MIME_STRING_TYPE);
32698da112cSIngo Weinhold 	}
32798da112cSIngo Weinhold 	return error;
328d6b205f3SIngo Weinhold }
329d6b205f3SIngo Weinhold 
330d6b205f3SIngo Weinhold // GetAppFlags
331d6b205f3SIngo Weinhold /*!	\brief Gets the file's application flags.
332d6b205f3SIngo Weinhold 
333d6b205f3SIngo Weinhold 	\param flags A pointer to a pre-allocated uint32 into which the application
334d6b205f3SIngo Weinhold 		   flags of the file shall be written.
335d6b205f3SIngo Weinhold 	\return
336d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
337d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
338d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a flags.
339d6b205f3SIngo Weinhold 	- \c B_BAD_TYPE: The attribute/resources the flags are stored in have
340d6b205f3SIngo Weinhold 	  the wrong type.
341d6b205f3SIngo Weinhold 	- \c B_ENTRY_NOT_FOUND: No application flags are set on the file.
342d6b205f3SIngo Weinhold 	- other error codes
343d6b205f3SIngo Weinhold */
344d6b205f3SIngo Weinhold status_t
345d6b205f3SIngo Weinhold BAppFileInfo::GetAppFlags(uint32 *flags) const
346d6b205f3SIngo Weinhold {
34798da112cSIngo Weinhold 	// check param and initialization
34898da112cSIngo Weinhold 	status_t error = (flags ? B_OK : B_BAD_VALUE);
34998da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
35098da112cSIngo Weinhold 		error = B_NO_INIT;
35198da112cSIngo Weinhold 	// read the data
35298da112cSIngo Weinhold 	size_t read = 0;
35398da112cSIngo Weinhold 	if (error == B_OK) {
35498da112cSIngo Weinhold 		error = _ReadData(kAppFlagsAttribute, kAppFlagsResourceID,
35598da112cSIngo Weinhold 						  B_APP_FLAGS_TYPE, flags, sizeof(uint32),
35698da112cSIngo Weinhold 						  read);
35798da112cSIngo Weinhold 	}
35898da112cSIngo Weinhold 	// check the read data
35998da112cSIngo Weinhold 	if (error == B_OK && read != sizeof(uint32))
36098da112cSIngo Weinhold 		error = B_ERROR;
36198da112cSIngo Weinhold 	return error;
362d6b205f3SIngo Weinhold }
363d6b205f3SIngo Weinhold 
364d6b205f3SIngo Weinhold // SetAppFlags
365d6b205f3SIngo Weinhold /*!	\brief Sets the file's application flags.
366d6b205f3SIngo Weinhold 	\param flags The application flags to be assigned to the file.
367d6b205f3SIngo Weinhold 	\return
368d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
369d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
370d6b205f3SIngo Weinhold 	- other error codes
371d6b205f3SIngo Weinhold */
372d6b205f3SIngo Weinhold status_t
373d6b205f3SIngo Weinhold BAppFileInfo::SetAppFlags(uint32 flags)
374d6b205f3SIngo Weinhold {
37598da112cSIngo Weinhold 	// check initialization
37698da112cSIngo Weinhold 	status_t error = B_OK;
37798da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
37898da112cSIngo Weinhold 		error = B_NO_INIT;
37998da112cSIngo Weinhold 	if (error == B_OK) {
38098da112cSIngo Weinhold 		// write the data
38198da112cSIngo Weinhold 		if (error == B_OK) {
38298da112cSIngo Weinhold 			error = _WriteData(kAppFlagsAttribute, kAppFlagsResourceID,
38398da112cSIngo Weinhold 							   B_APP_FLAGS_TYPE, &flags, sizeof(uint32));
38498da112cSIngo Weinhold 		}
38598da112cSIngo Weinhold 	}
38698da112cSIngo Weinhold 	return error;
387d6b205f3SIngo Weinhold }
388d6b205f3SIngo Weinhold 
389d6b205f3SIngo Weinhold // GetSupportedTypes
390d6b205f3SIngo Weinhold /*!	\brief Gets the MIME types supported by the application.
391d6b205f3SIngo Weinhold 
392d6b205f3SIngo Weinhold 	The supported MIME types are added to a field "types" of type
393d6b205f3SIngo Weinhold 	\c B_STRING_TYPE in \a types.
394d6b205f3SIngo Weinhold 
395d6b205f3SIngo Weinhold 	\param types A pointer to a pre-allocated BMessage into which the
396d6b205f3SIngo Weinhold 		   MIME types supported by the appplication shall be written.
397d6b205f3SIngo Weinhold 	\return
398d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
399d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
400d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a types.
401d6b205f3SIngo Weinhold 	- \c B_BAD_TYPE: The attribute/resources the supported types are stored in
402d6b205f3SIngo Weinhold 	  have the wrong type.
403d6b205f3SIngo Weinhold 	- \c B_ENTRY_NOT_FOUND: No supported types are set on the file.
404d6b205f3SIngo Weinhold 	- other error codes
405d6b205f3SIngo Weinhold */
406d6b205f3SIngo Weinhold status_t
407d6b205f3SIngo Weinhold BAppFileInfo::GetSupportedTypes(BMessage *types) const
408d6b205f3SIngo Weinhold {
40998da112cSIngo Weinhold 	// check param and initialization
41098da112cSIngo Weinhold 	status_t error = (types ? B_OK : B_BAD_VALUE);
41198da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
41298da112cSIngo Weinhold 		error = B_NO_INIT;
41398da112cSIngo Weinhold 	// read the data
41498da112cSIngo Weinhold 	size_t read = 0;
41598da112cSIngo Weinhold 	void *buffer = NULL;
41698da112cSIngo Weinhold 	if (error == B_OK) {
41798da112cSIngo Weinhold 		error = _ReadData(kSupportedTypesAttribute, kSupportedTypesResourceID,
41898da112cSIngo Weinhold 						  B_MESSAGE_TYPE, NULL, 0, read, &buffer);
41998da112cSIngo Weinhold 	}
42098da112cSIngo Weinhold 	// unflatten the buffer
42198da112cSIngo Weinhold 	if (error == B_OK)
42298da112cSIngo Weinhold 		error = types->Unflatten((const char*)buffer);
42398da112cSIngo Weinhold 	// clean up
42498da112cSIngo Weinhold 	if (buffer)
42598da112cSIngo Weinhold 		free(buffer);
42698da112cSIngo Weinhold 	return error;
427d6b205f3SIngo Weinhold }
428d6b205f3SIngo Weinhold 
429d6b205f3SIngo Weinhold // SetSupportedTypes
430d6b205f3SIngo Weinhold /*!	\brief Sets the MIME types supported by the application.
431d6b205f3SIngo Weinhold 
432d6b205f3SIngo Weinhold 	If \a types is \c NULL the application's supported types are unset.
433d6b205f3SIngo Weinhold 
434d6b205f3SIngo Weinhold 	The supported MIME types must be stored in a field "types" of type
435d6b205f3SIngo Weinhold 	\c B_STRING_TYPE in \a types.
436d6b205f3SIngo Weinhold 
43783a812a1SIngo Weinhold 	The method informs the registrar about this news.
43883a812a1SIngo Weinhold 	For each supported type the result of BMimeType::GetSupportingApps() will
43983a812a1SIngo Weinhold 	afterwards include the signature of this application. That is, the
44083a812a1SIngo Weinhold 	application file needs to have a signature set.
44183a812a1SIngo Weinhold 
44283a812a1SIngo Weinhold 	\a syncAll specifies whether the not longer supported types shall be
44383a812a1SIngo Weinhold 	updated as well, i.e. whether this application shall be remove from the
44483a812a1SIngo Weinhold 	lists of supporting applications.
44583a812a1SIngo Weinhold 
446d6b205f3SIngo Weinhold 	\param types The supported types to be assigned to the file.
447d6b205f3SIngo Weinhold 		   May be \c NULL.
44883a812a1SIngo Weinhold 	\param syncAll \c true to also synchronize the not longer supported
44983a812a1SIngo Weinhold 		   types, \c false otherwise.
450d6b205f3SIngo Weinhold 	\return
451d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
452d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
453d6b205f3SIngo Weinhold 	- other error codes
454d6b205f3SIngo Weinhold */
455d6b205f3SIngo Weinhold status_t
456d6b205f3SIngo Weinhold BAppFileInfo::SetSupportedTypes(const BMessage *types, bool syncAll)
457d6b205f3SIngo Weinhold {
45898da112cSIngo Weinhold 	// check initialization
45998da112cSIngo Weinhold 	status_t error = B_OK;
46098da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
46198da112cSIngo Weinhold 		error = B_NO_INIT;
46298da112cSIngo Weinhold 	BMimeType mimeType;
46398da112cSIngo Weinhold 	if (error == B_OK)
46498da112cSIngo Weinhold 		error = GetMetaMime(&mimeType);
4657f20062dSJérôme Duval 	if (error == B_OK || error == B_ENTRY_NOT_FOUND) {
4667f20062dSJérôme Duval 		error = B_OK;
46798da112cSIngo Weinhold 		if (types) {
46817819be3SIngo Weinhold 			// check param -- supported types must be valid
46917819be3SIngo Weinhold 			const char *type;
47017819be3SIngo Weinhold 			for (int32 i = 0;
47117819be3SIngo Weinhold 				 error == B_OK && types->FindString("types", i, &type) == B_OK;
47217819be3SIngo Weinhold 				 i++) {
47317819be3SIngo Weinhold 				if (!BMimeType::IsValid(type))
47417819be3SIngo Weinhold 					error = B_BAD_VALUE;
47517819be3SIngo Weinhold 			}
47617819be3SIngo Weinhold 			// get flattened size
47717819be3SIngo Weinhold 			ssize_t size = 0;
47817819be3SIngo Weinhold 			if (error == B_OK) {
47917819be3SIngo Weinhold 				size = types->FlattenedSize();
48098da112cSIngo Weinhold 				if (size < 0)
48198da112cSIngo Weinhold 					error = size;
48217819be3SIngo Weinhold 			}
48398da112cSIngo Weinhold 			// allocate a buffer for the flattened data
48498da112cSIngo Weinhold 			char *buffer = NULL;
48598da112cSIngo Weinhold 			if (error == B_OK) {
48698da112cSIngo Weinhold 				buffer = new(nothrow) char[size];
48798da112cSIngo Weinhold 				if (!buffer)
48898da112cSIngo Weinhold 					error = B_NO_MEMORY;
48998da112cSIngo Weinhold 			}
49098da112cSIngo Weinhold 			// flatten the message
49198da112cSIngo Weinhold 			if (error == B_OK)
49298da112cSIngo Weinhold 				error = types->Flatten(buffer, size);
49398da112cSIngo Weinhold 			// write the data
49498da112cSIngo Weinhold 			if (error == B_OK) {
49598da112cSIngo Weinhold 				error = _WriteData(kSupportedTypesAttribute,
49698da112cSIngo Weinhold 								   kSupportedTypesResourceID, B_MESSAGE_TYPE,
49798da112cSIngo Weinhold 								   buffer, size);
49898da112cSIngo Weinhold 			}
49998da112cSIngo Weinhold 			// clean up
50098da112cSIngo Weinhold 			if (buffer)
50198da112cSIngo Weinhold 				delete[] buffer;
50298da112cSIngo Weinhold 		} else
50398da112cSIngo Weinhold 			error = _RemoveData(kSupportedTypesAttribute, B_MESSAGE_TYPE);
50498da112cSIngo Weinhold 		// update the MIME database, if the app signature is installed
50517819be3SIngo Weinhold 		if (error == B_OK && mimeType.IsInstalled())
50617819be3SIngo Weinhold 			error = mimeType.SetSupportedTypes(types, syncAll);
50798da112cSIngo Weinhold 	}
50898da112cSIngo Weinhold 	return error;
509d6b205f3SIngo Weinhold }
510d6b205f3SIngo Weinhold 
511d6b205f3SIngo Weinhold // SetSupportedTypes
512d6b205f3SIngo Weinhold /*!	\brief Sets the MIME types supported by the application.
513d6b205f3SIngo Weinhold 
51498da112cSIngo Weinhold 	This method is a short-hand for SetSupportedTypes(types, false).
51583a812a1SIngo Weinhold 	\see SetSupportedType(const BMessage*, bool) for detailed information.
516d6b205f3SIngo Weinhold 
517d6b205f3SIngo Weinhold 	\param types The supported types to be assigned to the file.
518d6b205f3SIngo Weinhold 		   May be \c NULL.
519d6b205f3SIngo Weinhold 	\return
520d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
521d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
522d6b205f3SIngo Weinhold 	- other error codes
523d6b205f3SIngo Weinhold */
524d6b205f3SIngo Weinhold status_t
525d6b205f3SIngo Weinhold BAppFileInfo::SetSupportedTypes(const BMessage *types)
526d6b205f3SIngo Weinhold {
52798da112cSIngo Weinhold 	return SetSupportedTypes(types, false);
528d6b205f3SIngo Weinhold }
529d6b205f3SIngo Weinhold 
530d6b205f3SIngo Weinhold // IsSupportedType
531d6b205f3SIngo Weinhold /*!	\brief Returns whether the application supports the supplied MIME type.
532d6b205f3SIngo Weinhold 
533d6b205f3SIngo Weinhold 	If the application supports the wildcard type "application/octet-stream"
534d6b205f3SIngo Weinhold 	any this method returns \c true for any MIME type.
535d6b205f3SIngo Weinhold 
536d6b205f3SIngo Weinhold 	\param type The MIME type in question.
537d6b205f3SIngo Weinhold 	\return \c true, if \a type is a valid MIME type and it is supported by
538d6b205f3SIngo Weinhold 			the application, \c false otherwise.
539d6b205f3SIngo Weinhold */
540d6b205f3SIngo Weinhold bool
541d6b205f3SIngo Weinhold BAppFileInfo::IsSupportedType(const char *type) const
542d6b205f3SIngo Weinhold {
54398da112cSIngo Weinhold 	status_t error = (type ? B_OK : B_BAD_VALUE);
54498da112cSIngo Weinhold 	// get the supported types
54598da112cSIngo Weinhold 	BMessage types;
54698da112cSIngo Weinhold 	if (error == B_OK)
54798da112cSIngo Weinhold 		error = GetSupportedTypes(&types);
54898da112cSIngo Weinhold 	// turn type into a BMimeType
54998da112cSIngo Weinhold 	BMimeType mimeType;
55098da112cSIngo Weinhold 	if (error == B_OK)
55198da112cSIngo Weinhold 		error = mimeType.SetTo(type);
55298da112cSIngo Weinhold 	// iterate through the supported types
55398da112cSIngo Weinhold 	bool found = false;
55498da112cSIngo Weinhold 	if (error == B_OK) {
55598da112cSIngo Weinhold 		const char *supportedType;
55698da112cSIngo Weinhold 		for (int32 i = 0;
55798da112cSIngo Weinhold 			 !found && types.FindString("types", i, &supportedType) == B_OK;
55898da112cSIngo Weinhold 			 i++) {
55998da112cSIngo Weinhold 			found = !strcmp(supportedType, "application/octet-stream")
56098da112cSIngo Weinhold 					|| BMimeType(supportedType).Contains(&mimeType);
56198da112cSIngo Weinhold 		}
56298da112cSIngo Weinhold 	}
56398da112cSIngo Weinhold 	return found;
564d6b205f3SIngo Weinhold }
565d6b205f3SIngo Weinhold 
566d6b205f3SIngo Weinhold // Supports
567d6b205f3SIngo Weinhold /*!	\brief Returns whether the application supports the supplied MIME type
568d6b205f3SIngo Weinhold 		   explicitly.
569d6b205f3SIngo Weinhold 
570d6b205f3SIngo Weinhold 	Unlike IsSupportedType(), this method returns \c true, only if the type
571d6b205f3SIngo Weinhold 	is explicitly supported, regardless of whether it supports
572d6b205f3SIngo Weinhold 	"application/octet-stream".
573d6b205f3SIngo Weinhold 
574d6b205f3SIngo Weinhold 	\param type The MIME type in question.
575d6b205f3SIngo Weinhold 	\return \c true, if \a type is a valid MIME type and it is explicitly
576d6b205f3SIngo Weinhold 			supported by the application, \c false otherwise.
577d6b205f3SIngo Weinhold */
578d6b205f3SIngo Weinhold bool
579d6b205f3SIngo Weinhold BAppFileInfo::Supports(BMimeType *type) const
580d6b205f3SIngo Weinhold {
58198da112cSIngo Weinhold 	status_t error = (type && type->InitCheck() == B_OK ? B_OK : B_BAD_VALUE);
58298da112cSIngo Weinhold 	// get the supported types
58398da112cSIngo Weinhold 	BMessage types;
58498da112cSIngo Weinhold 	if (error == B_OK)
58598da112cSIngo Weinhold 		error = GetSupportedTypes(&types);
58698da112cSIngo Weinhold 	// iterate through the supported types
58798da112cSIngo Weinhold 	bool found = false;
58898da112cSIngo Weinhold 	if (error == B_OK) {
58998da112cSIngo Weinhold 		const char *supportedType;
59098da112cSIngo Weinhold 		for (int32 i = 0;
59198da112cSIngo Weinhold 			 !found && types.FindString("types", i, &supportedType) == B_OK;
59298da112cSIngo Weinhold 			 i++) {
59398da112cSIngo Weinhold 			found = BMimeType(supportedType).Contains(type);
59498da112cSIngo Weinhold 		}
59598da112cSIngo Weinhold 	}
59698da112cSIngo Weinhold 	return found;
597d6b205f3SIngo Weinhold }
598d6b205f3SIngo Weinhold 
599d6b205f3SIngo Weinhold // GetIcon
600d6b205f3SIngo Weinhold /*!	\brief Gets the file's icon.
601d6b205f3SIngo Weinhold 	\param icon A pointer to a pre-allocated BBitmap of the correct dimension
602d6b205f3SIngo Weinhold 		   to store the requested icon (16x16 for the mini and 32x32 for the
603d6b205f3SIngo Weinhold 		   large icon).
604d6b205f3SIngo Weinhold 	\param which Specifies the size of the icon to be retrieved:
605d6b205f3SIngo Weinhold 		   \c B_MINI_ICON for the mini and \c B_LARGE_ICON for the large icon.
606d6b205f3SIngo Weinhold 	\return
607d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
608d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
609d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a icon, unsupported icon size \a which or bitmap
610d6b205f3SIngo Weinhold 		 dimensions (\a icon) and icon size (\a which) do not match.
611d6b205f3SIngo Weinhold 	- other error codes
612d6b205f3SIngo Weinhold */
613d6b205f3SIngo Weinhold status_t
614d6b205f3SIngo Weinhold BAppFileInfo::GetIcon(BBitmap *icon, icon_size which) const
615d6b205f3SIngo Weinhold {
61698da112cSIngo Weinhold 	return GetIconForType(NULL, icon, which);
617d6b205f3SIngo Weinhold }
618d6b205f3SIngo Weinhold 
6197fb6186fSStephan Aßmus // GetIcon
6207fb6186fSStephan Aßmus /*!	\brief Gets the file's icon.
6217fb6186fSStephan Aßmus 	\param data The pointer in which the flat icon data will be returned.
6227fb6186fSStephan Aßmus 	\param size The pointer in which the size of the data found will be returned.
6237fb6186fSStephan Aßmus 	\return
6247fb6186fSStephan Aßmus 	- \c B_OK: Everything went fine.
6257fb6186fSStephan Aßmus 	- \c B_NO_INIT: The object is not properly initialized.
6267fb6186fSStephan Aßmus 	- \c B_BAD_VALUE: \c NULL \a data or \c NULL size.
6277fb6186fSStephan Aßmus 	- other error codes
6287fb6186fSStephan Aßmus */
6297fb6186fSStephan Aßmus status_t
6307fb6186fSStephan Aßmus BAppFileInfo::GetIcon(uint8** data, size_t* size) const
6317fb6186fSStephan Aßmus {
6327fb6186fSStephan Aßmus 	return GetIconForType(NULL, data, size);
6337fb6186fSStephan Aßmus }
6347fb6186fSStephan Aßmus 
635d6b205f3SIngo Weinhold // SetIcon
636d6b205f3SIngo Weinhold /*!	\brief Sets the file's icon.
637d6b205f3SIngo Weinhold 
638d6b205f3SIngo Weinhold 	If \a icon is \c NULL the file's icon is unset.
639d6b205f3SIngo Weinhold 
640d6b205f3SIngo Weinhold 	\param icon A pointer to the BBitmap containing the icon to be set.
641d6b205f3SIngo Weinhold 		   May be \c NULL.
642d6b205f3SIngo Weinhold 	\param which Specifies the size of the icon to be set: \c B_MINI_ICON
643d6b205f3SIngo Weinhold 		   for the mini and \c B_LARGE_ICON for the large icon.
644d6b205f3SIngo Weinhold 	\return
645d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
646d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
647d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: Unknown icon size \a which or bitmap dimensions (\a icon)
648d6b205f3SIngo Weinhold 		 and icon size (\a which) do not match.
649d6b205f3SIngo Weinhold 	- other error codes
650d6b205f3SIngo Weinhold */
651d6b205f3SIngo Weinhold status_t
652d6b205f3SIngo Weinhold BAppFileInfo::SetIcon(const BBitmap *icon, icon_size which)
653d6b205f3SIngo Weinhold {
65498da112cSIngo Weinhold 	return SetIconForType(NULL, icon, which);
655d6b205f3SIngo Weinhold }
656d6b205f3SIngo Weinhold 
6577fb6186fSStephan Aßmus // SetIcon
6587fb6186fSStephan Aßmus /*!	\brief Sets the file's icon.
6597fb6186fSStephan Aßmus 
6607fb6186fSStephan Aßmus 	If \a icon is \c NULL the file's icon is unset.
6617fb6186fSStephan Aßmus 
6627fb6186fSStephan Aßmus 	\param data A pointer to the data buffer containing the vector icon
6637fb6186fSStephan Aßmus 		   to be set. May be \c NULL.
6647fb6186fSStephan Aßmus 	\param size Specifies the size of buffer pointed to by \a data.
6657fb6186fSStephan Aßmus 	\return
6667fb6186fSStephan Aßmus 	- \c B_OK: Everything went fine.
6677fb6186fSStephan Aßmus 	- \c B_NO_INIT: The object is not properly initialized.
6687fb6186fSStephan Aßmus 	- \c B_BAD_VALUE: \c NULL data.
6697fb6186fSStephan Aßmus 	- other error codes
6707fb6186fSStephan Aßmus */
6717fb6186fSStephan Aßmus status_t
6727fb6186fSStephan Aßmus BAppFileInfo::SetIcon(const uint8* data, size_t size)
6737fb6186fSStephan Aßmus {
6747fb6186fSStephan Aßmus 	return SetIconForType(NULL, data, size);
6757fb6186fSStephan Aßmus }
6767fb6186fSStephan Aßmus 
677d6b205f3SIngo Weinhold // GetVersionInfo
678d6b205f3SIngo Weinhold /*!	\brief Gets the file's version info.
679d6b205f3SIngo Weinhold 	\param info A pointer to a pre-allocated version_info structure into which
680d6b205f3SIngo Weinhold 		   the version info should be written.
681d6b205f3SIngo Weinhold 	\param kind Specifies the kind of the version info to be retrieved:
682d6b205f3SIngo Weinhold 		   \c B_APP_VERSION_KIND for the application's version info and
683d6b205f3SIngo Weinhold 		   \c B_SYSTEM_VERSION_KIND for the suite's info the application
684d6b205f3SIngo Weinhold 		   belongs to.
685d6b205f3SIngo Weinhold 	\return
686d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
687d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
688d6b205f3SIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a info.
689d6b205f3SIngo Weinhold 	- other error codes
690d6b205f3SIngo Weinhold */
691d6b205f3SIngo Weinhold status_t
692d6b205f3SIngo Weinhold BAppFileInfo::GetVersionInfo(version_info *info, version_kind kind) const
693d6b205f3SIngo Weinhold {
69498da112cSIngo Weinhold 	// check params and initialization
695b1970bb8SIngo Weinhold 	if (!info)
696b1970bb8SIngo Weinhold 		return B_BAD_VALUE;
697b1970bb8SIngo Weinhold 
69898da112cSIngo Weinhold 	int32 index = 0;
69998da112cSIngo Weinhold 	switch (kind) {
70098da112cSIngo Weinhold 		case B_APP_VERSION_KIND:
70198da112cSIngo Weinhold 			index = 0;
70298da112cSIngo Weinhold 			break;
70398da112cSIngo Weinhold 		case B_SYSTEM_VERSION_KIND:
70498da112cSIngo Weinhold 			index = 1;
70598da112cSIngo Weinhold 			break;
70698da112cSIngo Weinhold 		default:
707b1970bb8SIngo Weinhold 			return B_BAD_VALUE;
70898da112cSIngo Weinhold 	}
709b1970bb8SIngo Weinhold 
710b1970bb8SIngo Weinhold 	if (InitCheck() != B_OK)
711b1970bb8SIngo Weinhold 		return B_NO_INIT;
712b1970bb8SIngo Weinhold 
71398da112cSIngo Weinhold 	// read the data
71498da112cSIngo Weinhold 	size_t read = 0;
71598da112cSIngo Weinhold 	version_info infos[2];
716b1970bb8SIngo Weinhold 	status_t error = _ReadData(kVersionInfoAttribute, kVersionInfoResourceID,
717b1970bb8SIngo Weinhold 		B_VERSION_INFO_TYPE, infos, 2 * sizeof(version_info), read);
718b1970bb8SIngo Weinhold 	if (error != B_OK)
71998da112cSIngo Weinhold 		return error;
720b1970bb8SIngo Weinhold 
721b1970bb8SIngo Weinhold 	// check the read data
722b1970bb8SIngo Weinhold 	if (read == sizeof(version_info)) {
723b1970bb8SIngo Weinhold 		// only the app version info is there -- return a cleared system info
724b1970bb8SIngo Weinhold 		if (index == 0)
725b1970bb8SIngo Weinhold 			*info = infos[index];
726b1970bb8SIngo Weinhold 		else if (index == 1)
727b1970bb8SIngo Weinhold 			memset(info, 0, sizeof(version_info));
728b1970bb8SIngo Weinhold 	} else if (read == 2 * sizeof(version_info)) {
729b1970bb8SIngo Weinhold 		*info = infos[index];
730b1970bb8SIngo Weinhold 	} else
731b1970bb8SIngo Weinhold 		return B_ERROR;
732b1970bb8SIngo Weinhold 
733b1970bb8SIngo Weinhold 	// return result
734b1970bb8SIngo Weinhold 	return B_OK;
735d6b205f3SIngo Weinhold }
736d6b205f3SIngo Weinhold 
737d6b205f3SIngo Weinhold // SetVersionInfo
738d6b205f3SIngo Weinhold /*!	\brief Sets the file's version info.
739d6b205f3SIngo Weinhold 
740d6b205f3SIngo Weinhold 	If \a info is \c NULL the file's version info is unset.
741d6b205f3SIngo Weinhold 
742d6b205f3SIngo Weinhold 	\param info The version info to be set. May be \c NULL.
743d6b205f3SIngo Weinhold 	\param kind Specifies kind of version info to be set:
744d6b205f3SIngo Weinhold 		   \c B_APP_VERSION_KIND for the application's version info and
745d6b205f3SIngo Weinhold 		   \c B_SYSTEM_VERSION_KIND for the suite's info the application
746d6b205f3SIngo Weinhold 		   belongs to.
747d6b205f3SIngo Weinhold 	\return
748d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
749d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
750d6b205f3SIngo Weinhold 	- other error codes
751d6b205f3SIngo Weinhold */
752d6b205f3SIngo Weinhold status_t
753d6b205f3SIngo Weinhold BAppFileInfo::SetVersionInfo(const version_info *info, version_kind kind)
754d6b205f3SIngo Weinhold {
75598da112cSIngo Weinhold 	// check initialization
75698da112cSIngo Weinhold 	status_t error = B_OK;
75798da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
75898da112cSIngo Weinhold 		error = B_NO_INIT;
75998da112cSIngo Weinhold 	if (error == B_OK) {
76098da112cSIngo Weinhold 		if (info) {
76198da112cSIngo Weinhold 			// check param
76298da112cSIngo Weinhold 			int32 index = 0;
76398da112cSIngo Weinhold 			if (error == B_OK) {
76498da112cSIngo Weinhold 				switch (kind) {
76598da112cSIngo Weinhold 					case B_APP_VERSION_KIND:
76698da112cSIngo Weinhold 						index = 0;
76798da112cSIngo Weinhold 						break;
76898da112cSIngo Weinhold 					case B_SYSTEM_VERSION_KIND:
76998da112cSIngo Weinhold 						index = 1;
77098da112cSIngo Weinhold 						break;
77198da112cSIngo Weinhold 					default:
77298da112cSIngo Weinhold 						error = B_BAD_VALUE;
77398da112cSIngo Weinhold 						break;
77498da112cSIngo Weinhold 				}
77598da112cSIngo Weinhold 			}
77698da112cSIngo Weinhold 			// read both infos
77798da112cSIngo Weinhold 			version_info infos[2];
77898da112cSIngo Weinhold 			if (error == B_OK) {
77998da112cSIngo Weinhold 				size_t read;
780b1970bb8SIngo Weinhold 				if (_ReadData(kVersionInfoAttribute, kVersionInfoResourceID,
781b1970bb8SIngo Weinhold 						B_VERSION_INFO_TYPE, infos, 2 * sizeof(version_info),
782b1970bb8SIngo Weinhold 						read) == B_OK) {
783b1970bb8SIngo Weinhold 					// clear the part that hasn't been read
784b1970bb8SIngo Weinhold 					if (read < sizeof(infos))
785b1970bb8SIngo Weinhold 						memset((char*)infos + read, 0, sizeof(infos) - read);
786b1970bb8SIngo Weinhold 				} else {
787b1970bb8SIngo Weinhold 					// failed to read -- clear
788b1970bb8SIngo Weinhold 					memset(infos, 0, sizeof(infos));
789b1970bb8SIngo Weinhold 				}
79098da112cSIngo Weinhold 			}
79198da112cSIngo Weinhold 			infos[index] = *info;
79298da112cSIngo Weinhold 			// write the data
79398da112cSIngo Weinhold 			if (error == B_OK) {
79498da112cSIngo Weinhold 				error = _WriteData(kVersionInfoAttribute,
79598da112cSIngo Weinhold 								   kVersionInfoResourceID,
79698da112cSIngo Weinhold 								   B_VERSION_INFO_TYPE, infos,
79798da112cSIngo Weinhold 								   2 * sizeof(version_info));
79898da112cSIngo Weinhold 			}
79998da112cSIngo Weinhold 		} else
80098da112cSIngo Weinhold 			error = _RemoveData(kVersionInfoAttribute, B_VERSION_INFO_TYPE);
80198da112cSIngo Weinhold 	}
80298da112cSIngo Weinhold 	return error;
803d6b205f3SIngo Weinhold }
804d6b205f3SIngo Weinhold 
805d6b205f3SIngo Weinhold // GetIconForType
806d6b205f3SIngo Weinhold /*!	\brief Gets the icon the application provides for a given MIME type.
80798da112cSIngo Weinhold 
80898da112cSIngo Weinhold 	If \a type is \c NULL, the application's icon is retrieved.
80998da112cSIngo Weinhold 
81098da112cSIngo Weinhold 	\param type The MIME type in question. May be \c NULL.
811d6b205f3SIngo Weinhold 	\param icon A pointer to a pre-allocated BBitmap of the correct dimension
812d6b205f3SIngo Weinhold 		   to store the requested icon (16x16 for the mini and 32x32 for the
813d6b205f3SIngo Weinhold 		   large icon).
814d6b205f3SIngo Weinhold 	\param which Specifies the size of the icon to be retrieved:
815d6b205f3SIngo Weinhold 		   \c B_MINI_ICON for the mini and \c B_LARGE_ICON for the large icon.
816d6b205f3SIngo Weinhold 	\return
817d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
818d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
81998da112cSIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a icon, unsupported icon size
820d6b205f3SIngo Weinhold 		 \a which or bitmap dimensions (\a icon) and icon size (\a which) do
821d6b205f3SIngo Weinhold 		 not match.
822d6b205f3SIngo Weinhold 	- other error codes
823d6b205f3SIngo Weinhold */
824d6b205f3SIngo Weinhold status_t
825d6b205f3SIngo Weinhold BAppFileInfo::GetIconForType(const char* type, BBitmap* icon,
8269f507806SStephan Aßmus 							 icon_size size) const
827d6b205f3SIngo Weinhold {
8289ecf9d1cSIngo Weinhold 	if (InitCheck() != B_OK)
8299ecf9d1cSIngo Weinhold 		return B_NO_INIT;
8309ecf9d1cSIngo Weinhold 
8319ecf9d1cSIngo Weinhold 	if (!icon || icon->InitCheck() != B_OK)
8329ecf9d1cSIngo Weinhold 		return B_BAD_VALUE;
8339ecf9d1cSIngo Weinhold 
834*2a74c553SStephan Aßmus 	// TODO: for consistency with attribute based icon reading, we
835*2a74c553SStephan Aßmus 	// could also prefer B_CMAP8 icons here if the provided bitmap
836*2a74c553SStephan Aßmus 	// is in that format. Right now, an existing B_CMAP8 icon resource
837*2a74c553SStephan Aßmus 	// would be ignored as soon as a vector icon is present. On the other
838*2a74c553SStephan Aßmus 	// hand, maybe this still results in a more consistent user interface,
839*2a74c553SStephan Aßmus 	// since Tracker/Deskbar would surely show the vector icon.
840*2a74c553SStephan Aßmus 
8419ecf9d1cSIngo Weinhold 	// try vector icon first
8429ecf9d1cSIngo Weinhold 	BString vectorAttributeName(kIconAttribute);
8439ecf9d1cSIngo Weinhold 
8449ecf9d1cSIngo Weinhold 	// check type param
8459ecf9d1cSIngo Weinhold 	if (type) {
8469ecf9d1cSIngo Weinhold 		if (BMimeType::IsValid(type))
8479ecf9d1cSIngo Weinhold 			vectorAttributeName += type;
8489ecf9d1cSIngo Weinhold 		else
8499ecf9d1cSIngo Weinhold 			return B_BAD_VALUE;
8509ecf9d1cSIngo Weinhold 	} else {
8519ecf9d1cSIngo Weinhold 		vectorAttributeName += kIconType;
8529ecf9d1cSIngo Weinhold 	}
8539ecf9d1cSIngo Weinhold 	const char* attribute = vectorAttributeName.String();
8549ecf9d1cSIngo Weinhold 
8559ecf9d1cSIngo Weinhold 	size_t bytesRead;
8569ecf9d1cSIngo Weinhold 	void* allocatedBuffer;
857bae87c91SAxel Dörfler 	status_t error = _ReadData(attribute, -1, B_VECTOR_ICON_TYPE, NULL, 0,
8589ecf9d1cSIngo Weinhold 							   bytesRead, &allocatedBuffer);
8599ecf9d1cSIngo Weinhold 	if (error == B_OK) {
8607fb6186fSStephan Aßmus 		error = BIconUtils::GetVectorIcon((uint8*)allocatedBuffer,
8619ecf9d1cSIngo Weinhold 										  bytesRead, icon);
8627fb6186fSStephan Aßmus 		free(allocatedBuffer);
8637fb6186fSStephan Aßmus 		return error;
8649ecf9d1cSIngo Weinhold 	}
8659ecf9d1cSIngo Weinhold 
8669f507806SStephan Aßmus 	// no vector icon if we got this far,
8679f507806SStephan Aßmus 	// align size argument just in case
8689f507806SStephan Aßmus 	if (size < B_LARGE_ICON)
8699f507806SStephan Aßmus 		size = B_MINI_ICON;
8709f507806SStephan Aßmus 	else
8719f507806SStephan Aßmus 		size = B_LARGE_ICON;
8729ecf9d1cSIngo Weinhold 
8739ecf9d1cSIngo Weinhold 	error = B_OK;
87498da112cSIngo Weinhold 	// set some icon size related variables
87598da112cSIngo Weinhold 	BString attributeString;
87698da112cSIngo Weinhold 	BRect bounds;
877a04efc92SIngo Weinhold 	uint32 attrType = 0;
878a04efc92SIngo Weinhold 	size_t attrSize = 0;
8799f507806SStephan Aßmus 	switch (size) {
88098da112cSIngo Weinhold 		case B_MINI_ICON:
88198da112cSIngo Weinhold 			attributeString = kMiniIconAttribute;
88298da112cSIngo Weinhold 			bounds.Set(0, 0, 15, 15);
88398da112cSIngo Weinhold 			attrType = B_MINI_ICON_TYPE;
88498da112cSIngo Weinhold 			attrSize = 16 * 16;
88598da112cSIngo Weinhold 			break;
88698da112cSIngo Weinhold 		case B_LARGE_ICON:
88798da112cSIngo Weinhold 			attributeString = kLargeIconAttribute;
88898da112cSIngo Weinhold 			bounds.Set(0, 0, 31, 31);
88998da112cSIngo Weinhold 			attrType = B_LARGE_ICON_TYPE;
89098da112cSIngo Weinhold 			attrSize = 32 * 32;
89198da112cSIngo Weinhold 			break;
89298da112cSIngo Weinhold 		default:
8939ecf9d1cSIngo Weinhold 			return B_BAD_VALUE;
89498da112cSIngo Weinhold 	}
89598da112cSIngo Weinhold 	// check type param
89698da112cSIngo Weinhold 	if (type) {
89717819be3SIngo Weinhold 		if (BMimeType::IsValid(type))
89817819be3SIngo Weinhold 			attributeString += type;
89917819be3SIngo Weinhold 		else
9009ecf9d1cSIngo Weinhold 			return B_BAD_VALUE;
90198da112cSIngo Weinhold 	} else
90217819be3SIngo Weinhold 		attributeString += kStandardIconType;
9039ecf9d1cSIngo Weinhold 
9049ecf9d1cSIngo Weinhold 	attribute = attributeString.String();
90517819be3SIngo Weinhold 
9069f507806SStephan Aßmus 	// check parameters
9079f507806SStephan Aßmus 	// currently, scaling B_CMAP8 icons is not supported
9089f507806SStephan Aßmus 	if (icon->ColorSpace() == B_CMAP8 && icon->Bounds() != bounds)
9099ecf9d1cSIngo Weinhold 		return B_BAD_VALUE;
9109ecf9d1cSIngo Weinhold 
91198da112cSIngo Weinhold 	// read the data
91298da112cSIngo Weinhold 	if (error == B_OK) {
9139f507806SStephan Aßmus 		bool tempBuffer = (icon->ColorSpace() != B_CMAP8
9149f507806SStephan Aßmus 						   || icon->Bounds() != bounds);
9159f507806SStephan Aßmus 		uint8* buffer = NULL;
91698da112cSIngo Weinhold 		size_t read;
9179f507806SStephan Aßmus 		if (tempBuffer) {
9189f507806SStephan Aßmus 			// other color space or bitmap size than stored in attribute
9199f507806SStephan Aßmus 			buffer = new(nothrow) uint8[attrSize];
9209f507806SStephan Aßmus 			if (!buffer) {
92198da112cSIngo Weinhold 				error = B_NO_MEMORY;
9229f507806SStephan Aßmus 			} else {
92398da112cSIngo Weinhold 				error = _ReadData(attribute, -1, attrType, buffer, attrSize,
92498da112cSIngo Weinhold 								  read);
92598da112cSIngo Weinhold 			}
92698da112cSIngo Weinhold 		} else {
92798da112cSIngo Weinhold 			error = _ReadData(attribute, -1, attrType, icon->Bits(), attrSize,
92898da112cSIngo Weinhold 							  read);
92998da112cSIngo Weinhold 		}
93098da112cSIngo Weinhold 		if (error == B_OK && read != attrSize)
93198da112cSIngo Weinhold 			error = B_ERROR;
9329f507806SStephan Aßmus 		if (tempBuffer) {
93398da112cSIngo Weinhold 			// other color space than stored in attribute
93476ba3434SIngo Weinhold 			if (error == B_OK) {
9359f507806SStephan Aßmus 				error = BIconUtils::ConvertFromCMAP8(buffer,
9369f507806SStephan Aßmus 													 (uint32)size,
9379f507806SStephan Aßmus 													 (uint32)size,
9389f507806SStephan Aßmus 													 (uint32)size,
9399f507806SStephan Aßmus 													 icon);
94076ba3434SIngo Weinhold 			}
94198da112cSIngo Weinhold 			delete[] buffer;
94298da112cSIngo Weinhold 		}
94398da112cSIngo Weinhold 	}
94498da112cSIngo Weinhold 	return error;
945d6b205f3SIngo Weinhold }
946d6b205f3SIngo Weinhold 
9477fb6186fSStephan Aßmus // GetIconForType
9487fb6186fSStephan Aßmus /*!	\brief Gets the icon the application provides for a given MIME type.
9497fb6186fSStephan Aßmus 
9507fb6186fSStephan Aßmus 	If \a type is \c NULL, the application's icon is retrieved.
9517fb6186fSStephan Aßmus 
9527fb6186fSStephan Aßmus 	\param type The MIME type in question. May be \c NULL.
9537fb6186fSStephan Aßmus 	\param data A pointer in which the icon data will be returned. When you
9547fb6186fSStephan Aßmus 	are done with the data, you should use free() to deallocate it.
9557fb6186fSStephan Aßmus 	\param size A pointer in which the size of the retrieved data is returned.
9567fb6186fSStephan Aßmus 	\return
9577fb6186fSStephan Aßmus 	- \c B_OK: Everything went fine.
9587fb6186fSStephan Aßmus 	- \c B_NO_INIT: The object is not properly initialized.
9597fb6186fSStephan Aßmus 	- \c B_BAD_VALUE: \c NULL \a data and/or \a size. Or the supplied
9607fb6186fSStephan Aßmus 	\a type is not a valid MIME type.
9617fb6186fSStephan Aßmus 	- other error codes
9627fb6186fSStephan Aßmus */
9637fb6186fSStephan Aßmus status_t
9647fb6186fSStephan Aßmus BAppFileInfo::GetIconForType(const char *type, uint8** data,
9657fb6186fSStephan Aßmus 							 size_t* size) const
9667fb6186fSStephan Aßmus {
9677fb6186fSStephan Aßmus 	if (InitCheck() != B_OK)
9687fb6186fSStephan Aßmus 		return B_NO_INIT;
9697fb6186fSStephan Aßmus 
9707fb6186fSStephan Aßmus 	if (!data || !size)
9717fb6186fSStephan Aßmus 		return B_BAD_VALUE;
9727fb6186fSStephan Aßmus 
9737fb6186fSStephan Aßmus 	// get vector icon
9747fb6186fSStephan Aßmus 	BString attributeName(kIconAttribute);
9757fb6186fSStephan Aßmus 
9767fb6186fSStephan Aßmus 	// check type param
9777fb6186fSStephan Aßmus 	if (type) {
9787fb6186fSStephan Aßmus 		if (BMimeType::IsValid(type))
9797fb6186fSStephan Aßmus 			attributeName += type;
9807fb6186fSStephan Aßmus 		else
9817fb6186fSStephan Aßmus 			return B_BAD_VALUE;
9827fb6186fSStephan Aßmus 	} else {
9837fb6186fSStephan Aßmus 		attributeName += kIconType;
9847fb6186fSStephan Aßmus 	}
9857fb6186fSStephan Aßmus 
9867fb6186fSStephan Aßmus 	void* allocatedBuffer = NULL;
9877fb6186fSStephan Aßmus 	status_t ret = _ReadData(attributeName.String(), -1,
988bae87c91SAxel Dörfler 							 B_VECTOR_ICON_TYPE, NULL, 0, *size, &allocatedBuffer);
9897fb6186fSStephan Aßmus 
9907fb6186fSStephan Aßmus 	if (ret < B_OK)
9917fb6186fSStephan Aßmus 		return ret;
9927fb6186fSStephan Aßmus 
9937fb6186fSStephan Aßmus 	*data = (uint8*)allocatedBuffer;
9947fb6186fSStephan Aßmus 	return B_OK;
9957fb6186fSStephan Aßmus }
9967fb6186fSStephan Aßmus 
997d6b205f3SIngo Weinhold // SetIconForType
998d6b205f3SIngo Weinhold /*!	\brief Sets the icon the application provides for a given MIME type.
999d6b205f3SIngo Weinhold 
100098da112cSIngo Weinhold 	If \a type is \c NULL, the application's icon is set.
1001d6b205f3SIngo Weinhold 	If \a icon is \c NULL the icon is unset.
1002d6b205f3SIngo Weinhold 
100398da112cSIngo Weinhold 	If the file has a signature, then the icon is also set on the MIME type.
100498da112cSIngo Weinhold 	If the type for the signature has not been installed yet, it is installed
100598da112cSIngo Weinhold 	before.
100698da112cSIngo Weinhold 
100798da112cSIngo Weinhold 	\param type The MIME type in question. May be \c NULL.
1008d6b205f3SIngo Weinhold 	\param icon A pointer to the BBitmap containing the icon to be set.
1009d6b205f3SIngo Weinhold 		   May be \c NULL.
1010d6b205f3SIngo Weinhold 	\param which Specifies the size of the icon to be set: \c B_MINI_ICON
1011d6b205f3SIngo Weinhold 		   for the mini and \c B_LARGE_ICON for the large icon.
1012d6b205f3SIngo Weinhold 	\return
1013d6b205f3SIngo Weinhold 	- \c B_OK: Everything went fine.
1014d6b205f3SIngo Weinhold 	- \c B_NO_INIT: The object is not properly initialized.
10157fb6186fSStephan Aßmus 	- \c B_BAD_VALUE: Either the icon size \a which is unkown, bitmap dimensions (\a icon)
10167fb6186fSStephan Aßmus 		 and icon size (\a which) do not match, or the provided \a type is
10177fb6186fSStephan Aßmus 		 not a valid MIME type.
1018d6b205f3SIngo Weinhold 	- other error codes
1019d6b205f3SIngo Weinhold */
1020d6b205f3SIngo Weinhold status_t
1021d6b205f3SIngo Weinhold BAppFileInfo::SetIconForType(const char *type, const BBitmap *icon,
1022d6b205f3SIngo Weinhold 							 icon_size which)
1023d6b205f3SIngo Weinhold {
102498da112cSIngo Weinhold 	status_t error = B_OK;
102598da112cSIngo Weinhold 	// set some icon size related variables
102698da112cSIngo Weinhold 	BString attributeString;
102798da112cSIngo Weinhold 	BRect bounds;
1028a04efc92SIngo Weinhold 	uint32 attrType = 0;
1029a04efc92SIngo Weinhold 	size_t attrSize = 0;
1030a04efc92SIngo Weinhold 	int32 resourceID = 0;
103198da112cSIngo Weinhold 	switch (which) {
103298da112cSIngo Weinhold 		case B_MINI_ICON:
103398da112cSIngo Weinhold 			attributeString = kMiniIconAttribute;
103498da112cSIngo Weinhold 			bounds.Set(0, 0, 15, 15);
103598da112cSIngo Weinhold 			attrType = B_MINI_ICON_TYPE;
103698da112cSIngo Weinhold 			attrSize = 16 * 16;
103798da112cSIngo Weinhold 			resourceID = (type ? kMiniIconForTypeResourceID
103898da112cSIngo Weinhold 							   : kMiniIconResourceID);
103998da112cSIngo Weinhold 			break;
104098da112cSIngo Weinhold 		case B_LARGE_ICON:
104198da112cSIngo Weinhold 			attributeString = kLargeIconAttribute;
104298da112cSIngo Weinhold 			bounds.Set(0, 0, 31, 31);
104398da112cSIngo Weinhold 			attrType = B_LARGE_ICON_TYPE;
104498da112cSIngo Weinhold 			attrSize = 32 * 32;
104598da112cSIngo Weinhold 			resourceID = (type ? kLargeIconForTypeResourceID
104698da112cSIngo Weinhold 							   : kLargeIconResourceID);
104798da112cSIngo Weinhold 			break;
104898da112cSIngo Weinhold 		default:
104998da112cSIngo Weinhold 			error = B_BAD_VALUE;
105098da112cSIngo Weinhold 			break;
105198da112cSIngo Weinhold 	}
105298da112cSIngo Weinhold 	// check type param
105398da112cSIngo Weinhold 	if (error == B_OK) {
105498da112cSIngo Weinhold 		if (type) {
105517819be3SIngo Weinhold 			if (BMimeType::IsValid(type))
105698da112cSIngo Weinhold 				attributeString += type;
105717819be3SIngo Weinhold 			else
105817819be3SIngo Weinhold 				error = B_BAD_VALUE;
105998da112cSIngo Weinhold 		} else
106098da112cSIngo Weinhold 			attributeString += kStandardIconType;
106198da112cSIngo Weinhold 	}
106298da112cSIngo Weinhold 	const char *attribute = attributeString.String();
106398da112cSIngo Weinhold 	// check parameter and initialization
106498da112cSIngo Weinhold 	if (error == B_OK && icon
106598da112cSIngo Weinhold 		&& (icon->InitCheck() != B_OK || icon->Bounds() != bounds)) {
106698da112cSIngo Weinhold 		error = B_BAD_VALUE;
106798da112cSIngo Weinhold 	}
106898da112cSIngo Weinhold 	if (error == B_OK && InitCheck() != B_OK)
106998da112cSIngo Weinhold 		error = B_NO_INIT;
107098da112cSIngo Weinhold 	// write/remove the attribute
107198da112cSIngo Weinhold 	if (error == B_OK) {
107298da112cSIngo Weinhold 		if (icon) {
107398da112cSIngo Weinhold 			bool otherColorSpace = (icon->ColorSpace() != B_CMAP8);
107498da112cSIngo Weinhold 			if (otherColorSpace) {
1075290bc091SIngo Weinhold 				BBitmap bitmap(bounds, B_BITMAP_NO_SERVER_LINK, B_CMAP8);
107698da112cSIngo Weinhold 				error = bitmap.InitCheck();
107776ba3434SIngo Weinhold 				if (error == B_OK)
107876ba3434SIngo Weinhold 					error = bitmap.ImportBits(icon);
107998da112cSIngo Weinhold 				if (error == B_OK) {
108098da112cSIngo Weinhold 					error = _WriteData(attribute, resourceID, attrType,
108198da112cSIngo Weinhold 									   bitmap.Bits(), attrSize, true);
108298da112cSIngo Weinhold 				}
108398da112cSIngo Weinhold 			} else {
108498da112cSIngo Weinhold 				error = _WriteData(attribute, resourceID, attrType,
108598da112cSIngo Weinhold 								   icon->Bits(), attrSize, true);
108698da112cSIngo Weinhold 			}
108798da112cSIngo Weinhold 		} else	// no icon given => remove
108898da112cSIngo Weinhold 			error = _RemoveData(attribute, attrType);
108998da112cSIngo Weinhold 	}
109098da112cSIngo Weinhold 	// set the attribute on the MIME type, if the file has a signature
109198da112cSIngo Weinhold 	BMimeType mimeType;
109298da112cSIngo Weinhold 	if (error == B_OK && GetMetaMime(&mimeType) == B_OK) {
109398da112cSIngo Weinhold 		if (!mimeType.IsInstalled())
109498da112cSIngo Weinhold 			error = mimeType.Install();
109598da112cSIngo Weinhold 		if (error == B_OK)
109698da112cSIngo Weinhold 			error = mimeType.SetIconForType(type, icon, which);
109798da112cSIngo Weinhold 	}
109898da112cSIngo Weinhold 	return error;
1099d6b205f3SIngo Weinhold }
1100d6b205f3SIngo Weinhold 
11017fb6186fSStephan Aßmus // SetIconForType
11027fb6186fSStephan Aßmus /*!	\brief Sets the icon the application provides for a given MIME type.
11037fb6186fSStephan Aßmus 
11047fb6186fSStephan Aßmus 	If \a type is \c NULL, the application's icon is set.
11057fb6186fSStephan Aßmus 	If \a data is \c NULL the icon is unset.
11067fb6186fSStephan Aßmus 
11077fb6186fSStephan Aßmus 	If the file has a signature, then the icon is also set on the MIME type.
11087fb6186fSStephan Aßmus 	If the type for the signature has not been installed yet, it is installed
11097fb6186fSStephan Aßmus 	before.
11107fb6186fSStephan Aßmus 
11117fb6186fSStephan Aßmus 	\param type The MIME type in question. May be \c NULL.
11127fb6186fSStephan Aßmus 	\param data A pointer to the data containing the icon to be set.
11137fb6186fSStephan Aßmus 		   May be \c NULL.
11147fb6186fSStephan Aßmus 	\param size Specifies the size of buffer provided in \a data.
11157fb6186fSStephan Aßmus 	\return
11167fb6186fSStephan Aßmus 	- \c B_OK: Everything went fine.
11177fb6186fSStephan Aßmus 	- \c B_NO_INIT: The object is not properly initialized.
11187fb6186fSStephan Aßmus 	- \c B_BAD_VALUE: The provided \a type is not a valid MIME type.
11197fb6186fSStephan Aßmus 	- other error codes
11207fb6186fSStephan Aßmus */
11217fb6186fSStephan Aßmus status_t
11227fb6186fSStephan Aßmus BAppFileInfo::SetIconForType(const char* type, const uint8* data,
11237fb6186fSStephan Aßmus 							 size_t size)
11247fb6186fSStephan Aßmus {
11257fb6186fSStephan Aßmus 	if (InitCheck() != B_OK)
11267fb6186fSStephan Aßmus 		return B_NO_INIT;
11277fb6186fSStephan Aßmus 
11287fb6186fSStephan Aßmus 	// set some icon related variables
11297fb6186fSStephan Aßmus 	BString attributeString = kIconAttribute;
11307fb6186fSStephan Aßmus 	int32 resourceID = type ? kIconForTypeResourceID : kIconResourceID;
1131bae87c91SAxel Dörfler 	uint32 attrType = B_VECTOR_ICON_TYPE;
11327fb6186fSStephan Aßmus 
11337fb6186fSStephan Aßmus 	// check type param
11347fb6186fSStephan Aßmus 	if (type) {
11357fb6186fSStephan Aßmus 		if (BMimeType::IsValid(type))
11367fb6186fSStephan Aßmus 			attributeString += type;
11377fb6186fSStephan Aßmus 		else
11387fb6186fSStephan Aßmus 			return B_BAD_VALUE;
11397fb6186fSStephan Aßmus 	} else
11407fb6186fSStephan Aßmus 		attributeString += kIconType;
11417fb6186fSStephan Aßmus 
11427fb6186fSStephan Aßmus 	const char *attribute = attributeString.String();
11437fb6186fSStephan Aßmus 
11447fb6186fSStephan Aßmus 	status_t error;
11457fb6186fSStephan Aßmus 	// write/remove the attribute
11467fb6186fSStephan Aßmus 	if (data)
11477fb6186fSStephan Aßmus 		error = _WriteData(attribute, resourceID, attrType, data, size, true);
11487fb6186fSStephan Aßmus 	else	// no icon given => remove
11497fb6186fSStephan Aßmus 		error = _RemoveData(attribute, attrType);
11507fb6186fSStephan Aßmus 
11517fb6186fSStephan Aßmus 	// set the attribute on the MIME type, if the file has a signature
11527fb6186fSStephan Aßmus 	BMimeType mimeType;
11537fb6186fSStephan Aßmus 	if (error == B_OK && GetMetaMime(&mimeType) == B_OK) {
11547fb6186fSStephan Aßmus 		if (!mimeType.IsInstalled())
11557fb6186fSStephan Aßmus 			error = mimeType.Install();
11567fb6186fSStephan Aßmus 		if (error == B_OK)
11577fb6186fSStephan Aßmus 			error = mimeType.SetIconForType(type, data, size);
11587fb6186fSStephan Aßmus 	}
11597fb6186fSStephan Aßmus 	return error;
11607fb6186fSStephan Aßmus }
11617fb6186fSStephan Aßmus 
1162d6b205f3SIngo Weinhold // SetInfoLocation
1163d6b205f3SIngo Weinhold /*!	\brief Specifies the location where the meta data shall be stored.
1164d6b205f3SIngo Weinhold 
1165d6b205f3SIngo Weinhold 	The options for \a location are:
1166d6b205f3SIngo Weinhold 	- \c B_USE_ATTRIBUTES: Store the data in the attributes.
1167d6b205f3SIngo Weinhold 	- \c B_USE_RESOURCES: Store the data in the resources.
1168d6b205f3SIngo Weinhold 	- \c B_USE_BOTH_LOCATIONS: Store the data in attributes and resources.
1169d6b205f3SIngo Weinhold 
1170d6b205f3SIngo Weinhold 	\param location The location where the meta data shall be stored.
1171d6b205f3SIngo Weinhold */
1172d6b205f3SIngo Weinhold void
1173d6b205f3SIngo Weinhold BAppFileInfo::SetInfoLocation(info_location location)
1174d6b205f3SIngo Weinhold {
1175d0c290bfSAxel Dörfler 	// if the resources failed to initialize, we must not use them
1176d0c290bfSAxel Dörfler 	if (fResources == NULL)
1177d0c290bfSAxel Dörfler 		location = info_location(location & ~B_USE_RESOURCES);
1178d0c290bfSAxel Dörfler 
117998da112cSIngo Weinhold 	fWhere = location;
1180d6b205f3SIngo Weinhold }
1181d6b205f3SIngo Weinhold 
1182d6b205f3SIngo Weinhold // IsUsingAttributes
1183d6b205f3SIngo Weinhold /*!	\brief Returns whether the object stores the meta data (also) in the
1184d6b205f3SIngo Weinhold 		   file's attributes.
1185d6b205f3SIngo Weinhold 	\return \c true, if the meta data are (also) stored in the file's
1186d6b205f3SIngo Weinhold 			attributes, \c false otherwise.
1187d6b205f3SIngo Weinhold */
1188d6b205f3SIngo Weinhold bool
1189d6b205f3SIngo Weinhold BAppFileInfo::IsUsingAttributes() const
1190d6b205f3SIngo Weinhold {
1191d0c290bfSAxel Dörfler 	return (fWhere & B_USE_ATTRIBUTES) != 0;
1192d6b205f3SIngo Weinhold }
1193d6b205f3SIngo Weinhold 
1194d6b205f3SIngo Weinhold // IsUsingResources
1195d6b205f3SIngo Weinhold /*!	\brief Returns whether the object stores the meta data (also) in the
1196d6b205f3SIngo Weinhold 		   file's resources.
1197d6b205f3SIngo Weinhold 	\return \c true, if the meta data are (also) stored in the file's
1198d6b205f3SIngo Weinhold 			resources, \c false otherwise.
1199d6b205f3SIngo Weinhold */
1200d6b205f3SIngo Weinhold bool
1201d6b205f3SIngo Weinhold BAppFileInfo::IsUsingResources() const
1202d6b205f3SIngo Weinhold {
1203d0c290bfSAxel Dörfler 	return (fWhere & B_USE_RESOURCES) != 0;
1204d6b205f3SIngo Weinhold }
1205d6b205f3SIngo Weinhold 
1206d6b205f3SIngo Weinhold // FBC
1207d6b205f3SIngo Weinhold void BAppFileInfo::_ReservedAppFileInfo1() {}
1208d6b205f3SIngo Weinhold void BAppFileInfo::_ReservedAppFileInfo2() {}
1209d6b205f3SIngo Weinhold void BAppFileInfo::_ReservedAppFileInfo3() {}
1210d6b205f3SIngo Weinhold 
1211d6b205f3SIngo Weinhold // =
1212d6b205f3SIngo Weinhold /*!	\brief Privatized assignment operator to prevent usage.
1213d6b205f3SIngo Weinhold */
1214d6b205f3SIngo Weinhold BAppFileInfo &
1215d6b205f3SIngo Weinhold BAppFileInfo::operator=(const BAppFileInfo &)
1216d6b205f3SIngo Weinhold {
1217d6b205f3SIngo Weinhold 	return *this;
1218d6b205f3SIngo Weinhold }
1219d6b205f3SIngo Weinhold 
1220d6b205f3SIngo Weinhold // copy constructor
1221d6b205f3SIngo Weinhold /*!	\brief Privatized copy constructor to prevent usage.
1222d6b205f3SIngo Weinhold */
1223d6b205f3SIngo Weinhold BAppFileInfo::BAppFileInfo(const BAppFileInfo &)
1224d6b205f3SIngo Weinhold {
1225d6b205f3SIngo Weinhold }
1226d6b205f3SIngo Weinhold 
122798da112cSIngo Weinhold // GetMetaMime
122898da112cSIngo Weinhold /*!	\brief Initializes a BMimeType to the file's signature.
122998da112cSIngo Weinhold 
123098da112cSIngo Weinhold 	The parameter \a meta is not checked.
123198da112cSIngo Weinhold 
123298da112cSIngo Weinhold 	\param meta A pointer to a pre-allocated BMimeType that shall be
123398da112cSIngo Weinhold 		   initialized to the file's signature.
123498da112cSIngo Weinhold 	\return
123598da112cSIngo Weinhold 	- \c B_OK: Everything went fine.
123698da112cSIngo Weinhold 	- \c B_BAD_VALUE: \c NULL \a meta
123798da112cSIngo Weinhold 	- \c B_ENTRY_NOT_FOUND: The file has not signature or the signature is
123898da112cSIngo Weinhold (	  not installed in the MIME database.)
123998da112cSIngo Weinhold 	  no valid MIME string.
124098da112cSIngo Weinhold 	- other error codes
124198da112cSIngo Weinhold */
124298da112cSIngo Weinhold status_t
124398da112cSIngo Weinhold BAppFileInfo::GetMetaMime(BMimeType *meta) const
124498da112cSIngo Weinhold {
124598da112cSIngo Weinhold 	char signature[B_MIME_TYPE_LENGTH];
124698da112cSIngo Weinhold 	status_t error = GetSignature(signature);
124798da112cSIngo Weinhold 	if (error == B_OK)
124898da112cSIngo Weinhold 		error = meta->SetTo(signature);
12497f20062dSJérôme Duval 	else if (error == B_BAD_VALUE)
12507f20062dSJérôme Duval 		error = B_ENTRY_NOT_FOUND;
125198da112cSIngo Weinhold 	if (error == B_OK && !meta->IsValid())
125298da112cSIngo Weinhold 		error = B_BAD_VALUE;
125398da112cSIngo Weinhold 	return error;
125498da112cSIngo Weinhold }
125598da112cSIngo Weinhold 
125698da112cSIngo Weinhold // _ReadData
125798da112cSIngo Weinhold /*!	\brief Reads data from an attribute or resource.
125898da112cSIngo Weinhold 
125998da112cSIngo Weinhold 	The data are read from the location specified by \a fWhere.
126098da112cSIngo Weinhold 
126198da112cSIngo Weinhold 	The object must be properly initialized. The parameters are NOT checked.
126298da112cSIngo Weinhold 
126398da112cSIngo Weinhold 	\param name The name of the attribute/resource to be read.
126498da112cSIngo Weinhold 	\param id The resource ID of the resource to be read. Is ignored, when
126598da112cSIngo Weinhold 		   < 0.
126698da112cSIngo Weinhold 	\param type The type of the attribute/resource to be read.
126798da112cSIngo Weinhold 	\param buffer A pre-allocated buffer for the data to be read.
126898da112cSIngo Weinhold 	\param bufferSize The size of the supplied buffer.
126998da112cSIngo Weinhold 	\param bytesRead A reference parameter, set to the number of bytes
127098da112cSIngo Weinhold 		   actually read.
127198da112cSIngo Weinhold 	\param allocatedBuffer If not \c NULL, the method allocates a buffer
127298da112cSIngo Weinhold 		   large enough too store the whole data and writes a pointer to it
127398da112cSIngo Weinhold 		   into this variable. If \c NULL, the supplied buffer is used.
127498da112cSIngo Weinhold 	\return
127598da112cSIngo Weinhold 	- \c B_OK: Everything went fine.
127698da112cSIngo Weinhold 	- error code
127798da112cSIngo Weinhold */
127898da112cSIngo Weinhold status_t
127998da112cSIngo Weinhold BAppFileInfo::_ReadData(const char *name, int32 id, type_code type,
128098da112cSIngo Weinhold 						void *buffer, size_t bufferSize,
128198da112cSIngo Weinhold 						size_t &bytesRead, void **allocatedBuffer) const
128298da112cSIngo Weinhold {
128398da112cSIngo Weinhold 	status_t error = B_OK;
1284338b8dc3SIngo Weinhold 
128598da112cSIngo Weinhold 	if (allocatedBuffer)
128698da112cSIngo Weinhold 		buffer = NULL;
1287338b8dc3SIngo Weinhold 
1288338b8dc3SIngo Weinhold 	bool foundData = false;
1289338b8dc3SIngo Weinhold 
129098da112cSIngo Weinhold 	if (IsUsingAttributes()) {
129198da112cSIngo Weinhold 		// get an attribute info
129298da112cSIngo Weinhold 		attr_info info;
129398da112cSIngo Weinhold 		if (error == B_OK)
129498da112cSIngo Weinhold 			error = fNode->GetAttrInfo(name, &info);
1295338b8dc3SIngo Weinhold 
129698da112cSIngo Weinhold 		// check type and size, allocate a buffer, if required
129798da112cSIngo Weinhold 		if (error == B_OK && info.type != type)
129898da112cSIngo Weinhold 			error = B_BAD_VALUE;
1299b4598d95SIngo Weinhold 		if (error == B_OK && allocatedBuffer) {
130098da112cSIngo Weinhold 			buffer = malloc(info.size);
130198da112cSIngo Weinhold 			if (!buffer)
130298da112cSIngo Weinhold 				error = B_NO_MEMORY;
130398da112cSIngo Weinhold 			bufferSize = info.size;
130498da112cSIngo Weinhold 		}
130598da112cSIngo Weinhold 		if (error == B_OK && bufferSize < info.size)
130698da112cSIngo Weinhold 			error = B_BAD_VALUE;
1307338b8dc3SIngo Weinhold 
130898da112cSIngo Weinhold 		// read the data
130998da112cSIngo Weinhold 		if (error == B_OK) {
131098da112cSIngo Weinhold 			ssize_t read = fNode->ReadAttr(name, type, 0, buffer, info.size);
131198da112cSIngo Weinhold 			if (read < 0)
131298da112cSIngo Weinhold 				error = read;
131398da112cSIngo Weinhold 			else if (read != info.size)
131498da112cSIngo Weinhold 				error = B_ERROR;
131598da112cSIngo Weinhold 			else
131698da112cSIngo Weinhold 				bytesRead = read;
131798da112cSIngo Weinhold 		}
1318338b8dc3SIngo Weinhold 
1319338b8dc3SIngo Weinhold 		foundData = (error == B_OK);
1320b4598d95SIngo Weinhold 
1321b4598d95SIngo Weinhold 		// free the allocated buffer on error
1322b4598d95SIngo Weinhold 		if (!foundData && allocatedBuffer && buffer) {
1323b4598d95SIngo Weinhold 			free(buffer);
1324b4598d95SIngo Weinhold 			buffer = NULL;
1325b4598d95SIngo Weinhold 		}
1326338b8dc3SIngo Weinhold 	}
1327338b8dc3SIngo Weinhold 
1328338b8dc3SIngo Weinhold 	if (!foundData && IsUsingResources()) {
132998da112cSIngo Weinhold 		// get a resource info
1330338b8dc3SIngo Weinhold 		error = B_OK;
133198da112cSIngo Weinhold 		int32 idFound;
133298da112cSIngo Weinhold 		size_t sizeFound;
133398da112cSIngo Weinhold 		if (error == B_OK) {
133498da112cSIngo Weinhold 			if (!fResources->GetResourceInfo(type, name, &idFound, &sizeFound))
133598da112cSIngo Weinhold 				error = B_ENTRY_NOT_FOUND;
133698da112cSIngo Weinhold 		}
1337338b8dc3SIngo Weinhold 
133898da112cSIngo Weinhold 		// check id and size, allocate a buffer, if required
133998da112cSIngo Weinhold 		if (error == B_OK && id >= 0 && idFound != id)
134098da112cSIngo Weinhold 			error = B_ENTRY_NOT_FOUND;
1341b4598d95SIngo Weinhold 		if (error == B_OK && allocatedBuffer) {
134298da112cSIngo Weinhold 			buffer = malloc(sizeFound);
134398da112cSIngo Weinhold 			if (!buffer)
134498da112cSIngo Weinhold 				error = B_NO_MEMORY;
134598da112cSIngo Weinhold 			bufferSize = sizeFound;
134698da112cSIngo Weinhold 		}
134798da112cSIngo Weinhold 		if (error == B_OK && bufferSize < sizeFound)
134898da112cSIngo Weinhold 			error = B_BAD_VALUE;
1349338b8dc3SIngo Weinhold 
135098da112cSIngo Weinhold 		// load resource
135198da112cSIngo Weinhold 		const void *resourceData = NULL;
135298da112cSIngo Weinhold 		if (error == B_OK) {
135398da112cSIngo Weinhold 			resourceData = fResources->LoadResource(type, name, &bytesRead);
135498da112cSIngo Weinhold 			if (resourceData && sizeFound == bytesRead)
135598da112cSIngo Weinhold 				memcpy(buffer, resourceData, bytesRead);
135698da112cSIngo Weinhold 			else
135798da112cSIngo Weinhold 				error = B_ERROR;
135898da112cSIngo Weinhold 		}
1359773be699SAxel Dörfler 	} else if (!foundData)
136098da112cSIngo Weinhold 		error = B_BAD_VALUE;
1361338b8dc3SIngo Weinhold 
136298da112cSIngo Weinhold 	// return the allocated buffer, or free it on error
136398da112cSIngo Weinhold 	if (allocatedBuffer) {
136498da112cSIngo Weinhold 		if (error == B_OK)
136598da112cSIngo Weinhold 			*allocatedBuffer = buffer;
136698da112cSIngo Weinhold 		else
136798da112cSIngo Weinhold 			free(buffer);
136898da112cSIngo Weinhold 	}
1369338b8dc3SIngo Weinhold 
137098da112cSIngo Weinhold 	return error;
137198da112cSIngo Weinhold }
137298da112cSIngo Weinhold 
137398da112cSIngo Weinhold // _WriteData
137498da112cSIngo Weinhold /*!	\brief Writes data to an attribute or resource.
137598da112cSIngo Weinhold 
137698da112cSIngo Weinhold 	The data are written to the location(s) specified by \a fWhere.
137798da112cSIngo Weinhold 
137898da112cSIngo Weinhold 	The object must be properly initialized. The parameters are NOT checked.
137998da112cSIngo Weinhold 
138098da112cSIngo Weinhold 	\param name The name of the attribute/resource to be written.
138198da112cSIngo Weinhold 	\param id The resource ID of the resource to be written.
138298da112cSIngo Weinhold 	\param type The type of the attribute/resource to be written.
138398da112cSIngo Weinhold 	\param buffer A buffer containing the data to be written.
138498da112cSIngo Weinhold 	\param bufferSize The size of the supplied buffer.
138598da112cSIngo Weinhold 	\param findID If set to \c true use the ID that is already assigned to the
138698da112cSIngo Weinhold 		   \a name / \a type pair or take the first unused ID >= \a id.
138798da112cSIngo Weinhold 		   If \c false, \a id is used.
138898da112cSIngo Weinhold 	If \a id is already in use and .
138998da112cSIngo Weinhold 	\return
139098da112cSIngo Weinhold 	- \c B_OK: Everything went fine.
139198da112cSIngo Weinhold 	- error code
139298da112cSIngo Weinhold */
139398da112cSIngo Weinhold status_t
139498da112cSIngo Weinhold BAppFileInfo::_WriteData(const char *name, int32 id, type_code type,
139598da112cSIngo Weinhold 						 const void *buffer, size_t bufferSize, bool findID)
139698da112cSIngo Weinhold {
1397d0c290bfSAxel Dörfler 	if (!IsUsingAttributes() && !IsUsingResources())
1398d0c290bfSAxel Dörfler 		return B_NO_INIT;
1399d0c290bfSAxel Dörfler 
140098da112cSIngo Weinhold 	status_t error = B_OK;
1401d0c290bfSAxel Dörfler 
140298da112cSIngo Weinhold 	// write to attribute
1403d0c290bfSAxel Dörfler 	if (IsUsingAttributes()) {
140498da112cSIngo Weinhold 		ssize_t written = fNode->WriteAttr(name, type, 0, buffer, bufferSize);
140598da112cSIngo Weinhold 		if (written < 0)
140698da112cSIngo Weinhold 			error = written;
140798da112cSIngo Weinhold 		else if (written != (ssize_t)bufferSize)
140898da112cSIngo Weinhold 			error = B_ERROR;
140998da112cSIngo Weinhold 	}
141098da112cSIngo Weinhold 	// write to resource
141198da112cSIngo Weinhold 	if (IsUsingResources() && error == B_OK) {
141298da112cSIngo Weinhold 		if (findID) {
141398da112cSIngo Weinhold 			// get the resource info
141498da112cSIngo Weinhold 			int32 idFound;
141598da112cSIngo Weinhold 			size_t sizeFound;
141698da112cSIngo Weinhold 			if (fResources->GetResourceInfo(type, name, &idFound, &sizeFound))
141798da112cSIngo Weinhold 				id = idFound;
141898da112cSIngo Weinhold 			else {
141998da112cSIngo Weinhold 				// type-name pair doesn't exist yet -- find unused ID
142098da112cSIngo Weinhold 				while (fResources->HasResource(type, id))
142198da112cSIngo Weinhold 					id++;
142298da112cSIngo Weinhold 			}
142398da112cSIngo Weinhold 		}
142498da112cSIngo Weinhold 		error = fResources->AddResource(type, id, buffer, bufferSize, name);
142598da112cSIngo Weinhold 	}
142698da112cSIngo Weinhold 	return error;
142798da112cSIngo Weinhold }
142898da112cSIngo Weinhold 
142998da112cSIngo Weinhold // _RemoveData
143098da112cSIngo Weinhold /*!	\brief Removes an attribute or resource.
143198da112cSIngo Weinhold 
143298da112cSIngo Weinhold 	The removal location is specified by \a fWhere.
143398da112cSIngo Weinhold 
143498da112cSIngo Weinhold 	The object must be properly initialized. The parameters are NOT checked.
143598da112cSIngo Weinhold 
143698da112cSIngo Weinhold 	\param name The name of the attribute/resource to be remove.
143798da112cSIngo Weinhold 	\param type The type of the attribute/resource to be removed.
143898da112cSIngo Weinhold 	\return
143998da112cSIngo Weinhold 	- \c B_OK: Everything went fine.
144098da112cSIngo Weinhold 	- error code
144198da112cSIngo Weinhold */
144298da112cSIngo Weinhold status_t
144398da112cSIngo Weinhold BAppFileInfo::_RemoveData(const char *name, type_code type)
144498da112cSIngo Weinhold {
1445d0c290bfSAxel Dörfler 	if (!IsUsingAttributes() && !IsUsingResources())
1446d0c290bfSAxel Dörfler 		return B_NO_INIT;
1447d0c290bfSAxel Dörfler 
144898da112cSIngo Weinhold 	status_t error = B_OK;
1449d0c290bfSAxel Dörfler 
145098da112cSIngo Weinhold 	// remove the attribute
1451d0c290bfSAxel Dörfler 	if (IsUsingAttributes()) {
145298da112cSIngo Weinhold 		error = fNode->RemoveAttr(name);
145398da112cSIngo Weinhold 		// It's no error, if there has been no attribute.
145498da112cSIngo Weinhold 		if (error == B_ENTRY_NOT_FOUND)
145598da112cSIngo Weinhold 			error = B_OK;
145698da112cSIngo Weinhold 	}
145798da112cSIngo Weinhold 	// remove the resource
145898da112cSIngo Weinhold 	if (IsUsingResources() && error == B_OK) {
145998da112cSIngo Weinhold 		// get a resource info
146098da112cSIngo Weinhold 		int32 idFound;
146198da112cSIngo Weinhold 		size_t sizeFound;
146298da112cSIngo Weinhold 		if (fResources->GetResourceInfo(type, name, &idFound, &sizeFound))
146398da112cSIngo Weinhold 			error = fResources->RemoveResource(type, idFound);
146498da112cSIngo Weinhold 	}
146598da112cSIngo Weinhold 	return error;
146698da112cSIngo Weinhold }
146798da112cSIngo Weinhold 
1468