2 * Copyright 2011-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * John Scipione, jscipione@gmail.com
7 * Ingo Weinhold, bonefish@users.sf.net
10 * headers/os/storage/AppFileInfo.h hrev47402
11 * src/kits/storage/AppFileInfo.cpp hrev47402
19 \brief Provides the BAppFileInfo class.
27 \brief Provides access to the metadata associated with executables,
28 libraries and add-ons.
30 The BAppFileInfo class allows for information about an executable or
31 add-on to be accessed or set. Information about an executable that can be
32 accessed include the signature, catalog entry, supported MIME types,
33 application flags, icon(s), and version info.
35 You should initialize the BAppFileInfo with a BFile object that represents
36 the executable or add-on that you want to access. If you only want to read
37 metadata from the file you do not have to open it for reading. However, if
38 you also want to write metadata then you should open the BFile for writing.
40 To associate a BFile with a BAppFileInfo object you can either pass the
41 BFile object into the constructor or you can use the empty constructor and
42 then use the SetTo() method to set the BFile to the BAppFileInfo object.
44 When accessing information from a BFileInfo object it will first look in the
45 attributes of the BFile. If the information is not found then the BFileInfo
46 object will next look at the resource of the BFile. You can tell the
47 BFileInfo object to look only in the attributes or resources with the
48 SetInfoLocation() method.
55 \fn BAppFileInfo::BAppFileInfo()
56 \brief Creates an uninitialized BAppFileInfo object.
63 \fn BAppFileInfo::BAppFileInfo(BFile* file)
64 \brief Creates an BAppFileInfo object and initializes it to the supplied
67 The caller retains ownership of the supplied BFile object. It must not
68 be deleted during the life time of the BAppFileInfo. It is not deleted
69 when the BAppFileInfo is destroyed.
71 \param file The BFile object that the BAppFileInfo object shall be
79 \fn BAppFileInfo::~BAppFileInfo()
80 \brief Frees all resources associated with this object.
82 The supplied BFile object is not deleted if one is specified.
89 \fn status_t BAppFileInfo::SetTo(BFile *file)
90 \brief Initializes the BAppFileInfo to the supplied file.
92 The caller retains ownership of the supplied BFile object. It must not
93 be deleted during the life time of the BAppFileInfo. The BFile object
94 is not deleted when the BAppFileInfo is destroyed.
96 \param file The BFile object that the BAppFileInfo object shall be
99 \returns an status code.
100 \retval B_OK Everything went fine.
101 \retval B_BAD_VALUE \c NULL \a file or \a file is not properly initialized.
116 \fn status_t BAppFileInfo::GetType(char *type) const
117 \brief Gets the MIME type of the associated file.
119 \param type A pointer to a pre-allocated character buffer of size
120 \c B_MIME_TYPE_LENGTH or larger into which the MIME type of the
121 file will be written.
123 \returns A status code.
124 \retval B_OK Everything went fine.
125 \retval B_NO_INIT The object is not properly initialized.
126 \retval B_BAD_VALUE \c NULL \a type or the type string stored in the
127 attribute/resources is longer than \c B_MIME_TYPE_LENGTH.
128 \retval B_BAD_TYPE The attribute/resources the type string is stored in
130 \retval B_ENTRY_NOT_FOUND No type is set on the file.
137 \fn status_t BAppFileInfo::SetType(const char* type)
138 \brief Sets the MIME type of the associated file.
140 If \a type is \c NULL if the file's MIME type is unset.
142 \param type The MIME type to be assigned to the file. It must not be
143 longer than \c B_MIME_TYPE_LENGTH (including the terminating \0).
144 The MIME type may be \c NULL.
146 \returns a status code.
147 \retval B_OK Everything went fine.
148 \retval B_NO_INIT The object is not properly initialized.
149 \retval B_BAD_VALUE \a type is longer than \c B_MIME_TYPE_LENGTH.
167 \fn status_t BAppFileInfo::GetSignature(char* signature) const
168 \brief Gets the application signature of the associated file.
170 \param signature A pointer to a pre-allocated character buffer of size
171 \c B_MIME_TYPE_LENGTH or larger into which the application
172 signature of the file will be written.
174 \returns a status code.
175 \retval B_OK Everything went fine.
176 \retval B_NO_INIT The object is not properly initialized.
177 \retval B_BAD_VALUE \c NULL \a signature or the signature stored in the
178 attribute/resources is longer than \c B_MIME_TYPE_LENGTH.
179 \retval B_BAD_TYPE The attribute/resources the signature is stored in have
181 \retval B_ENTRY_NOT_FOUND No signature is set on the file.
188 \fn status_t BAppFileInfo::SetSignature(const char* signature)
189 \brief Sets the application signature of the associated file.
191 If \a signature is \c NULL the file's application signature is unset.
193 \param signature The application signature to be assigned to the file.
194 Must not be longer than \c B_MIME_TYPE_LENGTH (including the
195 terminating \0). The \a signature may be \c NULL.
197 \returns a status code.
198 \retval B_OK Everything went fine.
199 \retval B_NO_INIT The object is not properly initialized.
200 \retval B_BAD_VALUE \a signature is longer than \c B_MIME_TYPE_LENGTH.
218 \fn status_t BAppFileInfo::GetCatalogEntry(char *catalogEntry) const
219 \brief Gets the catalog entry of the associated file used for localization.
221 \param catalogEntry A pointer to a pre-allocated character buffer of size
222 \c B_MIME_TYPE_LENGTH * 3 or larger into which the catalog entry
223 of the file will be written.
225 \returns a status code.
226 \retval B_OK Everything went fine.
227 \retval B_NO_INIT The object is not properly initialized.
228 \retval B_BAD_VALUE \c NULL \a catalogEntry or the entry stored in the
229 attribute/resources is longer than \c B_MIME_TYPE_LENGTH * 3.
230 \retval B_BAD_TYPE The attribute/resources the entry is stored in have
232 \retval B_ENTRY_NOT_FOUND No catalog entry is set on the file.
239 \fn status_t BAppFileInfo::SetCatalogEntry(const char* catalogEntry)
240 \brief Sets the catalog entry of the associated file used for localization.
242 If \a catalogEntry is \c NULL the file's catalog entry is unset.
244 \param catalogEntry The catalog entry to be assigned to the file.
245 Of the form "x-vnd.Haiku-app:context:name". Must not be longer than
246 \c B_MIME_TYPE_LENGTH * 3 (including the terminating \0).
247 The \a catalogEntry may be \c NULL.
249 \returns a status code.
250 \retval B_OK Everything went fine.
251 \retval B_NO_INIT The object is not properly initialized.
252 \retval B_BAD_VALUE \a catalogEntry is longer than
253 \c B_MIME_TYPE_LENGTH * 3.
263 \name Application Flags
271 \fn status_t BAppFileInfo::GetAppFlags(uint32* flags) const
272 \brief Gets the application \a flags of the associated file.
274 \param flags A pointer to a pre-allocated \c uint32 into which the
275 application flags of the file are written.
277 \returns A status code.
278 \retval B_OK Everything went fine.
279 \retval B_NO_INIT The object is not properly initialized.
280 \retval B_BAD_VALUE \c NULL \a flags.
281 \retval B_BAD_TYPE The attribute/resources the flags are stored in have
283 \retval B_ENTRY_NOT_FOUND No application flags are set on the file.
290 \fn status_t BAppFileInfo::SetAppFlags(uint32 flags)
291 \brief Sets the application \a flags of the associated file.
293 \param flags The application \a flags to be assigned to the file.
295 \returns A status code.
296 \retval B_OK Everything went fine.
297 \retval B_NO_INIT The object was not properly initialized.
304 \fn status_t BAppFileInfo::RemoveAppFlags()
305 \brief Removes the application flags from the associated file.
307 \returns A status code.
308 \retval B_OK Everything went fine.
309 \retval B_NO_INIT The object was not properly initialized.
319 \name Supported MIME Types
327 \fn status_t BAppFileInfo::GetSupportedTypes(BMessage* types) const
328 \brief Gets the MIME types supported by the application.
330 The supported MIME types are added to a field "types" of type
331 \c B_STRING_TYPE in \a types.
333 \param types A pointer to a pre-allocated BMessage into which the
334 MIME types supported by the application will be written.
336 \returns A status code.
337 \retval B_OK Everything went fine.
338 \retval B_NO_INIT The object is not properly initialized.
339 \retval B_BAD_VALUE \c NULL \a types.
340 \retval B_BAD_TYPE The attribute/resources that the supported types
341 are stored in have the wrong type.
342 \retval B_ENTRY_NOT_FOUND No supported types are set on the file.
349 \fn status_t BAppFileInfo::SetSupportedTypes(const BMessage* types,
350 bool updateMimeDB, bool syncAll)
351 \brief Sets the MIME types that are supported by the application
352 and allows you to specify whether or not the supported types
353 in the MIME DB shall be updated as well.
355 If \a types is \c NULL then the application's supported types are unset.
357 The supported MIME types must be stored in a field "types" of type
358 \c B_STRING_TYPE in \a types.
360 If \a updateMimeDB is \c true, the method will inform the registrar about
361 this news. In this case for each supported type the result of
362 BMimeType::GetSupportingApps() will afterward include the signature of this
363 application. That is, the application file needs to have a signature set.
365 \a syncAll specifies whether the no longer supported types shall be
366 updated as well, i.e. whether or not this application shall be removed
367 from the list of supporting applications. Only relevant when \a updateMimeDB
370 \param types The supported types to be assigned to the file.
372 \param updateMimeDB \c true to update the supported types in the MIME DB,
374 \param syncAll \c true to also synchronize the no-longer supported
375 types, \c false otherwise.
377 \returns A status code.
378 \retval B_OK Everything went fine.
379 \retval B_NO_INIT The object is not properly initialized.
386 \fn status_t BAppFileInfo::SetSupportedTypes(const BMessage* types,
388 \brief Sets the MIME types that are supported by the application and allows
389 you to specify whether or not the no longer supported types shall be
392 If \a types is \c NULL then the application's supported types are unset.
394 The supported MIME types must be stored in a field "types" of type
395 \c B_STRING_TYPE in \a types.
397 The method informs the registrar about this news.
398 For each supported type the result of BMimeType::GetSupportingApps()
399 will afterwards include the signature of this application. That is,
400 the application file needs to have a signature set.
402 \a syncAll specifies whether the no longer supported types shall be
403 updated as well, i.e. whether or not this application shall be removed
404 from the list of supporting applications.
406 \param types The supported types to be assigned to the file.
408 \param syncAll \c true to also synchronize the no-longer supported
409 types, \c false otherwise.
411 \returns A status code.
412 \retval B_OK Everything went fine.
413 \retval B_NO_INIT The object is not properly initialized.
420 \fn status_t BAppFileInfo::SetSupportedTypes(const BMessage* types)
421 \brief Sets the MIME types supported by the application.
423 This method is a short-hand for SetSupportedTypes(types, false).
424 \see SetSupportedType(const BMessage*, bool) for detailed information.
426 \param types The supported types to be assigned to the file.
428 \returns A status code.
429 \retval B_OK Everything went fine.
430 \retval B_NO_INIT The object is not properly initialized.
437 \fn bool BAppFileInfo::IsSupportedType(const char* type) const
438 \brief Returns whether the application supports the supplied MIME type.
440 If the application supports the wildcard type "application/octet-stream"
441 then this method returns \c true for any MIME type.
443 \param type The MIME type in question.
445 \returns \c true if \a type is a valid MIME type and it is supported by
446 the application, \c false otherwise.
453 \fn bool BAppFileInfo::Supports(BMimeType* type) const
454 \brief Returns whether the application supports the supplied MIME type
457 Unlike IsSupportedType(), this method returns \c true, only if the type
458 is explicitly supported, regardless of whether it supports
459 "application/octet-stream".
461 \param type The MIME type in question.
463 \returns \c true if \a type is a valid MIME type and it is explicitly
464 supported by the application, \c false otherwise.
474 \name Application Icon
482 \fn status_t BAppFileInfo::GetIcon(BBitmap* icon, icon_size which) const
483 \brief Gets the icon of the associated file and puts it into a
484 pre-allocated BBitmap.
486 \param icon A pointer to a pre-allocated BBitmap of the correct dimension
487 to store the requested icon (16x16 for the \c B_MINI_ICON and 32x32
488 for the \c B_LARGE_ICON).
489 \param which Specifies the size of the icon to be retrieved:
490 \c B_MINI_ICON for the mini and \c B_LARGE_ICON for the large icon.
491 For HVIF icons this parameter has no effect.
493 \returns A status code.
494 \retval B_OK Everything went fine.
495 \retval B_NO_INIT The object is not properly initialized.
496 \retval B_BAD_VALUE \c NULL \a icon, unsupported icon size \a which or
497 bitmap dimensions (\a icon) and icon size (\a which) do not match.
504 \fn status_t BAppFileInfo::GetIcon(uint8** data, size_t* size) const
505 \brief Gets the icon of the associated file and puts it into a buffer.
507 \param data The pointer in which the flat icon data will be returned.
508 \param size The pointer in which the size of the data found will be
511 \returns A status code.
512 \retval B_OK Everything went fine.
513 \retval B_NO_INIT The object is not properly initialized.
514 \retval B_BAD_VALUE \c NULL \a data or \c NULL size.
521 \fn status_t BAppFileInfo::SetIcon(const BBitmap* icon, icon_size which,
523 \brief Sets the icon of the associated file from a BBitmap.
525 If \a icon is \c NULL then the icon of the file is unset.
527 \param icon A pointer to the BBitmap containing the icon to be set.
528 May be \c NULL to specify no icon.
529 \param which Specifies the size of the icon to be set: \c B_MINI_ICON for
530 16x16 mini icon and \c B_LARGE_ICON for the 32x32 large icon.
531 For HVIF icons this parameter has no effect.
532 \param updateMimeDB \c true to also set the icon for the application in the
533 MIME DB. \c false otherwise.
535 \returns A status code.
536 \retval B_OK Everything went fine.
537 \retval B_NO_INIT The object is not properly initialized.
538 \retval B_BAD_VALUE Unknown icon size \a which or bitmap dimensions
539 (\a icon) and icon size (\a which) do not match.
546 \fn status_t BAppFileInfo::SetIcon(const BBitmap* icon, icon_size which)
547 \brief Sets the icon of the associated file from a BBitmap.
549 If \a icon is \c NULL then the icon of the file is unset.
551 Also sets the application's icon in the MIME DB, if the file has a valid
552 application signature.
554 \param icon A pointer to the BBitmap containing the icon to be set.
555 May be \c NULL to specify no icon.
556 \param which Specifies the size of the icon to be set: \c B_MINI_ICON for
557 16x16 mini icon and \c B_LARGE_ICON for the 32x32 large icon.
558 For HVIF icons this parameter has no effect.
560 \returns A status code.
561 \retval B_OK Everything went fine.
562 \retval B_NO_INIT The object is not properly initialized.
563 \retval B_BAD_VALUE Unknown icon size \a which or bitmap dimensions
564 (\a icon) and icon size (\a which) do not match.
571 \fn status_t BAppFileInfo::SetIcon(const uint8* data, size_t size,
573 \brief Sets the icon of the associated file from a buffer.
575 If \a data is \c NULL then the icon of the file is unset.
577 \param data A pointer to the data buffer containing the vector icon
578 to be set. May be \c NULL.
579 \param size Specifies the size of buffer pointed to by \a data.
580 \param updateMimeDB \c true to also set the icon for the application in the
581 MIME DB. \c false otherwise.
583 \returns A status code.
584 \retval B_OK Everything went fine.
585 \retval B_NO_INIT The object is not properly initialized.
586 \retval B_BAD_VALUE \c NULL data.
593 \fn status_t BAppFileInfo::SetIcon(const uint8* data, size_t size)
594 \brief Sets the icon of the associated file from a buffer.
596 If \a data is \c NULL then the icon of the file is unset.
598 Also sets the application's icon in the MIME DB, if the file has a valid
599 application signature.
601 \param data A pointer to the data buffer containing the vector icon
602 to be set. May be \c NULL.
603 \param size Specifies the size of buffer pointed to by \a data.
605 \returns A status code.
606 \retval B_OK Everything went fine.
607 \retval B_NO_INIT The object is not properly initialized.
608 \retval B_BAD_VALUE \c NULL data.
615 \fn status_t BAppFileInfo::GetIconForType(const char* type, BBitmap* icon,
616 icon_size size) const
617 \brief Gets the icon the application provides for a given MIME type and
618 puts it into a BBitmap.
620 \note If \a type is \c NULL, the application's icon is retrieved.
622 \param type The MIME type in question. May be \c NULL.
623 \param icon A pointer to a pre-allocated BBitmap of the correct dimension
624 to store the requested icon (16x16 for the mini and 32x32 for the
626 \param size Specifies the size of the icon to be retrieved:
627 \c B_MINI_ICON for the mini and \c B_LARGE_ICON for the large icon.
629 \returns A status code.
630 \retval B_OK Everything went fine.
631 \retval B_NO_INIT The object is not properly initialized.
632 \retval B_BAD_VALUE \c NULL \a icon, unsupported icon size
633 \a which or bitmap dimensions (\a icon) and icon size (\a which)
641 \fn status_t BAppFileInfo::GetIconForType(const char* type, uint8** data,
643 \brief Gets the icon the application provides for a given MIME type and
644 puts it into a buffer.
646 \note If \a type is set to \c NULL the the application's icon is retrieved.
648 \param type The MIME type in question. May be \c NULL.
649 \param data A pointer in which the icon data will be returned. When you
650 are done with the data, you should use free() to deallocate it.
651 \param size A pointer in which the size of the retrieved data is returned.
653 \returns A status code.
654 \retval B_OK Everything went fine.
655 \retval B_NO_INIT The object is not properly initialized.
656 \retval B_BAD_VALUE \c NULL \a data and/or \a size. Or the supplied
657 \a type is not a valid MIME type.
664 \fn status_t BAppFileInfo::SetIconForType(const char* type,
665 const BBitmap* icon, icon_size which, bool updateMimeDB)
666 \brief Sets the icon the application provides for a given MIME type from a
669 \note If \a type is \c NULL then the icon is set.
670 \note If \a icon is \c NULL then the icon is unset.
672 If \a updateMimeDB is \c true and if the file has a signature, then the icon
673 is also set on the MIME type. If the type for the signature has not been
674 installed yet, it is installed before.
676 \param type The MIME type in question. May be \c NULL.
677 \param icon A pointer to the BBitmap containing the icon to be set.
679 \param which Specifies the size of the icon to be set: \c B_MINI_ICON
680 for the mini and \c B_LARGE_ICON for the large icon.
681 \param updateMimeDB \c true to also set the icon for the type in the MIME
682 DB. \c false otherwise.
684 \returns A status code.
685 \retval B_OK Everything went fine.
686 \retval B_NO_INIT The object is not properly initialized.
687 \retval B_BAD_VALUE Either the icon size \a which is unknown,
688 the bitmap dimensions (\a icon) and icon size (\a which) do not
689 match, or the provided \a type is not a valid MIME type.
696 \fn status_t BAppFileInfo::SetIconForType(const char* type,
697 const BBitmap* icon, icon_size which)
698 \brief Sets the icon the application provides for a given MIME type from a
701 \note If \a type is \c NULL then the icon is set.
702 \note If \a icon is \c NULL then the icon is unset.
704 If the file has a signature, then the icon is also set on the MIME type.
705 If the type for the signature has not been installed yet, it is installed
708 \param type The MIME type in question. May be \c NULL.
709 \param icon A pointer to the BBitmap containing the icon to be set.
711 \param which Specifies the size of the icon to be set: \c B_MINI_ICON
712 for the mini and \c B_LARGE_ICON for the large icon.
714 \returns A status code.
715 \retval B_OK Everything went fine.
716 \retval B_NO_INIT The object is not properly initialized.
717 \retval B_BAD_VALUE Either the icon size \a which is unknown,
718 the bitmap dimensions (\a icon) and icon size (\a which) do not
719 match, or the provided \a type is not a valid MIME type.
726 \fn status_t BAppFileInfo::SetIconForType(const char* type,
727 const uint8* data, size_t size, bool updateMimeDB)
728 \brief Sets the icon the application provides for a given MIME type from a
731 \note If \a type is \c NULL then the icon is set.
732 \note If \a data is \c NULL then the icon is unset.
734 If \a updateMimeDB is \c true and if the file has a signature, then the icon
735 is also set on the MIME type. If the type for the signature has not been
736 installed yet, it is installed before.
738 \param type The MIME type in question. May be \c NULL.
739 \param data A pointer to the data containing the icon to be set.
741 \param size Specifies the size of buffer provided in \a data.
742 \param updateMimeDB \c true to also set the icon for the type in the MIME
743 DB. \c false otherwise.
745 \returns A status code.
746 \retval B_OK Everything went fine.
747 \retval B_NO_INIT The object is not properly initialized.
748 \retval B_BAD_VALUE The provided \a type is not a valid MIME type.
755 \fn status_t BAppFileInfo::SetIconForType(const char* type,
756 const uint8* data, size_t size)
757 \brief Sets the icon the application provides for a given MIME type from a
760 \note If \a type is \c NULL then the icon is set.
761 \note If \a data is \c NULL then the icon is unset.
763 If the file has a signature, then the icon is also set on the MIME type.
764 If the type for the signature has not been installed yet, it is
767 \param type The MIME type in question. May be \c NULL.
768 \param data A pointer to the data containing the icon to be set.
770 \param size Specifies the size of buffer provided in \a data.
772 \returns A status code.
773 \retval B_OK Everything went fine.
774 \retval B_NO_INIT The object is not properly initialized.
775 \retval B_BAD_VALUE The provided \a type is not a valid MIME type.
793 \fn status_t BAppFileInfo::GetVersionInfo(version_info* info,
794 version_kind kind) const
795 \brief Gets the version info of the associated file.
797 \param info A pointer to a pre-allocated version_info structure into
798 which the version info should be written.
799 \param kind Specifies the kind of the version info to be retrieved:
800 - \c B_APP_VERSION_KIND for the application's version info and
801 - \c B_SYSTEM_VERSION_KIND for the suite's info the application
804 \returns A status code.
805 \retval B_OK Everything went fine.
806 \retval B_NO_INIT The object is not properly initialized.
807 \retval B_BAD_VALUE \c NULL \a info.
814 \fn status_t BAppFileInfo::SetVersionInfo(const version_info* info,
816 \brief Sets the version info of the associated file.
818 \note If \a info is set to \c NULL then the file's version info is unset.
820 \param info The version info to be set. May be \c NULL.
821 \param kind Specifies kind of version info to be set:
822 - \c B_APP_VERSION_KIND for the application's version info and
823 - \c B_SYSTEM_VERSION_KIND for the suite's info the application
826 \returns A status code.
827 \retval B_OK Everything went fine.
828 \retval B_NO_INIT The object is not properly initialized.
838 \name Attributes/Resources
846 \fn void BAppFileInfo::SetInfoLocation(info_location location)
847 \brief Specifies the location where the metadata shall be stored.
849 The options for \a location are:
850 - \c B_USE_ATTRIBUTES: Store the data in the attributes.
851 - \c B_USE_RESOURCES: Store the data in the resources.
852 - \c B_USE_BOTH_LOCATIONS: Store the data in attributes and resources.
854 \param location The location where the metadata shall be stored.
861 \fn bool BAppFileInfo::IsUsingAttributes() const
862 \brief Returns whether the object (also) stores the metadata in the
863 attributes of the associated file.
865 \returns \c true if the metadata are (also) stored in the file's
866 attributes, \c false otherwise.
873 \fn bool BAppFileInfo::IsUsingResources() const
874 \brief Returns whether the object (also) stores the metadata in the
875 resources of the associated file.
877 \returns \c true if the metadata are (also) stored in the file's
878 resources, \c false otherwise.